diff --git a/src/compiler/compile/render_ssr/handlers/Element.ts b/src/compiler/compile/render_ssr/handlers/Element.ts index cd5a130bd2..5fd13990c2 100644 --- a/src/compiler/compile/render_ssr/handlers/Element.ts +++ b/src/compiler/compile/render_ssr/handlers/Element.ts @@ -1,4 +1,4 @@ -import { is_void, quote_prop_if_necessary, quote_name_if_necessary } from '../../../utils/names'; +import { is_void, quote_prop_if_necessary } from '../../../utils/names'; import Attribute from '../../nodes/Attribute'; import Class from '../../nodes/Class'; import { stringify_attribute, stringify_class_attribute } from '../../utils/stringify_attribute'; @@ -183,13 +183,15 @@ export default function(node: Element, renderer: Renderer, options: RenderOption renderer.add_string('>'); if (node_contents !== undefined) { - // if (contenteditable) { - // renderer.append('${($$value => $$value === void 0 ? `'); - // renderer.render(node.children, options); - // renderer.append('` : ' + value + ')(' + node_contents + ')}'); - // } else { - // renderer.append(node_contents); - // } + if (contenteditable) { + renderer.push(); + renderer.render(node.children, options); + const result = renderer.pop(); + + renderer.add_expression(x`($$value => $$value === void 0 ? ${result} : ${node_contents})`); + } else { + renderer.add_expression(node_contents); + } } else { renderer.render(node.children, options); } diff --git a/src/compiler/compile/render_ssr/handlers/InlineComponent.ts b/src/compiler/compile/render_ssr/handlers/InlineComponent.ts index acb9fb3257..3c2f784455 100644 --- a/src/compiler/compile/render_ssr/handlers/InlineComponent.ts +++ b/src/compiler/compile/render_ssr/handlers/InlineComponent.ts @@ -1,8 +1,7 @@ -import { escape, escape_template, stringify, string_literal } from '../../utils/stringify'; +import { escape, escape_template, string_literal } from '../../utils/stringify'; import { quote_name_if_necessary } from '../../../utils/names'; import Renderer, { RenderOptions } from '../Renderer'; import { get_slot_scope } from './shared/get_slot_scope'; -import { AppendTarget } from '../../../interfaces'; import InlineComponent from '../../nodes/InlineComponent'; import { INode } from '../../nodes/interfaces'; import Text from '../../nodes/Text'; @@ -10,9 +9,12 @@ import { p, x } from 'code-red'; function stringify_attribute(chunk: INode) { if (chunk.type === 'Text') { - return escape_template(escape((chunk as Text).data)); + return string_literal(chunk.data); + // return escape_template(escape((chunk as Text).data)); } + return x`@escape(${chunk})`; + return '${@escape(' + snip(chunk) + ')}'; } diff --git a/src/compiler/compile/utils/stringify_attribute.ts b/src/compiler/compile/utils/stringify_attribute.ts index c837659b93..e907445766 100644 --- a/src/compiler/compile/utils/stringify_attribute.ts +++ b/src/compiler/compile/utils/stringify_attribute.ts @@ -1,7 +1,8 @@ import Attribute from '../nodes/Attribute'; -import { escape_template, escape } from './stringify'; +import { string_literal } from './stringify'; import { snip } from './snip'; import Text from '../nodes/Text'; +import { x } from 'code-red'; export function stringify_class_attribute(attribute: Attribute) { // handle special case — `class={possiblyUndefined}` with scoped CSS @@ -16,12 +17,12 @@ export function stringify_attribute(attribute: Attribute, is_ssr: boolean) { return attribute.chunks .map((chunk) => { if (chunk.type === 'Text') { - return escape_template(escape(chunk.data).replace(/"/g, '"')); + return string_literal(chunk.data.replace(/"/g, '"')); } return is_ssr - ? '${@escape(' + snip(chunk) + ')}' - : '${' + snip(chunk) + '}'; + ? x`@escape(${chunk.node})` + : chunk.node; }) - .join(''); + .reduce((lhs, rhs) => x`${lhs} + ${rhs}`); }