Skip to content

fix(optimizer): dep-scan misses imports whose local name starts with type - #23531

Closed
Dextheking1 wants to merge 1 commit into
vitejs:mainfrom
Dextheking1:fix/dep-scan-type-prefix-regex
Closed

Dextheking1 wants to merge 1 commit into
vitejs:mainfrom
Dextheking1:fix/dep-scan-type-prefix-regex

Conversation

@Dextheking1

Copy link
Copy Markdown

Description

Fixes #23471.

The dependency scanner's importsRE in packages/vite/src/node/optimizer/scan.ts used the negative lookahead (?!\s+type) without a word boundary, so any import whose local binding starts with type (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 Bar still correctly fail to match (verified).

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines
  • Read the Pull Request Guidelines
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the issue was, why it was fixed, and how it was fixed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

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 updated imports regex should work test fails without the fix (1 failed, 12 skipped) and passes with it. Full scan.spec.ts: 13/13 pass. oxfmt --check and eslint clean on both files.

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
@github-actions github-actions Bot added the bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR label Sep 19, 2026
@github-actions

Copy link
Copy Markdown
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.

@github-actions github-actions Bot closed this Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot: likely Likely a bot, LLM, or agent. Automatically comments and closes the issue or PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: dep-scan misses imports whose local name starts with "type"

1 participant