pull/3539/head
Richard Harris 6 years ago
parent 9ba199a716
commit c4a43a36a1

@ -5,7 +5,7 @@ import TemplateScope from './shared/TemplateScope';
import AbstractBlock from './shared/AbstractBlock'; import AbstractBlock from './shared/AbstractBlock';
import Element from './Element'; import Element from './Element';
import { x, p } from 'code-red'; import { x, p } from 'code-red';
import { Node, Identifier } from 'estree'; import { Node, Identifier, RestElement } from 'estree';
interface Context { interface Context {
key: Identifier; key: Identifier;
@ -32,8 +32,15 @@ function unpack_destructuring(contexts: Context[], node: Node, modifier: (node:
} else if (node.type === 'ObjectPattern') { } else if (node.type === 'ObjectPattern') {
const used_properties = []; const used_properties = [];
node.properties.forEach((property) => { node.properties.forEach((property, i) => {
if ((property as any).kind === 'rest') { // TODO is this right? if ((property as any).kind === 'rest') { // TODO is this right?
const replacement: RestElement = {
type: 'RestElement',
argument: property.key as Identifier
}
node.properties[i] = replacement;
unpack_destructuring( unpack_destructuring(
contexts, contexts,
property.value, property.value,

@ -16,11 +16,13 @@ export default class Let extends Node {
this.name = { type: 'Identifier', name: info.name }; this.name = { type: 'Identifier', name: info.name };
const { names } = this;
if (info.expression) { if (info.expression) {
this.value = 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)) {
component.error(node as any, { component.error(node as any, {
code: 'invalid-let', code: 'invalid-let',
@ -29,7 +31,7 @@ export default class Let extends Node {
} }
if (node.type === 'Identifier') { if (node.type === 'Identifier') {
this.names.push(node.name); names.push(node.name);
} }
// slightly unfortunate hack // slightly unfortunate hack
@ -43,7 +45,7 @@ export default class Let extends Node {
} }
}); });
} else { } else {
this.names.push(this.name.name); names.push(this.name.name);
} }
} }
} }
Loading…
Cancel
Save