ember-eslint-parser 0.11.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-eslint-parser",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -31,6 +31,8 @@
31
31
  },
32
32
  "devDependencies": {
33
33
  "@babel/core": "^7.23.6",
34
+ "@babel/eslint-parser": "^7.28.6",
35
+ "@babel/plugin-proposal-decorators": "^7.25.9",
34
36
  "@typescript-eslint/parser": "^7.1.0",
35
37
  "@typescript-eslint/scope-manager": "^7.1.0",
36
38
  "@typescript-eslint/visitor-keys": "^7.1.0",
@@ -53,9 +55,13 @@
53
55
  "vitest": "^1.2.2"
54
56
  },
55
57
  "peerDependencies": {
58
+ "@babel/eslint-parser": "^7.28.6",
56
59
  "@typescript-eslint/parser": "*"
57
60
  },
58
61
  "peerDependenciesMeta": {
62
+ "@babel/eslint-parser": {
63
+ "optional": true
64
+ },
59
65
  "@typescript-eslint/parser": {
60
66
  "optional": true
61
67
  }
@@ -4,10 +4,26 @@ import { registerParsedFile } from '../preprocessor/noop.js';
4
4
  import { patchTs, replaceExtensions, syncMtsGtsSourceFiles, typescriptParser } from './ts-patch.js';
5
5
  import { buildGlimmerVisitors } from './transforms.js';
6
6
  import { toTree } from 'ember-estree';
7
- import * as eslintScope from 'eslint-scope';
8
7
 
9
8
  const require = createRequire(import.meta.url);
10
9
 
10
+ // Resolved once at module load via createRequire — top-level `await import()`
11
+ // would mark the module as async, and the bench harness loads parsers
12
+ // synchronously through `createRequire`. `@babel/eslint-parser` is an optional
13
+ // peer (TS-only setups don't need it), so a missing dep yields null and the JS
14
+ // path below emits a targeted error.
15
+ //
16
+ // The experimental-worker entry point runs babel in a worker and matches the
17
+ // parser ember-cli wires up for plain `.js` files in JS-only apps, so config
18
+ // discovery (decorators & friends) lines up with how the rest of the project
19
+ // is being parsed.
20
+ let babelParser = null;
21
+ try {
22
+ babelParser = require('@babel/eslint-parser/experimental-worker');
23
+ } catch {
24
+ // optional peer; left null
25
+ }
26
+
11
27
  /**
12
28
  * implements https://eslint.org/docs/latest/extend/custom-parsers
13
29
  *
@@ -185,18 +201,25 @@ export function parseForESLint(code, options) {
185
201
  return tsResult;
186
202
  }
187
203
  : (placeholderJS) => {
188
- // JS path: parse with oxc, create scope manager from placeholder AST
189
- const { parseSync } = require('oxc-parser');
190
- const oxcResult = parseSync(filePath || 'input.js', placeholderJS);
191
- const program = oxcResult.program;
192
- program.tokens = oxcResult.tokens || [];
193
- program.comments = oxcResult.comments || [];
194
- scopeManager = eslintScope.analyze(program, {
195
- ecmaVersion: 2022,
196
- sourceType: 'module',
197
- range: true,
204
+ // JS path: defer to @babel/eslint-parser, which discovers the
205
+ // consuming app's babel config and applies its plugins (notably
206
+ // decorators) when parsing. That keeps gjs aligned with how the
207
+ // app's plain `.js` files are parsed, so syntax accepted there
208
+ // is accepted here without a second parser config.
209
+ if (!babelParser) {
210
+ throw new Error(
211
+ 'ember-eslint-parser: linting `.gjs`/`.gts` files in a JS-only ' +
212
+ 'project requires `@babel/eslint-parser`. Install it as a ' +
213
+ 'dev dependency, or install `@typescript-eslint/parser` to ' +
214
+ 'opt into the TypeScript-based path.'
215
+ );
216
+ }
217
+ const babelResult = babelParser.parseForESLint(placeholderJS, {
218
+ ...options,
219
+ filePath,
198
220
  });
199
- return { ast: program, scopeManager };
221
+ scopeManager = babelResult.scopeManager;
222
+ return babelResult;
200
223
  },
201
224
  // Factory form: scopeManager is set by the parser callback before this
202
225
  // runs. Returns null when unavailable so ember-estree skips the walk.