From 09c0cefe6ae1bd4258486e960c7b749f6948e6cb Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 22 Sep 2019 11:25:01 -0400 Subject: [PATCH] fix a bunch more tests --- src/compiler/compile/Component.ts | 16 +++++++++++++--- src/compiler/compile/nodes/Element.ts | 1 + src/compiler/compile/nodes/EventHandler.ts | 2 +- src/compiler/compile/render_dom/index.ts | 2 +- .../attribute-with-whitespace/output.json | 2 +- .../parser/samples/binding-shorthand/output.json | 1 + test/parser/samples/binding/output.json | 1 + test/parser/samples/css/output.json | 1 + test/parser/samples/dynamic-import/output.json | 1 + test/parser/samples/refs/output.json | 1 + .../samples/script-comment-only/output.json | 1 + .../output.json | 1 + .../samples/script-comment-trailing/output.json | 1 + test/parser/samples/script/output.json | 1 + test/validator/index.js | 2 +- 15 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index b477dcafbe..0facb30c1d 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -51,6 +51,7 @@ export default class Component { ignore_stack: Array> = []; ast: Ast; + original_ast: Ast; source: string; name: Identifier; compile_options: CompileOptions; @@ -124,6 +125,15 @@ export default class Component { this.source = source; this.compile_options = compile_options; + // the instance JS gets mutated, so we park + // a copy here for later. TODO this feels gross + this.original_ast = { + html: ast.html, + css: ast.css, + instance: ast.instance && JSON.parse(JSON.stringify(ast.instance)), + module: ast.module + }; + this.file = compile_options.filename && (typeof process !== 'undefined' @@ -364,7 +374,7 @@ export default class Component { return { js, css, - ast: this.ast, + ast: this.original_ast, warnings: this.warnings, vars: this.vars .filter(v => !v.global && !v.internal) @@ -710,9 +720,9 @@ export default class Component { const script = this.ast.instance; if (!script) return; + this.warn_on_undefined_store_value_references(); this.hoist_instance_declarations(); this.extract_reactive_declarations(); - this.extract_reactive_store_references(); } // TODO merge this with other walks that are independent @@ -751,7 +761,7 @@ export default class Component { }); } - extract_reactive_store_references() { + warn_on_undefined_store_value_references() { // TODO this pattern happens a lot... can we abstract it // (or better still, do fewer AST walks)? const component = this; diff --git a/src/compiler/compile/nodes/Element.ts b/src/compiler/compile/nodes/Element.ts index 2981741fa0..7e6aa2804b 100644 --- a/src/compiler/compile/nodes/Element.ts +++ b/src/compiler/compile/nodes/Element.ts @@ -676,6 +676,7 @@ export default class Element extends Node { if (modifier === 'passive') { if (passive_events.has(handler.name)) { + console.log('here', handler.name, handler.can_make_passive); if (handler.can_make_passive) { component.warn(handler, { code: 'redundant-event-modifier', diff --git a/src/compiler/compile/nodes/EventHandler.ts b/src/compiler/compile/nodes/EventHandler.ts index 11c030a55e..7faf5d15dd 100644 --- a/src/compiler/compile/nodes/EventHandler.ts +++ b/src/compiler/compile/nodes/EventHandler.ts @@ -39,7 +39,7 @@ export default class EventHandler extends Node { node = declarator && declarator.init; } - if (node && (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') && node.params.length === 0) { + if (node && (node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'ArrowFunctionExpression') && node.params.length === 0) { this.can_make_passive = true; } } diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index e01b43dc09..062b85090a 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -39,7 +39,7 @@ export default function dom( const should_add_css = ( !options.customElement && - styles.length > 0 && + !!styles && options.css !== false ); diff --git a/test/parser/samples/attribute-with-whitespace/output.json b/test/parser/samples/attribute-with-whitespace/output.json index eab6054f2a..11d5aa5e06 100644 --- a/test/parser/samples/attribute-with-whitespace/output.json +++ b/test/parser/samples/attribute-with-whitespace/output.json @@ -36,4 +36,4 @@ } ] } -} +} \ 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 7fe7acb5b3..0f10aeb40d 100644 --- a/test/parser/samples/binding-shorthand/output.json +++ b/test/parser/samples/binding-shorthand/output.json @@ -36,6 +36,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 28, "context": "default", diff --git a/test/parser/samples/binding/output.json b/test/parser/samples/binding/output.json index 72ad60202c..e5ebc3fbc7 100644 --- a/test/parser/samples/binding/output.json +++ b/test/parser/samples/binding/output.json @@ -36,6 +36,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 29, "context": "default", diff --git a/test/parser/samples/css/output.json b/test/parser/samples/css/output.json index 12d74ae7f8..676b11f6a9 100644 --- a/test/parser/samples/css/output.json +++ b/test/parser/samples/css/output.json @@ -30,6 +30,7 @@ ] }, "css": { + "type": "Style", "start": 16, "end": 56, "attributes": [], diff --git a/test/parser/samples/dynamic-import/output.json b/test/parser/samples/dynamic-import/output.json index f66cdaaa0b..ce6c7880bc 100644 --- a/test/parser/samples/dynamic-import/output.json +++ b/test/parser/samples/dynamic-import/output.json @@ -6,6 +6,7 @@ "children": [] }, "instance": { + "type": "Script", "start": 0, "end": 146, "context": "default", diff --git a/test/parser/samples/refs/output.json b/test/parser/samples/refs/output.json index e09383f9b6..707da89774 100644 --- a/test/parser/samples/refs/output.json +++ b/test/parser/samples/refs/output.json @@ -36,6 +36,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 28, "context": "default", diff --git a/test/parser/samples/script-comment-only/output.json b/test/parser/samples/script-comment-only/output.json index ba28434318..bc541abcc3 100644 --- a/test/parser/samples/script-comment-only/output.json +++ b/test/parser/samples/script-comment-only/output.json @@ -22,6 +22,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 43, "context": "default", diff --git a/test/parser/samples/script-comment-trailing-multiline/output.json b/test/parser/samples/script-comment-trailing-multiline/output.json index 7d01599efa..ec4f8fe693 100644 --- a/test/parser/samples/script-comment-trailing-multiline/output.json +++ b/test/parser/samples/script-comment-trailing-multiline/output.json @@ -48,6 +48,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 77, "context": "default", diff --git a/test/parser/samples/script-comment-trailing/output.json b/test/parser/samples/script-comment-trailing/output.json index bc8f3e4e67..166b1a134b 100644 --- a/test/parser/samples/script-comment-trailing/output.json +++ b/test/parser/samples/script-comment-trailing/output.json @@ -48,6 +48,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 66, "context": "default", diff --git a/test/parser/samples/script/output.json b/test/parser/samples/script/output.json index 75aa0a7d2c..4dee657354 100644 --- a/test/parser/samples/script/output.json +++ b/test/parser/samples/script/output.json @@ -48,6 +48,7 @@ ] }, "instance": { + "type": "Script", "start": 0, "end": 39, "context": "default", diff --git a/test/validator/index.js b/test/validator/index.js index 1e54cc20db..9be8d6b6b8 100644 --- a/test/validator/index.js +++ b/test/validator/index.js @@ -2,7 +2,7 @@ import * as fs from "fs"; import * as assert from "assert"; import { svelte, loadConfig, tryToLoadJson } from "../helpers.js"; -describe("validate", () => { +describe.only("validate", () => { fs.readdirSync("test/validator/samples").forEach(dir => { if (dir[0] === ".") return;