Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 8b4e548

Browse files
soda0289JamesHenry
authored andcommitted
Fix: Convert Void and Delete expressions to UnaryExpression (fixes #171) (#174)
1 parent f96b6e2 commit 8b4e548

File tree

5 files changed

+499
-0
lines changed

5 files changed

+499
-0
lines changed

lib/ast-converter.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,24 @@ module.exports = function(ast, extra) {
16531653
});
16541654
break;
16551655

1656+
case SyntaxKind.DeleteExpression:
1657+
assign(result, {
1658+
type: "UnaryExpression",
1659+
operator: "delete",
1660+
prefix: true,
1661+
argument: convertChild(node.expression)
1662+
});
1663+
break;
1664+
1665+
case SyntaxKind.VoidExpression:
1666+
assign(result, {
1667+
type: "UnaryExpression",
1668+
operator: "void",
1669+
prefix: true,
1670+
argument: convertChild(node.expression)
1671+
});
1672+
break;
1673+
16561674
case SyntaxKind.TypeOfExpression:
16571675
assign(result, {
16581676
type: "UnaryExpression",
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
module.exports = {
2+
"type": "Program",
3+
"range": [
4+
0,
5+
15
6+
],
7+
"loc": {
8+
"start": {
9+
"line": 1,
10+
"column": 0
11+
},
12+
"end": {
13+
"line": 1,
14+
"column": 15
15+
}
16+
},
17+
"body": [
18+
{
19+
"type": "ExpressionStatement",
20+
"range": [
21+
0,
22+
15
23+
],
24+
"loc": {
25+
"start": {
26+
"line": 1,
27+
"column": 0
28+
},
29+
"end": {
30+
"line": 1,
31+
"column": 15
32+
}
33+
},
34+
"expression": {
35+
"type": "UnaryExpression",
36+
"range": [
37+
0,
38+
14
39+
],
40+
"loc": {
41+
"start": {
42+
"line": 1,
43+
"column": 0
44+
},
45+
"end": {
46+
"line": 1,
47+
"column": 14
48+
}
49+
},
50+
"operator": "delete",
51+
"prefix": true,
52+
"argument": {
53+
"type": "MemberExpression",
54+
"range": [
55+
7,
56+
14
57+
],
58+
"loc": {
59+
"start": {
60+
"line": 1,
61+
"column": 7
62+
},
63+
"end": {
64+
"line": 1,
65+
"column": 14
66+
}
67+
},
68+
"object": {
69+
"type": "Identifier",
70+
"range": [
71+
7,
72+
10
73+
],
74+
"loc": {
75+
"start": {
76+
"line": 1,
77+
"column": 7
78+
},
79+
"end": {
80+
"line": 1,
81+
"column": 10
82+
}
83+
},
84+
"name": "foo"
85+
},
86+
"property": {
87+
"type": "Identifier",
88+
"range": [
89+
11,
90+
14
91+
],
92+
"loc": {
93+
"start": {
94+
"line": 1,
95+
"column": 11
96+
},
97+
"end": {
98+
"line": 1,
99+
"column": 14
100+
}
101+
},
102+
"name": "bar"
103+
},
104+
"computed": false
105+
}
106+
}
107+
}
108+
],
109+
"sourceType": "script",
110+
"tokens": [
111+
{
112+
"type": "Keyword",
113+
"value": "delete",
114+
"range": [
115+
0,
116+
6
117+
],
118+
"loc": {
119+
"start": {
120+
"line": 1,
121+
"column": 0
122+
},
123+
"end": {
124+
"line": 1,
125+
"column": 6
126+
}
127+
}
128+
},
129+
{
130+
"type": "Identifier",
131+
"value": "foo",
132+
"range": [
133+
7,
134+
10
135+
],
136+
"loc": {
137+
"start": {
138+
"line": 1,
139+
"column": 7
140+
},
141+
"end": {
142+
"line": 1,
143+
"column": 10
144+
}
145+
}
146+
},
147+
{
148+
"type": "Punctuator",
149+
"value": ".",
150+
"range": [
151+
10,
152+
11
153+
],
154+
"loc": {
155+
"start": {
156+
"line": 1,
157+
"column": 10
158+
},
159+
"end": {
160+
"line": 1,
161+
"column": 11
162+
}
163+
}
164+
},
165+
{
166+
"type": "Identifier",
167+
"value": "bar",
168+
"range": [
169+
11,
170+
14
171+
],
172+
"loc": {
173+
"start": {
174+
"line": 1,
175+
"column": 11
176+
},
177+
"end": {
178+
"line": 1,
179+
"column": 14
180+
}
181+
}
182+
},
183+
{
184+
"type": "Punctuator",
185+
"value": ";",
186+
"range": [
187+
14,
188+
15
189+
],
190+
"loc": {
191+
"start": {
192+
"line": 1,
193+
"column": 14
194+
},
195+
"end": {
196+
"line": 1,
197+
"column": 15
198+
}
199+
}
200+
}
201+
]
202+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
delete foo.bar;

0 commit comments

Comments
 (0)