Repository navigation
Conversation
`TransformOptions.preserveWhitespaces` is now the default for components whose decorator does not set it, as in ngtsc's `parseTemplateDeclaration`. The Vite plugin gets a `preserveWhitespaces` option, used for HMR updates too. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #631.
Problem
TransformOptions.preserveWhitespaces(ngc'sangularCompilerOptions.preserveWhitespaces) was ignored bytransformAngularFileandcompileComponentHmrUpdate:compile_component_fullparsed the template with the decorator'spreserveWhitespacesonly, so a project-widetruestill collapsed whitespace. The Vite plugin had no way to set it. Found with Angular'sngtsc_spec.ts: "should take preserveWhitespaces config option into account".Fix
Port ngtsc's
parseTemplateDeclaration(compiler-cli/src/ngtsc/annotations/component/src/resources.ts): start from the project default and let the decorator override it.ComponentMetadata.preserve_whitespacesis nowOption<bool>(Nonewhen the decorator does not set it).compile_component_fullresolves decorator →options.preserve_whitespaces→false, and writes the result back so partial declarations (ɵɵngDeclareComponent) carry it as well. HMR updates go through the same function.preserveWhitespacesoption, passed to the transform (and so to HMR updates); documented in the README. The plugin does not readangularCompilerOptionsfrom the tsconfig, so an explicit option is the smallest way in.compileTemplate, deprecatedcompileForHmr) already used the option as the template's value; unchanged.Checks
tests/preserve_whitespaces_test.rs, porting the three ngtsc cases (default, project option, decorator overrides the option both ways) plus the partial declaration.hmr_component_update_test::keeps_whitespace_the_project_option_preserves: the HMR update keeps whitespace and matches the transform's template.cargo test -p oxc_angular_compiler --all-features: 3522 passed, 0 failed.cargo check -p oxc_angular_compiler_napiandtsc --noEmiton the Vite plugin pass.🤖 Generated with Claude Code