Skip to content

Commit 4712775

Browse files
authored
Fix for ecmaVersion: "latest" (#171)
* Fix for `ecmaVersion: "latest"` * fix
1 parent 6469326 commit 4712775

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

explorer-v2/src/app.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<link rel="icon" href="/svelte-eslint-parser/favicon.ico" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77

8-
%svelte.head%
8+
%sveltekit.head%
99
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.33.0/min/vs/loader.min.js"></script>
1010
</head>
1111
<body>
12-
<div id="svelte">%svelte.body%</div>
12+
<div id="svelte">%sveltekit.body%</div>
1313
</body>
1414
</html>

src/parser/analyze-scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function analyzeScope(
2727
ignoreEval: true,
2828
nodejsScope: false,
2929
impliedStrict: ecmaFeatures.impliedStrict,
30-
ecmaVersion,
30+
ecmaVersion: typeof ecmaVersion === "number" ? ecmaVersion : 2022,
3131
sourceType,
3232
fallback: getFallbackKeys,
3333
})

tests/src/parser/eslint.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Linter } from "eslint"
22
import assert from "assert"
3+
import semver from "semver"
34
import * as parser from "../../../src/index"
45
import { BASIC_PARSER_OPTIONS } from "./test-utils"
56

@@ -52,6 +53,7 @@ describe("eslint custom parser", () => {
5253
line: number
5354
column: number
5455
}[]
56+
parserOptions?: any
5557
}[] = [
5658
{
5759
code: `
@@ -217,14 +219,37 @@ describe("eslint custom parser", () => {
217219
output: null,
218220
messages: [],
219221
},
222+
...(semver.satisfies(
223+
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -- ignore
224+
require("eslint/package.json").version,
225+
">=8.0.0",
226+
)
227+
? [
228+
{
229+
// test for ecmaVersion latest
230+
code: `
231+
<script>
232+
import { count } from './stores.js';
233+
</script>
234+
<h1>The count is {$count}</h1>
235+
`,
236+
output: null,
237+
parserOptions: { ecmaVersion: "latest" },
238+
messages: [],
239+
},
240+
]
241+
: []),
220242
]
221243

222-
for (const { code, output, messages } of tests) {
244+
for (const { code, output, messages, parserOptions } of tests) {
223245
it(code, () => {
224246
const linter = createLinter()
225247
const result = linter.verifyAndFix(code, {
226248
parser: "svelte-eslint-parser",
227-
parserOptions: BASIC_PARSER_OPTIONS,
249+
parserOptions: {
250+
...BASIC_PARSER_OPTIONS,
251+
...(parserOptions ? parserOptions : {}),
252+
},
228253
rules: {
229254
"no-unused-labels": "error",
230255
"no-extra-label": "error",

0 commit comments

Comments
 (0)