• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ota-meshi / astro-eslint-parser / 27600724045

16 Jun 2026 07:13AM UTC coverage: 81.279% (-0.5%) from 81.805%
27600724045

Pull #435

github

web-flow
Merge 8602d87cb into ce311c59d
Pull Request #435: feat!: use `@astrojs/compiler-rs` instead of `@astrojs/compiler`

648 of 870 branches covered (74.48%)

Branch coverage included in aggregate %.

350 of 398 new or added lines in 9 files covered. (87.94%)

9 existing lines in 4 files now uncovered.

1258 of 1475 relevant lines covered (85.29%)

52150.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.67
/src/parser/script.ts
1
import type { Context } from "../context";
2,831!
2
import { debug } from "../debug";
1✔
3
import type {
4
  ParserOptions,
5
  ParserOptionsContext,
6
} from "../context/parser-options";
7
import type { ESLintExtendedProgram } from "../types";
8
import { tsPatch } from "./ts-patch";
1✔
9
import { isEnhancedParserObject } from "../context/resolve-parser/parser-object";
1✔
10
import type { TSESTree } from "@typescript-eslint/types";
11
import type { ScopeManager as TSESLintScopeManager } from "@typescript-eslint/scope-manager";
12
import { analyze as analyzeForTypeScript } from "@typescript-eslint/scope-manager";
1✔
13
import type { AnalyzeOptions } from "eslint-scope";
14
import { KEYS } from "../visitor-keys";
1✔
15
import { getKeys } from "../traverse";
1✔
16
import { getEslintScope } from "./eslint-scope";
1✔
17

18
const eslintScope = getEslintScope();
1✔
19
/**
20
 * Parse for script
21
 */
22
export function parseScript(
1✔
23
  code: string,
24
  ctx: Context,
25
  parserOptionsCtx: ParserOptionsContext,
26
): ESLintExtendedProgram {
27
  const result = parseScriptInternal(code, ctx, parserOptionsCtx);
1,404✔
28

29
  const parserOptions = parserOptionsCtx.parserOptions;
1,404✔
30
  if (!result.scopeManager && parserOptions.eslintScopeManager) {
1,404✔
31
    result.scopeManager = analyzeScope(result, parserOptions);
50✔
32
  }
33

34
  return result;
1,404✔
35
}
36

37
/**
38
 * Analyze scope
39
 */
40
function analyzeScope(
1✔
41
  result: ESLintExtendedProgram,
42
  parserOptions: ParserOptions,
43
): TSESLintScopeManager {
44
  try {
50✔
45
    return analyzeForTypeScript(result.ast, {
50✔
46
      globalReturn: parserOptions.ecmaFeatures?.globalReturn,
47
      jsxPragma: parserOptions.jsxPragma,
48
      jsxFragmentName: parserOptions.jsxFragmentName,
49
      lib: parserOptions.lib,
50
      sourceType: parserOptions.sourceType,
51
    });
52
  } catch {
53
    // ignore
54
  }
55
  const ecmaFeatures = parserOptions.ecmaFeatures || {};
32!
56

57
  return analyzeForEcmaScript(result.ast, {
32✔
58
    ignoreEval: true,
59
    nodejsScope: ecmaFeatures.globalReturn,
60
    impliedStrict: ecmaFeatures.impliedStrict as never,
61
    ecmaVersion: 1e8,
62
    sourceType:
63
      parserOptions.sourceType === "commonjs"
32!
64
        ? "script"
65
        : parserOptions.sourceType || "script",
32!
66
    childVisitorKeys: result.visitorKeys || KEYS,
64✔
67
    fallback: getKeys,
68
  });
69
}
70

71
/**
72
 * Parse for script
73
 */
74
function parseScriptInternal(
1✔
75
  code: string,
76
  _ctx: Context,
77
  parserOptionsCtx: ParserOptionsContext,
78
): ESLintExtendedProgram {
79
  const parser = parserOptionsCtx.getParser();
1,404✔
80

81
  let patchResult;
82

83
  try {
1,404✔
84
    const parserOptions = parserOptionsCtx.parserOptions;
1,404✔
85
    if (
1,404✔
86
      parserOptionsCtx.isTypeScript() &&
4,108✔
87
      parserOptions.filePath &&
88
      parserOptions.project
89
    ) {
90
      patchResult = tsPatch(parserOptions, parserOptionsCtx.getTSParserName()!);
1,349✔
91
    } else if (
55✔
92
      parserOptionsCtx.isTypeScript() &&
61✔
93
      parserOptions.filePath &&
94
      parserOptions.projectService
95
    ) {
96
      console.warn(
2✔
97
        "`astro-eslint-parser` does not support the `projectService` option, it will parse it as `project: true` instead.",
98
      );
99
      patchResult = tsPatch(
2✔
100
        { ...parserOptions, project: true, projectService: undefined },
101
        parserOptionsCtx.getTSParserName()!,
102
      );
103
    }
104

105
    const result = isEnhancedParserObject(parser)
1,404✔
106
      ? patchResult?.parse
1,353✔
107
        ? patchResult.parse(code, parser)
108
        : parser.parseForESLint(code, parserOptions)
109
      : parser.parse(code, parserOptions);
110

111
    if ("ast" in result && result.ast != null) {
1,404✔
112
      return result;
1,353✔
113
    }
114
    return { ast: result } as ESLintExtendedProgram;
51✔
UNCOV
115
  } catch (e) {
×
116
    debug(
117
      "[script] parsing error:",
118
      (e as any).message,
119
      `@ ${JSON.stringify(code)}
120

121
${code}`,
122
    );
UNCOV
123
    throw e;
×
124
  } finally {
125
    patchResult?.terminate();
1,404✔
126
  }
127
}
128

129
/**
130
 * Analyzed scopes for JavaScript.
131
 */
132
function analyzeForEcmaScript(
2!
133
  tree: TSESTree.Program,
134
  providedOptions: AnalyzeOptions,
135
): TSESLintScopeManager {
136
  const options = Object.assign(
32✔
137
    {
138
      optimistic: false,
139
      nodejsScope: false,
140
      impliedStrict: false,
141
      sourceType: "script", // one of ['script', 'module', 'commonjs']
142
      ecmaVersion: 5,
143
      childVisitorKeys: null,
144
      fallback: "iteration",
145
      jsx: true,
146
    },
147
    providedOptions,
148
  );
149
  const scopeManager = eslintScope.analyze(tree as never, options);
32✔
150

151
  return scopeManager as never;
32✔
152
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc