diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 59f2e2a33e..6e5cf286e6 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -44,16 +44,6 @@ childKeys.EachBlock = childKeys.IfBlock = ['children', 'else']; childKeys.Attribute = ['value']; childKeys.ExportNamedDeclaration = ['declaration', 'specifiers']; -function remove_node( - body: Node[], - node: Node -) { - const i = body.indexOf(node); - if (i === -1) throw new Error('node not in list'); - - body.splice(i, 1); -} - export default class Component { stats: Stats; warnings: Warning[]; @@ -478,13 +468,15 @@ export default class Component { } extract_imports(content) { - content.body.forEach(node => { + let i = content.body.length; + while (i--) { + const node = content.body[i]; + if (node.type === 'ImportDeclaration') { - // imports need to be hoisted out of the IIFE - remove_node(content.body, node); + content.body.splice(i, 1); this.imports.push(node); } - }); + } } extract_exports(content) { diff --git a/src/compiler/compile/nodes/Let.ts b/src/compiler/compile/nodes/Let.ts index 1e8014285a..de8f73cdd2 100644 --- a/src/compiler/compile/nodes/Let.ts +++ b/src/compiler/compile/nodes/Let.ts @@ -15,9 +15,10 @@ export default class Let extends Node { super(component, parent, scope, info); this.name = { type: 'Identifier', name: info.name }; - this.value = info.expression.node; if (info.expression) { + this.value = info.expression; + walk(info.expression, { enter: node => { if (!applicable.has(node.type)) { @@ -30,6 +31,15 @@ export default class Let extends Node { if (node.type === 'Identifier') { this.names.push(node.name); } + + // slightly unfortunate hack + if (node.type === 'ArrayExpression') { + (node as any).type = 'ArrayPattern'; + } + + if (node.type === 'ObjectExpression') { + (node as any).type = 'ObjectPattern'; + } } }); } else { diff --git a/src/compiler/compile/render_dom/wrappers/shared/get_context_merger.ts b/src/compiler/compile/render_dom/wrappers/shared/get_context_merger.ts index eeec593847..8c27e8b503 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/get_context_merger.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/get_context_merger.ts @@ -4,8 +4,6 @@ import { x } from 'code-red'; export function get_context_merger(lets: Let[]) { if (lets.length === 0) return null; - console.log(lets); - const input = { type: 'ObjectPattern', properties: lets.map(l => ({