fix(optimizer): dep-scan misses imports whose local name starts with type - #23531
Closed
Dextheking1 wants to merge 1 commit into
Closed
Dextheking1 wants to merge 1 commit into
Dextheking1 wants to merge 1 commit into
Conversation
The dep-scan importsRE used a negative lookahead for TypeScript import type statements without a word boundary, so any value import whose binding starts with the letters type (e.g. import typescript from 'typescript') was treated as a type-only import and skipped by extractImportPaths. Add the missing word boundary so only real import type forms are skipped. Enable the previously commented-out false-negative cases in scan.spec.ts as regression tests. Fixes vitejs#23471
Contributor
|
This PR has been automatically flagged as likely to be created by a bot, LLM, or agent, and will be automatically closed. These contributions harm the maintenance of the project. Please read our AI policy for more information. If you believe this is a mistake, please reply to this comment and we will review it. |
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.
Description
Fixes #23471.
The dependency scanner's
importsREinpackages/vite/src/node/optimizer/scan.tsused the negative lookahead(?!\s+type)without a word boundary, so any import whose local binding starts withtype(e.g.import typescript from 'typescript',import typeorm from 'typeorm') was silently skipped by dep-scan.The fix adds the missing word boundary:
(?!\s+type\b).import type { Bar }/import type{ Bar }/import type Barstill correctly fail to match (verified).What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
Tests
Enabled the previously-commented-out false-negative cases in
packages/vite/src/node/__tests__/scan.spec.ts(import typescript from 'typescript',import typeorm from 'typeorm',import types from 'types') — the updatedimports regex should worktest fails without the fix (1 failed, 12 skipped) and passes with it. Fullscan.spec.ts: 13/13 pass.oxfmt --checkandeslintclean on both files.