Skip to content

Commit 628bf0e

Browse files
authored
fix(56376): import type from from "foo" (#56385)
1 parent 9f15002 commit 628bf0e

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

src/compiler/parser.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -7496,6 +7496,11 @@ namespace Parser {
74967496
function nextTokenIsStringLiteral() {
74977497
return nextToken() === SyntaxKind.StringLiteral;
74987498
}
7499+
7500+
function nextTokenIsFromKeyword() {
7501+
return nextToken() === SyntaxKind.FromKeyword;
7502+
}
7503+
74997504
function nextTokenIsIdentifierOrStringLiteralOnSameLine() {
75007505
nextToken();
75017506
return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token() === SyntaxKind.StringLiteral);
@@ -8328,8 +8333,8 @@ namespace Parser {
83288333

83298334
let isTypeOnly = false;
83308335
if (
8331-
token() !== SyntaxKind.FromKeyword &&
83328336
identifier?.escapedText === "type" &&
8337+
(token() !== SyntaxKind.FromKeyword || isIdentifier() && lookAhead(nextTokenIsFromKeyword)) &&
83338338
(isIdentifier() || tokenAfterImportDefinitelyProducesImportDeclaration())
83348339
) {
83358340
isTypeOnly = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [tests/cases/conformance/externalModules/typeOnly/importDefaultNamedType2.ts] ////
2+
3+
//// [a.ts]
4+
export default class A {}
5+
6+
//// [b.ts]
7+
import type from from './a';
8+
9+
10+
//// [a.js]
11+
"use strict";
12+
Object.defineProperty(exports, "__esModule", { value: true });
13+
var A = /** @class */ (function () {
14+
function A() {
15+
}
16+
return A;
17+
}());
18+
exports.default = A;
19+
//// [b.js]
20+
"use strict";
21+
Object.defineProperty(exports, "__esModule", { value: true });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [tests/cases/conformance/externalModules/typeOnly/importDefaultNamedType2.ts] ////
2+
3+
=== /a.ts ===
4+
export default class A {}
5+
>A : Symbol(A, Decl(a.ts, 0, 0))
6+
7+
=== /b.ts ===
8+
import type from from './a';
9+
>from : Symbol(from, Decl(b.ts, 0, 6))
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//// [tests/cases/conformance/externalModules/typeOnly/importDefaultNamedType2.ts] ////
2+
3+
=== /a.ts ===
4+
export default class A {}
5+
>A : A
6+
7+
=== /b.ts ===
8+
import type from from './a';
9+
>from : from
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @Filename: /a.ts
2+
export default class A {}
3+
4+
// @Filename: /b.ts
5+
import type from from './a';

0 commit comments

Comments
 (0)