Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/angular/build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ ts_project(
":node_modules/@angular/ssr",
":node_modules/@babel/core",
":node_modules/@inquirer/confirm",
":node_modules/@oxc-parser/binding-wasm32-wasi",
":node_modules/@oxc-project/types",
":node_modules/@parcel/watcher",
":node_modules/@vitejs/plugin-basic-ssl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

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

describe('OxcAstHost', () => {
Expand All @@ -18,14 +18,14 @@ describe('OxcAstHost', () => {
});

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

return stmt.declarations[0].init;
}

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

return program.body[0];
}
Expand Down
4 changes: 2 additions & 2 deletions packages/angular/build/src/tools/i18n/i18n-inliner-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@angular/localize';
import { MagicString } from 'magic-string';
import { deserialize } from 'node:v8';
import { loadOxcParser } from '../oxc/load-oxc-parser';
import { parseSync } from 'oxc-parser';
import { traversePostOrder } from '../oxc/traversal';
import { createSharedTranslationProxy } from './i18n-translation-reader';
import { loadLocaleData } from './locale-data';
Expand Down Expand Up @@ -402,7 +402,7 @@ interface FileLocalizeMetadata {
* @returns The extracted localization metadata.
*/
function extractLocalizeMetadata(filename: string, code: string): FileLocalizeMetadata {
const { program } = loadOxcParser().parseSync(filename, code, {
const { program } = parseSync(filename, code, {
sourceType: 'unambiguous',
});

Expand Down
124 changes: 0 additions & 124 deletions packages/angular/build/src/tools/oxc/load-oxc-parser.ts

This file was deleted.

114 changes: 0 additions & 114 deletions packages/angular/build/src/tools/oxc/load-oxc-parser_spec.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/angular/build/src/tools/oxc/oxc-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import type { DecodedSourceMap } from '@ampproject/remapping';
import { needsLinking } from '@angular/compiler-cli/linker';
import type { BindingIdentifier, Class, Node } from '@oxc-project/types';
import { MagicString } from 'magic-string';
import { parseSync } from 'oxc-parser';
import { OxcLinker } from '../angular/linker/oxc-linker';
import { loadOxcParser } from './load-oxc-parser';
import { traversePostOrder } from './traversal';

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

const shouldLink = options.link && needsLinking(filename, code);
Expand Down
6 changes: 2 additions & 4 deletions packages/angular/build/src/tools/oxc/traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
*/

import type { Node } from '@oxc-project/types';
import { loadOxcParser } from './load-oxc-parser';

let visitorKeys: Record<string, string[]> | undefined;
import { visitorKeys } from 'oxc-parser';

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

const keys = (visitorKeys ??= loadOxcParser().visitorKeys)[node.type];
const keys = visitorKeys[node.type];
if (!keys) {
break;
}
Expand Down
11 changes: 9 additions & 2 deletions packages/angular/build/src/utils/source-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@

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

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

let parseSync: typeof import('oxc-parser').parseSync | undefined;

/**
* Checks for a single trailing `//# sourceMappingURL=` comment on a raw buffer.
*
Expand Down Expand Up @@ -118,7 +120,12 @@ function removeSourceMappingURLFromString(code: string, skipTrailingCheck = fals
}
}

const { comments } = loadOxcParser().parseSync('source.js', code, {
if (!parseSync) {
const localRequire = createRequire(__filename);
parseSync = (localRequire('oxc-parser') as typeof import('oxc-parser')).parseSync;
}

const { comments } = parseSync('source.js', code, {
lang: 'js',
sourceType: 'unambiguous',
});
Expand Down
Loading