Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed Jan 21, 2024
1 parent cd0a0ff commit 02d7cbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/parser/espree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const createRequire: (filename: string) => (modName: string) => any =
return mod.exports;
});

let espreeCache: BasicParserObject | null = null;
let espreeCache: (BasicParserObject & { latestEcmaVersion: number }) | null =
null;

/** Checks if given path is linter path */
function isLinterPath(p: string): boolean {
Expand All @@ -35,7 +36,7 @@ function isLinterPath(p: string): boolean {
* Load `espree` from the loaded ESLint.
* If the loaded ESLint was not found, just returns `require("espree")`.
*/
export function getEspree(): BasicParserObject {
export function getEspree(): BasicParserObject & { latestEcmaVersion: number } {
if (!espreeCache) {
// Lookup the loaded eslint
const linterPath = Object.keys(require.cache || {}).find(isLinterPath);
Expand Down
6 changes: 4 additions & 2 deletions src/parser/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ function parseAttributeMustache(state: State):
if (state.eat("}")) {
const end = endCandidate;
try {
const espree = getEspree();

const expression = (
getEspree().parse(state.code.slice(start, end), {
ecmaVersion: "latest",
espree.parse(state.code.slice(start, end), {
ecmaVersion: espree.latestEcmaVersion,
}).body[0] as ESTree.ExpressionStatement
).expression;
delete expression.range;
Expand Down

0 comments on commit 02d7cbb

Please sign in to comment.