@isograph/babel-plugin 0.0.0-main-72f66445 → 0.0.0-main-e970ef76

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.
Files changed (2) hide show
  1. package/compileTag.js +16 -10
  2. package/package.json +1 -1
package/compileTag.js CHANGED
@@ -17,11 +17,15 @@ function compileTag(t, path, config) {
17
17
  // This throws if the tag is invalid
18
18
  compileImportStatement(t, path, type, field, 'entrypoint', config);
19
19
  } else if (keyword === 'field') {
20
- if (
21
- t.isCallExpression(path.parentPath.node) &&
22
- path.parentPath.node.arguments.length === 1
23
- ) {
24
- path.parentPath.replaceWith(path.parentPath.node.arguments[0]);
20
+ if (t.isCallExpression(path.parentPath.node)) {
21
+ const firstArg = path.parentPath.node.arguments[0];
22
+ if (path.parentPath.node.arguments.length === 1 && firstArg != null) {
23
+ path.parentPath.replaceWith(firstArg);
24
+ } else {
25
+ throw new Error(
26
+ 'Invalid iso tag usage. The iso function should be passed at most one argument.',
27
+ );
28
+ }
25
29
  } else {
26
30
  path.replaceWith(
27
31
  t.arrowFunctionExpression([t.identifier('x')], t.identifier('x')),
@@ -45,26 +49,28 @@ const typeAndFieldRegex = new RegExp(
45
49
  * @param {babel.NodePath<babel.types.CallExpression>} path
46
50
  * */
47
51
  function getTypeAndField(path) {
48
- if (path.node.arguments.length !== 1) {
52
+ const firstArg = path.node.arguments[0];
53
+ if (path.node.arguments.length !== 1 || firstArg == null) {
49
54
  throw new Error(
50
55
  `BabelPluginIsograph: Iso invocation require one parameter, found ${path.node.arguments.length}`,
51
56
  );
52
57
  }
53
58
 
54
- if (path.node.arguments[0].type !== 'TemplateLiteral') {
59
+ if (firstArg.type !== 'TemplateLiteral') {
55
60
  throw new Error(
56
61
  'BabelPluginIsograph: Only template literals are allowed in iso fragments.',
57
62
  );
58
63
  }
59
64
 
60
- const quasis = path.node.arguments[0].quasis;
61
- if (quasis.length !== 1) {
65
+ const quasis = firstArg.quasis;
66
+ const firstQuasi = quasis[0];
67
+ if (quasis.length !== 1 || firstQuasi == null) {
62
68
  throw new Error(
63
69
  'BabelPluginIsograph: Substitutions are not allowed in iso fragments.',
64
70
  );
65
71
  }
66
72
 
67
- const content = quasis[0].value.raw;
73
+ const content = firstQuasi.value.raw;
68
74
  const typeAndField = typeAndFieldRegex.exec(content);
69
75
 
70
76
  const keyword = typeAndField?.[1];
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@isograph/babel-plugin",
3
3
  "description": "A Babel plugin for use with Isograph applications.",
4
4
  "homepage": "https://isograph.dev",
5
- "version": "0.0.0-main-72f66445",
5
+ "version": "0.0.0-main-e970ef76",
6
6
  "keywords": [
7
7
  "graphql",
8
8
  "isograph",