Skip to content

Commit 0633e73

Browse files
committed
Fix: Convert MetaProperty (new.target) nodes correcly (fixes eslint#194)
1 parent 4d755ed commit 0633e73

File tree

4 files changed

+258
-16
lines changed

4 files changed

+258
-16
lines changed

lib/ast-converter.js

+19-15
Original file line numberDiff line numberDiff line change
@@ -1819,23 +1819,27 @@ module.exports = function(ast, extra) {
18191819
break;
18201820

18211821
case SyntaxKind.NewExpression:
1822-
1823-
// new.target
1824-
if (node.expression.kind === SyntaxKind.PropertyAccessExpression) {
1825-
assign(result, {
1826-
type: "MetaProperty",
1827-
meta: convertChild(node.expression.name),
1828-
property: convertChild(node.expression.propertyName)
1829-
});
1830-
} else {
1831-
assign(result, {
1832-
type: "NewExpression",
1833-
callee: convertChild(node.expression),
1834-
arguments: (node.arguments) ? node.arguments.map(convertChild) : []
1835-
});
1836-
}
1822+
assign(result, {
1823+
type: "NewExpression",
1824+
callee: convertChild(node.expression),
1825+
arguments: (node.arguments) ? node.arguments.map(convertChild) : []
1826+
});
18371827
break;
18381828

1829+
case SyntaxKind.MetaProperty:
1830+
var newToken = convertToken(node.getFirstToken(), ast);
1831+
1832+
assign(result, {
1833+
type: "MetaProperty",
1834+
meta: {
1835+
type: "Identifier",
1836+
range: newToken.range,
1837+
loc: newToken.loc,
1838+
name: "new"
1839+
},
1840+
property: convertChild(node.name)
1841+
});
1842+
break;
18391843

18401844

18411845
// Literals
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
module.exports = {
2+
"type": "Program",
3+
"range": [
4+
0,
5+
14
6+
],
7+
"loc": {
8+
"start": {
9+
"line": 1,
10+
"column": 0
11+
},
12+
"end": {
13+
"line": 1,
14+
"column": 14
15+
}
16+
},
17+
"body": [
18+
{
19+
"type": "ExpressionStatement",
20+
"range": [
21+
0,
22+
14
23+
],
24+
"loc": {
25+
"start": {
26+
"line": 1,
27+
"column": 0
28+
},
29+
"end": {
30+
"line": 1,
31+
"column": 14
32+
}
33+
},
34+
"expression": {
35+
"type": "NewExpression",
36+
"range": [
37+
0,
38+
13
39+
],
40+
"loc": {
41+
"start": {
42+
"line": 1,
43+
"column": 0
44+
},
45+
"end": {
46+
"line": 1,
47+
"column": 13
48+
}
49+
},
50+
"callee": {
51+
"type": "MemberExpression",
52+
"range": [
53+
4,
54+
11
55+
],
56+
"loc": {
57+
"start": {
58+
"line": 1,
59+
"column": 4
60+
},
61+
"end": {
62+
"line": 1,
63+
"column": 11
64+
}
65+
},
66+
"object": {
67+
"type": "Identifier",
68+
"range": [
69+
4,
70+
7
71+
],
72+
"loc": {
73+
"start": {
74+
"line": 1,
75+
"column": 4
76+
},
77+
"end": {
78+
"line": 1,
79+
"column": 7
80+
}
81+
},
82+
"name": "foo"
83+
},
84+
"property": {
85+
"type": "Identifier",
86+
"range": [
87+
8,
88+
11
89+
],
90+
"loc": {
91+
"start": {
92+
"line": 1,
93+
"column": 8
94+
},
95+
"end": {
96+
"line": 1,
97+
"column": 11
98+
}
99+
},
100+
"name": "bar"
101+
},
102+
"computed": false
103+
},
104+
"arguments": []
105+
}
106+
}
107+
],
108+
"sourceType": "script",
109+
"tokens": [
110+
{
111+
"type": "Keyword",
112+
"value": "new",
113+
"range": [
114+
0,
115+
3
116+
],
117+
"loc": {
118+
"start": {
119+
"line": 1,
120+
"column": 0
121+
},
122+
"end": {
123+
"line": 1,
124+
"column": 3
125+
}
126+
}
127+
},
128+
{
129+
"type": "Identifier",
130+
"value": "foo",
131+
"range": [
132+
4,
133+
7
134+
],
135+
"loc": {
136+
"start": {
137+
"line": 1,
138+
"column": 4
139+
},
140+
"end": {
141+
"line": 1,
142+
"column": 7
143+
}
144+
}
145+
},
146+
{
147+
"type": "Punctuator",
148+
"value": ".",
149+
"range": [
150+
7,
151+
8
152+
],
153+
"loc": {
154+
"start": {
155+
"line": 1,
156+
"column": 7
157+
},
158+
"end": {
159+
"line": 1,
160+
"column": 8
161+
}
162+
}
163+
},
164+
{
165+
"type": "Identifier",
166+
"value": "bar",
167+
"range": [
168+
8,
169+
11
170+
],
171+
"loc": {
172+
"start": {
173+
"line": 1,
174+
"column": 8
175+
},
176+
"end": {
177+
"line": 1,
178+
"column": 11
179+
}
180+
}
181+
},
182+
{
183+
"type": "Punctuator",
184+
"value": "(",
185+
"range": [
186+
11,
187+
12
188+
],
189+
"loc": {
190+
"start": {
191+
"line": 1,
192+
"column": 11
193+
},
194+
"end": {
195+
"line": 1,
196+
"column": 12
197+
}
198+
}
199+
},
200+
{
201+
"type": "Punctuator",
202+
"value": ")",
203+
"range": [
204+
12,
205+
13
206+
],
207+
"loc": {
208+
"start": {
209+
"line": 1,
210+
"column": 12
211+
},
212+
"end": {
213+
"line": 1,
214+
"column": 13
215+
}
216+
}
217+
},
218+
{
219+
"type": "Punctuator",
220+
"value": ";",
221+
"range": [
222+
13,
223+
14
224+
],
225+
"loc": {
226+
"start": {
227+
"line": 1,
228+
"column": 13
229+
},
230+
"end": {
231+
"line": 1,
232+
"column": 14
233+
}
234+
}
235+
}
236+
]
237+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
new foo.bar();

tests/lib/ecma-features.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var testFiles = shelljs.find(FIXTURES_DIR).filter(function(filename) {
4141
}).map(function(filename) {
4242
return filename.substring(FIXTURES_DIR.length - 1, filename.length - 7); // strip off ".src.js"
4343
}).filter(function(filename) {
44-
return !(/error\-|invalid\-|globalReturn|experimental|newTarget/.test(filename));
44+
return !(/error\-|invalid\-|globalReturn|experimental/.test(filename));
4545
});
4646

4747
// var moduleTestFiles = testFiles.filter(function(filename) {

0 commit comments

Comments
 (0)