fix(parser): parse source imports named type (#28062)

Source imports such as `import source type from "./f.wasm"` were rejected because a shortcut for value imports named `type` skipped the required `from` token.

Remove that shortcut. The ambiguous `import type from "module"` form is already handled before specifier parsing, so source imports now consume their `from` clause normally. The TypeScript `importSource3.ts` fixture added in #28057 covers the regression; the snapshots also record the more precise recovery diagnostic for an invalid deferred import.
This commit is contained in:
camc314 committed 2026-10-22 18:08:55 +00:00
1 parent 83633a7a64
commit af0258d583
3 files changed
+6 -28

No files matched your search

-11
View File
@@ -320,17 +320,6 @@ impl<'a, C: Config> ParserImpl<'a, C> {
_ => return self.unexpected(),
}
}
// If the default specifiers name was `type`, and it was not a type import
// then skip the `from` specifier expect. This is specifically to support an import
// like: `import type from 'source'`
if self.is_ts
&& import_kind == ImportOrExportKind::Value
&& specifiers.len() == 1
&& specifiers[0].name() == "type"
{
return specifiers;
}
} else if self.at(Kind::Star) {
// import * as name from "module-name";
let specifier = self.parse_import_namespace_specifier();
@@ -1,8 +1,8 @@
commit: 5237fd46
parser_typescript Summary:
AST Parsed : 9852/9862 (99.90%)
Positive Passed: 9842/9862 (99.80%)
AST Parsed : 9853/9862 (99.91%)
Positive Passed: 9843/9862 (99.81%)
Negative Passed: 1712/2806 (61.01%)
Expect Syntax Error: tasks/coverage/typescript/tsc/testdata/tests/cases/compiler/FunctionDeclaration3.ts
@@ -2383,15 +2383,6 @@ Expect to Parse: tasks/coverage/typescript/tsc/testdata/tests/cases/conformance/
╰────
help: If you want to use `export =`, remove other `export`s and put all of them to the right hand value of `export =`. If you want to use `export`s, remove `export =` statement.
Fatal error: tasks/coverage/typescript/tsc/testdata/tests/cases/conformance/importSource/importSource3.ts
× Unexpected token
╭─[typescript/tsc/testdata/tests/cases/conformance/importSource/importSource3.ts:1:20]
1 │ import source type from "./f.wasm";
· ────
2 │ const a: AbstractModuleSource = type;
╰────
× TS(1090): 'public' modifier cannot appear on a parameter.
╭─[typescript/tsc/testdata/tests/cases/compiler/ArrowFunctionExpression1.ts:1:10]
@@ -25205,10 +25196,11 @@ Fatal error: tasks/coverage/typescript/tsc/testdata/tests/cases/conformance/impo
· ─────
╰────
× Unexpected token
× Expected `from` but found `*`
╭─[typescript/tsc/testdata/tests/cases/conformance/importDefer/importDeferTypeConflict2.ts:1:19]
1 │ import defer type * as ns1 from "./a";
· ─
· ┬
· ╰── `from` expected
╰────
× The only valid property accesses on import are `import.meta`, `import.source()`, and `import.defer()`
@@ -2,7 +2,7 @@ commit: 5237fd46
semantic_typescript Summary:
AST Parsed : 5721/5721 (100.00%)
Positive Passed: 4156/5721 (72.64%)
Positive Passed: 4157/5721 (72.66%)
semantic Error: tasks/coverage/typescript/tsc/testdata/tests/cases/compiler/acceptableAlias1.ts
Bindings mismatch:
after transform: ScopeId(1): ["N", "X", "_M"]
@@ -23894,9 +23894,6 @@ Unresolved references mismatch:
after transform: []
rebuilt : ["a"]
semantic Error: tasks/coverage/typescript/tsc/testdata/tests/cases/conformance/importSource/importSource3.ts
Unexpected token
semantic Error: tasks/coverage/typescript/tsc/testdata/tests/cases/conformance/inferFromBindingPattern.ts
Bindings mismatch:
after transform: ScopeId(0): ["any", "f1", "f2", "f3", "foo", "isAny", "isStringTuple", "john", "makeTuple", "nufinspecial", "person", "personAgain", "selectJohn", "stringy", "whatever", "x", "x1", "x2", "x3"]