Skip to content

Commit 5affb76

Browse files
committed
refactor(@angular/build): remove oxc WASI shim
The upstream issue with @napi-rs/wasm-runtime and @emnapi/core WASI fallback resolution has been fixed in @napi-rs/wasm-runtime@1.2.7 (napi-rs/napi-rs#3680), making the temporary WASI shim no longer necessary.
1 parent 12578ec commit 5affb76

8 files changed

Lines changed: 18 additions & 252 deletions

File tree

‎packages/angular/build/BUILD.bazel‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ ts_project(
8989
":node_modules/@angular/ssr",
9090
":node_modules/@babel/core",
9191
":node_modules/@inquirer/confirm",
92-
":node_modules/@oxc-parser/binding-wasm32-wasi",
9392
":node_modules/@oxc-project/types",
9493
":node_modules/@parcel/watcher",
9594
":node_modules/@vitejs/plugin-basic-ssl",

‎packages/angular/build/src/tools/angular/linker/oxc-ast-host_spec.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { FatalLinkerError } from '@angular/compiler-cli/linker';
10-
import { loadOxcParser } from '../../oxc/load-oxc-parser';
10+
import { parseSync } from 'oxc-parser';
1111
import { OxcAstHost } from './oxc-ast-host';
1212

1313
describe('OxcAstHost', () => {
@@ -18,14 +18,14 @@ describe('OxcAstHost', () => {
1818
});
1919

2020
function parseExpression(code: string): unknown {
21-
const { program } = loadOxcParser().parseSync('test.js', `const x = ${code};`, { range: true });
21+
const { program } = parseSync('test.js', `const x = ${code};`, { range: true });
2222
const stmt = program.body[0] as { declarations: Array<{ init: unknown }> };
2323

2424
return stmt.declarations[0].init;
2525
}
2626

2727
function parseStatement(code: string): unknown {
28-
const { program } = loadOxcParser().parseSync('test.js', code, { range: true });
28+
const { program } = parseSync('test.js', code, { range: true });
2929

3030
return program.body[0];
3131
}

‎packages/angular/build/src/tools/i18n/i18n-inliner-worker.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from '@angular/localize';
1717
import { MagicString } from 'magic-string';
1818
import { deserialize } from 'node:v8';
19-
import { loadOxcParser } from '../oxc/load-oxc-parser';
19+
import { parseSync } from 'oxc-parser';
2020
import { traversePostOrder } from '../oxc/traversal';
2121
import { createSharedTranslationProxy } from './i18n-translation-reader';
2222
import { loadLocaleData } from './locale-data';
@@ -402,7 +402,7 @@ interface FileLocalizeMetadata {
402402
* @returns The extracted localization metadata.
403403
*/
404404
function extractLocalizeMetadata(filename: string, code: string): FileLocalizeMetadata {
405-
const { program } = loadOxcParser().parseSync(filename, code, {
405+
const { program } = parseSync(filename, code, {
406406
sourceType: 'unambiguous',
407407
});
408408

‎packages/angular/build/src/tools/oxc/load-oxc-parser.ts‎

Lines changed: 0 additions & 124 deletions
This file was deleted.

‎packages/angular/build/src/tools/oxc/load-oxc-parser_spec.ts‎

Lines changed: 0 additions & 114 deletions
This file was deleted.

‎packages/angular/build/src/tools/oxc/oxc-transform.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import type { DecodedSourceMap } from '@ampproject/remapping';
1010
import { needsLinking } from '@angular/compiler-cli/linker';
1111
import type { BindingIdentifier, Class, Node } from '@oxc-project/types';
1212
import { MagicString } from 'magic-string';
13+
import { parseSync } from 'oxc-parser';
1314
import { OxcLinker } from '../angular/linker/oxc-linker';
14-
import { loadOxcParser } from './load-oxc-parser';
1515
import { traversePostOrder } from './traversal';
1616

1717
export interface OxcTransformOptions {
@@ -261,7 +261,7 @@ function analyzeClassStaticProperties(classNode: Node, code: string): boolean {
261261
*/
262262
// eslint-disable-next-line max-lines-per-function
263263
export function transform(filename: string, code: string, options: OxcTransformOptions) {
264-
const { program } = loadOxcParser().parseSync(filename, code, { range: true });
264+
const { program } = parseSync(filename, code, { range: true });
265265
const source = new MagicString(code);
266266

267267
const shouldLink = options.link && needsLinking(filename, code);

‎packages/angular/build/src/tools/oxc/traversal.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
*/
88

99
import type { Node } from '@oxc-project/types';
10-
import { loadOxcParser } from './load-oxc-parser';
11-
12-
let visitorKeys: Record<string, string[]> | undefined;
10+
import { visitorKeys } from 'oxc-parser';
1311

1412
/**
1513
* Contextual scope information provided to AST visitor callbacks during traversal.
@@ -277,7 +275,7 @@ function pushChildNodes(node: Node, stack: (Node | null)[]): void {
277275
break;
278276
}
279277

280-
const keys = (visitorKeys ??= loadOxcParser().visitorKeys)[node.type];
278+
const keys = visitorKeys[node.type];
281279
if (!keys) {
282280
break;
283281
}

‎packages/angular/build/src/utils/source-map.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88

99
import type { EncodedSourceMap } from '@ampproject/remapping';
1010
import { existsSync, readFileSync } from 'node:fs';
11+
import { createRequire } from 'node:module';
1112
import { dirname, resolve } from 'node:path';
1213
import { fileURLToPath } from 'node:url';
13-
import { loadOxcParser } from '../tools/oxc/load-oxc-parser';
1414

1515
export const SOURCEMAP_COMMENT_PREFIX = '//# sourceMappingURL=';
1616
export const SOURCEMAP_COMMENT_BYTES = Buffer.from(SOURCEMAP_COMMENT_PREFIX);
1717
const SOURCEMAP_COMMENT_VALUE_PREFIX = SOURCEMAP_COMMENT_PREFIX.slice(2);
1818

19+
let parseSync: typeof import('oxc-parser').parseSync | undefined;
20+
1921
/**
2022
* Checks for a single trailing `//# sourceMappingURL=` comment on a raw buffer.
2123
*
@@ -118,7 +120,12 @@ function removeSourceMappingURLFromString(code: string, skipTrailingCheck = fals
118120
}
119121
}
120122

121-
const { comments } = loadOxcParser().parseSync('source.js', code, {
123+
if (!parseSync) {
124+
const localRequire = createRequire(__filename);
125+
parseSync = (localRequire('oxc-parser') as typeof import('oxc-parser')).parseSync;
126+
}
127+
128+
const { comments } = parseSync('source.js', code, {
122129
lang: 'js',
123130
sourceType: 'unambiguous',
124131
});

0 commit comments

Comments
 (0)