Skip to content

Commit

Permalink
Fix bad rebase :(
Browse files Browse the repository at this point in the history
  • Loading branch information
kaicataldo committed Feb 20, 2020
1 parent a9dc043 commit e77e6af
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
1 change: 0 additions & 1 deletion eslint/babel-eslint-parser/package.json
Expand Up @@ -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"
}
}
17 changes: 4 additions & 13 deletions eslint/babel-eslint-parser/src/convert/convertAST.js
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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) {
Expand Down
28 changes: 20 additions & 8 deletions 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)) {
Expand Down Expand Up @@ -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."));
});
});
Expand Down Expand Up @@ -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*/");
});

Expand Down
6 changes: 0 additions & 6 deletions packages/babel-parser/src/plugins/estree.js
Expand Up @@ -415,10 +415,4 @@ export default (superClass: Class<Parser>): Class<Parser> =>

super.toReferencedListDeep(exprList, isParenthesizedExpr);
}

createIdentifier(node, name) {
const idNode = super.createIdentifier(node, name);
delete idNode.loc.identifierName;
return idNode;
}
};

0 comments on commit e77e6af

Please sign in to comment.