add ssr-only tests passing

pull/3539/head
Richard Harris 6 years ago
parent 9fa133765d
commit 6ac2c8aa4c

@ -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);
}

@ -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) + ')}';
}

@ -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}`);
}

Loading…
Cancel
Save