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
6 changes: 6 additions & 0 deletions .changeset/dedupe-hermes-oxc-parser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rnx-kit/metro-transformer-oxc": patch
"@rnx-kit/tools-babel": patch
---

Bump `hermes-parser` to 0.35 and `oxc-parser` to 0.155
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ catalog:
memfs: ^4.56.10
metro-babel-transformer: ^0.84.0
metro-source-map: ^0.84.0
oxc-parser: ^0.134.0
oxc-parser: ^0.155.0
oxc-resolver: ^11.0.0
oxfmt: ^0.72.0
oxlint: ^1.87.0
Expand Down
2 changes: 1 addition & 1 deletion incubator/tools-babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"dependencies": {
"@rnx-kit/tools-performance": "workspace:^",
"hermes-parser": "^0.34.0",
"hermes-parser": "^0.35.0",
"oxc-parser": "catalog:"
},
"devDependencies": {
Expand Down
34 changes: 32 additions & 2 deletions incubator/tools-babel/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
} from "@rnx-kit/test-fixtures";
import fs from "node:fs";
import path from "node:path";
import { parseSync as oxcParseSync } from "oxc-parser";
import { toBabelAST } from "../src/estree.ts";
import { makeTransformerArgs } from "../src/options.ts";
import { oxcParseToAst } from "../src/parse.ts";
import { isFlowError } from "../src/parse.ts";
import type {
BabelTransformerArgs,
BabelTransformerOptions,
Expand Down Expand Up @@ -116,6 +118,34 @@ export function createFixtureWrapper(name: FixtureSetName) {
};
}

/**
* Like `oxcParseToAst()`, but returns the AST even if `oxc-parser` reports
* recoverable errors. Some fixtures contain invalid syntax that Babel accepts.
*/
function oxcParseIgnoringErrors({
src,
filename,
context,
config,
}: TransformerArgs): Node | null {
if (context.disableOxcParser ?? context.mayContainFlow) {
return null;
}

const isTypeScript =
context.srcSyntax === "ts" || context.srcSyntax === "tsx";
const { program, comments, errors } = oxcParseSync(filename, src, {
sourceType: config.sourceType ?? "unambiguous",
lang: context.srcSyntax,
astType: isTypeScript ? "ts" : "js",
});
if (isFlowError(errors)) {
return null;
}

return toBabelAST(program, src, isTypeScript, comments);
}

export class FileData {
babelArgs: BabelTransformerArgs;
error?: Error;
Expand Down Expand Up @@ -147,7 +177,7 @@ export class FileData {

get oxcAst(): Node | null {
if (this._oxcAst === undefined) {
this._oxcAst = this.args ? oxcParseToAst(this.args) : null;
this._oxcAst = this.args ? oxcParseIgnoringErrors(this.args) : null;
}
return this._oxcAst;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@types/node": "catalog:",
"@yarnpkg/types": "catalog:",
"eslint": "catalog:",
"knip": "^6.0.0",
"knip": "^6.44.1",
"nx": "patch:nx@npm%3A22.7.12#~/.yarn/patches/nx-npm-22.7.2-0fb0af5a48.patch",
"oxfmt": "catalog:",
"oxlint": "catalog:",
Expand Down
Loading
Loading