From cc7150df5a07fc06b37d952e48f19ef01fc45385 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 15 Sep 2018 21:50:43 -0400 Subject: [PATCH] remove ssr methods --- src/compile/nodes/AwaitBlock.ts | 20 ----- src/compile/nodes/Comment.ts | 7 -- src/compile/nodes/DebugTag.ts | 18 ---- src/compile/nodes/EachBlock.ts | 31 ------- src/compile/nodes/Element.ts | 93 -------------------- src/compile/nodes/Head.ts | 10 --- src/compile/nodes/IfBlock.ts | 21 ----- src/compile/nodes/InlineComponent.ts | 125 --------------------------- src/compile/nodes/MustacheTag.ts | 10 --- src/compile/nodes/RawMustacheTag.ts | 4 - src/compile/nodes/Slot.ts | 15 ---- src/compile/nodes/Text.ts | 13 --- src/compile/nodes/Title.ts | 10 --- src/compile/nodes/Window.ts | 4 - 14 files changed, 381 deletions(-) diff --git a/src/compile/nodes/AwaitBlock.ts b/src/compile/nodes/AwaitBlock.ts index 7420594a54..a6846c32b1 100644 --- a/src/compile/nodes/AwaitBlock.ts +++ b/src/compile/nodes/AwaitBlock.ts @@ -6,7 +6,6 @@ import ThenBlock from './ThenBlock'; import CatchBlock from './CatchBlock'; import createDebuggingComment from '../../utils/createDebuggingComment'; import Expression from './shared/Expression'; -import { SsrTarget } from '../ssr'; export default class AwaitBlock extends Node { expression: Expression; @@ -194,23 +193,4 @@ export default class AwaitBlock extends Node { }); }); } - - ssr() { - const target: SsrTarget = this.component.target; - const { snippet } = this.expression; - - target.append('${(function(__value) { if(@isPromise(__value)) return `'); - - this.pending.children.forEach((child: Node) => { - child.ssr(); - }); - - target.append('`; return function(ctx) { return `'); - - this.then.children.forEach((child: Node) => { - child.ssr(); - }); - - target.append(`\`;}(Object.assign({}, ctx, { ${this.value}: __value }));}(${snippet})) }`); - } } diff --git a/src/compile/nodes/Comment.ts b/src/compile/nodes/Comment.ts index 03ea0be9e6..97a28f25a1 100644 --- a/src/compile/nodes/Comment.ts +++ b/src/compile/nodes/Comment.ts @@ -8,11 +8,4 @@ export default class Comment extends Node { super(component, parent, scope, info); this.data = info.data; } - - ssr() { - // Allow option to preserve comments, otherwise ignore - if (this.component.options.preserveComments) { - this.component.target.append(``); - } - } } \ No newline at end of file diff --git a/src/compile/nodes/DebugTag.ts b/src/compile/nodes/DebugTag.ts index 26a326162b..b35a13a7be 100644 --- a/src/compile/nodes/DebugTag.ts +++ b/src/compile/nodes/DebugTag.ts @@ -68,22 +68,4 @@ export default class DebugTag extends Node { `); } } - - ssr() { - if (!this.component.options.dev) return; - - const filename = this.component.file || null; - const { line, column } = this.component.locate(this.start + 1); - - const obj = this.expressions.length === 0 - ? `ctx` - : `{ ${this.expressions - .map(e => e.node.name) - .map(name => `${name}: ctx.${name}`) - .join(', ')} }`; - - const str = '${@debug(' + `${filename && stringify(filename)}, ${line}, ${column}, ${obj})}`; - - this.component.target.append(str); - } } \ No newline at end of file diff --git a/src/compile/nodes/EachBlock.ts b/src/compile/nodes/EachBlock.ts index 5ba1c5f2b3..e5abfc91ea 100644 --- a/src/compile/nodes/EachBlock.ts +++ b/src/compile/nodes/EachBlock.ts @@ -515,35 +515,4 @@ export default class EachBlock extends Node { // TODO consider keyed blocks return `for (var #i = 0; #i < ${this.iterations}.length; #i += 1) ${this.iterations}[#i].m(${name}._slotted.default, null);`; } - - ssr() { - const { component } = this; - const { snippet } = this.expression; - - const props = this.contexts.map(prop => `${prop.key.name}: item${prop.tail}`); - - const getContext = this.index - ? `(item, i) => Object.assign({}, ctx, { ${props.join(', ')}, ${this.index}: i })` - : `item => Object.assign({}, ctx, { ${props.join(', ')} })`; - - const open = `\${ ${this.else ? `${snippet}.length ? ` : ''}@each(${snippet}, ${getContext}, ctx => \``; - component.target.append(open); - - this.children.forEach((child: Node) => { - child.ssr(); - }); - - const close = `\`)`; - component.target.append(close); - - if (this.else) { - component.target.append(` : \``); - this.else.children.forEach((child: Node) => { - child.ssr(); - }); - component.target.append(`\``); - } - - component.target.append('}'); - } } diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index 6a739dc9d1..cdf3543a60 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -1399,99 +1399,6 @@ export default class Element extends Node { ); } } - - ssr() { - const { component } = this; - - let openingTag = `<${this.name}`; - let textareaContents; // awkward special case - - const slot = this.getStaticAttributeValue('slot'); - if (slot && this.hasAncestor('InlineComponent')) { - const slot = this.attributes.find((attribute: Node) => attribute.name === 'slot'); - const slotName = slot.chunks[0].data; - const appendTarget = component.target.appendTargets[component.target.appendTargets.length - 1]; - appendTarget.slotStack.push(slotName); - appendTarget.slots[slotName] = ''; - } - - const classExpr = this.classes.map((classDir: Class) => { - const { expression, name } = classDir; - const snippet = expression ? expression.snippet : `ctx${quotePropIfNecessary(name)}`; - return `${snippet} ? "${name}" : ""`; - }).join(', '); - - let addClassAttribute = classExpr ? true : false; - - if (this.attributes.find(attr => attr.isSpread)) { - // TODO dry this out - const args = []; - this.attributes.forEach(attribute => { - if (attribute.isSpread) { - args.push(attribute.expression.snippet); - } else { - if (attribute.name === 'value' && this.name === 'textarea') { - textareaContents = attribute.stringifyForSsr(); - } else if (attribute.isTrue) { - args.push(`{ ${quoteNameIfNecessary(attribute.name)}: true }`); - } else if ( - booleanAttributes.has(attribute.name) && - attribute.chunks.length === 1 && - attribute.chunks[0].type !== 'Text' - ) { - // a boolean attribute with one non-Text chunk - args.push(`{ ${quoteNameIfNecessary(attribute.name)}: ${attribute.chunks[0].snippet} }`); - } else { - args.push(`{ ${quoteNameIfNecessary(attribute.name)}: \`${attribute.stringifyForSsr()}\` }`); - } - } - }); - - openingTag += "${@spread([" + args.join(', ') + "])}"; - } else { - this.attributes.forEach((attribute: Node) => { - if (attribute.type !== 'Attribute') return; - - if (attribute.name === 'value' && this.name === 'textarea') { - textareaContents = attribute.stringifyForSsr(); - } else if (attribute.isTrue) { - openingTag += ` ${attribute.name}`; - } else if ( - booleanAttributes.has(attribute.name) && - attribute.chunks.length === 1 && - attribute.chunks[0].type !== 'Text' - ) { - // a boolean attribute with one non-Text chunk - openingTag += '${' + attribute.chunks[0].snippet + ' ? " ' + attribute.name + '" : "" }'; - } else if (attribute.name === 'class' && classExpr) { - addClassAttribute = false; - openingTag += ` class="\${ [\`${attribute.stringifyForSsr()}\`, ${classExpr} ].join(' ').trim() }"`; - } else { - openingTag += ` ${attribute.name}="${attribute.stringifyForSsr()}"`; - } - }); - } - - if (addClassAttribute) { - openingTag += ` class="\${ [${classExpr}].join(' ').trim() }"`; - } - - openingTag += '>'; - - component.target.append(openingTag); - - if (this.name === 'textarea' && textareaContents !== undefined) { - component.target.append(textareaContents); - } else { - this.children.forEach((child: Node) => { - child.ssr(); - }); - } - - if (!isVoidElementName(this.name)) { - component.target.append(``); - } - } } function getRenderStatement( diff --git a/src/compile/nodes/Head.ts b/src/compile/nodes/Head.ts index f0cb3d2365..86b2c7e125 100644 --- a/src/compile/nodes/Head.ts +++ b/src/compile/nodes/Head.ts @@ -40,14 +40,4 @@ export default class Head extends Node { child.build(block, 'document.head', null); }); } - - ssr() { - this.component.target.append('${(__result.head += `'); - - this.children.forEach((child: Node) => { - child.ssr(); - }); - - this.component.target.append('`, "")}'); - } } diff --git a/src/compile/nodes/IfBlock.ts b/src/compile/nodes/IfBlock.ts index 16e6a2115d..6a6c9b034e 100644 --- a/src/compile/nodes/IfBlock.ts +++ b/src/compile/nodes/IfBlock.ts @@ -483,27 +483,6 @@ export default class IfBlock extends Node { return branches; } - ssr() { - const { component } = this; - const { snippet } = this.expression; - - component.target.append('${ ' + snippet + ' ? `'); - - this.children.forEach((child: Node) => { - child.ssr(); - }); - - component.target.append('` : `'); - - if (this.else) { - this.else.children.forEach((child: Node) => { - child.ssr(); - }); - } - - component.target.append('` }'); - } - visitChildren(block: Block, node: Node) { node.children.forEach((child: Node) => { child.build(node.block, null, 'nodes'); diff --git a/src/compile/nodes/InlineComponent.ts b/src/compile/nodes/InlineComponent.ts index a544617e7f..c91dd76196 100644 --- a/src/compile/nodes/InlineComponent.ts +++ b/src/compile/nodes/InlineComponent.ts @@ -541,131 +541,6 @@ export default class InlineComponent extends Node { remount(name: string) { return `${this.var}._mount(${name}._slotted.default, null);`; } - - ssr() { - function stringifyAttribute(chunk: Node) { - if (chunk.type === 'Text') { - return escapeTemplate(escape(chunk.data)); - } - - return '${@escape( ' + chunk.snippet + ')}'; - } - - const bindingProps = this.bindings.map(binding => { - const { name } = getObject(binding.value.node); - const tail = binding.value.node.type === 'MemberExpression' - ? getTailSnippet(binding.value.node) - : ''; - - return `${quoteNameIfNecessary(binding.name)}: ctx${quotePropIfNecessary(name)}${tail}`; - }); - - function getAttributeValue(attribute) { - if (attribute.isTrue) return `true`; - if (attribute.chunks.length === 0) return `''`; - - if (attribute.chunks.length === 1) { - const chunk = attribute.chunks[0]; - if (chunk.type === 'Text') { - return stringify(chunk.data); - } - - return chunk.snippet; - } - - return '`' + attribute.chunks.map(stringifyAttribute).join('') + '`'; - } - - const usesSpread = this.attributes.find(attr => attr.isSpread); - - const props = usesSpread - ? `Object.assign(${ - this.attributes - .map(attribute => { - if (attribute.isSpread) { - return attribute.expression.snippet; - } else { - return `{ ${quoteNameIfNecessary(attribute.name)}: ${getAttributeValue(attribute)} }`; - } - }) - .concat(bindingProps.map(p => `{ ${p} }`)) - .join(', ') - })` - : `{ ${this.attributes - .map(attribute => `${quoteNameIfNecessary(attribute.name)}: ${getAttributeValue(attribute)}`) - .concat(bindingProps) - .join(', ')} }`; - - const expression = ( - this.name === 'svelte:self' - ? this.component.name - : this.name === 'svelte:component' - ? `((${this.expression.snippet}) || @missingComponent)` - : `%components-${this.name}` - ); - - this.bindings.forEach(binding => { - const conditions = []; - - let node = this; - while (node = node.parent) { - if (node.type === 'IfBlock') { - // TODO handle contextual bindings... - conditions.push(`(${node.expression.snippet})`); - } - } - - conditions.push( - `!('${binding.name}' in ctx)`, - `${expression}.data` - ); - - const { name } = getObject(binding.value.node); - - this.component.target.bindings.push(deindent` - if (${conditions.reverse().join('&&')}) { - tmp = ${expression}.data(); - if ('${name}' in tmp) { - ctx${quotePropIfNecessary(binding.name)} = tmp.${name}; - settled = false; - } - } - `); - }); - - let open = `\${@validateSsrComponent(${expression}, '${this.name}')._render(__result, ${props}`; - - const options = []; - options.push(`store: options.store`); - - if (this.children.length) { - const appendTarget: AppendTarget = { - slots: { default: '' }, - slotStack: ['default'] - }; - - this.component.target.appendTargets.push(appendTarget); - - this.children.forEach((child: Node) => { - child.ssr(); - }); - - const slotted = Object.keys(appendTarget.slots) - .map(name => `${quoteNameIfNecessary(name)}: () => \`${appendTarget.slots[name]}\``) - .join(', '); - - options.push(`slotted: { ${slotted} }`); - - this.component.target.appendTargets.pop(); - } - - if (options.length) { - open += `, { ${options.join(', ')} }`; - } - - this.component.target.append(open); - this.component.target.append(')}'); - } } function isComputed(node: Node) { diff --git a/src/compile/nodes/MustacheTag.ts b/src/compile/nodes/MustacheTag.ts index 227301b164..3fc92d323f 100644 --- a/src/compile/nodes/MustacheTag.ts +++ b/src/compile/nodes/MustacheTag.ts @@ -24,14 +24,4 @@ export default class MustacheTag extends Tag { remount(name: string) { return `@append(${name}._slotted.default, ${this.var});`; } - - ssr() { - this.component.target.append( - this.parent && - this.parent.type === 'Element' && - this.parent.name === 'style' - ? '${' + this.expression.snippet + '}' - : '${@escape(' + this.expression.snippet + ')}' - ); - } } \ No newline at end of file diff --git a/src/compile/nodes/RawMustacheTag.ts b/src/compile/nodes/RawMustacheTag.ts index a5f8a46dc3..a23cfe04ea 100644 --- a/src/compile/nodes/RawMustacheTag.ts +++ b/src/compile/nodes/RawMustacheTag.ts @@ -93,8 +93,4 @@ export default class RawMustacheTag extends Tag { remount(name: string) { return `@append(${name}._slotted.default, ${this.var});`; } - - ssr() { - this.component.target.append('${' + this.expression.snippet + '}'); - } } \ No newline at end of file diff --git a/src/compile/nodes/Slot.ts b/src/compile/nodes/Slot.ts index 4b2273ef8f..b80d2a5896 100644 --- a/src/compile/nodes/Slot.ts +++ b/src/compile/nodes/Slot.ts @@ -204,19 +204,4 @@ export default class Slot extends Element { return null; } - - ssr() { - const name = this.attributes.find(attribute => attribute.name === 'name'); - - const slotName = name && name.chunks[0].data || 'default'; - const prop = quotePropIfNecessary(slotName); - - this.component.target.append(`\${options && options.slotted && options.slotted${prop} ? options.slotted${prop}() : \``); - - this.children.forEach((child: Node) => { - child.ssr(); - }); - - this.component.target.append(`\`}`); - } } \ No newline at end of file diff --git a/src/compile/nodes/Text.ts b/src/compile/nodes/Text.ts index b4f891662e..7900486615 100644 --- a/src/compile/nodes/Text.ts +++ b/src/compile/nodes/Text.ts @@ -63,17 +63,4 @@ export default class Text extends Node { remount(name: string) { return `@append(${name}._slotted.default, ${this.var});`; } - - ssr() { - let text = this.data; - if ( - !this.parent || - this.parent.type !== 'Element' || - (this.parent.name !== 'script' && this.parent.name !== 'style') - ) { - // unless this Text node is inside a