@next-core/cook 1.6.83 → 2.0.2
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/dist/cjs/AnalysisContext.js +4 -8
- package/dist/cjs/AnalysisContext.js.map +1 -1
- package/dist/cjs/ExecutionContext.js +10 -15
- package/dist/cjs/ExecutionContext.js.map +1 -1
- package/dist/cjs/context-free.js +2 -2
- package/dist/cjs/context-free.js.map +1 -1
- package/dist/cjs/cook.js +7 -4
- package/dist/cjs/cook.js.map +1 -1
- package/dist/cjs/hasOwnProperty.js.map +1 -1
- package/dist/cjs/index.js +5 -40
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lint.js +5 -3
- package/dist/cjs/lint.js.map +1 -1
- package/dist/cjs/parse.js +0 -20
- package/dist/cjs/parse.js.map +1 -1
- package/dist/cjs/parseForAnalysis.js +27 -0
- package/dist/cjs/parseForAnalysis.js.map +1 -0
- package/dist/cjs/precook.js +5 -5
- package/dist/cjs/precook.js.map +1 -1
- package/dist/cjs/precookFunction.js +2 -2
- package/dist/cjs/precookFunction.js.map +1 -1
- package/dist/cjs/preevaluate.js +2 -2
- package/dist/cjs/preevaluate.js.map +1 -1
- package/dist/cjs/sanitize.js.map +1 -1
- package/dist/cjs/traverse.js.map +1 -1
- package/dist/esm/AnalysisContext.js.map +1 -1
- package/dist/esm/ExecutionContext.js.map +1 -1
- package/dist/esm/context-free.js +2 -2
- package/dist/esm/context-free.js.map +1 -1
- package/dist/esm/cook.js +7 -4
- package/dist/esm/cook.js.map +1 -1
- package/dist/esm/hasOwnProperty.js.map +1 -1
- package/dist/esm/index.js +6 -8
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lint.js +4 -2
- package/dist/esm/lint.js.map +1 -1
- package/dist/esm/parse.js +0 -20
- package/dist/esm/parse.js.map +1 -1
- package/dist/esm/parseForAnalysis.js +22 -0
- package/dist/esm/parseForAnalysis.js.map +1 -0
- package/dist/esm/precook.js +5 -5
- package/dist/esm/precook.js.map +1 -1
- package/dist/esm/precookFunction.js +2 -2
- package/dist/esm/precookFunction.js.map +1 -1
- package/dist/esm/preevaluate.js +2 -2
- package/dist/esm/preevaluate.js.map +1 -1
- package/dist/esm/sanitize.js.map +1 -1
- package/dist/esm/traverse.js.map +1 -1
- package/dist/types/AnalysisContext.d.ts +5 -5
- package/dist/types/ExecutionContext.d.ts +11 -11
- package/dist/types/context-free.d.ts +2 -2
- package/dist/types/cook.d.ts +1 -1
- package/dist/types/index.d.ts +5 -8
- package/dist/types/interfaces.d.ts +9 -9
- package/dist/types/lint.d.ts +2 -2
- package/dist/types/parse.d.ts +0 -7
- package/dist/types/parseForAnalysis.d.ts +7 -0
- package/dist/types/precook.d.ts +2 -2
- package/dist/types/precookFunction.d.ts +1 -1
- package/dist/types/preevaluate.d.ts +2 -2
- package/dist/types/traverse.d.ts +4 -4
- package/package.json +29 -10
- package/dist/types/cook.spec.d.ts +0 -1
- package/dist/types/lint.spec.d.ts +0 -1
- package/dist/types/precook.spec.d.ts +0 -1
- package/dist/types/precookFunction.spec.d.ts +0 -1
- package/dist/types/preevaluate.spec.d.ts +0 -1
package/dist/esm/lint.js.map
CHANGED
|
@@ -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 {\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,GAA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AAC,CAAC;UACF,OAAO,IAAI;QACb;MACF;IACF,CAAC,CAAC;EACJ;EACA,OAAOX,MAAM;AACf"}
|
|
1
|
+
{"version":3,"file":"lint.js","names":["parseForAnalysis","precook","lint","source","typescript","rules","arguments","length","undefined","errors","file","body","program","jsNodes","node","type","startsWith","test","push","message","concat","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":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\nimport {\n type FunctionDeclaration,\n SourceLocation,\n Statement,\n} from \"@babel/types\";\nimport type { CookRules, ParseResultOfFile } from \"./interfaces.js\";\nimport { parseForAnalysis } from \"./parseForAnalysis.js\";\nimport { precook } from \"./precook.js\";\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 | null,\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 | undefined;\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":"AAAA;;AAOA,SAASA,gBAAgB,QAAQ,uBAAuB;AACxD,SAASC,OAAO,QAAQ,cAAc;AAatC;AACA,OAAO,SAASC,IAAIA,CAClBC,MAAyC,EAE5B;EAAA,IADb;IAAEC,UAAU;IAAEC;EAAmB,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEvC,IAAMG,MAAmB,GAAG,EAAE;EAC9B,IAAMC,IAAI,GACR,OAAOP,MAAM,KAAK,QAAQ,GACtBH,gBAAgB,CAACG,MAAM,EAAE;IAAEC;EAAW,CAAC,CAAC,GACxCD,MAAM;EACZ,IAAI,CAACO,IAAI,EAAE;IACT;IACA,OAAOD,MAAM;EACf;EACA,IAAME,IAAI,GAAGD,IAAI,CAACE,OAAO,CAACD,IAAI;EAC9B,IAAME,OAAoB,GAAGT,UAAU,GAAG,EAAE,GAAGO,IAAI;EACnD,IAAIP,UAAU,EAAE;IACd,KAAK,IAAMU,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,qCAAAC,MAAA,CAAsCN,IAAI,CAACC,IAAI,MAAI;YAC1DM,GAAG,EAAEP,IAAI,CAACO;UACZ,CAAC,CAAC;QACJ;MACF,CAAC,MAAM;QACLR,OAAO,CAACK,IAAI,CAACJ,IAAI,CAAC;MACpB;IACF;EACF;EACA,IAAIQ,IAAqC;EACzC,KAAK,IAAMR,KAAI,I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VH,IAAI,EAAE,aAAa;kBACnBI,OAAO,EACL,kEAAkE;kBACpEE,GAAG,EAAE;oBACHI,KAAK,EAAEX,IAAI,CAACO,GAAG,CAAEI,KAAK;oBACtBG,GAAG,EAAE;sBACHF,IAAI,EAAEZ,IAAI,CAACO,GAAG,CAAEI,KAAK,CAACC,IAAI;sBAC1B;sBACAC,MAAM,EAAEb,IAAI,CAACO,GAAG,CAAEI,KAAK,CAACE,MAAM,GAAG;oBACnC;kBACF;gBACF,CAAC,CAAC;cACJ;cACA;UAAM;QAEZ,CAAC;QACDiB,iBAAiBA,CAAC9B,IAAI,EAAE;UACtB,IAAIA,IAAI,CAAC4B,IAAI,KAAK,WAAW,EAAE;YAC7BjC,MAAM,CAACS,IAAI,CAAC;cACVH,IAAI,EAAE,aAAa;cACnBI,OAAO,EAAE,gDAAgD;cACzDE,GAAG,EAAEP,IAAI,CAACO;YACZ,CAAC,CAAC;UACJ;QACF,CAAC;QACDwB,kBAAkBA,CAAC/B,IAAI,EAAE;UACvBL,MAAM,CAACS,IAAI,CAAC;YACVH,IAAI,EAAE,aAAa;YACnBI,OAAO,0BAAAC,MAAA,CAA2BN,IAAI,CAACC,IAAI,MAAI;YAC/CM,GAAG,EAAEP,IAAI,CAACO;UACZ,CAAC,CAAC;UACF,OAAO,IAAI;QACb;MACF;IACF,CAAC,CAAC;EACJ;EACA,OAAOZ,MAAM;AACf"}
|
package/dist/esm/parse.js
CHANGED
|
@@ -37,24 +37,4 @@ export function parseAsEstree(source) {
|
|
|
37
37
|
}
|
|
38
38
|
return jsNodes[0];
|
|
39
39
|
}
|
|
40
|
-
/** For next-core internal or devtools usage only. */
|
|
41
|
-
export function parseForAnalysis(source) {
|
|
42
|
-
var {
|
|
43
|
-
typescript,
|
|
44
|
-
tokens
|
|
45
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
46
|
-
try {
|
|
47
|
-
return parse(source, {
|
|
48
|
-
plugins: ["estree", typescript && "typescript"].filter(Boolean),
|
|
49
|
-
strictMode: true,
|
|
50
|
-
attachComment: false,
|
|
51
|
-
// Allow export/import declarations to make analyser handle errors.
|
|
52
|
-
sourceType: "unambiguous",
|
|
53
|
-
tokens
|
|
54
|
-
});
|
|
55
|
-
} catch (e) {
|
|
56
|
-
// Return no errors if parse failed.
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
40
|
//# sourceMappingURL=parse.js.map
|
package/dist/esm/parse.js.map
CHANGED
|
@@ -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","
|
|
1
|
+
{"version":3,"file":"parse.js","names":["parse","parseExpression","parseAsEstreeExpression","source","plugins","proposal","attachComment","parseAsEstree","typescript","arguments","length","undefined","file","filter","Boolean","strictMode","body","program","jsNodes","node","type","startsWith","test","SyntaxError","concat","push","map","join"],"sources":["../../src/parse.ts"],"sourcesContent":["import { parse, parseExpression, type ParserPlugin } from \"@babel/parser\";\nimport type { Expression, 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"],"mappings":"AAAA,SAASA,KAAK,EAAEC,eAAe,QAA2B,eAAe;AAGzE,OAAO,SAASC,uBAAuBA,CAACC,MAAc,EAAc;EAClE,OAAOF,eAAe,CAACE,MAAM,EAAE;IAC7BC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,kBAAkB,EAAE;MAAEC,QAAQ,EAAE;IAAU,CAAC,CAAC,CAAC;IAClEC,aAAa,EAAE;EACjB,CAAC,CAAC;AACJ;AAMA,OAAO,SAASC,aAAaA,CAC3BJ,MAAc,EAEO;EAAA,IADrB;IAAEK;EAA+B,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEvC,IAAMG,IAAI,GAAGZ,KAAK,CAACG,MAAM,EAAE;IACzBC,OAAO,EAAE,CAAC,QAAQ,EAAEI,UAAU,IAAI,YAAY,CAAC,CAACK,MAAM,CACpDC,OAAO,CACU;IACnBC,UAAU,EAAE,IAAI;IAChBT,aAAa,EAAE;EACjB,CAAC,CAAC;EACF,IAAMU,IAAI,GAAGJ,IAAI,CAACK,OAAO,CAACD,IAAI;EAC9B,IAAME,OAAoB,GAAGV,UAAU,GAAG,EAAE,GAAGQ,IAAI;EACnD,IAAIR,UAAU,EAAE;IACd,KAAK,IAAMW,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;UACxC,MAAM,IAAIG,WAAW,mCAAAC,MAAA,CAAmCL,IAAI,CAACC,IAAI,EAAG;QACtE;MACF,CAAC,MAAM;QACLF,OAAO,CAACO,IAAI,CAACN,IAAI,CAAC;MACpB;IACF;EACF;EACA,IAAID,OAAO,CAACR,MAAM,KAAK,CAAC,EAAE;IACxB,MAAM,IAAIa,WAAW,CAAC,gCAAgC,CAAC;EACzD;EACA,IAAIL,OAAO,CAACR,MAAM,GAAG,CAAC,IAAIQ,OAAO,CAAC,CAAC,CAAC,CAACE,IAAI,KAAK,qBAAqB,EAAE;IACnE,MAAM,IAAIG,WAAW,qEAAAC,MAAA,CACiDN,OAAO,CACxEQ,GAAG,CAAEP,IAAI,SAAAK,MAAA,CAASL,IAAI,CAACC,IAAI,OAAG,CAAC,CAC/BO,IAAI,CAAC,IAAI,CAAC,EACd;EACH;EACA,OAAOT,OAAO,CAAC,CAAC,CAAC;AACnB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { parse } from "@babel/parser";
|
|
2
|
+
/** For next-core internal or devtools usage only. */
|
|
3
|
+
export function parseForAnalysis(source) {
|
|
4
|
+
var {
|
|
5
|
+
typescript,
|
|
6
|
+
tokens
|
|
7
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8
|
+
try {
|
|
9
|
+
return parse(source, {
|
|
10
|
+
plugins: ["estree", typescript && "typescript"].filter(Boolean),
|
|
11
|
+
strictMode: true,
|
|
12
|
+
attachComment: false,
|
|
13
|
+
// Allow export/import declarations to make analyser handle errors.
|
|
14
|
+
sourceType: "unambiguous",
|
|
15
|
+
tokens
|
|
16
|
+
});
|
|
17
|
+
} catch (e) {
|
|
18
|
+
// Return no errors if parse failed.
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=parseForAnalysis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseForAnalysis.js","names":["parse","parseForAnalysis","source","typescript","tokens","arguments","length","undefined","plugins","filter","Boolean","strictMode","attachComment","sourceType","e"],"sources":["../../src/parseForAnalysis.ts"],"sourcesContent":["import { parse, type ParserPlugin } from \"@babel/parser\";\nimport { ParseResultOfFile } from \"./interfaces.js\";\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 | null {\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,QAA2B,eAAe;AAQxD;AACA,OAAO,SAASC,gBAAgBA,CAC9BC,MAAc,EAEY;EAAA,IAD1B;IAAEC,UAAU;IAAEC;EAAwB,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAE5C,IAAI;IACF,OAAOL,KAAK,CAACE,MAAM,EAAE;MACnBM,OAAO,EAAE,CAAC,QAAQ,EAAEL,UAAU,IAAI,YAAY,CAAC,CAACM,MAAM,CACpDC,OAAO,CACU;MACnBC,UAAU,EAAE,IAAI;MAChBC,aAAa,EAAE,KAAK;MACpB;MACAC,UAAU,EAAE,aAAa;MACzBT;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,OAAOU,CAAC,EAAE;IACV;IACA,OAAO,IAAI;EACb;AACF"}
|
package/dist/esm/precook.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
-
import { hasOwnProperty } from "./hasOwnProperty";
|
|
3
|
-
import { AnalysisContext, AnalysisEnvironment } from "./AnalysisContext";
|
|
4
|
-
import { collectBoundNames, collectScopedDeclarations, containsExpression } from "./traverse";
|
|
2
|
+
import { hasOwnProperty } from "./hasOwnProperty.js";
|
|
3
|
+
import { AnalysisContext, AnalysisEnvironment } from "./AnalysisContext.js";
|
|
4
|
+
import { collectBoundNames, collectScopedDeclarations, containsExpression } from "./traverse.js";
|
|
5
5
|
/**
|
|
6
6
|
* Analysis an AST of a storyboard function or an evaluation expression.
|
|
7
7
|
*
|
|
@@ -27,7 +27,7 @@ export function precook(rootAst) {
|
|
|
27
27
|
return analysisContextStack[analysisContextStack.length - 1];
|
|
28
28
|
}
|
|
29
29
|
function visit(node) {
|
|
30
|
-
if (hasOwnProperty(visitors, node.type)) {
|
|
30
|
+
if (visitors && hasOwnProperty(visitors, node.type)) {
|
|
31
31
|
visitors[node.type](node);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -50,7 +50,7 @@ export function precook(rootAst) {
|
|
|
50
50
|
var _hooks$beforeVisit, _hooks$beforeVisitUnk;
|
|
51
51
|
// `node` maybe `null` in some cases.
|
|
52
52
|
(_hooks$beforeVisit = hooks.beforeVisit) === null || _hooks$beforeVisit === void 0 ? void 0 : _hooks$beforeVisit.call(hooks, node, parent);
|
|
53
|
-
|
|
53
|
+
visit(node);
|
|
54
54
|
// Expressions:
|
|
55
55
|
switch (node.type) {
|
|
56
56
|
case "Identifier":
|
package/dist/esm/precook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"precook.js","names":["hasOwnProperty","AnalysisContext","AnalysisEnvironment","collectBoundNames","collectScopedDeclarations","containsExpression","precook","rootAst","expressionOnly","visitors","withParent","hooks","attemptToVisitGlobals","Set","analysisContextStack","rootEnv","rootContext","VariableEnvironment","LexicalEnvironment","push","getRunningContext","length","visit","node","type","EvaluateChildren","keys","parent","key","Evaluate","concat","Array","isArray","forEach","n","index","slice","beforeVisit","ResolveBinding","name","beforeVisitGlobal","add","env","closure","OrdinaryFunctionCreate","CallFunction","computed","body","runningContext","oldEnv","blockEnv","BlockDeclarationInstantiation","catchEnv","BoundNamesInstantiation","param","lexicalBinding","left","kind","newEnv","iterationEnv","init","loopEnv","fn","fo","CreateBinding","InstantiateOrdinaryFunctionExpression","cases","silent","beforeVisitUnknown","console","warn","declarations","GetIdentifierReference","HasBinding","OuterEnv","code","var","topLevel","PrepareOrdinaryCall","FunctionDeclarationInstantiation","ECMAScriptCode","Function","pop","F","calleeContext","localEnv","Environment","func","formals","FormalParameters","hasParameterExpressions","varDeclarations","varNames","varEnv","lexEnv","lexDeclarations","functionExpression","scope","id","funcEnv","params","undefined"],"sources":["../../src/precook.ts"],"sourcesContent":["import {\n ArrowFunctionExpression,\n Expression,\n FunctionDeclaration,\n FunctionExpression,\n Identifier,\n Statement,\n SwitchCase,\n VariableDeclaration,\n} from \"@babel/types\";\nimport { hasOwnProperty } from \"./hasOwnProperty\";\nimport {\n AnalysisContext,\n AnalysisEnvironment,\n AnalysisFunctionObject,\n} from \"./AnalysisContext\";\nimport { EstreeNode, EstreeVisitors, NodeWithBoundNames } from \"./interfaces\";\nimport {\n collectBoundNames,\n collectScopedDeclarations,\n containsExpression,\n} from \"./traverse\";\n\nexport interface PrecookOptions {\n expressionOnly?: boolean;\n /** @deprecated Use hooks instead. */\n visitors?: EstreeVisitors;\n hooks?: PrecookHooks;\n withParent?: boolean;\n}\n\nexport type EstreeParent = EstreeParentItem[];\n\nexport interface EstreeParentItem {\n node: EstreeNode;\n key: string;\n index?: number;\n}\n\nexport interface PrecookHooks {\n beforeVisit?(node: EstreeNode, parent?: EstreeParent): void;\n beforeVisitGlobal?(node: Identifier, parent?: EstreeParent): void;\n /** Return true if want to silent warnings for unknown nodes. */\n beforeVisitUnknown?(node: EstreeNode, parent?: EstreeParent): boolean | void;\n}\n\n/**\n * Analysis an AST of a storyboard function or an evaluation expression.\n *\n * @param rootAst - The root AST.\n * @param options - Analysis options.\n * @returns A set of global variables the root AST attempts to access.\n */\nexport function precook(\n rootAst: Expression | FunctionDeclaration,\n { expressionOnly, visitors, withParent, hooks = {} }: PrecookOptions = {}\n): Set<string> {\n const attemptToVisitGlobals = new Set<string>();\n const analysisContextStack: AnalysisContext[] = [];\n const rootEnv = new AnalysisEnvironment(null);\n const rootContext = new AnalysisContext();\n rootContext.VariableEnvironment = rootEnv;\n rootContext.LexicalEnvironment = rootEnv;\n analysisContextStack.push(rootContext);\n\n function getRunningContext(): AnalysisContext {\n return analysisContextStack[analysisContextStack.length - 1];\n }\n\n function visit(node: EstreeNode): void {\n if (hasOwnProperty(visitors, node.type)) {\n visitors[node.type](node);\n }\n }\n\n function EvaluateChildren<T extends EstreeNode>(\n node: T,\n keys: (keyof T)[],\n parent?: EstreeParent\n ): void {\n for (const key of keys) {\n Evaluate(\n node[key] as unknown as EstreeNode | EstreeNode[],\n parent?.concat({ node, key } as EstreeParentItem)\n );\n }\n }\n\n function Evaluate(\n node: EstreeNode | EstreeNode[],\n parent?: EstreeParent\n ): void {\n if (Array.isArray(node)) {\n node.forEach((n, index) => {\n Evaluate(\n n,\n parent\n ? parent.slice(0, -1).concat({\n ...parent[parent.length - 1],\n index,\n })\n : parent\n );\n });\n } else if (node) {\n // `node` maybe `null` in some cases.\n hooks.beforeVisit?.(node, parent);\n visitors && visit(node);\n // Expressions:\n switch (node.type) {\n case \"Identifier\":\n if (!ResolveBinding(node.name)) {\n hooks.beforeVisitGlobal?.(node, parent);\n attemptToVisitGlobals.add(node.name);\n }\n return;\n case \"ArrayExpression\":\n case \"ArrayPattern\":\n EvaluateChildren(node, [\"elements\"], parent);\n return;\n case \"ArrowFunctionExpression\": {\n const env = getRunningContext().LexicalEnvironment;\n const closure = OrdinaryFunctionCreate(node, env);\n CallFunction(closure, parent);\n return;\n }\n case \"AssignmentPattern\":\n case \"BinaryExpression\":\n case \"LogicalExpression\":\n EvaluateChildren(node, [\"left\", \"right\"], parent);\n return;\n case \"CallExpression\":\n case \"NewExpression\":\n EvaluateChildren(node, [\"callee\", \"arguments\"], parent);\n return;\n case \"ChainExpression\":\n EvaluateChildren(node, [\"expression\"], parent);\n return;\n case \"ConditionalExpression\":\n EvaluateChildren(node, [\"test\", \"consequent\", \"alternate\"], parent);\n return;\n case \"MemberExpression\":\n EvaluateChildren(node, [\"object\"], parent);\n if (node.computed) {\n EvaluateChildren(node, [\"property\"], parent);\n }\n return;\n case \"ObjectExpression\":\n case \"ObjectPattern\":\n EvaluateChildren(node, [\"properties\"], parent);\n return;\n case \"Property\":\n if (node.computed) {\n EvaluateChildren(node, [\"key\"], parent);\n }\n EvaluateChildren(node, [\"value\"], parent);\n return;\n case \"RestElement\":\n case \"SpreadElement\":\n case \"UnaryExpression\":\n EvaluateChildren(node, [\"argument\"], parent);\n return;\n case \"SequenceExpression\":\n case \"TemplateLiteral\":\n EvaluateChildren(node, [\"expressions\"], parent);\n return;\n case \"TaggedTemplateExpression\":\n EvaluateChildren(node, [\"tag\", \"quasi\"], parent);\n return;\n case \"Literal\":\n return;\n }\n if (!expressionOnly) {\n // Statements and assignments:\n switch (node.type) {\n case \"AssignmentExpression\":\n EvaluateChildren(node, [\"right\", \"left\"], parent);\n return;\n case \"BlockStatement\": {\n if (!node.body.length) {\n return;\n }\n const runningContext = getRunningContext();\n const oldEnv = runningContext.LexicalEnvironment;\n const blockEnv = new AnalysisEnvironment(oldEnv);\n BlockDeclarationInstantiation(node.body, blockEnv);\n runningContext.LexicalEnvironment = blockEnv;\n EvaluateChildren(node, [\"body\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n return;\n }\n case \"BreakStatement\":\n case \"ContinueStatement\":\n case \"EmptyStatement\":\n return;\n case \"CatchClause\": {\n const runningContext = getRunningContext();\n const oldEnv = runningContext.LexicalEnvironment;\n const catchEnv = new AnalysisEnvironment(oldEnv);\n BoundNamesInstantiation(node.param, catchEnv);\n runningContext.LexicalEnvironment = catchEnv;\n EvaluateChildren(node, [\"param\", \"body\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n return;\n }\n case \"DoWhileStatement\":\n EvaluateChildren(node, [\"body\", \"test\"], parent);\n return;\n case \"ExpressionStatement\":\n case \"TSAsExpression\":\n EvaluateChildren(node, [\"expression\"], parent);\n return;\n case \"ForInStatement\":\n case \"ForOfStatement\": {\n // ForIn/OfHeadEvaluation\n const lexicalBinding =\n node.left.type === \"VariableDeclaration\" &&\n node.left.kind !== \"var\";\n const runningContext = getRunningContext();\n const oldEnv = runningContext.LexicalEnvironment;\n if (lexicalBinding) {\n const newEnv = new AnalysisEnvironment(oldEnv);\n BoundNamesInstantiation(node.left, newEnv);\n runningContext.LexicalEnvironment = newEnv;\n }\n EvaluateChildren(node, [\"right\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n\n // ForIn/OfBodyEvaluation\n if (lexicalBinding) {\n const iterationEnv = new AnalysisEnvironment(oldEnv);\n BoundNamesInstantiation(node.left, iterationEnv);\n runningContext.LexicalEnvironment = iterationEnv;\n }\n EvaluateChildren(node, [\"left\", \"body\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n return;\n }\n case \"ForStatement\": {\n const lexicalBinding =\n node.init?.type === \"VariableDeclaration\" &&\n node.init.kind !== \"var\";\n const runningContext = getRunningContext();\n const oldEnv = runningContext.LexicalEnvironment;\n if (lexicalBinding) {\n const loopEnv = new AnalysisEnvironment(oldEnv);\n BoundNamesInstantiation(\n node.init as VariableDeclaration,\n loopEnv\n );\n runningContext.LexicalEnvironment = loopEnv;\n }\n EvaluateChildren(node, [\"init\", \"test\", \"body\", \"update\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n return;\n }\n case \"FunctionDeclaration\": {\n const [fn] = collectBoundNames(node);\n const env = getRunningContext().LexicalEnvironment;\n const fo = OrdinaryFunctionCreate(node, env);\n env.CreateBinding(fn);\n CallFunction(fo, parent);\n return;\n }\n case \"FunctionExpression\": {\n const closure = InstantiateOrdinaryFunctionExpression(node);\n CallFunction(closure, parent);\n return;\n }\n case \"IfStatement\":\n EvaluateChildren(node, [\"test\", \"consequent\", \"alternate\"], parent);\n return;\n case \"ReturnStatement\":\n case \"ThrowStatement\":\n case \"UpdateExpression\":\n EvaluateChildren(node, [\"argument\"], parent);\n return;\n case \"SwitchCase\":\n EvaluateChildren(node, [\"test\", \"consequent\"], parent);\n return;\n case \"SwitchStatement\": {\n EvaluateChildren(node, [\"discriminant\"], parent);\n const runningContext = getRunningContext();\n const oldEnv = runningContext.LexicalEnvironment;\n const blockEnv = new AnalysisEnvironment(oldEnv);\n BlockDeclarationInstantiation(node.cases, blockEnv);\n runningContext.LexicalEnvironment = blockEnv;\n EvaluateChildren(node, [\"cases\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n return;\n }\n case \"TryStatement\":\n EvaluateChildren(node, [\"block\", \"handler\", \"finalizer\"], parent);\n return;\n case \"VariableDeclaration\":\n EvaluateChildren(node, [\"declarations\"], parent);\n return;\n case \"VariableDeclarator\":\n EvaluateChildren(node, [\"id\", \"init\"], parent);\n return;\n case \"WhileStatement\":\n EvaluateChildren(node, [\"test\", \"body\"], parent);\n return;\n }\n }\n const silent = hooks.beforeVisitUnknown?.(node, parent);\n if (!silent) {\n // eslint-disable-next-line no-console\n console.warn(`Unsupported node type \\`${node.type}\\``);\n }\n }\n }\n\n function BoundNamesInstantiation(\n declarations: NodeWithBoundNames | NodeWithBoundNames[],\n env: AnalysisEnvironment\n ): void {\n for (const name of collectBoundNames(declarations)) {\n env.CreateBinding(name);\n }\n }\n\n function ResolveBinding(name: string): boolean {\n const env = getRunningContext().LexicalEnvironment;\n return GetIdentifierReference(env, name);\n }\n\n function GetIdentifierReference(\n env: AnalysisEnvironment,\n name: string\n ): boolean {\n return (\n !!env &&\n (env.HasBinding(name) || GetIdentifierReference(env.OuterEnv, name))\n );\n }\n\n function BlockDeclarationInstantiation(\n code: Statement[] | SwitchCase[],\n env: AnalysisEnvironment\n ): void {\n const declarations = collectScopedDeclarations(code, {\n var: false,\n topLevel: false,\n });\n BoundNamesInstantiation(declarations, env);\n }\n\n function CallFunction(\n closure: AnalysisFunctionObject,\n parent?: EstreeParent\n ): void {\n PrepareOrdinaryCall(closure);\n FunctionDeclarationInstantiation(closure, parent);\n Evaluate(\n closure.ECMAScriptCode,\n parent\n ?.concat({\n node: closure.Function,\n key: \"body\",\n })\n .concat(\n closure.Function.body.type === \"BlockStatement\"\n ? {\n node: closure.Function.body,\n key: \"body\",\n }\n : []\n )\n );\n analysisContextStack.pop();\n }\n\n function PrepareOrdinaryCall(F: AnalysisFunctionObject): void {\n const calleeContext = new AnalysisContext();\n const localEnv = new AnalysisEnvironment(F.Environment);\n calleeContext.VariableEnvironment = localEnv;\n calleeContext.LexicalEnvironment = localEnv;\n analysisContextStack.push(calleeContext);\n }\n\n function FunctionDeclarationInstantiation(\n func: AnalysisFunctionObject,\n parent?: EstreeParent\n ): void {\n const calleeContext = getRunningContext();\n const code = func.ECMAScriptCode;\n const formals = func.FormalParameters;\n const hasParameterExpressions = containsExpression(formals);\n const varDeclarations = collectScopedDeclarations(code, {\n var: true,\n topLevel: true,\n });\n const varNames = collectBoundNames(varDeclarations);\n\n const env = calleeContext.LexicalEnvironment;\n BoundNamesInstantiation(formals, env);\n\n Evaluate(formals, parent?.concat({ node: func.Function, key: \"params\" }));\n\n let varEnv: AnalysisEnvironment;\n if (!hasParameterExpressions) {\n // NOTE: Only a single Environment Record is needed for the parameters\n // and top-level vars.\n for (const n of varNames) {\n env.CreateBinding(n);\n }\n varEnv = env;\n } else {\n // NOTE: A separate Environment Record is needed to ensure that closures\n // created by expressions in the formal parameter list do not have\n // visibility of declarations in the function body.\n varEnv = new AnalysisEnvironment(env);\n calleeContext.VariableEnvironment = varEnv;\n for (const n of varNames) {\n varEnv.CreateBinding(n);\n }\n }\n const lexEnv = varEnv;\n calleeContext.LexicalEnvironment = lexEnv;\n\n const lexDeclarations = collectScopedDeclarations(code, {\n var: false,\n topLevel: true,\n });\n BoundNamesInstantiation(lexDeclarations, lexEnv);\n }\n\n function InstantiateOrdinaryFunctionExpression(\n functionExpression: FunctionExpression\n ): AnalysisFunctionObject {\n const scope = getRunningContext().LexicalEnvironment;\n if (!functionExpression.id) {\n return OrdinaryFunctionCreate(functionExpression, scope);\n }\n const name = functionExpression.id.name;\n const funcEnv = new AnalysisEnvironment(scope);\n funcEnv.CreateBinding(name);\n return OrdinaryFunctionCreate(functionExpression, funcEnv);\n }\n\n function OrdinaryFunctionCreate(\n func: FunctionDeclaration | FunctionExpression | ArrowFunctionExpression,\n scope: AnalysisEnvironment\n ): AnalysisFunctionObject {\n return {\n Function: func,\n FormalParameters: func.params,\n ECMAScriptCode:\n func.body.type === \"BlockStatement\" ? func.body.body : func.body,\n Environment: scope,\n };\n }\n\n Evaluate(rootAst, withParent ? [] : undefined);\n\n return attemptToVisitGlobals;\n}\n"],"mappings":";AAUA,SAASA,cAAc,QAAQ,kBAAkB;AACjD,SACEC,eAAe,EACfC,mBAAmB,QAEd,mBAAmB;AAE1B,SACEC,iBAAiB,EACjBC,yBAAyB,EACzBC,kBAAkB,QACb,YAAY;AAyBnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAO,CACrBC,OAAyC,EAE5B;EAAA,IADb;IAAEC,cAAc;IAAEC,QAAQ;IAAEC,UAAU;IAAEC,KAAK,GAAG,CAAC;EAAkB,CAAC,uEAAG,CAAC,CAAC;EAEzE,IAAMC,qBAAqB,GAAG,IAAIC,GAAG,EAAU;EAC/C,IAAMC,oBAAuC,GAAG,EAAE;EAClD,IAAMC,OAAO,GAAG,IAAIb,mBAAmB,CAAC,IAAI,CAAC;EAC7C,IAAMc,WAAW,GAAG,IAAIf,eAAe,EAAE;EACzCe,WAAW,CAACC,mBAAmB,GAAGF,OAAO;EACzCC,WAAW,CAACE,kBAAkB,GAAGH,OAAO;EACxCD,oBAAoB,CAACK,IAAI,CAACH,WAAW,CAAC;EAEtC,SAASI,iBAAiB,GAAoB;IAC5C,OAAON,oBAAoB,CAACA,oBAAoB,CAACO,MAAM,GAAG,CAAC,CAAC;EAC9D;EAEA,SAAS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ClD;EAEA,SAAS7B,qCAAqC,CAC5C+B,kBAAsC,EACd;IACxB,IAAMC,KAAK,GAAG7E,iBAAiB,EAAE,CAACF,kBAAkB;IACpD,IAAI,CAAC8E,kBAAkB,CAACE,EAAE,EAAE;MAC1B,OAAOtD,sBAAsB,CAACoD,kBAAkB,EAAEC,KAAK,CAAC;IAC1D;IACA,IAAM1D,IAAI,GAAGyD,kBAAkB,CAACE,EAAE,CAAC3D,IAAI;IACvC,IAAM4D,OAAO,GAAG,IAAIjG,mBAAmB,CAAC+F,KAAK,CAAC;IAC9CE,OAAO,CAACnC,aAAa,CAACzB,IAAI,CAAC;IAC3B,OAAOK,sBAAsB,CAACoD,kBAAkB,EAAEG,OAAO,CAAC;EAC5D;EAEA,SAASvD,sBAAsB,CAC7B2C,IAAwE,EACxEU,KAA0B,EACF;IACxB,OAAO;MACLhB,QAAQ,EAAEM,IAAI;MACdE,gBAAgB,EAAEF,IAAI,CAACa,MAAM;MAC7BpB,cAAc,EACZO,IAAI,CAACxC,IAAI,CAACvB,IAAI,KAAK,gBAAgB,GAAG+D,IAAI,CAACxC,IAAI,CAACA,IAAI,GAAGwC,IAAI,CAACxC,IAAI;MAClEuC,WAAW,EAAEW;IACf,CAAC;EACH;EAEApE,QAAQ,CAACtB,OAAO,EAAEG,UAAU,GAAG,EAAE,GAAG2F,SAAS,CAAC;EAE9C,OAAOzF,qBAAqB;AAC9B"}
|
|
1
|
+
{"version":3,"file":"precook.js","names":["hasOwnProperty","AnalysisContext","AnalysisEnvironment","collectBoundNames","collectScopedDeclarations","containsExpression","precook","rootAst","expressionOnly","visitors","withParent","hooks","arguments","length","undefined","attemptToVisitGlobals","Set","analysisContextStack","rootEnv","rootContext","VariableEnvironment","LexicalEnvironment","push","getRunningContext","visit","node","type","EvaluateChildren","keys","parent","key","Evaluate","concat","Array","isArray","forEach","n","index","slice","_objectSpread","_hooks$beforeVisit","_hooks$beforeVisitUnk","beforeVisit","call","ResolveBinding","name","_hooks$beforeVisitGlo","beforeVisitGlobal","add","env","closure","OrdinaryFunctionCreate","CallFunction","computed","body","runningContext","oldEnv","blockEnv","BlockDeclarationInstantiation","catchEnv","BoundNamesInstantiation","param","lexicalBinding","left","kind","newEnv","iterationEnv","_node$init","init","loopEnv","fn","fo","CreateBinding","InstantiateOrdinaryFunctionExpression","cases","silent","beforeVisitUnknown","console","warn","declarations","GetIdentifierReference","HasBinding","OuterEnv","code","var","topLevel","PrepareOrdinaryCall","FunctionDeclarationInstantiation","ECMAScriptCode","Function","pop","F","calleeContext","localEnv","Environment","func","formals","FormalParameters","hasParameterExpressions","varDeclarations","varNames","varEnv","lexEnv","lexDeclarations","functionExpression","scope","id","funcEnv","params"],"sources":["../../src/precook.ts"],"sourcesContent":["import {\n ArrowFunctionExpression,\n Expression,\n FunctionDeclaration,\n FunctionExpression,\n Identifier,\n Statement,\n SwitchCase,\n VariableDeclaration,\n} from \"@babel/types\";\nimport { hasOwnProperty } from \"./hasOwnProperty.js\";\nimport {\n AnalysisContext,\n AnalysisEnvironment,\n AnalysisFunctionObject,\n} from \"./AnalysisContext.js\";\nimport {\n EstreeNode,\n EstreeVisitors,\n NodeWithBoundNames,\n} from \"./interfaces.js\";\nimport {\n collectBoundNames,\n collectScopedDeclarations,\n containsExpression,\n} from \"./traverse.js\";\n\nexport interface PrecookOptions {\n expressionOnly?: boolean;\n /** @deprecated Use hooks instead. */\n visitors?: EstreeVisitors;\n hooks?: PrecookHooks;\n withParent?: boolean;\n}\n\nexport type EstreeParent = EstreeParentItem[];\n\nexport interface EstreeParentItem {\n node: EstreeNode;\n key: string;\n index?: number;\n}\n\nexport interface PrecookHooks {\n beforeVisit?(node: EstreeNode, parent?: EstreeParent): void;\n beforeVisitGlobal?(node: Identifier, parent?: EstreeParent): void;\n /** Return true if want to silent warnings for unknown nodes. */\n beforeVisitUnknown?(node: EstreeNode, parent?: EstreeParent): boolean | void;\n}\n\n/**\n * Analysis an AST of a storyboard function or an evaluation expression.\n *\n * @param rootAst - The root AST.\n * @param options - Analysis options.\n * @returns A set of global variables the root AST attempts to access.\n */\nexport function precook(\n rootAst: Expression | FunctionDeclaration,\n { expressionOnly, visitors, withParent, hooks = {} }: PrecookOptions = {}\n): Set<string> {\n const attemptToVisitGlobals = new Set<string>();\n const analysisContextStack: AnalysisContext[] = [];\n const rootEnv = new AnalysisEnvironment(null);\n const rootContext = new AnalysisContext();\n rootContext.VariableEnvironment = rootEnv;\n rootContext.LexicalEnvironment = rootEnv;\n analysisContextStack.push(rootContext);\n\n function getRunningContext(): AnalysisContext {\n return analysisContextStack[analysisContextStack.length - 1];\n }\n\n function visit(node: EstreeNode): void {\n if (visitors && hasOwnProperty(visitors, node.type)) {\n visitors[node.type](node);\n }\n }\n\n function EvaluateChildren<T extends EstreeNode>(\n node: T,\n keys: (keyof T)[],\n parent?: EstreeParent\n ): void {\n for (const key of keys) {\n Evaluate(\n node[key] as unknown as EstreeNode | EstreeNode[],\n parent?.concat({ node, key } as EstreeParentItem)\n );\n }\n }\n\n function Evaluate(\n node: EstreeNode | EstreeNode[],\n parent?: EstreeParent\n ): void {\n if (Array.isArray(node)) {\n node.forEach((n, index) => {\n Evaluate(\n n,\n parent\n ? parent.slice(0, -1).concat({\n ...parent[parent.length - 1],\n index,\n })\n : parent\n );\n });\n } else if (node) {\n // `node` maybe `null` in some cases.\n hooks.beforeVisit?.(node, parent);\n visit(node);\n // Expressions:\n switch (node.type) {\n case \"Identifier\":\n if (!ResolveBinding(node.name)) {\n hooks.beforeVisitGlobal?.(node, parent);\n attemptToVisitGlobals.add(node.name);\n }\n return;\n case \"ArrayExpression\":\n case \"ArrayPattern\":\n EvaluateChildren(node, [\"elements\"], parent);\n return;\n case \"ArrowFunctionExpression\": {\n const env = getRunningContext().LexicalEnvironment;\n const closure = OrdinaryFunctionCreate(node, env);\n CallFunction(closure, parent);\n return;\n }\n case \"AssignmentPattern\":\n case \"BinaryExpression\":\n case \"LogicalExpression\":\n EvaluateChildren(node, [\"left\", \"right\"], parent);\n return;\n case \"CallExpression\":\n case \"NewExpression\":\n EvaluateChildren(node, [\"callee\", \"arguments\"], parent);\n return;\n case \"ChainExpression\":\n EvaluateChildren(node, [\"expression\"], parent);\n return;\n case \"ConditionalExpression\":\n EvaluateChildren(node, [\"test\", \"consequent\", \"alternate\"], parent);\n return;\n case \"MemberExpression\":\n EvaluateChildren(node, [\"object\"], parent);\n if (node.computed) {\n EvaluateChildren(node, [\"property\"], parent);\n }\n return;\n case \"ObjectExpression\":\n case \"ObjectPattern\":\n EvaluateChildren(node, [\"properties\"], parent);\n return;\n case \"Property\":\n if (node.computed) {\n EvaluateChildren(node, [\"key\"], parent);\n }\n EvaluateChildren(node, [\"value\"], parent);\n return;\n case \"RestElement\":\n case \"SpreadElement\":\n case \"UnaryExpression\":\n EvaluateChildren(node, [\"argument\"], parent);\n return;\n case \"SequenceExpression\":\n case \"TemplateLiteral\":\n EvaluateChildren(node, [\"expressions\"], parent);\n return;\n case \"TaggedTemplateExpression\":\n EvaluateChildren(node, [\"tag\", \"quasi\"], parent);\n return;\n case \"Literal\":\n return;\n }\n if (!expressionOnly) {\n // Statements and assignments:\n switch (node.type) {\n case \"AssignmentExpression\":\n EvaluateChildren(node, [\"right\", \"left\"], parent);\n return;\n case \"BlockStatement\": {\n if (!node.body.length) {\n return;\n }\n const runningContext = getRunningContext();\n const oldEnv = runningContext.LexicalEnvironment;\n const blockEnv = new AnalysisEnvironment(oldEnv);\n BlockDeclarationInstantiation(node.body, blockEnv);\n runningContext.LexicalEnvironment = blockEnv;\n EvaluateChildren(node, [\"body\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n return;\n }\n case \"BreakStatement\":\n case \"ContinueStatement\":\n case \"EmptyStatement\":\n return;\n case \"CatchClause\": {\n const runningContext = getRunningContext();\n const oldEnv = runningContext.LexicalEnvironment;\n const catchEnv = new AnalysisEnvironment(oldEnv);\n BoundNamesInstantiation(node.param, catchEnv);\n runningContext.LexicalEnvironment = catchEnv;\n EvaluateChildren(node, [\"param\", \"body\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n return;\n }\n case \"DoWhileStatement\":\n EvaluateChildren(node, [\"body\", \"test\"], parent);\n return;\n case \"ExpressionStatement\":\n case \"TSAsExpression\":\n EvaluateChildren(node, [\"expression\"], parent);\n return;\n case \"ForInStatement\":\n case \"ForOfStatement\": {\n // ForIn/OfHeadEvaluation\n const lexicalBinding =\n node.left.type === \"VariableDeclaration\" &&\n node.left.kind !== \"var\";\n const runningContext = getRunningContext();\n const oldEnv = runningContext.LexicalEnvironment;\n if (lexicalBinding) {\n const newEnv = new AnalysisEnvironment(oldEnv);\n BoundNamesInstantiation(node.left, newEnv);\n runningContext.LexicalEnvironment = newEnv;\n }\n EvaluateChildren(node, [\"right\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n\n // ForIn/OfBodyEvaluation\n if (lexicalBinding) {\n const iterationEnv = new AnalysisEnvironment(oldEnv);\n BoundNamesInstantiation(node.left, iterationEnv);\n runningContext.LexicalEnvironment = iterationEnv;\n }\n EvaluateChildren(node, [\"left\", \"body\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n return;\n }\n case \"ForStatement\": {\n const lexicalBinding =\n node.init?.type === \"VariableDeclaration\" &&\n node.init.kind !== \"var\";\n const runningContext = getRunningContext();\n const oldEnv = runningContext.LexicalEnvironment;\n if (lexicalBinding) {\n const loopEnv = new AnalysisEnvironment(oldEnv);\n BoundNamesInstantiation(\n node.init as VariableDeclaration,\n loopEnv\n );\n runningContext.LexicalEnvironment = loopEnv;\n }\n EvaluateChildren(node, [\"init\", \"test\", \"body\", \"update\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n return;\n }\n case \"FunctionDeclaration\": {\n const [fn] = collectBoundNames(node);\n const env = getRunningContext().LexicalEnvironment!;\n const fo = OrdinaryFunctionCreate(node, env);\n env.CreateBinding(fn);\n CallFunction(fo, parent);\n return;\n }\n case \"FunctionExpression\": {\n const closure = InstantiateOrdinaryFunctionExpression(node);\n CallFunction(closure, parent);\n return;\n }\n case \"IfStatement\":\n EvaluateChildren(node, [\"test\", \"consequent\", \"alternate\"], parent);\n return;\n case \"ReturnStatement\":\n case \"ThrowStatement\":\n case \"UpdateExpression\":\n EvaluateChildren(node, [\"argument\"], parent);\n return;\n case \"SwitchCase\":\n EvaluateChildren(node, [\"test\", \"consequent\"], parent);\n return;\n case \"SwitchStatement\": {\n EvaluateChildren(node, [\"discriminant\"], parent);\n const runningContext = getRunningContext();\n const oldEnv = runningContext.LexicalEnvironment;\n const blockEnv = new AnalysisEnvironment(oldEnv);\n BlockDeclarationInstantiation(node.cases, blockEnv);\n runningContext.LexicalEnvironment = blockEnv;\n EvaluateChildren(node, [\"cases\"], parent);\n runningContext.LexicalEnvironment = oldEnv;\n return;\n }\n case \"TryStatement\":\n EvaluateChildren(node, [\"block\", \"handler\", \"finalizer\"], parent);\n return;\n case \"VariableDeclaration\":\n EvaluateChildren(node, [\"declarations\"], parent);\n return;\n case \"VariableDeclarator\":\n EvaluateChildren(node, [\"id\", \"init\"], parent);\n return;\n case \"WhileStatement\":\n EvaluateChildren(node, [\"test\", \"body\"], parent);\n return;\n }\n }\n const silent = hooks.beforeVisitUnknown?.(node, parent);\n if (!silent) {\n // eslint-disable-next-line no-console\n console.warn(`Unsupported node type \\`${node.type}\\``);\n }\n }\n }\n\n function BoundNamesInstantiation(\n declarations: NodeWithBoundNames | NodeWithBoundNames[] | null | undefined,\n env: AnalysisEnvironment\n ): void {\n for (const name of collectBoundNames(declarations)) {\n env.CreateBinding(name);\n }\n }\n\n function ResolveBinding(name: string): boolean {\n const env = getRunningContext().LexicalEnvironment;\n return GetIdentifierReference(env, name);\n }\n\n function GetIdentifierReference(\n env: AnalysisEnvironment | null | undefined,\n name: string\n ): boolean {\n return (\n !!env &&\n (env.HasBinding(name) || GetIdentifierReference(env.OuterEnv, name))\n );\n }\n\n function BlockDeclarationInstantiation(\n code: Statement[] | SwitchCase[],\n env: AnalysisEnvironment\n ): void {\n const declarations = collectScopedDeclarations(code, {\n var: false,\n topLevel: false,\n });\n BoundNamesInstantiation(declarations, env);\n }\n\n function CallFunction(\n closure: AnalysisFunctionObject,\n parent?: EstreeParent\n ): void {\n PrepareOrdinaryCall(closure);\n FunctionDeclarationInstantiation(closure, parent);\n Evaluate(\n closure.ECMAScriptCode,\n parent\n ?.concat({\n node: closure.Function,\n key: \"body\",\n })\n .concat(\n closure.Function.body.type === \"BlockStatement\"\n ? {\n node: closure.Function.body,\n key: \"body\",\n }\n : []\n )\n );\n analysisContextStack.pop();\n }\n\n function PrepareOrdinaryCall(F: AnalysisFunctionObject): void {\n const calleeContext = new AnalysisContext();\n const localEnv = new AnalysisEnvironment(F.Environment);\n calleeContext.VariableEnvironment = localEnv;\n calleeContext.LexicalEnvironment = localEnv;\n analysisContextStack.push(calleeContext);\n }\n\n function FunctionDeclarationInstantiation(\n func: AnalysisFunctionObject,\n parent?: EstreeParent\n ): void {\n const calleeContext = getRunningContext();\n const code = func.ECMAScriptCode;\n const formals = func.FormalParameters;\n const hasParameterExpressions = containsExpression(formals);\n const varDeclarations = collectScopedDeclarations(code, {\n var: true,\n topLevel: true,\n });\n const varNames = collectBoundNames(varDeclarations);\n\n const env = calleeContext.LexicalEnvironment!;\n BoundNamesInstantiation(formals, env);\n\n Evaluate(formals, parent?.concat({ node: func.Function, key: \"params\" }));\n\n let varEnv: AnalysisEnvironment;\n if (!hasParameterExpressions) {\n // NOTE: Only a single Environment Record is needed for the parameters\n // and top-level vars.\n for (const n of varNames) {\n env.CreateBinding(n);\n }\n varEnv = env;\n } else {\n // NOTE: A separate Environment Record is needed to ensure that closures\n // created by expressions in the formal parameter list do not have\n // visibility of declarations in the function body.\n varEnv = new AnalysisEnvironment(env);\n calleeContext.VariableEnvironment = varEnv;\n for (const n of varNames) {\n varEnv.CreateBinding(n);\n }\n }\n const lexEnv = varEnv;\n calleeContext.LexicalEnvironment = lexEnv;\n\n const lexDeclarations = collectScopedDeclarations(code, {\n var: false,\n topLevel: true,\n });\n BoundNamesInstantiation(lexDeclarations, lexEnv);\n }\n\n function InstantiateOrdinaryFunctionExpression(\n functionExpression: FunctionExpression\n ): AnalysisFunctionObject {\n const scope = getRunningContext().LexicalEnvironment;\n if (!functionExpression.id) {\n return OrdinaryFunctionCreate(functionExpression, scope);\n }\n const name = functionExpression.id.name;\n const funcEnv = new AnalysisEnvironment(scope);\n funcEnv.CreateBinding(name);\n return OrdinaryFunctionCreate(functionExpression, funcEnv);\n }\n\n function OrdinaryFunctionCreate(\n func: FunctionDeclaration | FunctionExpression | ArrowFunctionExpression,\n scope?: AnalysisEnvironment\n ): AnalysisFunctionObject {\n return {\n Function: func,\n FormalParameters: func.params,\n ECMAScriptCode:\n func.body.type === \"BlockStatement\" ? func.body.body : func.body,\n Environment: scope,\n };\n }\n\n Evaluate(rootAst, withParent ? [] : undefined);\n\n return attemptToVisitGlobals;\n}\n"],"mappings":";AAUA,SAASA,cAAc,QAAQ,qBAAqB;AACpD,SACEC,eAAe,EACfC,mBAAmB,QAEd,sBAAsB;AAM7B,SACEC,iBAAiB,EACjBC,yBAAyB,EACzBC,kBAAkB,QACb,eAAe;AAyBtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CACrBC,OAAyC,EAE5B;EAAA,IADb;IAAEC,cAAc;IAAEC,QAAQ;IAAEC,UAAU;IAAEC,KAAK,GAAG,CAAC;EAAkB,CAAC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEzE,IAAMG,qBAAqB,GAAG,IAAIC,GAAG,EAAU;EAC/C,IAAMC,oBAAuC,GAAG,EAAE;EAClD,IAAMC,OAAO,GAAG,IAAIhB,mBAAmB,CAAC,IAAI,CAAC;EAC7C,IAAMiB,WAAW,GAAG,IAAIlB,eAAe,EAAE;EACzCkB,WAAW,CAACC,mBAAmB,GAAGF,OAAO;EACzCC,WAAW,CAACE,kBAAkB,GAAGH,OAAO;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AAO,EAAEG,UAAU,GAAG,EAAE,GAAGI,SAAS,CAAC;EAE9C,OAAOC,qBAAqB;AAC9B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
2
|
var _excluded = ["typescript"];
|
|
3
|
-
import { parseAsEstree } from "./parse";
|
|
4
|
-
import { precook } from "./precook";
|
|
3
|
+
import { parseAsEstree } from "./parse.js";
|
|
4
|
+
import { precook } from "./precook.js";
|
|
5
5
|
export function precookFunction(source) {
|
|
6
6
|
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
7
7
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"precookFunction.js","names":["parseAsEstree","precook","precookFunction","source","typescript","restOptions","func","attemptToVisitGlobals","function"],"sources":["../../src/precookFunction.ts"],"sourcesContent":["import { FunctionDeclaration } from \"@babel/types\";\nimport { parseAsEstree } from \"./parse\";\nimport { precook, PrecookOptions } from \"./precook\";\n\nexport interface PrecookFunctionOptions extends PrecookOptions {\n typescript?: boolean;\n}\n\nexport interface PrecookFunctionResult {\n function: FunctionDeclaration;\n attemptToVisitGlobals: Set<string>;\n}\n\nexport function precookFunction(\n source: string,\n { typescript, ...restOptions }: PrecookFunctionOptions = {}\n): PrecookFunctionResult {\n const func = parseAsEstree(source, { typescript });\n const attemptToVisitGlobals = precook(func, restOptions);\n return {\n function: func,\n attemptToVisitGlobals,\n };\n}\n"],"mappings":";;AACA,SAASA,aAAa,QAAQ,
|
|
1
|
+
{"version":3,"file":"precookFunction.js","names":["parseAsEstree","precook","precookFunction","source","_ref","arguments","length","undefined","typescript","restOptions","_objectWithoutProperties","_excluded","func","attemptToVisitGlobals","function"],"sources":["../../src/precookFunction.ts"],"sourcesContent":["import { FunctionDeclaration } from \"@babel/types\";\nimport { parseAsEstree } from \"./parse.js\";\nimport { precook, PrecookOptions } from \"./precook.js\";\n\nexport interface PrecookFunctionOptions extends PrecookOptions {\n typescript?: boolean;\n}\n\nexport interface PrecookFunctionResult {\n function: FunctionDeclaration;\n attemptToVisitGlobals: Set<string>;\n}\n\nexport function precookFunction(\n source: string,\n { typescript, ...restOptions }: PrecookFunctionOptions = {}\n): PrecookFunctionResult {\n const func = parseAsEstree(source, { typescript });\n const attemptToVisitGlobals = precook(func, restOptions);\n return {\n function: func,\n attemptToVisitGlobals,\n };\n}\n"],"mappings":";;AACA,SAASA,aAAa,QAAQ,YAAY;AAC1C,SAASC,OAAO,QAAwB,cAAc;AAWtD,OAAO,SAASC,eAAeA,CAC7BC,MAAc,EAES;EAAA,IAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MADkC,CAAC,CAAC;IAA3D;MAAEG;IAAmD,CAAC,GAAAJ,IAAA;IAArCK,WAAW,GAAAC,wBAAA,CAAAN,IAAA,EAAAO,SAAA;EAE5B,IAAMC,IAAI,GAAGZ,aAAa,CAACG,MAAM,EAAE;IAAEK;EAAW,CAAC,CAAC;EAClD,IAAMK,qBAAqB,GAAGZ,OAAO,CAACW,IAAI,EAAEH,WAAW,CAAC;EACxD,OAAO;IACLK,QAAQ,EAAEF,IAAI;IACdC;EACF,CAAC;AACH"}
|
package/dist/esm/preevaluate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
-
import { parseAsEstreeExpression } from "./parse";
|
|
3
|
-
import { precook } from "./precook";
|
|
2
|
+
import { parseAsEstreeExpression } from "./parse.js";
|
|
3
|
+
import { precook } from "./precook.js";
|
|
4
4
|
// `raw` should always be asserted by `isEvaluable`.
|
|
5
5
|
export function preevaluate(raw, options) {
|
|
6
6
|
var fixes = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preevaluate.js","names":["parseAsEstreeExpression","precook","preevaluate","raw","options","fixes","source","replace","m","push","expression","attemptToVisitGlobals","expressionOnly","prefix","suffix","isEvaluable","test","shouldAllowRecursiveEvaluations"],"sources":["../../src/preevaluate.ts"],"sourcesContent":["import { Expression } from \"@babel/types\";\nimport { parseAsEstreeExpression } from \"./parse\";\nimport { precook, PrecookOptions } from \"./precook\";\n\nexport type PreevaluateOptions = Omit<PrecookOptions, \"expressionOnly\">;\n\nexport interface PreevaluateResult {\n expression: Expression;\n attemptToVisitGlobals: Set<string>;\n source: string;\n prefix: string;\n suffix: string;\n}\n\n// `raw` should always be asserted by `isEvaluable`.\nexport function preevaluate(\n raw: string,\n options?: PreevaluateOptions\n): PreevaluateResult {\n const fixes: string[] = [];\n const source = raw.replace(/^\\s*<%~?\\s|\\s%>\\s*$/g, (m) => {\n fixes.push(m);\n return \"\";\n });\n const expression = parseAsEstreeExpression(source);\n const attemptToVisitGlobals = precook(expression, {\n ...options,\n expressionOnly: true,\n });\n return {\n expression,\n attemptToVisitGlobals,\n source,\n prefix: fixes[0],\n suffix: fixes[1],\n };\n}\n\nexport function isEvaluable(raw: string): boolean {\n return /^\\s*<%~?\\s/.test(raw) && /\\s%>\\s*$/.test(raw);\n}\n\nexport function shouldAllowRecursiveEvaluations(raw: string): boolean {\n return /^\\s*<%~\\s/.test(raw);\n}\n"],"mappings":";AACA,SAASA,uBAAuB,QAAQ,
|
|
1
|
+
{"version":3,"file":"preevaluate.js","names":["parseAsEstreeExpression","precook","preevaluate","raw","options","fixes","source","replace","m","push","expression","attemptToVisitGlobals","_objectSpread","expressionOnly","prefix","suffix","isEvaluable","test","shouldAllowRecursiveEvaluations"],"sources":["../../src/preevaluate.ts"],"sourcesContent":["import { Expression } from \"@babel/types\";\nimport { parseAsEstreeExpression } from \"./parse.js\";\nimport { precook, PrecookOptions } from \"./precook.js\";\n\nexport type PreevaluateOptions = Omit<PrecookOptions, \"expressionOnly\">;\n\nexport interface PreevaluateResult {\n expression: Expression;\n attemptToVisitGlobals: Set<string>;\n source: string;\n prefix: string;\n suffix: string;\n}\n\n// `raw` should always be asserted by `isEvaluable`.\nexport function preevaluate(\n raw: string,\n options?: PreevaluateOptions\n): PreevaluateResult {\n const fixes: string[] = [];\n const source = raw.replace(/^\\s*<%~?\\s|\\s%>\\s*$/g, (m) => {\n fixes.push(m);\n return \"\";\n });\n const expression = parseAsEstreeExpression(source);\n const attemptToVisitGlobals = precook(expression, {\n ...options,\n expressionOnly: true,\n });\n return {\n expression,\n attemptToVisitGlobals,\n source,\n prefix: fixes[0],\n suffix: fixes[1],\n };\n}\n\nexport function isEvaluable(raw: string): boolean {\n return /^\\s*<%~?\\s/.test(raw) && /\\s%>\\s*$/.test(raw);\n}\n\nexport function shouldAllowRecursiveEvaluations(raw: string): boolean {\n return /^\\s*<%~\\s/.test(raw);\n}\n"],"mappings":";AACA,SAASA,uBAAuB,QAAQ,YAAY;AACpD,SAASC,OAAO,QAAwB,cAAc;AAYtD;AACA,OAAO,SAASC,WAAWA,CACzBC,GAAW,EACXC,OAA4B,EACT;EACnB,IAAMC,KAAe,GAAG,EAAE;EAC1B,IAAMC,MAAM,GAAGH,GAAG,CAACI,OAAO,CAAC,sBAAsB,EAAGC,CAAC,IAAK;IACxDH,KAAK,CAACI,IAAI,CAACD,CAAC,CAAC;IACb,OAAO,EAAE;EACX,CAAC,CAAC;EACF,IAAME,UAAU,GAAGV,uBAAuB,CAACM,MAAM,CAAC;EAClD,IAAMK,qBAAqB,GAAGV,OAAO,CAACS,UAAU,EAAAE,aAAA,CAAAA,aAAA,KAC3CR,OAAO;IACVS,cAAc,EAAE;EAAI,GACpB;EACF,OAAO;IACLH,UAAU;IACVC,qBAAqB;IACrBL,MAAM;IACNQ,MAAM,EAAET,KAAK,CAAC,CAAC,CAAC;IAChBU,MAAM,EAAEV,KAAK,CAAC,CAAC;EACjB,CAAC;AACH;AAEA,OAAO,SAASW,WAAWA,CAACb,GAAW,EAAW;EAChD,OAAO,YAAY,CAACc,IAAI,CAACd,GAAG,CAAC,IAAI,UAAU,CAACc,IAAI,CAACd,GAAG,CAAC;AACvD;AAEA,OAAO,SAASe,+BAA+BA,CAACf,GAAW,EAAW;EACpE,OAAO,WAAW,CAACc,IAAI,CAACd,GAAG,CAAC;AAC9B"}
|
package/dist/esm/sanitize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.js","names":["getGlobal","self","window","global","Error","reservedObjects","WeakSet","Function","Object","prototype","sanitize","cooked","has","TypeError","allowedConstructors","Array","Map","Set","URLSearchParams","WeakMap","isAllowedConstructor","constructor","Date"],"sources":["../../src/sanitize.ts"],"sourcesContent":["// Ref https://github.com/tc39/proposal-global\n// In addition, the es6-shim had to switch from Function('return this')()\n// due to CSP concerns, such that the current check to handle browsers,\n// node, web workers, and frames is:\n// istanbul ignore next\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction getGlobal(): object {\n // the only reliable means to get the global object is\n // `Function('return this')()`\n // However, this causes CSP violations in Chrome apps.\n if (typeof self !== \"undefined\") {\n return self;\n }\n if (typeof window !== \"undefined\") {\n return window;\n }\n if (typeof global !== \"undefined\") {\n return global;\n }\n throw new Error(\"unable to locate global object\");\n}\n\n/**\n * There are chances to construct a `Function` from a string, etc.\n * ```\n * ((a,b)=>a[b])(()=>1, 'constructor')('console.log(`yo`)')()\n * ```\n */\nconst reservedObjects = new WeakSet([\n // `Function(\"...\")` is considered *extremely vulnerable*.\n Function,\n // `Object.assign()` is considered vulnerable.\n Object,\n // `prototype` is considered vulnerable.\n Function.prototype,\n Object.prototype,\n // Global `window` is considered vulnerable, too.\n getGlobal(),\n]);\n\nexport function sanitize(cooked: unknown): void {\n // eslint-disable-next-line @typescript-eslint/ban-types\n if (reservedObjects.has(cooked as object)) {\n throw new TypeError(\"Cannot access reserved objects such as `Function`.\");\n }\n}\n\nconst allowedConstructors = new WeakSet([\n Array,\n Map,\n Set,\n URLSearchParams,\n WeakMap,\n WeakSet,\n]);\n\nexport function isAllowedConstructor(constructor: unknown): boolean {\n // `Date` maybe mocked when running tests for storyboard functions.\n return (\n allowedConstructors.has(constructor as ArrayConstructor) ||\n constructor === Date\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,
|
|
1
|
+
{"version":3,"file":"sanitize.js","names":["getGlobal","self","window","global","Error","reservedObjects","WeakSet","Function","Object","prototype","sanitize","cooked","has","TypeError","allowedConstructors","Array","Map","Set","URLSearchParams","WeakMap","isAllowedConstructor","constructor","Date"],"sources":["../../src/sanitize.ts"],"sourcesContent":["// Ref https://github.com/tc39/proposal-global\n// In addition, the es6-shim had to switch from Function('return this')()\n// due to CSP concerns, such that the current check to handle browsers,\n// node, web workers, and frames is:\n// istanbul ignore next\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction getGlobal(): object {\n // the only reliable means to get the global object is\n // `Function('return this')()`\n // However, this causes CSP violations in Chrome apps.\n if (typeof self !== \"undefined\") {\n return self;\n }\n if (typeof window !== \"undefined\") {\n return window;\n }\n if (typeof global !== \"undefined\") {\n return global;\n }\n throw new Error(\"unable to locate global object\");\n}\n\n/**\n * There are chances to construct a `Function` from a string, etc.\n * ```\n * ((a,b)=>a[b])(()=>1, 'constructor')('console.log(`yo`)')()\n * ```\n */\nconst reservedObjects = new WeakSet([\n // `Function(\"...\")` is considered *extremely vulnerable*.\n Function,\n // `Object.assign()` is considered vulnerable.\n Object,\n // `prototype` is considered vulnerable.\n Function.prototype,\n Object.prototype,\n // Global `window` is considered vulnerable, too.\n getGlobal(),\n]);\n\nexport function sanitize(cooked: unknown): void {\n // eslint-disable-next-line @typescript-eslint/ban-types\n if (reservedObjects.has(cooked as object)) {\n throw new TypeError(\"Cannot access reserved objects such as `Function`.\");\n }\n}\n\nconst allowedConstructors = new WeakSet([\n Array,\n Map,\n Set,\n URLSearchParams,\n WeakMap,\n WeakSet,\n]);\n\nexport function isAllowedConstructor(constructor: unknown): boolean {\n // `Date` maybe mocked when running tests for storyboard functions.\n return (\n allowedConstructors.has(constructor as ArrayConstructor) ||\n constructor === Date\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,SAASA,CAAA,EAAW;EAC3B;EACA;EACA;EACA,IAAI,OAAOC,IAAI,KAAK,WAAW,EAAE;IAC/B,OAAOA,IAAI;EACb;EACA,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,OAAOA,MAAM;EACf;EACA,IAAI,OAAOC,MAAM,KAAK,WAAW,EAAE;IACjC,OAAOA,MAAM;EACf;EACA,MAAM,IAAIC,KAAK,CAAC,gCAAgC,CAAC;AACnD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,eAAe,GAAG,IAAIC,OAAO,CAAC;AAClC;AACAC,QAAQ;AACR;AACAC,MAAM;AACN;AACAD,QAAQ,CAACE,SAAS,EAClBD,MAAM,CAACC,SAAS;AAChB;AACAT,SAAS,EAAE,CACZ,CAAC;AAEF,OAAO,SAASU,QAAQA,CAACC,MAAe,EAAQ;EAC9C;EACA,IAAIN,eAAe,CAACO,GAAG,CAACD,MAAM,CAAW,EAAE;IACzC,MAAM,IAAIE,SAAS,CAAC,oDAAoD,CAAC;EAC3E;AACF;AAEA,IAAMC,mBAAmB,GAAG,IAAIR,OAAO,CAAC,CACtCS,KAAK,EACLC,GAAG,EACHC,GAAG,EACHC,eAAe,EACfC,OAAO,EACPb,OAAO,CACR,CAAC;AAEF,OAAO,SAASc,oBAAoBA,CAACC,WAAoB,EAAW;EAClE;EACA,OACEP,mBAAmB,CAACF,GAAG,CAACS,WAAW,CAAqB,IACxDA,WAAW,KAAKC,IAAI;AAExB"}
|
package/dist/esm/traverse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"traverse.js","names":["collectBoundNames","root","names","Set","collect","node","Array","isArray","n","type","add","name","declarations","id","elements","left","properties","value","argument","from","containsExpression","some","computed","collectScopedDeclarations","options","nextOptions","var","Number","topLevel","push","kind","consequent","body","alternate","init","cases","block","handler","finalizer"],"sources":["../../src/traverse.ts"],"sourcesContent":["import { FunctionDeclaration, VariableDeclaration } from \"@babel/types\";\nimport { EstreeNode, NodeWithBoundNames } from \"./interfaces\";\n\ntype InternalCollect<T = void, O = unknown> = (\n node: EstreeNode | EstreeNode[],\n options?: O\n) => T;\ntype InternalCollectWithOptions<T = void, O = unknown> = (\n node: EstreeNode | EstreeNode[],\n options: O\n) => T;\n\nexport function collectBoundNames(\n root: NodeWithBoundNames | NodeWithBoundNames[]\n): string[] {\n const names = new Set<string>();\n const collect: InternalCollect = (node) => {\n if (Array.isArray(node)) {\n for (const n of node) {\n collect(n);\n }\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"Identifier\":\n names.add(node.name);\n return;\n case \"VariableDeclaration\":\n return collect(node.declarations);\n case \"VariableDeclarator\":\n return collect(node.id);\n case \"ArrayPattern\":\n return collect(node.elements);\n case \"AssignmentPattern\":\n return collect(node.left);\n case \"ObjectPattern\":\n return collect(node.properties);\n case \"Property\":\n return collect(node.value);\n case \"RestElement\":\n return collect(node.argument);\n case \"FunctionDeclaration\":\n return collect(node.id);\n }\n }\n };\n collect(root);\n return Array.from(names);\n}\n\nexport function containsExpression(root: EstreeNode | EstreeNode[]): boolean {\n const collect: InternalCollect<boolean> = (node) => {\n if (Array.isArray(node)) {\n return node.some(collect);\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"ArrayPattern\":\n return collect(node.elements);\n case \"AssignmentPattern\":\n return true;\n case \"ObjectPattern\":\n return collect(node.properties);\n case \"Property\":\n return node.computed || collect(node.value);\n case \"RestElement\":\n return collect(node.argument);\n }\n }\n };\n return collect(root);\n}\n\ninterface ScopedDeclarationOptions {\n var?: boolean;\n topLevel?: boolean;\n}\n\ntype ScopedDeclaration = VariableDeclaration | FunctionDeclaration;\n\nexport function collectScopedDeclarations(\n root: EstreeNode | EstreeNode[],\n options: ScopedDeclarationOptions\n): ScopedDeclaration[] {\n const declarations: ScopedDeclaration[] = [];\n const nextOptions = { var: options.var };\n const collect: InternalCollectWithOptions<void, ScopedDeclarationOptions> = (\n node,\n options\n ): void => {\n if (Array.isArray(node)) {\n for (const n of node) {\n collect(n, options);\n }\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"FunctionDeclaration\":\n // At the top level of a function, or script, function declarations are\n // treated like var declarations rather than like lexical declarations.\n // See https://tc39.es/ecma262/#sec-static-semantics-toplevellexicallydeclarednames\n if (Number(!options.var) ^ Number(options.topLevel)) {\n declarations.push(node);\n }\n return;\n case \"VariableDeclaration\":\n if (Number(!options.var) ^ Number(node.kind === \"var\")) {\n declarations.push(node);\n }\n return;\n case \"SwitchCase\":\n collect(node.consequent, nextOptions);\n return;\n case \"CatchClause\":\n collect(node.body, nextOptions);\n return;\n }\n if (options.var) {\n switch (node.type) {\n case \"BlockStatement\":\n collect(node.body, nextOptions);\n return;\n case \"IfStatement\":\n collect(node.consequent, nextOptions);\n collect(node.alternate, nextOptions);\n return;\n case \"DoWhileStatement\":\n case \"WhileStatement\":\n collect(node.body, nextOptions);\n return;\n case \"ForStatement\":\n collect(node.init, nextOptions);\n collect(node.body, nextOptions);\n return;\n case \"ForInStatement\":\n case \"ForOfStatement\":\n collect(node.left, nextOptions);\n collect(node.body, nextOptions);\n return;\n case \"SwitchStatement\":\n collect(node.cases, nextOptions);\n return;\n case \"TryStatement\":\n collect(node.block, nextOptions);\n collect(node.handler, nextOptions);\n collect(node.finalizer, nextOptions);\n return;\n }\n }\n }\n };\n collect(root, options);\n return declarations;\n}\n"],"mappings":"AAYA,OAAO,SAASA,
|
|
1
|
+
{"version":3,"file":"traverse.js","names":["collectBoundNames","root","names","Set","collect","node","Array","isArray","n","type","add","name","declarations","id","elements","left","properties","value","argument","from","containsExpression","some","computed","collectScopedDeclarations","options","nextOptions","var","Number","topLevel","push","kind","consequent","body","alternate","init","cases","block","handler","finalizer"],"sources":["../../src/traverse.ts"],"sourcesContent":["import { FunctionDeclaration, VariableDeclaration } from \"@babel/types\";\nimport { EstreeNode, NodeWithBoundNames } from \"./interfaces.js\";\n\ntype InternalCollect<T = void, O = unknown> = (\n node: EstreeNode | null | undefined | (EstreeNode | null)[],\n options?: O\n) => T;\ntype InternalCollectWithOptions<T = void, O = unknown> = (\n node: EstreeNode | null | undefined | (EstreeNode | null)[],\n options: O\n) => T;\n\nexport function collectBoundNames(\n root: NodeWithBoundNames | NodeWithBoundNames[] | null | undefined\n): string[] {\n const names = new Set<string>();\n const collect: InternalCollect = (node) => {\n if (Array.isArray(node)) {\n for (const n of node) {\n collect(n);\n }\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"Identifier\":\n names.add(node.name);\n return;\n case \"VariableDeclaration\":\n return collect(node.declarations);\n case \"VariableDeclarator\":\n return collect(node.id);\n case \"ArrayPattern\":\n return collect(node.elements);\n case \"AssignmentPattern\":\n return collect(node.left);\n case \"ObjectPattern\":\n return collect(node.properties);\n case \"Property\":\n return collect(node.value);\n case \"RestElement\":\n return collect(node.argument);\n case \"FunctionDeclaration\":\n return collect(node.id);\n }\n }\n };\n collect(root);\n return Array.from(names);\n}\n\nexport function containsExpression(\n root: EstreeNode | EstreeNode[]\n): boolean | undefined {\n const collect: InternalCollect<boolean | undefined> = (node) => {\n if (Array.isArray(node)) {\n return node.some(collect);\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"ArrayPattern\":\n return collect(node.elements);\n case \"AssignmentPattern\":\n return true;\n case \"ObjectPattern\":\n return collect(node.properties);\n case \"Property\":\n return node.computed || collect(node.value);\n case \"RestElement\":\n return collect(node.argument);\n }\n }\n };\n return collect(root);\n}\n\ninterface ScopedDeclarationOptions {\n var?: boolean;\n topLevel?: boolean;\n}\n\ntype ScopedDeclaration = VariableDeclaration | FunctionDeclaration;\n\nexport function collectScopedDeclarations(\n root: EstreeNode | EstreeNode[],\n options: ScopedDeclarationOptions\n): ScopedDeclaration[] {\n const declarations: ScopedDeclaration[] = [];\n const nextOptions = { var: options.var };\n const collect: InternalCollectWithOptions<void, ScopedDeclarationOptions> = (\n node,\n options\n ): void => {\n if (Array.isArray(node)) {\n for (const n of node) {\n collect(n, options);\n }\n } else if (node) {\n // `node` maybe `null` in some cases.\n switch (node.type) {\n case \"FunctionDeclaration\":\n // At the top level of a function, or script, function declarations are\n // treated like var declarations rather than like lexical declarations.\n // See https://tc39.es/ecma262/#sec-static-semantics-toplevellexicallydeclarednames\n if (Number(!options.var) ^ Number(options.topLevel)) {\n declarations.push(node);\n }\n return;\n case \"VariableDeclaration\":\n if (Number(!options.var) ^ Number(node.kind === \"var\")) {\n declarations.push(node);\n }\n return;\n case \"SwitchCase\":\n collect(node.consequent, nextOptions);\n return;\n case \"CatchClause\":\n collect(node.body, nextOptions);\n return;\n }\n if (options.var) {\n switch (node.type) {\n case \"BlockStatement\":\n collect(node.body, nextOptions);\n return;\n case \"IfStatement\":\n collect(node.consequent, nextOptions);\n collect(node.alternate, nextOptions);\n return;\n case \"DoWhileStatement\":\n case \"WhileStatement\":\n collect(node.body, nextOptions);\n return;\n case \"ForStatement\":\n collect(node.init, nextOptions);\n collect(node.body, nextOptions);\n return;\n case \"ForInStatement\":\n case \"ForOfStatement\":\n collect(node.left, nextOptions);\n collect(node.body, nextOptions);\n return;\n case \"SwitchStatement\":\n collect(node.cases, nextOptions);\n return;\n case \"TryStatement\":\n collect(node.block, nextOptions);\n collect(node.handler, nextOptions);\n collect(node.finalizer, nextOptions);\n return;\n }\n }\n }\n };\n collect(root, options);\n return declarations;\n}\n"],"mappings":"AAYA,OAAO,SAASA,iBAAiBA,CAC/BC,IAAkE,EACxD;EACV,IAAMC,KAAK,GAAG,IAAIC,GAAG,EAAU;EAC/B,IAAMC,OAAwB,GAAIC,IAAI,IAAK;IACzC,IAAIC,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,EAAE;MACvB,KAAK,IAAMG,CAAC,IAAIH,IAAI,EAAE;QACpBD,OAAO,CAACI,CAAC,CAAC;MACZ;IACF,CAAC,MAAM,IAAIH,I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AAW,CAAC;UAC/B;MAAO;MAEX,IAAID,OAAO,CAACE,GAAG,EAAE;QACf,QAAQrB,IAAI,CAACI,IAAI;UACf,KAAK,gBAAgB;YACnBL,OAAO,CAACC,IAAI,CAAC2B,IAAI,EAAEP,WAAW,CAAC;YAC/B;UACF,KAAK,aAAa;YAChBrB,OAAO,CAACC,IAAI,CAAC0B,UAAU,EAAEN,WAAW,CAAC;YACrCrB,OAAO,CAACC,IAAI,CAAC4B,SAAS,EAAER,WAAW,CAAC;YACpC;UACF,KAAK,kBAAkB;UACvB,KAAK,gBAAgB;YACnBrB,OAAO,CAACC,IAAI,CAAC2B,IAAI,EAAEP,WAAW,CAAC;YAC/B;UACF,KAAK,cAAc;YACjBrB,OAAO,CAACC,IAAI,CAAC6B,IAAI,EAAET,WAAW,CAAC;YAC/BrB,OAAO,CAACC,IAAI,CAAC2B,IAAI,EAAEP,WAAW,CAAC;YAC/B;UACF,KAAK,gBAAgB;UACrB,KAAK,gBAAgB;YACnBrB,OAAO,CAACC,IAAI,CAACU,IAAI,EAAEU,WAAW,CAAC;YAC/BrB,OAAO,CAACC,IAAI,CAAC2B,IAAI,EAAEP,WAAW,CAAC;YAC/B;UACF,KAAK,iBAAiB;YACpBrB,OAAO,CAACC,IAAI,CAAC8B,KAAK,EAAEV,WAAW,CAAC;YAChC;UACF,KAAK,cAAc;YACjBrB,OAAO,CAACC,IAAI,CAAC+B,KAAK,EAAEX,WAAW,CAAC;YAChCrB,OAAO,CAACC,IAAI,CAACgC,OAAO,EAAEZ,WAAW,CAAC;YAClCrB,OAAO,CAACC,IAAI,CAACiC,SAAS,EAAEb,WAAW,CAAC;YACpC;QAAO;MAEb;IACF;EACF,CAAC;EACDrB,OAAO,CAACH,IAAI,EAAEuB,OAAO,CAAC;EACtB,OAAOZ,YAAY;AACrB"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ArrowFunctionExpression, Expression, FunctionDeclaration, FunctionExpression, Statement } from "@babel/types";
|
|
2
2
|
export declare class AnalysisContext {
|
|
3
|
-
VariableEnvironment
|
|
4
|
-
LexicalEnvironment
|
|
3
|
+
VariableEnvironment?: AnalysisEnvironment;
|
|
4
|
+
LexicalEnvironment?: AnalysisEnvironment;
|
|
5
5
|
}
|
|
6
6
|
export declare class AnalysisEnvironment {
|
|
7
|
-
readonly OuterEnv: AnalysisEnvironment;
|
|
7
|
+
readonly OuterEnv: AnalysisEnvironment | null | undefined;
|
|
8
8
|
private readonly bindingSet;
|
|
9
|
-
constructor(outer: AnalysisEnvironment);
|
|
9
|
+
constructor(outer: AnalysisEnvironment | null | undefined);
|
|
10
10
|
HasBinding(name: string): boolean;
|
|
11
11
|
CreateBinding(name: string): void;
|
|
12
12
|
}
|
|
@@ -14,5 +14,5 @@ export interface AnalysisFunctionObject {
|
|
|
14
14
|
Function: FunctionDeclaration | FunctionExpression | ArrowFunctionExpression;
|
|
15
15
|
FormalParameters: FunctionDeclaration["params"];
|
|
16
16
|
ECMAScriptCode: Statement[] | Expression;
|
|
17
|
-
Environment
|
|
17
|
+
Environment?: AnalysisEnvironment;
|
|
18
18
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ArrowFunctionExpression, Expression, FunctionDeclaration, FunctionExpression, Statement } from "@babel/types";
|
|
2
2
|
export declare class ExecutionContext {
|
|
3
|
-
VariableEnvironment
|
|
4
|
-
LexicalEnvironment
|
|
5
|
-
Function
|
|
3
|
+
VariableEnvironment?: EnvironmentRecord;
|
|
4
|
+
LexicalEnvironment?: EnvironmentRecord;
|
|
5
|
+
Function?: FunctionObject;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export type EnvironmentRecordType = "function" | "declarative";
|
|
8
8
|
export declare class EnvironmentRecord {
|
|
9
|
-
readonly OuterEnv: EnvironmentRecord;
|
|
9
|
+
readonly OuterEnv: EnvironmentRecord | null | undefined;
|
|
10
10
|
private readonly bindingMap;
|
|
11
|
-
constructor(outer: EnvironmentRecord);
|
|
11
|
+
constructor(outer: EnvironmentRecord | null | undefined);
|
|
12
12
|
HasBinding(name: string): boolean;
|
|
13
13
|
CreateMutableBinding(name: string, deletable: boolean): CompletionRecord;
|
|
14
14
|
/**
|
|
@@ -28,8 +28,8 @@ export declare class EnvironmentRecord {
|
|
|
28
28
|
* @param strict - For functions, strict is always false, otherwise it depends on strict-mode.
|
|
29
29
|
* @returns
|
|
30
30
|
*/
|
|
31
|
-
SetMutableBinding(name: string, value: unknown, strict
|
|
32
|
-
GetBindingValue(name: string, strict
|
|
31
|
+
SetMutableBinding(name: string, value: unknown, strict?: boolean): CompletionRecord;
|
|
32
|
+
GetBindingValue(name: string, strict?: boolean): unknown;
|
|
33
33
|
}
|
|
34
34
|
export declare class DeclarativeEnvironment extends EnvironmentRecord {
|
|
35
35
|
}
|
|
@@ -62,8 +62,8 @@ export interface FunctionObject {
|
|
|
62
62
|
[IsConstructor]: boolean;
|
|
63
63
|
}
|
|
64
64
|
export declare class ReferenceRecord {
|
|
65
|
-
readonly Base
|
|
66
|
-
readonly ReferenceName
|
|
65
|
+
readonly Base: Record<PropertyKey, unknown> | EnvironmentRecord | "unresolvable";
|
|
66
|
+
readonly ReferenceName: PropertyKey;
|
|
67
67
|
/** Whether the reference is in strict mode. */
|
|
68
68
|
readonly Strict?: boolean;
|
|
69
69
|
constructor(base: Record<PropertyKey, unknown> | EnvironmentRecord | "unresolvable", referenceName: PropertyKey, strict: boolean);
|
|
@@ -73,7 +73,7 @@ export declare class CompletionRecord {
|
|
|
73
73
|
readonly Value: unknown;
|
|
74
74
|
constructor(type: CompletionRecordType, value: unknown);
|
|
75
75
|
}
|
|
76
|
-
export
|
|
76
|
+
export type CompletionRecordType = "normal" | "break" | "continue" | "return" | "throw";
|
|
77
77
|
export declare function NormalCompletion(value: unknown): CompletionRecord;
|
|
78
78
|
export declare const Empty: unique symbol;
|
|
79
79
|
export interface OptionalChainRef {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BinaryExpression, UnaryExpression, VariableDeclaration } from "@babel/types";
|
|
2
|
-
import { CompletionRecord, EnvironmentRecord, ReferenceRecord } from "./ExecutionContext";
|
|
2
|
+
import { CompletionRecord, EnvironmentRecord, ReferenceRecord } from "./ExecutionContext.js";
|
|
3
3
|
export declare function IsPropertyReference(V: ReferenceRecord): boolean;
|
|
4
4
|
export declare function InitializeReferencedBinding(V: ReferenceRecord, W: unknown): CompletionRecord;
|
|
5
5
|
export declare function CopyDataProperties(target: Record<PropertyKey, unknown>, source: unknown, excludedItems: Set<PropertyKey>): Record<PropertyKey, unknown>;
|
|
@@ -12,7 +12,7 @@ export declare function GetV(V: unknown, P: PropertyKey): unknown;
|
|
|
12
12
|
export declare function PutValue(V: ReferenceRecord, W: unknown): CompletionRecord;
|
|
13
13
|
export declare function CreateListIteratorRecord(args: Iterable<unknown>): Iterator<unknown>;
|
|
14
14
|
export declare function RequireObjectCoercible(arg: unknown): void;
|
|
15
|
-
export declare function GetIdentifierReference(env: EnvironmentRecord, name: string, strict: boolean): ReferenceRecord;
|
|
15
|
+
export declare function GetIdentifierReference(env: EnvironmentRecord | null | undefined, name: string, strict: boolean): ReferenceRecord;
|
|
16
16
|
export declare function ApplyStringOrNumericBinaryOperator(leftValue: number, operator: BinaryExpression["operator"] | "|>", rightValue: number): unknown;
|
|
17
17
|
export declare function ApplyStringOrNumericAssignment(leftValue: string | number, operator: string, rightValue: string | number): unknown;
|
|
18
18
|
export declare function ApplyUnaryOperator(target: unknown, operator: UnaryExpression["operator"]): unknown;
|
package/dist/types/cook.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Expression, FunctionDeclaration } from "@babel/types";
|
|
2
|
-
import { EstreeNode, CookRules } from "./interfaces";
|
|
2
|
+
import { EstreeNode, CookRules } from "./interfaces.js";
|
|
3
3
|
export interface CookOptions {
|
|
4
4
|
rules?: CookRules;
|
|
5
5
|
globalVariables?: Record<string, unknown>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
export * from "./cook";
|
|
2
|
-
export * from "./
|
|
3
|
-
export
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./preevaluate";
|
|
7
|
-
export * from "./interfaces";
|
|
8
|
-
export { tokTypes } from "@babel/parser";
|
|
1
|
+
export * from "./cook.js";
|
|
2
|
+
export * from "./precook.js";
|
|
3
|
+
export * from "./precookFunction.js";
|
|
4
|
+
export * from "./preevaluate.js";
|
|
5
|
+
export * from "./interfaces.js";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { parse } from "@babel/parser";
|
|
2
2
|
import { Expression, FunctionDeclaration, LVal, Node, ObjectExpression, ObjectPattern, ObjectProperty, RestElement, SourceLocation, SpreadElement, VariableDeclaration } from "@babel/types";
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
3
|
+
export type EstreeNode = Node | EstreeObjectExpression | EstreeObjectPattern | EstreeProperty | EstreeChainExpression | EstreeLiteral;
|
|
4
|
+
export type EstreeLVal = LVal | EstreeObjectPattern;
|
|
5
|
+
export type EstreeObjectExpression = Omit<ObjectExpression, "properties"> & {
|
|
6
6
|
properties: (EstreeProperty | SpreadElement)[];
|
|
7
7
|
};
|
|
8
|
-
export
|
|
8
|
+
export type EstreeObjectPattern = Omit<ObjectPattern, "properties"> & {
|
|
9
9
|
properties: (EstreeProperty | RestElement)[];
|
|
10
10
|
};
|
|
11
|
-
export
|
|
11
|
+
export type EstreeProperty = Omit<ObjectProperty, "type"> & {
|
|
12
12
|
type: "Property";
|
|
13
13
|
kind: "init" | "get" | "set";
|
|
14
14
|
};
|
|
@@ -26,10 +26,10 @@ export interface EstreeLiteral {
|
|
|
26
26
|
};
|
|
27
27
|
loc: SourceLocation;
|
|
28
28
|
}
|
|
29
|
-
export
|
|
30
|
-
export
|
|
31
|
-
export
|
|
29
|
+
export type NodeWithBoundNames = LVal | VariableDeclaration | FunctionDeclaration;
|
|
30
|
+
export type EstreeVisitors = Record<string, EstreeVisitorFn>;
|
|
31
|
+
export type EstreeVisitorFn = (node: any) => void;
|
|
32
32
|
export interface CookRules {
|
|
33
33
|
noVar?: boolean;
|
|
34
34
|
}
|
|
35
|
-
export
|
|
35
|
+
export type ParseResultOfFile = ReturnType<typeof parse>;
|
package/dist/types/lint.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SourceLocation } from "@babel/types";
|
|
2
|
-
import type { CookRules, ParseResultOfFile } from "./interfaces";
|
|
2
|
+
import type { CookRules, ParseResultOfFile } from "./interfaces.js";
|
|
3
3
|
export interface LintOptions {
|
|
4
4
|
typescript?: boolean;
|
|
5
5
|
rules?: CookRules;
|
|
@@ -10,4 +10,4 @@ export interface LintError {
|
|
|
10
10
|
loc: SourceLocation;
|
|
11
11
|
}
|
|
12
12
|
/** For next-core internal or devtools usage only. */
|
|
13
|
-
export declare function lint(source: string | ParseResultOfFile, { typescript, rules }?: LintOptions): LintError[];
|
|
13
|
+
export declare function lint(source: string | ParseResultOfFile | null, { typescript, rules }?: LintOptions): LintError[];
|