babel-plugin-relay 15.0.0 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel-plugin-relay.js +2 -2
- package/babel-plugin-relay.min.js +2 -2
- package/compileGraphQLTag.js.flow +18 -11
- package/index.js +1 -1
- package/lib/BabelPluginRelay.js +0 -21
- package/lib/BabelPluginRelay.macro.js +0 -11
- package/lib/compileGraphQLTag.js +9 -33
- package/lib/getValidGraphQLTag.js +0 -17
- package/macro.js +1 -1
- package/package.json +3 -2
package/babel-plugin-relay.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Relay
|
|
2
|
+
* Relay v16.0.0
|
|
3
3
|
*/
|
|
4
|
-
module.exports=function(e){var r={};function n(t){if(r[t])return r[t].exports;var i=r[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var i in e)n.d(t,i,function(r){return e[r]}.bind(null,i));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=1)}([function(e,r){e.exports=require("graphql")},function(e,r,n){"use strict";var t,i=(0,n(2).default)(n(3)),o=n(4),a=n(7),
|
|
4
|
+
module.exports=function(e){var r={};function n(t){if(r[t])return r[t].exports;var i=r[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var i in e)n.d(t,i,function(r){return e[r]}.bind(null,i));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=1)}([function(e,r){e.exports=require("graphql")},function(e,r,n){"use strict";var t,i=(0,n(2).default)(n(3)),o=n(4),a=n(7),l=n(8),s=l("relay",{searchPlaces:["relay.config.js","relay.config.json","package.json"],loaders:{".json":l.loadJson,".js":l.loadJs,noExt:l.loadYaml}}).searchSync();s&&(t=s.config),e.exports=function(e){var r=e.types;if(!r)throw new Error('BabelPluginRelay: Expected plugin context to include "types", but got:'+String(e));var n={TaggedTemplateExpression:function(e,n){var t=a(e);t&&o(r,e,n,t)}};return{visitor:{Program:function(e,r){e.traverse(n,(0,i.default)((0,i.default)({},r),{},{opts:(0,i.default)((0,i.default)({},t),r.opts)}))}}}}},function(e,r){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,r){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,r,n){"use strict";var t=n(5),i=n(0).print,o=n(6),a=o.dirname,l=o.join,s=o.relative,u=o.resolve;e.exports=function(e,r,n,o){var d,c,p,f,g,v,m;if(1!==o.definitions.length)throw new Error("BabelPluginRelay: Expected exactly one definition per graphql tag.");var x=o.definitions[0];if("FragmentDefinition"!==x.kind&&"OperationDefinition"!==x.kind)throw new Error("BabelPluginRelay: Expected a fragment, mutation, query, or subscription, got `"+x.kind+"`.");var h=null!==(d=null===(c=n.opts)||void 0===c?void 0:c.eagerEsModules)&&void 0!==d&&d,b="haste"===(null===(p=n.opts)||void 0===p?void 0:p.jsModuleFormat),y=null===(f=n.opts)||void 0===f?void 0:f.isDevVariableName;return function(e,r,n,o,d){var c=o.name&&o.name.value;if(!c)throw new Error("GraphQL operations and fragments must contain names");var p=c+".graphql",f=d.isHasteMode?p:d.artifactDirectory?function(e,r,n){if(null==e.file)throw new Error("Babel state is missing expected file name");var t=e.file.opts.filename,i=s(a(t),u(r));return(0!==i.length&&i.startsWith(".")?"":"./")+l(i,n)}(r,d.artifactDirectory,p):"./__generated__/"+p,g=t.createHash("md5").update(i(o),"utf8").digest("hex"),v=n.scope;for(;v.parent;)v=v.parent;var m=v.generateUidIdentifier(c),x=e.MemberExpression(e.cloneNode(m),e.Identifier("hash")),h=function(e,r,n){return e.callExpression(e.memberExpression(e.identifier("console"),e.identifier("error")),[e.stringLiteral("The definition of '".concat(r,"' appears to have changed. Run ")+"`"+n+"` to update the generated files to receive the expected data.")])}(e,c,d.buildCommand),b=e.LogicalExpression("&&",e.cloneNode(x),e.LogicalExpression("&&",e.BinaryExpression("!==",x,e.StringLiteral(g)),h));if(d.eagerEsModules){var y=e.ImportDeclaration([e.ImportDefaultSpecifier(m)],e.StringLiteral(f));n.findParent((function(e){return e.isProgram()})).unshiftContainer("body",y);var E,q=e.SequenceExpression([b,e.cloneNode(m)]);E=null!=d.isDevVariable?e.ConditionalExpression(e.Identifier(d.isDevVariable),q,e.cloneNode(m)):d.isDevelopment?q:e.cloneNode(m),n.replaceWith(E)}else{v.push({id:e.cloneNode(m)});var D,w=e.CallExpression(e.Identifier("require"),[e.StringLiteral(f)]),j=e.AssignmentExpression("=",e.cloneNode(m),w),N=e.SequenceExpression([j,b,e.cloneNode(m)]);D=null!=d.isDevVariable?e.ConditionalExpression(e.Identifier(d.isDevVariable),N,j):d.isDevelopment?N:j;var S=e.UnaryExpression("void",e.NumericLiteral(0));n.replaceWith(e.ConditionalExpression(e.BinaryExpression("!==",e.cloneNode(m),S),e.cloneNode(m),e.cloneNode(D)))}}(e,n,r,x,{artifactDirectory:null===(g=n.opts)||void 0===g?void 0:g.artifactDirectory,eagerEsModules:h,buildCommand:null!==(v=null===(m=n.opts)||void 0===m?void 0:m.codegenCommand)&&void 0!==v?v:"relay-compiler",isDevelopment:"production"!==(process.env.BABEL_ENV||"development"),isHasteMode:b,isDevVariable:y})}},function(e,r){e.exports=require("crypto")},function(e,r){e.exports=require("path")},function(e,r,n){"use strict";var t=n(0);e.exports=function(e){if(!e.get("tag").isIdentifier({name:"graphql"}))return null;var r=e.node.quasi.quasis;if(1!==r.length)throw new Error("BabelPluginRelay: Substitutions are not allowed in graphql fragments. Included fragments should be referenced as `...MyModule_propName`.");var n=r[0].value.raw,i=t.parse(n);if(0===i.definitions.length)throw new Error("BabelPluginRelay: Unexpected empty graphql tag.");return i}},function(e,r){e.exports=require("cosmiconfig")}]);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Relay
|
|
2
|
+
* Relay v16.0.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
5
5
|
*
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
module.exports=function(e){var r={};function n(t){if(r[t])return r[t].exports;var i=r[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var i in e)n.d(t,i,function(r){return e[r]}.bind(null,i));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=1)}([function(e,r){e.exports=require("graphql")},function(e,r,n){"use strict";var t,i=(0,n(2).default)(n(3)),o=n(4),a=n(7),
|
|
9
|
+
module.exports=function(e){var r={};function n(t){if(r[t])return r[t].exports;var i=r[t]={i:t,l:!1,exports:{}};return e[t].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=r,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,r){if(1&r&&(e=n(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(n.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var i in e)n.d(t,i,function(r){return e[r]}.bind(null,i));return t},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},n.p="",n(n.s=1)}([function(e,r){e.exports=require("graphql")},function(e,r,n){"use strict";var t,i=(0,n(2).default)(n(3)),o=n(4),a=n(7),l=n(8),s=l("relay",{searchPlaces:["relay.config.js","relay.config.json","package.json"],loaders:{".json":l.loadJson,".js":l.loadJs,noExt:l.loadYaml}}).searchSync();s&&(t=s.config),e.exports=function(e){var r=e.types;if(!r)throw new Error('BabelPluginRelay: Expected plugin context to include "types", but got:'+String(e));var n={TaggedTemplateExpression:function(e,n){var t=a(e);t&&o(r,e,n,t)}};return{visitor:{Program:function(e,r){e.traverse(n,(0,i.default)((0,i.default)({},r),{},{opts:(0,i.default)((0,i.default)({},t),r.opts)}))}}}}},function(e,r){e.exports=require("@babel/runtime/helpers/interopRequireDefault")},function(e,r){e.exports=require("@babel/runtime/helpers/objectSpread2")},function(e,r,n){"use strict";var t=n(5),i=n(0).print,o=n(6),a=o.dirname,l=o.join,s=o.relative,u=o.resolve;e.exports=function(e,r,n,o){var d,c,p,f,g,v,m;if(1!==o.definitions.length)throw new Error("BabelPluginRelay: Expected exactly one definition per graphql tag.");var x=o.definitions[0];if("FragmentDefinition"!==x.kind&&"OperationDefinition"!==x.kind)throw new Error("BabelPluginRelay: Expected a fragment, mutation, query, or subscription, got `"+x.kind+"`.");var h=null!==(d=null===(c=n.opts)||void 0===c?void 0:c.eagerEsModules)&&void 0!==d&&d,b="haste"===(null===(p=n.opts)||void 0===p?void 0:p.jsModuleFormat),y=null===(f=n.opts)||void 0===f?void 0:f.isDevVariableName;return function(e,r,n,o,d){var c=o.name&&o.name.value;if(!c)throw new Error("GraphQL operations and fragments must contain names");var p=c+".graphql",f=d.isHasteMode?p:d.artifactDirectory?function(e,r,n){if(null==e.file)throw new Error("Babel state is missing expected file name");var t=e.file.opts.filename,i=s(a(t),u(r));return(0!==i.length&&i.startsWith(".")?"":"./")+l(i,n)}(r,d.artifactDirectory,p):"./__generated__/"+p,g=t.createHash("md5").update(i(o),"utf8").digest("hex"),v=n.scope;for(;v.parent;)v=v.parent;var m=v.generateUidIdentifier(c),x=e.MemberExpression(e.cloneNode(m),e.Identifier("hash")),h=function(e,r,n){return e.callExpression(e.memberExpression(e.identifier("console"),e.identifier("error")),[e.stringLiteral("The definition of '".concat(r,"' appears to have changed. Run ")+"`"+n+"` to update the generated files to receive the expected data.")])}(e,c,d.buildCommand),b=e.LogicalExpression("&&",e.cloneNode(x),e.LogicalExpression("&&",e.BinaryExpression("!==",x,e.StringLiteral(g)),h));if(d.eagerEsModules){var y=e.ImportDeclaration([e.ImportDefaultSpecifier(m)],e.StringLiteral(f));n.findParent((function(e){return e.isProgram()})).unshiftContainer("body",y);var E,q=e.SequenceExpression([b,e.cloneNode(m)]);E=null!=d.isDevVariable?e.ConditionalExpression(e.Identifier(d.isDevVariable),q,e.cloneNode(m)):d.isDevelopment?q:e.cloneNode(m),n.replaceWith(E)}else{v.push({id:e.cloneNode(m)});var D,w=e.CallExpression(e.Identifier("require"),[e.StringLiteral(f)]),j=e.AssignmentExpression("=",e.cloneNode(m),w),N=e.SequenceExpression([j,b,e.cloneNode(m)]);D=null!=d.isDevVariable?e.ConditionalExpression(e.Identifier(d.isDevVariable),N,j):d.isDevelopment?N:j;var S=e.UnaryExpression("void",e.NumericLiteral(0));n.replaceWith(e.ConditionalExpression(e.BinaryExpression("!==",e.cloneNode(m),S),e.cloneNode(m),e.cloneNode(D)))}}(e,n,r,x,{artifactDirectory:null===(g=n.opts)||void 0===g?void 0:g.artifactDirectory,eagerEsModules:h,buildCommand:null!==(v=null===(m=n.opts)||void 0===m?void 0:m.codegenCommand)&&void 0!==v?v:"relay-compiler",isDevelopment:"production"!==(process.env.BABEL_ENV||"production"),isHasteMode:b,isDevVariable:y})}},function(e,r){e.exports=require("crypto")},function(e,r){e.exports=require("path")},function(e,r,n){"use strict";var t=n(0);e.exports=function(e){if(!e.get("tag").isIdentifier({name:"graphql"}))return null;var r=e.node.quasi.quasis;if(1!==r.length)throw new Error("BabelPluginRelay: Substitutions are not allowed in graphql fragments. Included fragments should be referenced as `...MyModule_propName`.");var n=r[0].value.raw,i=t.parse(n);if(0===i.definitions.length)throw new Error("BabelPluginRelay: Unexpected empty graphql tag.");return i}},function(e,r){e.exports=require("cosmiconfig")}]);
|
|
@@ -125,11 +125,11 @@ function createNode(
|
|
|
125
125
|
|
|
126
126
|
const id = topScope.generateUidIdentifier(definitionName);
|
|
127
127
|
|
|
128
|
-
const expHash = t.MemberExpression(id, t.Identifier('hash'));
|
|
128
|
+
const expHash = t.MemberExpression(t.cloneNode(id), t.Identifier('hash'));
|
|
129
129
|
const expWarn = warnNeedsRebuild(t, definitionName, options.buildCommand);
|
|
130
130
|
const expWarnIfOutdated = t.LogicalExpression(
|
|
131
131
|
'&&',
|
|
132
|
-
expHash,
|
|
132
|
+
t.cloneNode(expHash),
|
|
133
133
|
t.LogicalExpression(
|
|
134
134
|
'&&',
|
|
135
135
|
t.BinaryExpression('!==', expHash, t.StringLiteral(hash)),
|
|
@@ -145,34 +145,41 @@ function createNode(
|
|
|
145
145
|
const program = path.findParent(parent => parent.isProgram());
|
|
146
146
|
program.unshiftContainer('body', importDeclaration);
|
|
147
147
|
|
|
148
|
-
const expAssignAndCheck = t.SequenceExpression([
|
|
148
|
+
const expAssignAndCheck = t.SequenceExpression([
|
|
149
|
+
expWarnIfOutdated,
|
|
150
|
+
t.cloneNode(id),
|
|
151
|
+
]);
|
|
149
152
|
|
|
150
153
|
let expAssign;
|
|
151
154
|
if (options.isDevVariable != null) {
|
|
152
155
|
expAssign = t.ConditionalExpression(
|
|
153
156
|
t.Identifier(options.isDevVariable),
|
|
154
157
|
expAssignAndCheck,
|
|
155
|
-
id,
|
|
158
|
+
t.cloneNode(id),
|
|
156
159
|
);
|
|
157
160
|
} else if (options.isDevelopment) {
|
|
158
161
|
expAssign = expAssignAndCheck;
|
|
159
162
|
} else {
|
|
160
|
-
expAssign = id;
|
|
163
|
+
expAssign = t.cloneNode(id);
|
|
161
164
|
}
|
|
162
165
|
|
|
163
166
|
path.replaceWith(expAssign);
|
|
164
167
|
} else {
|
|
165
|
-
topScope.push({id});
|
|
168
|
+
topScope.push({id: t.cloneNode(id)});
|
|
166
169
|
|
|
167
170
|
const requireGraphQLModule = t.CallExpression(t.Identifier('require'), [
|
|
168
171
|
t.StringLiteral(requiredPath),
|
|
169
172
|
]);
|
|
170
173
|
|
|
171
|
-
const expAssignProd = t.AssignmentExpression(
|
|
174
|
+
const expAssignProd = t.AssignmentExpression(
|
|
175
|
+
'=',
|
|
176
|
+
t.cloneNode(id),
|
|
177
|
+
requireGraphQLModule,
|
|
178
|
+
);
|
|
172
179
|
const expAssignAndCheck = t.SequenceExpression([
|
|
173
180
|
expAssignProd,
|
|
174
181
|
expWarnIfOutdated,
|
|
175
|
-
id,
|
|
182
|
+
t.cloneNode(id),
|
|
176
183
|
]);
|
|
177
184
|
|
|
178
185
|
let expAssign;
|
|
@@ -191,9 +198,9 @@ function createNode(
|
|
|
191
198
|
const expVoid0 = t.UnaryExpression('void', t.NumericLiteral(0));
|
|
192
199
|
path.replaceWith(
|
|
193
200
|
t.ConditionalExpression(
|
|
194
|
-
t.BinaryExpression('!==', id, expVoid0),
|
|
195
|
-
id,
|
|
196
|
-
expAssign,
|
|
201
|
+
t.BinaryExpression('!==', t.cloneNode(id), expVoid0),
|
|
202
|
+
t.cloneNode(id),
|
|
203
|
+
t.cloneNode(expAssign),
|
|
197
204
|
),
|
|
198
205
|
);
|
|
199
206
|
}
|
package/index.js
CHANGED
package/lib/BabelPluginRelay.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall relay
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
|
@@ -29,15 +18,6 @@ var result = configExplorer.searchSync();
|
|
|
29
18
|
if (result) {
|
|
30
19
|
RelayConfig = result.config;
|
|
31
20
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Using babel-plugin-relay with only the modern runtime?
|
|
34
|
-
*
|
|
35
|
-
* {
|
|
36
|
-
* plugins: [
|
|
37
|
-
* "relay"
|
|
38
|
-
* ]
|
|
39
|
-
* }
|
|
40
|
-
*/
|
|
41
21
|
module.exports = function BabelPluginRelay(context) {
|
|
42
22
|
var t = context.types;
|
|
43
23
|
if (!t) {
|
|
@@ -45,7 +25,6 @@ module.exports = function BabelPluginRelay(context) {
|
|
|
45
25
|
}
|
|
46
26
|
var visitor = {
|
|
47
27
|
TaggedTemplateExpression: function TaggedTemplateExpression(path, state) {
|
|
48
|
-
// Convert graphql`` literals
|
|
49
28
|
var ast = getValidGraphQLTag(path);
|
|
50
29
|
if (ast) {
|
|
51
30
|
compileGraphQLTag(t, path, state, ast);
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall relay
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var compileGraphQLTag = require('./compileGraphQLTag');
|
package/lib/compileGraphQLTag.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall relay
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var crypto = require('crypto');
|
|
@@ -20,11 +9,6 @@ var _require2 = require('path'),
|
|
|
20
9
|
relativePath = _require2.relative,
|
|
21
10
|
resolvePath = _require2.resolve;
|
|
22
11
|
var GENERATED = './__generated__/';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Given a graphql`` tagged template literal, replace it with the appropriate
|
|
26
|
-
* runtime artifact.
|
|
27
|
-
*/
|
|
28
12
|
function compileGraphQLTag(t, path, state, ast) {
|
|
29
13
|
var _state$opts$eagerEsMo, _state$opts, _state$opts2, _state$opts3, _state$opts4, _state$opts$codegenCo, _state$opts5;
|
|
30
14
|
if (ast.definitions.length !== 1) {
|
|
@@ -39,7 +23,6 @@ function compileGraphQLTag(t, path, state, ast) {
|
|
|
39
23
|
var isDevVariable = (_state$opts3 = state.opts) === null || _state$opts3 === void 0 ? void 0 : _state$opts3.isDevVariableName;
|
|
40
24
|
var artifactDirectory = (_state$opts4 = state.opts) === null || _state$opts4 === void 0 ? void 0 : _state$opts4.artifactDirectory;
|
|
41
25
|
var buildCommand = (_state$opts$codegenCo = (_state$opts5 = state.opts) === null || _state$opts5 === void 0 ? void 0 : _state$opts5.codegenCommand) !== null && _state$opts$codegenCo !== void 0 ? _state$opts$codegenCo : 'relay-compiler';
|
|
42
|
-
// Fallback is 'true'
|
|
43
26
|
var isDevelopment = (process.env.BABEL_ENV || process.env.NODE_ENV) !== 'production';
|
|
44
27
|
return createNode(t, state, path, definition, {
|
|
45
28
|
artifactDirectory: artifactDirectory,
|
|
@@ -50,13 +33,6 @@ function compileGraphQLTag(t, path, state, ast) {
|
|
|
50
33
|
isDevVariable: isDevVariable
|
|
51
34
|
});
|
|
52
35
|
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The Relay compiler generates separate modules that contain the compiled code.
|
|
56
|
-
* Here we generate:
|
|
57
|
-
* - a memoized `require` call for that generated code
|
|
58
|
-
* - for development mode, runtime validation that the artifacts are up to date
|
|
59
|
-
*/
|
|
60
36
|
function createNode(t, state, path, graphqlDefinition, options) {
|
|
61
37
|
var definitionName = graphqlDefinition.name && graphqlDefinition.name.value;
|
|
62
38
|
if (!definitionName) {
|
|
@@ -70,32 +46,32 @@ function createNode(t, state, path, graphqlDefinition, options) {
|
|
|
70
46
|
topScope = topScope.parent;
|
|
71
47
|
}
|
|
72
48
|
var id = topScope.generateUidIdentifier(definitionName);
|
|
73
|
-
var expHash = t.MemberExpression(id, t.Identifier('hash'));
|
|
49
|
+
var expHash = t.MemberExpression(t.cloneNode(id), t.Identifier('hash'));
|
|
74
50
|
var expWarn = warnNeedsRebuild(t, definitionName, options.buildCommand);
|
|
75
|
-
var expWarnIfOutdated = t.LogicalExpression('&&', expHash, t.LogicalExpression('&&', t.BinaryExpression('!==', expHash, t.StringLiteral(hash)), expWarn));
|
|
51
|
+
var expWarnIfOutdated = t.LogicalExpression('&&', t.cloneNode(expHash), t.LogicalExpression('&&', t.BinaryExpression('!==', expHash, t.StringLiteral(hash)), expWarn));
|
|
76
52
|
if (options.eagerEsModules) {
|
|
77
53
|
var importDeclaration = t.ImportDeclaration([t.ImportDefaultSpecifier(id)], t.StringLiteral(requiredPath));
|
|
78
54
|
var program = path.findParent(function (parent) {
|
|
79
55
|
return parent.isProgram();
|
|
80
56
|
});
|
|
81
57
|
program.unshiftContainer('body', importDeclaration);
|
|
82
|
-
var expAssignAndCheck = t.SequenceExpression([expWarnIfOutdated, id]);
|
|
58
|
+
var expAssignAndCheck = t.SequenceExpression([expWarnIfOutdated, t.cloneNode(id)]);
|
|
83
59
|
var expAssign;
|
|
84
60
|
if (options.isDevVariable != null) {
|
|
85
|
-
expAssign = t.ConditionalExpression(t.Identifier(options.isDevVariable), expAssignAndCheck, id);
|
|
61
|
+
expAssign = t.ConditionalExpression(t.Identifier(options.isDevVariable), expAssignAndCheck, t.cloneNode(id));
|
|
86
62
|
} else if (options.isDevelopment) {
|
|
87
63
|
expAssign = expAssignAndCheck;
|
|
88
64
|
} else {
|
|
89
|
-
expAssign = id;
|
|
65
|
+
expAssign = t.cloneNode(id);
|
|
90
66
|
}
|
|
91
67
|
path.replaceWith(expAssign);
|
|
92
68
|
} else {
|
|
93
69
|
topScope.push({
|
|
94
|
-
id: id
|
|
70
|
+
id: t.cloneNode(id)
|
|
95
71
|
});
|
|
96
72
|
var requireGraphQLModule = t.CallExpression(t.Identifier('require'), [t.StringLiteral(requiredPath)]);
|
|
97
|
-
var expAssignProd = t.AssignmentExpression('=', id, requireGraphQLModule);
|
|
98
|
-
var _expAssignAndCheck = t.SequenceExpression([expAssignProd, expWarnIfOutdated, id]);
|
|
73
|
+
var expAssignProd = t.AssignmentExpression('=', t.cloneNode(id), requireGraphQLModule);
|
|
74
|
+
var _expAssignAndCheck = t.SequenceExpression([expAssignProd, expWarnIfOutdated, t.cloneNode(id)]);
|
|
99
75
|
var _expAssign;
|
|
100
76
|
if (options.isDevVariable != null) {
|
|
101
77
|
_expAssign = t.ConditionalExpression(t.Identifier(options.isDevVariable), _expAssignAndCheck, expAssignProd);
|
|
@@ -105,7 +81,7 @@ function createNode(t, state, path, graphqlDefinition, options) {
|
|
|
105
81
|
_expAssign = expAssignProd;
|
|
106
82
|
}
|
|
107
83
|
var expVoid0 = t.UnaryExpression('void', t.NumericLiteral(0));
|
|
108
|
-
path.replaceWith(t.ConditionalExpression(t.BinaryExpression('!==', id, expVoid0), id, _expAssign));
|
|
84
|
+
path.replaceWith(t.ConditionalExpression(t.BinaryExpression('!==', t.cloneNode(id), expVoid0), t.cloneNode(id), t.cloneNode(_expAssign)));
|
|
109
85
|
}
|
|
110
86
|
}
|
|
111
87
|
function warnNeedsRebuild(t, definitionName, buildCommand) {
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @format
|
|
9
|
-
* @oncall relay
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
1
|
'use strict';
|
|
13
2
|
|
|
14
3
|
var GraphQL = require('graphql');
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Given a babel AST path to a tagged template literal, return an AST if it is
|
|
18
|
-
* a graphql literal being used in a valid way.
|
|
19
|
-
* If it is some other type of template literal then return nothing.
|
|
20
|
-
*/
|
|
21
4
|
function getValidGraphQLTag(path) {
|
|
22
5
|
var tag = path.get('tag');
|
|
23
6
|
if (!tag.isIdentifier({
|
package/macro.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-relay",
|
|
3
3
|
"description": "A Babel Plugin for use with Relay applications.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "16.0.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"relay",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@babel/core": "^7.20.0",
|
|
26
|
-
"prettier": "2.
|
|
26
|
+
"prettier": "2.8.8",
|
|
27
|
+
"prettier-plugin-hermes-parser": "0.17.0"
|
|
27
28
|
}
|
|
28
29
|
}
|