Skip to content

Commit 3f49224

Browse files
finicoplatinumazure
authored andcommitted
Fix: tokenize the latest right curly brace (fixes #403) (#419)
* Fix: tokenize the latest right curly brace (fixes #403) * Chore: add link to an issue for a test
1 parent f5e58cc commit 3f49224

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/espree.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ module.exports = () => Parser => class Espree extends Parser {
175175
this.next();
176176
} while (this.type !== tokTypes.eof);
177177

178+
// Consume the final eof token
179+
this.next();
180+
178181
const extra = this[STATE];
179182
const tokens = extra.tokens;
180183

tests/lib/tokenize.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,20 @@ describe("tokenize()", () => {
199199
espree.tokenize("foo", Object.freeze({ ecmaFeatures: Object.freeze({}) }));
200200
});
201201

202+
/**
203+
* Make sure we tokenize closing curly brace in a block statement at end of file
204+
* @see https://github.com/eslint/espree/issues/403 for more information
205+
*/
206+
it("should produce tokens when } is the last token", () => {
207+
const tokens = espree.tokenize("{}");
208+
209+
assert.deepStrictEqual(
210+
tester.getRaw(tokens),
211+
[
212+
{ type: "Punctuator", value: "{" },
213+
{ type: "Punctuator", value: "}" }
214+
]
215+
);
216+
});
217+
202218
});

0 commit comments

Comments
 (0)