fix a bunch more tests

pull/3539/head
Richard Harris 6 years ago
parent b02028db32
commit 09c0cefe6a

@ -51,6 +51,7 @@ export default class Component {
ignore_stack: Array<Set<string>> = []; ignore_stack: Array<Set<string>> = [];
ast: Ast; ast: Ast;
original_ast: Ast;
source: string; source: string;
name: Identifier; name: Identifier;
compile_options: CompileOptions; compile_options: CompileOptions;
@ -124,6 +125,15 @@ export default class Component {
this.source = source; this.source = source;
this.compile_options = compile_options; 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 = this.file =
compile_options.filename && compile_options.filename &&
(typeof process !== 'undefined' (typeof process !== 'undefined'
@ -364,7 +374,7 @@ export default class Component {
return { return {
js, js,
css, css,
ast: this.ast, ast: this.original_ast,
warnings: this.warnings, warnings: this.warnings,
vars: this.vars vars: this.vars
.filter(v => !v.global && !v.internal) .filter(v => !v.global && !v.internal)
@ -710,9 +720,9 @@ export default class Component {
const script = this.ast.instance; const script = this.ast.instance;
if (!script) return; if (!script) return;
this.warn_on_undefined_store_value_references();
this.hoist_instance_declarations(); this.hoist_instance_declarations();
this.extract_reactive_declarations(); this.extract_reactive_declarations();
this.extract_reactive_store_references();
} }
// TODO merge this with other walks that are independent // 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 // TODO this pattern happens a lot... can we abstract it
// (or better still, do fewer AST walks)? // (or better still, do fewer AST walks)?
const component = this; const component = this;

@ -676,6 +676,7 @@ export default class Element extends Node {
if (modifier === 'passive') { if (modifier === 'passive') {
if (passive_events.has(handler.name)) { if (passive_events.has(handler.name)) {
console.log('here', handler.name, handler.can_make_passive);
if (handler.can_make_passive) { if (handler.can_make_passive) {
component.warn(handler, { component.warn(handler, {
code: 'redundant-event-modifier', code: 'redundant-event-modifier',

@ -39,7 +39,7 @@ export default class EventHandler extends Node {
node = declarator && declarator.init; 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; this.can_make_passive = true;
} }
} }

@ -39,7 +39,7 @@ export default function dom(
const should_add_css = ( const should_add_css = (
!options.customElement && !options.customElement &&
styles.length > 0 && !!styles &&
options.css !== false options.css !== false
); );

@ -36,6 +36,7 @@
] ]
}, },
"instance": { "instance": {
"type": "Script",
"start": 0, "start": 0,
"end": 28, "end": 28,
"context": "default", "context": "default",

@ -36,6 +36,7 @@
] ]
}, },
"instance": { "instance": {
"type": "Script",
"start": 0, "start": 0,
"end": 29, "end": 29,
"context": "default", "context": "default",

@ -30,6 +30,7 @@
] ]
}, },
"css": { "css": {
"type": "Style",
"start": 16, "start": 16,
"end": 56, "end": 56,
"attributes": [], "attributes": [],

@ -6,6 +6,7 @@
"children": [] "children": []
}, },
"instance": { "instance": {
"type": "Script",
"start": 0, "start": 0,
"end": 146, "end": 146,
"context": "default", "context": "default",

@ -36,6 +36,7 @@
] ]
}, },
"instance": { "instance": {
"type": "Script",
"start": 0, "start": 0,
"end": 28, "end": 28,
"context": "default", "context": "default",

@ -22,6 +22,7 @@
] ]
}, },
"instance": { "instance": {
"type": "Script",
"start": 0, "start": 0,
"end": 43, "end": 43,
"context": "default", "context": "default",

@ -48,6 +48,7 @@
] ]
}, },
"instance": { "instance": {
"type": "Script",
"start": 0, "start": 0,
"end": 77, "end": 77,
"context": "default", "context": "default",

@ -48,6 +48,7 @@
] ]
}, },
"instance": { "instance": {
"type": "Script",
"start": 0, "start": 0,
"end": 66, "end": 66,
"context": "default", "context": "default",

@ -48,6 +48,7 @@
] ]
}, },
"instance": { "instance": {
"type": "Script",
"start": 0, "start": 0,
"end": 39, "end": 39,
"context": "default", "context": "default",

@ -2,7 +2,7 @@ import * as fs from "fs";
import * as assert from "assert"; import * as assert from "assert";
import { svelte, loadConfig, tryToLoadJson } from "../helpers.js"; import { svelte, loadConfig, tryToLoadJson } from "../helpers.js";
describe("validate", () => { describe.only("validate", () => {
fs.readdirSync("test/validator/samples").forEach(dir => { fs.readdirSync("test/validator/samples").forEach(dir => {
if (dir[0] === ".") return; if (dir[0] === ".") return;

Loading…
Cancel
Save