ember-eslint-parser 0.14.4 → 0.14.6

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/README.md CHANGED
@@ -31,6 +31,21 @@ It's recommended to only use _overrides_ when defining your eslint config, so us
31
31
  if we detect a typescript parser, it will also be used for all files, otherwise babel parser will be used.
32
32
  If we cannot find a typescript parser when linting gts we throw an error.
33
33
 
34
+ If you use type-aware rules, route `.js`/`.ts` through this parser too, as
35
+ `eslint-plugin-ember`'s configs do:
36
+
37
+ ```js
38
+ {
39
+ files: ['**/*.{js,ts}'],
40
+ parser: 'ember-eslint-parser',
41
+ // ...
42
+ },
43
+ ```
44
+
45
+ `@typescript-eslint/parser` hands TypeScript the source as ESLint read it, so a
46
+ `.ts` file importing from a `.gts` gets an `error` type for that import. This
47
+ parser rewrites the specifier first.
48
+
34
49
  ## HBS (Handlebars) support
35
50
 
36
51
  For `.hbs` template files, use the `ember-eslint-parser/hbs` parser. In ESLint's flat config format (ESLint 9+):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-eslint-parser",
3
- "version": "0.14.4",
3
+ "version": "0.14.6",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'node:module';
2
2
  import { registerParsedFile } from '../preprocessor/noop.js';
3
- import { patchTs, replaceExtensions, syncMtsGtsSourceFiles, typescriptParser } from './ts-patch.js';
3
+ import { replaceExtensions, syncMtsGtsSourceFiles, typescriptParser } from './ts-patch.js';
4
4
  import { buildGlimmerVisitors } from './transforms.js';
5
5
  import { toTree } from 'ember-estree';
6
6
 
@@ -48,10 +48,6 @@ export const meta = {
48
48
  };
49
49
 
50
50
  export function parseForESLint(code, options) {
51
- // Only patch TypeScript if we actually need it.
52
- if (options.programs || options.projectService || options.project) {
53
- patchTs();
54
- }
55
51
  registerParsedFile(options.filePath);
56
52
 
57
53
  const isTypescript = options.filePath.endsWith('.gts') || options.filePath.endsWith('.ts');
@@ -123,6 +123,12 @@ try {
123
123
  return jsCode;
124
124
  };
125
125
 
126
+ // typescript-eslint copies `ts.sys` by value when it builds a program or
127
+ // project service, on the first type-aware parse in the process — which may be
128
+ // a plain .ts file that never reaches this parser. Patching at module load is
129
+ // what puts the wrappers in that copy, and in the project's first file scan.
130
+ patchTs();
131
+
126
132
  /**
127
133
  *
128
134
  * @param program {ts.Program}
@@ -155,6 +161,14 @@ try {
155
161
  originalFileName: virtualSourceFile.originalFileName,
156
162
  resolvedPath: virtualSourceFile.resolvedPath,
157
163
  impliedNodeFormat: virtualSourceFile.impliedNodeFormat,
164
+ // The twin is a .mts/.mjs, so its script kind has to stay the one the language
165
+ // service host reports for that extension. Inheriting the .gts/.gjs file's
166
+ // Deferred kind makes TypeScript's getOrCreateSourceFileByPath see a script-kind
167
+ // mismatch on the next program sync, and it responds by releasing and
168
+ // re-acquiring the document instead of updating it — a full re-parse of every
169
+ // twin, on every parse. It never settles either: the re-acquired file comes back
170
+ // as TS, and the next call to this function stamps it back to Deferred.
171
+ scriptKind: virtualSourceFile.scriptKind,
158
172
  };
159
173
  Object.assign(virtualSourceFile, sourceFile, keep);
160
174
  virtualSourceFile[virtualFlag] = true;