dont worry con i promise i will squash these commits

pull/3539/head
Richard Harris 6 years ago
parent 42f4d69d3b
commit 8d093c6200

@ -1,4 +1,4 @@
import { stringify, string_literal } from '../utils/stringify'; import { string_literal } from '../utils/stringify';
import add_to_set from '../utils/add_to_set'; import add_to_set from '../utils/add_to_set';
import Component from '../Component'; import Component from '../Component';
import Node from './shared/Node'; import Node from './shared/Node';
@ -6,6 +6,7 @@ import Element from './Element';
import Text from './Text'; import Text from './Text';
import Expression from './shared/Expression'; import Expression from './shared/Expression';
import TemplateScope from './shared/TemplateScope'; import TemplateScope from './shared/TemplateScope';
import { x } from 'code-red';
export default class Attribute extends Node { export default class Attribute extends Node {
type: 'Attribute'; type: 'Attribute';
@ -78,8 +79,8 @@ export default class Attribute extends Node {
} }
get_value(block) { get_value(block) {
if (this.is_true) return true; if (this.is_true) return x`true`;
if (this.chunks.length === 0) return `""`; if (this.chunks.length === 0) return x`""`;
if (this.chunks.length === 1) { if (this.chunks.length === 1) {
return this.chunks[0].type === 'Text' return this.chunks[0].type === 'Text'
@ -87,17 +88,15 @@ export default class Attribute extends Node {
: (this.chunks[0] as Expression).manipulate(block); : (this.chunks[0] as Expression).manipulate(block);
} }
return (this.chunks[0].type === 'Text' ? '' : `"" + `) + let expression = this.chunks
this.chunks .map(chunk => chunk.type === 'Text' ? string_literal(chunk.data) : chunk.manipulate(block))
.map(chunk => { .reduce((lhs, rhs) => x`${lhs} + ${rhs}`);
if (chunk.type === 'Text') {
return stringify(chunk.data); if (this.chunks[0].type !== 'Text') {
} else { expression = x`"" + ${expression}`;
// @ts-ignore todo: probably error
return chunk.get_precedence() <= 13 ? `(${chunk.render()})` : chunk.render();
} }
})
.join(' + '); return expression;
} }
get_static_value() { get_static_value() {

@ -2,6 +2,7 @@ import Renderer from './Renderer';
import Wrapper from './wrappers/shared/Wrapper'; import Wrapper from './wrappers/shared/Wrapper';
import { b, x } from 'code-red'; import { b, x } from 'code-red';
import { Node, Identifier } from '../../interfaces'; import { Node, Identifier } from '../../interfaces';
import { is_head } from './wrappers/shared/is_head';
export interface BlockOptions { export interface BlockOptions {
parent?: Block; parent?: Block;
@ -167,7 +168,7 @@ export default class Block {
id: Identifier, id: Identifier,
render_statement: Node, render_statement: Node,
claim_statement: Node, claim_statement: Node,
parent_node: string, parent_node: Node,
no_detach?: boolean no_detach?: boolean
) { ) {
this.add_variable(id); this.add_variable(id);
@ -179,7 +180,7 @@ export default class Block {
if (parent_node) { if (parent_node) {
this.chunks.mount.push(b`@append(${parent_node}, ${id});`); this.chunks.mount.push(b`@append(${parent_node}, ${id});`);
if (parent_node === '@_document.head' && !no_detach) this.chunks.destroy.push(b`@detach(${id});`); if (is_head(parent_node) && !no_detach) this.chunks.destroy.push(b`@detach(${id});`);
} else { } else {
this.chunks.mount.push(b`@insert(#target, ${id}, anchor);`); this.chunks.mount.push(b`@insert(#target, ${id}, anchor);`);
if (!no_detach) this.chunks.destroy.push(b`if (detaching) @detach(${id});`); if (!no_detach) this.chunks.destroy.push(b`if (detaching) @detach(${id});`);

@ -2,6 +2,7 @@ import Block from './Block';
import { CompileOptions, Node, Identifier } from '../../interfaces'; import { CompileOptions, Node, Identifier } from '../../interfaces';
import Component from '../Component'; import Component from '../Component';
import FragmentWrapper from './wrappers/Fragment'; import FragmentWrapper from './wrappers/Fragment';
import { x } from 'code-red';
export default class Renderer { export default class Renderer {
component: Component; // TODO Maybe Renderer shouldn't know about Component? component: Component; // TODO Maybe Renderer shouldn't know about Component?
@ -56,6 +57,6 @@ export default class Renderer {
this.block.assign_variable_names(); this.block.assign_variable_names();
this.fragment.render(this.block, null, 'nodes'); this.fragment.render(this.block, null, x`nodes` as unknown as Identifier);
} }
} }

@ -122,8 +122,8 @@ export default class AwaitBlockWrapper extends Wrapper {
render( render(
block: Block, block: Block,
parent_node: string, parent_node: Identifier,
parent_nodes: string parent_nodes: Identifier
) { ) {
const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes); const anchor = this.get_or_create_anchor(block, parent_node, parent_nodes);
const update_mount_node = this.get_update_mount_node(anchor); const update_mount_node = this.get_update_mount_node(anchor);
@ -234,7 +234,7 @@ export default class AwaitBlockWrapper extends Wrapper {
`); `);
[this.pending, this.then, this.catch].forEach(branch => { [this.pending, this.then, this.catch].forEach(branch => {
branch.fragment.render(branch.block, null, 'nodes'); branch.fragment.render(branch.block, null, x`nodes` as unknown as Identifier);
}); });
} }
} }

@ -2,11 +2,12 @@ import Block from '../Block';
import Wrapper from './shared/Wrapper'; import Wrapper from './shared/Wrapper';
import { b } from 'code-red'; import { b } from 'code-red';
import Body from '../../nodes/Body'; import Body from '../../nodes/Body';
import { Identifier } from '../../../interfaces';
export default class BodyWrapper extends Wrapper { export default class BodyWrapper extends Wrapper {
node: Body; node: Body;
render(block: Block, _parent_node: string, _parent_nodes: string) { render(block: Block, _parent_node: Identifier, _parent_nodes: Identifier) {
this.node.handlers.forEach(handler => { this.node.handlers.forEach(handler => {
const snippet = handler.render(block); const snippet = handler.render(block);

@ -4,6 +4,7 @@ import Block from '../Block';
import DebugTag from '../../nodes/DebugTag'; import DebugTag from '../../nodes/DebugTag';
// import add_to_set from '../../utils/add_to_set'; // import add_to_set from '../../utils/add_to_set';
import { b } from 'code-red'; import { b } from 'code-red';
import { Identifier } from '../../../interfaces';
export default class DebugTagWrapper extends Wrapper { export default class DebugTagWrapper extends Wrapper {
node: DebugTag; node: DebugTag;
@ -19,7 +20,7 @@ export default class DebugTagWrapper extends Wrapper {
super(renderer, block, parent, node); super(renderer, block, parent, node);
} }
render(block: Block, _parent_node: string, _parent_nodes: string) { render(block: Block, _parent_node: Identifier, _parent_nodes: Identifier) {
const { renderer } = this; const { renderer } = this;
// const { component } = renderer; // const { component } = renderer;

@ -179,7 +179,7 @@ export default class EachBlockWrapper extends Wrapper {
} }
} }
render(block: Block, parent_node: string, parent_nodes: string) { render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
if (this.fragment.nodes.length === 0) return; if (this.fragment.nodes.length === 0) return;
const { renderer } = this; const { renderer } = this;
@ -207,7 +207,7 @@ export default class EachBlockWrapper extends Wrapper {
`); `);
const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : 'anchor' }; const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : 'anchor' };
const initial_mount_node: Identifier = { type: 'Identifier', name: parent_node || '#target' }; const initial_mount_node: Identifier = parent_node || { type: 'Identifier', name: '#target' };
const update_anchor_node = needs_anchor const update_anchor_node = needs_anchor
? block.get_unique_name(`${this.var.name}_anchor`) ? block.get_unique_name(`${this.var.name}_anchor`)
: (this.next && this.next.var) || { type: 'Identifier', name: 'null' }; : (this.next && this.next.var) || { type: 'Identifier', name: 'null' };
@ -243,7 +243,7 @@ export default class EachBlockWrapper extends Wrapper {
update_anchor_node as Identifier, update_anchor_node as Identifier,
x`@empty()`, x`@empty()`,
parent_nodes && x`@empty()`, parent_nodes && x`@empty()`,
parent_node parent_node as unknown as Node
); );
} }
@ -299,10 +299,10 @@ export default class EachBlockWrapper extends Wrapper {
`); `);
} }
this.fragment.render(this.block, null, 'nodes'); this.fragment.render(this.block, null, x`nodes` as unknown as Identifier);
if (this.else) { if (this.else) {
this.else.fragment.render(this.else.block, null, 'nodes'); this.else.fragment.render(this.else.block, null, x`nodes` as unknown as Identifier);
} }
} }
@ -317,8 +317,8 @@ export default class EachBlockWrapper extends Wrapper {
update_mount_node update_mount_node
}: { }: {
block: Block; block: Block;
parent_node: string; parent_node: Identifier;
parent_nodes: string; parent_nodes: Identifier;
snippet: Node; snippet: Node;
initial_anchor_node: Identifier; initial_anchor_node: Identifier;
initial_mount_node: Identifier; initial_mount_node: Identifier;
@ -425,7 +425,7 @@ export default class EachBlockWrapper extends Wrapper {
update_mount_node update_mount_node
}: { }: {
block: Block; block: Block;
parent_nodes: string; parent_nodes: Identifier;
snippet: Node; snippet: Node;
initial_anchor_node: Identifier; initial_anchor_node: Identifier;
initial_mount_node: Identifier; initial_mount_node: Identifier;

@ -172,8 +172,8 @@ export default class AttributeWrapper {
is_legacy_input_type is_legacy_input_type
? b`@set_input_type(${element.var}, ${value});` ? b`@set_input_type(${element.var}, ${value});`
: property_name : property_name
? b`${element.var}.${property_name} = ${value === true ? { type: 'Literal', value: true } : value};` ? b`${element.var}.${property_name} = ${value};`
: b`${method}(${element.var}, "${name}", ${value === true ? x`""` : value});` : b`${method}(${element.var}, "${name}", ${value});`
); );
block.chunks.hydrate.push(statement); block.chunks.hydrate.push(statement);

@ -21,6 +21,8 @@ import create_debugging_comment from '../shared/create_debugging_comment';
import { get_context_merger } from '../shared/get_context_merger'; import { get_context_merger } from '../shared/get_context_merger';
import bind_this from '../shared/bind_this'; import bind_this from '../shared/bind_this';
import { changed } from '../shared/changed'; import { changed } from '../shared/changed';
import { is_head } from '../shared/is_head';
import { Identifier } from '../../../../interfaces';
const events = [ const events = [
{ {
@ -152,7 +154,7 @@ export default class ElementWrapper extends Wrapper {
if (owner && owner.node.type === 'InlineComponent') { if (owner && owner.node.type === 'InlineComponent') {
const name = attribute.get_static_value() as string; const name = attribute.get_static_value() as string;
if (!(owner as InlineComponentWrapper).slots.has(name)) { if (!(owner as unknown as InlineComponentWrapper).slots.has(name)) {
const child_block = block.child({ const child_block = block.child({
comment: create_debugging_comment(node, this.renderer.component), comment: create_debugging_comment(node, this.renderer.component),
name: this.renderer.component.get_unique_name(`create_${sanitize(name)}_slot`), name: this.renderer.component.get_unique_name(`create_${sanitize(name)}_slot`),
@ -162,13 +164,13 @@ export default class ElementWrapper extends Wrapper {
const lets = this.node.lets; const lets = this.node.lets;
const seen = new Set(lets.map(l => l.name)); const seen = new Set(lets.map(l => l.name));
(owner as InlineComponentWrapper).node.lets.forEach(l => { (owner as unknown as InlineComponentWrapper).node.lets.forEach(l => {
if (!seen.has(l.name)) lets.push(l); if (!seen.has(l.name)) lets.push(l);
}); });
const fn = get_context_merger(lets); const fn = get_context_merger(lets);
(owner as InlineComponentWrapper).slots.set(name, { (owner as unknown as InlineComponentWrapper).slots.set(name, {
block: child_block, block: child_block,
scope: this.node.scope, scope: this.node.scope,
fn fn
@ -176,7 +178,7 @@ export default class ElementWrapper extends Wrapper {
this.renderer.blocks.push(child_block); this.renderer.blocks.push(child_block);
} }
this.slot_block = (owner as InlineComponentWrapper).slots.get(name).block; this.slot_block = (owner as unknown as InlineComponentWrapper).slots.get(name).block;
block = this.slot_block; block = this.slot_block;
} }
} }
@ -240,7 +242,7 @@ export default class ElementWrapper extends Wrapper {
} }
} }
render(block: Block, parent_node: string, parent_nodes: string) { render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
const { renderer } = this; const { renderer } = this;
if (this.node.name === 'noscript') return; if (this.node.name === 'noscript') return;
@ -276,7 +278,7 @@ export default class ElementWrapper extends Wrapper {
b`@append(${parent_node}, ${node});` b`@append(${parent_node}, ${node});`
); );
if (parent_node === '@_document.head') { if (is_head(parent_node)) {
block.chunks.destroy.push(b`@detach(${node});`); block.chunks.destroy.push(b`@detach(${node});`);
} }
} else { } else {
@ -320,7 +322,7 @@ export default class ElementWrapper extends Wrapper {
child.render( child.render(
block, block,
this.node.name === 'template' ? `${node}.content` : node, this.node.name === 'template' ? `${node}.content` : node,
nodes.name nodes
); );
}); });
} }
@ -376,7 +378,7 @@ export default class ElementWrapper extends Wrapper {
return x`@element("${name}")`; return x`@element("${name}")`;
} }
get_claim_statement(nodes: string) { get_claim_statement(nodes: Identifier) {
const attributes = this.node.attributes const attributes = this.node.attributes
.filter((attr) => attr.type === 'Attribute') .filter((attr) => attr.type === 'Attribute')
.map((attr) => `${quote_name_if_necessary(attr.name)}: true`) .map((attr) => `${quote_name_if_necessary(attr.name)}: true`)

@ -17,6 +17,7 @@ import { INode } from '../../nodes/interfaces';
import Renderer from '../Renderer'; import Renderer from '../Renderer';
import Block from '../Block'; import Block from '../Block';
import { trim_start, trim_end } from '../../../utils/trim'; import { trim_start, trim_end } from '../../../utils/trim';
import { Identifier } from 'estree';
const wrappers = { const wrappers = {
AwaitBlock, AwaitBlock,
@ -145,7 +146,7 @@ export default class FragmentWrapper {
} }
} }
render(block: Block, parent_node: string, parent_nodes: string) { render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
for (let i = 0; i < this.nodes.length; i += 1) { for (let i = 0; i < this.nodes.length; i += 1) {
this.nodes[i].render(block, parent_node, parent_nodes); this.nodes[i].render(block, parent_node, parent_nodes);
} }

@ -3,6 +3,8 @@ import Renderer from '../Renderer';
import Block from '../Block'; import Block from '../Block';
import Head from '../../nodes/Head'; import Head from '../../nodes/Head';
import FragmentWrapper from './Fragment'; import FragmentWrapper from './Fragment';
import { x } from 'code-red';
import { Identifier } from 'estree';
export default class HeadWrapper extends Wrapper { export default class HeadWrapper extends Wrapper {
fragment: FragmentWrapper; fragment: FragmentWrapper;
@ -29,7 +31,7 @@ export default class HeadWrapper extends Wrapper {
); );
} }
render(block: Block, _parent_node: string, _parent_nodes: string) { render(block: Block, _parent_node: Identifier, _parent_nodes: Identifier) {
this.fragment.render(block, '@_document.head', 'nodes'); this.fragment.render(block, x`@_document.head` as unknown as Identifier, x`nodes` as unknown as Identifier);
} }
} }

@ -10,6 +10,7 @@ import { b, x } from 'code-red';
import { walk } from 'estree-walker'; import { walk } from 'estree-walker';
import { Identifier } from '../../../interfaces'; import { Identifier } from '../../../interfaces';
import Node from '../../nodes/shared/Node'; import Node from '../../nodes/shared/Node';
import { is_head } from './shared/is_head';
function is_else_if(node: ElseBlock) { function is_else_if(node: ElseBlock) {
return ( return (
@ -170,8 +171,8 @@ export default class IfBlockWrapper extends Wrapper {
render( render(
block: Block, block: Block,
parent_node: string, parent_node: Identifier,
parent_nodes: string parent_nodes: Identifier
) { ) {
const name = this.var; const name = this.var;
@ -190,7 +191,7 @@ export default class IfBlockWrapper extends Wrapper {
const vars = { name, anchor, if_exists_condition, has_else, has_transitions }; const vars = { name, anchor, if_exists_condition, has_else, has_transitions };
const detaching = (parent_node && parent_node !== '@_document.head') ? '' : 'detaching'; const detaching = is_head(parent_node) ? '' : 'detaching';
if (this.node.else) { if (this.node.else) {
this.branches.forEach(branch => { this.branches.forEach(branch => {
@ -229,19 +230,19 @@ export default class IfBlockWrapper extends Wrapper {
anchor as Identifier, anchor as Identifier,
x`@empty()`, x`@empty()`,
parent_nodes && x`@empty()`, parent_nodes && x`@empty()`,
parent_node parent_node as unknown as Node
); );
} }
this.branches.forEach(branch => { this.branches.forEach(branch => {
branch.fragment.render(branch.block, null, 'nodes'); branch.fragment.render(branch.block, null, x`nodes` as unknown as Identifier);
}); });
} }
render_compound( render_compound(
block: Block, block: Block,
parent_node: string, parent_node: Identifier,
_parent_nodes: string, _parent_nodes: Identifier,
dynamic, dynamic,
{ name, anchor, has_else, if_exists_condition, has_transitions }, { name, anchor, has_else, if_exists_condition, has_transitions },
detaching detaching
@ -328,8 +329,8 @@ export default class IfBlockWrapper extends Wrapper {
// (TODO does this only apply to bidi transitions?) // (TODO does this only apply to bidi transitions?)
render_compound_with_outros( render_compound_with_outros(
block: Block, block: Block,
parent_node: string, parent_node: Identifier,
_parent_nodes: string, _parent_nodes: Identifier,
dynamic, dynamic,
{ name, anchor, has_else, has_transitions }, { name, anchor, has_else, has_transitions },
detaching detaching
@ -467,8 +468,8 @@ export default class IfBlockWrapper extends Wrapper {
render_simple( render_simple(
block: Block, block: Block,
parent_node: string, parent_node: Identifier,
_parent_nodes: string, _parent_nodes: Identifier,
dynamic, dynamic,
{ name, anchor, if_exists_condition, has_transitions }, { name, anchor, if_exists_condition, has_transitions },
detaching detaching

@ -106,8 +106,8 @@ export default class InlineComponentWrapper extends Wrapper {
render( render(
block: Block, block: Block,
parent_node: string, parent_node: Identifier,
parent_nodes: string parent_nodes: Identifier
) { ) {
const { renderer } = this; const { renderer } = this;
const { component } = renderer; const { component } = renderer;
@ -149,7 +149,7 @@ export default class InlineComponentWrapper extends Wrapper {
kind: 'init', kind: 'init',
key: { type: 'Identifier', name: '$$scope' }, key: { type: 'Identifier', name: '$$scope' },
value: x`{ ctx: #ctx }` value: x`{ ctx: #ctx }`
}) });
} }
if (uses_spread) { if (uses_spread) {
@ -189,7 +189,7 @@ export default class InlineComponentWrapper extends Wrapper {
const default_slot = this.slots.get('default'); const default_slot = this.slots.get('default');
this.fragment.nodes.forEach((child) => { this.fragment.nodes.forEach((child) => {
child.render(default_slot.block, null, 'nodes'); child.render(default_slot.block, null, x`nodes` as unknown as Identifier);
}); });
} }

@ -4,7 +4,7 @@ import Tag from './shared/Tag';
import Wrapper from './shared/Wrapper'; import Wrapper from './shared/Wrapper';
import MustacheTag from '../../nodes/MustacheTag'; import MustacheTag from '../../nodes/MustacheTag';
import RawMustacheTag from '../../nodes/RawMustacheTag'; import RawMustacheTag from '../../nodes/RawMustacheTag';
import { Identifier } from '../../../interfaces'; import { Identifier, Node } from '../../../interfaces';
import { x } from 'code-red'; import { x } from 'code-red';
export default class MustacheTagWrapper extends Tag { export default class MustacheTagWrapper extends Tag {
@ -15,7 +15,7 @@ export default class MustacheTagWrapper extends Tag {
this.cannot_use_innerhtml(); this.cannot_use_innerhtml();
} }
render(block: Block, parent_node: string, parent_nodes: string) { render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
const { init } = this.rename_this_method( const { init } = this.rename_this_method(
block, block,
value => x`@set_data(${this.var}, ${value});` value => x`@set_data(${this.var}, ${value});`
@ -25,7 +25,7 @@ export default class MustacheTagWrapper extends Tag {
this.var, this.var,
x`@text(${init})`, x`@text(${init})`,
parent_nodes && x`@claim_text(${parent_nodes}, ${init})`, parent_nodes && x`@claim_text(${parent_nodes}, ${init})`,
parent_node parent_node as unknown as Node
); );
} }
} }

@ -5,7 +5,8 @@ import Tag from './shared/Tag';
import Wrapper from './shared/Wrapper'; import Wrapper from './shared/Wrapper';
import MustacheTag from '../../nodes/MustacheTag'; import MustacheTag from '../../nodes/MustacheTag';
import RawMustacheTag from '../../nodes/RawMustacheTag'; import RawMustacheTag from '../../nodes/RawMustacheTag';
import { Identifier } from '../../../interfaces'; import { Identifier, Node } from '../../../interfaces';
import { is_head } from './shared/is_head';
export default class RawMustacheTagWrapper extends Tag { export default class RawMustacheTagWrapper extends Tag {
var: Identifier = { type: 'Identifier', name: 'raw' }; var: Identifier = { type: 'Identifier', name: 'raw' };
@ -20,8 +21,8 @@ export default class RawMustacheTagWrapper extends Tag {
this.cannot_use_innerhtml(); this.cannot_use_innerhtml();
} }
render(block: Block, parent_node: string, _parent_nodes: string) { render(block: Block, parent_node: Identifier, _parent_nodes: Identifier) {
const in_head = parent_node === '@_document.head'; const in_head = is_head(parent_node);
const can_use_innerhtml = !in_head && parent_node && !this.prev && !this.next; const can_use_innerhtml = !in_head && parent_node && !this.prev && !this.next;
@ -55,7 +56,7 @@ export default class RawMustacheTagWrapper extends Tag {
block.chunks.mount.push(b`${html_tag}.m(${parent_node || '#target'}, ${parent_node ? null : 'anchor'});`); block.chunks.mount.push(b`${html_tag}.m(${parent_node || '#target'}, ${parent_node ? null : 'anchor'});`);
if (needs_anchor) { if (needs_anchor) {
block.add_element(html_anchor, x`@empty()`, x`@empty()`, parent_node); block.add_element(html_anchor, x`@empty()`, x`@empty()`, parent_node as unknown as Node);
} }
if (!parent_node || in_head) { if (!parent_node || in_head) {

@ -52,8 +52,8 @@ export default class SlotWrapper extends Wrapper {
render( render(
block: Block, block: Block,
parent_node: string, parent_node: Identifier,
parent_nodes: string parent_nodes: Identifier
) { ) {
const { renderer } = this; const { renderer } = this;

@ -4,6 +4,7 @@ import Text from '../../nodes/Text';
import Wrapper from './shared/Wrapper'; import Wrapper from './shared/Wrapper';
import { Identifier } from '../../../interfaces'; import { Identifier } from '../../../interfaces';
import { x } from 'code-red'; import { x } from 'code-red';
import Node from '../../nodes/shared/Node';
// Whitespace inside one of these elements will not result in // Whitespace inside one of these elements will not result in
// a whitespace node being created in any circumstances. (This // a whitespace node being created in any circumstances. (This
@ -65,7 +66,7 @@ export default class TextWrapper extends Wrapper {
return true; return true;
} }
render(block: Block, parent_node: string, parent_nodes: string) { render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
if (this.skip) return; if (this.skip) return;
const use_space = this.use_space(); const use_space = this.use_space();
@ -73,7 +74,7 @@ export default class TextWrapper extends Wrapper {
this.var, this.var,
use_space ? x`@space()` : x`@text("${this.data}")`, use_space ? x`@space()` : x`@text("${this.data}")`,
parent_nodes && (use_space ? x`@claim_space(${parent_nodes})` : x`@claim_text(${parent_nodes}, "${this.data}")`), parent_nodes && (use_space ? x`@claim_space(${parent_nodes})` : x`@claim_text(${parent_nodes}, "${this.data}")`),
parent_node parent_node as unknown as Node
); );
} }
} }

@ -6,6 +6,7 @@ import Title from '../../nodes/Title';
import { stringify } from '../../utils/stringify'; import { stringify } from '../../utils/stringify';
import add_to_set from '../../utils/add_to_set'; import add_to_set from '../../utils/add_to_set';
import Text from '../../nodes/Text'; import Text from '../../nodes/Text';
import { Identifier } from '../../../interfaces';
export default class TitleWrapper extends Wrapper { export default class TitleWrapper extends Wrapper {
node: Title; node: Title;
@ -21,7 +22,7 @@ export default class TitleWrapper extends Wrapper {
super(renderer, block, parent, node); super(renderer, block, parent, node);
} }
render(block: Block, _parent_node: string, _parent_nodes: string) { render(block: Block, _parent_node: Identifier, _parent_nodes: Identifier) {
const is_dynamic = !!this.node.children.find(node => node.type !== 'Text'); const is_dynamic = !!this.node.children.find(node => node.type !== 'Text');
if (is_dynamic) { if (is_dynamic) {

@ -7,6 +7,7 @@ import Window from '../../nodes/Window';
import add_actions from './shared/add_actions'; import add_actions from './shared/add_actions';
import { INode } from '../../nodes/interfaces'; import { INode } from '../../nodes/interfaces';
import { changed } from './shared/changed'; import { changed } from './shared/changed';
import { Identifier } from '../../../interfaces';
const associated_events = { const associated_events = {
innerWidth: 'resize', innerWidth: 'resize',
@ -38,7 +39,7 @@ export default class WindowWrapper extends Wrapper {
super(renderer, block, parent, node); super(renderer, block, parent, node);
} }
render(block: Block, _parent_node: string, _parent_nodes: string) { render(block: Block, _parent_node: Identifier, _parent_nodes: Identifier) {
const { renderer } = this; const { renderer } = this;
const { component } = renderer; const { component } = renderer;

@ -1,7 +1,7 @@
import Renderer from '../../Renderer'; import Renderer from '../../Renderer';
import Block from '../../Block'; import Block from '../../Block';
import { INode } from '../../../nodes/interfaces'; import { INode } from '../../../nodes/interfaces';
import { Identifier } from '../../../../interfaces'; import { Identifier, Node } from '../../../../interfaces';
import { x } from 'code-red'; import { x } from 'code-red';
export default class Wrapper { export default class Wrapper {
@ -44,7 +44,7 @@ export default class Wrapper {
if (this.parent) this.parent.cannot_use_innerhtml(); if (this.parent) this.parent.cannot_use_innerhtml();
} }
get_or_create_anchor(block: Block, parent_node: string, parent_nodes: string) { get_or_create_anchor(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
// TODO use this in EachBlock and IfBlock — tricky because // TODO use this in EachBlock and IfBlock — tricky because
// children need to be created first // children need to be created first
const needs_anchor = this.next ? !this.next.is_dom_node() : !parent_node || !this.parent.is_dom_node(); const needs_anchor = this.next ? !this.next.is_dom_node() : !parent_node || !this.parent.is_dom_node();
@ -57,7 +57,7 @@ export default class Wrapper {
anchor, anchor,
x`@empty()`, x`@empty()`,
parent_nodes && x`@empty()`, parent_nodes && x`@empty()`,
parent_node parent_node as unknown as Node
); );
} }
@ -78,7 +78,7 @@ export default class Wrapper {
); );
} }
render(_block: Block, _parent_node: string, _parent_nodes: string) { render(_block: Block, _parent_node: Identifier, _parent_nodes: Identifier) {
throw Error('Wrapper class is not renderable'); throw Error('Wrapper class is not renderable');
} }
} }

@ -0,0 +1,3 @@
export function is_head(node) {
return node && node.type === 'MemberExpression' && node.object.name === '@_document' && node.property.name === 'head';
}
Loading…
Cancel
Save