|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import { isBoolean, isNumber, isString } from '@intlify/shared' |
6 | | -import { parse as parseJavaScript } from 'acorn' |
7 | 6 | import { generate as generateJavaScript } from 'escodegen' |
8 | | -import { walk } from 'estree-walker' |
| 7 | +import { parseSync as parseJavaScript } from 'oxc-parser' |
| 8 | +import { walk } from 'oxc-walker' |
9 | 9 | import { |
10 | 10 | createCodeGenerator, |
11 | 11 | generateMessageFunction, |
12 | 12 | generateResourceAst, |
13 | 13 | mapLinesColumns |
14 | 14 | } from './codegen' |
15 | 15 |
|
16 | | -import type { Node } from 'estree' |
| 16 | +import type { Node } from 'oxc-parser' |
17 | 17 | import type { RawSourceMap } from 'source-map-js' |
18 | 18 | import type { CodeGenerator, CodeGenFunction, CodeGenOptions, CodeGenResult } from './codegen' |
19 | 19 |
|
@@ -50,12 +50,11 @@ export function generate( |
50 | 50 |
|
51 | 51 | const _options = Object.assign({}, DEFAULT_OPTIONS, options, { source: value }) |
52 | 52 | const generator = createCodeGenerator(_options) |
53 | | - const ast = parseJavaScript(value, { |
54 | | - ecmaVersion: 'latest', |
| 53 | + |
| 54 | + const { program: ast } = parseJavaScript(_options.filename ?? '', value, { |
55 | 55 | sourceType: 'module', |
56 | | - sourceFile: _options.filename, |
57 | | - allowImportExportEverywhere: true |
58 | | - }) as Node |
| 56 | + lang: 'js' |
| 57 | + }) |
59 | 58 |
|
60 | 59 | const exportResult = scanAst(ast) |
61 | 60 | if (!_options.allowDynamic) { |
@@ -154,15 +153,9 @@ function _generate( |
154 | 153 | // slice and reuse imports and top-level variable declarations as-is |
155 | 154 | // NOTE: this prevents optimization/compilation of top-level variables, we may be able to add support for this |
156 | 155 | walk(node, { |
157 | | - /** |
158 | | - * NOTE: |
159 | | - * force cast to Node of `estree-walker@3.x`, |
160 | | - * because `estree-walker@3.x` is not dual packages, |
161 | | - * so it's support only esm only ... |
162 | | - */ |
163 | 156 | // @ts-ignore |
164 | | - enter(node: Node, _parent) { |
165 | | - if (_parent?.type != null) this.skip() |
| 157 | + enter(node, parent) { |
| 158 | + if (parent?.type != null) this.skip() |
166 | 159 | switch (node.type) { |
167 | 160 | case 'ExportDefaultDeclaration': |
168 | 161 | this.skip() |
@@ -201,7 +194,7 @@ function _generate( |
201 | 194 | * so it's support only esm only ... |
202 | 195 | */ |
203 | 196 | // @ts-ignore |
204 | | - enter(node: Node, parent: Node) { |
| 197 | + enter(node, parent) { |
205 | 198 | // skip imports and top-level variable declarations |
206 | 199 | if (parent?.type === 'Program') { |
207 | 200 | switch (node.type) { |
@@ -336,12 +329,6 @@ function _generate( |
336 | 329 | break |
337 | 330 | } |
338 | 331 | }, |
339 | | - /** |
340 | | - * NOTE: |
341 | | - * force cast to Node of `estree-walker@3.x`, |
342 | | - * because `estree-walker@3.x` is not dual packages, |
343 | | - * so it's support only esm only ... |
344 | | - */ |
345 | 332 | // @ts-ignore |
346 | 333 | leave(node: Node, parent: Node) { |
347 | 334 | switch (node.type) { |
|
0 commit comments