metro-bundler: stricter TransformedCodeFile type and fix use sites

Summary: Here's a good example why Flow "exact types" are useful: there are a few place where we were adding unusused fields in the objects. As these fields end up in JSON files used to communicate with Buck, this can amount to a waste of resources. This changeset make the type exact and removes the unused fields.

Reviewed By: mjesun

Differential Revision: D6159350

fbshipit-source-id: 8cdf29d5729253f119778943ad961eacb8990c04
This commit is contained in:
Jean Lauliac 2017-10-26 07:41:24 -07:00 committed by Facebook Github Bot
parent 0e764686e1
commit c293f4bfab
3 changed files with 3 additions and 8 deletions

View File

@ -152,13 +152,13 @@ export type TransformResults = {[string]: TransformResult};
export type TransformVariants = {+[name: string]: {}, +default: {}};
export type TransformedCodeFile = {
export type TransformedCodeFile = {|
+file: string,
+hasteID: ?string,
package?: PackageData,
+transformed: TransformResults,
+type: CodeFileTypes,
};
|};
export type ImageSize = {|+width: number, +height: number|};

View File

@ -49,12 +49,11 @@ describe('transforming JS modules:', () => {
ast: t.file(t.program(body)),
});
it('passes through file name and code', () => {
it('passes through file name', () => {
const result = transformModule(sourceCode, options());
expect(result.type).toBe('code');
expect(result.details).toEqual(
expect.objectContaining({
code: sourceCode,
file: filename,
}),
);

View File

@ -99,8 +99,6 @@ function transformModule(
return {
details: {
assetContent: null,
code,
file: filename,
hasteID: hasteID || null,
transformed,
@ -129,8 +127,6 @@ function transformJSON(json, options): TransformedSourceFile {
);
const result: TransformedCodeFile = {
assetContent: null,
code: json,
file: filename,
hasteID: value.name,
transformed,