Skip to content

Commit 0c3e44a

Browse files
authored
Merge pull request #1193 from sveltejs/TODO
[WIP] fix some TODOs
2 parents 22f0ed9 + 0c66e9e commit 0c3e44a

File tree

19 files changed

+361
-403
lines changed

19 files changed

+361
-403
lines changed

src/generators/Generator.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import MagicString, { Bundle } from 'magic-string';
2+
import isReference from 'is-reference';
23
import { walk, childKeys } from 'estree-walker';
34
import { getLocator } from 'locate-character';
45
import deindent from '../utils/deindent';
56
import CodeBuilder from '../utils/CodeBuilder';
67
import getCodeFrame from '../utils/getCodeFrame';
7-
import isReference from '../utils/isReference';
88
import flattenReference from '../utils/flattenReference';
99
import reservedNames from '../utils/reservedNames';
1010
import namespaces from '../utils/namespaces';
@@ -168,7 +168,7 @@ export default class Generator {
168168
if (options.customElement === true) {
169169
this.customElement = {
170170
tag: this.tag,
171-
props: this.props // TODO autofill this in
171+
props: this.props
172172
}
173173
} else {
174174
this.customElement = options.customElement;
@@ -752,12 +752,6 @@ export default class Generator {
752752
if (node.type === 'Element' && (node.name === ':Component' || node.name === ':Self' || generator.components.has(node.name))) {
753753
node.type = 'Component';
754754
Object.setPrototypeOf(node, nodes.Component.prototype);
755-
} else if (node.name === ':Window') { // TODO do this in parse?
756-
node.type = 'Window';
757-
Object.setPrototypeOf(node, nodes.Window.prototype);
758-
} else if (node.name === ':Head') { // TODO do this in parse?
759-
node.type = 'Head';
760-
Object.setPrototypeOf(node, nodes.Head.prototype);
761755
} else if (node.type === 'Element' && node.name === 'title' && parentIsHead(parent)) { // TODO do this in parse?
762756
node.type = 'Title';
763757
Object.setPrototypeOf(node, nodes.Title.prototype);

src/generators/dom/Block.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,19 @@ export default class Block {
312312
if (this.hasOutroMethod) {
313313
if (hasOutros) {
314314
properties.addBlock(deindent`
315-
o: function outro(${this.alias('outrocallback')}) {
315+
o: function outro(#outrocallback) {
316316
if (${outroing}) return;
317317
${outroing} = true;
318318
${hasIntros && `${introing} = false;`}
319319
320-
var ${this.alias('outros')} = ${this.outros};
320+
var #outros = ${this.outros};
321321
322322
${this.builders.outro}
323323
},
324324
`);
325325
} else {
326-
// TODO should this be a helper?
327326
properties.addBlock(deindent`
328-
o: function outro(outrocallback) {
329-
outrocallback();
330-
},
327+
o: @run,
331328
`);
332329
}
333330
}

src/generators/dom/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import MagicString from 'magic-string';
2+
import isReference from 'is-reference';
23
import { parseExpressionAt } from 'acorn';
34
import annotateWithScopes from '../../utils/annotateWithScopes';
4-
import isReference from '../../utils/isReference';
55
import { walk } from 'estree-walker';
66
import deindent from '../../utils/deindent';
77
import { stringify, escape } from '../../utils/stringify';

src/generators/nodes/Component.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export default class Component extends Node {
320320
${name} = new ${switch_vars.value}(${switch_vars.props}(state));
321321
${name}._fragment.c();
322322
323-
${this.children.map(child => remount(generator, child, name))}
323+
${this.children.map(child => child.remount(name))}
324324
${name}._mount(${updateMountNode}, ${anchor});
325325
326326
${eventHandlers.map(handler => deindent`
@@ -398,6 +398,10 @@ export default class Component extends Node {
398398
`);
399399
}
400400
}
401+
402+
remount(name: string) {
403+
return `${this.var}._mount(${name}._slotted${this.generator.legacy ? `["default"]` : `.default`}, null);`;
404+
}
401405
}
402406

403407
function mungeAttribute(attribute: Node, block: Block): Attribute {
@@ -547,32 +551,4 @@ function isComputed(node: Node) {
547551
}
548552

549553
return false;
550-
}
551-
552-
function remount(generator: DomGenerator, node: Node, name: string) {
553-
// TODO make this a method of the nodes
554-
555-
if (node.type === 'Component') {
556-
return `${node.var}._mount(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
557-
}
558-
559-
if (node.type === 'Element') {
560-
const slot = node.attributes.find(attribute => attribute.name === 'slot');
561-
if (slot) {
562-
return `@appendNode(${node.var}, ${name}._slotted.${node.getStaticAttributeValue('slot')});`;
563-
}
564-
565-
return `@appendNode(${node.var}, ${name}._slotted${generator.legacy ? `["default"]` : `.default`});`;
566-
}
567-
568-
if (node.type === 'Text' || node.type === 'MustacheTag' || node.type === 'RawMustacheTag') {
569-
return `@appendNode(${node.var}, ${name}._slotted${generator.legacy ? `["default"]` : `.default`});`;
570-
}
571-
572-
if (node.type === 'EachBlock') {
573-
// TODO consider keyed blocks
574-
return `for (var #i = 0; #i < ${node.iterations}.length; #i += 1) ${node.iterations}[#i].m(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
575-
}
576-
577-
return `${node.var}.m(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
578554
}

src/generators/nodes/EachBlock.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,4 +594,9 @@ export default class EachBlock extends Node {
594594

595595
block.builders.destroy.addBlock(`@destroyEach(${iterations});`);
596596
}
597+
598+
remount(name: string) {
599+
// TODO consider keyed blocks
600+
return `for (var #i = 0; #i < ${this.iterations}.length; #i += 1) ${this.iterations}[#i].m(${name}._slotted${this.generator.legacy ? `["default"]` : `.default`}, null);`;
601+
}
597602
}

src/generators/nodes/Element.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,15 @@ export default class Element extends Node {
671671
isMediaNode() {
672672
return this.name === 'audio' || this.name === 'video';
673673
}
674+
675+
remount(name: string) {
676+
const slot = this.attributes.find(attribute => attribute.name === 'slot');
677+
if (slot) {
678+
return `@appendNode(${this.var}, ${name}._slotted.${this.getStaticAttributeValue('slot')});`;
679+
}
680+
681+
return `@appendNode(${this.var}, ${name}._slotted${this.generator.legacy ? `["default"]` : `.default`});`;
682+
}
674683
}
675684

676685
function getRenderStatement(

0 commit comments

Comments
 (0)