From 98ddf8b58884f312bfa774804a3e52b4fb3b8ac9 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Tue, 29 Jun 2021 22:44:54 +0800 Subject: [PATCH] update periscopic (#6471) --- package-lock.json | 33 +++++++++++++++++-- package.json | 2 +- src/compiler/compile/Component.ts | 3 +- .../compile/nodes/shared/Expression.ts | 3 +- src/compiler/compile/render_dom/index.ts | 3 +- src/compiler/compile/render_ssr/index.ts | 5 +-- src/compiler/compile/utils/scope.ts | 4 +-- .../errors.json | 15 +++++++++ .../input.svelte | 3 ++ .../errors.json | 15 +++++++++ .../input.svelte | 3 ++ 11 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 test/validator/samples/default-export-anonymous-class/errors.json create mode 100644 test/validator/samples/default-export-anonymous-class/input.svelte create mode 100644 test/validator/samples/default-export-anonymous-function/errors.json create mode 100644 test/validator/samples/default-export-anonymous-function/input.svelte diff --git a/package-lock.json b/package-lock.json index a46f90c4b8..c51e9aff70 100644 --- a/package-lock.json +++ b/package-lock.json @@ -956,6 +956,24 @@ "is-reference": "^1.1.4", "periscopic": "^2.0.1", "sourcemap-codec": "^1.4.6" + }, + "dependencies": { + "estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + }, + "periscopic": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/periscopic/-/periscopic-2.0.3.tgz", + "integrity": "sha512-FuCZe61mWxQOJAQFEfmt9FjzebRlcpFz8sFPbyaCKtdusPkMEbA9ey0eARnRav5zAhmXznhaQkKGFAPn7X9NUw==", + "dev": true, + "requires": { + "estree-walker": "^2.0.2", + "is-reference": "^1.1.4" + } + } } }, "codecov": { @@ -3440,12 +3458,21 @@ "dev": true }, "periscopic": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/periscopic/-/periscopic-2.0.1.tgz", - "integrity": "sha512-twJ8e4RatllMAcbmBqKj8cvZ94HtqSzbb8hJoGj4iSCcCHXxKb06HRxOq4heyq2x/6mKynJDvTTreHCz+m6lJw==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/periscopic/-/periscopic-2.0.3.tgz", + "integrity": "sha512-FuCZe61mWxQOJAQFEfmt9FjzebRlcpFz8sFPbyaCKtdusPkMEbA9ey0eARnRav5zAhmXznhaQkKGFAPn7X9NUw==", "dev": true, "requires": { + "estree-walker": "^2.0.2", "is-reference": "^1.1.4" + }, + "dependencies": { + "estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "dev": true + } } }, "picomatch": { diff --git a/package.json b/package.json index 316cfcb9b0..6d85e5bf5b 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,7 @@ "locate-character": "^2.0.5", "magic-string": "^0.25.3", "mocha": "^7.0.0", - "periscopic": "^2.0.1", + "periscopic": "^2.0.3", "puppeteer": "^2.1.1", "rollup": "^1.27.14", "source-map": "^0.7.3", diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index e3738a8dba..241a2c05d4 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -10,6 +10,7 @@ import { Scope, extract_identifiers } from './utils/scope'; +import { Node as PeriscopicNode } from 'periscopic'; import Stylesheet from './css/Stylesheet'; import { test } from '../config'; import Fragment from './nodes/Fragment'; @@ -829,7 +830,7 @@ export default class Component { if (node.type === 'AssignmentExpression' || node.type === 'UpdateExpression') { const assignee = node.type === 'AssignmentExpression' ? node.left : node.argument; - const names = extract_names(assignee); + const names = extract_names(assignee as PeriscopicNode); const deep = assignee.type === 'MemberExpression'; diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts index cca81b6372..9253a47e70 100644 --- a/src/compiler/compile/nodes/shared/Expression.ts +++ b/src/compiler/compile/nodes/shared/Expression.ts @@ -17,6 +17,7 @@ import replace_object from '../../utils/replace_object'; import is_contextual from './is_contextual'; import EachBlock from '../EachBlock'; import { clone } from '../../../utils/clone'; +import { Node as PeriscopicNode } from 'periscopic'; type Owner = INode; @@ -356,7 +357,7 @@ export default class Expression { // (a or b). In destructuring cases (`[d, e] = [e, d]`) there // may be more, in which case we need to tack the extra ones // onto the initial function call - const names = new Set(extract_names(assignee)); + const names = new Set(extract_names(assignee as PeriscopicNode)); const traced: Set = new Set(); names.forEach(name => { diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 8be14c6b54..fc9c5b87dd 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -9,6 +9,7 @@ import Block from './Block'; import { ClassDeclaration, FunctionExpression, Node, Statement, ObjectExpression, Expression } from 'estree'; import { apply_preprocessor_sourcemap } from '../../utils/mapped_code'; import { RawSourceMap, DecodedSourceMap } from '@ampproject/remapping/dist/types/types'; +import { Node as PeriscopicNode } from 'periscopic'; export default function dom( component: Component, @@ -252,7 +253,7 @@ export default function dom( // (a or b). In destructuring cases (`[d, e] = [e, d]`) there // may be more, in which case we need to tack the extra ones // onto the initial function call - const names = new Set(extract_names(assignee)); + const names = new Set(extract_names(assignee as PeriscopicNode)); this.replace(invalidate(renderer, scope, node, names, execution_context === null)); } diff --git a/src/compiler/compile/render_ssr/index.ts b/src/compiler/compile/render_ssr/index.ts index 6a46475463..baafe40251 100644 --- a/src/compiler/compile/render_ssr/index.ts +++ b/src/compiler/compile/render_ssr/index.ts @@ -6,8 +6,9 @@ import Renderer from './Renderer'; import { INode as TemplateNode } from '../nodes/interfaces'; // TODO import Text from '../nodes/Text'; import { LabeledStatement, Statement, Node } from 'estree'; +import { Node as PeriscopicNode , extract_names } from 'periscopic'; import { walk } from 'estree-walker'; -import { extract_names } from 'periscopic'; + import { invalidate } from '../render_dom/invalidate'; export default function ssr( @@ -89,7 +90,7 @@ export default function ssr( if (node.type === 'AssignmentExpression' || node.type === 'UpdateExpression') { const assignee = node.type === 'AssignmentExpression' ? node.left : node.argument; - const names = new Set(extract_names(assignee)); + const names = new Set(extract_names(assignee as PeriscopicNode)); const to_invalidate = new Set(); for (const name of names) { diff --git a/src/compiler/compile/utils/scope.ts b/src/compiler/compile/utils/scope.ts index e103defa4d..033baf32c0 100644 --- a/src/compiler/compile/utils/scope.ts +++ b/src/compiler/compile/utils/scope.ts @@ -1,8 +1,8 @@ import { Node } from 'estree'; -import { analyze, Scope, extract_names, extract_identifiers } from 'periscopic'; +import { Node as PeriscopicNode, analyze, Scope, extract_names, extract_identifiers } from 'periscopic'; export function create_scopes(expression: Node) { - return analyze(expression); + return analyze(expression as PeriscopicNode); } export { Scope, extract_names, extract_identifiers }; diff --git a/test/validator/samples/default-export-anonymous-class/errors.json b/test/validator/samples/default-export-anonymous-class/errors.json new file mode 100644 index 0000000000..0a410e5eda --- /dev/null +++ b/test/validator/samples/default-export-anonymous-class/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "default-export", + "message": "A component cannot have a default export", + "pos": 10, + "start": { + "line": 2, + "column": 1, + "character": 10 + }, + "end": { + "line": 2, + "column": 30, + "character": 39 + } +}] diff --git a/test/validator/samples/default-export-anonymous-class/input.svelte b/test/validator/samples/default-export-anonymous-class/input.svelte new file mode 100644 index 0000000000..d78759e113 --- /dev/null +++ b/test/validator/samples/default-export-anonymous-class/input.svelte @@ -0,0 +1,3 @@ + diff --git a/test/validator/samples/default-export-anonymous-function/errors.json b/test/validator/samples/default-export-anonymous-function/errors.json new file mode 100644 index 0000000000..1f144e8392 --- /dev/null +++ b/test/validator/samples/default-export-anonymous-function/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "default-export", + "message": "A component cannot have a default export", + "pos": 10, + "start": { + "line": 2, + "column": 1, + "character": 10 + }, + "end": { + "line": 2, + "column": 24, + "character": 33 + } +}] diff --git a/test/validator/samples/default-export-anonymous-function/input.svelte b/test/validator/samples/default-export-anonymous-function/input.svelte new file mode 100644 index 0000000000..5e98ca42ab --- /dev/null +++ b/test/validator/samples/default-export-anonymous-function/input.svelte @@ -0,0 +1,3 @@ +