Skip to content

Commit c44d819

Browse files
committed
port babel-eslint path-based introspection, fixup tests
1 parent 320d926 commit c44d819

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

acorn-to-esprima.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,73 +175,74 @@ function convertTemplateType(tokens) {
175175
var astTransformVisitor = {
176176
noScope: true,
177177
exit: function (node, parent) {
178-
if (t.isSpreadProperty(node)) {
178+
if (this.isSpreadProperty()) {
179179
node.type = "Property";
180180
node.kind = "init";
181181
node.computed = true;
182182
node.key = node.value = node.argument;
183183
delete node.argument;
184184
}
185185

186-
if (t.isRestElement(node)) {
186+
if (this.isRestElement()) {
187187
return node.argument;
188188
}
189189

190190
// flow
191-
if (t.isTypeCastExpression(node)) {
191+
if (this.isTypeCastExpression()) {
192192
return node.expression;
193193
}
194194

195-
if (t.isFlow(node)) {
195+
if (this.isFlow()) {
196196
return this.remove();
197197
}
198198

199199
// modules
200200

201-
if (t.isImportDeclaration(node)) {
201+
if (this.isImportDeclaration()) {
202202
delete node.isType;
203203
}
204204

205-
if (t.isExportDeclaration(node)) {
206-
if (t.isClassExpression(node.declaration)) {
205+
if (this.isExportDeclaration()) {
206+
var declar = this.get("declaration");
207+
if (declar.isClassExpression()) {
207208
node.declaration.type = "ClassDeclaration";
208-
} else if (t.isFunctionExpression(node.declaration)) {
209+
} else if (declar.isFunctionExpression()) {
209210
node.declaration.type = "FunctionDeclaration";
210211
}
211212
}
212213

213-
if (t.isFunctionDeclaration(node) || t.isFunctionExpression(node)) {
214+
if (this.isFunctionDeclaration() || this.isFunctionExpression()) {
214215
if (!node.defaults) {
215216
node.defaults = [];
216217
}
217218
}
218219

219220
// classes
220221

221-
if (t.isReferencedIdentifier(node, parent, { name: "super" })) {
222+
if (this.isReferencedIdentifier({ name: "super" })) {
222223
return t.inherits(t.thisExpression(), node);
223224
}
224225

225-
if (t.isClassProperty(node)) {
226+
if (this.isClassProperty()) {
226227
delete node.key;
227228
}
228229

229230
// functions
230231

231-
if (t.isFunction(node)) {
232+
if (this.isFunction()) {
232233
if (node.async) node.generator = true;
233234
delete node.async;
234235
}
235236

236-
if (t.isAwaitExpression(node)) {
237+
if (this.isAwaitExpression()) {
237238
node.type = "YieldExpression";
238239
node.delegate = node.all;
239240
delete node.all;
240241
}
241242

242243
// template strings
243244

244-
if (t.isTemplateLiteral(node)) {
245+
if (this.isTemplateLiteral()) {
245246
node.quasis.forEach(function (q) {
246247
q.range[0] -= 1;
247248
if (q.tail) {

test/babel-jscs.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,13 @@ describe("acorn-to-esprima", function () {
118118
});
119119

120120
it("template with destructuring", function () {
121-
verifyAndAssertMessages([
121+
parseAndAssertSame([
122122
"module.exports = {",
123123
"render() {",
124124
"var {name} = this.props;",
125125
"return Math.max(null, `Name: ${name}, Name: ${name}`);",
126126
"}",
127-
"};"].join("\n"),
128-
{ "comma-spacing": 1 },
129-
[]
127+
"};"].join("\n")
130128
);
131129
});
132130
});

test/non-regression.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe("verify", function () {
7676
"return Math.max(null, `Name: ${name}, Name: ${name}`);",
7777
"}",
7878
"};"].join("\n"),
79-
{ "comma-spacing": 1 },
79+
{},
8080
[]
8181
);
8282
});

0 commit comments

Comments
 (0)