Skip to content

fix(vite): mask comments before scanning module export names - #11473

Merged
NathanWalker merged 2 commits into
NativeScript:mainfrom
aleclarson:fix/vite-commented-export-names
Sep 29, 2026
Merged

NathanWalker merged 2 commits into
NativeScript:mainfrom
aleclarson:fix/vite-commented-export-names

Conversation

@aleclarson

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

extractDirectExportedNames scans module source for export declarations using regexes over raw text — comments are never masked. A CJS module containing a commented-out declaration such as

module.exports = {};
// export const roundRadiusProperty = {};

produces a phantom export name. Downstream, expandStarExports then emits

export { roundRadiusProperty } from "/ns/m/node_modules/ui-image/index-common.js";

which fails at link time on device because the served module never provides that binding (SyntaxError during HTTP-ESM instantiation; the boot aborts).

Same class of bug exists in scanModuleExportSurface's export */export {} from regexes and in extractExportMetadata, which scan raw text independently.

Real-world trigger: @nativescript-community/ui-image ships index-common.js with a commented-out // export const roundRadiusProperty = ... — any app depending on it can't boot a dev session.

What is the new behavior?

New maskJsComments helper blanks // and /* */ comment regions in-place while leaving string literals untouched (newlines preserved so match positions stay meaningful). Applied inside extractDirectExportedNames (the shared primitive) and at the top of scanModuleExportSurface and extractExportMetadata.

Fixes #11471.

Testing note

Added a regression spec in websocket-star-export-expansion.spec.ts — a star-export target carrying commented-out export lines no longer leaks the phantom name into the emitted import list. Verified locally via the bundled output (the workspace's full Nx setup wasn't available in my env). Minimal standalone repro: https://github.com/aleclarson/repro/tree/nativescript-11471

@nx-cloud

nx-cloud Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 70357c0

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 48s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-09-29 21:27:16 UTC

@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nativescript/core@11473
npm i https://pkg.pr.new/@nativescript/vite@11473
npm i https://pkg.pr.new/@nativescript/webpack@11473

commit: 70357c0

A quote inside a regex literal (e.g. /["']/) desynced string tracking, so a
later string containing /* or // was treated as a comment and real export
declarations were blanked.
@NathanWalker
NathanWalker merged commit 523252f into NativeScript:main Sep 29, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vite: extractDirectExportedNames matches 'export' inside comments, producing phantom CJS exports

2 participants