all tests passing

pull/1367/head
Rich Harris 6 years ago
parent c3c7970dc9
commit 7224ef4eff

@ -89,7 +89,7 @@ export default class Attribute extends Node {
if (chunk.type === 'Text') { if (chunk.type === 'Text') {
return stringify(chunk.data); return stringify(chunk.data);
} else { } else {
return getExpressionPrecedence(chunk.node) <= 13 ? `(${chunk.snippet})` : snippet; return getExpressionPrecedence(chunk.node) <= 13 ? `(${chunk.snippet})` : chunk.snippet;
} }
}) })
.join(' + '); .join(' + ');
@ -194,11 +194,13 @@ export default class Attribute extends Node {
const isSelectValueAttribute = const isSelectValueAttribute =
name === 'value' && node.name === 'select'; name === 'value' && node.name === 'select';
const last = (shouldCache || isSelectValueAttribute) && block.getUniqueName( if (isSelectValueAttribute) shouldCache = true;
const last = shouldCache && block.getUniqueName(
`${node.var}_${name.replace(/[^a-zA-Z_$]/g, '_')}_value` `${node.var}_${name.replace(/[^a-zA-Z_$]/g, '_')}_value`
); );
if (shouldCache || isSelectValueAttribute) block.addVariable(last); if (shouldCache) block.addVariable(last);
let updater; let updater;
const init = shouldCache ? `${last} = ${value}` : value; const init = shouldCache ? `${last} = ${value}` : value;

@ -17,6 +17,7 @@ const readOnlyMediaAttributes = new Set([
export default class Binding extends Node { export default class Binding extends Node {
name: string; name: string;
value: Expression; value: Expression;
usesContext: boolean;
obj: string; obj: string;
prop: string; prop: string;
@ -33,10 +34,14 @@ export default class Binding extends Node {
prop = `[✂${this.value.node.property.start}-${this.value.node.property.end}✂]`; prop = `[✂${this.value.node.property.start}-${this.value.node.property.end}✂]`;
if (!this.value.node.computed) prop = `'${prop}'`; if (!this.value.node.computed) prop = `'${prop}'`;
obj = `[✂${this.value.node.object.start}-${this.value.node.object.end}✂]`; obj = `[✂${this.value.node.object.start}-${this.value.node.object.end}✂]`;
this.usesContext = true;
} else { } else {
const { name } = getObject(this.value.node); const { name } = getObject(this.value.node);
obj = 'ctx'; obj = 'ctx';
prop = `'${name}'`; prop = `'${name}'`;
this.usesContext = scope.names.has(name);
} }
this.obj = obj; this.obj = obj;

@ -320,16 +320,15 @@ export default class Element extends Node {
//(this.hasAncestor('EachBlock') && this.bindings.length > 0) || //(this.hasAncestor('EachBlock') && this.bindings.length > 0) ||
this.handlers.some(handler => handler.shouldHoist) this.handlers.some(handler => handler.shouldHoist)
); );
let eventHandlerOrBindingUsesComponent; const eventHandlerOrBindingUsesComponent = (
let eventHandlerOrBindingUsesContext; this.bindings.length > 0 ||
this.handlers.some(handler => handler.usesComponent)
);
if (this.bindings.length > 0) { const eventHandlerOrBindingUsesContext = (
eventHandlerOrBindingUsesComponent = true; this.bindings.some(binding => binding.usesContext) ||
eventHandlerOrBindingUsesContext = true; this.handlers.some(handler => handler.usesContext)
} else { );
eventHandlerOrBindingUsesComponent = this.handlers.some(handler => handler.usesComponent);
eventHandlerOrBindingUsesContext = this.handlers.some(handler => handler.usesContext);
}
if (hasHoistedEventHandlerOrBinding) { if (hasHoistedEventHandlerOrBinding) {
const initialProps: string[] = []; const initialProps: string[] = [];

@ -11,7 +11,9 @@ export default class Head extends Node {
constructor(compiler, parent, scope, info) { constructor(compiler, parent, scope, info) {
super(compiler, parent, scope, info); super(compiler, parent, scope, info);
this.children = mapChildren(compiler, parent, scope, info.children); this.children = mapChildren(compiler, parent, scope, info.children.filter(child => {
return (child.type !== 'Text' || /\S/.test(child.data));
}));
} }
init( init(

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

@ -1,2 +1 @@
<title>a custom title</title>
<title>a custom title</title>
Loading…
Cancel
Save