Skip to content

fix(napi/transform): correct error messages for compile options - #30280

Merged
overlookmotel merged 1 commit into
mainfrom
om/11-25-fix_napi_transform_correct_error_messages_for_compile_options
Nov 25, 2026
Merged

overlookmotel merged 1 commit into
mainfrom
om/11-25-fix_napi_transform_correct_error_messages_for_compile_options

Conversation

@overlookmotel

@overlookmotel overlookmotel commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

transform and transformSync reported errors in the options (e.g. a syntax error in the value of a define) with a code frame. The code frame was rendered against the source text of the file being transformed. But the position of such an error is an offset into the option's value, not into the source text. So the code frame pointed at unrelated code, and was misleading.

Input:

import { transformSync } from "oxc-transform";

const code = "const first = 'aaa';\nconst second = 'bbb';\n";
const ret = transformSync("a.js", code, { define: { FOO: "1 +" } });
console.log(ret.errors[0].codeframe);

Before output:

  x Unexpected token
   ,-[a.js:1:4]
 1 | const first = 'aaa';
   :    ^
 2 | const second = 'bbb';
   `----

After output:

The define value `1 +` for key `FOO` is not a valid expression: Unexpected token

The error is at offset 3 of the define's value 1 +. Before, that offset was looked up in the file, which is why the code frame pointed at line 1, column 4 of a.js.

Now options errors have no code frame, only the message, and the message says which define the problem is in.

It'd be ideal to produce a codeframe showing the define's value, but that would require much more intrusive changes, as OxcDiagnostic doesn't support providing source text.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@github-actions github-actions Bot added A-transformer Area - JS/TS transforms and downleveling, oxc_transformer A-napi Area - Node.js bindings and WASM builds of the napi/ packages, oxc_napi labels Nov 25, 2026
@overlookmotel overlookmotel self-assigned this Nov 25, 2026
@overlookmotel
overlookmotel marked this pull request as draft November 25, 2026 17:41
@overlookmotel
overlookmotel force-pushed the om/11-25-fix_napi_transform_correct_error_messages_for_compile_options branch from 9b245ea to 062cee7 Compare November 25, 2026 17:49
@overlookmotel
overlookmotel marked this pull request as ready for review November 25, 2026 17:50
Comment thread napi/transform/test/transform.test.ts Resolved
@overlookmotel
overlookmotel force-pushed the om/11-25-fix_napi_transform_correct_error_messages_for_compile_options branch from 062cee7 to 4302ea8 Compare November 25, 2026 18:55
@codspeed

codspeed Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

Warning

oxc-project has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

✅ 81 untouched benchmarks
⏩ 29 skipped benchmarks1


Comparing om/11-25-fix_napi_transform_correct_error_messages_for_compile_options (4302ea8) with main (1ca8aaa)

Open in CodSpeed

Footnotes

  1. 29 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@overlookmotel
overlookmotel added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit f10f033 Nov 25, 2026
42 checks passed
@overlookmotel
overlookmotel deleted the om/11-25-fix_napi_transform_correct_error_messages_for_compile_options branch November 25, 2026 22:29
Dunqing added a commit to rolldown/rolldown that referenced this pull request Nov 26, 2026
Pins the decorators-lowering head restacked onto oxc main 746ad93f.

Snapshot changes from oxc main:
- ts_experimental_decorators: computed keys of decorated `declare`
  fields are evaluated and passed to __decorate again
  (oxc-project/oxc#30264).
- ts_declare_class_fields: keys of `declare` fields are no longer
  evaluated, as tsc and esbuild do (oxc-project/oxc#30272).
- invalid_define_config/value: the error names the key and value
  (oxc-project/oxc#30280).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-napi Area - Node.js bindings and WASM builds of the napi/ packages, oxc_napi A-transformer Area - JS/TS transforms and downleveling, oxc_transformer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants