Skip to content

Commit

Permalink
Fix: tokenize the latest right curly brace (fixes #403) (#419)
Browse files Browse the repository at this point in the history
* Fix: tokenize the latest right curly brace (fixes #403)

* Chore: add link to an issue for a test
  • Loading branch information
finico authored and platinumazure committed Aug 15, 2019
1 parent f5e58cc commit 3f49224
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/espree.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ module.exports = () => Parser => class Espree extends Parser {
this.next();
} while (this.type !== tokTypes.eof);

// Consume the final eof token
this.next();

const extra = this[STATE];
const tokens = extra.tokens;

Expand Down
16 changes: 16 additions & 0 deletions tests/lib/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,20 @@ describe("tokenize()", () => {
espree.tokenize("foo", Object.freeze({ ecmaFeatures: Object.freeze({}) }));
});

/**
* Make sure we tokenize closing curly brace in a block statement at end of file
* @see https://github.com/eslint/espree/issues/403 for more information
*/
it("should produce tokens when } is the last token", () => {
const tokens = espree.tokenize("{}");

assert.deepStrictEqual(
tester.getRaw(tokens),
[
{ type: "Punctuator", value: "{" },
{ type: "Punctuator", value: "}" }
]
);
});

});

0 comments on commit 3f49224

Please sign in to comment.