- Notifications
You must be signed in to change notification settings - Fork13.2k
Update type-only import semantics to allow type queries#36092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from23 commits
b40284c2ae9edcdb93eb2a2548c88d3f167b56ad7d0547a3d124dcd62dd3690eefa3359a24cba875349d171e314910dd842a7c47211ba11a0c2899440a2c3c1cbfb81124d746bbbcbd51044c5ca5ca4928571a8a8b4c235be5f50f19b3206File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -44,14 +44,6 @@ namespace ts { | ||
| return (symbol.flags & SymbolFlags.Transient) !== 0; | ||
| } | ||
| const stringWriter = createSingleLineStringWriter(); | ||
| function createSingleLineStringWriter(): EmitTextWriter { | ||
| @@ -1779,6 +1771,31 @@ namespace ts { | ||
| } | ||
| } | ||
| export function isPartOfTypeQuery(node: Node) { | ||
| while (node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.Identifier) { | ||
andrewbranch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| node = node.parent; | ||
| } | ||
| return node.kind === SyntaxKind.TypeQuery; | ||
| } | ||
| export function isPartOfPossiblyValidTypeOrAbstractComputedPropertyName(node: Node) { | ||
| while (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.PropertyAccessExpression) { | ||
| node = node.parent; | ||
| } | ||
| if (node.kind !== SyntaxKind.ComputedPropertyName) { | ||
| return false; | ||
| } | ||
| if (hasModifier(node.parent, ModifierFlags.Abstract)) { | ||
| return true; | ||
| } | ||
| const containerKind = node.parent.parent.kind; | ||
| return containerKind === SyntaxKind.InterfaceDeclaration || containerKind === SyntaxKind.TypeLiteral; | ||
| } | ||
| export function isAbstractDeclarationName(node: Node) { | ||
andrewbranch marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| return isDeclarationName(node) && hasModifier(node, ModifierFlags.Abstract); | ||
| } | ||
| export function isExternalModuleImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration & { moduleReference: ExternalModuleReference } { | ||
| return node.kind === SyntaxKind.ImportEqualsDeclaration && (<ImportEqualsDeclaration>node).moduleReference.kind === SyntaxKind.ExternalModuleReference; | ||
| } | ||
| @@ -2285,6 +2302,19 @@ namespace ts { | ||
| return node.kind === SyntaxKind.ImportDeclaration && !!node.importClause && !!node.importClause.name; | ||
| } | ||
| export function forEachImportClauseDeclaration<T>(node: ImportClause, action: (declaration: ImportClause | NamespaceImport | ImportSpecifier) => T | undefined): T | undefined { | ||
| if (node.name) { | ||
| const result = action(node); | ||
| if (result) return result; | ||
| } | ||
| if (node.namedBindings) { | ||
| const result = isNamespaceImport(node.namedBindings) | ||
| ? action(node.namedBindings) | ||
| : forEach(node.namedBindings.elements, action); | ||
| if (result) return result; | ||
| } | ||
| } | ||
| export function hasQuestionToken(node: Node) { | ||
| if (node) { | ||
| switch (node.kind) { | ||
| @@ -2734,6 +2764,16 @@ namespace ts { | ||
| node.kind === SyntaxKind.PropertyAssignment && isAliasableExpression((node as PropertyAssignment).initializer); | ||
| } | ||
| export function getTypeOnlyCompatibleAliasDeclarationFromName(node: Identifier): TypeOnlyCompatibleAliasDeclaration | undefined { | ||
| switch (node.parent.kind) { | ||
| case SyntaxKind.ImportClause: | ||
| case SyntaxKind.ImportSpecifier: | ||
| case SyntaxKind.NamespaceImport: | ||
| case SyntaxKind.ExportSpecifier: | ||
| return node.parent as TypeOnlyCompatibleAliasDeclaration; | ||
| } | ||
| } | ||
| function isAliasableExpression(e: Expression) { | ||
| return isEntityNameExpression(e) || isClassExpression(e); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //// [tests/cases/conformance/externalModules/typeOnly/ambient.ts] //// | ||
| //// [a.ts] | ||
| export class A { a!: string } | ||
| //// [b.ts] | ||
| import type { A } from './a'; | ||
| declare class B extends A {} | ||
| declare namespace ns { | ||
| class C extends A {} | ||
| } | ||
| //// [a.js] | ||
| "use strict"; | ||
| exports.__esModule = true; | ||
| var A = /** @class */ (function () { | ||
| function A() { | ||
| } | ||
| return A; | ||
| }()); | ||
| exports.A = A; | ||
| //// [b.js] | ||
| "use strict"; | ||
| exports.__esModule = true; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| === /a.ts === | ||
| export class A { a!: string } | ||
| >A : Symbol(A, Decl(a.ts, 0, 0)) | ||
| >a : Symbol(A.a, Decl(a.ts, 0, 16)) | ||
| === /b.ts === | ||
| import type { A } from './a'; | ||
| >A : Symbol(A, Decl(b.ts, 0, 13)) | ||
| declare class B extends A {} | ||
| >B : Symbol(B, Decl(b.ts, 0, 29)) | ||
| >A : Symbol(A, Decl(b.ts, 0, 13)) | ||
| declare namespace ns { | ||
| >ns : Symbol(ns, Decl(b.ts, 1, 28)) | ||
| class C extends A {} | ||
| >C : Symbol(C, Decl(b.ts, 2, 22)) | ||
| >A : Symbol(A, Decl(b.ts, 0, 13)) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| === /a.ts === | ||
| export class A { a!: string } | ||
| >A : A | ||
| >a : string | ||
| === /b.ts === | ||
| import type { A } from './a'; | ||
| >A : A | ||
| declare class B extends A {} | ||
| >B : B | ||
| >A : A | ||
| declare namespace ns { | ||
| >ns : typeof ns | ||
| class C extends A {} | ||
| >C : C | ||
| >A : A | ||
| } | ||
Uh oh!
There was an error while loading.Please reload this page.