From 4d25d93ea08c552a06b4e16df38b90d89631723d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 29 Jan 2019 09:10:10 -0500 Subject: [PATCH] =?UTF-8?q?Overhaul=20stats=20=E2=80=94=20closes=20#1891?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Stats.ts | 13 +- src/compile/Component.ts | 340 ++++++++++-------- src/compile/css/Stylesheet.ts | 6 +- src/compile/nodes/Attribute.ts | 17 +- src/compile/nodes/Binding.ts | 19 +- src/compile/nodes/Element.ts | 3 +- src/compile/nodes/EventHandler.ts | 9 +- src/compile/nodes/InlineComponent.ts | 2 +- src/compile/nodes/shared/Expression.ts | 121 ++++--- src/compile/nodes/shared/TemplateScope.ts | 29 +- src/compile/render-dom/index.ts | 79 ++-- src/compile/render-dom/wrappers/AwaitBlock.ts | 8 +- src/compile/render-dom/wrappers/DebugTag.ts | 2 +- src/compile/render-dom/wrappers/EachBlock.ts | 4 +- .../render-dom/wrappers/Element/Attribute.ts | 4 +- .../render-dom/wrappers/Element/Binding.ts | 10 +- .../wrappers/Element/StyleAttribute.ts | 2 +- .../render-dom/wrappers/Element/index.ts | 23 +- src/compile/render-dom/wrappers/IfBlock.ts | 2 +- .../wrappers/InlineComponent/index.ts | 39 +- src/compile/render-dom/wrappers/Title.ts | 4 +- src/compile/render-dom/wrappers/Window.ts | 10 +- src/compile/render-dom/wrappers/shared/Tag.ts | 23 +- .../render-dom/wrappers/shared/addActions.ts | 14 +- src/compile/render-ssr/index.ts | 17 +- src/interfaces.ts | 21 +- src/parse/acorn.ts | 4 +- src/parse/index.ts | 22 +- src/parse/read/script.ts | 25 +- src/utils/annotateWithScopes.ts | 7 +- test/parser/index.js | 3 +- .../samples/action-with-call/output.json | 5 +- .../action-with-identifier/output.json | 5 +- .../samples/action-with-literal/output.json | 5 +- test/parser/samples/action/output.json | 5 +- test/parser/samples/animation/output.json | 5 +- .../attribute-containing-solidus/output.json | 5 +- .../attribute-dynamic-boolean/output.json | 5 +- .../attribute-dynamic-reserved/output.json | 5 +- .../samples/attribute-dynamic/output.json | 5 +- .../samples/attribute-escaped/output.json | 5 +- .../samples/attribute-multiple/output.json | 5 +- .../samples/attribute-shorthand/output.json | 5 +- .../attribute-static-boolean/output.json | 5 +- .../samples/attribute-static/output.json | 5 +- .../samples/attribute-unquoted/output.json | 5 +- .../samples/await-then-catch/output.json | 5 +- .../samples/binding-shorthand/output.json | 5 +- test/parser/samples/binding/output.json | 5 +- test/parser/samples/comment/output.json | 5 +- .../samples/component-dynamic/output.json | 5 +- .../convert-entities-in-element/output.json | 5 +- .../samples/convert-entities/output.json | 5 +- test/parser/samples/css/output.json | 117 +++--- .../parser/samples/dynamic-import/output.json | 328 +++++++++-------- .../each-block-destructured/output.json | 5 +- .../samples/each-block-else/output.json | 5 +- .../samples/each-block-indexed/output.json | 5 +- .../samples/each-block-keyed/output.json | 5 +- test/parser/samples/each-block/output.json | 5 +- .../samples/element-with-mustache/output.json | 5 +- .../samples/element-with-text/output.json | 5 +- test/parser/samples/elements/output.json | 5 +- test/parser/samples/event-handler/output.json | 5 +- test/parser/samples/if-block-else/output.json | 5 +- .../samples/if-block-elseif/output.json | 5 +- test/parser/samples/if-block/output.json | 5 +- .../samples/implicitly-closed-li/output.json | 5 +- test/parser/samples/nbsp/output.json | 5 +- test/parser/samples/raw-mustaches/output.json | 5 +- test/parser/samples/refs/output.json | 5 +- .../samples/script-comment-only/output.json | 25 +- .../output.json | 73 ++-- .../script-comment-trailing/output.json | 73 ++-- test/parser/samples/script/output.json | 73 ++-- .../samples/self-closing-element/output.json | 5 +- .../parser/samples/self-reference/output.json | 5 +- .../space-between-mustaches/output.json | 5 +- test/parser/samples/spread/output.json | 5 +- .../samples/textarea-children/output.json | 5 +- .../transition-intro-no-params/output.json | 5 +- .../samples/transition-intro/output.json | 5 +- .../samples/unusual-identifier/output.json | 5 +- .../whitespace-leading-trailing/output.json | 5 +- .../samples/whitespace-normal/output.json | 5 +- test/parser/samples/yield/output.json | 5 +- test/stats/samples/implicit-action/_config.js | 5 + test/stats/samples/implicit-action/input.html | 1 + test/stats/samples/implicit/_config.js | 5 + test/stats/samples/implicit/input.html | 1 + test/stats/samples/imports/_config.js | 32 +- .../mutated-vs-reassigned-bindings/_config.js | 26 ++ .../mutated-vs-reassigned-bindings/input.html | 7 + .../samples/mutated-vs-reassigned/_config.js | 26 ++ .../samples/mutated-vs-reassigned/input.html | 7 + test/stats/samples/props/_config.js | 43 ++- .../stats/samples/store-referenced/_config.js | 26 ++ .../stats/samples/store-referenced/input.html | 5 + .../samples/store-unreferenced/_config.js | 26 ++ .../samples/store-unreferenced/input.html | 4 + .../samples/template-references/_config.js | 5 +- test/stats/samples/undeclared/_config.js | 5 + test/stats/samples/undeclared/input.html | 3 + test/validator/index.js | 17 +- .../samples/binding-invalid-value/errors.json | 15 + .../samples/binding-invalid-value/input.html | 2 + .../errors.json | 6 +- .../errors.json | 6 +- .../script-invalid-context/errors.json | 4 +- 109 files changed, 1265 insertions(+), 828 deletions(-) create mode 100644 test/stats/samples/implicit-action/_config.js create mode 100644 test/stats/samples/implicit-action/input.html create mode 100644 test/stats/samples/implicit/_config.js create mode 100644 test/stats/samples/implicit/input.html create mode 100644 test/stats/samples/mutated-vs-reassigned-bindings/_config.js create mode 100644 test/stats/samples/mutated-vs-reassigned-bindings/input.html create mode 100644 test/stats/samples/mutated-vs-reassigned/_config.js create mode 100644 test/stats/samples/mutated-vs-reassigned/input.html create mode 100644 test/stats/samples/store-referenced/_config.js create mode 100644 test/stats/samples/store-referenced/input.html create mode 100644 test/stats/samples/store-unreferenced/_config.js create mode 100644 test/stats/samples/store-unreferenced/input.html create mode 100644 test/stats/samples/undeclared/_config.js create mode 100644 test/stats/samples/undeclared/input.html create mode 100644 test/validator/samples/binding-invalid-value/errors.json create mode 100644 test/validator/samples/binding-invalid-value/input.html diff --git a/src/Stats.ts b/src/Stats.ts index 33f651b2fa..5236e6a85c 100644 --- a/src/Stats.ts +++ b/src/Stats.ts @@ -97,11 +97,18 @@ export default class Stats { }); return { - props: component.props.map(prop => prop.as), timings, warnings: this.warnings, - imports, - templateReferences: component && component.template_references + vars: component.vars.filter(variable => !variable.global && !variable.implicit && !variable.internal).map(variable => ({ + name: variable.name, + export_name: variable.export_name || null, + injected: variable.injected || false, + module: variable.module || false, + mutated: variable.mutated || false, + reassigned: variable.reassigned || false, + referenced: variable.referenced || false, + writable: variable.writable || false + })) }; } diff --git a/src/compile/Component.ts b/src/compile/Component.ts index c7ca6b7feb..42d3f7a449 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -11,11 +11,10 @@ import Stylesheet from './css/Stylesheet'; import { test } from '../config'; import Fragment from './nodes/Fragment'; import internal_exports from './internal-exports'; -import { Node, Ast, CompileOptions } from '../interfaces'; +import { Node, Ast, CompileOptions, Var } from '../interfaces'; import error from '../utils/error'; import getCodeFrame from '../utils/getCodeFrame'; import flattenReference from '../utils/flattenReference'; -import addToSet from '../utils/addToSet'; import isReference from 'is-reference'; import TemplateScope from './nodes/shared/TemplateScope'; import fuzzymatch from '../utils/fuzzymatch'; @@ -56,31 +55,22 @@ export default class Component { namespace: string; tag: string; - instance_script: Node; - module_script: Node; + vars: Var[] = []; + var_lookup: Map = new Map(); imports: Node[] = []; module_javascript: string; javascript: string; - declarations: string[] = []; - props: Array<{ name: string, as: string }> = []; - writable_declarations: Set = new Set(); - initialised_declarations: Set = new Set(); - imported_declarations: Set = new Set(); - hoistable_names: Set = new Set(); hoistable_nodes: Set = new Set(); node_for_declaration: Map = new Map(); - module_exports: Array<{ name: string, as: string }> = []; partly_hoisted: string[] = []; fully_hoisted: string[] = []; reactive_declarations: Array<{ assignees: Set, dependencies: Set, snippet: string }> = []; reactive_declaration_nodes: Set = new Set(); has_reactive_assignments = false; - mutable_props: Set = new Set(); indirectDependencies: Map> = new Map(); - template_references: Set = new Set(); file: string; locate: (c: number) => { line: number, column: number }; @@ -93,7 +83,6 @@ export default class Component { stylesheet: Stylesheet; - userVars: Set = new Set(); aliases: Map = new Map(); usedNames: Set = new Set(); @@ -122,26 +111,6 @@ export default class Component { this.stylesheet = new Stylesheet(source, ast, options.filename, options.dev); this.stylesheet.validate(this); - const module_scripts = ast.js.filter(script => this.get_context(script) === 'module'); - const instance_scripts = ast.js.filter(script => this.get_context(script) === 'default'); - - if (module_scripts.length > 1) { - this.error(module_scripts[1], { - code: `invalid-script`, - message: `A component can only have one '; +function get_context(parser: Parser, attributes: Node[], start: number) { + const context = attributes.find(attribute => attribute.name === 'context'); + if (!context) return 'default'; + + if (context.value.length !== 1 || context.value[0].type !== 'Text') { + parser.error({ + code: 'invalid-script', + message: `context attribute must be static` + }, start); + } + + const value = context.value[0].data; + + if (value !== 'module') { + parser.error({ + code: `invalid-script`, + message: `If the context attribute is supplied, its value must be "module"` + }, context.start); + } + + return value; +} + export default function readScript(parser: Parser, start: number, attributes: Node[]) { const scriptStart = parser.index; const scriptEnd = parser.template.indexOf(scriptClosingTag, scriptStart); @@ -30,7 +53,7 @@ export default function readScript(parser: Parser, start: number, attributes: No return { start, end: parser.index, - attributes, + context: get_context(parser, attributes, start), content: ast, }; } diff --git a/src/utils/annotateWithScopes.ts b/src/utils/annotateWithScopes.ts index 96459e1ede..adf7619bed 100644 --- a/src/utils/annotateWithScopes.ts +++ b/src/utils/annotateWithScopes.ts @@ -52,6 +52,10 @@ export function createScopes(expression: Node) { }, }); + scope.declarations.forEach((node, name) => { + globals.delete(name); + }); + return { map, scope, globals }; } @@ -60,7 +64,6 @@ export class Scope { block: boolean; declarations: Map = new Map(); - writable_declarations: Set = new Set(); initialised_declarations: Set = new Set(); constructor(parent: Scope, block: boolean) { @@ -72,13 +75,11 @@ export class Scope { if (node.kind === 'var' && this.block && this.parent) { this.parent.addDeclaration(node); } else if (node.type === 'VariableDeclaration') { - const writable = node.kind !== 'const'; const initialised = !!node.init; node.declarations.forEach((declarator: Node) => { extractNames(declarator.id).forEach(name => { this.declarations.set(name, node); - if (writable) this.writable_declarations.add(name); if (initialised) this.initialised_declarations.add(name); }); }); diff --git a/test/parser/index.js b/test/parser/index.js index 8f20c77abd..900cc3ae05 100644 --- a/test/parser/index.js +++ b/test/parser/index.js @@ -31,7 +31,8 @@ describe('parse', () => { assert.deepEqual(ast.html, expectedOutput.html); assert.deepEqual(ast.css, expectedOutput.css); - assert.deepEqual(ast.js, expectedOutput.js); + assert.deepEqual(ast.instance, expectedOutput.instance); + assert.deepEqual(ast.module, expectedOutput.module); } catch (err) { if (err.name !== 'ParseError') throw err; if (!expectedError) throw err; diff --git a/test/parser/samples/action-with-call/output.json b/test/parser/samples/action-with-call/output.json index 521599544b..d6aaa72892 100644 --- a/test/parser/samples/action-with-call/output.json +++ b/test/parser/samples/action-with-call/output.json @@ -42,6 +42,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/action-with-identifier/output.json b/test/parser/samples/action-with-identifier/output.json index 800ab800be..d58b9097b7 100644 --- a/test/parser/samples/action-with-identifier/output.json +++ b/test/parser/samples/action-with-identifier/output.json @@ -28,6 +28,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/action-with-literal/output.json b/test/parser/samples/action-with-literal/output.json index 0705cd9e39..4a6f596d10 100644 --- a/test/parser/samples/action-with-literal/output.json +++ b/test/parser/samples/action-with-literal/output.json @@ -29,6 +29,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/action/output.json b/test/parser/samples/action/output.json index 68afd79d23..2f553b5efa 100644 --- a/test/parser/samples/action/output.json +++ b/test/parser/samples/action/output.json @@ -23,6 +23,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/animation/output.json b/test/parser/samples/animation/output.json index 585ab3ff1c..8332b3ad04 100644 --- a/test/parser/samples/animation/output.json +++ b/test/parser/samples/animation/output.json @@ -55,6 +55,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/attribute-containing-solidus/output.json b/test/parser/samples/attribute-containing-solidus/output.json index 920a9420c8..95372bd77d 100644 --- a/test/parser/samples/attribute-containing-solidus/output.json +++ b/test/parser/samples/attribute-containing-solidus/output.json @@ -36,6 +36,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-boolean/output.json b/test/parser/samples/attribute-dynamic-boolean/output.json index e50640f279..81a19f49b9 100644 --- a/test/parser/samples/attribute-dynamic-boolean/output.json +++ b/test/parser/samples/attribute-dynamic-boolean/output.json @@ -34,6 +34,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic-reserved/output.json b/test/parser/samples/attribute-dynamic-reserved/output.json index 042712b872..3a830d448f 100644 --- a/test/parser/samples/attribute-dynamic-reserved/output.json +++ b/test/parser/samples/attribute-dynamic-reserved/output.json @@ -34,6 +34,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/attribute-dynamic/output.json b/test/parser/samples/attribute-dynamic/output.json index f3099f6e62..50d8ec60a5 100644 --- a/test/parser/samples/attribute-dynamic/output.json +++ b/test/parser/samples/attribute-dynamic/output.json @@ -58,6 +58,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/attribute-escaped/output.json b/test/parser/samples/attribute-escaped/output.json index 979b54d713..6a4143e674 100644 --- a/test/parser/samples/attribute-escaped/output.json +++ b/test/parser/samples/attribute-escaped/output.json @@ -29,6 +29,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/attribute-multiple/output.json b/test/parser/samples/attribute-multiple/output.json index 5864363cdf..668409c0ef 100644 --- a/test/parser/samples/attribute-multiple/output.json +++ b/test/parser/samples/attribute-multiple/output.json @@ -43,6 +43,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/attribute-shorthand/output.json b/test/parser/samples/attribute-shorthand/output.json index 69f9329ed1..08ddf5eda9 100644 --- a/test/parser/samples/attribute-shorthand/output.json +++ b/test/parser/samples/attribute-shorthand/output.json @@ -34,6 +34,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/attribute-static-boolean/output.json b/test/parser/samples/attribute-static-boolean/output.json index 79ea9e9d11..f63b5734e0 100644 --- a/test/parser/samples/attribute-static-boolean/output.json +++ b/test/parser/samples/attribute-static-boolean/output.json @@ -22,6 +22,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/attribute-static/output.json b/test/parser/samples/attribute-static/output.json index cb0d7684da..3185e48736 100644 --- a/test/parser/samples/attribute-static/output.json +++ b/test/parser/samples/attribute-static/output.json @@ -29,6 +29,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/attribute-unquoted/output.json b/test/parser/samples/attribute-unquoted/output.json index 940ac5b01d..c7556f2eba 100644 --- a/test/parser/samples/attribute-unquoted/output.json +++ b/test/parser/samples/attribute-unquoted/output.json @@ -29,6 +29,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/await-then-catch/output.json b/test/parser/samples/await-then-catch/output.json index 1ab557f99d..21fc13eff9 100644 --- a/test/parser/samples/await-then-catch/output.json +++ b/test/parser/samples/await-then-catch/output.json @@ -155,6 +155,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/binding-shorthand/output.json b/test/parser/samples/binding-shorthand/output.json index c80fc5f7f2..3be1db50b4 100644 --- a/test/parser/samples/binding-shorthand/output.json +++ b/test/parser/samples/binding-shorthand/output.json @@ -28,6 +28,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/binding/output.json b/test/parser/samples/binding/output.json index 031d291fa7..5dc173c2a2 100644 --- a/test/parser/samples/binding/output.json +++ b/test/parser/samples/binding/output.json @@ -28,6 +28,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/comment/output.json b/test/parser/samples/comment/output.json index 10d85bf422..89295c188a 100644 --- a/test/parser/samples/comment/output.json +++ b/test/parser/samples/comment/output.json @@ -12,6 +12,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/component-dynamic/output.json b/test/parser/samples/component-dynamic/output.json index 9b08732c38..c2e4e3ee79 100644 --- a/test/parser/samples/component-dynamic/output.json +++ b/test/parser/samples/component-dynamic/output.json @@ -37,6 +37,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/convert-entities-in-element/output.json b/test/parser/samples/convert-entities-in-element/output.json index f481345a02..fb0f5b288e 100644 --- a/test/parser/samples/convert-entities-in-element/output.json +++ b/test/parser/samples/convert-entities-in-element/output.json @@ -21,6 +21,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/convert-entities/output.json b/test/parser/samples/convert-entities/output.json index b3e66a9007..ca1c1356f8 100644 --- a/test/parser/samples/convert-entities/output.json +++ b/test/parser/samples/convert-entities/output.json @@ -12,6 +12,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/css/output.json b/test/parser/samples/css/output.json index e91c31a71a..3127e01c71 100644 --- a/test/parser/samples/css/output.json +++ b/test/parser/samples/css/output.json @@ -27,71 +27,70 @@ } ] }, - "css": [ - { - "start": 16, - "end": 56, - "attributes": [], - "children": [ - { - "type": "Rule", - "selector": { - "type": "SelectorList", - "children": [ - { - "type": "Selector", + "css": { + "start": 16, + "end": 56, + "attributes": [], + "children": [ + { + "type": "Rule", + "selector": { + "type": "SelectorList", + "children": [ + { + "type": "Selector", + "children": [ + { + "type": "TypeSelector", + "name": "div", + "start": 25, + "end": 28 + } + ], + "start": 25, + "end": 28 + } + ], + "start": 25, + "end": 28 + }, + "block": { + "type": "Block", + "children": [ + { + "type": "Declaration", + "important": false, + "property": "color", + "value": { + "type": "Value", "children": [ { - "type": "TypeSelector", - "name": "div", - "start": 25, - "end": 28 + "type": "Identifier", + "name": "red", + "start": 40, + "end": 43 } ], - "start": 25, - "end": 28 - } - ], - "start": 25, - "end": 28 - }, - "block": { - "type": "Block", - "children": [ - { - "type": "Declaration", - "important": false, - "property": "color", - "value": { - "type": "Value", - "children": [ - { - "type": "Identifier", - "name": "red", - "start": 40, - "end": 43 - } - ], - "start": 39, - "end": 43 - }, - "start": 33, + "start": 39, "end": 43 - } - ], - "start": 29, - "end": 47 - }, - "start": 25, + }, + "start": 33, + "end": 43 + } + ], + "start": 29, "end": 47 - } - ], - "content": { - "start": 23, - "end": 48, - "styles": "\n\tdiv {\n\t\tcolor: red;\n\t}\n" + }, + "start": 25, + "end": 47 } + ], + "content": { + "start": 23, + "end": 48, + "styles": "\n\tdiv {\n\t\tcolor: red;\n\t}\n" } - ], - "js": [] + }, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/dynamic-import/output.json b/test/parser/samples/dynamic-import/output.json index 55c1bdf756..c0d4a45e0d 100644 --- a/test/parser/samples/dynamic-import/output.json +++ b/test/parser/samples/dynamic-import/output.json @@ -5,201 +5,199 @@ "type": "Fragment", "children": [] }, - "css": [], - "js": [ - { - "start": 0, - "end": 146, - "attributes": [], - "content": { - "type": "Program", - "start": 8, - "end": 137, - "body": [ - { - "type": "ImportDeclaration", - "start": 10, - "end": 43, - "specifiers": [ - { - "type": "ImportSpecifier", + "css": null, + "instance": { + "start": 0, + "end": 146, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 137, + "body": [ + { + "type": "ImportDeclaration", + "start": 10, + "end": 43, + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 19, + "end": 26, + "imported": { + "type": "Identifier", "start": 19, "end": 26, - "imported": { - "type": "Identifier", - "start": 19, - "end": 26, - "name": "onMount" - }, - "local": { - "type": "Identifier", - "start": 19, - "end": 26, - "name": "onMount" - } + "name": "onMount" + }, + "local": { + "type": "Identifier", + "start": 19, + "end": 26, + "name": "onMount" } - ], - "source": { - "type": "Literal", - "start": 34, - "end": 42, - "value": "svelte", - "raw": "'svelte'" } - }, - { - "type": "ExpressionStatement", + ], + "source": { + "type": "Literal", + "start": 34, + "end": 42, + "value": "svelte", + "raw": "'svelte'" + } + }, + { + "type": "ExpressionStatement", + "start": 46, + "end": 136, + "expression": { + "type": "CallExpression", "start": 46, - "end": 136, - "expression": { - "type": "CallExpression", + "end": 135, + "callee": { + "type": "Identifier", "start": 46, - "end": 135, - "callee": { - "type": "Identifier", - "start": 46, - "end": 53, - "name": "onMount" - }, - "arguments": [ - { - "type": "ArrowFunctionExpression", - "start": 54, + "end": 53, + "name": "onMount" + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 54, + "end": 134, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 60, "end": 134, - "id": null, - "generator": false, - "expression": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 60, - "end": 134, - "body": [ - { - "type": "ExpressionStatement", + "body": [ + { + "type": "ExpressionStatement", + "start": 64, + "end": 131, + "expression": { + "type": "CallExpression", "start": 64, - "end": 131, - "expression": { - "type": "CallExpression", + "end": 130, + "callee": { + "type": "MemberExpression", "start": 64, - "end": 130, - "callee": { - "type": "MemberExpression", + "end": 87, + "object": { + "type": "CallExpression", "start": 64, - "end": 87, - "object": { - "type": "CallExpression", + "end": 82, + "callee": { + "type": "Import", "start": 64, - "end": 82, - "callee": { - "type": "Import", - "start": 64, - "end": 70 - }, - "arguments": [ - { - "type": "Literal", - "start": 71, - "end": 81, - "value": "./foo.js", - "raw": "'./foo.js'" - } - ] - }, - "property": { - "type": "Identifier", - "start": 83, - "end": 87, - "name": "then" + "end": 70 }, - "computed": false + "arguments": [ + { + "type": "Literal", + "start": 71, + "end": 81, + "value": "./foo.js", + "raw": "'./foo.js'" + } + ] + }, + "property": { + "type": "Identifier", + "start": 83, + "end": 87, + "name": "then" }, - "arguments": [ - { - "type": "ArrowFunctionExpression", - "start": 88, + "computed": false + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "start": 88, + "end": 129, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 88, + "end": 91, + "name": "foo" + } + ], + "body": { + "type": "BlockStatement", + "start": 95, "end": 129, - "id": null, - "generator": false, - "expression": false, - "async": false, - "params": [ + "body": [ { - "type": "Identifier", - "start": 88, - "end": 91, - "name": "foo" - } - ], - "body": { - "type": "BlockStatement", - "start": 95, - "end": 129, - "body": [ - { - "type": "ExpressionStatement", + "type": "ExpressionStatement", + "start": 100, + "end": 125, + "expression": { + "type": "CallExpression", "start": 100, - "end": 125, - "expression": { - "type": "CallExpression", + "end": 124, + "callee": { + "type": "MemberExpression", "start": 100, - "end": 124, - "callee": { - "type": "MemberExpression", + "end": 111, + "object": { + "type": "Identifier", "start": 100, + "end": 107, + "name": "console" + }, + "property": { + "type": "Identifier", + "start": 108, "end": 111, + "name": "log" + }, + "computed": false + }, + "arguments": [ + { + "type": "MemberExpression", + "start": 112, + "end": 123, "object": { "type": "Identifier", - "start": 100, - "end": 107, - "name": "console" + "start": 112, + "end": 115, + "name": "foo" }, "property": { "type": "Identifier", - "start": 108, - "end": 111, - "name": "log" + "start": 116, + "end": 123, + "name": "default" }, "computed": false - }, - "arguments": [ - { - "type": "MemberExpression", - "start": 112, - "end": 123, - "object": { - "type": "Identifier", - "start": 112, - "end": 115, - "name": "foo" - }, - "property": { - "type": "Identifier", - "start": 116, - "end": 123, - "name": "default" - }, - "computed": false - } - ] - } + } + ] } - ] - } + } + ] } - ] - } + } + ] } - ] - } + } + ] } - ] - } + } + ] } - ], - "sourceType": "module" - } + } + ], + "sourceType": "module" } - ] + } } \ No newline at end of file diff --git a/test/parser/samples/each-block-destructured/output.json b/test/parser/samples/each-block-destructured/output.json index fdca5f82a2..b9efc18906 100644 --- a/test/parser/samples/each-block-destructured/output.json +++ b/test/parser/samples/each-block-destructured/output.json @@ -75,6 +75,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/each-block-else/output.json b/test/parser/samples/each-block-else/output.json index be0ac6d550..aefc8c2f39 100644 --- a/test/parser/samples/each-block-else/output.json +++ b/test/parser/samples/each-block-else/output.json @@ -67,6 +67,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/each-block-indexed/output.json b/test/parser/samples/each-block-indexed/output.json index bda5f86a89..7518652468 100644 --- a/test/parser/samples/each-block-indexed/output.json +++ b/test/parser/samples/each-block-indexed/output.json @@ -63,6 +63,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/each-block-keyed/output.json b/test/parser/samples/each-block-keyed/output.json index a00694fc4e..fe893bcdb9 100644 --- a/test/parser/samples/each-block-keyed/output.json +++ b/test/parser/samples/each-block-keyed/output.json @@ -63,6 +63,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/each-block/output.json b/test/parser/samples/each-block/output.json index a24c32e9ad..c16a71ad5d 100644 --- a/test/parser/samples/each-block/output.json +++ b/test/parser/samples/each-block/output.json @@ -45,6 +45,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/element-with-mustache/output.json b/test/parser/samples/element-with-mustache/output.json index a56cd27967..c8a386d681 100644 --- a/test/parser/samples/element-with-mustache/output.json +++ b/test/parser/samples/element-with-mustache/output.json @@ -38,6 +38,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/element-with-text/output.json b/test/parser/samples/element-with-text/output.json index 1ae33df94f..70f6163c93 100644 --- a/test/parser/samples/element-with-text/output.json +++ b/test/parser/samples/element-with-text/output.json @@ -21,6 +21,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/elements/output.json b/test/parser/samples/elements/output.json index 219799df3e..d216f7f5d8 100644 --- a/test/parser/samples/elements/output.json +++ b/test/parser/samples/elements/output.json @@ -22,6 +22,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/event-handler/output.json b/test/parser/samples/event-handler/output.json index 740e43e48d..b1fe89fc2a 100644 --- a/test/parser/samples/event-handler/output.json +++ b/test/parser/samples/event-handler/output.json @@ -98,6 +98,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/if-block-else/output.json b/test/parser/samples/if-block-else/output.json index 8e96c34efc..dedf2797c4 100644 --- a/test/parser/samples/if-block-else/output.json +++ b/test/parser/samples/if-block-else/output.json @@ -56,6 +56,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/if-block-elseif/output.json b/test/parser/samples/if-block-elseif/output.json index 257eb1e7d2..426e1f7fbc 100644 --- a/test/parser/samples/if-block-elseif/output.json +++ b/test/parser/samples/if-block-elseif/output.json @@ -96,6 +96,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/if-block/output.json b/test/parser/samples/if-block/output.json index ba734c0e56..d560824766 100644 --- a/test/parser/samples/if-block/output.json +++ b/test/parser/samples/if-block/output.json @@ -25,6 +25,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/implicitly-closed-li/output.json b/test/parser/samples/implicitly-closed-li/output.json index 69def7a9a2..caf69d7109 100644 --- a/test/parser/samples/implicitly-closed-li/output.json +++ b/test/parser/samples/implicitly-closed-li/output.json @@ -66,6 +66,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/nbsp/output.json b/test/parser/samples/nbsp/output.json index 7373bc9673..4fa318ce48 100644 --- a/test/parser/samples/nbsp/output.json +++ b/test/parser/samples/nbsp/output.json @@ -21,6 +21,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/raw-mustaches/output.json b/test/parser/samples/raw-mustaches/output.json index 41dab885e0..1d92b21c85 100644 --- a/test/parser/samples/raw-mustaches/output.json +++ b/test/parser/samples/raw-mustaches/output.json @@ -55,6 +55,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/refs/output.json b/test/parser/samples/refs/output.json index 3cd6c4d9fa..2cf5054304 100644 --- a/test/parser/samples/refs/output.json +++ b/test/parser/samples/refs/output.json @@ -28,6 +28,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/script-comment-only/output.json b/test/parser/samples/script-comment-only/output.json index b04d38633d..95ca769b20 100644 --- a/test/parser/samples/script-comment-only/output.json +++ b/test/parser/samples/script-comment-only/output.json @@ -20,19 +20,16 @@ } ] }, - "css": [], - "js": [ - { - "start": 0, - "end": 43, - "attributes": [], - "content": { - "type": "Program", - "start": 8, - "end": 34, - "body": [], - "sourceType": "module" - } + "instance": { + "start": 0, + "end": 43, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 34, + "body": [], + "sourceType": "module" } - ] + } } \ No newline at end of file diff --git a/test/parser/samples/script-comment-trailing-multiline/output.json b/test/parser/samples/script-comment-trailing-multiline/output.json index a32ff799f7..d4a45911a1 100644 --- a/test/parser/samples/script-comment-trailing-multiline/output.json +++ b/test/parser/samples/script-comment-trailing-multiline/output.json @@ -44,46 +44,43 @@ } ] }, - "css": [], - "js": [ - { - "start": 0, - "end": 77, - "attributes": [], - "content": { - "type": "Program", - "start": 8, - "end": 68, - "body": [ - { - "type": "VariableDeclaration", - "start": 10, - "end": 29, - "declarations": [ - { - "type": "VariableDeclarator", + "instance": { + "start": 0, + "end": 77, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 68, + "body": [ + { + "type": "VariableDeclaration", + "start": 10, + "end": 29, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 14, + "end": 28, + "id": { + "type": "Identifier", "start": 14, + "end": 18, + "name": "name" + }, + "init": { + "type": "Literal", + "start": 21, "end": 28, - "id": { - "type": "Identifier", - "start": 14, - "end": 18, - "name": "name" - }, - "init": { - "type": "Literal", - "start": 21, - "end": 28, - "value": "world", - "raw": "'world'" - } + "value": "world", + "raw": "'world'" } - ], - "kind": "let" - } - ], - "sourceType": "module" - } + } + ], + "kind": "let" + } + ], + "sourceType": "module" } - ] + } } \ No newline at end of file diff --git a/test/parser/samples/script-comment-trailing/output.json b/test/parser/samples/script-comment-trailing/output.json index 78012d4438..92d431b558 100644 --- a/test/parser/samples/script-comment-trailing/output.json +++ b/test/parser/samples/script-comment-trailing/output.json @@ -44,46 +44,43 @@ } ] }, - "css": [], - "js": [ - { - "start": 0, - "end": 66, - "attributes": [], - "content": { - "type": "Program", - "start": 8, - "end": 57, - "body": [ - { - "type": "VariableDeclaration", - "start": 10, - "end": 29, - "declarations": [ - { - "type": "VariableDeclarator", + "instance": { + "start": 0, + "end": 66, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 57, + "body": [ + { + "type": "VariableDeclaration", + "start": 10, + "end": 29, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 14, + "end": 28, + "id": { + "type": "Identifier", "start": 14, + "end": 18, + "name": "name" + }, + "init": { + "type": "Literal", + "start": 21, "end": 28, - "id": { - "type": "Identifier", - "start": 14, - "end": 18, - "name": "name" - }, - "init": { - "type": "Literal", - "start": 21, - "end": 28, - "value": "world", - "raw": "'world'" - } + "value": "world", + "raw": "'world'" } - ], - "kind": "let" - } - ], - "sourceType": "module" - } + } + ], + "kind": "let" + } + ], + "sourceType": "module" } - ] + } } \ No newline at end of file diff --git a/test/parser/samples/script/output.json b/test/parser/samples/script/output.json index bf89a0ff02..95966f5dc6 100644 --- a/test/parser/samples/script/output.json +++ b/test/parser/samples/script/output.json @@ -44,46 +44,43 @@ } ] }, - "css": [], - "js": [ - { - "start": 0, - "end": 39, - "attributes": [], - "content": { - "type": "Program", - "start": 8, - "end": 30, - "body": [ - { - "type": "VariableDeclaration", - "start": 10, - "end": 29, - "declarations": [ - { - "type": "VariableDeclarator", + "instance": { + "start": 0, + "end": 39, + "context": "default", + "content": { + "type": "Program", + "start": 8, + "end": 30, + "body": [ + { + "type": "VariableDeclaration", + "start": 10, + "end": 29, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 14, + "end": 28, + "id": { + "type": "Identifier", "start": 14, + "end": 18, + "name": "name" + }, + "init": { + "type": "Literal", + "start": 21, "end": 28, - "id": { - "type": "Identifier", - "start": 14, - "end": 18, - "name": "name" - }, - "init": { - "type": "Literal", - "start": 21, - "end": 28, - "value": "world", - "raw": "'world'" - } + "value": "world", + "raw": "'world'" } - ], - "kind": "let" - } - ], - "sourceType": "module" - } + } + ], + "kind": "let" + } + ], + "sourceType": "module" } - ] + } } \ No newline at end of file diff --git a/test/parser/samples/self-closing-element/output.json b/test/parser/samples/self-closing-element/output.json index f7475b41d7..47eea2f333 100644 --- a/test/parser/samples/self-closing-element/output.json +++ b/test/parser/samples/self-closing-element/output.json @@ -14,6 +14,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/self-reference/output.json b/test/parser/samples/self-reference/output.json index ff111e17ba..de5112a087 100644 --- a/test/parser/samples/self-reference/output.json +++ b/test/parser/samples/self-reference/output.json @@ -73,6 +73,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/space-between-mustaches/output.json b/test/parser/samples/space-between-mustaches/output.json index d66735213d..c89409daeb 100644 --- a/test/parser/samples/space-between-mustaches/output.json +++ b/test/parser/samples/space-between-mustaches/output.json @@ -72,6 +72,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/spread/output.json b/test/parser/samples/spread/output.json index a632dc89ab..3986da3578 100644 --- a/test/parser/samples/spread/output.json +++ b/test/parser/samples/spread/output.json @@ -26,6 +26,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/textarea-children/output.json b/test/parser/samples/textarea-children/output.json index 08f42919ed..3b403458fc 100644 --- a/test/parser/samples/textarea-children/output.json +++ b/test/parser/samples/textarea-children/output.json @@ -44,6 +44,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/transition-intro-no-params/output.json b/test/parser/samples/transition-intro-no-params/output.json index d53b4d9d88..edb15457e6 100644 --- a/test/parser/samples/transition-intro-no-params/output.json +++ b/test/parser/samples/transition-intro-no-params/output.json @@ -32,6 +32,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/transition-intro/output.json b/test/parser/samples/transition-intro/output.json index 6405d0bad5..5583dd89bc 100644 --- a/test/parser/samples/transition-intro/output.json +++ b/test/parser/samples/transition-intro/output.json @@ -60,6 +60,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/unusual-identifier/output.json b/test/parser/samples/unusual-identifier/output.json index fe9b175128..c0d4ecc3ff 100644 --- a/test/parser/samples/unusual-identifier/output.json +++ b/test/parser/samples/unusual-identifier/output.json @@ -45,6 +45,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/whitespace-leading-trailing/output.json b/test/parser/samples/whitespace-leading-trailing/output.json index 7dbf259721..f164af01ba 100644 --- a/test/parser/samples/whitespace-leading-trailing/output.json +++ b/test/parser/samples/whitespace-leading-trailing/output.json @@ -27,6 +27,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/whitespace-normal/output.json b/test/parser/samples/whitespace-normal/output.json index c150b53f04..e4ce956331 100644 --- a/test/parser/samples/whitespace-normal/output.json +++ b/test/parser/samples/whitespace-normal/output.json @@ -62,6 +62,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/parser/samples/yield/output.json b/test/parser/samples/yield/output.json index b16ab436f6..16ea79d8e8 100644 --- a/test/parser/samples/yield/output.json +++ b/test/parser/samples/yield/output.json @@ -17,6 +17,7 @@ } ] }, - "css": [], - "js": [] + "css": null, + "instance": null, + "module": null } \ No newline at end of file diff --git a/test/stats/samples/implicit-action/_config.js b/test/stats/samples/implicit-action/_config.js new file mode 100644 index 0000000000..71c255d54b --- /dev/null +++ b/test/stats/samples/implicit-action/_config.js @@ -0,0 +1,5 @@ +export default { + test(assert, stats) { + assert.deepEqual(stats.vars, []); + }, +}; diff --git a/test/stats/samples/implicit-action/input.html b/test/stats/samples/implicit-action/input.html new file mode 100644 index 0000000000..466495d255 --- /dev/null +++ b/test/stats/samples/implicit-action/input.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/test/stats/samples/implicit/_config.js b/test/stats/samples/implicit/_config.js new file mode 100644 index 0000000000..71c255d54b --- /dev/null +++ b/test/stats/samples/implicit/_config.js @@ -0,0 +1,5 @@ +export default { + test(assert, stats) { + assert.deepEqual(stats.vars, []); + }, +}; diff --git a/test/stats/samples/implicit/input.html b/test/stats/samples/implicit/input.html new file mode 100644 index 0000000000..e076ac55f8 --- /dev/null +++ b/test/stats/samples/implicit/input.html @@ -0,0 +1 @@ +{foo} \ No newline at end of file diff --git a/test/stats/samples/imports/_config.js b/test/stats/samples/imports/_config.js index f7c15183dd..287c5837ad 100644 --- a/test/stats/samples/imports/_config.js +++ b/test/stats/samples/imports/_config.js @@ -1,17 +1,35 @@ export default { test(assert, stats) { - assert.deepEqual(stats.imports, [ + assert.deepEqual(stats.vars, [ { - source: 'x', - specifiers: [{ name: 'default', as: 'x' }] + name: 'x', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: false }, { - source: 'y', - specifiers: [{ name: 'y', as: 'y' }] + name: 'y', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: false }, { - source: 'z', - specifiers: [{ name: '*', as: 'z' }] + name: 'z', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: false } ]); } diff --git a/test/stats/samples/mutated-vs-reassigned-bindings/_config.js b/test/stats/samples/mutated-vs-reassigned-bindings/_config.js new file mode 100644 index 0000000000..a1d027cbb5 --- /dev/null +++ b/test/stats/samples/mutated-vs-reassigned-bindings/_config.js @@ -0,0 +1,26 @@ +export default { + test(assert, stats) { + assert.deepEqual(stats.vars, [ + { + name: 'count', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: true, + referenced: true, + writable: true + }, + { + name: 'user', + export_name: null, + injected: false, + module: false, + mutated: true, + reassigned: false, + referenced: true, + writable: false + } + ]); + } +}; \ No newline at end of file diff --git a/test/stats/samples/mutated-vs-reassigned-bindings/input.html b/test/stats/samples/mutated-vs-reassigned-bindings/input.html new file mode 100644 index 0000000000..c1186ad3a7 --- /dev/null +++ b/test/stats/samples/mutated-vs-reassigned-bindings/input.html @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/test/stats/samples/mutated-vs-reassigned/_config.js b/test/stats/samples/mutated-vs-reassigned/_config.js new file mode 100644 index 0000000000..a1d027cbb5 --- /dev/null +++ b/test/stats/samples/mutated-vs-reassigned/_config.js @@ -0,0 +1,26 @@ +export default { + test(assert, stats) { + assert.deepEqual(stats.vars, [ + { + name: 'count', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: true, + referenced: true, + writable: true + }, + { + name: 'user', + export_name: null, + injected: false, + module: false, + mutated: true, + reassigned: false, + referenced: true, + writable: false + } + ]); + } +}; \ No newline at end of file diff --git a/test/stats/samples/mutated-vs-reassigned/input.html b/test/stats/samples/mutated-vs-reassigned/input.html new file mode 100644 index 0000000000..6a5e604c26 --- /dev/null +++ b/test/stats/samples/mutated-vs-reassigned/input.html @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/test/stats/samples/props/_config.js b/test/stats/samples/props/_config.js index 50c01e2ffb..cbec831f61 100644 --- a/test/stats/samples/props/_config.js +++ b/test/stats/samples/props/_config.js @@ -1,5 +1,46 @@ export default { test(assert, stats) { - assert.deepEqual(stats.props.sort(), ['cats', 'name']); + assert.deepEqual(stats.vars, [ + { + name: 'name', + export_name: 'name', + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: true, + writable: true + }, + { + name: 'cats', + export_name: 'cats', + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: true, + writable: true + }, + { + name: 'foo', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: false, + writable: true + }, + { + name: 'bar', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: true, + referenced: true, + writable: true + } + ]); } }; \ No newline at end of file diff --git a/test/stats/samples/store-referenced/_config.js b/test/stats/samples/store-referenced/_config.js new file mode 100644 index 0000000000..ecb958df1e --- /dev/null +++ b/test/stats/samples/store-referenced/_config.js @@ -0,0 +1,26 @@ +export default { + test(assert, stats) { + assert.deepEqual(stats.vars, [ + { + name: 'foo', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: true, + writable: true + }, + { + name: '$foo', + export_name: null, + injected: true, + module: false, + mutated: true, + reassigned: false, + referenced: true, + writable: true + } + ]); + } +}; diff --git a/test/stats/samples/store-referenced/input.html b/test/stats/samples/store-referenced/input.html new file mode 100644 index 0000000000..0222372f4d --- /dev/null +++ b/test/stats/samples/store-referenced/input.html @@ -0,0 +1,5 @@ + + +{$foo} \ No newline at end of file diff --git a/test/stats/samples/store-unreferenced/_config.js b/test/stats/samples/store-unreferenced/_config.js new file mode 100644 index 0000000000..9ea5784f92 --- /dev/null +++ b/test/stats/samples/store-unreferenced/_config.js @@ -0,0 +1,26 @@ +export default { + test(assert, stats) { + assert.deepEqual(stats.vars, [ + { + name: 'foo', + export_name: null, + injected: false, + module: false, + mutated: false, + reassigned: false, + referenced: true, + writable: true + }, + { + name: '$foo', + export_name: null, + injected: true, + module: false, + mutated: true, + reassigned: false, + referenced: false, + writable: true + } + ]); + } +}; diff --git a/test/stats/samples/store-unreferenced/input.html b/test/stats/samples/store-unreferenced/input.html new file mode 100644 index 0000000000..3ad525047d --- /dev/null +++ b/test/stats/samples/store-unreferenced/input.html @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/test/stats/samples/template-references/_config.js b/test/stats/samples/template-references/_config.js index 0bc844928f..71c255d54b 100644 --- a/test/stats/samples/template-references/_config.js +++ b/test/stats/samples/template-references/_config.js @@ -1,8 +1,5 @@ export default { test(assert, stats) { - assert.equal(stats.templateReferences.size, 3); - assert.ok(stats.templateReferences.has('foo')); - assert.ok(stats.templateReferences.has('Bar')); - assert.ok(stats.templateReferences.has('baz')); + assert.deepEqual(stats.vars, []); }, }; diff --git a/test/stats/samples/undeclared/_config.js b/test/stats/samples/undeclared/_config.js new file mode 100644 index 0000000000..71c255d54b --- /dev/null +++ b/test/stats/samples/undeclared/_config.js @@ -0,0 +1,5 @@ +export default { + test(assert, stats) { + assert.deepEqual(stats.vars, []); + }, +}; diff --git a/test/stats/samples/undeclared/input.html b/test/stats/samples/undeclared/input.html new file mode 100644 index 0000000000..0178466fe3 --- /dev/null +++ b/test/stats/samples/undeclared/input.html @@ -0,0 +1,3 @@ + + +{foo} \ No newline at end of file diff --git a/test/validator/index.js b/test/validator/index.js index 9ca3fc57d1..517427e817 100644 --- a/test/validator/index.js +++ b/test/validator/index.js @@ -64,11 +64,16 @@ describe("validate", () => { throw new Error(`Expected an error: ${expected.message}`); } - assert.equal(error.code, expected.code); - assert.equal(error.message, expected.message); - assert.deepEqual(error.start, expected.start); - assert.deepEqual(error.end, expected.end); - assert.equal(error.pos, expected.pos); + try { + assert.equal(error.code, expected.code); + assert.equal(error.message, expected.message); + assert.deepEqual(error.start, expected.start); + assert.deepEqual(error.end, expected.end); + assert.equal(error.pos, expected.pos); + } catch (e) { + console.error(error) + throw e; + } } }); }); @@ -102,7 +107,7 @@ describe("validate", () => { name: "_", generate: false }); - + assert.deepEqual(stats.warnings, []); }); }); diff --git a/test/validator/samples/binding-invalid-value/errors.json b/test/validator/samples/binding-invalid-value/errors.json new file mode 100644 index 0000000000..07eb7b0f1c --- /dev/null +++ b/test/validator/samples/binding-invalid-value/errors.json @@ -0,0 +1,15 @@ +[{ + "code": "binding-undeclared", + "message": "foo is not declared", + "pos": 37, + "start": { + "line": 2, + "column": 19, + "character": 37 + }, + "end": { + "line": 2, + "column": 22, + "character": 40 + } +}] \ No newline at end of file diff --git a/test/validator/samples/binding-invalid-value/input.html b/test/validator/samples/binding-invalid-value/input.html new file mode 100644 index 0000000000..9eeeba5fed --- /dev/null +++ b/test/validator/samples/binding-invalid-value/input.html @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/test/validator/samples/multiple-script-default-context/errors.json b/test/validator/samples/multiple-script-default-context/errors.json index 6e9a53d691..6f0637b51b 100644 --- a/test/validator/samples/multiple-script-default-context/errors.json +++ b/test/validator/samples/multiple-script-default-context/errors.json @@ -8,8 +8,8 @@ "character": 30 }, "end": { - "line": 7, - "column": 9, - "character": 58 + "line": 5, + "column": 0, + "character": 30 } }] \ No newline at end of file diff --git a/test/validator/samples/multiple-script-module-context/errors.json b/test/validator/samples/multiple-script-module-context/errors.json index ef8dc15273..7b86c61926 100644 --- a/test/validator/samples/multiple-script-module-context/errors.json +++ b/test/validator/samples/multiple-script-module-context/errors.json @@ -8,8 +8,8 @@ "character": 47 }, "end": { - "line": 7, - "column": 9, - "character": 92 + "line": 5, + "column": 0, + "character": 47 } }] \ No newline at end of file diff --git a/test/validator/samples/script-invalid-context/errors.json b/test/validator/samples/script-invalid-context/errors.json index 9c276d932d..07ad0f1270 100644 --- a/test/validator/samples/script-invalid-context/errors.json +++ b/test/validator/samples/script-invalid-context/errors.json @@ -9,7 +9,7 @@ }, "end": { "line": 1, - "column": 22, - "character": 22 + "column": 8, + "character": 8 } }] \ No newline at end of file