Skip to content

Commit a5ad4f1

Browse files
authored
Fix crash by removing getNameFromImportDeclaration in favor of Node.Name() (#2027)
1 parent 4916e22 commit a5ad4f1

File tree

6 files changed

+64
-15
lines changed

6 files changed

+64
-15
lines changed

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13987,7 +13987,7 @@ func (c *Checker) checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(nod
1398713987
// TODO: how to get name for export *?
1398813988
name := "*"
1398913989
if !ast.IsExportDeclaration(typeOnlyDeclaration) {
13990-
name = getNameFromImportDeclaration(typeOnlyDeclaration).Text()
13990+
name = typeOnlyDeclaration.Name().Text()
1399113991
}
1399213992
c.error(decl.ModuleReference, message).AddRelatedInfo(createDiagnosticForNode(typeOnlyDeclaration, relatedMessage, name))
1399313993
}

internal/checker/utilities.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,6 @@ func IsInTypeQuery(node *ast.Node) bool {
189189
}) != nil
190190
}
191191

192-
func getNameFromImportDeclaration(node *ast.Node) *ast.Node {
193-
switch node.Kind {
194-
case ast.KindImportSpecifier:
195-
return node.AsImportSpecifier().Name()
196-
case ast.KindNamespaceImport:
197-
return node.AsNamespaceImport().Name()
198-
case ast.KindImportClause:
199-
return node.AsImportClause().Name()
200-
case ast.KindImportEqualsDeclaration:
201-
return node.AsImportEqualsDeclaration().Name()
202-
}
203-
return nil
204-
}
205-
206192
func nodeCanBeDecorated(useLegacyDecorators bool, node *ast.Node, parent *ast.Node, grandparent *ast.Node) bool {
207193
// private names cannot be used with decorators yet
208194
if useLegacyDecorators && node.Name() != nil && ast.IsPrivateIdentifier(node.Name()) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
t.ts(2,14): error TS1379: An import alias cannot reference a declaration that was exported using 'export type'.
2+
3+
4+
==== t.ts (1 errors) ====
5+
import a = require("./a");
6+
import foo = a.Foo
7+
~~~~~
8+
!!! error TS1379: An import alias cannot reference a declaration that was exported using 'export type'.
9+
!!! related TS1377 a.ts:2:15: 'Foo' was exported here.
10+
11+
==== a.ts (0 errors) ====
12+
type Foo = { x: number }
13+
export type { Foo };
14+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/importAliasTypeOnlyExport.ts] ////
2+
3+
=== t.ts ===
4+
import a = require("./a");
5+
>a : Symbol(a, Decl(t.ts, 0, 0))
6+
7+
import foo = a.Foo
8+
>foo : Symbol(foo, Decl(t.ts, 0, 26))
9+
>a : Symbol(a, Decl(t.ts, 0, 0))
10+
>Foo : Symbol(a.Foo, Decl(a.ts, 1, 13))
11+
12+
=== a.ts ===
13+
type Foo = { x: number }
14+
>Foo : Symbol(Foo, Decl(a.ts, 0, 0))
15+
>x : Symbol(x, Decl(a.ts, 0, 12))
16+
17+
export type { Foo };
18+
>Foo : Symbol(Foo, Decl(a.ts, 1, 13))
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [tests/cases/compiler/importAliasTypeOnlyExport.ts] ////
2+
3+
=== t.ts ===
4+
import a = require("./a");
5+
>a : typeof a
6+
7+
import foo = a.Foo
8+
>foo : any
9+
>a : typeof a
10+
>Foo : foo
11+
12+
=== a.ts ===
13+
type Foo = { x: number }
14+
>Foo : Foo
15+
>x : number
16+
17+
export type { Foo };
18+
>Foo : Foo
19+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @target: esnext
2+
// @module: commonjs
3+
// @noEmit: true
4+
5+
// @filename: t.ts
6+
import a = require("./a");
7+
import foo = a.Foo
8+
9+
// @filename: a.ts
10+
type Foo = { x: number }
11+
export type { Foo };

0 commit comments

Comments
 (0)