@next-core/cook 1.6.77 → 1.6.79

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 (55) hide show
  1. package/dist/cjs/AnalysisContext.js +2 -11
  2. package/dist/cjs/AnalysisContext.js.map +1 -1
  3. package/dist/cjs/ExecutionContext.js +11 -37
  4. package/dist/cjs/ExecutionContext.js.map +1 -1
  5. package/dist/cjs/context-free.js +30 -71
  6. package/dist/cjs/context-free.js.map +1 -1
  7. package/dist/cjs/cook.js +147 -386
  8. package/dist/cjs/cook.js.map +1 -1
  9. package/dist/cjs/hasOwnProperty.js +0 -1
  10. package/dist/cjs/hasOwnProperty.js.map +1 -1
  11. package/dist/cjs/index.js +0 -14
  12. package/dist/cjs/index.js.map +1 -1
  13. package/dist/cjs/interfaces.js.map +1 -1
  14. package/dist/cjs/lint.js +0 -21
  15. package/dist/cjs/lint.js.map +1 -1
  16. package/dist/cjs/parse.js +0 -8
  17. package/dist/cjs/parse.js.map +1 -1
  18. package/dist/cjs/precook.js +6 -74
  19. package/dist/cjs/precook.js.map +1 -1
  20. package/dist/cjs/precookFunction.js +0 -3
  21. package/dist/cjs/precookFunction.js.map +1 -1
  22. package/dist/cjs/preevaluate.js +2 -6
  23. package/dist/cjs/preevaluate.js.map +1 -1
  24. package/dist/cjs/sanitize.js +9 -13
  25. package/dist/cjs/sanitize.js.map +1 -1
  26. package/dist/cjs/traverse.js +0 -32
  27. package/dist/cjs/traverse.js.map +1 -1
  28. package/dist/esm/AnalysisContext.js +2 -8
  29. package/dist/esm/AnalysisContext.js.map +1 -1
  30. package/dist/esm/ExecutionContext.js +11 -30
  31. package/dist/esm/ExecutionContext.js.map +1 -1
  32. package/dist/esm/context-free.js +32 -53
  33. package/dist/esm/context-free.js.map +1 -1
  34. package/dist/esm/cook.js +145 -411
  35. package/dist/esm/cook.js.map +1 -1
  36. package/dist/esm/hasOwnProperty.js.map +1 -1
  37. package/dist/esm/index.js.map +1 -1
  38. package/dist/esm/interfaces.js.map +1 -1
  39. package/dist/esm/lint.js +0 -19
  40. package/dist/esm/lint.js.map +1 -1
  41. package/dist/esm/parse.js +0 -6
  42. package/dist/esm/parse.js.map +1 -1
  43. package/dist/esm/precook.js +4 -82
  44. package/dist/esm/precook.js.map +1 -1
  45. package/dist/esm/precookFunction.js +4 -5
  46. package/dist/esm/precookFunction.js.map +1 -1
  47. package/dist/esm/preevaluate.js.map +1 -1
  48. package/dist/esm/sanitize.js +9 -9
  49. package/dist/esm/sanitize.js.map +1 -1
  50. package/dist/esm/traverse.js +0 -29
  51. package/dist/esm/traverse.js.map +1 -1
  52. package/dist/types/interfaces.d.ts +2 -0
  53. package/dist/types/lint.d.ts +3 -4
  54. package/dist/types/parse.d.ts +3 -3
  55. package/package.json +6 -6
package/dist/esm/lint.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import { parseForAnalysis } from "./parse";
2
2
  import { precook } from "./precook";
3
-
4
3
  /** For next-core internal or devtools usage only. */
5
4
  export function lint(source) {
6
5
  var {
@@ -11,15 +10,12 @@ export function lint(source) {
11
10
  var file = typeof source === "string" ? parseForAnalysis(source, {
12
11
  typescript
13
12
  }) : source;
14
-
15
13
  if (!file) {
16
14
  // Return no errors if parse failed.
17
15
  return errors;
18
16
  }
19
-
20
17
  var body = file.program.body;
21
18
  var jsNodes = typescript ? [] : body;
22
-
23
19
  if (typescript) {
24
20
  for (var node of body) {
25
21
  if (node.type.startsWith("TS")) {
@@ -35,12 +31,9 @@ export function lint(source) {
35
31
  }
36
32
  }
37
33
  }
38
-
39
34
  var func;
40
-
41
35
  for (var _node of jsNodes) {
42
36
  var isFunctionDeclaration = _node.type === "FunctionDeclaration";
43
-
44
37
  if (isFunctionDeclaration && !func) {
45
38
  func = _node;
46
39
  } else {
@@ -51,7 +44,6 @@ export function lint(source) {
51
44
  });
52
45
  }
53
46
  }
54
-
55
47
  if (!func) {
56
48
  errors.unshift({
57
49
  type: "SyntaxError",
@@ -82,9 +74,7 @@ export function lint(source) {
82
74
  loc: node.loc
83
75
  });
84
76
  }
85
-
86
77
  break;
87
-
88
78
  case "Literal":
89
79
  if (node.regex) {
90
80
  if (node.value === null) {
@@ -101,9 +91,7 @@ export function lint(source) {
101
91
  });
102
92
  }
103
93
  }
104
-
105
94
  break;
106
-
107
95
  case "ObjectExpression":
108
96
  for (var prop of node.properties) {
109
97
  if (prop.type === "Property") {
@@ -122,9 +110,7 @@ export function lint(source) {
122
110
  }
123
111
  }
124
112
  }
125
-
126
113
  break;
127
-
128
114
  case "VariableDeclaration":
129
115
  if (node.kind === "var" && rules !== null && rules !== void 0 && rules.noVar) {
130
116
  errors.push({
@@ -140,11 +126,9 @@ export function lint(source) {
140
126
  }
141
127
  });
142
128
  }
143
-
144
129
  break;
145
130
  }
146
131
  },
147
-
148
132
  beforeVisitGlobal(node) {
149
133
  if (node.name === "arguments") {
150
134
  errors.push({
@@ -154,7 +138,6 @@ export function lint(source) {
154
138
  });
155
139
  }
156
140
  },
157
-
158
141
  beforeVisitUnknown(node) {
159
142
  errors.push({
160
143
  type: "SyntaxError",
@@ -163,11 +146,9 @@ export function lint(source) {
163
146
  });
164
147
  return true;
165
148
  }
166
-
167
149
  }
168
150
  });
169
151
  }
170
-
171
152
  return errors;
172
153
  }
173
154
  //# sourceMappingURL=lint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lint.js","names":["parseForAnalysis","precook","lint","source","typescript","rules","errors","file","body","program","jsNodes","node","type","startsWith","test","push","message","loc","func","isFunctionDeclaration","unshift","start","line","column","end","hooks","beforeVisit","async","generator","regex","value","flags","includes","prop","properties","kind","computed","key","name","noVar","beforeVisitGlobal","beforeVisitUnknown"],"sources":["../../src/lint.ts"],"sourcesContent":["import { ParseResult } from \"@babel/parser\";\nimport {\n File,\n FunctionDeclaration,\n SourceLocation,\n Statement,\n} from \"@babel/types\";\nimport { CookRules } from \"./interfaces\";\nimport { parseForAnalysis } from \"./parse\";\nimport { precook } from \"./precook\";\n\nexport interface LintOptions {\n typescript?: boolean;\n rules?: CookRules;\n}\n\nexport interface LintError {\n type: \"SyntaxError\" | \"TypeError\";\n message: string;\n loc: SourceLocation;\n}\n\n/** For next-core internal or devtools usage only. */\nexport function lint(\n source: string | ParseResult<File>,\n { typescript, rules }: LintOptions = {}\n): LintError[] {\n const errors: LintError[] = [];\n const file =\n typeof source === \"string\"\n ? parseForAnalysis(source, { typescript })\n : source;\n if (!file) {\n // Return no errors if parse failed.\n return errors;\n }\n const body = file.program.body;\n const jsNodes: Statement[] = typescript ? [] : body;\n if (typescript) {\n for (const node of body) {\n if (node.type.startsWith(\"TS\")) {\n if (/Enum|Import|Export/.test(node.type)) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported TypeScript syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n }\n } else {\n jsNodes.push(node);\n }\n }\n }\n let func: FunctionDeclaration;\n for (const node of jsNodes) {\n const isFunctionDeclaration = node.type === \"FunctionDeclaration\";\n if (isFunctionDeclaration && !func) {\n func = node;\n } else {\n errors.push({\n type: \"SyntaxError\",\n message: isFunctionDeclaration\n ? \"Expect a single function declaration\"\n : `\\`${node.type}\\` is not allowed in top level`,\n loc: node.loc,\n });\n }\n }\n if (!func) {\n errors.unshift({\n type: \"SyntaxError\",\n message: \"Function declaration not found\",\n loc: {\n start: { line: 1, column: 0 },\n end: { line: 1, column: 0 },\n },\n });\n } else {\n precook(func, {\n hooks: {\n beforeVisit(node) {\n switch (node.type) {\n case \"ArrowFunctionExpression\":\n case \"FunctionDeclaration\":\n case \"FunctionExpression\":\n if (node.async || node.generator) {\n errors.push({\n type: \"SyntaxError\",\n message: `${\n node.async ? \"Async\" : \"Generator\"\n } function is not allowed`,\n loc: node.loc,\n });\n }\n break;\n case \"Literal\":\n if (node.regex) {\n if (node.value === null) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Invalid regular expression\",\n loc: node.loc,\n });\n } else if (node.regex.flags.includes(\"u\")) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported unicode flag in regular expression\",\n loc: node.loc,\n });\n }\n }\n break;\n case \"ObjectExpression\":\n for (const prop of node.properties) {\n if (prop.type === \"Property\") {\n if (prop.kind !== \"init\") {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported object getter/setter property\",\n loc: prop.loc,\n });\n } else if (\n !prop.computed &&\n prop.key.type === \"Identifier\" &&\n prop.key.name === \"__proto__\"\n ) {\n errors.push({\n type: \"TypeError\",\n message: \"Setting '__proto__' property is not allowed\",\n loc: prop.key.loc,\n });\n }\n }\n }\n break;\n case \"VariableDeclaration\":\n if (node.kind === \"var\" && rules?.noVar) {\n errors.push({\n type: \"SyntaxError\",\n message:\n \"Var declaration is not recommended, use `let` or `const` instead\",\n loc: {\n start: node.loc.start,\n end: {\n line: node.loc.start.line,\n // Only decorate the \"var\".\n column: node.loc.start.column + 3,\n },\n },\n });\n }\n break;\n }\n },\n beforeVisitGlobal(node) {\n if (node.name === \"arguments\") {\n errors.push({\n type: \"SyntaxError\",\n message: \"Use the rest parameters instead of 'arguments'\",\n loc: node.loc,\n });\n }\n },\n beforeVisitUnknown(node) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n return true;\n },\n },\n });\n }\n return errors;\n}\n"],"mappings":"AAQA,SAASA,gBAAT,QAAiC,SAAjC;AACA,SAASC,OAAT,QAAwB,WAAxB;;AAaA;AACA,OAAO,SAASC,IAAT,CACLC,MADK,EAGQ;EAAA,IADb;IAAEC,UAAF;IAAcC;EAAd,CACa,uEADwB,EACxB;EACb,IAAMC,MAAmB,GAAG,EAA5B;EACA,IAAMC,IAAI,GACR,OAAOJ,MAAP,KAAkB,QAAlB,GACIH,gBAAgB,CAACG,MAAD,EAAS;IAAEC;EAAF,CAAT,CADpB,GAEID,MAHN;;EAIA,IAAI,CAACI,IAAL,EAAW;IACT;IACA,OAAOD,MAAP;EACD;;EACD,IAAME,IAAI,GAAGD,IAAI,CAAC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AACC,IAAhC,MAFG;YAGVK,GAAG,EAAEN,IAAI,CAACM;UAHA,CAAZ;UAKA,OAAO,IAAP;QACD;;MA3FI;IADK,CAAP,CAAP;EA+FD;;EACD,OAAOX,MAAP;AACD"}
1
+ {"version":3,"file":"lint.js","names":["parseForAnalysis","precook","lint","source","typescript","rules","errors","file","body","program","jsNodes","node","type","startsWith","test","push","message","loc","func","isFunctionDeclaration","unshift","start","line","column","end","hooks","beforeVisit","async","generator","regex","value","flags","includes","prop","properties","kind","computed","key","name","noVar","beforeVisitGlobal","beforeVisitUnknown"],"sources":["../../src/lint.ts"],"sourcesContent":["import {\n type FunctionDeclaration,\n SourceLocation,\n Statement,\n} from \"@babel/types\";\nimport type { CookRules, ParseResultOfFile } from \"./interfaces\";\nimport { parseForAnalysis } from \"./parse\";\nimport { precook } from \"./precook\";\n\nexport interface LintOptions {\n typescript?: boolean;\n rules?: CookRules;\n}\n\nexport interface LintError {\n type: \"SyntaxError\" | \"TypeError\";\n message: string;\n loc: SourceLocation;\n}\n\n/** For next-core internal or devtools usage only. */\nexport function lint(\n source: string | ParseResultOfFile,\n { typescript, rules }: LintOptions = {}\n): LintError[] {\n const errors: LintError[] = [];\n const file =\n typeof source === \"string\"\n ? parseForAnalysis(source, { typescript })\n : source;\n if (!file) {\n // Return no errors if parse failed.\n return errors;\n }\n const body = file.program.body;\n const jsNodes: Statement[] = typescript ? [] : body;\n if (typescript) {\n for (const node of body) {\n if (node.type.startsWith(\"TS\")) {\n if (/Enum|Import|Export/.test(node.type)) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported TypeScript syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n }\n } else {\n jsNodes.push(node);\n }\n }\n }\n let func: FunctionDeclaration;\n for (const node of jsNodes) {\n const isFunctionDeclaration = node.type === \"FunctionDeclaration\";\n if (isFunctionDeclaration && !func) {\n func = node;\n } else {\n errors.push({\n type: \"SyntaxError\",\n message: isFunctionDeclaration\n ? \"Expect a single function declaration\"\n : `\\`${node.type}\\` is not allowed in top level`,\n loc: node.loc,\n });\n }\n }\n if (!func) {\n errors.unshift({\n type: \"SyntaxError\",\n message: \"Function declaration not found\",\n loc: {\n start: { line: 1, column: 0 },\n end: { line: 1, column: 0 },\n },\n });\n } else {\n precook(func, {\n hooks: {\n beforeVisit(node) {\n switch (node.type) {\n case \"ArrowFunctionExpression\":\n case \"FunctionDeclaration\":\n case \"FunctionExpression\":\n if (node.async || node.generator) {\n errors.push({\n type: \"SyntaxError\",\n message: `${\n node.async ? \"Async\" : \"Generator\"\n } function is not allowed`,\n loc: node.loc,\n });\n }\n break;\n case \"Literal\":\n if (node.regex) {\n if (node.value === null) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Invalid regular expression\",\n loc: node.loc,\n });\n } else if (node.regex.flags.includes(\"u\")) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported unicode flag in regular expression\",\n loc: node.loc,\n });\n }\n }\n break;\n case \"ObjectExpression\":\n for (const prop of node.properties) {\n if (prop.type === \"Property\") {\n if (prop.kind !== \"init\") {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported object getter/setter property\",\n loc: prop.loc,\n });\n } else if (\n !prop.computed &&\n prop.key.type === \"Identifier\" &&\n prop.key.name === \"__proto__\"\n ) {\n errors.push({\n type: \"TypeError\",\n message: \"Setting '__proto__' property is not allowed\",\n loc: prop.key.loc,\n });\n }\n }\n }\n break;\n case \"VariableDeclaration\":\n if (node.kind === \"var\" && rules?.noVar) {\n errors.push({\n type: \"SyntaxError\",\n message:\n \"Var declaration is not recommended, use `let` or `const` instead\",\n loc: {\n start: node.loc.start,\n end: {\n line: node.loc.start.line,\n // Only decorate the \"var\".\n column: node.loc.start.column + 3,\n },\n },\n });\n }\n break;\n }\n },\n beforeVisitGlobal(node) {\n if (node.name === \"arguments\") {\n errors.push({\n type: \"SyntaxError\",\n message: \"Use the rest parameters instead of 'arguments'\",\n loc: node.loc,\n });\n }\n },\n beforeVisitUnknown(node) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n return true;\n },\n },\n });\n }\n return errors;\n}\n"],"mappings":"AAMA,SAASA,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,OAAO,QAAQ,WAAW;AAanC;AACA,OAAO,SAASC,IAAI,CAClBC,MAAkC,EAErB;EAAA,IADb;IAAEC,UAAU;IAAEC;EAAmB,CAAC,uEAAG,CAAC,CAAC;EAEvC,IAAMC,MAAmB,GAAG,EAAE;EAC9B,IAAMC,IAAI,GACR,OAAOJ,MAAM,KAAK,QAAQ,GACtBH,gBAAgB,CAACG,MAAM,EAAE;IAAEC;EAAW,CAAC,CAAC,GACxCD,MAAM;EACZ,IAAI,CAACI,IAAI,EAAE;IACT;IACA,OAAOD,MAAM;EACf;EACA,IAAME,IAAI,GAAGD,IAAI,CAACE,OAAO,CAACD,IAAI;EAC9B,IAAME,OAAoB,GAAGN,UAAU,GAAG,EAAE,GAAGI,IAAI;EACnD,IAAIJ,UAAU,EAAE;IACd,KAAK,IAAMO,IAAI,IAAIH,IAAI,EAAE;MACvB,IAAIG,IAAI,CAACC,IAAI,CAACC,UAAU,CAAC,IAAI,CAAC,EAAE;QAC9B,IAAI,oBAAoB,CAACC,IAAI,CAACH,IAAI,CAACC,IAAI,CAAC,EAAE;UACxCN,MAAM,CAACS,IAAI,CAAC;YACVH,IAAI,EAAE,aAAa;YACnBI,OAAO,4CAAsCL,IAAI,CAACC,IAAI,MAAI;YAC1DK,GAAG,EAAEN,IAAI,CAACM;UACZ,CAAC,CAAC;QACJ;MACF,CAAC,MAAM;QACLP,OAAO,CAACK,IAAI,CAACJ,IAAI,CAAC;MACpB;IACF;EACF;EACA,IAAIO,IAAyB;EAC7B,KAAK,IAAMP,KAAI,IAAID,OAAO,EAAE;IAC1B,IAAMS,qBAAqB,GAAGR,KAAI,CAACC,IAAI,KAAK,qBAAqB;IACjE,IAAIO,qBAAqB,IAAI,CAACD,IAAI,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IAAI,EAAEX,IAAI,CAACM,GAAG,CAACI,KAAK,CAACC,IAAI;sBACzB;sBACAC,MAAM,EAAEZ,IAAI,CAACM,GAAG,CAACI,KAAK,CAACE,MAAM,GAAG;oBAClC;kBACF;gBACF,CAAC,CAAC;cACJ;cACA;UAAM;QAEZ,CAAC;QACDiB,iBAAiB,CAAC7B,IAAI,EAAE;UACtB,IAAIA,IAAI,CAAC2B,IAAI,KAAK,WAAW,EAAE;YAC7BhC,MAAM,CAACS,IAAI,CAAC;cACVH,IAAI,EAAE,aAAa;cACnBI,OAAO,EAAE,gDAAgD;cACzDC,GAAG,EAAEN,IAAI,CAACM;YACZ,CAAC,CAAC;UACJ;QACF,CAAC;QACDwB,kBAAkB,CAAC9B,IAAI,EAAE;UACvBL,MAAM,CAACS,IAAI,CAAC;YACVH,IAAI,EAAE,aAAa;YACnBI,OAAO,iCAA2BL,IAAI,CAACC,IAAI,MAAI;YAC/CK,GAAG,EAAEN,IAAI,CAACM;UACZ,CAAC,CAAC;UACF,OAAO,IAAI;QACb;MACF;IACF,CAAC,CAAC;EACJ;EACA,OAAOX,MAAM;AACf"}
package/dist/esm/parse.js CHANGED
@@ -18,7 +18,6 @@ export function parseAsEstree(source) {
18
18
  });
19
19
  var body = file.program.body;
20
20
  var jsNodes = typescript ? [] : body;
21
-
22
21
  if (typescript) {
23
22
  for (var node of body) {
24
23
  if (node.type.startsWith("TS")) {
@@ -30,25 +29,20 @@ export function parseAsEstree(source) {
30
29
  }
31
30
  }
32
31
  }
33
-
34
32
  if (jsNodes.length === 0) {
35
33
  throw new SyntaxError("Function declaration not found");
36
34
  }
37
-
38
35
  if (jsNodes.length > 1 || jsNodes[0].type !== "FunctionDeclaration") {
39
36
  throw new SyntaxError("Expect a single function declaration at top level, but received: ".concat(jsNodes.map(node => "\"".concat(node.type, "\"")).join(", ")));
40
37
  }
41
-
42
38
  return jsNodes[0];
43
39
  }
44
-
45
40
  /** For next-core internal or devtools usage only. */
46
41
  export function parseForAnalysis(source) {
47
42
  var {
48
43
  typescript,
49
44
  tokens
50
45
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
51
-
52
46
  try {
53
47
  return parse(source, {
54
48
  plugins: ["estree", typescript && "typescript"].filter(Boolean),
@@ -1 +1 @@
1
- {"version":3,"file":"parse.js","names":["parse","parseExpression","parseAsEstreeExpression","source","plugins","proposal","attachComment","parseAsEstree","typescript","file","filter","Boolean","strictMode","body","program","jsNodes","node","type","startsWith","test","SyntaxError","push","length","map","join","parseForAnalysis","tokens","sourceType","e"],"sources":["../../src/parse.ts"],"sourcesContent":["import {\n parse,\n parseExpression,\n ParseResult,\n ParserPlugin,\n} from \"@babel/parser\";\nimport { Expression, File, FunctionDeclaration, Statement } from \"@babel/types\";\n\nexport function parseAsEstreeExpression(source: string): Expression {\n return parseExpression(source, {\n plugins: [\"estree\", [\"pipelineOperator\", { proposal: \"minimal\" }]],\n attachComment: false,\n });\n}\n\nexport interface ParseEstreeOptions {\n typescript?: boolean;\n}\n\nexport function parseAsEstree(\n source: string,\n { typescript }: ParseEstreeOptions = {}\n): FunctionDeclaration {\n const file = parse(source, {\n plugins: [\"estree\", typescript && \"typescript\"].filter(\n Boolean\n ) as ParserPlugin[],\n strictMode: true,\n attachComment: false,\n });\n const body = file.program.body;\n const jsNodes: Statement[] = typescript ? [] : body;\n if (typescript) {\n for (const node of body) {\n if (node.type.startsWith(\"TS\")) {\n if (/Enum|Import|Export/.test(node.type)) {\n throw new SyntaxError(`Unsupported TypeScript syntax: ${node.type}`);\n }\n } else {\n jsNodes.push(node);\n }\n }\n }\n if (jsNodes.length === 0) {\n throw new SyntaxError(\"Function declaration not found\");\n }\n if (jsNodes.length > 1 || jsNodes[0].type !== \"FunctionDeclaration\") {\n throw new SyntaxError(\n `Expect a single function declaration at top level, but received: ${jsNodes\n .map((node) => `\"${node.type}\"`)\n .join(\", \")}`\n );\n }\n return jsNodes[0] as FunctionDeclaration;\n}\n\nexport interface AnalysisOptions {\n typescript?: boolean;\n tokens?: boolean;\n}\n\n/** For next-core internal or devtools usage only. */\nexport function parseForAnalysis(\n source: string,\n { typescript, tokens }: AnalysisOptions = {}\n): ParseResult<File> {\n try {\n return parse(source, {\n plugins: [\"estree\", typescript && \"typescript\"].filter(\n Boolean\n ) as ParserPlugin[],\n strictMode: true,\n attachComment: false,\n // Allow export/import declarations to make analyser handle errors.\n sourceType: \"unambiguous\",\n tokens,\n });\n } catch (e) {\n // Return no errors if parse failed.\n return null;\n }\n}\n"],"mappings":"AAAA,SACEA,KADF,EAEEC,eAFF,QAKO,eALP;AAQA,OAAO,SAASC,uBAAT,CAAiCC,MAAjC,EAA6D;EAClE,OAAOF,eAAe,CAACE,MAAD,EAAS;IAC7BC,OAAO,EAAE,CAAC,QAAD,EAAW,CAAC,kBAAD,EAAqB;MAAEC,QAAQ,EAAE;IAAZ,CAArB,CAAX,CADoB;IAE7BC,aAAa,EAAE;EAFc,CAAT,CAAtB;AAID;AAMD,OAAO,SAASC,aAAT,CACLJ,MADK,EAGgB;EAAA,IADrB;IAAEK;EAAF,CACqB,uEADgB,EAChB;EACrB,IAAMC,IAAI,GAAGT,KAAK,CAACG,MAAD,EAAS;IACzBC,OAAO,EAAE,CAAC,QAAD,EAAWI,UAAU,IAAI,YAAzB,EAAuCE,MAAvC,CACPC,OADO,CADgB;IAIzBC,UAAU,EAAE,IAJa;IAKzBN,aAAa,EAAE;EALU,CAAT,CAAlB;EAOA,IAAMO,IAAI,GAAGJ,IAAI,CAACK,OAAL,CAAaD,IAA1B;EACA,IAAME,OAAoB,GAAGP,UAAU,GAAG,EAAH,GAAQK,IAA/C;;EACA,IAAIL,UAAJ,EAAgB;IACd,KAAK,IAAMQ,IAAX,IAAmBH,IAAnB,EAAyB;MACvB,IAAIG,IAAI,CAACC,IAAL,CAAUC,UAAV,CAAqB,IAArB,CAAJ,EAAgC;QAC9B,IAAI,qBAAqBC,IAArB,CAA0BH,IAAI,CAACC,IAA/B,CAAJ,EAA0C;UACxC,MAAM,IAAIG,WAAJ,0CAAkDJ,IAAI,CAACC,IAAvD,EAAN;QACD;MACF,CAJD,MAIO;QACLF,OAAO,CAACM,IAAR,CAAaL,IAAb;MACD;IACF;EACF;;EACD,IAAID,OAAO,CAACO,MAAR,KAAmB,CAAvB,EAA0B;IACxB,MAAM,IAAIF,WAAJ,CAAgB,gCAAhB,CAAN;EACD;;EACD,IAAIL,OAAO,CAACO,MAAR,GAAiB,CAAjB,IAAsBP,OAAO,CAAC,CAAD,CAAP,CAAWE,IAAX,KAAoB,qBAA9C,EAAqE;IACnE,MAAM,IAAIG,WAAJ,4EACgEL,OAAO,CACxEQ,GADiE,CAC5DP,IAAD,gBAAcA,IAAI,CAACC,IAAnB,OAD6D,EAEjEO,IAFiE,CAE5D,IAF4D,CADhE,EAAN;EAKD;;EACD,OAAOT,OAAO,CAAC,CAAD,CAAd;AACD;;AAOD;AACA,OAAO,SAASU,gBAAT,CACLtB,MADK,EAGc;EAAA,IADnB;IAAEK,UAAF;IAAckB;EAAd,CACmB,uEADuB,EACvB;;EACnB,IAAI;IACF,OAAO1B,KAAK,CAACG,MAAD,EAAS;MACnBC,OAAO,EAAE,CAAC,QAAD,EAAWI,UAAU,IAAI,YAAzB,EAAuCE,MAAvC,CACPC,OADO,CADU;MAInBC,UAAU,EAAE,IAJO;MAKnBN,aAAa,EAAE,KALI;MAMnB;MACAqB,UAAU,EAAE,aAPO;MAQnBD;IARmB,CAAT,CAAZ;EAUD,CAXD,CAWE,OAAOE,CAAP,EAAU;IACV;IACA,OAAO,IAAP;EACD;AACF"}
1
+ {"version":3,"file":"parse.js","names":["parse","parseExpression","parseAsEstreeExpression","source","plugins","proposal","attachComment","parseAsEstree","typescript","file","filter","Boolean","strictMode","body","program","jsNodes","node","type","startsWith","test","SyntaxError","push","length","map","join","parseForAnalysis","tokens","sourceType","e"],"sources":["../../src/parse.ts"],"sourcesContent":["import { parse, parseExpression, type ParserPlugin } from \"@babel/parser\";\nimport type { Expression, FunctionDeclaration, Statement } from \"@babel/types\";\nimport type { ParseResultOfFile } from \"./interfaces\";\n\nexport function parseAsEstreeExpression(source: string): Expression {\n return parseExpression(source, {\n plugins: [\"estree\", [\"pipelineOperator\", { proposal: \"minimal\" }]],\n attachComment: false,\n });\n}\n\nexport interface ParseEstreeOptions {\n typescript?: boolean;\n}\n\nexport function parseAsEstree(\n source: string,\n { typescript }: ParseEstreeOptions = {}\n): FunctionDeclaration {\n const file = parse(source, {\n plugins: [\"estree\", typescript && \"typescript\"].filter(\n Boolean\n ) as ParserPlugin[],\n strictMode: true,\n attachComment: false,\n });\n const body = file.program.body;\n const jsNodes: Statement[] = typescript ? [] : body;\n if (typescript) {\n for (const node of body) {\n if (node.type.startsWith(\"TS\")) {\n if (/Enum|Import|Export/.test(node.type)) {\n throw new SyntaxError(`Unsupported TypeScript syntax: ${node.type}`);\n }\n } else {\n jsNodes.push(node);\n }\n }\n }\n if (jsNodes.length === 0) {\n throw new SyntaxError(\"Function declaration not found\");\n }\n if (jsNodes.length > 1 || jsNodes[0].type !== \"FunctionDeclaration\") {\n throw new SyntaxError(\n `Expect a single function declaration at top level, but received: ${jsNodes\n .map((node) => `\"${node.type}\"`)\n .join(\", \")}`\n );\n }\n return jsNodes[0] as FunctionDeclaration;\n}\n\nexport interface AnalysisOptions {\n typescript?: boolean;\n tokens?: boolean;\n}\n\n/** For next-core internal or devtools usage only. */\nexport function parseForAnalysis(\n source: string,\n { typescript, tokens }: AnalysisOptions = {}\n): ParseResultOfFile {\n try {\n return parse(source, {\n plugins: [\"estree\", typescript && \"typescript\"].filter(\n Boolean\n ) as ParserPlugin[],\n strictMode: true,\n attachComment: false,\n // Allow export/import declarations to make analyser handle errors.\n sourceType: \"unambiguous\",\n tokens,\n });\n } catch (e) {\n // Return no errors if parse failed.\n return null;\n }\n}\n"],"mappings":"AAAA,SAASA,KAAK,EAAEC,eAAe,QAA2B,eAAe;AAIzE,OAAO,SAASC,uBAAuB,CAACC,MAAc,EAAc;EAClE,OAAOF,e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AAI,OAAG,CAAC,CAC/BO,IAAI,CAAC,IAAI,CAAC,EACd;EACH;EACA,OAAOT,OAAO,CAAC,CAAC,CAAC;AACnB;AAOA;AACA,OAAO,SAASU,gBAAgB,CAC9BtB,MAAc,EAEK;EAAA,IADnB;IAAEK,UAAU;IAAEkB;EAAwB,CAAC,uEAAG,CAAC,CAAC;EAE5C,IAAI;IACF,OAAO1B,KAAK,CAACG,MAAM,EAAE;MACnBC,OAAO,EAAE,CAAC,QAAQ,EAAEI,UAAU,IAAI,YAAY,CAAC,CAACE,MAAM,CACpDC,OAAO,CACU;MACnBC,UAAU,EAAE,IAAI;MAChBN,aAAa,EAAE,KAAK;MACpB;MACAqB,UAAU,EAAE,aAAa;MACzBD;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,OAAOE,CAAC,EAAE;IACV;IACA,OAAO,IAAI;EACb;AACF"}
@@ -2,7 +2,6 @@ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
2
  import { hasOwnProperty } from "./hasOwnProperty";
3
3
  import { AnalysisContext, AnalysisEnvironment } from "./AnalysisContext";
4
4
  import { collectBoundNames, collectScopedDeclarations, containsExpression } from "./traverse";
5
-
6
5
  /**
7
6
  * Analysis an AST of a storyboard function or an evaluation expression.
8
7
  *
@@ -24,17 +23,14 @@ export function precook(rootAst) {
24
23
  rootContext.VariableEnvironment = rootEnv;
25
24
  rootContext.LexicalEnvironment = rootEnv;
26
25
  analysisContextStack.push(rootContext);
27
-
28
26
  function getRunningContext() {
29
27
  return analysisContextStack[analysisContextStack.length - 1];
30
28
  }
31
-
32
29
  function visit(node) {
33
30
  if (hasOwnProperty(visitors, node.type)) {
34
31
  visitors[node.type](node);
35
32
  }
36
33
  }
37
-
38
34
  function EvaluateChildren(node, keys, parent) {
39
35
  for (var key of keys) {
40
36
  Evaluate(node[key], parent === null || parent === void 0 ? void 0 : parent.concat({
@@ -43,7 +39,6 @@ export function precook(rootAst) {
43
39
  }));
44
40
  }
45
41
  }
46
-
47
42
  function Evaluate(node, parent) {
48
43
  if (Array.isArray(node)) {
49
44
  node.forEach((n, index) => {
@@ -53,27 +48,22 @@ export function precook(rootAst) {
53
48
  });
54
49
  } else if (node) {
55
50
  var _hooks$beforeVisit, _hooks$beforeVisitUnk;
56
-
57
51
  // `node` maybe `null` in some cases.
58
52
  (_hooks$beforeVisit = hooks.beforeVisit) === null || _hooks$beforeVisit === void 0 ? void 0 : _hooks$beforeVisit.call(hooks, node, parent);
59
- visitors && visit(node); // Expressions:
60
-
53
+ visitors && visit(node);
54
+ // Expressions:
61
55
  switch (node.type) {
62
56
  case "Identifier":
63
57
  if (!ResolveBinding(node.name)) {
64
58
  var _hooks$beforeVisitGlo;
65
-
66
59
  (_hooks$beforeVisitGlo = hooks.beforeVisitGlobal) === null || _hooks$beforeVisitGlo === void 0 ? void 0 : _hooks$beforeVisitGlo.call(hooks, node, parent);
67
60
  attemptToVisitGlobals.add(node.name);
68
61
  }
69
-
70
62
  return;
71
-
72
63
  case "ArrayExpression":
73
64
  case "ArrayPattern":
74
65
  EvaluateChildren(node, ["elements"], parent);
75
66
  return;
76
-
77
67
  case "ArrowFunctionExpression":
78
68
  {
79
69
  var env = getRunningContext().LexicalEnvironment;
@@ -81,80 +71,63 @@ export function precook(rootAst) {
81
71
  CallFunction(closure, parent);
82
72
  return;
83
73
  }
84
-
85
74
  case "AssignmentPattern":
86
75
  case "BinaryExpression":
87
76
  case "LogicalExpression":
88
77
  EvaluateChildren(node, ["left", "right"], parent);
89
78
  return;
90
-
91
79
  case "CallExpression":
92
80
  case "NewExpression":
93
81
  EvaluateChildren(node, ["callee", "arguments"], parent);
94
82
  return;
95
-
96
83
  case "ChainExpression":
97
84
  EvaluateChildren(node, ["expression"], parent);
98
85
  return;
99
-
100
86
  case "ConditionalExpression":
101
87
  EvaluateChildren(node, ["test", "consequent", "alternate"], parent);
102
88
  return;
103
-
104
89
  case "MemberExpression":
105
90
  EvaluateChildren(node, ["object"], parent);
106
-
107
91
  if (node.computed) {
108
92
  EvaluateChildren(node, ["property"], parent);
109
93
  }
110
-
111
94
  return;
112
-
113
95
  case "ObjectExpression":
114
96
  case "ObjectPattern":
115
97
  EvaluateChildren(node, ["properties"], parent);
116
98
  return;
117
-
118
99
  case "Property":
119
100
  if (node.computed) {
120
101
  EvaluateChildren(node, ["key"], parent);
121
102
  }
122
-
123
103
  EvaluateChildren(node, ["value"], parent);
124
104
  return;
125
-
126
105
  case "RestElement":
127
106
  case "SpreadElement":
128
107
  case "UnaryExpression":
129
108
  EvaluateChildren(node, ["argument"], parent);
130
109
  return;
131
-
132
110
  case "SequenceExpression":
133
111
  case "TemplateLiteral":
134
112
  EvaluateChildren(node, ["expressions"], parent);
135
113
  return;
136
-
137
114
  case "TaggedTemplateExpression":
138
115
  EvaluateChildren(node, ["tag", "quasi"], parent);
139
116
  return;
140
-
141
117
  case "Literal":
142
118
  return;
143
119
  }
144
-
145
120
  if (!expressionOnly) {
146
121
  // Statements and assignments:
147
122
  switch (node.type) {
148
123
  case "AssignmentExpression":
149
124
  EvaluateChildren(node, ["right", "left"], parent);
150
125
  return;
151
-
152
126
  case "BlockStatement":
153
127
  {
154
128
  if (!node.body.length) {
155
129
  return;
156
130
  }
157
-
158
131
  var runningContext = getRunningContext();
159
132
  var oldEnv = runningContext.LexicalEnvironment;
160
133
  var blockEnv = new AnalysisEnvironment(oldEnv);
@@ -164,16 +137,13 @@ export function precook(rootAst) {
164
137
  runningContext.LexicalEnvironment = oldEnv;
165
138
  return;
166
139
  }
167
-
168
140
  case "BreakStatement":
169
141
  case "ContinueStatement":
170
142
  case "EmptyStatement":
171
143
  return;
172
-
173
144
  case "CatchClause":
174
145
  {
175
146
  var _runningContext = getRunningContext();
176
-
177
147
  var _oldEnv = _runningContext.LexicalEnvironment;
178
148
  var catchEnv = new AnalysisEnvironment(_oldEnv);
179
149
  BoundNamesInstantiation(node.param, catchEnv);
@@ -182,160 +152,124 @@ export function precook(rootAst) {
182
152
  _runningContext.LexicalEnvironment = _oldEnv;
183
153
  return;
184
154
  }
185
-
186
155
  case "DoWhileStatement":
187
156
  EvaluateChildren(node, ["body", "test"], parent);
188
157
  return;
189
-
190
158
  case "ExpressionStatement":
191
159
  case "TSAsExpression":
192
160
  EvaluateChildren(node, ["expression"], parent);
193
161
  return;
194
-
195
162
  case "ForInStatement":
196
163
  case "ForOfStatement":
197
164
  {
198
165
  // ForIn/OfHeadEvaluation
199
166
  var lexicalBinding = node.left.type === "VariableDeclaration" && node.left.kind !== "var";
200
-
201
167
  var _runningContext2 = getRunningContext();
202
-
203
168
  var _oldEnv2 = _runningContext2.LexicalEnvironment;
204
-
205
169
  if (lexicalBinding) {
206
170
  var newEnv = new AnalysisEnvironment(_oldEnv2);
207
171
  BoundNamesInstantiation(node.left, newEnv);
208
172
  _runningContext2.LexicalEnvironment = newEnv;
209
173
  }
210
-
211
174
  EvaluateChildren(node, ["right"], parent);
212
- _runningContext2.LexicalEnvironment = _oldEnv2; // ForIn/OfBodyEvaluation
175
+ _runningContext2.LexicalEnvironment = _oldEnv2;
213
176
 
177
+ // ForIn/OfBodyEvaluation
214
178
  if (lexicalBinding) {
215
179
  var iterationEnv = new AnalysisEnvironment(_oldEnv2);
216
180
  BoundNamesInstantiation(node.left, iterationEnv);
217
181
  _runningContext2.LexicalEnvironment = iterationEnv;
218
182
  }
219
-
220
183
  EvaluateChildren(node, ["left", "body"], parent);
221
184
  _runningContext2.LexicalEnvironment = _oldEnv2;
222
185
  return;
223
186
  }
224
-
225
187
  case "ForStatement":
226
188
  {
227
189
  var _node$init;
228
-
229
190
  var _lexicalBinding = ((_node$init = node.init) === null || _node$init === void 0 ? void 0 : _node$init.type) === "VariableDeclaration" && node.init.kind !== "var";
230
-
231
191
  var _runningContext3 = getRunningContext();
232
-
233
192
  var _oldEnv3 = _runningContext3.LexicalEnvironment;
234
-
235
193
  if (_lexicalBinding) {
236
194
  var loopEnv = new AnalysisEnvironment(_oldEnv3);
237
195
  BoundNamesInstantiation(node.init, loopEnv);
238
196
  _runningContext3.LexicalEnvironment = loopEnv;
239
197
  }
240
-
241
198
  EvaluateChildren(node, ["init", "test", "body", "update"], parent);
242
199
  _runningContext3.LexicalEnvironment = _oldEnv3;
243
200
  return;
244
201
  }
245
-
246
202
  case "FunctionDeclaration":
247
203
  {
248
204
  var [fn] = collectBoundNames(node);
249
205
  var _env = getRunningContext().LexicalEnvironment;
250
206
  var fo = OrdinaryFunctionCreate(node, _env);
251
-
252
207
  _env.CreateBinding(fn);
253
-
254
208
  CallFunction(fo, parent);
255
209
  return;
256
210
  }
257
-
258
211
  case "FunctionExpression":
259
212
  {
260
213
  var _closure = InstantiateOrdinaryFunctionExpression(node);
261
-
262
214
  CallFunction(_closure, parent);
263
215
  return;
264
216
  }
265
-
266
217
  case "IfStatement":
267
218
  EvaluateChildren(node, ["test", "consequent", "alternate"], parent);
268
219
  return;
269
-
270
220
  case "ReturnStatement":
271
221
  case "ThrowStatement":
272
222
  case "UpdateExpression":
273
223
  EvaluateChildren(node, ["argument"], parent);
274
224
  return;
275
-
276
225
  case "SwitchCase":
277
226
  EvaluateChildren(node, ["test", "consequent"], parent);
278
227
  return;
279
-
280
228
  case "SwitchStatement":
281
229
  {
282
230
  EvaluateChildren(node, ["discriminant"], parent);
283
-
284
231
  var _runningContext4 = getRunningContext();
285
-
286
232
  var _oldEnv4 = _runningContext4.LexicalEnvironment;
287
-
288
233
  var _blockEnv = new AnalysisEnvironment(_oldEnv4);
289
-
290
234
  BlockDeclarationInstantiation(node.cases, _blockEnv);
291
235
  _runningContext4.LexicalEnvironment = _blockEnv;
292
236
  EvaluateChildren(node, ["cases"], parent);
293
237
  _runningContext4.LexicalEnvironment = _oldEnv4;
294
238
  return;
295
239
  }
296
-
297
240
  case "TryStatement":
298
241
  EvaluateChildren(node, ["block", "handler", "finalizer"], parent);
299
242
  return;
300
-
301
243
  case "VariableDeclaration":
302
244
  EvaluateChildren(node, ["declarations"], parent);
303
245
  return;
304
-
305
246
  case "VariableDeclarator":
306
247
  EvaluateChildren(node, ["id", "init"], parent);
307
248
  return;
308
-
309
249
  case "WhileStatement":
310
250
  EvaluateChildren(node, ["test", "body"], parent);
311
251
  return;
312
252
  }
313
253
  }
314
-
315
254
  var silent = (_hooks$beforeVisitUnk = hooks.beforeVisitUnknown) === null || _hooks$beforeVisitUnk === void 0 ? void 0 : _hooks$beforeVisitUnk.call(hooks, node, parent);
316
-
317
255
  if (!silent) {
318
256
  // eslint-disable-next-line no-console
319
257
  console.warn("Unsupported node type `".concat(node.type, "`"));
320
258
  }
321
259
  }
322
260
  }
323
-
324
261
  function BoundNamesInstantiation(declarations, env) {
325
262
  for (var name of collectBoundNames(declarations)) {
326
263
  env.CreateBinding(name);
327
264
  }
328
265
  }
329
-
330
266
  function ResolveBinding(name) {
331
267
  var env = getRunningContext().LexicalEnvironment;
332
268
  return GetIdentifierReference(env, name);
333
269
  }
334
-
335
270
  function GetIdentifierReference(env, name) {
336
271
  return !!env && (env.HasBinding(name) || GetIdentifierReference(env.OuterEnv, name));
337
272
  }
338
-
339
273
  function BlockDeclarationInstantiation(code, env) {
340
274
  var declarations = collectScopedDeclarations(code, {
341
275
  var: false,
@@ -343,7 +277,6 @@ export function precook(rootAst) {
343
277
  });
344
278
  BoundNamesInstantiation(declarations, env);
345
279
  }
346
-
347
280
  function CallFunction(closure, parent) {
348
281
  PrepareOrdinaryCall(closure);
349
282
  FunctionDeclarationInstantiation(closure, parent);
@@ -356,7 +289,6 @@ export function precook(rootAst) {
356
289
  } : []));
357
290
  analysisContextStack.pop();
358
291
  }
359
-
360
292
  function PrepareOrdinaryCall(F) {
361
293
  var calleeContext = new AnalysisContext();
362
294
  var localEnv = new AnalysisEnvironment(F.Environment);
@@ -364,7 +296,6 @@ export function precook(rootAst) {
364
296
  calleeContext.LexicalEnvironment = localEnv;
365
297
  analysisContextStack.push(calleeContext);
366
298
  }
367
-
368
299
  function FunctionDeclarationInstantiation(func, parent) {
369
300
  var calleeContext = getRunningContext();
370
301
  var code = func.ECMAScriptCode;
@@ -382,14 +313,12 @@ export function precook(rootAst) {
382
313
  key: "params"
383
314
  }));
384
315
  var varEnv;
385
-
386
316
  if (!hasParameterExpressions) {
387
317
  // NOTE: Only a single Environment Record is needed for the parameters
388
318
  // and top-level vars.
389
319
  for (var n of varNames) {
390
320
  env.CreateBinding(n);
391
321
  }
392
-
393
322
  varEnv = env;
394
323
  } else {
395
324
  // NOTE: A separate Environment Record is needed to ensure that closures
@@ -397,12 +326,10 @@ export function precook(rootAst) {
397
326
  // visibility of declarations in the function body.
398
327
  varEnv = new AnalysisEnvironment(env);
399
328
  calleeContext.VariableEnvironment = varEnv;
400
-
401
329
  for (var _n of varNames) {
402
330
  varEnv.CreateBinding(_n);
403
331
  }
404
332
  }
405
-
406
333
  var lexEnv = varEnv;
407
334
  calleeContext.LexicalEnvironment = lexEnv;
408
335
  var lexDeclarations = collectScopedDeclarations(code, {
@@ -411,20 +338,16 @@ export function precook(rootAst) {
411
338
  });
412
339
  BoundNamesInstantiation(lexDeclarations, lexEnv);
413
340
  }
414
-
415
341
  function InstantiateOrdinaryFunctionExpression(functionExpression) {
416
342
  var scope = getRunningContext().LexicalEnvironment;
417
-
418
343
  if (!functionExpression.id) {
419
344
  return OrdinaryFunctionCreate(functionExpression, scope);
420
345
  }
421
-
422
346
  var name = functionExpression.id.name;
423
347
  var funcEnv = new AnalysisEnvironment(scope);
424
348
  funcEnv.CreateBinding(name);
425
349
  return OrdinaryFunctionCreate(functionExpression, funcEnv);
426
350
  }
427
-
428
351
  function OrdinaryFunctionCreate(func, scope) {
429
352
  return {
430
353
  Function: func,
@@ -433,7 +356,6 @@ export function precook(rootAst) {
433
356
  Environment: scope
434
357
  };
435
358
  }
436
-
437
359
  Evaluate(rootAst, withParent ? [] : undefined);
438
360
  return attemptToVisitGlobals;
439
361
  }