@next-core/cook 1.2.1 → 1.3.1
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/CHANGELOG.md +24 -14
- package/dist/cjs/ExecutionContext.js +2 -1
- package/dist/cjs/ExecutionContext.js.map +1 -1
- package/dist/cjs/context-free.js +11 -11
- package/dist/cjs/parse.js +1 -1
- package/dist/cjs/preevaluate.js +9 -3
- package/dist/cjs/preevaluate.js.map +1 -1
- package/dist/cjs/sanitize.js +1 -1
- package/dist/cjs/traverse.js +1 -1
- package/dist/esm/preevaluate.js +8 -2
- package/dist/esm/preevaluate.js.map +1 -1
- package/dist/types/preevaluate.d.ts +4 -4
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,60 +3,70 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [1.
|
|
6
|
+
## [1.3.1](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.3.0...@next-core/cook@1.3.1) (2021-10-20)
|
|
7
7
|
|
|
8
|
+
**Note:** Version bump only for package @next-core/cook
|
|
8
9
|
|
|
9
|
-
### Bug Fixes
|
|
10
10
|
|
|
11
|
-
* **cook-hooks:** use beforeCall for functions ([78073ab](https://github.com/easyops-cn/next-core/commit/78073abb4025c2d3f428a1b42447a07b7fc222a3))
|
|
12
11
|
|
|
13
12
|
|
|
14
13
|
|
|
14
|
+
# [1.3.0](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.2.3...@next-core/cook@1.3.0) (2021-10-20)
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
### Features
|
|
18
18
|
|
|
19
|
+
* support widget functions ([a5a5cff](https://github.com/easyops-cn/next-core/commit/a5a5cff7b183b971e434506e531d0fddbbf5e597))
|
|
19
20
|
|
|
20
|
-
### Features
|
|
21
21
|
|
|
22
|
-
* **function:** support to collect coverage ([93835f0](https://github.com/easyops-cn/next-core/commit/93835f0f202b6fb18c915045b5c2e0cf8e5e1f25))
|
|
23
22
|
|
|
24
23
|
|
|
25
24
|
|
|
25
|
+
## [1.2.3](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.2.2...@next-core/cook@1.2.3) (2021-10-13)
|
|
26
26
|
|
|
27
|
+
**Note:** Version bump only for package @next-core/cook
|
|
27
28
|
|
|
28
|
-
# [1.1.0](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.0.3...@next-core/cook@1.1.0) (2021-09-27)
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
### Features
|
|
32
31
|
|
|
33
|
-
* expose StoryboardFunctionRegistryFactory ([c7079e8](https://github.com/easyops-cn/next-core/commit/c7079e838a37350264ca3bf210527e1b09a542f7))
|
|
34
32
|
|
|
33
|
+
## [1.2.2](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.2.1...@next-core/cook@1.2.2) (2021-10-12)
|
|
35
34
|
|
|
35
|
+
**Note:** Version bump only for package @next-core/cook
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
## [1.0.3](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.0.2...@next-core/cook@1.0.3) (2021-09-23)
|
|
40
39
|
|
|
41
40
|
|
|
41
|
+
## [1.2.1](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.2.0...@next-core/cook@1.2.1) (2021-09-30)
|
|
42
|
+
|
|
42
43
|
### Bug Fixes
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
- **cook-hooks:** use beforeCall for functions ([78073ab](https://github.com/easyops-cn/next-core/commit/78073abb4025c2d3f428a1b42447a07b7fc222a3))
|
|
45
46
|
|
|
47
|
+
# [1.2.0](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.1.0...@next-core/cook@1.2.0) (2021-09-30)
|
|
46
48
|
|
|
49
|
+
### Features
|
|
47
50
|
|
|
51
|
+
- **function:** support to collect coverage ([93835f0](https://github.com/easyops-cn/next-core/commit/93835f0f202b6fb18c915045b5c2e0cf8e5e1f25))
|
|
48
52
|
|
|
53
|
+
# [1.1.0](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.0.3...@next-core/cook@1.1.0) (2021-09-27)
|
|
49
54
|
|
|
50
|
-
|
|
55
|
+
### Features
|
|
51
56
|
|
|
57
|
+
- expose StoryboardFunctionRegistryFactory ([c7079e8](https://github.com/easyops-cn/next-core/commit/c7079e838a37350264ca3bf210527e1b09a542f7))
|
|
52
58
|
|
|
53
|
-
|
|
59
|
+
## [1.0.3](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.0.2...@next-core/cook@1.0.3) (2021-09-23)
|
|
54
60
|
|
|
55
|
-
|
|
61
|
+
### Bug Fixes
|
|
56
62
|
|
|
63
|
+
- **lint:** fix false negative of var declarations ([930efc0](https://github.com/easyops-cn/next-core/commit/930efc0305853f1e8c72814886d174f70e015a71))
|
|
57
64
|
|
|
65
|
+
## [1.0.2](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.0.1...@next-core/cook@1.0.2) (2021-09-22)
|
|
58
66
|
|
|
67
|
+
### Bug Fixes
|
|
59
68
|
|
|
69
|
+
- **lint:** fix literals other than regex ([df8036c](https://github.com/easyops-cn/next-core/commit/df8036c1a2b29befcd4fec0df55463618cbf65cf))
|
|
60
70
|
|
|
61
71
|
## 1.0.1 (2021-09-22)
|
|
62
72
|
|
|
@@ -5,8 +5,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
exports.IsConstructor = exports.FunctionEnvironment = exports.FormalParameters = exports.ExecutionContext = exports.EnvironmentRecord = exports.Environment = exports.Empty = exports.ECMAScriptCode = exports.DeclarativeEnvironment = exports.CompletionRecord = void 0;
|
|
8
9
|
exports.NormalCompletion = NormalCompletion;
|
|
9
|
-
exports.
|
|
10
|
+
exports.SourceNode = exports.ReferenceRecord = void 0;
|
|
10
11
|
|
|
11
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
13
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ExecutionContext.ts"],"names":["ExecutionContext","EnvironmentRecord","constructor","outer","Map","OuterEnv","HasBinding","name","bindingMap","has","CreateMutableBinding","deletable","set","mutable","NormalCompletion","undefined","CreateImmutableBinding","strict","InitializeBinding","value","binding","get","Object","assign","initialized","SetMutableBinding","ReferenceError","TypeError","GetBindingValue","DeclarativeEnvironment","FunctionEnvironment","SourceNode","Symbol","for","FormalParameters","ECMAScriptCode","Environment","IsConstructor","ReferenceRecord","base","referenceName","Base","ReferenceName","Strict","CompletionRecord","type","Type","Value","Empty"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/ExecutionContext.ts"],"names":["ExecutionContext","EnvironmentRecord","constructor","outer","Map","OuterEnv","HasBinding","name","bindingMap","has","CreateMutableBinding","deletable","set","mutable","NormalCompletion","undefined","CreateImmutableBinding","strict","InitializeBinding","value","binding","get","Object","assign","initialized","SetMutableBinding","ReferenceError","TypeError","GetBindingValue","DeclarativeEnvironment","FunctionEnvironment","SourceNode","Symbol","for","FormalParameters","ECMAScriptCode","Environment","IsConstructor","ReferenceRecord","base","referenceName","Base","ReferenceName","Strict","CompletionRecord","type","Type","Value","Empty"],"mappings":";;;;;;;;;;;;;AAQA;AACO,MAAMA,gBAAN,CAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;;;;AAQ9B;AACO,MAAMC,iBAAN,CAAwB;AAI7BC,EAAAA,WAAW,CAACC,KAAD,EAA2B;AAAA;AAAA,sDAFR,IAAIC,GAAJ,EAEQ;AACpC,SAAKC,QAAL,GAAgBF,KAAhB;AACD;;AAEDG,EAAAA,UAAU,CAACC,IAAD,EAAwB;AAChC,WAAO,KAAKC,UAAL,CAAgBC,GAAhB,CAAoBF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AAiB9B;AACO,SAASL,gBAAT,CAA0BK,KAA1B,EAA4D;AACjE,SAAO,IAAIyB,gBAAJ,CAAqB,QAArB,EAA+BzB,KAA/B,CAAP;AACD;;AAEM,MAAM6B,KAAK,GAAGhB,MAAM,CAAC,kBAAD,CAApB","sourcesContent":["import {\n ArrowFunctionExpression,\n Expression,\n FunctionDeclaration,\n FunctionExpression,\n Statement,\n} from \"@babel/types\";\n\n// https://tc39.es/ecma262/#sec-execution-contexts\nexport class ExecutionContext {\n VariableEnvironment: EnvironmentRecord;\n LexicalEnvironment: EnvironmentRecord;\n Function: FunctionObject;\n}\n\nexport type EnvironmentRecordType = \"function\" | \"declarative\";\n\n// https://tc39.es/ecma262/#sec-environment-records\nexport class EnvironmentRecord {\n readonly OuterEnv: EnvironmentRecord;\n private readonly bindingMap = new Map<string, BindingState>();\n\n constructor(outer: EnvironmentRecord) {\n this.OuterEnv = outer;\n }\n\n HasBinding(name: string): boolean {\n return this.bindingMap.has(name);\n }\n\n CreateMutableBinding(name: string, deletable: boolean): CompletionRecord {\n // Assert: binding does not exist.\n this.bindingMap.set(name, {\n mutable: true,\n deletable,\n });\n return NormalCompletion(undefined);\n }\n\n /**\n * Create an immutable binding.\n *\n * @param name - The binding name.\n * @param strict - For named function expressions, strict is false, otherwise it's true.\n * @returns CompletionRecord.\n */\n CreateImmutableBinding(name: string, strict: boolean): CompletionRecord {\n // Assert: binding does not exist.\n this.bindingMap.set(name, {\n strict,\n });\n return NormalCompletion(undefined);\n }\n\n InitializeBinding(name: string, value: unknown): CompletionRecord {\n const binding = this.bindingMap.get(name);\n // Assert: binding exists and uninitialized.\n Object.assign<BindingState, Partial<BindingState>>(binding, {\n initialized: true,\n value,\n });\n return NormalCompletion(undefined);\n }\n\n /**\n * Update a mutable binding value, including function declarations.\n *\n * @param name - The binding name.\n * @param value - The binding value.\n * @param strict - For functions, strict is always false, otherwise it depends on strict-mode.\n * @returns\n */\n SetMutableBinding(\n name: string,\n value: unknown,\n strict: boolean\n ): CompletionRecord {\n const binding = this.bindingMap.get(name);\n // Assert: binding exists.\n if (!binding.initialized) {\n throw new ReferenceError(`${name} is not initialized`);\n } else if (binding.mutable) {\n binding.value = value;\n } else {\n throw new TypeError(`Assignment to constant variable`);\n }\n return NormalCompletion(undefined);\n }\n\n GetBindingValue(name: string, strict: boolean): unknown {\n const binding = this.bindingMap.get(name);\n // Assert: binding exists.\n if (!binding.initialized) {\n throw new ReferenceError(`${name} is not initialized`);\n }\n return binding.value;\n }\n}\n\nexport class DeclarativeEnvironment extends EnvironmentRecord {}\n\nexport class FunctionEnvironment extends EnvironmentRecord {}\n\nexport interface BindingState {\n initialized?: boolean;\n value?: unknown;\n mutable?: boolean;\n\n /** This is used for mutable bindings only. */\n deletable?: boolean;\n\n /**\n * This is used for immutable bindings only.\n * For named function expressions, `strict` is false,\n * otherwise it's true.\n */\n strict?: boolean;\n}\n\nexport const SourceNode = Symbol.for(\"SourceNode\");\nexport const FormalParameters = Symbol.for(\"FormalParameters\");\nexport const ECMAScriptCode = Symbol.for(\"ECMAScriptCode\");\nexport const Environment = Symbol.for(\"Environment\");\nexport const IsConstructor = Symbol.for(\"IsConstructor\");\n\nexport interface FunctionObject {\n (...args: unknown[]): unknown;\n [SourceNode]:\n | FunctionDeclaration\n | FunctionExpression\n | ArrowFunctionExpression;\n [FormalParameters]: FunctionDeclaration[\"params\"];\n [ECMAScriptCode]: Statement[] | Expression;\n [Environment]: EnvironmentRecord;\n [IsConstructor]: boolean;\n}\n\n// https://tc39.es/ecma262/#sec-reference-record-specification-type\nexport class ReferenceRecord {\n readonly Base?:\n | Record<PropertyKey, unknown>\n | EnvironmentRecord\n | \"unresolvable\";\n readonly ReferenceName?: PropertyKey;\n /** Whether the reference is in strict mode. */\n readonly Strict?: boolean;\n\n constructor(\n base: Record<PropertyKey, unknown> | EnvironmentRecord | \"unresolvable\",\n referenceName: PropertyKey,\n strict: boolean\n ) {\n this.Base = base;\n this.ReferenceName = referenceName;\n this.Strict = strict;\n }\n}\n\n// https://tc39.es/ecma262/#sec-completion-record-specification-type\nexport class CompletionRecord {\n readonly Type: CompletionRecordType;\n readonly Value: unknown;\n\n constructor(type: CompletionRecordType, value: unknown) {\n this.Type = type;\n this.Value = value;\n }\n}\n\nexport type CompletionRecordType =\n | \"normal\"\n | \"break\"\n | \"continue\"\n | \"return\"\n | \"throw\";\n\n// https://tc39.es/ecma262/#sec-normalcompletion\nexport function NormalCompletion(value: unknown): CompletionRecord {\n return new CompletionRecord(\"normal\", value);\n}\n\nexport const Empty = Symbol(\"empty completion\");\n\nexport interface OptionalChainRef {\n skipped?: boolean;\n}\n"],"file":"ExecutionContext.js"}
|
package/dist/cjs/context-free.js
CHANGED
|
@@ -3,22 +3,22 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
6
|
+
exports.ApplyStringOrNumericAssignment = ApplyStringOrNumericAssignment;
|
|
7
|
+
exports.ApplyStringOrNumericBinaryOperator = ApplyStringOrNumericBinaryOperator;
|
|
8
|
+
exports.ApplyUnaryOperator = ApplyUnaryOperator;
|
|
8
9
|
exports.CopyDataProperties = CopyDataProperties;
|
|
10
|
+
exports.CreateListIteratorRecord = CreateListIteratorRecord;
|
|
9
11
|
exports.ForDeclarationBindingInstantiation = ForDeclarationBindingInstantiation;
|
|
10
|
-
exports.
|
|
11
|
-
exports.UpdateEmpty = UpdateEmpty;
|
|
12
|
-
exports.GetValue = GetValue;
|
|
13
|
-
exports.ToPropertyKey = ToPropertyKey;
|
|
12
|
+
exports.GetIdentifierReference = GetIdentifierReference;
|
|
14
13
|
exports.GetV = GetV;
|
|
14
|
+
exports.GetValue = GetValue;
|
|
15
|
+
exports.InitializeReferencedBinding = InitializeReferencedBinding;
|
|
16
|
+
exports.IsPropertyReference = IsPropertyReference;
|
|
17
|
+
exports.LoopContinues = LoopContinues;
|
|
15
18
|
exports.PutValue = PutValue;
|
|
16
|
-
exports.CreateListIteratorRecord = CreateListIteratorRecord;
|
|
17
19
|
exports.RequireObjectCoercible = RequireObjectCoercible;
|
|
18
|
-
exports.
|
|
19
|
-
exports.
|
|
20
|
-
exports.ApplyStringOrNumericAssignment = ApplyStringOrNumericAssignment;
|
|
21
|
-
exports.ApplyUnaryOperator = ApplyUnaryOperator;
|
|
20
|
+
exports.ToPropertyKey = ToPropertyKey;
|
|
21
|
+
exports.UpdateEmpty = UpdateEmpty;
|
|
22
22
|
exports.isIterable = isIterable;
|
|
23
23
|
|
|
24
24
|
var _ExecutionContext = require("./ExecutionContext");
|
package/dist/cjs/parse.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.parseAsEstreeExpression = parseAsEstreeExpression;
|
|
7
6
|
exports.parseAsEstree = parseAsEstree;
|
|
7
|
+
exports.parseAsEstreeExpression = parseAsEstreeExpression;
|
|
8
8
|
|
|
9
9
|
var _parser = require("@babel/parser");
|
|
10
10
|
|
package/dist/cjs/preevaluate.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.preevaluate = preevaluate;
|
|
7
6
|
exports.isEvaluable = isEvaluable;
|
|
7
|
+
exports.preevaluate = preevaluate;
|
|
8
8
|
exports.shouldAllowRecursiveEvaluations = shouldAllowRecursiveEvaluations;
|
|
9
9
|
|
|
10
10
|
var _parse = require("./parse");
|
|
@@ -13,7 +13,11 @@ var _precook = require("./precook");
|
|
|
13
13
|
|
|
14
14
|
// `raw` should always be asserted by `isEvaluable`.
|
|
15
15
|
function preevaluate(raw, options) {
|
|
16
|
-
const
|
|
16
|
+
const fixes = [];
|
|
17
|
+
const source = raw.replace(/^\s*<%~?\s|\s%>\s*$/g, m => {
|
|
18
|
+
fixes.push(m);
|
|
19
|
+
return "";
|
|
20
|
+
});
|
|
17
21
|
const expression = (0, _parse.parseAsEstreeExpression)(source);
|
|
18
22
|
const attemptToVisitGlobals = (0, _precook.precook)(expression, { ...options,
|
|
19
23
|
expressionOnly: true
|
|
@@ -21,7 +25,9 @@ function preevaluate(raw, options) {
|
|
|
21
25
|
return {
|
|
22
26
|
expression,
|
|
23
27
|
attemptToVisitGlobals,
|
|
24
|
-
source
|
|
28
|
+
source,
|
|
29
|
+
prefix: fixes[0],
|
|
30
|
+
suffix: fixes[1]
|
|
25
31
|
};
|
|
26
32
|
}
|
|
27
33
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preevaluate.ts"],"names":["preevaluate","raw","options","source","replace","expression","attemptToVisitGlobals","expressionOnly","isEvaluable","test","shouldAllowRecursiveEvaluations"],"mappings":";;;;;;;;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["../../src/preevaluate.ts"],"names":["preevaluate","raw","options","fixes","source","replace","m","push","expression","attemptToVisitGlobals","expressionOnly","prefix","suffix","isEvaluable","test","shouldAllowRecursiveEvaluations"],"mappings":";;;;;;;;;AACA;;AACA;;AAYA;AACO,SAASA,WAAT,CACLC,GADK,EAELC,OAFK,EAGc;AACnB,QAAMC,KAAe,GAAG,EAAxB;AACA,QAAMC,MAAM,GAAGH,GAAG,CAACI,OAAJ,CAAY,sBAAZ,EAAqCC,CAAD,IAAO;AACxDH,IAAAA,KAAK,CAACI,IAAN,CAAWD,CAAX;AACA,WAAO,EAAP;AACD,GAHc,CAAf;AAIA,QAAME,UAAU,GAAG,oCAAwBJ,MAAxB,CAAnB;AACA,QAAMK,qBAAqB,GAAG,sBAAQD,UAAR,EAAoB,EAChD,GAAGN,OAD6C;AAEhDQ,IAAAA,cAAc,EAAE;AAFgC,GAApB,CAA9B;AAIA,SAAO;AACLF,IAAAA,UADK;AAELC,IAAAA,qBAFK;AAGLL,IAAAA,MAHK;AAILO,IAAAA,MAAM,EAAER,KAAK,CAAC,CAAD,CAJR;AAKLS,IAAAA,MAAM,EAAET,KAAK,CAAC,CAAD;AALR,GAAP;AAOD;;AAEM,SAASU,WAAT,CAAqBZ,GAArB,EAA2C;AAChD,SAAO,aAAaa,IAAb,CAAkBb,GAAlB,KAA0B,WAAWa,IAAX,CAAgBb,GAAhB,CAAjC;AACD;;AAEM,SAASc,+BAAT,CAAyCd,GAAzC,EAA+D;AACpE,SAAO,YAAYa,IAAZ,CAAiBb,GAAjB,CAAP;AACD","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"],"file":"preevaluate.js"}
|
package/dist/cjs/sanitize.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.sanitize = sanitize;
|
|
7
6
|
exports.isAllowedConstructor = isAllowedConstructor;
|
|
7
|
+
exports.sanitize = sanitize;
|
|
8
8
|
|
|
9
9
|
// Ref https://github.com/tc39/proposal-global
|
|
10
10
|
// In addition, the es6-shim had to switch from Function('return this')()
|
package/dist/cjs/traverse.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.collectBoundNames = collectBoundNames;
|
|
7
|
-
exports.containsExpression = containsExpression;
|
|
8
7
|
exports.collectScopedDeclarations = collectScopedDeclarations;
|
|
8
|
+
exports.containsExpression = containsExpression;
|
|
9
9
|
|
|
10
10
|
function collectBoundNames(root) {
|
|
11
11
|
const names = new Set();
|
package/dist/esm/preevaluate.js
CHANGED
|
@@ -3,7 +3,11 @@ import { parseAsEstreeExpression } from "./parse";
|
|
|
3
3
|
import { precook } from "./precook";
|
|
4
4
|
// `raw` should always be asserted by `isEvaluable`.
|
|
5
5
|
export function preevaluate(raw, options) {
|
|
6
|
-
var
|
|
6
|
+
var fixes = [];
|
|
7
|
+
var source = raw.replace(/^\s*<%~?\s|\s%>\s*$/g, m => {
|
|
8
|
+
fixes.push(m);
|
|
9
|
+
return "";
|
|
10
|
+
});
|
|
7
11
|
var expression = parseAsEstreeExpression(source);
|
|
8
12
|
var attemptToVisitGlobals = precook(expression, _objectSpread(_objectSpread({}, options), {}, {
|
|
9
13
|
expressionOnly: true
|
|
@@ -11,7 +15,9 @@ export function preevaluate(raw, options) {
|
|
|
11
15
|
return {
|
|
12
16
|
expression,
|
|
13
17
|
attemptToVisitGlobals,
|
|
14
|
-
source
|
|
18
|
+
source,
|
|
19
|
+
prefix: fixes[0],
|
|
20
|
+
suffix: fixes[1]
|
|
15
21
|
};
|
|
16
22
|
}
|
|
17
23
|
export function isEvaluable(raw) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/preevaluate.ts"],"names":["parseAsEstreeExpression","precook","preevaluate","raw","options","source","replace","expression","attemptToVisitGlobals","expressionOnly","isEvaluable","test","shouldAllowRecursiveEvaluations"],"mappings":";AACA,SAASA,uBAAT,QAAwC,SAAxC;AACA,SAASC,OAAT,
|
|
1
|
+
{"version":3,"sources":["../../src/preevaluate.ts"],"names":["parseAsEstreeExpression","precook","preevaluate","raw","options","fixes","source","replace","m","push","expression","attemptToVisitGlobals","expressionOnly","prefix","suffix","isEvaluable","test","shouldAllowRecursiveEvaluations"],"mappings":";AACA,SAASA,uBAAT,QAAwC,SAAxC;AACA,SAASC,OAAT,QAAwC,WAAxC;AAYA;AACA,OAAO,SAASC,WAAT,CACLC,GADK,EAELC,OAFK,EAGc;AACnB,MAAMC,KAAe,GAAG,EAAxB;AACA,MAAMC,MAAM,GAAGH,GAAG,CAACI,OAAJ,CAAY,sBAAZ,EAAqCC,CAAD,IAAO;AACxDH,IAAAA,KAAK,CAACI,IAAN,CAAWD,CAAX;AACA,WAAO,EAAP;AACD,GAHc,CAAf;AAIA,MAAME,UAAU,GAAGV,uBAAuB,CAACM,MAAD,CAA1C;AACA,MAAMK,qBAAqB,GAAGV,OAAO,CAACS,UAAD,kCAChCN,OADgC;AAEnCQ,IAAAA,cAAc,EAAE;AAFmB,KAArC;AAIA,SAAO;AACLF,IAAAA,UADK;AAELC,IAAAA,qBAFK;AAGLL,IAAAA,MAHK;AAILO,IAAAA,MAAM,EAAER,KAAK,CAAC,CAAD,CAJR;AAKLS,IAAAA,MAAM,EAAET,KAAK,CAAC,CAAD;AALR,GAAP;AAOD;AAED,OAAO,SAASU,WAAT,CAAqBZ,GAArB,EAA2C;AAChD,SAAO,aAAaa,IAAb,CAAkBb,GAAlB,KAA0B,WAAWa,IAAX,CAAgBb,GAAhB,CAAjC;AACD;AAED,OAAO,SAASc,+BAAT,CAAyCd,GAAzC,EAA+D;AACpE,SAAO,YAAYa,IAAZ,CAAiBb,GAAjB,CAAP;AACD","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"],"file":"preevaluate.js"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Expression } from "@babel/types";
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
4
|
-
visitors?: EstreeVisitors;
|
|
5
|
-
}
|
|
2
|
+
import { PrecookOptions } from "./precook";
|
|
3
|
+
export declare type PreevaluateOptions = Omit<PrecookOptions, "expressionOnly">;
|
|
6
4
|
export interface PreevaluateResult {
|
|
7
5
|
expression: Expression;
|
|
8
6
|
attemptToVisitGlobals: Set<string>;
|
|
9
7
|
source: string;
|
|
8
|
+
prefix: string;
|
|
9
|
+
suffix: string;
|
|
10
10
|
}
|
|
11
11
|
export declare function preevaluate(raw: string, options?: PreevaluateOptions): PreevaluateResult;
|
|
12
12
|
export declare function isEvaluable(raw: string): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/cook",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Cook expressions and storyboard functions",
|
|
5
5
|
"homepage": "https://github.com/easyops-cn/next-core/tree/master/packages/cook",
|
|
6
6
|
"license": "GPL-3.0",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
},
|
|
30
30
|
"sideEffects": false,
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@babel/parser": "^7.15.
|
|
33
|
-
"@next-core/brick-types": "^2.
|
|
32
|
+
"@babel/parser": "^7.15.8",
|
|
33
|
+
"@next-core/brick-types": "^2.42.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@next-core/supply": "^1.0.
|
|
36
|
+
"@next-core/supply": "^1.0.5",
|
|
37
37
|
"lodash": "^4.17.21"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "327d5144a16ed35411c047ca47c8874dc7520d9a"
|
|
40
40
|
}
|