@next-core/cook 1.3.6 → 1.4.0
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 +18 -24
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lint.js +6 -12
- package/dist/cjs/lint.js.map +1 -1
- package/dist/cjs/parse.js +21 -0
- package/dist/cjs/parse.js.map +1 -1
- package/dist/esm/cook.js +6 -5
- package/dist/esm/cook.js.map +1 -1
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lint.js +11 -16
- package/dist/esm/lint.js.map +1 -1
- package/dist/esm/parse.js +26 -3
- package/dist/esm/parse.js.map +1 -1
- package/dist/esm/precook.js +11 -9
- package/dist/esm/precook.js.map +1 -1
- package/dist/esm/precookFunction.js +3 -2
- package/dist/esm/precookFunction.js.map +1 -1
- package/dist/types/index.d.ts +3 -0
- package/dist/types/lint.d.ts +3 -2
- package/dist/types/parse.d.ts +8 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,15 +3,18 @@
|
|
|
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
|
-
|
|
6
|
+
# [1.4.0](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.3.9...@next-core/cook@1.4.0) (2021-11-25)
|
|
7
7
|
|
|
8
|
-
**Note:** Version bump only for package @next-core/cook
|
|
9
8
|
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* support parseForAnalysis ([681de0a](https://github.com/easyops-cn/next-core/commit/681de0aef914b4e30d428180cad54cc0f9882b59))
|
|
10
12
|
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
## [1.3.9](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.3.8...@next-core/cook@1.3.9) (2021-11-23)
|
|
15
18
|
|
|
16
19
|
**Note:** Version bump only for package @next-core/cook
|
|
17
20
|
|
|
@@ -19,7 +22,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
19
22
|
|
|
20
23
|
|
|
21
24
|
|
|
22
|
-
## [1.3.
|
|
25
|
+
## [1.3.8](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.3.7...@next-core/cook@1.3.8) (2021-11-18)
|
|
23
26
|
|
|
24
27
|
**Note:** Version bump only for package @next-core/cook
|
|
25
28
|
|
|
@@ -27,57 +30,48 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
|
|
30
|
-
## [1.3.
|
|
33
|
+
## [1.3.7](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.3.6...@next-core/cook@1.3.7) (2021-11-11)
|
|
31
34
|
|
|
32
35
|
**Note:** Version bump only for package @next-core/cook
|
|
33
36
|
|
|
37
|
+
## [1.3.6](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.3.5...@next-core/cook@1.3.6) (2021-11-02)
|
|
34
38
|
|
|
39
|
+
**Note:** Version bump only for package @next-core/cook
|
|
35
40
|
|
|
41
|
+
## [1.3.5](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.3.4...@next-core/cook@1.3.5) (2021-11-01)
|
|
36
42
|
|
|
43
|
+
**Note:** Version bump only for package @next-core/cook
|
|
37
44
|
|
|
38
|
-
## [1.3.
|
|
45
|
+
## [1.3.4](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.3.3...@next-core/cook@1.3.4) (2021-10-28)
|
|
39
46
|
|
|
40
47
|
**Note:** Version bump only for package @next-core/cook
|
|
41
48
|
|
|
49
|
+
## [1.3.3](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.3.2...@next-core/cook@1.3.3) (2021-10-28)
|
|
42
50
|
|
|
51
|
+
**Note:** Version bump only for package @next-core/cook
|
|
43
52
|
|
|
53
|
+
## [1.3.2](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.3.1...@next-core/cook@1.3.2) (2021-10-21)
|
|
44
54
|
|
|
55
|
+
**Note:** Version bump only for package @next-core/cook
|
|
45
56
|
|
|
46
57
|
## [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)
|
|
47
58
|
|
|
48
59
|
**Note:** Version bump only for package @next-core/cook
|
|
49
60
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
61
|
# [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)
|
|
55
62
|
|
|
56
|
-
|
|
57
63
|
### Features
|
|
58
64
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
- support widget functions ([a5a5cff](https://github.com/easyops-cn/next-core/commit/a5a5cff7b183b971e434506e531d0fddbbf5e597))
|
|
64
66
|
|
|
65
67
|
## [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)
|
|
66
68
|
|
|
67
69
|
**Note:** Version bump only for package @next-core/cook
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
71
|
## [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)
|
|
74
72
|
|
|
75
73
|
**Note:** Version bump only for package @next-core/cook
|
|
76
74
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
75
|
## [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)
|
|
82
76
|
|
|
83
77
|
### Bug Fixes
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,11 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
parseForAnalysis: true,
|
|
8
|
+
tokTypes: true
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "parseForAnalysis", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _parse.parseForAnalysis;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "tokTypes", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _parser.tokTypes;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
6
22
|
|
|
7
23
|
var _cook = require("./cook");
|
|
8
24
|
|
|
9
25
|
Object.keys(_cook).forEach(function (key) {
|
|
10
26
|
if (key === "default" || key === "__esModule") return;
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
11
28
|
if (key in exports && exports[key] === _cook[key]) return;
|
|
12
29
|
Object.defineProperty(exports, key, {
|
|
13
30
|
enumerable: true,
|
|
@@ -21,6 +38,7 @@ var _lint = require("./lint");
|
|
|
21
38
|
|
|
22
39
|
Object.keys(_lint).forEach(function (key) {
|
|
23
40
|
if (key === "default" || key === "__esModule") return;
|
|
41
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
24
42
|
if (key in exports && exports[key] === _lint[key]) return;
|
|
25
43
|
Object.defineProperty(exports, key, {
|
|
26
44
|
enumerable: true,
|
|
@@ -30,10 +48,27 @@ Object.keys(_lint).forEach(function (key) {
|
|
|
30
48
|
});
|
|
31
49
|
});
|
|
32
50
|
|
|
51
|
+
var _parse = require("./parse");
|
|
52
|
+
|
|
53
|
+
var _precook = require("./precook");
|
|
54
|
+
|
|
55
|
+
Object.keys(_precook).forEach(function (key) {
|
|
56
|
+
if (key === "default" || key === "__esModule") return;
|
|
57
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
58
|
+
if (key in exports && exports[key] === _precook[key]) return;
|
|
59
|
+
Object.defineProperty(exports, key, {
|
|
60
|
+
enumerable: true,
|
|
61
|
+
get: function () {
|
|
62
|
+
return _precook[key];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
33
67
|
var _precookFunction = require("./precookFunction");
|
|
34
68
|
|
|
35
69
|
Object.keys(_precookFunction).forEach(function (key) {
|
|
36
70
|
if (key === "default" || key === "__esModule") return;
|
|
71
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
37
72
|
if (key in exports && exports[key] === _precookFunction[key]) return;
|
|
38
73
|
Object.defineProperty(exports, key, {
|
|
39
74
|
enumerable: true,
|
|
@@ -47,6 +82,7 @@ var _preevaluate = require("./preevaluate");
|
|
|
47
82
|
|
|
48
83
|
Object.keys(_preevaluate).forEach(function (key) {
|
|
49
84
|
if (key === "default" || key === "__esModule") return;
|
|
85
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
50
86
|
if (key in exports && exports[key] === _preevaluate[key]) return;
|
|
51
87
|
Object.defineProperty(exports, key, {
|
|
52
88
|
enumerable: true,
|
|
@@ -60,6 +96,7 @@ var _interfaces = require("./interfaces");
|
|
|
60
96
|
|
|
61
97
|
Object.keys(_interfaces).forEach(function (key) {
|
|
62
98
|
if (key === "default" || key === "__esModule") return;
|
|
99
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
63
100
|
if (key in exports && exports[key] === _interfaces[key]) return;
|
|
64
101
|
Object.defineProperty(exports, key, {
|
|
65
102
|
enumerable: true,
|
|
@@ -68,4 +105,6 @@ Object.keys(_interfaces).forEach(function (key) {
|
|
|
68
105
|
}
|
|
69
106
|
});
|
|
70
107
|
});
|
|
108
|
+
|
|
109
|
+
var _parser = require("@babel/parser");
|
|
71
110
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA","sourcesContent":["export * from \"./cook\";\nexport * from \"./lint\";\nexport { parseForAnalysis } from \"./parse\";\nexport * from \"./precook\";\nexport * from \"./precookFunction\";\nexport * from \"./preevaluate\";\nexport * from \"./interfaces\";\nexport { tokTypes } from \"@babel/parser\";\n"],"file":"index.js"}
|
package/dist/cjs/lint.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.lint = lint;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _parse = require("./parse");
|
|
9
9
|
|
|
10
10
|
var _precook = require("./precook");
|
|
11
11
|
|
|
@@ -15,17 +15,11 @@ function lint(source, {
|
|
|
15
15
|
rules
|
|
16
16
|
} = {}) {
|
|
17
17
|
const errors = [];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
strictMode: true,
|
|
24
|
-
attachComment: false,
|
|
25
|
-
// Allow export/import declarations to make linter handle errors.
|
|
26
|
-
sourceType: "unambiguous"
|
|
27
|
-
});
|
|
28
|
-
} catch (e) {
|
|
18
|
+
const file = typeof source === "string" ? (0, _parse.parseForAnalysis)(source, {
|
|
19
|
+
typescript
|
|
20
|
+
}) : source;
|
|
21
|
+
|
|
22
|
+
if (!file) {
|
|
29
23
|
// Return no errors if parse failed.
|
|
30
24
|
return errors;
|
|
31
25
|
}
|
package/dist/cjs/lint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lint.ts"],"names":["lint","source","typescript","rules","errors","file","plugins","filter","Boolean","strictMode","attachComment","sourceType","e","body","program","jsNodes","node","type","startsWith","test","push","message","loc","func","isFunctionDeclaration","unshift","start","line","column","end","FunctionVisitor","async","generator","visitors","ArrowFunctionExpression","FunctionDeclaration","FunctionExpression","Literal","regex","value","flags","includes","ObjectExpression","prop","properties","kind","computed","key","name","VariableDeclaration","noVar","__UnknownNode","__GlobalVariable"],"mappings":";;;;;;;AAAA;;AAkBA;;AAaA;AACO,SAASA,IAAT,CACLC,MADK,EAEL;AAAEC,EAAAA,UAAF;AAAcC,EAAAA;AAAd,IAAqC,EAFhC,EAGQ;AACb,QAAMC,MAAmB,GAAG,EAA5B;AACA,MAAIC,IAAJ;;AACA,MAAI;AACFA,IAAAA,IAAI,GAAG,mBAAMJ,MAAN,EAAc;AACnBK,MAAAA,OAAO,EAAE,CAAC,QAAD,EAAWJ,UAAU,IAAI,YAAzB,EAAuCK,MAAvC,CACPC,OADO,CADU;AAInBC,MAAAA,UAAU,EAAE,IAJO;AAKnBC,MAAAA,aAAa,EAAE,KALI;AAMnB;AACAC,MAAAA,UAAU,EAAE;AAPO,KAAd,CAAP;AASD,GAVD,CAUE,OAAOC,CAAP,EAAU;AACV;AACA,WAAOR,MAAP;AACD;;AACD,QAAMS,IAAI,GAAGR,IAAI,CAACS,OAAL,CAAaD,IAA1B;AACA,QAAME,OAAoB,GAAGb,UAAU,GAAG,EAAH,GAAQW,IAA/C;;AACA,MAAIX,U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;AACF,SA5DO;;AA6DRuB,QAAAA,aAAa,CAACnC,IAAD,EAAmB;AAC9BZ,UAAAA,MAAM,CAACgB,IAAP,CAAY;AACVH,YAAAA,IAAI,EAAE,aADI;AAEVI,YAAAA,OAAO,EAAG,yBAAwBL,IAAI,CAACC,IAAK,IAFlC;AAGVK,YAAAA,GAAG,EAAEN,IAAI,CAACM;AAHA,WAAZ;AAKD,SAnEO;;AAoER8B,QAAAA,gBAAgB,CAACpC,IAAD,EAAmB;AACjC,cAAIA,IAAI,CAACgC,IAAL,KAAc,WAAlB,EAA+B;AAC7B5C,YAAAA,MAAM,CAACgB,IAAP,CAAY;AACVH,cAAAA,IAAI,EAAE,aADI;AAEVI,cAAAA,OAAO,EAAE,gDAFC;AAGVC,cAAAA,GAAG,EAAEN,IAAI,CAACM;AAHA,aAAZ;AAKD;AACF;;AA5EO;AADE,KAAd;AAgFD;;AACD,SAAOlB,MAAP;AACD","sourcesContent":["import { parse, ParseResult, ParserPlugin } from \"@babel/parser\";\nimport {\n ArrowFunctionExpression,\n File,\n FunctionDeclaration,\n FunctionExpression,\n Identifier,\n SourceLocation,\n Statement,\n VariableDeclaration,\n} from \"@babel/types\";\nimport {\n EstreeLiteral,\n CookRules,\n EstreeObjectExpression,\n EstreeVisitorFn,\n EstreeNode,\n} from \"./interfaces\";\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,\n { typescript, rules }: LintOptions = {}\n): LintError[] {\n const errors: LintError[] = [];\n let file: ParseResult<File>;\n try {\n file = 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 linter handle errors.\n sourceType: \"unambiguous\",\n });\n } catch (e) {\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 const FunctionVisitor: EstreeVisitorFn = (\n node: FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n ) => {\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 };\n precook(func, {\n visitors: {\n ArrowFunctionExpression: FunctionVisitor,\n FunctionDeclaration: FunctionVisitor,\n FunctionExpression: FunctionVisitor,\n Literal(node: EstreeLiteral) {\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 },\n ObjectExpression(node: EstreeObjectExpression) {\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 },\n VariableDeclaration(node: 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.end.line,\n // Only decorate the \"var\".\n column: node.loc.start.column + 3,\n },\n },\n });\n }\n },\n __UnknownNode(node: EstreeNode) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n },\n __GlobalVariable(node: Identifier) {\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 },\n });\n }\n return errors;\n}\n"],"file":"lint.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/lint.ts"],"names":["lint","source","typescript","rules","errors","file","body","program","jsNodes","node","type","startsWith","test","push","message","loc","func","isFunctionDeclaration","unshift","start","line","column","end","FunctionVisitor","async","generator","visitors","ArrowFunctionExpression","FunctionDeclaration","FunctionExpression","Literal","regex","value","flags","includes","ObjectExpression","prop","properties","kind","computed","key","name","VariableDeclaration","noVar","__UnknownNode","__GlobalVariable"],"mappings":";;;;;;;AAkBA;;AACA;;AAaA;AACO,SAASA,IAAT,CACLC,MADK,EAEL;AAAEC,EAAAA,UAAF;AAAcC,EAAAA;AAAd,IAAqC,EAFhC,EAGQ;AACb,QAAMC,MAAmB,GAAG,EAA5B;AACA,QAAMC,IAAI,GACR,OAAOJ,MAAP,KAAkB,QAAlB,GACI,6BAAiBA,MAAjB,EAAyB;AAAEC,IAAAA;AAAF,GAAzB,CADJ,GAEID,MAHN;;AAIA,MAAI,CAACI,IAAL,EAAW;AACT;AACA,WAAO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,CAAaF,IADhB;AAEH;AACAC,kBAAAA,MAAM,EAAEZ,IAAI,CAACM,GAAL,CAASI,KAAT,CAAeE,MAAf,GAAwB;AAH7B;AAFF;AAJK,aAAZ;AAaD;AACF,SA5DO;;AA6DRuB,QAAAA,aAAa,CAACnC,IAAD,EAAmB;AAC9BL,UAAAA,MAAM,CAACS,IAAP,CAAY;AACVH,YAAAA,IAAI,EAAE,aADI;AAEVI,YAAAA,OAAO,EAAG,yBAAwBL,IAAI,CAACC,IAAK,IAFlC;AAGVK,YAAAA,GAAG,EAAEN,IAAI,CAACM;AAHA,WAAZ;AAKD,SAnEO;;AAoER8B,QAAAA,gBAAgB,CAACpC,IAAD,EAAmB;AACjC,cAAIA,IAAI,CAACgC,IAAL,KAAc,WAAlB,EAA+B;AAC7BrC,YAAAA,MAAM,CAACS,IAAP,CAAY;AACVH,cAAAA,IAAI,EAAE,aADI;AAEVI,cAAAA,OAAO,EAAE,gDAFC;AAGVC,cAAAA,GAAG,EAAEN,IAAI,CAACM;AAHA,aAAZ;AAKD;AACF;;AA5EO;AADE,KAAd;AAgFD;;AACD,SAAOX,MAAP;AACD","sourcesContent":["import { ParseResult } from \"@babel/parser\";\nimport {\n ArrowFunctionExpression,\n File,\n FunctionDeclaration,\n FunctionExpression,\n Identifier,\n SourceLocation,\n Statement,\n VariableDeclaration,\n} from \"@babel/types\";\nimport {\n EstreeLiteral,\n CookRules,\n EstreeObjectExpression,\n EstreeVisitorFn,\n EstreeNode,\n} from \"./interfaces\";\nimport { parseForAnalysis } from \"./parse\";\nimport { precook } from \"./precook\";\n\nexport interface LintOptions {\n typescript?: boolean;\n rules?: CookRules;\n}\n\nexport interface LintError {\n type: \"SyntaxError\" | \"TypeError\";\n message: string;\n loc: SourceLocation;\n}\n\n/** For next-core internal or devtools usage only. */\nexport function lint(\n source: string | ParseResult<File>,\n { typescript, rules }: LintOptions = {}\n): LintError[] {\n const errors: LintError[] = [];\n const file =\n typeof source === \"string\"\n ? parseForAnalysis(source, { typescript })\n : source;\n if (!file) {\n // Return no errors if parse failed.\n return errors;\n }\n const body = file.program.body;\n const jsNodes: Statement[] = typescript ? [] : body;\n if (typescript) {\n for (const node of body) {\n if (node.type.startsWith(\"TS\")) {\n if (/Enum|Import|Export/.test(node.type)) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported TypeScript syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n }\n } else {\n jsNodes.push(node);\n }\n }\n }\n let func: FunctionDeclaration;\n for (const node of jsNodes) {\n const isFunctionDeclaration = node.type === \"FunctionDeclaration\";\n if (isFunctionDeclaration && !func) {\n func = node;\n } else {\n errors.push({\n type: \"SyntaxError\",\n message: isFunctionDeclaration\n ? \"Expect a single function declaration\"\n : `\\`${node.type}\\` is not allowed in top level`,\n loc: node.loc,\n });\n }\n }\n if (!func) {\n errors.unshift({\n type: \"SyntaxError\",\n message: \"Function declaration not found\",\n loc: {\n start: { line: 1, column: 0 },\n end: { line: 1, column: 0 },\n },\n });\n } else {\n const FunctionVisitor: EstreeVisitorFn = (\n node: FunctionDeclaration | FunctionExpression | ArrowFunctionExpression\n ) => {\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 };\n precook(func, {\n visitors: {\n ArrowFunctionExpression: FunctionVisitor,\n FunctionDeclaration: FunctionVisitor,\n FunctionExpression: FunctionVisitor,\n Literal(node: EstreeLiteral) {\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 },\n ObjectExpression(node: EstreeObjectExpression) {\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 },\n VariableDeclaration(node: 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.end.line,\n // Only decorate the \"var\".\n column: node.loc.start.column + 3,\n },\n },\n });\n }\n },\n __UnknownNode(node: EstreeNode) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n },\n __GlobalVariable(node: Identifier) {\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 },\n });\n }\n return errors;\n}\n"],"file":"lint.js"}
|
package/dist/cjs/parse.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.parseAsEstree = parseAsEstree;
|
|
7
7
|
exports.parseAsEstreeExpression = parseAsEstreeExpression;
|
|
8
|
+
exports.parseForAnalysis = parseForAnalysis;
|
|
8
9
|
|
|
9
10
|
var _parser = require("@babel/parser");
|
|
10
11
|
|
|
@@ -50,4 +51,24 @@ function parseAsEstree(source, {
|
|
|
50
51
|
|
|
51
52
|
return jsNodes[0];
|
|
52
53
|
}
|
|
54
|
+
|
|
55
|
+
/** For next-core internal or devtools usage only. */
|
|
56
|
+
function parseForAnalysis(source, {
|
|
57
|
+
typescript,
|
|
58
|
+
tokens
|
|
59
|
+
} = {}) {
|
|
60
|
+
try {
|
|
61
|
+
return (0, _parser.parse)(source, {
|
|
62
|
+
plugins: ["estree", typescript && "typescript"].filter(Boolean),
|
|
63
|
+
strictMode: true,
|
|
64
|
+
attachComment: false,
|
|
65
|
+
// Allow export/import declarations to make analyser handle errors.
|
|
66
|
+
sourceType: "unambiguous",
|
|
67
|
+
tokens
|
|
68
|
+
});
|
|
69
|
+
} catch (e) {
|
|
70
|
+
// Return no errors if parse failed.
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
53
74
|
//# sourceMappingURL=parse.js.map
|
package/dist/cjs/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/parse.ts"],"names":["parseAsEstreeExpression","source","plugins","proposal","attachComment","parseAsEstree","typescript","file","filter","Boolean","strictMode","body","program","jsNodes","node","type","startsWith","test","SyntaxError","push","length","map","join"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/parse.ts"],"names":["parseAsEstreeExpression","source","plugins","proposal","attachComment","parseAsEstree","typescript","file","filter","Boolean","strictMode","body","program","jsNodes","node","type","startsWith","test","SyntaxError","push","length","map","join","parseForAnalysis","tokens","sourceType","e"],"mappings":";;;;;;;;;AAAA;;AAQO,SAASA,uBAAT,CAAiCC,MAAjC,EAA6D;AAClE,SAAO,6BAAgBA,MAAhB,EAAwB;AAC7BC,IAAAA,OAAO,EAAE,CAAC,QAAD,EAAW,CAAC,kBAAD,EAAqB;AAAEC,MAAAA,QAAQ,EAAE;AAAZ,KAArB,CAAX,CADoB;AAE7BC,IAAAA,aAAa,EAAE;AAFc,GAAxB,CAAP;AAID;;AAMM,SAASC,aAAT,CACLJ,MADK,EAEL;AAAEK,EAAAA;AAAF,IAAqC,EAFhC,EAGgB;AACrB,QAAMC,IAAI,GAAG,mBAAMN,MAAN,EAAc;AACzBC,IAAAA,OAAO,EAAE,CAAC,QAAD,EAAWI,UAAU,IAAI,YAAzB,EAAuCE,MAAvC,CACPC,OADO,CADgB;AAIzBC,IAAAA,UAAU,EAAE,IAJa;AAKzBN,IAAAA,aAAa,EAAE;AALU,GAA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EAAE,KALI;AAMnB;AACAqB,MAAAA,UAAU,EAAE,aAPO;AAQnBD,MAAAA;AARmB,KAAd,CAAP;AAUD,GAXD,CAWE,OAAOE,CAAP,EAAU;AACV;AACA,WAAO,IAAP;AACD;AACF","sourcesContent":["import {\n parse,\n parseExpression,\n ParseResult,\n ParserPlugin,\n} from \"@babel/parser\";\nimport { Expression, File, FunctionDeclaration, Statement } from \"@babel/types\";\n\nexport function parseAsEstreeExpression(source: string): Expression {\n return parseExpression(source, {\n plugins: [\"estree\", [\"pipelineOperator\", { proposal: \"minimal\" }]],\n attachComment: false,\n });\n}\n\nexport interface ParseEstreeOptions {\n typescript?: boolean;\n}\n\nexport function parseAsEstree(\n source: string,\n { typescript }: ParseEstreeOptions = {}\n): FunctionDeclaration {\n const file = parse(source, {\n plugins: [\"estree\", typescript && \"typescript\"].filter(\n Boolean\n ) as ParserPlugin[],\n strictMode: true,\n attachComment: false,\n });\n const body = file.program.body;\n const jsNodes: Statement[] = typescript ? [] : body;\n if (typescript) {\n for (const node of body) {\n if (node.type.startsWith(\"TS\")) {\n if (/Enum|Import|Export/.test(node.type)) {\n throw new SyntaxError(`Unsupported TypeScript syntax: ${node.type}`);\n }\n } else {\n jsNodes.push(node);\n }\n }\n }\n if (jsNodes.length === 0) {\n throw new SyntaxError(\"Function declaration not found\");\n }\n if (jsNodes.length > 1 || jsNodes[0].type !== \"FunctionDeclaration\") {\n throw new SyntaxError(\n `Expect a single function declaration at top level, but received: ${jsNodes\n .map((node) => `\"${node.type}\"`)\n .join(\", \")}`\n );\n }\n return jsNodes[0] as FunctionDeclaration;\n}\n\nexport interface AnalysisOptions {\n typescript?: boolean;\n tokens?: boolean;\n}\n\n/** For next-core internal or devtools usage only. */\nexport function parseForAnalysis(\n source: string,\n { typescript, tokens }: AnalysisOptions = {}\n): ParseResult<File> {\n try {\n return parse(source, {\n plugins: [\"estree\", typescript && \"typescript\"].filter(\n Boolean\n ) as ParserPlugin[],\n strictMode: true,\n attachComment: false,\n // Allow export/import declarations to make analyser handle errors.\n sourceType: \"unambiguous\",\n tokens,\n });\n } catch (e) {\n // Return no errors if parse failed.\n return null;\n }\n}\n"],"file":"parse.js"}
|
package/dist/esm/cook.js
CHANGED
|
@@ -4,13 +4,14 @@ import { sanitize, isAllowedConstructor } from "./sanitize";
|
|
|
4
4
|
import { collectBoundNames, collectScopedDeclarations, containsExpression } from "./traverse";
|
|
5
5
|
|
|
6
6
|
/** For next-core internal usage only. */
|
|
7
|
-
export function cook(rootAst, codeSource
|
|
8
|
-
rules,
|
|
9
|
-
globalVariables = {},
|
|
10
|
-
hooks = {}
|
|
11
|
-
} = {}) {
|
|
7
|
+
export function cook(rootAst, codeSource) {
|
|
12
8
|
var _hooks$beforeEvaluate3;
|
|
13
9
|
|
|
10
|
+
var {
|
|
11
|
+
rules,
|
|
12
|
+
globalVariables = {},
|
|
13
|
+
hooks = {}
|
|
14
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
14
15
|
var expressionOnly = rootAst.type !== "FunctionDeclaration";
|
|
15
16
|
var rootEnv = new DeclarativeEnvironment(null);
|
|
16
17
|
var rootContext = new ExecutionContext();
|