Skip to content

Commit da079f7

Browse files
davidaurelioFacebook Github Bot
authored and
Facebook Github Bot
committed
change isPolyfill to type = 'module' | 'script'
Summary: When building, we will process modules in a special way, *not* polyfillys. We will also add more types of (virtual) files that are not modules. That’s why a “type” property makes more sense. Reviewed By: cpojer Differential Revision: D4244583 fbshipit-source-id: 92a0b4a0a2026d0b97ba88034483a6ce4e0c1ebb
1 parent 021b313 commit da079f7

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

Diff for: packager/react-packager/src/ModuleGraph/Graph.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type LoadQueue =
5050
Async$Queue<{id: string, parent: string}, Callback<File, Array<string>>>;
5151

5252
const createParentModule =
53-
() => ({file: {code: '', isPolyfill: false, path: ''}, dependencies: []});
53+
() => ({file: {code: '', type: 'script', path: ''}, dependencies: []});
5454

5555
const noop = () => {};
5656
const NO_OPTIONS = {};

Diff for: packager/react-packager/src/ModuleGraph/types.flow.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ type Dependency = {|
4040

4141
export type File = {|
4242
code: string,
43-
isPolyfill: boolean,
4443
map?: ?Object,
4544
path: string,
45+
type: FileTypes,
4646
|};
4747

48+
type FileTypes = 'module' | 'script';
49+
4850
export type Module = {|
4951
dependencies: Array<Dependency>,
5052
file: File,
@@ -82,9 +84,9 @@ export type TransformedFile = {
8284
code: string,
8385
file: string,
8486
hasteID: ?string,
85-
isPolyfill: boolean,
8687
package?: PackageData,
8788
transformed: {[variant: string]: TransformResult},
89+
type: FileTypes,
8890
};
8991

9092
export type PackageData = {|

Diff for: packager/react-packager/src/ModuleGraph/worker/__tests__/transform-module-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ describe('transforming JS modules:', () => {
6262
});
6363
});
6464

65-
it('sets `isPolyfill` to `false` by default', done => {
65+
it('sets `type` to `"module"` by default', done => {
6666
transformModule(sourceCode, options(), (error, result) => {
67-
expect(result).toEqual(objectContaining({isPolyfill: false}));
67+
expect(result).toEqual(objectContaining({type: 'module'}));
6868
done();
6969
});
7070
});
7171

72-
it('sets `isPolyfill` to `true` if the input is a polyfill', done => {
72+
it('sets `type` to `"script"` if the input is a polyfill', done => {
7373
transformModule(sourceCode, {...options(), polyfill: true}, (error, result) => {
74-
expect(result).toEqual(objectContaining({isPolyfill: true}));
74+
expect(result).toEqual(objectContaining({type: 'script'}));
7575
done();
7676
});
7777
});

Diff for: packager/react-packager/src/ModuleGraph/worker/transform-module.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ function transformModule(
7575
callback(null, {
7676
code,
7777
file: filename,
78-
isPolyfill: !!options.polyfill,
7978
hasteID: annotations.providesModule || annotations.provide || null,
8079
transformed,
80+
type: options.polyfill ? 'script' : 'module',
8181
});
8282
});
8383
}
@@ -105,8 +105,8 @@ function transformJSON(json, options, callback) {
105105
code: json,
106106
file: filename,
107107
hasteID: value.name,
108-
isPolyfill: false,
109108
transformed,
109+
type: 'module',
110110
};
111111

112112
if (basename(filename) === 'package.json') {

0 commit comments

Comments
 (0)