fix(56376): import type from from "foo" (#56385)

This commit is contained in:
Oleksandr T 2023-11-14 00:43:24 +02:00 committed by GitHub
parent 9f15002959
commit 628bf0ec85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 1 deletions

View File

@ -7496,6 +7496,11 @@ namespace Parser {
function nextTokenIsStringLiteral() {
return nextToken() === SyntaxKind.StringLiteral;
}
function nextTokenIsFromKeyword() {
return nextToken() === SyntaxKind.FromKeyword;
}
function nextTokenIsIdentifierOrStringLiteralOnSameLine() {
nextToken();
return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token() === SyntaxKind.StringLiteral);
@ -8328,8 +8333,8 @@ namespace Parser {
let isTypeOnly = false;
if (
token() !== SyntaxKind.FromKeyword &&
identifier?.escapedText === "type" &&
(token() !== SyntaxKind.FromKeyword || isIdentifier() && lookAhead(nextTokenIsFromKeyword)) &&
(isIdentifier() || tokenAfterImportDefinitelyProducesImportDeclaration())
) {
isTypeOnly = true;

View File

@ -0,0 +1,21 @@
//// [tests/cases/conformance/externalModules/typeOnly/importDefaultNamedType2.ts] ////
//// [a.ts]
export default class A {}
//// [b.ts]
import type from from './a';
//// [a.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var A = /** @class */ (function () {
function A() {
}
return A;
}());
exports.default = A;
//// [b.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -0,0 +1,10 @@
//// [tests/cases/conformance/externalModules/typeOnly/importDefaultNamedType2.ts] ////
=== /a.ts ===
export default class A {}
>A : Symbol(A, Decl(a.ts, 0, 0))
=== /b.ts ===
import type from from './a';
>from : Symbol(from, Decl(b.ts, 0, 6))

View File

@ -0,0 +1,10 @@
//// [tests/cases/conformance/externalModules/typeOnly/importDefaultNamedType2.ts] ////
=== /a.ts ===
export default class A {}
>A : A
=== /b.ts ===
import type from from './a';
>from : from

View File

@ -0,0 +1,5 @@
// @Filename: /a.ts
export default class A {}
// @Filename: /b.ts
import type from from './a';