diff --git a/src/generators/nodes/Attribute.ts b/src/generators/nodes/Attribute.ts index db0ef9c960..c4d8324598 100644 --- a/src/generators/nodes/Attribute.ts +++ b/src/generators/nodes/Attribute.ts @@ -89,7 +89,7 @@ export default class Attribute extends Node { if (chunk.type === 'Text') { return stringify(chunk.data); } else { - return getExpressionPrecedence(chunk.node) <= 13 ? `(${chunk.snippet})` : snippet; + return getExpressionPrecedence(chunk.node) <= 13 ? `(${chunk.snippet})` : chunk.snippet; } }) .join(' + '); @@ -194,11 +194,13 @@ export default class Attribute extends Node { const isSelectValueAttribute = 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` ); - if (shouldCache || isSelectValueAttribute) block.addVariable(last); + if (shouldCache) block.addVariable(last); let updater; const init = shouldCache ? `${last} = ${value}` : value; diff --git a/src/generators/nodes/Binding.ts b/src/generators/nodes/Binding.ts index a8a3e821f2..dcd763120c 100644 --- a/src/generators/nodes/Binding.ts +++ b/src/generators/nodes/Binding.ts @@ -17,6 +17,7 @@ const readOnlyMediaAttributes = new Set([ export default class Binding extends Node { name: string; value: Expression; + usesContext: boolean; obj: string; prop: string; @@ -33,10 +34,14 @@ export default class Binding extends Node { prop = `[✂${this.value.node.property.start}-${this.value.node.property.end}✂]`; if (!this.value.node.computed) prop = `'${prop}'`; obj = `[✂${this.value.node.object.start}-${this.value.node.object.end}✂]`; + + this.usesContext = true; } else { const { name } = getObject(this.value.node); obj = 'ctx'; prop = `'${name}'`; + + this.usesContext = scope.names.has(name); } this.obj = obj; diff --git a/src/generators/nodes/Element.ts b/src/generators/nodes/Element.ts index a2c9ef0bcc..6c0e9a6ff4 100644 --- a/src/generators/nodes/Element.ts +++ b/src/generators/nodes/Element.ts @@ -320,16 +320,15 @@ export default class Element extends Node { //(this.hasAncestor('EachBlock') && this.bindings.length > 0) || this.handlers.some(handler => handler.shouldHoist) ); - let eventHandlerOrBindingUsesComponent; - let eventHandlerOrBindingUsesContext; + const eventHandlerOrBindingUsesComponent = ( + this.bindings.length > 0 || + this.handlers.some(handler => handler.usesComponent) + ); - if (this.bindings.length > 0) { - eventHandlerOrBindingUsesComponent = true; - eventHandlerOrBindingUsesContext = true; - } else { - eventHandlerOrBindingUsesComponent = this.handlers.some(handler => handler.usesComponent); - eventHandlerOrBindingUsesContext = this.handlers.some(handler => handler.usesContext); - } + const eventHandlerOrBindingUsesContext = ( + this.bindings.some(binding => binding.usesContext) || + this.handlers.some(handler => handler.usesContext) + ); if (hasHoistedEventHandlerOrBinding) { const initialProps: string[] = []; diff --git a/src/generators/nodes/Head.ts b/src/generators/nodes/Head.ts index fc6ceb3e3a..903d44f0d2 100644 --- a/src/generators/nodes/Head.ts +++ b/src/generators/nodes/Head.ts @@ -11,7 +11,9 @@ export default class Head extends Node { constructor(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( diff --git a/test/js/index.js b/test/js/index.js index 28d40c0740..8c6104fa37 100644 --- a/test/js/index.js +++ b/test/js/index.js @@ -4,7 +4,7 @@ import * as path from "path"; import { rollup } from "rollup"; import { loadConfig, svelte } from "../helpers.js"; -describe.only("js", () => { +describe("js", () => { fs.readdirSync("test/js/samples").forEach(dir => { if (dir[0] === ".") return; diff --git a/test/server-side-rendering/samples/head-title/_actual-head.html b/test/server-side-rendering/samples/head-title/_actual-head.html index b0a06af0cc..7d696352f9 100644 --- a/test/server-side-rendering/samples/head-title/_actual-head.html +++ b/test/server-side-rendering/samples/head-title/_actual-head.html @@ -1,2 +1 @@ - - a custom title +a custom title \ No newline at end of file