Skip to content

Commit

Permalink
Babel plugin no longer produces thunks
Browse files Browse the repository at this point in the history
Summary:
The babel plugin used to produce thunks to require the generated files. This was useful during the migration period where compat mode would generate classic and modern ASTs to avoid instantiating both versions of the AST.

Now that everything is in the new style, no longer generating the closure should be slightly faster and importantly removes the risk of that closure to capture variables and prevent garbage collection of some values.

Reviewed By: alunyov

Differential Revision: D18694202

fbshipit-source-id: 5fcbeb8c6d695b2ae403596a1fae1b24db207571
  • Loading branch information
kassens authored and facebook-github-bot committed Dec 2, 2019
1 parent c4f4faa commit 490c89d
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ const testFragment = graphql\`
*/
'use strict';
var _TestFragment;
const {graphql} = require('relay-runtime');
const testFragment = function() {
return require('../test/artifacts/TestFragment.graphql');
};
const testFragment =
_TestFragment !== void 0
? _TestFragment
: (_TestFragment = require('../test/artifacts/TestFragment.graphql'));
`;

Expand Down Expand Up @@ -76,7 +79,7 @@ function SomeTopLevelView() {
*/
'use strict';
var _graphql2;
var _ExampleQuery;
function SomeTopLevelView() {
const _graphql = 'unrelated';
Expand All @@ -85,10 +88,9 @@ function SomeTopLevelView() {
<QueryRenderer
environment={RelayEnvironment}
query={
_graphql2 ||
(_graphql2 = function() {
return require('../test/artifacts/ExampleQuery.graphql');
})
_ExampleQuery !== void 0
? _ExampleQuery
: (_ExampleQuery = require('../test/artifacts/ExampleQuery.graphql'))
}
variables={{
id: '12345',
Expand Down Expand Up @@ -130,11 +132,14 @@ const testMutation = graphql\`
*/
'use strict';
var _TestMutation;
const {graphql} = require('relay-runtime');
const testMutation = function() {
return require('../test/artifacts/TestMutation.graphql');
};
const testMutation =
_TestMutation !== void 0
? _TestMutation
: (_TestMutation = require('../test/artifacts/TestMutation.graphql'));
`;
Expand Down Expand Up @@ -166,11 +171,14 @@ const testQuery = graphql\`
*/
'use strict';
var _TestQuery;
const {graphql} = require('relay-runtime');
const testQuery = function() {
return require('../test/artifacts/TestQuery.graphql');
};
const testQuery =
_TestQuery !== void 0
? _TestQuery
: (_TestQuery = require('../test/artifacts/TestQuery.graphql'));
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ const testFragment = graphql\`
*/
'use strict';
var _TestFragment;
const {graphql} = require('relay-runtime');
const testFragment = function() {
return require('TestFragment.graphql');
};
const testFragment =
_TestFragment !== void 0
? _TestFragment
: (_TestFragment = require('TestFragment.graphql'));
`;

Expand Down Expand Up @@ -76,7 +79,7 @@ function SomeTopLevelView() {
*/
'use strict';
var _graphql2;
var _ExampleQuery;
function SomeTopLevelView() {
const _graphql = 'unrelated';
Expand All @@ -85,10 +88,9 @@ function SomeTopLevelView() {
<QueryRenderer
environment={RelayEnvironment}
query={
_graphql2 ||
(_graphql2 = function() {
return require('ExampleQuery.graphql');
})
_ExampleQuery !== void 0
? _ExampleQuery
: (_ExampleQuery = require('ExampleQuery.graphql'))
}
variables={{
id: '12345',
Expand Down Expand Up @@ -130,11 +132,14 @@ const testMutation = graphql\`
*/
'use strict';
var _TestMutation;
const {graphql} = require('relay-runtime');
const testMutation = function() {
return require('TestMutation.graphql');
};
const testMutation =
_TestMutation !== void 0
? _TestMutation
: (_TestMutation = require('TestMutation.graphql'));
`;
Expand Down Expand Up @@ -166,11 +171,14 @@ const testQuery = graphql\`
*/
'use strict';
var _TestQuery;
const {graphql} = require('relay-runtime');
const testQuery = function() {
return require('TestQuery.graphql');
};
const testQuery =
_TestQuery !== void 0
? _TestQuery
: (_TestQuery = require('TestQuery.graphql'));
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ const testFragment = graphql\`
*/
'use strict';
var _TestFragment;
const {graphql} = require('relay-runtime');
const testFragment = function() {
return require('./__generated__/TestFragment.graphql');
};
const testFragment =
_TestFragment !== void 0
? _TestFragment
: (_TestFragment = require('./__generated__/TestFragment.graphql'));
`;

Expand Down Expand Up @@ -76,7 +79,7 @@ function SomeTopLevelView() {
*/
'use strict';
var _graphql2;
var _ExampleQuery;
function SomeTopLevelView() {
const _graphql = 'unrelated';
Expand All @@ -85,10 +88,9 @@ function SomeTopLevelView() {
<QueryRenderer
environment={RelayEnvironment}
query={
_graphql2 ||
(_graphql2 = function() {
return require('./__generated__/ExampleQuery.graphql');
})
_ExampleQuery !== void 0
? _ExampleQuery
: (_ExampleQuery = require('./__generated__/ExampleQuery.graphql'))
}
variables={{
id: '12345',
Expand Down Expand Up @@ -130,11 +132,14 @@ const testMutation = graphql\`
*/
'use strict';
var _TestMutation;
const {graphql} = require('relay-runtime');
const testMutation = function() {
return require('./__generated__/TestMutation.graphql');
};
const testMutation =
_TestMutation !== void 0
? _TestMutation
: (_TestMutation = require('./__generated__/TestMutation.graphql'));
`;
Expand Down Expand Up @@ -166,11 +171,14 @@ const testQuery = graphql\`
*/
'use strict';
var _TestQuery;
const {graphql} = require('relay-runtime');
const testQuery = function() {
return require('./__generated__/TestQuery.graphql');
};
const testQuery =
_TestQuery !== void 0
? _TestQuery
: (_TestQuery = require('./__generated__/TestQuery.graphql'));
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`\`development\` option does not test the hash when \`development\` is not set 1`] = `
"(function() {
return require('./__generated__/TestFrag.graphql');
});
"var _TestFrag;
_TestFrag !== void 0
? _TestFrag
: (_TestFrag = require('./__generated__/TestFrag.graphql'));
"
`;

exports[`\`development\` option tests the hash when \`development\` is set 1`] = `
"(function() {
const node = require('./__generated__/TestFrag.graphql');
if (node.hash && node.hash !== '0bb6b7b29bc3e910921551c4ff5b6757') {
console.error(
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-compiler\` to update the generated files to receive the expected data.\\",
);
}
"var _TestFrag;
return require('./__generated__/TestFrag.graphql');
});
_TestFrag !== void 0
? _TestFrag
: ((_TestFrag = require('./__generated__/TestFrag.graphql')),
_TestFrag.hash &&
_TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
console.error(
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-compiler\` to update the generated files to receive the expected data.\\",
),
_TestFrag);
"
`;

exports[`\`development\` option tests the hash when \`isDevVariable\` is set 1`] = `
"(function() {
if (IS_DEV) {
const node = require('./__generated__/TestFrag.graphql');
if (node.hash && node.hash !== '0bb6b7b29bc3e910921551c4ff5b6757') {
"var _TestFrag;
_TestFrag !== void 0
? _TestFrag
: IS_DEV
? ((_TestFrag = require('./__generated__/TestFrag.graphql')),
_TestFrag.hash &&
_TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
console.error(
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-compiler\` to update the generated files to receive the expected data.\\",
);
}
}
return require('./__generated__/TestFrag.graphql');
});
),
_TestFrag)
: (_TestFrag = require('./__generated__/TestFrag.graphql'));
"
`;

exports[`\`development\` option uses a custom build command in message 1`] = `
"(function() {
const node = require('./__generated__/TestFrag.graphql');
"var _TestFrag;
if (node.hash && node.hash !== '0bb6b7b29bc3e910921551c4ff5b6757') {
console.error(
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-build\` to update the generated files to receive the expected data.\\",
);
}
return require('./__generated__/TestFrag.graphql');
});
_TestFrag !== void 0
? _TestFrag
: ((_TestFrag = require('./__generated__/TestFrag.graphql')),
_TestFrag.hash &&
_TestFrag.hash !== '0bb6b7b29bc3e910921551c4ff5b6757' &&
console.error(
\\"The definition of 'TestFrag' appears to have changed. Run \`relay-build\` to update the generated files to receive the expected data.\\",
),
_TestFrag);
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ const ViewerQuery = graphql\`
'use strict';
const ProfilePic = require('ProfilePic');
const ViewerQuery = function () {
const node = require(\\"./__generated__/ViewerQuery.graphql\\");
var _ViewerQuery;
if (node.hash && node.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.\\");
}
const ProfilePic = require('ProfilePic');
return require(\\"./__generated__/ViewerQuery.graphql\\");
};
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);
"
`;
Loading

0 comments on commit 490c89d

Please sign in to comment.