@next-core/cook 1.9.21 → 1.9.22
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/cook.js +2 -0
- package/dist/cjs/cook.js.map +1 -1
- package/dist/cjs/interfaces.js.map +1 -1
- package/dist/cjs/precookFunction.js +15 -3
- package/dist/cjs/precookFunction.js.map +1 -1
- package/dist/cjs/preevaluate.js +17 -3
- package/dist/cjs/preevaluate.js.map +1 -1
- package/dist/esm/cook.js +2 -0
- package/dist/esm/cook.js.map +1 -1
- package/dist/esm/interfaces.js.map +1 -1
- package/dist/esm/precookFunction.js +16 -5
- package/dist/esm/precookFunction.js.map +1 -1
- package/dist/esm/preevaluate.js +20 -3
- package/dist/esm/preevaluate.js.map +1 -1
- package/dist/types/interfaces.d.ts +1 -0
- package/dist/types/precookFunction.d.ts +4 -2
- package/dist/types/preevaluate.d.ts +6 -3
- package/package.json +2 -2
|
@@ -3,20 +3,32 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.clearFunctionASTCache = clearFunctionASTCache;
|
|
6
7
|
exports.precookFunction = precookFunction;
|
|
7
8
|
var _parse = require("./parse");
|
|
8
9
|
var _precook = require("./precook");
|
|
10
|
+
let ASTCache = new WeakMap();
|
|
9
11
|
function precookFunction(source, {
|
|
10
12
|
typescript,
|
|
13
|
+
cacheKey,
|
|
11
14
|
...restOptions
|
|
12
15
|
} = {}) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
let func = cacheKey ? ASTCache.get(cacheKey) : undefined;
|
|
17
|
+
if (!func) {
|
|
18
|
+
func = (0, _parse.parseAsEstree)(source, {
|
|
19
|
+
typescript
|
|
20
|
+
});
|
|
21
|
+
if (cacheKey) {
|
|
22
|
+
ASTCache.set(cacheKey, func);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
16
25
|
const attemptToVisitGlobals = (0, _precook.precook)(func, restOptions);
|
|
17
26
|
return {
|
|
18
27
|
function: func,
|
|
19
28
|
attemptToVisitGlobals
|
|
20
29
|
};
|
|
21
30
|
}
|
|
31
|
+
function clearFunctionASTCache() {
|
|
32
|
+
ASTCache = new WeakMap();
|
|
33
|
+
}
|
|
22
34
|
//# sourceMappingURL=precookFunction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"precookFunction.js","names":["precookFunction","source","typescript","restOptions","func","parseAsEstree","attemptToVisitGlobals","precook","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
|
|
1
|
+
{"version":3,"file":"precookFunction.js","names":["ASTCache","WeakMap","precookFunction","source","typescript","cacheKey","restOptions","func","get","undefined","parseAsEstree","set","attemptToVisitGlobals","precook","function","clearFunctionASTCache"],"sources":["../../src/precookFunction.ts"],"sourcesContent":["import type { FunctionDeclaration } from \"@babel/types\";\nimport { parseAsEstree } from \"./parse\";\nimport { precook, PrecookOptions } from \"./precook\";\n\nlet ASTCache = new WeakMap<object, FunctionDeclaration>();\n\nexport interface PrecookFunctionOptions extends PrecookOptions {\n cacheKey?: object;\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, cacheKey, ...restOptions }: PrecookFunctionOptions = {}\n): PrecookFunctionResult {\n let func = cacheKey ? ASTCache.get(cacheKey) : undefined;\n if (!func) {\n func = parseAsEstree(source, { typescript });\n if (cacheKey) {\n ASTCache.set(cacheKey, func);\n }\n }\n const attemptToVisitGlobals = precook(func, restOptions);\n return {\n function: func,\n attemptToVisitGlobals,\n };\n}\n\nexport function clearFunctionASTCache(): void {\n ASTCache = new WeakMap();\n}\n"],"mappings":";;;;;;;AACA;AACA;AAEA,IAAIA,QAAQ,GAAG,IAAIC,OAAO,EAA+B;AAYlD,SAASC,eAAe,CAC7BC,MAAc,EACd;EAAEC,UAAU;EAAEC,QAAQ;EAAE,GAAGC;AAAoC,CAAC,GAAG,CAAC,CAAC,EAC9C;EACvB,IAAIC,IAAI,GAAGF,QAAQ,GAAGL,QAAQ,CAACQ,GAAG,CAACH,QAAQ,CAAC,GAAGI,SAAS;EACxD,IAAI,CAACF,IAAI,EAAE;IACTA,IAAI,GAAG,IAAAG,oBAAa,EAACP,MAAM,EAAE;MAAEC;IAAW,CAAC,CAAC;IAC5C,IAAIC,QAAQ,EAAE;MACZL,QAAQ,CAACW,GAAG,CAACN,QAAQ,EAAEE,IAAI,CAAC;IAC9B;EACF;EACA,MAAMK,qBAAqB,GAAG,IAAAC,gBAAO,EAACN,IAAI,EAAED,WAAW,CAAC;EACxD,OAAO;IACLQ,QAAQ,EAAEP,IAAI;IACdK;EACF,CAAC;AACH;AAEO,SAASG,qBAAqB,GAAS;EAC5Cf,QAAQ,GAAG,IAAIC,OAAO,EAAE;AAC1B"}
|
package/dist/cjs/preevaluate.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.clearExpressionASTCache = clearExpressionASTCache;
|
|
6
7
|
exports.isEvaluable = isEvaluable;
|
|
7
8
|
exports.isSnippetEvaluation = isSnippetEvaluation;
|
|
8
9
|
exports.isTrackAll = isTrackAll;
|
|
@@ -10,16 +11,26 @@ exports.preevaluate = preevaluate;
|
|
|
10
11
|
exports.shouldAllowRecursiveEvaluations = shouldAllowRecursiveEvaluations;
|
|
11
12
|
var _parse = require("./parse");
|
|
12
13
|
var _precook = require("./precook");
|
|
14
|
+
const ASTCache = new Map();
|
|
13
15
|
// `raw` should always be asserted by `isEvaluable`.
|
|
14
|
-
function preevaluate(raw,
|
|
16
|
+
function preevaluate(raw, {
|
|
17
|
+
cache,
|
|
18
|
+
...restOptions
|
|
19
|
+
} = {}) {
|
|
15
20
|
const fixes = [];
|
|
16
21
|
const source = raw.replace(/^\s*<%[~=!]?\s|\s%>\s*$/g, m => {
|
|
17
22
|
fixes.push(m);
|
|
18
23
|
return "";
|
|
19
24
|
});
|
|
20
|
-
|
|
25
|
+
let expression = cache ? ASTCache.get(source) : undefined;
|
|
26
|
+
if (!expression) {
|
|
27
|
+
expression = (0, _parse.parseAsEstreeExpression)(source);
|
|
28
|
+
if (cache) {
|
|
29
|
+
ASTCache.set(source, expression);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
21
32
|
const attemptToVisitGlobals = (0, _precook.precook)(expression, {
|
|
22
|
-
...
|
|
33
|
+
...restOptions,
|
|
23
34
|
expressionOnly: true
|
|
24
35
|
});
|
|
25
36
|
return {
|
|
@@ -42,4 +53,7 @@ function isSnippetEvaluation(raw) {
|
|
|
42
53
|
function isTrackAll(raw) {
|
|
43
54
|
return /^\s*<%=\s/.test(raw) && /\s%>\s*$/.test(raw);
|
|
44
55
|
}
|
|
56
|
+
function clearExpressionASTCache() {
|
|
57
|
+
ASTCache.clear();
|
|
58
|
+
}
|
|
45
59
|
//# sourceMappingURL=preevaluate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preevaluate.js","names":["preevaluate","raw","
|
|
1
|
+
{"version":3,"file":"preevaluate.js","names":["ASTCache","Map","preevaluate","raw","cache","restOptions","fixes","source","replace","m","push","expression","get","undefined","parseAsEstreeExpression","set","attemptToVisitGlobals","precook","expressionOnly","prefix","suffix","isEvaluable","test","shouldAllowRecursiveEvaluations","isSnippetEvaluation","isTrackAll","clearExpressionASTCache","clear"],"sources":["../../src/preevaluate.ts"],"sourcesContent":["import type { Expression } from \"@babel/types\";\nimport { parseAsEstreeExpression } from \"./parse\";\nimport { precook, PrecookOptions } from \"./precook\";\n\nconst ASTCache = new Map<string, Expression>();\n\nexport type PreevaluateOptions = Omit<PrecookOptions, \"expressionOnly\"> & {\n cache?: boolean;\n};\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 { cache, ...restOptions }: 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 let expression = cache ? ASTCache.get(source) : undefined;\n if (!expression) {\n expression = parseAsEstreeExpression(source);\n if (cache) {\n ASTCache.set(source, expression);\n }\n }\n const attemptToVisitGlobals = precook(expression, {\n ...restOptions,\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\nexport function isSnippetEvaluation(raw: string): boolean {\n return /^\\s*<%[!@]=?\\s/.test(raw) && /\\s%>\\s*$/.test(raw);\n}\n\nexport function isTrackAll(raw: string): boolean {\n return /^\\s*<%=\\s/.test(raw) && /\\s%>\\s*$/.test(raw);\n}\n\nexport function clearExpressionASTCache(): void {\n ASTCache.clear();\n}\n"],"mappings":";;;;;;;;;;;AACA;AACA;AAEA,MAAMA,QAAQ,GAAG,IAAIC,GAAG,EAAsB;AAc9C;AACO,SAASC,WAAW,CACzBC,GAAW,EACX;EAAEC,KAAK;EAAE,GAAGC;AAAgC,CAAC,GA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mB,IAAI,CAACnB,GAAG,CAAC;AACtD;AAEO,SAASuB,uBAAuB,GAAS;EAC9C1B,QAAQ,CAAC2B,KAAK,EAAE;AAClB"}
|
package/dist/esm/cook.js
CHANGED
|
@@ -128,6 +128,8 @@ export function cook(rootAst, codeSource) {
|
|
|
128
128
|
// Currently unicode flag is not fully supported across major browsers.
|
|
129
129
|
throw new SyntaxError("Unsupported unicode flag in regular expression: ".concat(node.raw));
|
|
130
130
|
}
|
|
131
|
+
// Always create a new RegExp, because the AST will be reused.
|
|
132
|
+
return NormalCompletion(new RegExp(node.regex.pattern, node.regex.flags));
|
|
131
133
|
}
|
|
132
134
|
return NormalCompletion(node.value);
|
|
133
135
|
}
|