fix a couple of TODOs

pull/1193/head
Rich Harris 8 years ago
parent 0648998a5c
commit 1bc675da50

@ -168,7 +168,7 @@ export default class Generator {
if (options.customElement === true) { if (options.customElement === true) {
this.customElement = { this.customElement = {
tag: this.tag, tag: this.tag,
props: this.props // TODO autofill this in props: this.props
} }
} else { } else {
this.customElement = options.customElement; 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))) { if (node.type === 'Element' && (node.name === ':Component' || node.name === ':Self' || generator.components.has(node.name))) {
node.type = 'Component'; node.type = 'Component';
Object.setPrototypeOf(node, nodes.Component.prototype); 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? } else if (node.type === 'Element' && node.name === 'title' && parentIsHead(parent)) { // TODO do this in parse?
node.type = 'Title'; node.type = 'Title';
Object.setPrototypeOf(node, nodes.Title.prototype); Object.setPrototypeOf(node, nodes.Title.prototype);

@ -308,22 +308,19 @@ export default class Block {
if (this.hasOutroMethod) { if (this.hasOutroMethod) {
if (hasOutros) { if (hasOutros) {
properties.addBlock(deindent` properties.addBlock(deindent`
o: function outro(${this.alias('outrocallback')}) { o: function outro(#outrocallback) {
if (${outroing}) return; if (${outroing}) return;
${outroing} = true; ${outroing} = true;
${hasIntros && `${introing} = false;`} ${hasIntros && `${introing} = false;`}
var ${this.alias('outros')} = ${this.outros}; var #outros = ${this.outros};
${this.builders.outro} ${this.builders.outro}
}, },
`); `);
} else { } else {
// TODO should this be a helper?
properties.addBlock(deindent` properties.addBlock(deindent`
o: function outro(outrocallback) { o: @run,
outrocallback();
},
`); `);
} }
} }

@ -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 = { const element: Node = {
start, start,
end: null, // filled in later end: null, // filled in later
type: 'Element', type,
name, name,
attributes: [], attributes: [],
children: [], children: [],

@ -138,6 +138,10 @@ export function onDev(eventName, handler) {
return on.call(this, eventName, handler); return on.call(this, eventName, handler);
} }
export function run(fn) {
fn();
}
export function set(newState) { export function set(newState) {
this._set(assign({}, newState)); this._set(assign({}, newState));
if (this.root._lock) return; if (this.root._lock) return;

@ -7,11 +7,6 @@ import flattenReference from '../../utils/flattenReference';
import { Validator } from '../index'; import { Validator } from '../index';
import { Node } from '../../interfaces'; import { Node } from '../../interfaces';
const meta = new Map([
[':Window', validateWindow],
[':Head', validateHead]
]);
function isEmptyBlock(node: Node) { function isEmptyBlock(node: Node) {
if (!/Block$/.test(node.type) || !node.children) return false; if (!/Block$/.test(node.type) || !node.children) return false;
if (node.children.length > 1) return false; if (node.children.length > 1) return false;
@ -26,11 +21,15 @@ export default function validateHtml(validator: Validator, html: Node) {
const elementStack: Node[] = []; const elementStack: Node[] = [];
function visit(node: Node) { function visit(node: Node) {
if (node.type === 'Element') { if (node.type === 'Window') {
if (meta.has(node.name)) { validateWindow(validator, node, refs, refCallees);
return meta.get(node.name)(validator, node, refs, refCallees); }
}
else if (node.type === 'Head') {
validateHead(validator, node, refs, refCallees);
}
else if (node.type === 'Element') {
const isComponent = const isComponent =
node.name === ':Self' || node.name === ':Self' ||
node.name === ':Component' || node.name === ':Component' ||
@ -49,7 +48,9 @@ export default function validateHtml(validator: Validator, html: Node) {
if (!isComponent) { if (!isComponent) {
a11y(validator, node, elementStack); a11y(validator, node, elementStack);
} }
} else if (node.type === 'EachBlock') { }
else if (node.type === 'EachBlock') {
if (validator.helpers.has(node.context)) { if (validator.helpers.has(node.context)) {
let c = node.expression.end; let c = node.expression.end;

Loading…
Cancel
Save