From de82ce74772782fa828420258a910e54f8c2cfb2 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 8 Jul 2024 14:26:59 +0200 Subject: [PATCH 1/3] Add support for `import defer` proposal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolò Ribaudo --- src/compiler/checker.ts | 10 +- src/compiler/diagnosticMessages.json | 12 + src/compiler/emitter.ts | 5 + src/compiler/factory/nodeFactory.ts | 9 +- src/compiler/factory/utilities.ts | 3 +- src/compiler/parser.ts | 38 +- src/compiler/scanner.ts | 1 + src/compiler/transformers/declarations.ts | 3 + src/compiler/transformers/jsx.ts | 3 +- .../transformers/module/esnextAnd2015.ts | 3 + src/compiler/transformers/ts.ts | 2 +- src/compiler/types.ts | 18 +- src/compiler/visitorPublic.ts | 1 + .../codefixes/convertToTypeOnlyImport.ts | 7 +- src/services/codefixes/importFixes.ts | 4 + src/services/codefixes/requireInTs.ts | 3 +- src/services/codefixes/splitTypeOnlyImport.ts | 4 +- src/services/organizeImports.ts | 2 +- src/services/refactors/convertImport.ts | 3 +- src/services/refactors/moveToFile.ts | 5 +- src/services/utilities.ts | 3 +- src/testRunner/unittests/transform.ts | 1 + ...ocComments.parsesCorrectly.importTag1.json | 3 +- ...ocComments.parsesCorrectly.importTag2.json | 3 +- ...ocComments.parsesCorrectly.importTag3.json | 3 +- ...ocComments.parsesCorrectly.importTag4.json | 3 +- tests/baselines/reference/api/typescript.d.ts | 425 +++++++++--------- .../reference/exportDeferInvalid.errors.txt | 31 ++ .../baselines/reference/exportDeferInvalid.js | 20 + .../reference/exportDeferInvalid.symbols | 16 + .../reference/exportDeferInvalid.types | 35 ++ .../reference/importDefaultBindingDefer.js | 19 + .../importDefaultBindingDefer.symbols | 19 + .../reference/importDefaultBindingDefer.types | 31 ++ .../importDeferInvalidDefault.errors.txt | 14 + .../reference/importDeferInvalidDefault.js | 19 + .../importDeferInvalidDefault.symbols | 19 + .../reference/importDeferInvalidDefault.types | 31 ++ .../importDeferInvalidNamed.errors.txt | 14 + .../reference/importDeferInvalidNamed.js | 19 + .../reference/importDeferInvalidNamed.symbols | 19 + .../reference/importDeferInvalidNamed.types | 31 ++ .../importDeferMissingModuleESNext.errors.txt | 18 + .../importDeferMissingModuleESNext.js | 25 ++ .../importDeferMissingModuleESNext.symbols | 19 + .../importDeferMissingModuleESNext.types | 35 ++ .../reference/importDeferNamespace.js | 19 + .../reference/importDeferNamespace.symbols | 21 + .../reference/importDeferNamespace.types | 35 ++ .../importDeferTypeConflict1.errors.txt | 28 ++ .../reference/importDeferTypeConflict1.js | 20 + .../importDeferTypeConflict1.symbols | 16 + .../reference/importDeferTypeConflict1.types | 39 ++ .../importDeferTypeConflict2.errors.txt | 31 ++ .../reference/importDeferTypeConflict2.js | 20 + .../importDeferTypeConflict2.symbols | 16 + .../reference/importDeferTypeConflict2.types | 37 ++ .../link-ParseForTypeErrors-file.js.diff | 2 +- .../link-ParseForTypeErrors-file.ts.diff | 2 +- .../link-ParseForTypeInfo-file.js.diff | 2 +- .../link-ParseForTypeInfo-file.ts.diff | 4 +- .../link-ParseNone-file.js.diff | 4 +- .../link-ParseNone-file.ts.diff | 4 +- .../importDefer/exportDeferInvalid.ts | 8 + .../importDefer/importDefaultBindingDefer.ts | 10 + .../importDefer/importDeferInvalidDefault.ts | 11 + .../importDefer/importDeferInvalidNamed.ts | 10 + .../importDeferMissingModuleESNext.ts | 9 + .../importDefer/importDeferNamespace.ts | 10 + .../importDefer/importDeferTypeConflict1.ts | 8 + .../importDefer/importDeferTypeConflict2.ts | 8 + 71 files changed, 1130 insertions(+), 255 deletions(-) create mode 100644 tests/baselines/reference/exportDeferInvalid.errors.txt create mode 100644 tests/baselines/reference/exportDeferInvalid.js create mode 100644 tests/baselines/reference/exportDeferInvalid.symbols create mode 100644 tests/baselines/reference/exportDeferInvalid.types create mode 100644 tests/baselines/reference/importDefaultBindingDefer.js create mode 100644 tests/baselines/reference/importDefaultBindingDefer.symbols create mode 100644 tests/baselines/reference/importDefaultBindingDefer.types create mode 100644 tests/baselines/reference/importDeferInvalidDefault.errors.txt create mode 100644 tests/baselines/reference/importDeferInvalidDefault.js create mode 100644 tests/baselines/reference/importDeferInvalidDefault.symbols create mode 100644 tests/baselines/reference/importDeferInvalidDefault.types create mode 100644 tests/baselines/reference/importDeferInvalidNamed.errors.txt create mode 100644 tests/baselines/reference/importDeferInvalidNamed.js create mode 100644 tests/baselines/reference/importDeferInvalidNamed.symbols create mode 100644 tests/baselines/reference/importDeferInvalidNamed.types create mode 100644 tests/baselines/reference/importDeferMissingModuleESNext.errors.txt create mode 100644 tests/baselines/reference/importDeferMissingModuleESNext.js create mode 100644 tests/baselines/reference/importDeferMissingModuleESNext.symbols create mode 100644 tests/baselines/reference/importDeferMissingModuleESNext.types create mode 100644 tests/baselines/reference/importDeferNamespace.js create mode 100644 tests/baselines/reference/importDeferNamespace.symbols create mode 100644 tests/baselines/reference/importDeferNamespace.types create mode 100644 tests/baselines/reference/importDeferTypeConflict1.errors.txt create mode 100644 tests/baselines/reference/importDeferTypeConflict1.js create mode 100644 tests/baselines/reference/importDeferTypeConflict1.symbols create mode 100644 tests/baselines/reference/importDeferTypeConflict1.types create mode 100644 tests/baselines/reference/importDeferTypeConflict2.errors.txt create mode 100644 tests/baselines/reference/importDeferTypeConflict2.js create mode 100644 tests/baselines/reference/importDeferTypeConflict2.symbols create mode 100644 tests/baselines/reference/importDeferTypeConflict2.types create mode 100644 tests/cases/conformance/importDefer/exportDeferInvalid.ts create mode 100644 tests/cases/conformance/importDefer/importDefaultBindingDefer.ts create mode 100644 tests/cases/conformance/importDefer/importDeferInvalidDefault.ts create mode 100644 tests/cases/conformance/importDefer/importDeferInvalidNamed.ts create mode 100644 tests/cases/conformance/importDefer/importDeferMissingModuleESNext.ts create mode 100644 tests/cases/conformance/importDefer/importDeferNamespace.ts create mode 100644 tests/cases/conformance/importDefer/importDeferTypeConflict1.ts create mode 100644 tests/cases/conformance/importDefer/importDeferTypeConflict2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 565420738d8ce..3dbc8f4c24328 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -432,6 +432,7 @@ import { ImportDeclaration, ImportEqualsDeclaration, ImportOrExportSpecifier, + ImportPhase, ImportSpecifier, ImportTypeNode, IndexedAccessType, @@ -9858,6 +9859,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { propertyName && isIdentifier(propertyName) ? factory.createIdentifier(idText(propertyName)) : undefined, factory.createIdentifier(localName), )]), + ImportPhase.Evaluation, ), factory.createStringLiteral(specifier), /*attributes*/ undefined, @@ -9944,7 +9946,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { addResult( factory.createImportDeclaration( /*modifiers*/ undefined, - factory.createImportClause(isTypeOnly, factory.createIdentifier(localName), /*namedBindings*/ undefined), + factory.createImportClause(isTypeOnly, factory.createIdentifier(localName), /*namedBindings*/ undefined, ImportPhase.Evaluation), specifier, attributes, ), @@ -9959,7 +9961,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { addResult( factory.createImportDeclaration( /*modifiers*/ undefined, - factory.createImportClause(isTypeOnly, /*name*/ undefined, factory.createNamespaceImport(factory.createIdentifier(localName))), + factory.createImportClause(isTypeOnly, /*name*/ undefined, factory.createNamespaceImport(factory.createIdentifier(localName)), ImportPhase.Evaluation), specifier, (node as ImportClause).parent.attributes, ), @@ -9995,6 +9997,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { factory.createIdentifier(localName), ), ]), + ImportPhase.Evaluation, ), specifier, (node as ImportSpecifier).parent.parent.parent.attributes, @@ -52860,6 +52863,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (node.isTypeOnly && node.namedBindings?.kind === SyntaxKind.NamedImports) { return checkGrammarNamedImportsOrExports(node.namedBindings); } + if (node.phase !== ImportPhase.Evaluation && moduleKind !== ModuleKind.ESNext) { + return grammarErrorOnNode(node, Diagnostics.Deferred_imports_are_only_supported_when_the_module_flag_is_set_to_esnext); + } return false; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0b2951d8dee2d..36f7959b5b0ad 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -8433,5 +8433,17 @@ "String literal import and export names are not supported when the '--module' flag is set to 'es2015' or 'es2020'.": { "category": "Error", "code": 18057 + }, + "Default imports aren't allowed for deferred imports.": { + "category": "Error", + "code": 18058 + }, + "Named imports aren't allowed for deferred imports.": { + "category": "Error", + "code": 18059 + }, + "Deferred imports are only supported when the '--module' flag is set to 'esnext'.": { + "category": "Error", + "code": 18060 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 01a96579861f4..ac7872c3cdade 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -182,6 +182,7 @@ import { ImportDeclaration, ImportEqualsDeclaration, ImportOrExportSpecifier, + ImportPhase, ImportSpecifier, ImportTypeNode, IndexedAccessTypeNode, @@ -3689,6 +3690,10 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri emitTokenWithComment(SyntaxKind.TypeKeyword, node.pos, writeKeyword, node); writeSpace(); } + else if (node.phase !== ImportPhase.Evaluation) { + emitTokenWithComment(SyntaxKind.DeferKeyword, node.pos, writeKeyword, node); + writeSpace(); + } emit(node.name); if (node.name && node.namedBindings) { emitTokenWithComment(SyntaxKind.CommaToken, node.name.end, writePunctuation, node); diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 694262eeeb54a..b56ca87b8c005 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -135,6 +135,7 @@ import { ImportClause, ImportDeclaration, ImportEqualsDeclaration, + ImportPhase, ImportSpecifier, ImportTypeAssertionContainer, ImportTypeNode, @@ -4723,11 +4724,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause { + function createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase): ImportClause { const node = createBaseDeclaration(SyntaxKind.ImportClause); node.isTypeOnly = isTypeOnly; node.name = name; node.namedBindings = namedBindings; + node.phase = phase; node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.namedBindings); if (isTypeOnly) { @@ -4738,11 +4740,12 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined) { + function updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase) { return node.isTypeOnly !== isTypeOnly || node.name !== name || node.namedBindings !== namedBindings - ? update(createImportClause(isTypeOnly, name, namedBindings), node) + || node.phase !== phase + ? update(createImportClause(isTypeOnly, name, namedBindings, phase), node) : node; } diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 80df86fd3ceae..12d635b6278c9 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -75,6 +75,7 @@ import { ImportCall, ImportDeclaration, ImportEqualsDeclaration, + ImportPhase, InternalEmitFlags, isAssignmentExpression, isAssignmentOperator, @@ -730,7 +731,7 @@ export function createExternalHelpersImportDeclarationIfNeeded(nodeFactory: Node const externalHelpersImportDeclaration = nodeFactory.createImportDeclaration( /*modifiers*/ undefined, - nodeFactory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, namedBindings), + nodeFactory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, namedBindings, ImportPhase.Evaluation), nodeFactory.createStringLiteral(externalHelpersModuleNameText), /*attributes*/ undefined, ); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 59ad1f030220f..fb500d3f1bd34 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -123,6 +123,7 @@ import { ImportDeclaration, ImportEqualsDeclaration, ImportOrExportSpecifier, + ImportPhase, ImportSpecifier, ImportTypeAssertionContainer, ImportTypeNode, @@ -7190,6 +7191,7 @@ namespace Parser { // could be legal, it would add complexity for very little gain. case SyntaxKind.InterfaceKeyword: case SyntaxKind.TypeKeyword: + case SyntaxKind.DeferKeyword: return nextTokenIsIdentifierOnSameLine(); case SyntaxKind.ModuleKeyword: case SyntaxKind.NamespaceKeyword: @@ -7221,7 +7223,7 @@ namespace Parser { case SyntaxKind.ImportKeyword: nextToken(); - return token() === SyntaxKind.StringLiteral || token() === SyntaxKind.AsteriskToken || + return token() === SyntaxKind.DeferKeyword || token() === SyntaxKind.StringLiteral || token() === SyntaxKind.AsteriskToken || token() === SyntaxKind.OpenBraceToken || tokenIsIdentifierOrKeyword(token()); case SyntaxKind.ExportKeyword: let currentToken = nextToken(); @@ -7295,6 +7297,7 @@ namespace Parser { case SyntaxKind.NamespaceKeyword: case SyntaxKind.TypeKeyword: case SyntaxKind.GlobalKeyword: + case SyntaxKind.DeferKeyword: // When these don't start a declaration, they're an identifier in an expression statement return true; @@ -8366,6 +8369,7 @@ namespace Parser { } let isTypeOnly = false; + let phase = ImportPhase.Evaluation; if ( identifier?.escapedText === "type" && (token() !== SyntaxKind.FromKeyword || isIdentifier() && lookAhead(nextTokenIsFromKeywordOrEqualsToken)) && @@ -8374,12 +8378,20 @@ namespace Parser { isTypeOnly = true; identifier = isIdentifier() ? parseIdentifier() : undefined; } + else if (identifier?.escapedText === "defer" && token() !== SyntaxKind.FromKeyword) { + phase = ImportPhase.Defer; + identifier = undefined; + if (isIdentifier()) { + parseErrorAtCurrentToken(Diagnostics.Default_imports_aren_t_allowed_for_deferred_imports); + identifier = parseIdentifier(); + } + } - if (identifier && !tokenAfterImportedIdentifierDefinitelyProducesImportDeclaration()) { + if (identifier && !tokenAfterImportedIdentifierDefinitelyProducesImportDeclaration() && phase !== ImportPhase.Defer) { return parseImportEqualsDeclaration(pos, hasJSDoc, modifiers, identifier, isTypeOnly); } - const importClause = tryParseImportClause(identifier, afterImportPos, isTypeOnly); + const importClause = tryParseImportClause(identifier, afterImportPos, isTypeOnly, /*skipJsDocLeadingAsterisks*/ undefined, phase); const moduleSpecifier = parseModuleSpecifier(); const attributes = tryParseImportAttributes(); @@ -8388,7 +8400,7 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function tryParseImportClause(identifier: Identifier | undefined, pos: number, isTypeOnly: boolean, skipJsDocLeadingAsterisks = false) { + function tryParseImportClause(identifier: Identifier | undefined, pos: number, isTypeOnly: boolean, skipJsDocLeadingAsterisks = false, phase: ImportPhase) { // ImportDeclaration: // import ImportClause from ModuleSpecifier ; // import ModuleSpecifier; @@ -8398,7 +8410,7 @@ namespace Parser { token() === SyntaxKind.AsteriskToken || // import * token() === SyntaxKind.OpenBraceToken // import { ) { - importClause = parseImportClause(identifier, pos, isTypeOnly, skipJsDocLeadingAsterisks); + importClause = parseImportClause(identifier, pos, isTypeOnly, skipJsDocLeadingAsterisks, phase); parseExpected(SyntaxKind.FromKeyword); } return importClause; @@ -8464,7 +8476,7 @@ namespace Parser { return finished; } - function parseImportClause(identifier: Identifier | undefined, pos: number, isTypeOnly: boolean, skipJsDocLeadingAsterisks: boolean) { + function parseImportClause(identifier: Identifier | undefined, pos: number, isTypeOnly: boolean, skipJsDocLeadingAsterisks: boolean, phase: ImportPhase) { // ImportClause: // ImportedDefaultBinding // NameSpaceImport @@ -8480,11 +8492,19 @@ namespace Parser { parseOptional(SyntaxKind.CommaToken) ) { if (skipJsDocLeadingAsterisks) scanner.setSkipJsDocLeadingAsterisks(true); - namedBindings = token() === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImportsOrExports(SyntaxKind.NamedImports); + if (token() === SyntaxKind.AsteriskToken) { + namedBindings = parseNamespaceImport(); + } + else { + if (phase === ImportPhase.Defer) { + parseErrorAtCurrentToken(Diagnostics.Named_imports_aren_t_allowed_for_deferred_imports); + } + namedBindings = parseNamedImportsOrExports(SyntaxKind.NamedImports); + } if (skipJsDocLeadingAsterisks) scanner.setSkipJsDocLeadingAsterisks(false); } - return finishNode(factory.createImportClause(isTypeOnly, identifier, namedBindings), pos); + return finishNode(factory.createImportClause(isTypeOnly, identifier, namedBindings, phase), pos); } function parseModuleReference() { @@ -9518,7 +9538,7 @@ namespace Parser { identifier = parseIdentifier(); } - const importClause = tryParseImportClause(identifier, afterImportTagPos, /*isTypeOnly*/ true, /*skipJsDocLeadingAsterisks*/ true); + const importClause = tryParseImportClause(identifier, afterImportTagPos, /*isTypeOnly*/ true, /*skipJsDocLeadingAsterisks*/ true, ImportPhase.Evaluation); const moduleSpecifier = parseModuleSpecifier(); const attributes = tryParseImportAttributes(); diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 50e827c17bd24..db53e197fecef 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -203,6 +203,7 @@ export const textToKeywordObj: MapLike = { true: SyntaxKind.TrueKeyword, try: SyntaxKind.TryKeyword, type: SyntaxKind.TypeKeyword, + defer: SyntaxKind.DeferKeyword, typeof: SyntaxKind.TypeOfKeyword, undefined: SyntaxKind.UndefinedKeyword, unique: SyntaxKind.UniqueKeyword, diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 7c41bcccc3e7a..c24aa1c2d1e7e 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -889,6 +889,7 @@ export function transformDeclarations(context: TransformationContext): Transform decl.importClause.isTypeOnly, visibleDefaultBinding, /*namedBindings*/ undefined, + decl.importClause.phase, ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), tryGetResolutionModeOverride(decl.attributes), @@ -905,6 +906,7 @@ export function transformDeclarations(context: TransformationContext): Transform decl.importClause.isTypeOnly, visibleDefaultBinding, namedBindings, + decl.importClause.phase, ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), tryGetResolutionModeOverride(decl.attributes), @@ -921,6 +923,7 @@ export function transformDeclarations(context: TransformationContext): Transform decl.importClause.isTypeOnly, visibleDefaultBinding, bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined, + decl.importClause.phase, ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), tryGetResolutionModeOverride(decl.attributes), diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index bcb0cbf8ee2cc..eb7d05dfbb417 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -22,6 +22,7 @@ import { getSemanticJsxChildren, Identifier, idText, + ImportPhase, ImportSpecifier, insertStatementAfterCustomPrologue, isExpression, @@ -172,7 +173,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B for (const [importSource, importSpecifiersMap] of arrayFrom(currentFileState.utilizedImplicitRuntimeImports.entries())) { if (isExternalModule(node)) { // Add `import` statement - const importStatement = factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamedImports(arrayFrom(importSpecifiersMap.values()))), factory.createStringLiteral(importSource), /*attributes*/ undefined); + const importStatement = factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamedImports(arrayFrom(importSpecifiersMap.values())), ImportPhase.Evaluation), factory.createStringLiteral(importSource), /*attributes*/ undefined); setParentRecursive(importStatement, /*incremental*/ false); statements = insertStatementAfterCustomPrologue(statements.slice(), importStatement); } diff --git a/src/compiler/transformers/module/esnextAnd2015.ts b/src/compiler/transformers/module/esnextAnd2015.ts index 2f2d23c468089..c31881d176fa2 100644 --- a/src/compiler/transformers/module/esnextAnd2015.ts +++ b/src/compiler/transformers/module/esnextAnd2015.ts @@ -28,6 +28,7 @@ import { idText, ImportDeclaration, ImportEqualsDeclaration, + ImportPhase, insertStatementsAfterCustomPrologue, isExportNamespaceAsDefaultDeclaration, isExternalModule, @@ -224,6 +225,7 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S factory.createNamedImports([ factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier("createRequire"), createRequireName), ]), + ImportPhase.Evaluation, ), factory.createStringLiteral("module"), /*attributes*/ undefined, @@ -356,6 +358,7 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S factory.createNamespaceImport( synthName, ), + ImportPhase.Evaluation, ), updatedModuleSpecifier!, node.attributes, diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 75656cf5aefab..dd04662f99a05 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2286,7 +2286,7 @@ export function transformTypeScript(context: TransformationContext): Transformer // Elide the import clause if we elide both its name and its named bindings. const name = shouldEmitAliasDeclaration(node) ? node.name : undefined; const namedBindings = visitNode(node.namedBindings, visitNamedImportBindings, isNamedImportBindings); - return (name || namedBindings) ? factory.updateImportClause(node, /*isTypeOnly*/ false, name, namedBindings) : undefined; + return (name || namedBindings) ? factory.updateImportClause(node, /*isTypeOnly*/ false, name, namedBindings, node.phase) : undefined; } /** diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 46ff57009e7fa..d6520e51eae9c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -221,7 +221,8 @@ export const enum SyntaxKind { GlobalKeyword, BigIntKeyword, OverrideKeyword, - OfKeyword, // LastKeyword and LastToken and LastContextualKeyword + OfKeyword, + DeferKeyword, // LastKeyword and LastToken and LastContextualKeyword // Parse tree nodes @@ -461,7 +462,7 @@ export const enum SyntaxKind { FirstReservedWord = BreakKeyword, LastReservedWord = WithKeyword, FirstKeyword = BreakKeyword, - LastKeyword = OfKeyword, + LastKeyword = DeferKeyword, FirstFutureReservedWord = ImplementsKeyword, LastFutureReservedWord = YieldKeyword, FirstTypeNode = TypePredicate, @@ -486,7 +487,7 @@ export const enum SyntaxKind { FirstJSDocTagNode = JSDocTag, LastJSDocTagNode = JSDocImportTag, /** @internal */ FirstContextualKeyword = AbstractKeyword, - /** @internal */ LastContextualKeyword = OfKeyword, + /** @internal */ LastContextualKeyword = DeferKeyword, } export type TriviaSyntaxKind = @@ -598,6 +599,7 @@ export type KeywordSyntaxKind = | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword + | SyntaxKind.DeferKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword @@ -3713,6 +3715,12 @@ export interface ImportClause extends NamedDeclaration { readonly isTypeOnly: boolean; readonly name?: Identifier; // Default binding readonly namedBindings?: NamedImportBindings; + readonly phase: ImportPhase; +} + +export const enum ImportPhase { + Evaluation, + Defer, } /** @deprecated */ @@ -9023,8 +9031,8 @@ export interface NodeFactory { updateImportEqualsDeclaration(node: ImportEqualsDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; createImportDeclaration(modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes?: ImportAttributes): ImportDeclaration; updateImportDeclaration(node: ImportDeclaration, modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes: ImportAttributes | undefined): ImportDeclaration; - createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; - updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase): ImportClause; + updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase): ImportClause; /** @deprecated */ createAssertClause(elements: NodeArray, multiLine?: boolean): AssertClause; /** @deprecated */ updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause; /** @deprecated */ createAssertEntry(name: AssertionKey, value: Expression): AssertEntry; diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index dbd49379e5750..60affb83d9b6e 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -1552,6 +1552,7 @@ const visitEachChildTable: VisitEachChildTable = { node.isTypeOnly, nodeVisitor(node.name, visitor, isIdentifier), nodeVisitor(node.namedBindings, visitor, isNamedImportBindings), + node.phase, ); }, diff --git a/src/services/codefixes/convertToTypeOnlyImport.ts b/src/services/codefixes/convertToTypeOnlyImport.ts index 3fdc81f3e4bbb..503b64d791537 100644 --- a/src/services/codefixes/convertToTypeOnlyImport.ts +++ b/src/services/codefixes/convertToTypeOnlyImport.ts @@ -13,6 +13,7 @@ import { getTokenAtPosition, ImportClause, ImportDeclaration, + ImportPhase, ImportSpecifier, isImportDeclaration, isImportSpecifier, @@ -125,13 +126,13 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, de changes.replaceNodeWithNodes(sourceFile, declaration, [ factory.createImportDeclaration( getSynthesizedDeepClones(declaration.modifiers, /*includeTrivia*/ true), - factory.createImportClause(/*isTypeOnly*/ true, getSynthesizedDeepClone(importClause.name, /*includeTrivia*/ true), /*namedBindings*/ undefined), + factory.createImportClause(/*isTypeOnly*/ true, getSynthesizedDeepClone(importClause.name, /*includeTrivia*/ true), /*namedBindings*/ undefined, ImportPhase.Evaluation), getSynthesizedDeepClone(declaration.moduleSpecifier, /*includeTrivia*/ true), getSynthesizedDeepClone(declaration.attributes, /*includeTrivia*/ true), ), factory.createImportDeclaration( getSynthesizedDeepClones(declaration.modifiers, /*includeTrivia*/ true), - factory.createImportClause(/*isTypeOnly*/ true, /*name*/ undefined, getSynthesizedDeepClone(importClause.namedBindings, /*includeTrivia*/ true)), + factory.createImportClause(/*isTypeOnly*/ true, /*name*/ undefined, getSynthesizedDeepClone(importClause.namedBindings, /*includeTrivia*/ true), ImportPhase.Evaluation), getSynthesizedDeepClone(declaration.moduleSpecifier, /*includeTrivia*/ true), getSynthesizedDeepClone(declaration.attributes, /*includeTrivia*/ true), ), @@ -144,7 +145,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, de sameMap(importClause.namedBindings.elements, e => factory.updateImportSpecifier(e, /*isTypeOnly*/ false, e.propertyName, e.name)), ) : importClause.namedBindings; - const importDeclaration = factory.updateImportDeclaration(declaration, declaration.modifiers, factory.updateImportClause(importClause, /*isTypeOnly*/ true, importClause.name, newNamedBindings), declaration.moduleSpecifier, declaration.attributes); + const importDeclaration = factory.updateImportDeclaration(declaration, declaration.modifiers, factory.updateImportClause(importClause, /*isTypeOnly*/ true, importClause.name, newNamedBindings, ImportPhase.Evaluation), declaration.moduleSpecifier, declaration.attributes); changes.replaceNode(sourceFile, declaration, importDeclaration); } } diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index a1537c8bde5b7..8b2e9994d6211 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -77,6 +77,7 @@ import { ImportEqualsDeclaration, importFromModuleSpecifier, ImportKind, + ImportPhase, ImportSpecifier, insertImports, InternalSymbolName, @@ -625,6 +626,7 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog declaration.importClause!.isTypeOnly, declaration.importClause!.name, /*namedBindings*/ undefined, + declaration.importClause!.phase, ), ); } @@ -725,6 +727,7 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog (d.importClause.namedBindings as NamedImports).elements.filter(e => verbatimImports.has(e)), ) : undefined, + d.importClause.phase, ), d.moduleSpecifier, d.attributes, @@ -2082,6 +2085,7 @@ function getNewImports( shouldUseTypeOnly(namespaceLikeImport, preferences), /*name*/ undefined, factory.createNamespaceImport(factory.createIdentifier(namespaceLikeImport.name)), + ImportPhase.Evaluation, ), quotedModuleSpecifier, /*attributes*/ undefined, diff --git a/src/services/codefixes/requireInTs.ts b/src/services/codefixes/requireInTs.ts index 500a88aad8999..19101ec8eed45 100644 --- a/src/services/codefixes/requireInTs.ts +++ b/src/services/codefixes/requireInTs.ts @@ -13,6 +13,7 @@ import { getQuotePreference, getTokenAtPosition, Identifier, + ImportPhase, ImportSpecifier, isIdentifier, isNoSubstitutionTemplateLiteral, @@ -61,7 +62,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, in statement, defaultImportName && !allowSyntheticDefaults ? factory.createImportEqualsDeclaration(/*modifiers*/ undefined, /*isTypeOnly*/ false, defaultImportName, factory.createExternalModuleReference(moduleSpecifier)) - : factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports), moduleSpecifier, /*attributes*/ undefined), + : factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports, ImportPhase.Evaluation), moduleSpecifier, /*attributes*/ undefined), ); } diff --git a/src/services/codefixes/splitTypeOnlyImport.ts b/src/services/codefixes/splitTypeOnlyImport.ts index 967d6fc837c10..39b8cc5a68a90 100644 --- a/src/services/codefixes/splitTypeOnlyImport.ts +++ b/src/services/codefixes/splitTypeOnlyImport.ts @@ -51,7 +51,7 @@ function splitTypeOnlyImport(changes: textChanges.ChangeTracker, importDeclarati factory.updateImportDeclaration( importDeclaration, importDeclaration.modifiers, - factory.updateImportClause(importClause, importClause.isTypeOnly, importClause.name, /*namedBindings*/ undefined), + factory.updateImportClause(importClause, importClause.isTypeOnly, importClause.name, /*namedBindings*/ undefined, importClause.phase), importDeclaration.moduleSpecifier, importDeclaration.attributes, ), @@ -62,7 +62,7 @@ function splitTypeOnlyImport(changes: textChanges.ChangeTracker, importDeclarati importDeclaration, factory.createImportDeclaration( /*modifiers*/ undefined, - factory.updateImportClause(importClause, importClause.isTypeOnly, /*name*/ undefined, importClause.namedBindings), + factory.updateImportClause(importClause, importClause.isTypeOnly, /*name*/ undefined, importClause.namedBindings, importClause.phase), importDeclaration.moduleSpecifier, importDeclaration.attributes, ), diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index 1508ba7672d5e..6a65d615e2651 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -639,7 +639,7 @@ function updateImportDeclarationAndClause( return factory.updateImportDeclaration( importDeclaration, importDeclaration.modifiers, - factory.updateImportClause(importDeclaration.importClause!, importDeclaration.importClause!.isTypeOnly, name, namedBindings), // TODO: GH#18217 + factory.updateImportClause(importDeclaration.importClause!, importDeclaration.importClause!.isTypeOnly, name, namedBindings, importDeclaration.importClause!.phase), // TODO: GH#18217 importDeclaration.moduleSpecifier, importDeclaration.attributes, ); diff --git a/src/services/refactors/convertImport.ts b/src/services/refactors/convertImport.ts index 1b21d2d5beb02..9dc1626514fd0 100644 --- a/src/services/refactors/convertImport.ts +++ b/src/services/refactors/convertImport.ts @@ -20,6 +20,7 @@ import { ImportClause, ImportDeclaration, ImportKind, + ImportPhase, ImportSpecifier, isExportSpecifier, isImportDeclaration, @@ -290,5 +291,5 @@ function createImport(node: ImportDeclaration, defaultImportName: Identifier | u } function createImportClause(defaultImportName: Identifier | undefined, elements: readonly ImportSpecifier[] | undefined) { - return factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, elements && elements.length ? factory.createNamedImports(elements) : undefined); + return factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, elements && elements.length ? factory.createNamedImports(elements) : undefined, ImportPhase.Evaluation); } diff --git a/src/services/refactors/moveToFile.ts b/src/services/refactors/moveToFile.ts index 6245fe4903dcc..93c207d794b02 100644 --- a/src/services/refactors/moveToFile.ts +++ b/src/services/refactors/moveToFile.ts @@ -74,6 +74,7 @@ import { ImportDeclaration, ImportEqualsDeclaration, importFromModuleSpecifier, + ImportPhase, InterfaceDeclaration, isArrayLiteralExpression, isBinaryExpression, @@ -423,7 +424,7 @@ function updateNamespaceLikeImportNode(node: SupportedImport, newNamespaceName: case SyntaxKind.ImportDeclaration: return factory.createImportDeclaration( /*modifiers*/ undefined, - factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamespaceImport(newNamespaceId)), + factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamespaceImport(newNamespaceId), ImportPhase.Evaluation), newModuleString, /*attributes*/ undefined, ); @@ -645,7 +646,7 @@ function filterImport(i: SupportedImport, moduleSpecifier: StringLiteralLike, ke const defaultImport = clause.name && keep(clause.name) ? clause.name : undefined; const namedBindings = clause.namedBindings && filterNamedBindings(clause.namedBindings, keep); return defaultImport || namedBindings - ? factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(clause.isTypeOnly, defaultImport, namedBindings), getSynthesizedDeepClone(moduleSpecifier), /*attributes*/ undefined) + ? factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(clause.isTypeOnly, defaultImport, namedBindings, ImportPhase.Evaluation), getSynthesizedDeepClone(moduleSpecifier), /*attributes*/ undefined) : undefined; } case SyntaxKind.ImportEqualsDeclaration: diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 0f7b99250111f..557e6151abc9c 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -129,6 +129,7 @@ import { IfStatement, ImportClause, ImportDeclaration, + ImportPhase, ImportSpecifier, ImportTypeNode, indexOfNode, @@ -2497,7 +2498,7 @@ export function makeImport(defaultImport: Identifier | undefined, namedImports: return factory.createImportDeclaration( /*modifiers*/ undefined, defaultImport || namedImports - ? factory.createImportClause(!!isTypeOnly, defaultImport, namedImports && namedImports.length ? factory.createNamedImports(namedImports) : undefined) + ? factory.createImportClause(!!isTypeOnly, defaultImport, namedImports && namedImports.length ? factory.createNamedImports(namedImports) : undefined, ImportPhase.Evaluation) : undefined, typeof moduleSpecifier === "string" ? makeStringLiteral(moduleSpecifier, quotePreference) : moduleSpecifier, /*attributes*/ undefined, diff --git a/src/testRunner/unittests/transform.ts b/src/testRunner/unittests/transform.ts index 4c4f84790ea63..8f63e6d8f2428 100644 --- a/src/testRunner/unittests/transform.ts +++ b/src/testRunner/unittests/transform.ts @@ -345,6 +345,7 @@ describe("unittests:: TransformAPI", () => { /*isTypeOnly*/ false, /*name*/ undefined, ts.factory.createNamespaceImport(ts.factory.createIdentifier("i0")), + ts.ImportPhase.Evaluation, ), /*moduleSpecifier*/ ts.factory.createStringLiteral("./comp1"), /*attributes*/ undefined, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json index 817598cb1e86e..6b9c81b520c26 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json @@ -32,7 +32,8 @@ "end": 19, "transformFlags": 0, "escapedText": "foo" - } + }, + "phase": 0 }, "moduleSpecifier": { "kind": "StringLiteral", diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json index d11fa4eb24320..6579049c80981 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json @@ -54,7 +54,8 @@ "hasTrailingComma": false, "transformFlags": 0 } - } + }, + "phase": 0 }, "moduleSpecifier": { "kind": "StringLiteral", diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json index a34c07e9983a9..42e2fedc99dc9 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json @@ -39,7 +39,8 @@ "transformFlags": 0, "escapedText": "types" } - } + }, + "phase": 0 }, "moduleSpecifier": { "kind": "StringLiteral", diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json index e60e392ffb8eb..1e366241b5e29 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json @@ -40,7 +40,8 @@ "transformFlags": 0, "escapedText": "types" } - } + }, + "phase": 0 }, "moduleSpecifier": { "kind": "StringLiteral", diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 11a12e97d4b2e..8dd5bf169975f 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3837,203 +3837,204 @@ declare namespace ts { BigIntKeyword = 163, OverrideKeyword = 164, OfKeyword = 165, - QualifiedName = 166, - ComputedPropertyName = 167, - TypeParameter = 168, - Parameter = 169, - Decorator = 170, - PropertySignature = 171, - PropertyDeclaration = 172, - MethodSignature = 173, - MethodDeclaration = 174, - ClassStaticBlockDeclaration = 175, - Constructor = 176, - GetAccessor = 177, - SetAccessor = 178, - CallSignature = 179, - ConstructSignature = 180, - IndexSignature = 181, - TypePredicate = 182, - TypeReference = 183, - FunctionType = 184, - ConstructorType = 185, - TypeQuery = 186, - TypeLiteral = 187, - ArrayType = 188, - TupleType = 189, - OptionalType = 190, - RestType = 191, - UnionType = 192, - IntersectionType = 193, - ConditionalType = 194, - InferType = 195, - ParenthesizedType = 196, - ThisType = 197, - TypeOperator = 198, - IndexedAccessType = 199, - MappedType = 200, - LiteralType = 201, - NamedTupleMember = 202, - TemplateLiteralType = 203, - TemplateLiteralTypeSpan = 204, - ImportType = 205, - ObjectBindingPattern = 206, - ArrayBindingPattern = 207, - BindingElement = 208, - ArrayLiteralExpression = 209, - ObjectLiteralExpression = 210, - PropertyAccessExpression = 211, - ElementAccessExpression = 212, - CallExpression = 213, - NewExpression = 214, - TaggedTemplateExpression = 215, - TypeAssertionExpression = 216, - ParenthesizedExpression = 217, - FunctionExpression = 218, - ArrowFunction = 219, - DeleteExpression = 220, - TypeOfExpression = 221, - VoidExpression = 222, - AwaitExpression = 223, - PrefixUnaryExpression = 224, - PostfixUnaryExpression = 225, - BinaryExpression = 226, - ConditionalExpression = 227, - TemplateExpression = 228, - YieldExpression = 229, - SpreadElement = 230, - ClassExpression = 231, - OmittedExpression = 232, - ExpressionWithTypeArguments = 233, - AsExpression = 234, - NonNullExpression = 235, - MetaProperty = 236, - SyntheticExpression = 237, - SatisfiesExpression = 238, - TemplateSpan = 239, - SemicolonClassElement = 240, - Block = 241, - EmptyStatement = 242, - VariableStatement = 243, - ExpressionStatement = 244, - IfStatement = 245, - DoStatement = 246, - WhileStatement = 247, - ForStatement = 248, - ForInStatement = 249, - ForOfStatement = 250, - ContinueStatement = 251, - BreakStatement = 252, - ReturnStatement = 253, - WithStatement = 254, - SwitchStatement = 255, - LabeledStatement = 256, - ThrowStatement = 257, - TryStatement = 258, - DebuggerStatement = 259, - VariableDeclaration = 260, - VariableDeclarationList = 261, - FunctionDeclaration = 262, - ClassDeclaration = 263, - InterfaceDeclaration = 264, - TypeAliasDeclaration = 265, - EnumDeclaration = 266, - ModuleDeclaration = 267, - ModuleBlock = 268, - CaseBlock = 269, - NamespaceExportDeclaration = 270, - ImportEqualsDeclaration = 271, - ImportDeclaration = 272, - ImportClause = 273, - NamespaceImport = 274, - NamedImports = 275, - ImportSpecifier = 276, - ExportAssignment = 277, - ExportDeclaration = 278, - NamedExports = 279, - NamespaceExport = 280, - ExportSpecifier = 281, - MissingDeclaration = 282, - ExternalModuleReference = 283, - JsxElement = 284, - JsxSelfClosingElement = 285, - JsxOpeningElement = 286, - JsxClosingElement = 287, - JsxFragment = 288, - JsxOpeningFragment = 289, - JsxClosingFragment = 290, - JsxAttribute = 291, - JsxAttributes = 292, - JsxSpreadAttribute = 293, - JsxExpression = 294, - JsxNamespacedName = 295, - CaseClause = 296, - DefaultClause = 297, - HeritageClause = 298, - CatchClause = 299, - ImportAttributes = 300, - ImportAttribute = 301, - /** @deprecated */ AssertClause = 300, - /** @deprecated */ AssertEntry = 301, - /** @deprecated */ ImportTypeAssertionContainer = 302, - PropertyAssignment = 303, - ShorthandPropertyAssignment = 304, - SpreadAssignment = 305, - EnumMember = 306, - SourceFile = 307, - Bundle = 308, - JSDocTypeExpression = 309, - JSDocNameReference = 310, - JSDocMemberName = 311, - JSDocAllType = 312, - JSDocUnknownType = 313, - JSDocNullableType = 314, - JSDocNonNullableType = 315, - JSDocOptionalType = 316, - JSDocFunctionType = 317, - JSDocVariadicType = 318, - JSDocNamepathType = 319, - JSDoc = 320, + DeferKeyword = 166, + QualifiedName = 167, + ComputedPropertyName = 168, + TypeParameter = 169, + Parameter = 170, + Decorator = 171, + PropertySignature = 172, + PropertyDeclaration = 173, + MethodSignature = 174, + MethodDeclaration = 175, + ClassStaticBlockDeclaration = 176, + Constructor = 177, + GetAccessor = 178, + SetAccessor = 179, + CallSignature = 180, + ConstructSignature = 181, + IndexSignature = 182, + TypePredicate = 183, + TypeReference = 184, + FunctionType = 185, + ConstructorType = 186, + TypeQuery = 187, + TypeLiteral = 188, + ArrayType = 189, + TupleType = 190, + OptionalType = 191, + RestType = 192, + UnionType = 193, + IntersectionType = 194, + ConditionalType = 195, + InferType = 196, + ParenthesizedType = 197, + ThisType = 198, + TypeOperator = 199, + IndexedAccessType = 200, + MappedType = 201, + LiteralType = 202, + NamedTupleMember = 203, + TemplateLiteralType = 204, + TemplateLiteralTypeSpan = 205, + ImportType = 206, + ObjectBindingPattern = 207, + ArrayBindingPattern = 208, + BindingElement = 209, + ArrayLiteralExpression = 210, + ObjectLiteralExpression = 211, + PropertyAccessExpression = 212, + ElementAccessExpression = 213, + CallExpression = 214, + NewExpression = 215, + TaggedTemplateExpression = 216, + TypeAssertionExpression = 217, + ParenthesizedExpression = 218, + FunctionExpression = 219, + ArrowFunction = 220, + DeleteExpression = 221, + TypeOfExpression = 222, + VoidExpression = 223, + AwaitExpression = 224, + PrefixUnaryExpression = 225, + PostfixUnaryExpression = 226, + BinaryExpression = 227, + ConditionalExpression = 228, + TemplateExpression = 229, + YieldExpression = 230, + SpreadElement = 231, + ClassExpression = 232, + OmittedExpression = 233, + ExpressionWithTypeArguments = 234, + AsExpression = 235, + NonNullExpression = 236, + MetaProperty = 237, + SyntheticExpression = 238, + SatisfiesExpression = 239, + TemplateSpan = 240, + SemicolonClassElement = 241, + Block = 242, + EmptyStatement = 243, + VariableStatement = 244, + ExpressionStatement = 245, + IfStatement = 246, + DoStatement = 247, + WhileStatement = 248, + ForStatement = 249, + ForInStatement = 250, + ForOfStatement = 251, + ContinueStatement = 252, + BreakStatement = 253, + ReturnStatement = 254, + WithStatement = 255, + SwitchStatement = 256, + LabeledStatement = 257, + ThrowStatement = 258, + TryStatement = 259, + DebuggerStatement = 260, + VariableDeclaration = 261, + VariableDeclarationList = 262, + FunctionDeclaration = 263, + ClassDeclaration = 264, + InterfaceDeclaration = 265, + TypeAliasDeclaration = 266, + EnumDeclaration = 267, + ModuleDeclaration = 268, + ModuleBlock = 269, + CaseBlock = 270, + NamespaceExportDeclaration = 271, + ImportEqualsDeclaration = 272, + ImportDeclaration = 273, + ImportClause = 274, + NamespaceImport = 275, + NamedImports = 276, + ImportSpecifier = 277, + ExportAssignment = 278, + ExportDeclaration = 279, + NamedExports = 280, + NamespaceExport = 281, + ExportSpecifier = 282, + MissingDeclaration = 283, + ExternalModuleReference = 284, + JsxElement = 285, + JsxSelfClosingElement = 286, + JsxOpeningElement = 287, + JsxClosingElement = 288, + JsxFragment = 289, + JsxOpeningFragment = 290, + JsxClosingFragment = 291, + JsxAttribute = 292, + JsxAttributes = 293, + JsxSpreadAttribute = 294, + JsxExpression = 295, + JsxNamespacedName = 296, + CaseClause = 297, + DefaultClause = 298, + HeritageClause = 299, + CatchClause = 300, + ImportAttributes = 301, + ImportAttribute = 302, + /** @deprecated */ AssertClause = 301, + /** @deprecated */ AssertEntry = 302, + /** @deprecated */ ImportTypeAssertionContainer = 303, + PropertyAssignment = 304, + ShorthandPropertyAssignment = 305, + SpreadAssignment = 306, + EnumMember = 307, + SourceFile = 308, + Bundle = 309, + JSDocTypeExpression = 310, + JSDocNameReference = 311, + JSDocMemberName = 312, + JSDocAllType = 313, + JSDocUnknownType = 314, + JSDocNullableType = 315, + JSDocNonNullableType = 316, + JSDocOptionalType = 317, + JSDocFunctionType = 318, + JSDocVariadicType = 319, + JSDocNamepathType = 320, + JSDoc = 321, /** @deprecated Use SyntaxKind.JSDoc */ - JSDocComment = 320, - JSDocText = 321, - JSDocTypeLiteral = 322, - JSDocSignature = 323, - JSDocLink = 324, - JSDocLinkCode = 325, - JSDocLinkPlain = 326, - JSDocTag = 327, - JSDocAugmentsTag = 328, - JSDocImplementsTag = 329, - JSDocAuthorTag = 330, - JSDocDeprecatedTag = 331, - JSDocClassTag = 332, - JSDocPublicTag = 333, - JSDocPrivateTag = 334, - JSDocProtectedTag = 335, - JSDocReadonlyTag = 336, - JSDocOverrideTag = 337, - JSDocCallbackTag = 338, - JSDocOverloadTag = 339, - JSDocEnumTag = 340, - JSDocParameterTag = 341, - JSDocReturnTag = 342, - JSDocThisTag = 343, - JSDocTypeTag = 344, - JSDocTemplateTag = 345, - JSDocTypedefTag = 346, - JSDocSeeTag = 347, - JSDocPropertyTag = 348, - JSDocThrowsTag = 349, - JSDocSatisfiesTag = 350, - JSDocImportTag = 351, - SyntaxList = 352, - NotEmittedStatement = 353, - NotEmittedTypeElement = 354, - PartiallyEmittedExpression = 355, - CommaListExpression = 356, - SyntheticReferenceExpression = 357, - Count = 358, + JSDocComment = 321, + JSDocText = 322, + JSDocTypeLiteral = 323, + JSDocSignature = 324, + JSDocLink = 325, + JSDocLinkCode = 326, + JSDocLinkPlain = 327, + JSDocTag = 328, + JSDocAugmentsTag = 329, + JSDocImplementsTag = 330, + JSDocAuthorTag = 331, + JSDocDeprecatedTag = 332, + JSDocClassTag = 333, + JSDocPublicTag = 334, + JSDocPrivateTag = 335, + JSDocProtectedTag = 336, + JSDocReadonlyTag = 337, + JSDocOverrideTag = 338, + JSDocCallbackTag = 339, + JSDocOverloadTag = 340, + JSDocEnumTag = 341, + JSDocParameterTag = 342, + JSDocReturnTag = 343, + JSDocThisTag = 344, + JSDocTypeTag = 345, + JSDocTemplateTag = 346, + JSDocTypedefTag = 347, + JSDocSeeTag = 348, + JSDocPropertyTag = 349, + JSDocThrowsTag = 350, + JSDocSatisfiesTag = 351, + JSDocImportTag = 352, + SyntaxList = 353, + NotEmittedStatement = 354, + NotEmittedTypeElement = 355, + PartiallyEmittedExpression = 356, + CommaListExpression = 357, + SyntheticReferenceExpression = 358, + Count = 359, FirstAssignment = 64, LastAssignment = 79, FirstCompoundAssignment = 65, @@ -4041,15 +4042,15 @@ declare namespace ts { FirstReservedWord = 83, LastReservedWord = 118, FirstKeyword = 83, - LastKeyword = 165, + LastKeyword = 166, FirstFutureReservedWord = 119, LastFutureReservedWord = 127, - FirstTypeNode = 182, - LastTypeNode = 205, + FirstTypeNode = 183, + LastTypeNode = 206, FirstPunctuation = 19, LastPunctuation = 79, FirstToken = 0, - LastToken = 165, + LastToken = 166, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 9, @@ -4058,13 +4059,13 @@ declare namespace ts { LastTemplateToken = 18, FirstBinaryOperator = 30, LastBinaryOperator = 79, - FirstStatement = 243, - LastStatement = 259, - FirstNode = 166, - FirstJSDocNode = 309, - LastJSDocNode = 351, - FirstJSDocTagNode = 327, - LastJSDocTagNode = 351, + FirstStatement = 244, + LastStatement = 260, + FirstNode = 167, + FirstJSDocNode = 310, + LastJSDocNode = 352, + FirstJSDocTagNode = 328, + LastJSDocTagNode = 352, } type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; @@ -4152,6 +4153,7 @@ declare namespace ts { | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword + | SyntaxKind.DeferKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword @@ -5516,6 +5518,11 @@ declare namespace ts { readonly isTypeOnly: boolean; readonly name?: Identifier; readonly namedBindings?: NamedImportBindings; + readonly phase: ImportPhase; + } + enum ImportPhase { + Evaluation = 0, + Defer = 1, } /** @deprecated */ type AssertionKey = ImportAttributeName; @@ -7711,8 +7718,8 @@ declare namespace ts { updateImportEqualsDeclaration(node: ImportEqualsDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; createImportDeclaration(modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes?: ImportAttributes): ImportDeclaration; updateImportDeclaration(node: ImportDeclaration, modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes: ImportAttributes | undefined): ImportDeclaration; - createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; - updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase): ImportClause; + updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase): ImportClause; /** @deprecated */ createAssertClause(elements: NodeArray, multiLine?: boolean): AssertClause; /** @deprecated */ updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause; /** @deprecated */ createAssertEntry(name: AssertionKey, value: Expression): AssertEntry; diff --git a/tests/baselines/reference/exportDeferInvalid.errors.txt b/tests/baselines/reference/exportDeferInvalid.errors.txt new file mode 100644 index 0000000000000..21055164ce6d4 --- /dev/null +++ b/tests/baselines/reference/exportDeferInvalid.errors.txt @@ -0,0 +1,31 @@ +b.ts(1,1): error TS1128: Declaration or statement expected. +b.ts(1,8): error TS2304: Cannot find name 'defer'. +b.ts(1,16): error TS2304: Cannot find name 'as'. +b.ts(1,19): error TS1005: ';' expected. +b.ts(1,19): error TS2304: Cannot find name 'ns'. +b.ts(1,22): error TS1434: Unexpected keyword or identifier. +b.ts(1,22): error TS2304: Cannot find name 'from'. + + +==== a.ts (0 errors) ==== + export function foo() { + console.log("foo from a"); + } + +==== b.ts (7 errors) ==== + export defer * as ns from "a"; + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + ~~~~~ +!!! error TS2304: Cannot find name 'defer'. + ~~ +!!! error TS2304: Cannot find name 'as'. + ~~ +!!! error TS1005: ';' expected. + ~~ +!!! error TS2304: Cannot find name 'ns'. + ~~~~ +!!! error TS1434: Unexpected keyword or identifier. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + \ No newline at end of file diff --git a/tests/baselines/reference/exportDeferInvalid.js b/tests/baselines/reference/exportDeferInvalid.js new file mode 100644 index 0000000000000..8b2e752a22b66 --- /dev/null +++ b/tests/baselines/reference/exportDeferInvalid.js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importDefer/exportDeferInvalid.ts] //// + +//// [a.ts] +export function foo() { + console.log("foo from a"); +} + +//// [b.ts] +export defer * as ns from "a"; + + +//// [a.js] +export function foo() { + console.log("foo from a"); +} +//// [b.js] +defer * as; +ns; +from; +"a"; diff --git a/tests/baselines/reference/exportDeferInvalid.symbols b/tests/baselines/reference/exportDeferInvalid.symbols new file mode 100644 index 0000000000000..ccc6ae0d9a914 --- /dev/null +++ b/tests/baselines/reference/exportDeferInvalid.symbols @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/importDefer/exportDeferInvalid.ts] //// + +=== a.ts === +export function foo() { +>foo : Symbol(foo, Decl(a.ts, 0, 0)) + + console.log("foo from a"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +} + +=== b.ts === + +export defer * as ns from "a"; + diff --git a/tests/baselines/reference/exportDeferInvalid.types b/tests/baselines/reference/exportDeferInvalid.types new file mode 100644 index 0000000000000..e10299d8b12e7 --- /dev/null +++ b/tests/baselines/reference/exportDeferInvalid.types @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/importDefer/exportDeferInvalid.ts] //// + +=== a.ts === +export function foo() { +>foo : () => void +> : ^^^^^^^^^^ + + console.log("foo from a"); +>console.log("foo from a") : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>"foo from a" : "foo from a" +> : ^^^^^^^^^^^^ +} + +=== b.ts === +export defer * as ns from "a"; +>defer * as : number +> : ^^^^^^ +>defer : any +> : ^^^ +>as : any +> : ^^^ +>ns : any +> : ^^^ +>from : any +> : ^^^ +>"a" : "a" +> : ^^^ + diff --git a/tests/baselines/reference/importDefaultBindingDefer.js b/tests/baselines/reference/importDefaultBindingDefer.js new file mode 100644 index 0000000000000..aa2e7c26211db --- /dev/null +++ b/tests/baselines/reference/importDefaultBindingDefer.js @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importDefer/importDefaultBindingDefer.ts] //// + +//// [a.ts] +export default function defer() { + console.log("defer from a"); +} + +//// [b.ts] +import defer from "a"; + +defer(); + +//// [a.js] +export default function defer() { + console.log("defer from a"); +} +//// [b.js] +import defer from "a"; +defer(); diff --git a/tests/baselines/reference/importDefaultBindingDefer.symbols b/tests/baselines/reference/importDefaultBindingDefer.symbols new file mode 100644 index 0000000000000..9c233fcf0bda0 --- /dev/null +++ b/tests/baselines/reference/importDefaultBindingDefer.symbols @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importDefer/importDefaultBindingDefer.ts] //// + +=== a.ts === +export default function defer() { +>defer : Symbol(defer, Decl(a.ts, 0, 0)) + + console.log("defer from a"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +} + +=== b.ts === +import defer from "a"; +>defer : Symbol(defer, Decl(b.ts, 0, 6)) + +defer(); +>defer : Symbol(defer, Decl(b.ts, 0, 6)) + diff --git a/tests/baselines/reference/importDefaultBindingDefer.types b/tests/baselines/reference/importDefaultBindingDefer.types new file mode 100644 index 0000000000000..f647f0914868d --- /dev/null +++ b/tests/baselines/reference/importDefaultBindingDefer.types @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/importDefer/importDefaultBindingDefer.ts] //// + +=== a.ts === +export default function defer() { +>defer : () => void +> : ^^^^^^^^^^ + + console.log("defer from a"); +>console.log("defer from a") : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>"defer from a" : "defer from a" +> : ^^^^^^^^^^^^^^ +} + +=== b.ts === +import defer from "a"; +>defer : () => void +> : ^^^^^^^^^^ + +defer(); +>defer() : void +> : ^^^^ +>defer : () => void +> : ^^^^^^^^^^ + diff --git a/tests/baselines/reference/importDeferInvalidDefault.errors.txt b/tests/baselines/reference/importDeferInvalidDefault.errors.txt new file mode 100644 index 0000000000000..f0460162e2025 --- /dev/null +++ b/tests/baselines/reference/importDeferInvalidDefault.errors.txt @@ -0,0 +1,14 @@ +b.ts(1,14): error TS18058: Default imports aren't allowed for deferred imports. + + +==== a.ts (0 errors) ==== + export default function foo() { + console.log("foo from a"); + } + +==== b.ts (1 errors) ==== + import defer foo from "a"; + ~~~ +!!! error TS18058: Default imports aren't allowed for deferred imports. + + foo(); \ No newline at end of file diff --git a/tests/baselines/reference/importDeferInvalidDefault.js b/tests/baselines/reference/importDeferInvalidDefault.js new file mode 100644 index 0000000000000..e0f3491c6329f --- /dev/null +++ b/tests/baselines/reference/importDeferInvalidDefault.js @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importDefer/importDeferInvalidDefault.ts] //// + +//// [a.ts] +export default function foo() { + console.log("foo from a"); +} + +//// [b.ts] +import defer foo from "a"; + +foo(); + +//// [a.js] +export default function foo() { + console.log("foo from a"); +} +//// [b.js] +import defer foo from "a"; +foo(); diff --git a/tests/baselines/reference/importDeferInvalidDefault.symbols b/tests/baselines/reference/importDeferInvalidDefault.symbols new file mode 100644 index 0000000000000..dd548fc59340a --- /dev/null +++ b/tests/baselines/reference/importDeferInvalidDefault.symbols @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importDefer/importDeferInvalidDefault.ts] //// + +=== a.ts === +export default function foo() { +>foo : Symbol(foo, Decl(a.ts, 0, 0)) + + console.log("foo from a"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +} + +=== b.ts === +import defer foo from "a"; +>foo : Symbol(foo, Decl(b.ts, 0, 6)) + +foo(); +>foo : Symbol(foo, Decl(b.ts, 0, 6)) + diff --git a/tests/baselines/reference/importDeferInvalidDefault.types b/tests/baselines/reference/importDeferInvalidDefault.types new file mode 100644 index 0000000000000..ae22c6fd8d417 --- /dev/null +++ b/tests/baselines/reference/importDeferInvalidDefault.types @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/importDefer/importDeferInvalidDefault.ts] //// + +=== a.ts === +export default function foo() { +>foo : () => void +> : ^^^^^^^^^^ + + console.log("foo from a"); +>console.log("foo from a") : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>"foo from a" : "foo from a" +> : ^^^^^^^^^^^^ +} + +=== b.ts === +import defer foo from "a"; +>foo : () => void +> : ^^^^^^^^^^ + +foo(); +>foo() : void +> : ^^^^ +>foo : () => void +> : ^^^^^^^^^^ + diff --git a/tests/baselines/reference/importDeferInvalidNamed.errors.txt b/tests/baselines/reference/importDeferInvalidNamed.errors.txt new file mode 100644 index 0000000000000..7a72a9edd77b5 --- /dev/null +++ b/tests/baselines/reference/importDeferInvalidNamed.errors.txt @@ -0,0 +1,14 @@ +b.ts(1,14): error TS18059: Named imports aren't allowed for deferred imports. + + +==== a.ts (0 errors) ==== + export function foo() { + console.log("foo from a"); + } + +==== b.ts (1 errors) ==== + import defer { foo } from "a"; + ~ +!!! error TS18059: Named imports aren't allowed for deferred imports. + + foo(); \ No newline at end of file diff --git a/tests/baselines/reference/importDeferInvalidNamed.js b/tests/baselines/reference/importDeferInvalidNamed.js new file mode 100644 index 0000000000000..8f92f52fa0ee5 --- /dev/null +++ b/tests/baselines/reference/importDeferInvalidNamed.js @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importDefer/importDeferInvalidNamed.ts] //// + +//// [a.ts] +export function foo() { + console.log("foo from a"); +} + +//// [b.ts] +import defer { foo } from "a"; + +foo(); + +//// [a.js] +export function foo() { + console.log("foo from a"); +} +//// [b.js] +import defer { foo } from "a"; +foo(); diff --git a/tests/baselines/reference/importDeferInvalidNamed.symbols b/tests/baselines/reference/importDeferInvalidNamed.symbols new file mode 100644 index 0000000000000..77f3959cd7e06 --- /dev/null +++ b/tests/baselines/reference/importDeferInvalidNamed.symbols @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importDefer/importDeferInvalidNamed.ts] //// + +=== a.ts === +export function foo() { +>foo : Symbol(foo, Decl(a.ts, 0, 0)) + + console.log("foo from a"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +} + +=== b.ts === +import defer { foo } from "a"; +>foo : Symbol(foo, Decl(b.ts, 0, 14)) + +foo(); +>foo : Symbol(foo, Decl(b.ts, 0, 14)) + diff --git a/tests/baselines/reference/importDeferInvalidNamed.types b/tests/baselines/reference/importDeferInvalidNamed.types new file mode 100644 index 0000000000000..5568523603e08 --- /dev/null +++ b/tests/baselines/reference/importDeferInvalidNamed.types @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/importDefer/importDeferInvalidNamed.ts] //// + +=== a.ts === +export function foo() { +>foo : () => void +> : ^^^^^^^^^^ + + console.log("foo from a"); +>console.log("foo from a") : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>"foo from a" : "foo from a" +> : ^^^^^^^^^^^^ +} + +=== b.ts === +import defer { foo } from "a"; +>foo : () => void +> : ^^^^^^^^^^ + +foo(); +>foo() : void +> : ^^^^ +>foo : () => void +> : ^^^^^^^^^^ + diff --git a/tests/baselines/reference/importDeferMissingModuleESNext.errors.txt b/tests/baselines/reference/importDeferMissingModuleESNext.errors.txt new file mode 100644 index 0000000000000..f931b4e67d328 --- /dev/null +++ b/tests/baselines/reference/importDeferMissingModuleESNext.errors.txt @@ -0,0 +1,18 @@ +b.ts(1,8): error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext'. +b.ts(1,28): error TS2307: Cannot find module 'a' or its corresponding type declarations. + + +==== a.ts (0 errors) ==== + export function foo() { + console.log("foo from a"); + } + +==== b.ts (2 errors) ==== + import defer * as aNs from "a"; + ~~~~~~~~~~~~~~ +!!! error TS18060: Deferred imports are only supported when the '--module' flag is set to 'esnext'. + ~~~ +!!! error TS2307: Cannot find module 'a' or its corresponding type declarations. + + aNs.foo(); + \ No newline at end of file diff --git a/tests/baselines/reference/importDeferMissingModuleESNext.js b/tests/baselines/reference/importDeferMissingModuleESNext.js new file mode 100644 index 0000000000000..60f2c2d9c6d6a --- /dev/null +++ b/tests/baselines/reference/importDeferMissingModuleESNext.js @@ -0,0 +1,25 @@ +//// [tests/cases/conformance/importDefer/importDeferMissingModuleESNext.ts] //// + +//// [a.ts] +export function foo() { + console.log("foo from a"); +} + +//// [b.ts] +import defer * as aNs from "a"; + +aNs.foo(); + + +//// [a.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.foo = foo; +function foo() { + console.log("foo from a"); +} +//// [b.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var aNs = require("a"); +aNs.foo(); diff --git a/tests/baselines/reference/importDeferMissingModuleESNext.symbols b/tests/baselines/reference/importDeferMissingModuleESNext.symbols new file mode 100644 index 0000000000000..e556f00387bda --- /dev/null +++ b/tests/baselines/reference/importDeferMissingModuleESNext.symbols @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importDefer/importDeferMissingModuleESNext.ts] //// + +=== a.ts === +export function foo() { +>foo : Symbol(foo, Decl(a.ts, 0, 0)) + + console.log("foo from a"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +} + +=== b.ts === +import defer * as aNs from "a"; +>aNs : Symbol(aNs, Decl(b.ts, 0, 12)) + +aNs.foo(); +>aNs : Symbol(aNs, Decl(b.ts, 0, 12)) + diff --git a/tests/baselines/reference/importDeferMissingModuleESNext.types b/tests/baselines/reference/importDeferMissingModuleESNext.types new file mode 100644 index 0000000000000..d75d7fd356307 --- /dev/null +++ b/tests/baselines/reference/importDeferMissingModuleESNext.types @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/importDefer/importDeferMissingModuleESNext.ts] //// + +=== a.ts === +export function foo() { +>foo : () => void +> : ^^^^^^^^^^ + + console.log("foo from a"); +>console.log("foo from a") : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>"foo from a" : "foo from a" +> : ^^^^^^^^^^^^ +} + +=== b.ts === +import defer * as aNs from "a"; +>aNs : any +> : ^^^ + +aNs.foo(); +>aNs.foo() : any +> : ^^^ +>aNs.foo : any +> : ^^^ +>aNs : any +> : ^^^ +>foo : any +> : ^^^ + diff --git a/tests/baselines/reference/importDeferNamespace.js b/tests/baselines/reference/importDeferNamespace.js new file mode 100644 index 0000000000000..80edab5e81278 --- /dev/null +++ b/tests/baselines/reference/importDeferNamespace.js @@ -0,0 +1,19 @@ +//// [tests/cases/conformance/importDefer/importDeferNamespace.ts] //// + +//// [a.ts] +export function foo() { + console.log("foo from a"); +} + +//// [b.ts] +import defer * as aNs from "a"; + +aNs.foo(); + +//// [a.js] +export function foo() { + console.log("foo from a"); +} +//// [b.js] +import defer * as aNs from "a"; +aNs.foo(); diff --git a/tests/baselines/reference/importDeferNamespace.symbols b/tests/baselines/reference/importDeferNamespace.symbols new file mode 100644 index 0000000000000..115690adecd50 --- /dev/null +++ b/tests/baselines/reference/importDeferNamespace.symbols @@ -0,0 +1,21 @@ +//// [tests/cases/conformance/importDefer/importDeferNamespace.ts] //// + +=== a.ts === +export function foo() { +>foo : Symbol(foo, Decl(a.ts, 0, 0)) + + console.log("foo from a"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +} + +=== b.ts === +import defer * as aNs from "a"; +>aNs : Symbol(aNs, Decl(b.ts, 0, 12)) + +aNs.foo(); +>aNs.foo : Symbol(aNs.foo, Decl(a.ts, 0, 0)) +>aNs : Symbol(aNs, Decl(b.ts, 0, 12)) +>foo : Symbol(aNs.foo, Decl(a.ts, 0, 0)) + diff --git a/tests/baselines/reference/importDeferNamespace.types b/tests/baselines/reference/importDeferNamespace.types new file mode 100644 index 0000000000000..eda2b889f3fd2 --- /dev/null +++ b/tests/baselines/reference/importDeferNamespace.types @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/importDefer/importDeferNamespace.ts] //// + +=== a.ts === +export function foo() { +>foo : () => void +> : ^^^^^^^^^^ + + console.log("foo from a"); +>console.log("foo from a") : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>"foo from a" : "foo from a" +> : ^^^^^^^^^^^^ +} + +=== b.ts === +import defer * as aNs from "a"; +>aNs : typeof aNs +> : ^^^^^^^^^^ + +aNs.foo(); +>aNs.foo() : void +> : ^^^^ +>aNs.foo : () => void +> : ^^^^^^^^^^ +>aNs : typeof aNs +> : ^^^^^^^^^^ +>foo : () => void +> : ^^^^^^^^^^ + diff --git a/tests/baselines/reference/importDeferTypeConflict1.errors.txt b/tests/baselines/reference/importDeferTypeConflict1.errors.txt new file mode 100644 index 0000000000000..138cfa68e9b36 --- /dev/null +++ b/tests/baselines/reference/importDeferTypeConflict1.errors.txt @@ -0,0 +1,28 @@ +b.ts(1,19): error TS1005: '=' expected. +b.ts(1,21): error TS2304: Cannot find name 'as'. +b.ts(1,24): error TS1005: ';' expected. +b.ts(1,24): error TS2304: Cannot find name 'ns1'. +b.ts(1,28): error TS1434: Unexpected keyword or identifier. +b.ts(1,28): error TS2304: Cannot find name 'from'. + + +==== a.ts (0 errors) ==== + export function foo() { + console.log("foo from a"); + } + +==== b.ts (6 errors) ==== + import type defer * as ns1 from "a"; + ~ +!!! error TS1005: '=' expected. + ~~ +!!! error TS2304: Cannot find name 'as'. + ~~~ +!!! error TS1005: ';' expected. + ~~~ +!!! error TS2304: Cannot find name 'ns1'. + ~~~~ +!!! error TS1434: Unexpected keyword or identifier. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + \ No newline at end of file diff --git a/tests/baselines/reference/importDeferTypeConflict1.js b/tests/baselines/reference/importDeferTypeConflict1.js new file mode 100644 index 0000000000000..0577f6a08cb7c --- /dev/null +++ b/tests/baselines/reference/importDeferTypeConflict1.js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importDefer/importDeferTypeConflict1.ts] //// + +//// [a.ts] +export function foo() { + console.log("foo from a"); +} + +//// [b.ts] +import type defer * as ns1 from "a"; + + +//// [a.js] +export function foo() { + console.log("foo from a"); +} +//// [b.js] + * as; +ns1; +from; +"a"; diff --git a/tests/baselines/reference/importDeferTypeConflict1.symbols b/tests/baselines/reference/importDeferTypeConflict1.symbols new file mode 100644 index 0000000000000..961367f241e5b --- /dev/null +++ b/tests/baselines/reference/importDeferTypeConflict1.symbols @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/importDefer/importDeferTypeConflict1.ts] //// + +=== a.ts === +export function foo() { +>foo : Symbol(foo, Decl(a.ts, 0, 0)) + + console.log("foo from a"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +} + +=== b.ts === +import type defer * as ns1 from "a"; +>defer : Symbol(defer, Decl(b.ts, 0, 0)) + diff --git a/tests/baselines/reference/importDeferTypeConflict1.types b/tests/baselines/reference/importDeferTypeConflict1.types new file mode 100644 index 0000000000000..ea2a7ef944685 --- /dev/null +++ b/tests/baselines/reference/importDeferTypeConflict1.types @@ -0,0 +1,39 @@ +//// [tests/cases/conformance/importDefer/importDeferTypeConflict1.ts] //// + +=== a.ts === +export function foo() { +>foo : () => void +> : ^^^^^^^^^^ + + console.log("foo from a"); +>console.log("foo from a") : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>"foo from a" : "foo from a" +> : ^^^^^^^^^^^^ +} + +=== b.ts === +import type defer * as ns1 from "a"; +>defer : any +> : ^^^ +> : any +> : ^^^ +>* as : number +> : ^^^^^^ +> : any +> : ^^^ +>as : any +> : ^^^ +>ns1 : any +> : ^^^ +>from : any +> : ^^^ +>"a" : "a" +> : ^^^ + diff --git a/tests/baselines/reference/importDeferTypeConflict2.errors.txt b/tests/baselines/reference/importDeferTypeConflict2.errors.txt new file mode 100644 index 0000000000000..ae646749a1748 --- /dev/null +++ b/tests/baselines/reference/importDeferTypeConflict2.errors.txt @@ -0,0 +1,31 @@ +b.ts(1,14): error TS18058: Default imports aren't allowed for deferred imports. +b.ts(1,19): error TS1005: 'from' expected. +b.ts(1,19): error TS1141: String literal expected. +b.ts(1,24): error TS1005: ';' expected. +b.ts(1,24): error TS2304: Cannot find name 'ns1'. +b.ts(1,28): error TS1434: Unexpected keyword or identifier. +b.ts(1,28): error TS2304: Cannot find name 'from'. + + +==== a.ts (0 errors) ==== + export function foo() { + console.log("foo from a"); + } + +==== b.ts (7 errors) ==== + import defer type * as ns1 from "a"; + ~~~~ +!!! error TS18058: Default imports aren't allowed for deferred imports. + ~ +!!! error TS1005: 'from' expected. + ~~~~ +!!! error TS1141: String literal expected. + ~~~ +!!! error TS1005: ';' expected. + ~~~ +!!! error TS2304: Cannot find name 'ns1'. + ~~~~ +!!! error TS1434: Unexpected keyword or identifier. + ~~~~ +!!! error TS2304: Cannot find name 'from'. + \ No newline at end of file diff --git a/tests/baselines/reference/importDeferTypeConflict2.js b/tests/baselines/reference/importDeferTypeConflict2.js new file mode 100644 index 0000000000000..1c06d70469687 --- /dev/null +++ b/tests/baselines/reference/importDeferTypeConflict2.js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/importDefer/importDeferTypeConflict2.ts] //// + +//// [a.ts] +export function foo() { + console.log("foo from a"); +} + +//// [b.ts] +import defer type * as ns1 from "a"; + + +//// [a.js] +export function foo() { + console.log("foo from a"); +} +//// [b.js] +ns1; +from; +"a"; +export {}; diff --git a/tests/baselines/reference/importDeferTypeConflict2.symbols b/tests/baselines/reference/importDeferTypeConflict2.symbols new file mode 100644 index 0000000000000..ea867e3cfdc51 --- /dev/null +++ b/tests/baselines/reference/importDeferTypeConflict2.symbols @@ -0,0 +1,16 @@ +//// [tests/cases/conformance/importDefer/importDeferTypeConflict2.ts] //// + +=== a.ts === +export function foo() { +>foo : Symbol(foo, Decl(a.ts, 0, 0)) + + console.log("foo from a"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +} + +=== b.ts === +import defer type * as ns1 from "a"; +>type : Symbol(type, Decl(b.ts, 0, 6)) + diff --git a/tests/baselines/reference/importDeferTypeConflict2.types b/tests/baselines/reference/importDeferTypeConflict2.types new file mode 100644 index 0000000000000..bbcc915ad31bc --- /dev/null +++ b/tests/baselines/reference/importDeferTypeConflict2.types @@ -0,0 +1,37 @@ +//// [tests/cases/conformance/importDefer/importDeferTypeConflict2.ts] //// + +=== a.ts === +export function foo() { +>foo : () => void +> : ^^^^^^^^^^ + + console.log("foo from a"); +>console.log("foo from a") : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>"foo from a" : "foo from a" +> : ^^^^^^^^^^^^ +} + +=== b.ts === +import defer type * as ns1 from "a"; +>type : any +> : ^^^ +>* as : number +> : ^^^^^^ +> : any +> : ^^^ +>as : any +> : ^^^ +>ns1 : any +> : ^^^ +>from : any +> : ^^^ +>"a" : "a" +> : ^^^ + diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.js.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.js.diff index e85d3dac9427d..f9a6bdcff52dc 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeErrors -@@ -214,7 +214,7 @@ +@@ -216,7 +216,7 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.ts.diff index d54b75b0af7d6..93dd08f83a579 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeErrors-file.ts.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeErrors -@@ -214,6 +214,6 @@ +@@ -216,6 +216,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.js.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.js.diff index 894c809d38c7e..8e9b6490c335e 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeInfo -@@ -214,7 +214,7 @@ +@@ -216,7 +216,7 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff index 0c2bff5a4677e..5a838cf8451b4 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseForTypeInfo-file.ts.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseForTypeInfo -@@ -88,52 +88,9 @@ +@@ -89,52 +89,9 @@ "pos": 69, "end": 69, "hasTrailingComma": false, @@ -55,7 +55,7 @@ "length": 2, "pos": 0, "end": 70, -@@ -214,6 +171,6 @@ +@@ -216,6 +173,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff index 3a1028bb08254..8d86662fa7f32 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.js.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseNone -@@ -88,52 +88,9 @@ +@@ -89,52 +89,9 @@ "pos": 69, "end": 69, "hasTrailingComma": false, @@ -55,7 +55,7 @@ "length": 2, "pos": 0, "end": 70, -@@ -214,7 +171,6 @@ +@@ -216,7 +173,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff index 41135dc2495ba..c2edc9324a2a0 100644 --- a/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff +++ b/tests/baselines/reference/skipJSDocParsing/link-ParseNone-file.ts.diff @@ -1,7 +1,7 @@ =================================================================== --- default +++ ParseNone -@@ -88,52 +88,9 @@ +@@ -89,52 +89,9 @@ "pos": 69, "end": 69, "hasTrailingComma": false, @@ -55,7 +55,7 @@ "length": 2, "pos": 0, "end": 70, -@@ -214,6 +171,6 @@ +@@ -216,6 +173,6 @@ "typeReferenceDirectives": [], "libReferenceDirectives": [], "amdDependencies": [], diff --git a/tests/cases/conformance/importDefer/exportDeferInvalid.ts b/tests/cases/conformance/importDefer/exportDeferInvalid.ts new file mode 100644 index 0000000000000..0d0dc587bf2bd --- /dev/null +++ b/tests/cases/conformance/importDefer/exportDeferInvalid.ts @@ -0,0 +1,8 @@ +// @module: esnext +// @filename: a.ts +export function foo() { + console.log("foo from a"); +} + +// @filename: b.ts +export defer * as ns from "a"; diff --git a/tests/cases/conformance/importDefer/importDefaultBindingDefer.ts b/tests/cases/conformance/importDefer/importDefaultBindingDefer.ts new file mode 100644 index 0000000000000..bcbacf6c13a53 --- /dev/null +++ b/tests/cases/conformance/importDefer/importDefaultBindingDefer.ts @@ -0,0 +1,10 @@ +// @module: esnext +// @filename: a.ts +export default function defer() { + console.log("defer from a"); +} + +// @filename: b.ts +import defer from "a"; + +defer(); \ No newline at end of file diff --git a/tests/cases/conformance/importDefer/importDeferInvalidDefault.ts b/tests/cases/conformance/importDefer/importDeferInvalidDefault.ts new file mode 100644 index 0000000000000..d3f02c8d13926 --- /dev/null +++ b/tests/cases/conformance/importDefer/importDeferInvalidDefault.ts @@ -0,0 +1,11 @@ + +// @module: esnext +// @filename: a.ts +export default function foo() { + console.log("foo from a"); +} + +// @filename: b.ts +import defer foo from "a"; + +foo(); \ No newline at end of file diff --git a/tests/cases/conformance/importDefer/importDeferInvalidNamed.ts b/tests/cases/conformance/importDefer/importDeferInvalidNamed.ts new file mode 100644 index 0000000000000..078f5a132223f --- /dev/null +++ b/tests/cases/conformance/importDefer/importDeferInvalidNamed.ts @@ -0,0 +1,10 @@ +// @module: esnext +// @filename: a.ts +export function foo() { + console.log("foo from a"); +} + +// @filename: b.ts +import defer { foo } from "a"; + +foo(); \ No newline at end of file diff --git a/tests/cases/conformance/importDefer/importDeferMissingModuleESNext.ts b/tests/cases/conformance/importDefer/importDeferMissingModuleESNext.ts new file mode 100644 index 0000000000000..937a0bcfa80c6 --- /dev/null +++ b/tests/cases/conformance/importDefer/importDeferMissingModuleESNext.ts @@ -0,0 +1,9 @@ +// @filename: a.ts +export function foo() { + console.log("foo from a"); +} + +// @filename: b.ts +import defer * as aNs from "a"; + +aNs.foo(); diff --git a/tests/cases/conformance/importDefer/importDeferNamespace.ts b/tests/cases/conformance/importDefer/importDeferNamespace.ts new file mode 100644 index 0000000000000..c5b0e08d1fd56 --- /dev/null +++ b/tests/cases/conformance/importDefer/importDeferNamespace.ts @@ -0,0 +1,10 @@ +// @module: esnext +// @filename: a.ts +export function foo() { + console.log("foo from a"); +} + +// @filename: b.ts +import defer * as aNs from "a"; + +aNs.foo(); \ No newline at end of file diff --git a/tests/cases/conformance/importDefer/importDeferTypeConflict1.ts b/tests/cases/conformance/importDefer/importDeferTypeConflict1.ts new file mode 100644 index 0000000000000..5cf5ef7c544ae --- /dev/null +++ b/tests/cases/conformance/importDefer/importDeferTypeConflict1.ts @@ -0,0 +1,8 @@ +// @module: esnext +// @filename: a.ts +export function foo() { + console.log("foo from a"); +} + +// @filename: b.ts +import type defer * as ns1 from "a"; diff --git a/tests/cases/conformance/importDefer/importDeferTypeConflict2.ts b/tests/cases/conformance/importDefer/importDeferTypeConflict2.ts new file mode 100644 index 0000000000000..a12aa3529e3a3 --- /dev/null +++ b/tests/cases/conformance/importDefer/importDeferTypeConflict2.ts @@ -0,0 +1,8 @@ +// @module: esnext +// @filename: a.ts +export function foo() { + console.log("foo from a"); +} + +// @filename: b.ts +import defer type * as ns1 from "a"; From 9e439397ad12f457313cf406a75d2dd561547361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 19 Dec 2024 16:34:09 +0100 Subject: [PATCH 2/3] Update AST to unify `type` with other modifiers --- src/compiler/checker.ts | 21 +++++++++------ src/compiler/emitter.ts | 9 +++---- src/compiler/factory/nodeFactory.ts | 23 +++++++++------- src/compiler/factory/utilities.ts | 3 +-- src/compiler/parser.ts | 27 +++++++++---------- src/compiler/transformers/declarations.ts | 9 +++---- src/compiler/transformers/jsx.ts | 3 +-- .../transformers/module/esnextAnd2015.ts | 7 ++--- src/compiler/transformers/ts.ts | 4 +-- src/compiler/types.ts | 17 ++++++------ src/compiler/utilities.ts | 5 ++-- src/compiler/utilitiesPublic.ts | 7 ++--- src/compiler/visitorPublic.ts | 3 +-- .../codefixes/convertToTypeOnlyImport.ts | 7 +++-- src/services/codefixes/importFixes.ts | 10 +++---- src/services/codefixes/requireInTs.ts | 3 +-- src/services/codefixes/splitTypeOnlyImport.ts | 4 +-- src/services/organizeImports.ts | 2 +- src/services/refactors/convertImport.ts | 3 +-- src/services/refactors/moveToFile.ts | 5 ++-- src/services/utilities.ts | 3 +-- src/testRunner/unittests/transform.ts | 3 +-- ...ocComments.parsesCorrectly.importTag1.json | 4 +-- ...ocComments.parsesCorrectly.importTag2.json | 4 +-- ...ocComments.parsesCorrectly.importTag3.json | 4 +-- ...ocComments.parsesCorrectly.importTag4.json | 4 +-- tests/baselines/reference/api/typescript.d.ts | 15 +++++------ 27 files changed, 100 insertions(+), 109 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3dbc8f4c24328..f2315bf21fc8a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -432,7 +432,6 @@ import { ImportDeclaration, ImportEqualsDeclaration, ImportOrExportSpecifier, - ImportPhase, ImportSpecifier, ImportTypeNode, IndexedAccessType, @@ -9852,14 +9851,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { factory.createImportDeclaration( /*modifiers*/ undefined, factory.createImportClause( - /*isTypeOnly*/ false, + /*phaseModifier*/ undefined, /*name*/ undefined, factory.createNamedImports([factory.createImportSpecifier( /*isTypeOnly*/ false, propertyName && isIdentifier(propertyName) ? factory.createIdentifier(idText(propertyName)) : undefined, factory.createIdentifier(localName), )]), - ImportPhase.Evaluation, ), factory.createStringLiteral(specifier), /*attributes*/ undefined, @@ -9946,7 +9944,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { addResult( factory.createImportDeclaration( /*modifiers*/ undefined, - factory.createImportClause(isTypeOnly, factory.createIdentifier(localName), /*namedBindings*/ undefined, ImportPhase.Evaluation), + factory.createImportClause( + /* phaseModifier */ isTypeOnly ? SyntaxKind.TypeKeyword : undefined, + factory.createIdentifier(localName), + /*namedBindings*/ undefined, + ), specifier, attributes, ), @@ -9961,7 +9963,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { addResult( factory.createImportDeclaration( /*modifiers*/ undefined, - factory.createImportClause(isTypeOnly, /*name*/ undefined, factory.createNamespaceImport(factory.createIdentifier(localName)), ImportPhase.Evaluation), + factory.createImportClause( + /* phaseModifier */ isTypeOnly ? SyntaxKind.TypeKeyword : undefined, + /*name*/ undefined, + factory.createNamespaceImport(factory.createIdentifier(localName)), + ), specifier, (node as ImportClause).parent.attributes, ), @@ -9988,7 +9994,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { factory.createImportDeclaration( /*modifiers*/ undefined, factory.createImportClause( - isTypeOnly, + /* phaseModifier */ isTypeOnly ? SyntaxKind.TypeKeyword : undefined, /*name*/ undefined, factory.createNamedImports([ factory.createImportSpecifier( @@ -9997,7 +10003,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { factory.createIdentifier(localName), ), ]), - ImportPhase.Evaluation, ), specifier, (node as ImportSpecifier).parent.parent.parent.attributes, @@ -52863,7 +52868,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (node.isTypeOnly && node.namedBindings?.kind === SyntaxKind.NamedImports) { return checkGrammarNamedImportsOrExports(node.namedBindings); } - if (node.phase !== ImportPhase.Evaluation && moduleKind !== ModuleKind.ESNext) { + if (node.phaseModifier === SyntaxKind.DeferKeyword && moduleKind !== ModuleKind.ESNext) { return grammarErrorOnNode(node, Diagnostics.Deferred_imports_are_only_supported_when_the_module_flag_is_set_to_esnext); } return false; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ac7872c3cdade..56a758d367aa6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -182,7 +182,6 @@ import { ImportDeclaration, ImportEqualsDeclaration, ImportOrExportSpecifier, - ImportPhase, ImportSpecifier, ImportTypeNode, IndexedAccessTypeNode, @@ -3686,12 +3685,12 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri } function emitImportClause(node: ImportClause) { - if (node.isTypeOnly) { - emitTokenWithComment(SyntaxKind.TypeKeyword, node.pos, writeKeyword, node); + if (node.phaseModifier !== undefined) { + emitTokenWithComment(node.phaseModifier, node.pos, writeKeyword, node); writeSpace(); } - else if (node.phase !== ImportPhase.Evaluation) { - emitTokenWithComment(SyntaxKind.DeferKeyword, node.pos, writeKeyword, node); + else if (node.isTypeOnly) { + emitTokenWithComment(SyntaxKind.TypeKeyword, node.pos, writeKeyword, node); writeSpace(); } emit(node.name); diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index b56ca87b8c005..77d1a5a8e458d 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -135,7 +135,7 @@ import { ImportClause, ImportDeclaration, ImportEqualsDeclaration, - ImportPhase, + ImportPhaseModifier, ImportSpecifier, ImportTypeAssertionContainer, ImportTypeNode, @@ -4724,15 +4724,18 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase): ImportClause { + function createImportClause(phaseModifier: ImportPhaseModifier | boolean | undefined, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause { const node = createBaseDeclaration(SyntaxKind.ImportClause); - node.isTypeOnly = isTypeOnly; + if (typeof phaseModifier === "boolean") { + phaseModifier = phaseModifier ? SyntaxKind.TypeKeyword : undefined; + } + node.isTypeOnly = phaseModifier === SyntaxKind.TypeKeyword; + node.phaseModifier = phaseModifier; node.name = name; node.namedBindings = namedBindings; - node.phase = phase; node.transformFlags |= propagateChildFlags(node.name) | propagateChildFlags(node.namedBindings); - if (isTypeOnly) { + if (phaseModifier === SyntaxKind.TypeKeyword) { node.transformFlags |= TransformFlags.ContainsTypeScript; } node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context @@ -4740,12 +4743,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode } // @api - function updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase) { - return node.isTypeOnly !== isTypeOnly + function updateImportClause(node: ImportClause, phaseModifier: ImportPhaseModifier | boolean | undefined, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined) { + if (typeof phaseModifier === "boolean") { + phaseModifier = phaseModifier ? SyntaxKind.TypeKeyword : undefined; + } + return node.phaseModifier !== phaseModifier || node.name !== name || node.namedBindings !== namedBindings - || node.phase !== phase - ? update(createImportClause(isTypeOnly, name, namedBindings, phase), node) + ? update(createImportClause(phaseModifier, name, namedBindings), node) : node; } diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 12d635b6278c9..f3ed23b582492 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -75,7 +75,6 @@ import { ImportCall, ImportDeclaration, ImportEqualsDeclaration, - ImportPhase, InternalEmitFlags, isAssignmentExpression, isAssignmentOperator, @@ -731,7 +730,7 @@ export function createExternalHelpersImportDeclarationIfNeeded(nodeFactory: Node const externalHelpersImportDeclaration = nodeFactory.createImportDeclaration( /*modifiers*/ undefined, - nodeFactory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, namedBindings, ImportPhase.Evaluation), + nodeFactory.createImportClause(/*phaseModifier*/ undefined, /*name*/ undefined, namedBindings), nodeFactory.createStringLiteral(externalHelpersModuleNameText), /*attributes*/ undefined, ); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index fb500d3f1bd34..44fa145fbc293 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -123,7 +123,7 @@ import { ImportDeclaration, ImportEqualsDeclaration, ImportOrExportSpecifier, - ImportPhase, + ImportPhaseModifier, ImportSpecifier, ImportTypeAssertionContainer, ImportTypeNode, @@ -8368,18 +8368,17 @@ namespace Parser { identifier = parseIdentifier(); } - let isTypeOnly = false; - let phase = ImportPhase.Evaluation; + let phaseModifier: ImportPhaseModifier | undefined; if ( identifier?.escapedText === "type" && (token() !== SyntaxKind.FromKeyword || isIdentifier() && lookAhead(nextTokenIsFromKeywordOrEqualsToken)) && (isIdentifier() || tokenAfterImportDefinitelyProducesImportDeclaration()) ) { - isTypeOnly = true; + phaseModifier = SyntaxKind.TypeKeyword; identifier = isIdentifier() ? parseIdentifier() : undefined; } else if (identifier?.escapedText === "defer" && token() !== SyntaxKind.FromKeyword) { - phase = ImportPhase.Defer; + phaseModifier = SyntaxKind.DeferKeyword; identifier = undefined; if (isIdentifier()) { parseErrorAtCurrentToken(Diagnostics.Default_imports_aren_t_allowed_for_deferred_imports); @@ -8387,11 +8386,11 @@ namespace Parser { } } - if (identifier && !tokenAfterImportedIdentifierDefinitelyProducesImportDeclaration() && phase !== ImportPhase.Defer) { - return parseImportEqualsDeclaration(pos, hasJSDoc, modifiers, identifier, isTypeOnly); + if (identifier && !tokenAfterImportedIdentifierDefinitelyProducesImportDeclaration() && phaseModifier !== SyntaxKind.DeferKeyword) { + return parseImportEqualsDeclaration(pos, hasJSDoc, modifiers, identifier, phaseModifier === SyntaxKind.TypeKeyword); } - const importClause = tryParseImportClause(identifier, afterImportPos, isTypeOnly, /*skipJsDocLeadingAsterisks*/ undefined, phase); + const importClause = tryParseImportClause(identifier, afterImportPos, phaseModifier, /*skipJsDocLeadingAsterisks*/ undefined); const moduleSpecifier = parseModuleSpecifier(); const attributes = tryParseImportAttributes(); @@ -8400,7 +8399,7 @@ namespace Parser { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function tryParseImportClause(identifier: Identifier | undefined, pos: number, isTypeOnly: boolean, skipJsDocLeadingAsterisks = false, phase: ImportPhase) { + function tryParseImportClause(identifier: Identifier | undefined, pos: number, phaseModifier: undefined | ImportPhaseModifier, skipJsDocLeadingAsterisks = false) { // ImportDeclaration: // import ImportClause from ModuleSpecifier ; // import ModuleSpecifier; @@ -8410,7 +8409,7 @@ namespace Parser { token() === SyntaxKind.AsteriskToken || // import * token() === SyntaxKind.OpenBraceToken // import { ) { - importClause = parseImportClause(identifier, pos, isTypeOnly, skipJsDocLeadingAsterisks, phase); + importClause = parseImportClause(identifier, pos, phaseModifier, skipJsDocLeadingAsterisks); parseExpected(SyntaxKind.FromKeyword); } return importClause; @@ -8476,7 +8475,7 @@ namespace Parser { return finished; } - function parseImportClause(identifier: Identifier | undefined, pos: number, isTypeOnly: boolean, skipJsDocLeadingAsterisks: boolean, phase: ImportPhase) { + function parseImportClause(identifier: Identifier | undefined, pos: number, phaseModifier: undefined | ImportPhaseModifier, skipJsDocLeadingAsterisks: boolean) { // ImportClause: // ImportedDefaultBinding // NameSpaceImport @@ -8496,7 +8495,7 @@ namespace Parser { namedBindings = parseNamespaceImport(); } else { - if (phase === ImportPhase.Defer) { + if (phaseModifier === SyntaxKind.DeferKeyword) { parseErrorAtCurrentToken(Diagnostics.Named_imports_aren_t_allowed_for_deferred_imports); } namedBindings = parseNamedImportsOrExports(SyntaxKind.NamedImports); @@ -8504,7 +8503,7 @@ namespace Parser { if (skipJsDocLeadingAsterisks) scanner.setSkipJsDocLeadingAsterisks(false); } - return finishNode(factory.createImportClause(isTypeOnly, identifier, namedBindings, phase), pos); + return finishNode(factory.createImportClause(phaseModifier, identifier, namedBindings), pos); } function parseModuleReference() { @@ -9538,7 +9537,7 @@ namespace Parser { identifier = parseIdentifier(); } - const importClause = tryParseImportClause(identifier, afterImportTagPos, /*isTypeOnly*/ true, /*skipJsDocLeadingAsterisks*/ true, ImportPhase.Evaluation); + const importClause = tryParseImportClause(identifier, afterImportTagPos, SyntaxKind.TypeKeyword, /*skipJsDocLeadingAsterisks*/ true); const moduleSpecifier = parseModuleSpecifier(); const attributes = tryParseImportAttributes(); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index c24aa1c2d1e7e..7608d5333e1e5 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -886,10 +886,9 @@ export function transformDeclarations(context: TransformationContext): Transform decl.modifiers, factory.updateImportClause( decl.importClause, - decl.importClause.isTypeOnly, + decl.importClause.phaseModifier, visibleDefaultBinding, /*namedBindings*/ undefined, - decl.importClause.phase, ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), tryGetResolutionModeOverride(decl.attributes), @@ -903,10 +902,9 @@ export function transformDeclarations(context: TransformationContext): Transform decl.modifiers, factory.updateImportClause( decl.importClause, - decl.importClause.isTypeOnly, + decl.importClause.phaseModifier, visibleDefaultBinding, namedBindings, - decl.importClause.phase, ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), tryGetResolutionModeOverride(decl.attributes), @@ -920,10 +918,9 @@ export function transformDeclarations(context: TransformationContext): Transform decl.modifiers, factory.updateImportClause( decl.importClause, - decl.importClause.isTypeOnly, + decl.importClause.phaseModifier, visibleDefaultBinding, bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined, - decl.importClause.phase, ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), tryGetResolutionModeOverride(decl.attributes), diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index eb7d05dfbb417..885f4c5d67ad6 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -22,7 +22,6 @@ import { getSemanticJsxChildren, Identifier, idText, - ImportPhase, ImportSpecifier, insertStatementAfterCustomPrologue, isExpression, @@ -173,7 +172,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B for (const [importSource, importSpecifiersMap] of arrayFrom(currentFileState.utilizedImplicitRuntimeImports.entries())) { if (isExternalModule(node)) { // Add `import` statement - const importStatement = factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamedImports(arrayFrom(importSpecifiersMap.values())), ImportPhase.Evaluation), factory.createStringLiteral(importSource), /*attributes*/ undefined); + const importStatement = factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*phaseModifier*/ undefined, /*name*/ undefined, factory.createNamedImports(arrayFrom(importSpecifiersMap.values()))), factory.createStringLiteral(importSource), /*attributes*/ undefined); setParentRecursive(importStatement, /*incremental*/ false); statements = insertStatementAfterCustomPrologue(statements.slice(), importStatement); } diff --git a/src/compiler/transformers/module/esnextAnd2015.ts b/src/compiler/transformers/module/esnextAnd2015.ts index c31881d176fa2..5bd5253933de6 100644 --- a/src/compiler/transformers/module/esnextAnd2015.ts +++ b/src/compiler/transformers/module/esnextAnd2015.ts @@ -28,7 +28,6 @@ import { idText, ImportDeclaration, ImportEqualsDeclaration, - ImportPhase, insertStatementsAfterCustomPrologue, isExportNamespaceAsDefaultDeclaration, isExternalModule, @@ -220,12 +219,11 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S const importStatement = factory.createImportDeclaration( /*modifiers*/ undefined, factory.createImportClause( - /*isTypeOnly*/ false, + /*phaseModifier*/ undefined, /*name*/ undefined, factory.createNamedImports([ factory.createImportSpecifier(/*isTypeOnly*/ false, factory.createIdentifier("createRequire"), createRequireName), ]), - ImportPhase.Evaluation, ), factory.createStringLiteral("module"), /*attributes*/ undefined, @@ -353,12 +351,11 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S const importDecl = factory.createImportDeclaration( /*modifiers*/ undefined, factory.createImportClause( - /*isTypeOnly*/ false, + /*phaseModifier*/ undefined, /*name*/ undefined, factory.createNamespaceImport( synthName, ), - ImportPhase.Evaluation, ), updatedModuleSpecifier!, node.attributes, diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index dd04662f99a05..cc3da23d2067b 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2282,11 +2282,11 @@ export function transformTypeScript(context: TransformationContext): Transformer * @param node The import clause node. */ function visitImportClause(node: ImportClause): VisitResult | undefined { - Debug.assert(!node.isTypeOnly); + Debug.assert(node.phaseModifier !== SyntaxKind.TypeKeyword); // Elide the import clause if we elide both its name and its named bindings. const name = shouldEmitAliasDeclaration(node) ? node.name : undefined; const namedBindings = visitNode(node.namedBindings, visitNamedImportBindings, isNamedImportBindings); - return (name || namedBindings) ? factory.updateImportClause(node, /*isTypeOnly*/ false, name, namedBindings, node.phase) : undefined; + return (name || namedBindings) ? factory.updateImportClause(node, node.phaseModifier, name, namedBindings) : undefined; } /** diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d6520e51eae9c..8187a6ce208d0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3712,16 +3712,13 @@ export type NamedExportBindings = export interface ImportClause extends NamedDeclaration { readonly kind: SyntaxKind.ImportClause; readonly parent: ImportDeclaration | JSDocImportTag; - readonly isTypeOnly: boolean; + /** @deprecated */ readonly isTypeOnly: boolean | "hello"; + readonly phaseModifier: undefined | ImportPhaseModifier; readonly name?: Identifier; // Default binding readonly namedBindings?: NamedImportBindings; - readonly phase: ImportPhase; } -export const enum ImportPhase { - Evaluation, - Defer, -} +export type ImportPhaseModifier = SyntaxKind.TypeKeyword | SyntaxKind.DeferKeyword; /** @deprecated */ export type AssertionKey = ImportAttributeName; @@ -9031,8 +9028,12 @@ export interface NodeFactory { updateImportEqualsDeclaration(node: ImportEqualsDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; createImportDeclaration(modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes?: ImportAttributes): ImportDeclaration; updateImportDeclaration(node: ImportDeclaration, modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes: ImportAttributes | undefined): ImportDeclaration; - createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase): ImportClause; - updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase): ImportClause; + createImportClause(phaseModifier: ImportPhaseModifier | undefined, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + // eslint-disable-next-line @typescript-eslint/unified-signatures -- Cannot unify due to the @deprecated tag + /** @deprecated */ createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + updateImportClause(node: ImportClause, phaseModifier: ImportPhaseModifier | undefined, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + // eslint-disable-next-line @typescript-eslint/unified-signatures -- Cannot unify due to the @deprecated tag + /** @deprecated */ updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; /** @deprecated */ createAssertClause(elements: NodeArray, multiLine?: boolean): AssertClause; /** @deprecated */ updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause; /** @deprecated */ createAssertEntry(name: AssertionKey, value: Expression): AssertEntry; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index debbf655c9947..30a949a5f5fc3 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -10909,10 +10909,11 @@ export function isTypeDeclaration(node: Node): node is TypeParameterDeclaration case SyntaxKind.JSDocEnumTag: return true; case SyntaxKind.ImportClause: - return (node as ImportClause).isTypeOnly; + return (node as ImportClause).phaseModifier === SyntaxKind.TypeKeyword; case SyntaxKind.ImportSpecifier: + return (node as ImportSpecifier).parent.parent.phaseModifier === SyntaxKind.TypeKeyword; case SyntaxKind.ExportSpecifier: - return (node as ImportSpecifier | ExportSpecifier).parent.parent.isTypeOnly; + return (node as ExportSpecifier).parent.parent.isTypeOnly; default: return false; } diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 02623678a0cf0..36eba18db07ba 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1534,12 +1534,13 @@ export function isImportOrExportSpecifier(node: Node): node is ImportSpecifier | export function isTypeOnlyImportDeclaration(node: Node): node is TypeOnlyImportDeclaration { switch (node.kind) { case SyntaxKind.ImportSpecifier: - return (node as ImportSpecifier).isTypeOnly || (node as ImportSpecifier).parent.parent.isTypeOnly; + return (node as ImportSpecifier).isTypeOnly || (node as ImportSpecifier).parent.parent.phaseModifier === SyntaxKind.TypeKeyword; case SyntaxKind.NamespaceImport: - return (node as NamespaceImport).parent.isTypeOnly; + return (node as NamespaceImport).parent.phaseModifier === SyntaxKind.TypeKeyword; case SyntaxKind.ImportClause: + return (node as ImportClause).phaseModifier === SyntaxKind.TypeKeyword; case SyntaxKind.ImportEqualsDeclaration: - return (node as ImportClause | ImportEqualsDeclaration).isTypeOnly; + return (node as ImportEqualsDeclaration).isTypeOnly; } return false; } diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 60affb83d9b6e..d1aee94bc6e1b 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -1549,10 +1549,9 @@ const visitEachChildTable: VisitEachChildTable = { [SyntaxKind.ImportClause]: function visitEachChildOfImportClause(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) { return context.factory.updateImportClause( node, - node.isTypeOnly, + node.phaseModifier, nodeVisitor(node.name, visitor, isIdentifier), nodeVisitor(node.namedBindings, visitor, isNamedImportBindings), - node.phase, ); }, diff --git a/src/services/codefixes/convertToTypeOnlyImport.ts b/src/services/codefixes/convertToTypeOnlyImport.ts index 503b64d791537..a5f2b191c36ae 100644 --- a/src/services/codefixes/convertToTypeOnlyImport.ts +++ b/src/services/codefixes/convertToTypeOnlyImport.ts @@ -13,7 +13,6 @@ import { getTokenAtPosition, ImportClause, ImportDeclaration, - ImportPhase, ImportSpecifier, isImportDeclaration, isImportSpecifier, @@ -126,13 +125,13 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, de changes.replaceNodeWithNodes(sourceFile, declaration, [ factory.createImportDeclaration( getSynthesizedDeepClones(declaration.modifiers, /*includeTrivia*/ true), - factory.createImportClause(/*isTypeOnly*/ true, getSynthesizedDeepClone(importClause.name, /*includeTrivia*/ true), /*namedBindings*/ undefined, ImportPhase.Evaluation), + factory.createImportClause(SyntaxKind.TypeKeyword, getSynthesizedDeepClone(importClause.name, /*includeTrivia*/ true), /*namedBindings*/ undefined), getSynthesizedDeepClone(declaration.moduleSpecifier, /*includeTrivia*/ true), getSynthesizedDeepClone(declaration.attributes, /*includeTrivia*/ true), ), factory.createImportDeclaration( getSynthesizedDeepClones(declaration.modifiers, /*includeTrivia*/ true), - factory.createImportClause(/*isTypeOnly*/ true, /*name*/ undefined, getSynthesizedDeepClone(importClause.namedBindings, /*includeTrivia*/ true), ImportPhase.Evaluation), + factory.createImportClause(SyntaxKind.TypeKeyword, /*name*/ undefined, getSynthesizedDeepClone(importClause.namedBindings, /*includeTrivia*/ true)), getSynthesizedDeepClone(declaration.moduleSpecifier, /*includeTrivia*/ true), getSynthesizedDeepClone(declaration.attributes, /*includeTrivia*/ true), ), @@ -145,7 +144,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, de sameMap(importClause.namedBindings.elements, e => factory.updateImportSpecifier(e, /*isTypeOnly*/ false, e.propertyName, e.name)), ) : importClause.namedBindings; - const importDeclaration = factory.updateImportDeclaration(declaration, declaration.modifiers, factory.updateImportClause(importClause, /*isTypeOnly*/ true, importClause.name, newNamedBindings, ImportPhase.Evaluation), declaration.moduleSpecifier, declaration.attributes); + const importDeclaration = factory.updateImportDeclaration(declaration, declaration.modifiers, factory.updateImportClause(importClause, SyntaxKind.TypeKeyword, importClause.name, newNamedBindings), declaration.moduleSpecifier, declaration.attributes); changes.replaceNode(sourceFile, declaration, importDeclaration); } } diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 8b2e9994d6211..8a06f8dd3ce07 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -77,7 +77,6 @@ import { ImportEqualsDeclaration, importFromModuleSpecifier, ImportKind, - ImportPhase, ImportSpecifier, insertImports, InternalSymbolName, @@ -623,10 +622,9 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog declaration.importClause!, factory.updateImportClause( declaration.importClause!, - declaration.importClause!.isTypeOnly, + declaration.importClause!.phaseModifier, declaration.importClause!.name, /*namedBindings*/ undefined, - declaration.importClause!.phase, ), ); } @@ -717,7 +715,7 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog d.modifiers, d.importClause && factory.updateImportClause( d.importClause, - d.importClause.isTypeOnly, + d.importClause.phaseModifier, verbatimImports.has(d.importClause) ? d.importClause.name : undefined, verbatimImports.has(d.importClause.namedBindings as NamespaceImport) ? d.importClause.namedBindings as NamespaceImport : @@ -727,7 +725,6 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog (d.importClause.namedBindings as NamedImports).elements.filter(e => verbatimImports.has(e)), ) : undefined, - d.importClause.phase, ), d.moduleSpecifier, d.attributes, @@ -2082,10 +2079,9 @@ function getNewImports( : factory.createImportDeclaration( /*modifiers*/ undefined, factory.createImportClause( - shouldUseTypeOnly(namespaceLikeImport, preferences), + shouldUseTypeOnly(namespaceLikeImport, preferences) ? SyntaxKind.TypeKeyword : undefined, /*name*/ undefined, factory.createNamespaceImport(factory.createIdentifier(namespaceLikeImport.name)), - ImportPhase.Evaluation, ), quotedModuleSpecifier, /*attributes*/ undefined, diff --git a/src/services/codefixes/requireInTs.ts b/src/services/codefixes/requireInTs.ts index 19101ec8eed45..b627fbbc153ec 100644 --- a/src/services/codefixes/requireInTs.ts +++ b/src/services/codefixes/requireInTs.ts @@ -13,7 +13,6 @@ import { getQuotePreference, getTokenAtPosition, Identifier, - ImportPhase, ImportSpecifier, isIdentifier, isNoSubstitutionTemplateLiteral, @@ -62,7 +61,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, in statement, defaultImportName && !allowSyntheticDefaults ? factory.createImportEqualsDeclaration(/*modifiers*/ undefined, /*isTypeOnly*/ false, defaultImportName, factory.createExternalModuleReference(moduleSpecifier)) - : factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports, ImportPhase.Evaluation), moduleSpecifier, /*attributes*/ undefined), + : factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*phaseModifier*/ undefined, defaultImportName, namedImports), moduleSpecifier, /*attributes*/ undefined), ); } diff --git a/src/services/codefixes/splitTypeOnlyImport.ts b/src/services/codefixes/splitTypeOnlyImport.ts index 39b8cc5a68a90..70267cae3ada9 100644 --- a/src/services/codefixes/splitTypeOnlyImport.ts +++ b/src/services/codefixes/splitTypeOnlyImport.ts @@ -51,7 +51,7 @@ function splitTypeOnlyImport(changes: textChanges.ChangeTracker, importDeclarati factory.updateImportDeclaration( importDeclaration, importDeclaration.modifiers, - factory.updateImportClause(importClause, importClause.isTypeOnly, importClause.name, /*namedBindings*/ undefined, importClause.phase), + factory.updateImportClause(importClause, importClause.phaseModifier, importClause.name, /*namedBindings*/ undefined), importDeclaration.moduleSpecifier, importDeclaration.attributes, ), @@ -62,7 +62,7 @@ function splitTypeOnlyImport(changes: textChanges.ChangeTracker, importDeclarati importDeclaration, factory.createImportDeclaration( /*modifiers*/ undefined, - factory.updateImportClause(importClause, importClause.isTypeOnly, /*name*/ undefined, importClause.namedBindings, importClause.phase), + factory.updateImportClause(importClause, importClause.phaseModifier, /*name*/ undefined, importClause.namedBindings), importDeclaration.moduleSpecifier, importDeclaration.attributes, ), diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index 6a65d615e2651..e1343a61d4471 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -639,7 +639,7 @@ function updateImportDeclarationAndClause( return factory.updateImportDeclaration( importDeclaration, importDeclaration.modifiers, - factory.updateImportClause(importDeclaration.importClause!, importDeclaration.importClause!.isTypeOnly, name, namedBindings, importDeclaration.importClause!.phase), // TODO: GH#18217 + factory.updateImportClause(importDeclaration.importClause!, importDeclaration.importClause!.phaseModifier, name, namedBindings), // TODO: GH#18217 importDeclaration.moduleSpecifier, importDeclaration.attributes, ); diff --git a/src/services/refactors/convertImport.ts b/src/services/refactors/convertImport.ts index 9dc1626514fd0..a628c77460425 100644 --- a/src/services/refactors/convertImport.ts +++ b/src/services/refactors/convertImport.ts @@ -20,7 +20,6 @@ import { ImportClause, ImportDeclaration, ImportKind, - ImportPhase, ImportSpecifier, isExportSpecifier, isImportDeclaration, @@ -291,5 +290,5 @@ function createImport(node: ImportDeclaration, defaultImportName: Identifier | u } function createImportClause(defaultImportName: Identifier | undefined, elements: readonly ImportSpecifier[] | undefined) { - return factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, elements && elements.length ? factory.createNamedImports(elements) : undefined, ImportPhase.Evaluation); + return factory.createImportClause(/*phaseModifier*/ undefined, defaultImportName, elements && elements.length ? factory.createNamedImports(elements) : undefined); } diff --git a/src/services/refactors/moveToFile.ts b/src/services/refactors/moveToFile.ts index 93c207d794b02..a894c3fdcb963 100644 --- a/src/services/refactors/moveToFile.ts +++ b/src/services/refactors/moveToFile.ts @@ -74,7 +74,6 @@ import { ImportDeclaration, ImportEqualsDeclaration, importFromModuleSpecifier, - ImportPhase, InterfaceDeclaration, isArrayLiteralExpression, isBinaryExpression, @@ -424,7 +423,7 @@ function updateNamespaceLikeImportNode(node: SupportedImport, newNamespaceName: case SyntaxKind.ImportDeclaration: return factory.createImportDeclaration( /*modifiers*/ undefined, - factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamespaceImport(newNamespaceId), ImportPhase.Evaluation), + factory.createImportClause(/*phaseModifier*/ undefined, /*name*/ undefined, factory.createNamespaceImport(newNamespaceId)), newModuleString, /*attributes*/ undefined, ); @@ -646,7 +645,7 @@ function filterImport(i: SupportedImport, moduleSpecifier: StringLiteralLike, ke const defaultImport = clause.name && keep(clause.name) ? clause.name : undefined; const namedBindings = clause.namedBindings && filterNamedBindings(clause.namedBindings, keep); return defaultImport || namedBindings - ? factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(clause.isTypeOnly, defaultImport, namedBindings, ImportPhase.Evaluation), getSynthesizedDeepClone(moduleSpecifier), /*attributes*/ undefined) + ? factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(clause.phaseModifier, defaultImport, namedBindings), getSynthesizedDeepClone(moduleSpecifier), /*attributes*/ undefined) : undefined; } case SyntaxKind.ImportEqualsDeclaration: diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 557e6151abc9c..f8f4a5b705745 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -129,7 +129,6 @@ import { IfStatement, ImportClause, ImportDeclaration, - ImportPhase, ImportSpecifier, ImportTypeNode, indexOfNode, @@ -2498,7 +2497,7 @@ export function makeImport(defaultImport: Identifier | undefined, namedImports: return factory.createImportDeclaration( /*modifiers*/ undefined, defaultImport || namedImports - ? factory.createImportClause(!!isTypeOnly, defaultImport, namedImports && namedImports.length ? factory.createNamedImports(namedImports) : undefined, ImportPhase.Evaluation) + ? factory.createImportClause(isTypeOnly ? SyntaxKind.TypeKeyword : undefined, defaultImport, namedImports && namedImports.length ? factory.createNamedImports(namedImports) : undefined) : undefined, typeof moduleSpecifier === "string" ? makeStringLiteral(moduleSpecifier, quotePreference) : moduleSpecifier, /*attributes*/ undefined, diff --git a/src/testRunner/unittests/transform.ts b/src/testRunner/unittests/transform.ts index 8f63e6d8f2428..624ef1ecc3ea4 100644 --- a/src/testRunner/unittests/transform.ts +++ b/src/testRunner/unittests/transform.ts @@ -342,10 +342,9 @@ describe("unittests:: TransformAPI", () => { const importStar = ts.factory.createImportDeclaration( /*modifiers*/ undefined, /*importClause*/ ts.factory.createImportClause( - /*isTypeOnly*/ false, + /*phaseModifier*/ undefined, /*name*/ undefined, ts.factory.createNamespaceImport(ts.factory.createIdentifier("i0")), - ts.ImportPhase.Evaluation, ), /*moduleSpecifier*/ ts.factory.createStringLiteral("./comp1"), /*attributes*/ undefined, diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json index 6b9c81b520c26..6419e4dc7fee7 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag1.json @@ -26,14 +26,14 @@ "modifierFlagsCache": 0, "transformFlags": 1, "isTypeOnly": true, + "phaseModifier": 156, "name": { "kind": "Identifier", "pos": 16, "end": 19, "transformFlags": 0, "escapedText": "foo" - }, - "phase": 0 + } }, "moduleSpecifier": { "kind": "StringLiteral", diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json index 6579049c80981..3094ffd460fd6 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag2.json @@ -26,6 +26,7 @@ "modifierFlagsCache": 0, "transformFlags": 1, "isTypeOnly": true, + "phaseModifier": 156, "namedBindings": { "kind": "NamedImports", "pos": 16, @@ -54,8 +55,7 @@ "hasTrailingComma": false, "transformFlags": 0 } - }, - "phase": 0 + } }, "moduleSpecifier": { "kind": "StringLiteral", diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json index 42e2fedc99dc9..8352b03a73522 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag3.json @@ -26,6 +26,7 @@ "modifierFlagsCache": 0, "transformFlags": 1, "isTypeOnly": true, + "phaseModifier": 156, "namedBindings": { "kind": "NamespaceImport", "pos": 16, @@ -39,8 +40,7 @@ "transformFlags": 0, "escapedText": "types" } - }, - "phase": 0 + } }, "moduleSpecifier": { "kind": "StringLiteral", diff --git a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json index 1e366241b5e29..a681ea5634d28 100644 --- a/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json +++ b/tests/baselines/reference/JSDocParsing/DocComments.parsesCorrectly.importTag4.json @@ -27,6 +27,7 @@ "modifierFlagsCache": 0, "transformFlags": 1, "isTypeOnly": true, + "phaseModifier": 156, "namedBindings": { "kind": "NamespaceImport", "pos": 16, @@ -40,8 +41,7 @@ "transformFlags": 0, "escapedText": "types" } - }, - "phase": 0 + } }, "moduleSpecifier": { "kind": "StringLiteral", diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 8dd5bf169975f..bc50ed0a973a3 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5515,15 +5515,12 @@ declare namespace ts { interface ImportClause extends NamedDeclaration { readonly kind: SyntaxKind.ImportClause; readonly parent: ImportDeclaration | JSDocImportTag; - readonly isTypeOnly: boolean; + /** @deprecated */ readonly isTypeOnly: boolean | "hello"; + readonly phaseModifier: undefined | ImportPhaseModifier; readonly name?: Identifier; readonly namedBindings?: NamedImportBindings; - readonly phase: ImportPhase; - } - enum ImportPhase { - Evaluation = 0, - Defer = 1, } + type ImportPhaseModifier = SyntaxKind.TypeKeyword | SyntaxKind.DeferKeyword; /** @deprecated */ type AssertionKey = ImportAttributeName; /** @deprecated */ @@ -7718,8 +7715,10 @@ declare namespace ts { updateImportEqualsDeclaration(node: ImportEqualsDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; createImportDeclaration(modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes?: ImportAttributes): ImportDeclaration; updateImportDeclaration(node: ImportDeclaration, modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes: ImportAttributes | undefined): ImportDeclaration; - createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase): ImportClause; - updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, phase: ImportPhase): ImportClause; + createImportClause(phaseModifier: ImportPhaseModifier | undefined, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + /** @deprecated */ createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + updateImportClause(node: ImportClause, phaseModifier: ImportPhaseModifier | undefined, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + /** @deprecated */ updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; /** @deprecated */ createAssertClause(elements: NodeArray, multiLine?: boolean): AssertClause; /** @deprecated */ updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause; /** @deprecated */ createAssertEntry(name: AssertionKey, value: Expression): AssertEntry; From b1f506bc15988785bb7d1df01b8b87c31ba6ad6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 19 Dec 2024 16:36:18 +0100 Subject: [PATCH 3/3] Add test for comments around `defer` --- tests/baselines/reference/importDeferComments.js | 13 +++++++++++++ .../baselines/reference/importDeferComments.symbols | 10 ++++++++++ tests/baselines/reference/importDeferComments.types | 11 +++++++++++ .../conformance/importDefer/importDeferComments.ts | 6 ++++++ 4 files changed, 40 insertions(+) create mode 100644 tests/baselines/reference/importDeferComments.js create mode 100644 tests/baselines/reference/importDeferComments.symbols create mode 100644 tests/baselines/reference/importDeferComments.types create mode 100644 tests/cases/conformance/importDefer/importDeferComments.ts diff --git a/tests/baselines/reference/importDeferComments.js b/tests/baselines/reference/importDeferComments.js new file mode 100644 index 0000000000000..3e7980dbc1665 --- /dev/null +++ b/tests/baselines/reference/importDeferComments.js @@ -0,0 +1,13 @@ +//// [tests/cases/conformance/importDefer/importDeferComments.ts] //// + +//// [a.ts] +export {}; + +//// [b.ts] +/*1*/ import /*2*/ defer /*3*/ * /*4*/ as /*5*/ aNs /*6*/ from /*7*/ "a" /*8*/; + + +//// [a.js] +export {}; +//// [b.js] +export {}; diff --git a/tests/baselines/reference/importDeferComments.symbols b/tests/baselines/reference/importDeferComments.symbols new file mode 100644 index 0000000000000..fec1187392018 --- /dev/null +++ b/tests/baselines/reference/importDeferComments.symbols @@ -0,0 +1,10 @@ +//// [tests/cases/conformance/importDefer/importDeferComments.ts] //// + +=== a.ts === + +export {}; + +=== b.ts === +/*1*/ import /*2*/ defer /*3*/ * /*4*/ as /*5*/ aNs /*6*/ from /*7*/ "a" /*8*/; +>aNs : Symbol(aNs, Decl(b.ts, 0, 24)) + diff --git a/tests/baselines/reference/importDeferComments.types b/tests/baselines/reference/importDeferComments.types new file mode 100644 index 0000000000000..6f06fb95216ac --- /dev/null +++ b/tests/baselines/reference/importDeferComments.types @@ -0,0 +1,11 @@ +//// [tests/cases/conformance/importDefer/importDeferComments.ts] //// + +=== a.ts === + +export {}; + +=== b.ts === +/*1*/ import /*2*/ defer /*3*/ * /*4*/ as /*5*/ aNs /*6*/ from /*7*/ "a" /*8*/; +>aNs : typeof aNs +> : ^^^^^^^^^^ + diff --git a/tests/cases/conformance/importDefer/importDeferComments.ts b/tests/cases/conformance/importDefer/importDeferComments.ts new file mode 100644 index 0000000000000..ce480f94260af --- /dev/null +++ b/tests/cases/conformance/importDefer/importDeferComments.ts @@ -0,0 +1,6 @@ +// @module: esnext +// @filename: a.ts +export {}; + +// @filename: b.ts +/*1*/ import /*2*/ defer /*3*/ * /*4*/ as /*5*/ aNs /*6*/ from /*7*/ "a" /*8*/;