From 1bc675da508e355789f3eae187e4a393dbbf4e54 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 25 Feb 2018 10:36:54 -0500 Subject: [PATCH] fix a couple of TODOs --- src/generators/Generator.ts | 8 +------- src/generators/dom/Block.ts | 9 +++------ src/parse/state/tag.ts | 6 +++++- src/shared/index.js | 4 ++++ src/validate/html/index.ts | 21 +++++++++++---------- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index cac7858c19..6aac05286d 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -168,7 +168,7 @@ export default class Generator { if (options.customElement === true) { this.customElement = { tag: this.tag, - props: this.props // TODO autofill this in + props: this.props } } else { this.customElement = options.customElement; @@ -752,12 +752,6 @@ export default class Generator { if (node.type === 'Element' && (node.name === ':Component' || node.name === ':Self' || generator.components.has(node.name))) { node.type = 'Component'; Object.setPrototypeOf(node, nodes.Component.prototype); - } else if (node.name === ':Window') { // TODO do this in parse? - node.type = 'Window'; - Object.setPrototypeOf(node, nodes.Window.prototype); - } else if (node.name === ':Head') { // TODO do this in parse? - node.type = 'Head'; - Object.setPrototypeOf(node, nodes.Head.prototype); } else if (node.type === 'Element' && node.name === 'title' && parentIsHead(parent)) { // TODO do this in parse? node.type = 'Title'; Object.setPrototypeOf(node, nodes.Title.prototype); diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index 0d786752dc..e393313e87 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -308,22 +308,19 @@ export default class Block { if (this.hasOutroMethod) { if (hasOutros) { properties.addBlock(deindent` - o: function outro(${this.alias('outrocallback')}) { + o: function outro(#outrocallback) { if (${outroing}) return; ${outroing} = true; ${hasIntros && `${introing} = false;`} - var ${this.alias('outros')} = ${this.outros}; + var #outros = ${this.outros}; ${this.builders.outro} }, `); } else { - // TODO should this be a helper? properties.addBlock(deindent` - o: function outro(outrocallback) { - outrocallback(); - }, + o: @run, `); } } diff --git a/src/parse/state/tag.ts b/src/parse/state/tag.ts index 57e2b1bbb9..b24fa31ae3 100644 --- a/src/parse/state/tag.ts +++ b/src/parse/state/tag.ts @@ -109,10 +109,14 @@ export default function tag(parser: Parser) { } } + const type = metaTags.has(name) + ? name.slice(1) + : 'Element'; // TODO in v2, capitalised name means 'Component' + const element: Node = { start, end: null, // filled in later - type: 'Element', + type, name, attributes: [], children: [], diff --git a/src/shared/index.js b/src/shared/index.js index d9d6475e64..839f9a4e54 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -138,6 +138,10 @@ export function onDev(eventName, handler) { return on.call(this, eventName, handler); } +export function run(fn) { + fn(); +} + export function set(newState) { this._set(assign({}, newState)); if (this.root._lock) return; diff --git a/src/validate/html/index.ts b/src/validate/html/index.ts index 9ae50baca1..680b8b729b 100644 --- a/src/validate/html/index.ts +++ b/src/validate/html/index.ts @@ -7,11 +7,6 @@ import flattenReference from '../../utils/flattenReference'; import { Validator } from '../index'; import { Node } from '../../interfaces'; -const meta = new Map([ - [':Window', validateWindow], - [':Head', validateHead] -]); - function isEmptyBlock(node: Node) { if (!/Block$/.test(node.type) || !node.children) return false; if (node.children.length > 1) return false; @@ -26,11 +21,15 @@ export default function validateHtml(validator: Validator, html: Node) { const elementStack: Node[] = []; function visit(node: Node) { - if (node.type === 'Element') { - if (meta.has(node.name)) { - return meta.get(node.name)(validator, node, refs, refCallees); - } + if (node.type === 'Window') { + validateWindow(validator, node, refs, refCallees); + } + else if (node.type === 'Head') { + validateHead(validator, node, refs, refCallees); + } + + else if (node.type === 'Element') { const isComponent = node.name === ':Self' || node.name === ':Component' || @@ -49,7 +48,9 @@ export default function validateHtml(validator: Validator, html: Node) { if (!isComponent) { a11y(validator, node, elementStack); } - } else if (node.type === 'EachBlock') { + } + + else if (node.type === 'EachBlock') { if (validator.helpers.has(node.context)) { let c = node.expression.end;