Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: misuse token types (fixes #393, refs eslint/eslint#11018) #426

Merged
merged 2 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/espree.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
"use strict";

/* eslint-disable no-param-reassign*/
const acorn = require("acorn");
const jsx = require("acorn-jsx");
const TokenTranslator = require("./token-translator");

const DEFAULT_ECMA_VERSION = 5;
const STATE = Symbol("espree's internal state");
const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
const tokTypes = Object.assign({}, acorn.tokTypes, jsx.tokTypes);


/**
* Normalize ECMAScript version from the initial config
Expand Down Expand Up @@ -111,7 +107,14 @@ function convertAcornCommentToEsprimaComment(block, text, start, end, startLoc,
return comment;
}

module.exports = () => Parser => class Espree extends Parser {
module.exports = () => Parser => {
const tokTypes = Object.assign({}, Parser.acorn.tokTypes);

if (Parser.acornJsx) {
Object.assign(tokTypes, Parser.acornJsx.tokTypes);
}

return class Espree extends Parser {
constructor(opts, code) {
if (typeof opts !== "object" || opts === null) {
opts = {};
Expand Down Expand Up @@ -249,7 +252,7 @@ module.exports = () => Parser => class Espree extends Parser {
* @returns {void}
*/
raise(pos, message) {
const loc = acorn.getLineInfo(this.input, pos);
const loc = Parser.acorn.getLineInfo(this.input, pos);
const err = new SyntaxError(message);

err.index = pos;
Expand Down Expand Up @@ -346,3 +349,4 @@ module.exports = () => Parser => class Espree extends Parser {
return result;
}
};
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
},
"license": "BSD-2-Clause",
"dependencies": {
"acorn": "^7.0.0",
"acorn-jsx": "^5.0.2",
"acorn": "^7.1.0",
"acorn-jsx": "^5.1.0",
"eslint-visitor-keys": "^1.1.0"
},
"devDependencies": {
Expand Down