pull/3539/head
Richard Harris 6 years ago
parent 9e1bc908d3
commit 6616b17c7a

@ -44,16 +44,6 @@ childKeys.EachBlock = childKeys.IfBlock = ['children', 'else'];
childKeys.Attribute = ['value']; childKeys.Attribute = ['value'];
childKeys.ExportNamedDeclaration = ['declaration', 'specifiers']; 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 { export default class Component {
stats: Stats; stats: Stats;
warnings: Warning[]; warnings: Warning[];
@ -478,13 +468,15 @@ export default class Component {
} }
extract_imports(content) { extract_imports(content) {
content.body.forEach(node => { let i = content.body.length;
while (i--) {
const node = content.body[i];
if (node.type === 'ImportDeclaration') { if (node.type === 'ImportDeclaration') {
// imports need to be hoisted out of the IIFE content.body.splice(i, 1);
remove_node(content.body, node);
this.imports.push(node); this.imports.push(node);
} }
}); }
} }
extract_exports(content) { extract_exports(content) {

@ -15,9 +15,10 @@ export default class Let extends Node {
super(component, parent, scope, info); super(component, parent, scope, info);
this.name = { type: 'Identifier', name: info.name }; this.name = { type: 'Identifier', name: info.name };
this.value = info.expression.node;
if (info.expression) { if (info.expression) {
this.value = info.expression;
walk(info.expression, { walk(info.expression, {
enter: node => { enter: node => {
if (!applicable.has(node.type)) { if (!applicable.has(node.type)) {
@ -30,6 +31,15 @@ export default class Let extends Node {
if (node.type === 'Identifier') { if (node.type === 'Identifier') {
this.names.push(node.name); 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 { } else {

@ -4,8 +4,6 @@ import { x } from 'code-red';
export function get_context_merger(lets: Let[]) { export function get_context_merger(lets: Let[]) {
if (lets.length === 0) return null; if (lets.length === 0) return null;
console.log(lets);
const input = { const input = {
type: 'ObjectPattern', type: 'ObjectPattern',
properties: lets.map(l => ({ properties: lets.map(l => ({

Loading…
Cancel
Save