From e77e6afe06f8ff36fd16e8ed2754ba8e5585e3d1 Mon Sep 17 00:00:00 2001 From: Kai Cataldo Date: Thu, 20 Feb 2020 09:35:13 -0500 Subject: [PATCH] Fix bad rebase :( --- eslint/babel-eslint-parser/package.json | 1 - .../src/convert/convertAST.js | 17 +++-------- eslint/babel-eslint-parser/test/index.js | 28 +++++++++++++------ packages/babel-parser/src/plugins/estree.js | 6 ---- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/eslint/babel-eslint-parser/package.json b/eslint/babel-eslint-parser/package.json index 2d219e6a3375..20580eb5d50a 100644 --- a/eslint/babel-eslint-parser/package.json +++ b/eslint/babel-eslint-parser/package.json @@ -31,7 +31,6 @@ "@babel/core": "^7.2.0", "@babel/eslint-shared-fixtures": "*", "eslint": "^6.0.1", - "espree": "^6.0.0", "lodash.clonedeep": "^4.5.0" } } diff --git a/eslint/babel-eslint-parser/src/convert/convertAST.js b/eslint/babel-eslint-parser/src/convert/convertAST.js index 012d6cfefc30..661f68c3bbd4 100644 --- a/eslint/babel-eslint-parser/src/convert/convertAST.js +++ b/eslint/babel-eslint-parser/src/convert/convertAST.js @@ -22,16 +22,12 @@ function convertNodes(ast, code) { exit(path) { const node = path.node; - if (node.extra) { + if (Object.hasOwnProperty.call(node, "extra")) { delete node.extra; } - if (node.variance) { - delete node.variance; - } - - if (node.typeArguments) { - delete node.typeArguments; + if (node.loc && Object.hasOwnProperty.call(node.loc, "identifierName")) { + delete node.loc.identifierName; } if (path.isTypeParameter()) { @@ -111,12 +107,7 @@ function convertProgramNode(ast) { if (ast.comments.length) { const lastComment = ast.comments[ast.comments.length - 1]; - if (!ast.tokens.length) { - // if no tokens, the program starts at the end of the last comment - ast.start = lastComment.end; - ast.loc.start.line = lastComment.loc.end.line; - ast.loc.start.column = lastComment.loc.end.column; - } else { + if (ast.tokens.length) { const lastToken = ast.tokens[ast.tokens.length - 1]; if (lastComment.end > lastToken.end) { diff --git a/eslint/babel-eslint-parser/test/index.js b/eslint/babel-eslint-parser/test/index.js index 433cd60f1855..8816e1efb415 100644 --- a/eslint/babel-eslint-parser/test/index.js +++ b/eslint/babel-eslint-parser/test/index.js @@ -1,15 +1,22 @@ +import path from "path"; import assert from "assert"; -import espree from "espree"; import escope from "eslint-scope"; import unpad from "dedent"; import { parseForESLint } from "../src"; +let espree; + const BABEL_OPTIONS = { configFile: require.resolve( "@babel/eslint-shared-fixtures/config/babel.config.js", ), }; -const ALLOWED_PROPERTIES = ["importKind", "exportKind"]; +const ALLOWED_PROPERTIES = [ + "importKind", + "exportKind", + "variance", + "typeArguments", +]; function deeplyRemoveProperties(obj, props) { for (const [k, v] of Object.entries(obj)) { @@ -53,15 +60,22 @@ function parseAndAssertSame(code) { } describe("Babel and Espree", () => { + beforeAll(async () => { + const espreePath = require.resolve("espree", { + paths: [path.dirname(require.resolve("eslint"))], + }); + espree = await import(espreePath); + }); + describe("compatibility", () => { it("should allow ast.analyze to be called without options", function() { - const esAST = parseForESLint("`test`", { + const ast = parseForESLint("`test`", { eslintScopeManager: true, eslintVisitorKeys: true, babelOptions: BABEL_OPTIONS, }).ast; expect(() => { - escope.analyze(esAST); + escope.analyze(ast); }).not.toThrow(new TypeError("Should allow no options argument.")); }); }); @@ -296,13 +310,11 @@ describe("Babel and Espree", () => { assert.strictEqual(babylonAST.tokens[3].value, "#"); }); - // eslint-disable-next-line jest/no-disabled-tests - it.skip("empty program with line comment", () => { + it("empty program with line comment", () => { parseAndAssertSame("// single comment"); }); - // eslint-disable-next-line jest/no-disabled-tests - it.skip("empty program with block comment", () => { + it("empty program with block comment", () => { parseAndAssertSame(" /* multiline\n * comment\n*/"); }); diff --git a/packages/babel-parser/src/plugins/estree.js b/packages/babel-parser/src/plugins/estree.js index b043ee0d14d7..6104e616057e 100644 --- a/packages/babel-parser/src/plugins/estree.js +++ b/packages/babel-parser/src/plugins/estree.js @@ -415,10 +415,4 @@ export default (superClass: Class): Class => super.toReferencedListDeep(exprList, isParenthesizedExpr); } - - createIdentifier(node, name) { - const idNode = super.createIdentifier(node, name); - delete idNode.loc.identifierName; - return idNode; - } };