Skip to content

Commit 281d76a

Browse files
captbaritonefacebook-github-bot
authored andcommitted
Update babel transform to default to default to ES modules to match compiler behavior (#4982)
Summary: Pull Request resolved: #4982 Test Plan: Would love help constructing a robust test plan here. Reviewed By: robhogan Differential Revision: D74219556 Pulled By: captbaritone fbshipit-source-id: 66a4963c25f5187db6dcddef1426255e2e87a58e
1 parent 3522921 commit 281d76a

9 files changed

+57
-109
lines changed

packages/babel-plugin-relay/BabelPluginRelay.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ export type RelayPluginOptions = {
4141
// Name of the global variable for dev mode
4242
isDevVariableName?: string,
4343

44-
// enable generating eager es modules for modern runtime
44+
// Enable generating eager es modules for modern runtime.
45+
// Defaults to `true` as of v19.0.1
4546
eagerEsModules?: boolean,
4647

4748
// Directory as specified by artifactDirectory when running relay-compiler

packages/babel-plugin-relay/__tests__/__snapshots__/BabelPluginRelay-modern-artifact-directory-test.js.snap

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ const testFragment = graphql\`
2929
3030
'use strict';
3131
32-
var _TestFragment;
32+
import _TestFragment from '../test/artifacts/TestFragment.graphql';
3333
const {graphql} = require('relay-runtime');
34-
const testFragment =
35-
_TestFragment !== void 0
36-
? _TestFragment
37-
: (_TestFragment = require('../test/artifacts/TestFragment.graphql'));
34+
const testFragment = _TestFragment;
3835
3936
`;
4037

@@ -79,18 +76,14 @@ function SomeTopLevelView() {
7976
8077
'use strict';
8178
82-
var _ExampleQuery;
79+
import _ExampleQuery from '../test/artifacts/ExampleQuery.graphql';
8380
function SomeTopLevelView() {
8481
const _graphql = 'unrelated';
8582
return (
8683
<View>
8784
<QueryRenderer
8885
environment={RelayEnvironment}
89-
query={
90-
_ExampleQuery !== void 0
91-
? _ExampleQuery
92-
: (_ExampleQuery = require('../test/artifacts/ExampleQuery.graphql'))
93-
}
86+
query={_ExampleQuery}
9487
variables={{
9588
id: '12345',
9689
}}
@@ -132,12 +125,9 @@ const testMutation = graphql\`
132125
133126
'use strict';
134127
135-
var _TestMutation;
128+
import _TestMutation from '../test/artifacts/TestMutation.graphql';
136129
const {graphql} = require('relay-runtime');
137-
const testMutation =
138-
_TestMutation !== void 0
139-
? _TestMutation
140-
: (_TestMutation = require('../test/artifacts/TestMutation.graphql'));
130+
const testMutation = _TestMutation;
141131
142132
`;
143133
@@ -170,12 +160,9 @@ const testQuery = graphql\`
170160
171161
'use strict';
172162
173-
var _TestQuery;
163+
import _TestQuery from '../test/artifacts/TestQuery.graphql';
174164
const {graphql} = require('relay-runtime');
175-
const testQuery =
176-
_TestQuery !== void 0
177-
? _TestQuery
178-
: (_TestQuery = require('../test/artifacts/TestQuery.graphql'));
165+
const testQuery = _TestQuery;
179166
180167
`;
181168

packages/babel-plugin-relay/__tests__/__snapshots__/BabelPluginRelay-modern-haste-test.js.snap

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ const testFragment = graphql\`
2929
3030
'use strict';
3131
32-
var _TestFragment;
32+
import _TestFragment from 'TestFragment.graphql';
3333
const {graphql} = require('relay-runtime');
34-
const testFragment =
35-
_TestFragment !== void 0
36-
? _TestFragment
37-
: (_TestFragment = require('TestFragment.graphql'));
34+
const testFragment = _TestFragment;
3835
3936
`;
4037

@@ -79,18 +76,14 @@ function SomeTopLevelView() {
7976
8077
'use strict';
8178
82-
var _ExampleQuery;
79+
import _ExampleQuery from 'ExampleQuery.graphql';
8380
function SomeTopLevelView() {
8481
const _graphql = 'unrelated';
8582
return (
8683
<View>
8784
<QueryRenderer
8885
environment={RelayEnvironment}
89-
query={
90-
_ExampleQuery !== void 0
91-
? _ExampleQuery
92-
: (_ExampleQuery = require('ExampleQuery.graphql'))
93-
}
86+
query={_ExampleQuery}
9487
variables={{
9588
id: '12345',
9689
}}
@@ -132,12 +125,9 @@ const testMutation = graphql\`
132125
133126
'use strict';
134127
135-
var _TestMutation;
128+
import _TestMutation from 'TestMutation.graphql';
136129
const {graphql} = require('relay-runtime');
137-
const testMutation =
138-
_TestMutation !== void 0
139-
? _TestMutation
140-
: (_TestMutation = require('TestMutation.graphql'));
130+
const testMutation = _TestMutation;
141131
142132
`;
143133
@@ -170,12 +160,9 @@ const testQuery = graphql\`
170160
171161
'use strict';
172162
173-
var _TestQuery;
163+
import _TestQuery from 'TestQuery.graphql';
174164
const {graphql} = require('relay-runtime');
175-
const testQuery =
176-
_TestQuery !== void 0
177-
? _TestQuery
178-
: (_TestQuery = require('TestQuery.graphql'));
165+
const testQuery = _TestQuery;
179166
180167
`;
181168

packages/babel-plugin-relay/__tests__/__snapshots__/BabelPluginRelay-modern-test.js.snap

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ const testFragment = graphql\`
2929
3030
'use strict';
3131
32-
var _TestFragment;
32+
import _TestFragment from './__generated__/TestFragment.graphql';
3333
const {graphql} = require('relay-runtime');
34-
const testFragment =
35-
_TestFragment !== void 0
36-
? _TestFragment
37-
: (_TestFragment = require('./__generated__/TestFragment.graphql'));
34+
const testFragment = _TestFragment;
3835
3936
`;
4037

@@ -79,18 +76,14 @@ function SomeTopLevelView() {
7976
8077
'use strict';
8178
82-
var _ExampleQuery;
79+
import _ExampleQuery from './__generated__/ExampleQuery.graphql';
8380
function SomeTopLevelView() {
8481
const _graphql = 'unrelated';
8582
return (
8683
<View>
8784
<QueryRenderer
8885
environment={RelayEnvironment}
89-
query={
90-
_ExampleQuery !== void 0
91-
? _ExampleQuery
92-
: (_ExampleQuery = require('./__generated__/ExampleQuery.graphql'))
93-
}
86+
query={_ExampleQuery}
9487
variables={{
9588
id: '12345',
9689
}}
@@ -132,12 +125,9 @@ const testMutation = graphql\`
132125
133126
'use strict';
134127
135-
var _TestMutation;
128+
import _TestMutation from './__generated__/TestMutation.graphql';
136129
const {graphql} = require('relay-runtime');
137-
const testMutation =
138-
_TestMutation !== void 0
139-
? _TestMutation
140-
: (_TestMutation = require('./__generated__/TestMutation.graphql'));
130+
const testMutation = _TestMutation;
141131
142132
`;
143133
@@ -170,12 +160,9 @@ const testQuery = graphql\`
170160
171161
'use strict';
172162
173-
var _TestQuery;
163+
import _TestQuery from './__generated__/TestQuery.graphql';
174164
const {graphql} = require('relay-runtime');
175-
const testQuery =
176-
_TestQuery !== void 0
177-
? _TestQuery
178-
: (_TestQuery = require('./__generated__/TestQuery.graphql'));
165+
const testQuery = _TestQuery;
179166
180167
`;
181168
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`\`development\` option tests the handling of file path 1`] = `
4-
"var _TestFrag;
5-
_TestFrag !== void 0
6-
? _TestFrag
7-
: ((_TestFrag = require('./test/artifacts/TestFrag.graphql')),
8-
_TestFrag.hash &&
9-
_TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
10-
console.error(
11-
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-compiler\` to update the generated files to receive the expected data.\\",
12-
),
13-
_TestFrag);
4+
"import _TestFrag from './test/artifacts/TestFrag.graphql';
5+
_TestFrag.hash &&
6+
_TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
7+
console.error(
8+
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-compiler\` to update the generated files to receive the expected data.\\",
9+
),
10+
_TestFrag;
1411
"
1512
`;
Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,42 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`\`development\` option does not test the hash when \`development\` is not set 1`] = `
4-
"var _TestFrag;
5-
_TestFrag !== void 0
6-
? _TestFrag
7-
: (_TestFrag = require('./__generated__/TestFrag.graphql'));
4+
"import _TestFrag from './__generated__/TestFrag.graphql';
5+
_TestFrag;
86
"
97
`;
108

119
exports[`\`development\` option tests the hash when \`development\` is set 1`] = `
12-
"var _TestFrag;
13-
_TestFrag !== void 0
14-
? _TestFrag
15-
: ((_TestFrag = require('./__generated__/TestFrag.graphql')),
16-
_TestFrag.hash &&
17-
_TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
18-
console.error(
19-
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-compiler\` to update the generated files to receive the expected data.\\",
20-
),
21-
_TestFrag);
10+
"import _TestFrag from './__generated__/TestFrag.graphql';
11+
_TestFrag.hash &&
12+
_TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
13+
console.error(
14+
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-compiler\` to update the generated files to receive the expected data.\\",
15+
),
16+
_TestFrag;
2217
"
2318
`;
2419

2520
exports[`\`development\` option tests the hash when \`isDevVariableName\` is set 1`] = `
26-
"var _TestFrag;
27-
_TestFrag !== void 0
28-
? _TestFrag
29-
: IS_DEV
30-
? ((_TestFrag = require('./__generated__/TestFrag.graphql')),
31-
_TestFrag.hash &&
21+
"import _TestFrag from './__generated__/TestFrag.graphql';
22+
IS_DEV
23+
? (_TestFrag.hash &&
3224
_TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
3325
console.error(
3426
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-compiler\` to update the generated files to receive the expected data.\\",
3527
),
3628
_TestFrag)
37-
: (_TestFrag = require('./__generated__/TestFrag.graphql'));
29+
: _TestFrag;
3830
"
3931
`;
4032

4133
exports[`\`development\` option uses a custom build command in message 1`] = `
42-
"var _TestFrag;
43-
_TestFrag !== void 0
44-
? _TestFrag
45-
: ((_TestFrag = require('./__generated__/TestFrag.graphql')),
46-
_TestFrag.hash &&
47-
_TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
48-
console.error(
49-
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-build\` to update the generated files to receive the expected data.\\",
50-
),
51-
_TestFrag);
34+
"import _TestFrag from './__generated__/TestFrag.graphql';
35+
_TestFrag.hash &&
36+
_TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
37+
console.error(
38+
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-build\` to update the generated files to receive the expected data.\\",
39+
),
40+
_TestFrag;
5241
"
5342
`;

packages/babel-plugin-relay/__tests__/__snapshots__/BabelPluginRelay.macro-test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const ViewerQuery = graphql\`
2222
2323
'use strict';
2424
25-
var _ViewerQuery;
25+
import _ViewerQuery from \\"./__generated__/ViewerQuery.graphql\\";
2626
const ProfilePic = require('ProfilePic');
27-
const ViewerQuery = _ViewerQuery !== void 0 ? _ViewerQuery : (_ViewerQuery = require(\\"./__generated__/ViewerQuery.graphql\\"), _ViewerQuery.hash && _ViewerQuery.hash !== \\"b046a97b7823510c05083ebb114377f4\\" && console.error(\\"The definition of 'ViewerQuery' appears to have changed. Run \`relay-compiler\` to update the generated files to receive the expected data.\\"), _ViewerQuery);
27+
const ViewerQuery = (_ViewerQuery.hash && _ViewerQuery.hash !== \\"b046a97b7823510c05083ebb114377f4\\" && console.error(\\"The definition of 'ViewerQuery' appears to have changed. Run \`relay-compiler\` to update the generated files to receive the expected data.\\"), _ViewerQuery);
2828
"
2929
`;

packages/babel-plugin-relay/compileGraphQLTag.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ function compileGraphQLTag(
6868
);
6969
}
7070

71-
const eagerEsModules = state.opts?.eagerEsModules ?? false;
71+
const eagerEsModules = state.opts?.eagerEsModules ?? true;
7272
const isHasteMode = state.opts?.jsModuleFormat === 'haste';
7373
const isDevVariable = state.opts?.isDevVariableName;
7474
const artifactDirectory = state.opts?.artifactDirectory;

scripts/jest/preprocessor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const babelOptions = getBabelOptions({
2020
env: 'test',
2121
autoImport: false,
2222
plugins: [
23-
'./dist/babel-plugin-relay',
23+
['./dist/babel-plugin-relay', {eagerEsModules: false}],
2424
'@babel/plugin-transform-flow-strip-types',
2525
'@babel/plugin-transform-runtime',
2626
'@babel/plugin-proposal-nullish-coalescing-operator',

0 commit comments

Comments
 (0)