|
29 | 29 | import { ast, initAst, SOURCE_CODE } from "./source_code.js"; |
30 | 30 | import { report } from "./report.js"; |
31 | 31 | import { settings, initSettings } from "./settings.js"; |
| 32 | +import visitorKeys from "../generated/keys.js"; |
32 | 33 | import { debugAssertIsNonNull } from "../utils/asserts.js"; |
33 | 34 |
|
34 | 35 | import type { RuleDetails } from "./load.ts"; |
35 | 36 | import type { Options } from "./options.ts"; |
36 | 37 | import type { Diagnostic } from "./report.ts"; |
37 | 38 | import type { Settings } from "./settings.ts"; |
38 | 39 | import type { SourceCode } from "./source_code.ts"; |
39 | | -import type { ModuleKind } from "../generated/types.d.ts"; |
| 40 | +import type { ModuleKind, Program } from "../generated/types.d.ts"; |
40 | 41 |
|
41 | 42 | const { freeze, assign: ObjectAssign, create: ObjectCreate } = Object; |
42 | 43 |
|
@@ -68,6 +69,68 @@ export function resetFileContext(): void { |
68 | 69 |
|
69 | 70 | // ECMAScript version. This matches ESLint's default. |
70 | 71 | const ECMA_VERSION = 2026; |
| 72 | +const ECMA_VERSION_NUMBER = 17; |
| 73 | + |
| 74 | +// Supported ECMAScript versions. This matches ESLint's default. |
| 75 | +const SUPPORTED_ECMA_VERSIONS = freeze([3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]); |
| 76 | + |
| 77 | +// Singleton object for parser's `Syntax` property. Generated lazily. |
| 78 | +let Syntax: Record<string, string> | null = null; |
| 79 | + |
| 80 | +// Singleton object for parser. |
| 81 | +const PARSER = freeze({ |
| 82 | + /** |
| 83 | + * Parser name. |
| 84 | + */ |
| 85 | + name: "oxc", |
| 86 | + |
| 87 | + /** |
| 88 | + * Parser version. |
| 89 | + */ |
| 90 | + // TODO: This can be statically defined, but need it be to be updated when we make a new release. |
| 91 | + version: "0.0.0", |
| 92 | + |
| 93 | + /** |
| 94 | + * Parse code into an AST. |
| 95 | + * @param code - Code to parse |
| 96 | + * @param options? - Parser options |
| 97 | + * @returns AST |
| 98 | + */ |
| 99 | + // oxlint-disable-next-line no-unused-vars |
| 100 | + parse(code: string, options?: Record<string, unknown>): Program { |
| 101 | + throw new Error("`context.languageOptions.parser.parse` not implemented yet."); // TODO |
| 102 | + }, |
| 103 | + |
| 104 | + /** |
| 105 | + * Visitor keys for AST nodes. |
| 106 | + */ |
| 107 | + VisitorKeys: visitorKeys, |
| 108 | + |
| 109 | + /** |
| 110 | + * Ast node types. |
| 111 | + */ |
| 112 | + get Syntax(): Readonly<Record<string, string>> { |
| 113 | + // Construct lazily, as it's probably rarely used |
| 114 | + if (Syntax === null) { |
| 115 | + Syntax = ObjectCreate(null); |
| 116 | + for (const key in visitorKeys) { |
| 117 | + Syntax![key] = key; |
| 118 | + } |
| 119 | + freeze(Syntax); |
| 120 | + } |
| 121 | + return Syntax!; |
| 122 | + }, |
| 123 | + |
| 124 | + /** |
| 125 | + * Latest ECMAScript version supported by parser. |
| 126 | + */ |
| 127 | + latestEcmaVersion: ECMA_VERSION_NUMBER, |
| 128 | + |
| 129 | + /** |
| 130 | + * ECMAScript versions supported by parser. |
| 131 | + */ |
| 132 | + supportedEcmaVersions: SUPPORTED_ECMA_VERSIONS, |
| 133 | +}); |
71 | 134 |
|
72 | 135 | // Singleton object for parser options. |
73 | 136 | // TODO: `sourceType` is the only property ESLint provides. But does TS-ESLint provide any further properties? |
@@ -109,9 +172,7 @@ const LANGUAGE_OPTIONS = freeze({ |
109 | 172 | /** |
110 | 173 | * Parser used to parse the file being linted. |
111 | 174 | */ |
112 | | - get parser(): Record<string, unknown> { |
113 | | - throw new Error("`context.languageOptions.parser` not implemented yet."); // TODO |
114 | | - }, |
| 175 | + parser: PARSER, |
115 | 176 |
|
116 | 177 | /** |
117 | 178 | * Parser options used to parse the file being linted. |
|
0 commit comments