Skip to content

Commit 8f41cd0

Browse files
committed
feat: support typescript-eslint-parser-for-extra-files
1 parent 1637af4 commit 8f41cd0

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/context/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ import {
2020
} from "../parser/parser-object";
2121
import { sortedLastIndex } from "../utils";
2222

23+
const TS_PARSER_NAMES = [
24+
"@typescript-eslint/parser",
25+
"typescript-eslint-parser-for-extra-files",
26+
];
27+
2328
export class ScriptsSourceCode {
2429
private raw: string;
2530

@@ -241,18 +246,18 @@ export class Context {
241246
isTSESLintParserObject(parserValue));
242247
}
243248
const parserName = parserValue;
244-
if (parserName === "@typescript-eslint/parser") {
249+
if (TS_PARSER_NAMES.includes(parserName)) {
245250
return (this.state.isTypeScript = true);
246251
}
247-
if (parserName.includes("@typescript-eslint/parser")) {
252+
if (TS_PARSER_NAMES.some((nm) => parserName.includes(nm))) {
248253
let targetPath = parserName;
249254
while (targetPath) {
250255
const pkgPath = path.join(targetPath, "package.json");
251256
if (fs.existsSync(pkgPath)) {
252257
try {
253-
return (this.state.isTypeScript =
254-
JSON.parse(fs.readFileSync(pkgPath, "utf-8"))?.name ===
255-
"@typescript-eslint/parser");
258+
return (this.state.isTypeScript = TS_PARSER_NAMES.includes(
259+
JSON.parse(fs.readFileSync(pkgPath, "utf-8"))?.name
260+
));
256261
} catch {
257262
return (this.state.isTypeScript = false);
258263
}

src/parser/typescript/restore.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@ export class RestoreContext {
8686
(f) => f.start < end && end <= f.end
8787
);
8888
if (endFragment) {
89+
end = endFragment.start;
8990
if (startFragment === endFragment) {
90-
end = start;
91-
} else {
92-
end = endFragment.start;
91+
start = startFragment.start;
9392
}
9493
}
9594

0 commit comments

Comments
 (0)