Skip to content

fix(parser): detect TS1363 error for type-only imports with mixed default and named/namespace bindings#17712

Merged
camc314 merged 9 commits intomainfrom
copilot/fix-missing-error-imports
Jan 6, 2026
Merged

fix(parser): detect TS1363 error for type-only imports with mixed default and named/namespace bindings#17712
camc314 merged 9 commits intomainfrom
copilot/fix-missing-error-imports

Conversation

Copy link
Contributor

Copilot AI commented Jan 6, 2026

The parser was not detecting import type foo, {} from 'bar'; and import type A, * as NS from 'mod'; as errors. TypeScript's TS1363 requires that type-only imports specify either a default import or named/namespace bindings, but not both—even when the named bindings list is empty.

Changes

  • Parser: Added TS1363 check in parse_import_declaration_specifiers when encountering LCurly or Star token after a type-only default import
  • Module record: Removed redundant TS1363 validation that couldn't detect empty {} cases
  • Error span: Now points at the default specifier instead of the entire import statement

Examples

The following patterns now correctly error with TS1363:

// Empty named bindings
import type foo, {} from 'bar';

// Named bindings with specifiers
import type foo, { bar } from 'baz';

// Namespace import
import type A, * as NS from 'mod';

The parser-level check is comprehensive and catches all cases including empty braces and namespace imports, which weren't being detected previously.

Testing

  • ✅ All parser unit tests pass (54/54)
  • ✅ Added test cases for both empty named bindings and namespace imports
  • ✅ Updated conformance test snapshots
  • ✅ Memory allocation snapshots updated with just allocs
Original prompt

This section details on the original issue you should resolve

<issue_title>parser: missing error for mixed type + non type imports</issue_title>
<issue_description>Missed

import type foo, {  } from 'bar';

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBDAnmApnAZhCAaOBvOOAXwyghDgHIAjAQykoG4g

Originally posted by @fisker in #17609 (comment)

cc @Sysix

we might have to move this check directly into the parser where we know if there's the {}</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

- Add error detection in parse_import_declaration_specifiers for TS1363
- Remove redundant check from module_record.rs (now handled in parser)
- Add test case for empty named imports: import-type-mixed-empty.ts
- Improve error span to point at default specifier instead of whole statement

Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix missing error for mixed type and non-type imports parser: detect TS1363 error for type-only imports with empty named bindings Jan 6, 2026
Copilot AI requested a review from camc314 January 6, 2026 11:07
Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
@github-actions github-actions bot added the A-parser Area - Parser label Jan 6, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 6, 2026

CodSpeed Performance Report

Merging #17712 will not alter performance

Comparing copilot/fix-missing-error-imports (34884e9) with main (2bd2d5a)

Summary

✅ 42 untouched
⏩ 3 skipped1

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@camc314 camc314 changed the title parser: detect TS1363 error for type-only imports with empty named bindings fix(parser): detect TS1363 error for type-only imports with empty named bindings Jan 6, 2026
@github-actions github-actions bot added the C-bug Category - Bug label Jan 6, 2026
@camc314
Copy link
Contributor

camc314 commented Jan 6, 2026

@copilot fix CI

you need to run just allocs as well as all tests

Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 6, 2026

@copilot fix CI

you need to run just allocs as well as all tests

Fixed in 07903b1. Updated allocation snapshots with cargo allocs. All tests pass.

Copilot AI requested a review from camc314 January 6, 2026 11:43
@Sysix
Copy link
Member

Sysix commented Jan 6, 2026

@camc314 thanks for fixing this :) Because the code targets Curly, I am not sure if namespaces will be reported too:
#17609 (comment)

@camc314
Copy link
Contributor

camc314 commented Jan 6, 2026

@copilot import type A, * as NS from 'mod' should also report an error

@camc314 camc314 closed this Jan 6, 2026
@camc314 camc314 reopened this Jan 6, 2026
@camc314
Copy link
Contributor

camc314 commented Jan 6, 2026

@copilot import type A, * as NS from 'mod' should also report an error

fix this

@camc314
Copy link
Contributor

camc314 commented Jan 6, 2026

@camc314 thanks for fixing this :) Because the code targets Curly, I am not sure if namespaces will be reported too: #17609 (comment)

copilot is doing my dirty work 🙂

Also report error for `import type A, * as NS from 'mod'` pattern

Co-authored-by: camc314 <18101008+camc314@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 6, 2026

@copilot import type A, * as NS from 'mod' should also report an error

fix this

Fixed in 84d4ee9. Now reports TS1363 error for import type A, * as NS from 'mod' pattern as well.

Copilot AI changed the title fix(parser): detect TS1363 error for type-only imports with empty named bindings fix(parser): detect TS1363 error for type-only imports with mixed default and named/namespace bindings Jan 6, 2026
Signed-off-by: Cameron <cameron.clark@hey.com>
@github-actions github-actions bot added the A-linter Area - Linter label Jan 6, 2026
Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't bother getting the spans to be correct - maybe point to the whole import statement, as it's a decent amount of work, for not much gain

@camc314 camc314 requested a review from Sysix January 6, 2026 14:29
@camc314 camc314 marked this pull request as ready for review January 6, 2026 14:36
Copilot AI review requested due to automatic review settings January 6, 2026 14:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a parser bug where TypeScript's TS1363 error was not being detected for type-only imports that mix default imports with empty named bindings or namespace imports. The fix moves error detection from the module record builder (which couldn't detect empty {} cases) to the parser itself, enabling comprehensive validation including empty braces.

  • Adds TS1363 validation directly in the parser when encountering { or * after a type-only default import
  • Removes redundant module-record-level validation that couldn't catch empty braces
  • Improves error span to point at the default specifier instead of the entire import statement

Reviewed changes

Copilot reviewed 6 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/oxc_parser/src/js/module.rs Added TS1363 error detection in parse_import_declaration_specifiers when type-only default import is followed by { or * tokens
crates/oxc_parser/src/module_record.rs Removed previous TS1363 validation logic that operated on import entries (couldn't detect empty braces)
tasks/coverage/misc/fail/import-type-mixed-empty.ts New test case for import type foo, {} from 'bar';
tasks/coverage/misc/fail/import-type-mixed-star.ts New test case for import type A, * as NS from 'mod';
tasks/coverage/snapshots/parser_misc.snap Updated snapshot showing correct TS1363 errors with improved spans
tasks/coverage/snapshots/parser_typescript.snap Updated snapshot showing improved error span (pointing at default specifier)
tasks/coverage/snapshots/parser_babel.snap Updated snapshot showing improved error span (pointing at default specifier)
crates/oxc_linter/src/rules/unicorn/require_module_specifiers.rs Commented out test cases that are now invalid TypeScript syntax due to TS1363
crates/oxc_linter/src/rules/import/no_empty_named_blocks.rs Commented out test cases that are now invalid TypeScript syntax due to TS1363
crates/oxc_linter/src/snapshots/unicorn_require_module_specifiers.snap Removed snapshot entries for now-invalid TypeScript patterns
tasks/track_memory_allocations/allocs_parser.snap Updated memory allocation counts (reduced by 8 system allocations for cal.com.tsx)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@camc314 camc314 merged commit 59a6228 into main Jan 6, 2026
28 checks passed
@camc314 camc314 deleted the copilot/fix-missing-error-imports branch January 6, 2026 14:45
Dunqing pushed a commit that referenced this pull request Jan 12, 2026
### 🚀 Features

- 10426af codegen: Print soft space between inline block comments on the
same line (#17799) (camc314)
- 2261e6e semantic: Improve error message to add `#` for private
identifiers (#17779) (Dunqing)

### 🐛 Bug Fixes

- 7422b7e parser/trivia: Correctly mark whether a block comment is on a
newline (#17754) (camc314)
- c32e8d5 codegen: Wrap `TSAsExpression` in parens when used with
in/instanceof operators (#17752) (camc314)
- 5755b2d semantic: Report duplicate private identifier for static and
instance elements (#17591) (camc314)
- 0600df3 isolated_declarations: Only print jsdoc comments (#17748)
(camc314)
- ef7e014 parser: Preserve `@__NO_SIDE_EFFECTS__` annotation with
parenthesized expressions (#17711) (camc314)
- 59a6228 parser: Detect TS1363 error for type-only imports with mixed
default and named/namespace bindings (#17712) (Copilot)

### ⚡ Performance

- 864f1fa semantic: Mark duplicate class element error reporting as cold
(#17746) (camc314)
- 3a452b8 semantic: Use smallvec for storing reference IDs (#17731)
(camchenry)
- d5979dc minifier: Do not allocate when checking to convert `const` to
`let` (#17730) (camchenry)
- 3f4429c parser: Do not re-allocate TS interface heritage (#17692)
(camchenry)

### 📚 Documentation

- 120a27c minifier: Add prettier-ignore for js-in-md part (#17687)
(leaysgur)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Dunqing pushed a commit that referenced this pull request Jan 12, 2026
# Oxlint
### 🚀 Features

- 9699a1b linter/prefer-global-this: Add suggestion (#17873) (Mikhail
Baev)
- 51c2815 linter/no-invalid-regexp: Add labels and help text to flag
diagnostics (#17865) (camchenry)
- 344d77d linter/no-ex-assign: Improve diagnostic with more detail
(#17864) (camchenry)
- 7d280e0 linter: Add fixer for
`unicorn/no-useless-error-capture-stack-trace` rule (#17839) (Mikhail
Baev)
- af1d0e3 linter/prefer-optional-chain: Add rule (#17831) (camc314)
- e3c4108 vscode: Add more supported languages to extension (#17812)
(Alexander Lichter)
- 4a46678 vscode: Activate extension on more languages (#17717) (Sysix)
- b1298fc vscode: Sync formatter with supported files (#17615)
(Alexander Lichter)
- c7f0848 linte/rno-required-prop-with-default: Implement suggestion
(#17747) (Minsu Lee)
- 0e8127e linter/vue: Implement no-lifecycle-after-await (#17701)
(yefan)
- 3567304 linter/vitest: Implement `consistent-each-for` (#17601) (Said
Atrahouch)
- 883e156 linter: Add fixer for `unicorn/no-useless-collection-argument`
rule (#17594) (Mikhail Baev)
- 4eb335c linter/vitest: Implemented prefer-called-once (#17674) (Said
Atrahouch)
- 2bd2d5a linter/vitest: Implement hoisted-apis-on-top (#17658) (Said
Atrahouch)
- cfb2bcc linter/vue: Implement no-arrow-functions-in-watch (#17672)
(yefan)
- a68208a linter/eslint-plugin-vitest: Implements
`prefer-describe-function-title` (#17677) (Said Atrahouch)
- efa029f linter/vitest: Implement no-unneeded-async-expect-function
(#17494) (Minsu Lee)

### 🐛 Bug Fixes

- 49cf66e lsp: Fix workspace worker selection for nested and
similar-named workspaces (#17853) (Copilot)
- 84f4f3c linter: Add doc url for tsgolint diagnostics (#17879) (Sysix)
- 76c903f linter/consistent-indexed-object-style: Skip fixing default
exported interface (#17874) (Copilot)
- 7e87d16 linter/tabindex-no-positive: Improve diagnostic phrasing
(#17849) (connorshea)
- 28f9fba vscode: Fix nested search for binaries (#17832) (Sysix)
- 8ca2cd2 linter: Move jsx-a11y/no-static-element-interactions rule to
nursery. (#17818) (connorshea)
- dc9fdd6 linter/consistent-indexed-object-style: Re-port test cases and
fix some bugs (#17802) (camc314)
- 7bbd880 linter: Update prefer-destructuring rule metadata (#17642)
(Hamir Mahal)
- 3c45185 linter/consistent-indexed-object-style: False positive with
circular reference (#17789) (heygsc)
- bd186b4 vscode: Search for `oxlint` and `oxfmt` in every workspace
directory (#17760) (Sysix)
- 3e0dff7 linter/no-hooks: Add punctuation to diagnostic message
(#17751) (camc314)
- 6ae21f9 linter/prefer-called-once: Avoid panic on trailing comma
(#17735) (Said Atrahouch)
- 32c3901 oxlint: Do not panic on invalid `no-unused-vars` configuration
(#17719) (Sysix)
- 59a6228 parser: Detect TS1363 error for type-only imports with mixed
default and named/namespace bindings (#17712) (Copilot)

### ⚡ Performance

- f87a1e2 linter: Check for giving reserved plugin name before calling
`load_plugin` on napi side (#17841) (Sysix)

### 📚 Documentation

- a2b3a24 linter/no-caller: Improve docs and diagnostic for rule.
(#17890) (connorshea)
- aa48247 linter/no-unsafe-finally: Improve rule docs. (#17891)
(connorshea)
- 1b0bdee linter: Tweak docs for no-useless-constructor and
hoisted-apis-on-top (#17888) (connorshea)
- 8f24fa9 vscode: Remove mention of a built-in server (#17836) (Sysix)
- e81a306 linter: Update the tsconfig flag mention for the import
plugin. (#17778) (connorshea)
# Oxfmt
### 🚀 Features

- 539b350 formatter/sort_imports: Update `NODE_BUILTINS` modules
(#17771) (nilptr)
- 2e03ebf oxfmt/lsp: Use `SourceFormatter` to support non-JS files and
napi features (#17655) (leaysgur)
- 623f7eb oxfmt/sort_package_json: Use `options.sort_scripts` (#17740)
(leaysgur)
- 86c0168 oxfmt/sort_package_json: Handle `oxfmtrc.sort_scripts` option
(#17738) (leaysgur)
- 256636a oxfmt/lsp: Add `.editorconfig` to `get_watcher_patterns`
(#17694) (leaysgur)
- 3f3db39 oxfmt/lsp: Use `ConfigResolver` to align with CLI (#17654)
(leaysgur)

### 🐛 Bug Fixes

- fdd1e1e formatter: Don't wrap parenthesis for type assertion when it's
an declaration of export default (#17878) (Dunqing)
- f0813ad formatter: Incorrect type annotation check for short argument
(#17877) (Dunqing)
- 9e89389 formatter/tailwindcss: Nested class string doesn't respect
`singleQuote: true` (#17838) (Dunqing)
- e2f534c formatter/sort_imports: Handle alignable comment with JsLabels
(#17791) (leaysgur)
- f0cedd4 formatter/tailwindcss: Class name is broken after sorting when
its contains single quotes with `singleQuote: true` (#17790) (Dunqing)
- 1864142 oxfmt/tailwindcss: Bundle `prettier/plugins/*` (#17782)
(leaysgur)
- 3a9d43b oxfmt: Ignore explicit positional path which is ignored by
directory (#17732) (leaysgur)
- 0563217 formatter: Classes will be stripped out when both
`experimentalTailwindcss` and `experimentalSortImports` are enabled
(#17726) (Dunqing)

### ⚡ Performance

- d1bc514 formatter: Optimize RegExpLiteral formatting to avoid heap
allocations (#17797) (Dunqing)

### 📚 Documentation

- 62b7a01 formatter: Clarify `experimentalTailwindcss` configuration
comments (#17898) (Dunqing)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter A-parser Area - Parser C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parser: missing error for mixed type + non type imports

4 participants