← 输入框|github.com|刷新
Skip to content

fix(vite): keep value: undefined in HMR-served Vue scripts - #11542

Merged
NathanWalker merged 2 commits into
mainfrom
fix/vite-sfc-undefined-property
Oct 21, 2026
Merged

NathanWalker merged 2 commits into
mainfrom
fix/vite-sfc-undefined-property

Conversation

@triniwiz

Copy link
Copy Markdown
Member

PR Checklist

What is the current behavior?

On the Vue /ns/asm HMR path, astExtractImportsAndStripTypes (hmr/helpers/ast-extract.ts) ran a regex over the printed code to strip residual parameter type annotations. It also matched object properties, so { label: 'System', value: undefined } became { label: 'System', value }, which references an undefined variable.

What is the new behavior?

Parameter annotations are removed on the AST before printing, and the regex is gone. The variable-annotation pass is unchanged.

Tests: 2 cases in ast-extract.spec.ts.

Each new test fails without the change. The @nativescript/vite suite (163 files) and tsc -p tsconfig.lib.json pass on the branch.

The Vue SFC assembler hoists imports out of a compiled `<script setup>` with
astExtractImportsAndStripTypes, which then ran a regex over the printed code
to strip leftover parameter annotations. The regex matched any `, name:
undefined` (or `null`, `string`, ...), so object properties were rewritten
too: `{ label: 'System', value: undefined }` became `{ label: 'System', value }`,
a shorthand for a variable that doesn't exist.

Parameter annotations are now removed on the AST before it is printed, so
object literals are left alone. TypeScript is already stripped by Babel
before and after this step; this only matters when that fails.
@nx-cloud

nx-cloud Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 3e306eb

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 19s 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-10-15 20:52:40 UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 3e306eb

@NathanWalker
NathanWalker merged commit 9893c1e into main Oct 21, 2026
10 checks passed
@NathanWalker
NathanWalker deleted the fix/vite-sfc-undefined-property branch October 21, 2026 18:39
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.

2 participants