-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathLet.ts
38 lines (32 loc) · 953 Bytes
/
Let.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import Node from './shared/Node';
import Component from '../Component';
import { walk } from 'estree-walker';
const applicable = new Set(['Identifier', 'ObjectExpression', 'ArrayExpression', 'Property']);
export default class Let extends Node {
type: 'Let';
name: string;
value: string;
names: string[] = [];
constructor(component: Component, parent, scope, info) {
super(component, parent, scope, info);
this.name = info.name;
this.value = info.expression && `[✂${info.expression.start}-${info.expression.end}✂]`;
if (info.expression) {
walk(info.expression, {
enter: node => {
if (!applicable.has(node.type)) {
component.error(node, {
code: 'invalid-let',
message: `let directive value must be an identifier or an object/array pattern`
});
}
if (node.type === 'Identifier') {
this.names.push(node.name);
}
}
});
} else {
this.names.push(this.name);
}
}
}