@next-core/cook 1.6.39 → 1.6.40
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 +11 -0
- package/dist/cjs/lint.js +1 -1
- package/dist/cjs/lint.js.map +1 -1
- package/dist/esm/lint.js +1 -1
- package/dist/esm/lint.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.40](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.6.39...@next-core/cook@1.6.40) (2022-08-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* fix linting with var in muti-line ([28c1f26](https://github.com/easyops-cn/next-core/commit/28c1f2611138f67ee650c942a86b217e77f30ba4))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [1.6.39](https://github.com/easyops-cn/next-core/compare/@next-core/cook@1.6.38...@next-core/cook@1.6.39) (2022-07-20)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @next-core/cook
|
package/dist/cjs/lint.js
CHANGED
package/dist/cjs/lint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lint.js","names":["lint","source","typescript","rules","errors","file","parseForAnalysis","body","program","jsNodes","node","type","startsWith","test","push","message","loc","func","isFunctionDeclaration","unshift","start","line","column","end","precook","hooks","beforeVisit","async","generator","regex","value","flags","includes","prop","properties","kind","computed","key","name","noVar","beforeVisitGlobal","beforeVisitUnknown"],"sources":["../../src/lint.ts"],"sourcesContent":["import { ParseResult } from \"@babel/parser\";\nimport {\n File,\n FunctionDeclaration,\n SourceLocation,\n Statement,\n} from \"@babel/types\";\nimport { CookRules } from \"./interfaces\";\nimport { parseForAnalysis } from \"./parse\";\nimport { precook } from \"./precook\";\n\nexport interface LintOptions {\n typescript?: boolean;\n rules?: CookRules;\n}\n\nexport interface LintError {\n type: \"SyntaxError\" | \"TypeError\";\n message: string;\n loc: SourceLocation;\n}\n\n/** For next-core internal or devtools usage only. */\nexport function lint(\n source: string | ParseResult<File>,\n { typescript, rules }: LintOptions = {}\n): LintError[] {\n const errors: LintError[] = [];\n const file =\n typeof source === \"string\"\n ? parseForAnalysis(source, { typescript })\n : source;\n if (!file) {\n // Return no errors if parse failed.\n return errors;\n }\n const body = file.program.body;\n const jsNodes: Statement[] = typescript ? [] : body;\n if (typescript) {\n for (const node of body) {\n if (node.type.startsWith(\"TS\")) {\n if (/Enum|Import|Export/.test(node.type)) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported TypeScript syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n }\n } else {\n jsNodes.push(node);\n }\n }\n }\n let func: FunctionDeclaration;\n for (const node of jsNodes) {\n const isFunctionDeclaration = node.type === \"FunctionDeclaration\";\n if (isFunctionDeclaration && !func) {\n func = node;\n } else {\n errors.push({\n type: \"SyntaxError\",\n message: isFunctionDeclaration\n ? \"Expect a single function declaration\"\n : `\\`${node.type}\\` is not allowed in top level`,\n loc: node.loc,\n });\n }\n }\n if (!func) {\n errors.unshift({\n type: \"SyntaxError\",\n message: \"Function declaration not found\",\n loc: {\n start: { line: 1, column: 0 },\n end: { line: 1, column: 0 },\n },\n });\n } else {\n precook(func, {\n hooks: {\n beforeVisit(node) {\n switch (node.type) {\n case \"ArrowFunctionExpression\":\n case \"FunctionDeclaration\":\n case \"FunctionExpression\":\n if (node.async || node.generator) {\n errors.push({\n type: \"SyntaxError\",\n message: `${\n node.async ? \"Async\" : \"Generator\"\n } function is not allowed`,\n loc: node.loc,\n });\n }\n break;\n case \"Literal\":\n if (node.regex) {\n if (node.value === null) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Invalid regular expression\",\n loc: node.loc,\n });\n } else if (node.regex.flags.includes(\"u\")) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported unicode flag in regular expression\",\n loc: node.loc,\n });\n }\n }\n break;\n case \"ObjectExpression\":\n for (const prop of node.properties) {\n if (prop.type === \"Property\") {\n if (prop.kind !== \"init\") {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported object getter/setter property\",\n loc: prop.loc,\n });\n } else if (\n !prop.computed &&\n prop.key.type === \"Identifier\" &&\n prop.key.name === \"__proto__\"\n ) {\n errors.push({\n type: \"TypeError\",\n message: \"Setting '__proto__' property is not allowed\",\n loc: prop.key.loc,\n });\n }\n }\n }\n break;\n case \"VariableDeclaration\":\n if (node.kind === \"var\" && rules?.noVar) {\n errors.push({\n type: \"SyntaxError\",\n message:\n \"Var declaration is not recommended, use `let` or `const` instead\",\n loc: {\n start: node.loc.start,\n end: {\n line: node.loc.
|
|
1
|
+
{"version":3,"file":"lint.js","names":["lint","source","typescript","rules","errors","file","parseForAnalysis","body","program","jsNodes","node","type","startsWith","test","push","message","loc","func","isFunctionDeclaration","unshift","start","line","column","end","precook","hooks","beforeVisit","async","generator","regex","value","flags","includes","prop","properties","kind","computed","key","name","noVar","beforeVisitGlobal","beforeVisitUnknown"],"sources":["../../src/lint.ts"],"sourcesContent":["import { ParseResult } from \"@babel/parser\";\nimport {\n File,\n FunctionDeclaration,\n SourceLocation,\n Statement,\n} from \"@babel/types\";\nimport { CookRules } from \"./interfaces\";\nimport { parseForAnalysis } from \"./parse\";\nimport { precook } from \"./precook\";\n\nexport interface LintOptions {\n typescript?: boolean;\n rules?: CookRules;\n}\n\nexport interface LintError {\n type: \"SyntaxError\" | \"TypeError\";\n message: string;\n loc: SourceLocation;\n}\n\n/** For next-core internal or devtools usage only. */\nexport function lint(\n source: string | ParseResult<File>,\n { typescript, rules }: LintOptions = {}\n): LintError[] {\n const errors: LintError[] = [];\n const file =\n typeof source === \"string\"\n ? parseForAnalysis(source, { typescript })\n : source;\n if (!file) {\n // Return no errors if parse failed.\n return errors;\n }\n const body = file.program.body;\n const jsNodes: Statement[] = typescript ? [] : body;\n if (typescript) {\n for (const node of body) {\n if (node.type.startsWith(\"TS\")) {\n if (/Enum|Import|Export/.test(node.type)) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported TypeScript syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n }\n } else {\n jsNodes.push(node);\n }\n }\n }\n let func: FunctionDeclaration;\n for (const node of jsNodes) {\n const isFunctionDeclaration = node.type === \"FunctionDeclaration\";\n if (isFunctionDeclaration && !func) {\n func = node;\n } else {\n errors.push({\n type: \"SyntaxError\",\n message: isFunctionDeclaration\n ? \"Expect a single function declaration\"\n : `\\`${node.type}\\` is not allowed in top level`,\n loc: node.loc,\n });\n }\n }\n if (!func) {\n errors.unshift({\n type: \"SyntaxError\",\n message: \"Function declaration not found\",\n loc: {\n start: { line: 1, column: 0 },\n end: { line: 1, column: 0 },\n },\n });\n } else {\n precook(func, {\n hooks: {\n beforeVisit(node) {\n switch (node.type) {\n case \"ArrowFunctionExpression\":\n case \"FunctionDeclaration\":\n case \"FunctionExpression\":\n if (node.async || node.generator) {\n errors.push({\n type: \"SyntaxError\",\n message: `${\n node.async ? \"Async\" : \"Generator\"\n } function is not allowed`,\n loc: node.loc,\n });\n }\n break;\n case \"Literal\":\n if (node.regex) {\n if (node.value === null) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Invalid regular expression\",\n loc: node.loc,\n });\n } else if (node.regex.flags.includes(\"u\")) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported unicode flag in regular expression\",\n loc: node.loc,\n });\n }\n }\n break;\n case \"ObjectExpression\":\n for (const prop of node.properties) {\n if (prop.type === \"Property\") {\n if (prop.kind !== \"init\") {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported object getter/setter property\",\n loc: prop.loc,\n });\n } else if (\n !prop.computed &&\n prop.key.type === \"Identifier\" &&\n prop.key.name === \"__proto__\"\n ) {\n errors.push({\n type: \"TypeError\",\n message: \"Setting '__proto__' property is not allowed\",\n loc: prop.key.loc,\n });\n }\n }\n }\n break;\n case \"VariableDeclaration\":\n if (node.kind === \"var\" && rules?.noVar) {\n errors.push({\n type: \"SyntaxError\",\n message:\n \"Var declaration is not recommended, use `let` or `const` instead\",\n loc: {\n start: node.loc.start,\n end: {\n line: node.loc.start.line,\n // Only decorate the \"var\".\n column: node.loc.start.column + 3,\n },\n },\n });\n }\n break;\n }\n },\n beforeVisitGlobal(node) {\n if (node.name === \"arguments\") {\n errors.push({\n type: \"SyntaxError\",\n message: \"Use the rest parameters instead of 'arguments'\",\n loc: node.loc,\n });\n }\n },\n beforeVisitUnknown(node) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n return true;\n },\n },\n });\n }\n return errors;\n}\n"],"mappings":";;;;;;;AAQA;;AACA;;AAaA;AACO,SAASA,IAAT,CACLC,MADK,EAEL;EAAEC,UAAF;EAAcC;AAAd,IAAqC,EAFhC,EAGQ;EACb,MAAMC,MAAmB,GAAG,EAA5B;EACA,MAAMC,IAAI,GACR,OAAOJ,MAAP,KAAkB,QAAlB,GACI,IAAAK,uBAAA,EAAiBL,MAAjB,EAAyB;IAAEC;EAAF,CAAzB,CADJ,GAEID,MAHN;;EAIA,IAAI,CAACI,IAAL,EAAW;IACT;IACA,OAAOD,MAAP;EACD;;EACD,MAAMG,IAAI,GAAGF,IAAI,CAACG,OAAL,CAAaD,IAA1B;EACA,MAAME,OAAoB,GAAGP,UAAU,GAAG,EAAH,GAAQK,IAA/C;;EACA,IAAIL,UAAJ,EAAgB;IACd,KAAK,MAAMQ,IAAX,IAAmBH,IAAnB,EAAyB;MACvB,IAAIG,IAAI,CAACC,IAAL,CAAUC,UAAV,CAAqB,IAArB,CAAJ,EAAgC;QAC9B,IAAI,qBAAqBC,IAArB,CAA0BH,IAAI,CAACC,IAA/B,CAAJ,EAA0C;UAC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G,EAAEiB,IAAI,CAACI,GAAL,CAASrB;oBAHJ,CAAZ;kBAKD;gBACF;cACF;;cACD;;YACF,KAAK,qBAAL;cACE,IAAIN,IAAI,CAACyB,IAAL,KAAc,KAAd,IAAuBhC,KAAvB,aAAuBA,KAAvB,eAAuBA,KAAK,CAAEoC,KAAlC,EAAyC;gBACvCnC,MAAM,CAACU,IAAP,CAAY;kBACVH,IAAI,EAAE,aADI;kBAEVI,OAAO,EACL,kEAHQ;kBAIVC,GAAG,EAAE;oBACHI,KAAK,EAAEV,IAAI,CAACM,GAAL,CAASI,KADb;oBAEHG,GAAG,EAAE;sBACHF,IAAI,EAAEX,IAAI,CAACM,GAAL,CAASI,KAAT,CAAeC,IADlB;sBAEH;sBACAC,MAAM,EAAEZ,IAAI,CAACM,GAAL,CAASI,KAAT,CAAeE,MAAf,GAAwB;oBAH7B;kBAFF;gBAJK,CAAZ;cAaD;;cACD;UAtEJ;QAwED,CA1EI;;QA2ELkB,iBAAiB,CAAC9B,IAAD,EAAO;UACtB,IAAIA,IAAI,CAAC4B,IAAL,KAAc,WAAlB,EAA+B;YAC7BlC,MAAM,CAACU,IAAP,CAAY;cACVH,IAAI,EAAE,aADI;cAEVI,OAAO,EAAE,gDAFC;cAGVC,GAAG,EAAEN,IAAI,CAACM;YAHA,CAAZ;UAKD;QACF,CAnFI;;QAoFLyB,kBAAkB,CAAC/B,IAAD,EAAO;UACvBN,MAAM,CAACU,IAAP,CAAY;YACVH,IAAI,EAAE,aADI;YAEVI,OAAO,EAAG,yBAAwBL,IAAI,CAACC,IAAK,IAFlC;YAGVK,GAAG,EAAEN,IAAI,CAACM;UAHA,CAAZ;UAKA,OAAO,IAAP;QACD;;MA3FI;IADK,CAAd;EA+FD;;EACD,OAAOZ,MAAP;AACD"}
|
package/dist/esm/lint.js
CHANGED
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 { ParseResult } from \"@babel/parser\";\nimport {\n File,\n FunctionDeclaration,\n SourceLocation,\n Statement,\n} from \"@babel/types\";\nimport { CookRules } from \"./interfaces\";\nimport { parseForAnalysis } from \"./parse\";\nimport { precook } from \"./precook\";\n\nexport interface LintOptions {\n typescript?: boolean;\n rules?: CookRules;\n}\n\nexport interface LintError {\n type: \"SyntaxError\" | \"TypeError\";\n message: string;\n loc: SourceLocation;\n}\n\n/** For next-core internal or devtools usage only. */\nexport function lint(\n source: string | ParseResult<File>,\n { typescript, rules }: LintOptions = {}\n): LintError[] {\n const errors: LintError[] = [];\n const file =\n typeof source === \"string\"\n ? parseForAnalysis(source, { typescript })\n : source;\n if (!file) {\n // Return no errors if parse failed.\n return errors;\n }\n const body = file.program.body;\n const jsNodes: Statement[] = typescript ? [] : body;\n if (typescript) {\n for (const node of body) {\n if (node.type.startsWith(\"TS\")) {\n if (/Enum|Import|Export/.test(node.type)) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported TypeScript syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n }\n } else {\n jsNodes.push(node);\n }\n }\n }\n let func: FunctionDeclaration;\n for (const node of jsNodes) {\n const isFunctionDeclaration = node.type === \"FunctionDeclaration\";\n if (isFunctionDeclaration && !func) {\n func = node;\n } else {\n errors.push({\n type: \"SyntaxError\",\n message: isFunctionDeclaration\n ? \"Expect a single function declaration\"\n : `\\`${node.type}\\` is not allowed in top level`,\n loc: node.loc,\n });\n }\n }\n if (!func) {\n errors.unshift({\n type: \"SyntaxError\",\n message: \"Function declaration not found\",\n loc: {\n start: { line: 1, column: 0 },\n end: { line: 1, column: 0 },\n },\n });\n } else {\n precook(func, {\n hooks: {\n beforeVisit(node) {\n switch (node.type) {\n case \"ArrowFunctionExpression\":\n case \"FunctionDeclaration\":\n case \"FunctionExpression\":\n if (node.async || node.generator) {\n errors.push({\n type: \"SyntaxError\",\n message: `${\n node.async ? \"Async\" : \"Generator\"\n } function is not allowed`,\n loc: node.loc,\n });\n }\n break;\n case \"Literal\":\n if (node.regex) {\n if (node.value === null) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Invalid regular expression\",\n loc: node.loc,\n });\n } else if (node.regex.flags.includes(\"u\")) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported unicode flag in regular expression\",\n loc: node.loc,\n });\n }\n }\n break;\n case \"ObjectExpression\":\n for (const prop of node.properties) {\n if (prop.type === \"Property\") {\n if (prop.kind !== \"init\") {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported object getter/setter property\",\n loc: prop.loc,\n });\n } else if (\n !prop.computed &&\n prop.key.type === \"Identifier\" &&\n prop.key.name === \"__proto__\"\n ) {\n errors.push({\n type: \"TypeError\",\n message: \"Setting '__proto__' property is not allowed\",\n loc: prop.key.loc,\n });\n }\n }\n }\n break;\n case \"VariableDeclaration\":\n if (node.kind === \"var\" && rules?.noVar) {\n errors.push({\n type: \"SyntaxError\",\n message:\n \"Var declaration is not recommended, use `let` or `const` instead\",\n loc: {\n start: node.loc.start,\n end: {\n line: node.loc.
|
|
1
|
+
{"version":3,"file":"lint.js","names":["parseForAnalysis","precook","lint","source","typescript","rules","errors","file","body","program","jsNodes","node","type","startsWith","test","push","message","loc","func","isFunctionDeclaration","unshift","start","line","column","end","hooks","beforeVisit","async","generator","regex","value","flags","includes","prop","properties","kind","computed","key","name","noVar","beforeVisitGlobal","beforeVisitUnknown"],"sources":["../../src/lint.ts"],"sourcesContent":["import { ParseResult } from \"@babel/parser\";\nimport {\n File,\n FunctionDeclaration,\n SourceLocation,\n Statement,\n} from \"@babel/types\";\nimport { CookRules } from \"./interfaces\";\nimport { parseForAnalysis } from \"./parse\";\nimport { precook } from \"./precook\";\n\nexport interface LintOptions {\n typescript?: boolean;\n rules?: CookRules;\n}\n\nexport interface LintError {\n type: \"SyntaxError\" | \"TypeError\";\n message: string;\n loc: SourceLocation;\n}\n\n/** For next-core internal or devtools usage only. */\nexport function lint(\n source: string | ParseResult<File>,\n { typescript, rules }: LintOptions = {}\n): LintError[] {\n const errors: LintError[] = [];\n const file =\n typeof source === \"string\"\n ? parseForAnalysis(source, { typescript })\n : source;\n if (!file) {\n // Return no errors if parse failed.\n return errors;\n }\n const body = file.program.body;\n const jsNodes: Statement[] = typescript ? [] : body;\n if (typescript) {\n for (const node of body) {\n if (node.type.startsWith(\"TS\")) {\n if (/Enum|Import|Export/.test(node.type)) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported TypeScript syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n }\n } else {\n jsNodes.push(node);\n }\n }\n }\n let func: FunctionDeclaration;\n for (const node of jsNodes) {\n const isFunctionDeclaration = node.type === \"FunctionDeclaration\";\n if (isFunctionDeclaration && !func) {\n func = node;\n } else {\n errors.push({\n type: \"SyntaxError\",\n message: isFunctionDeclaration\n ? \"Expect a single function declaration\"\n : `\\`${node.type}\\` is not allowed in top level`,\n loc: node.loc,\n });\n }\n }\n if (!func) {\n errors.unshift({\n type: \"SyntaxError\",\n message: \"Function declaration not found\",\n loc: {\n start: { line: 1, column: 0 },\n end: { line: 1, column: 0 },\n },\n });\n } else {\n precook(func, {\n hooks: {\n beforeVisit(node) {\n switch (node.type) {\n case \"ArrowFunctionExpression\":\n case \"FunctionDeclaration\":\n case \"FunctionExpression\":\n if (node.async || node.generator) {\n errors.push({\n type: \"SyntaxError\",\n message: `${\n node.async ? \"Async\" : \"Generator\"\n } function is not allowed`,\n loc: node.loc,\n });\n }\n break;\n case \"Literal\":\n if (node.regex) {\n if (node.value === null) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Invalid regular expression\",\n loc: node.loc,\n });\n } else if (node.regex.flags.includes(\"u\")) {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported unicode flag in regular expression\",\n loc: node.loc,\n });\n }\n }\n break;\n case \"ObjectExpression\":\n for (const prop of node.properties) {\n if (prop.type === \"Property\") {\n if (prop.kind !== \"init\") {\n errors.push({\n type: \"SyntaxError\",\n message: \"Unsupported object getter/setter property\",\n loc: prop.loc,\n });\n } else if (\n !prop.computed &&\n prop.key.type === \"Identifier\" &&\n prop.key.name === \"__proto__\"\n ) {\n errors.push({\n type: \"TypeError\",\n message: \"Setting '__proto__' property is not allowed\",\n loc: prop.key.loc,\n });\n }\n }\n }\n break;\n case \"VariableDeclaration\":\n if (node.kind === \"var\" && rules?.noVar) {\n errors.push({\n type: \"SyntaxError\",\n message:\n \"Var declaration is not recommended, use `let` or `const` instead\",\n loc: {\n start: node.loc.start,\n end: {\n line: node.loc.start.line,\n // Only decorate the \"var\".\n column: node.loc.start.column + 3,\n },\n },\n });\n }\n break;\n }\n },\n beforeVisitGlobal(node) {\n if (node.name === \"arguments\") {\n errors.push({\n type: \"SyntaxError\",\n message: \"Use the rest parameters instead of 'arguments'\",\n loc: node.loc,\n });\n }\n },\n beforeVisitUnknown(node) {\n errors.push({\n type: \"SyntaxError\",\n message: `Unsupported syntax: \\`${node.type}\\``,\n loc: node.loc,\n });\n return true;\n },\n },\n });\n }\n return errors;\n}\n"],"mappings":"AAQA,SAASA,gBAAT,QAAiC,SAAjC;AACA,SAASC,OAAT,QAAwB,WAAxB;;AAaA;AACA,OAAO,SAASC,IAAT,CACLC,MADK,EAGQ;EAAA,IADb;IAAEC,UAAF;IAAcC;EAAd,CACa,uEADwB,EACxB;EACb,IAAMC,MAAmB,GAAG,EAA5B;EACA,IAAMC,IAAI,GACR,OAAOJ,MAAP,KAAkB,QAAlB,GACIH,gBAAgB,CAACG,MAAD,EAAS;IAAEC;EAAF,CAAT,CADpB,GAEID,MAHN;;EAIA,IAAI,CAACI,IAAL,EAAW;IACT;IACA,OAAOD,MAAP;EACD;;EACD,IAAME,I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AAO,iCAA2BL,IAAI,CAACC,IAAhC,MAFG;YAGVK,GAAG,EAAEN,IAAI,CAACM;UAHA,CAAZ;UAKA,OAAO,IAAP;QACD;;MA3FI;IADK,CAAP,CAAP;EA+FD;;EACD,OAAOX,MAAP;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@next-core/cook",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.40",
|
|
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",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"sideEffects": false,
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/parser": "^7.18.9",
|
|
33
|
-
"@next-core/brick-types": "^2.
|
|
33
|
+
"@next-core/brick-types": "^2.66.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@next-core/supply": "^1.0.
|
|
36
|
+
"@next-core/supply": "^1.0.51",
|
|
37
37
|
"lodash": "^4.17.21"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "467118b05a753e109beb83a5be23691995e4012a"
|
|
40
40
|
}
|