From e1b3b78e87ca06c68b6384ef0d1b162d87dff9c1 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Sep 2020 18:43:23 +0800 Subject: [PATCH 01/25] Add parsing --- src/compiler/checker.ts | 14 +++-- src/compiler/factory/nodeFactory.ts | 60 ++++++++++++++++--- src/compiler/factory/nodeTests.ts | 8 +++ src/compiler/factory/utilities.ts | 3 +- src/compiler/parser.ts | 42 +++++++++++-- src/compiler/program.ts | 2 +- src/compiler/transformers/declarations.ts | 14 +++-- src/compiler/transformers/jsx.ts | 2 +- .../transformers/module/esnextAnd2015.ts | 1 + src/compiler/transformers/ts.ts | 8 ++- src/compiler/types.ts | 35 +++++++++-- src/compiler/visitorPublic.ts | 6 +- 12 files changed, 162 insertions(+), 33 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a9d11787a14a3..54934139c5bf1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6130,7 +6130,7 @@ namespace ts { function inlineExportModifiers(statements: Statement[]) { // Pass 3: Move all `export {}`'s to `export` modifiers where possible - const index = findIndex(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause && isNamedExports(d.exportClause)); + const index = findIndex(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !d.assertClause && !!d.exportClause && isNamedExports(d.exportClause)); if (index >= 0) { const exportDecl = statements[index] as ExportDeclaration & { readonly exportClause: NamedExports }; const replacements = mapDefined(exportDecl.exportClause.elements, e => { @@ -6162,7 +6162,8 @@ namespace ts { exportDecl.exportClause, replacements ), - exportDecl.moduleSpecifier + exportDecl.moduleSpecifier, + exportDecl.assertClause ); } } @@ -6798,7 +6799,8 @@ namespace ts { // We use `target.parent || target` below as `target.parent` is unset when the target is a module which has been export assigned // And then made into a default by the `esModuleInterop` or `allowSyntheticDefaultImports` flag // In such cases, the `target` refers to the module itself already - factory.createStringLiteral(getSpecifierForModuleSymbol(target.parent || target, context)) + factory.createStringLiteral(getSpecifierForModuleSymbol(target.parent || target, context)), + /*assertClause*/ undefined ), ModifierFlags.None); break; case SyntaxKind.NamespaceImport: @@ -6806,7 +6808,8 @@ namespace ts { /*decorators*/ undefined, /*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, /*importClause*/ undefined, factory.createNamespaceImport(factory.createIdentifier(localName))), - factory.createStringLiteral(getSpecifierForModuleSymbol(target, context)) + factory.createStringLiteral(getSpecifierForModuleSymbol(target, context)), + /*assertClause*/ undefined ), ModifierFlags.None); break; case SyntaxKind.NamespaceExport: @@ -6831,7 +6834,8 @@ namespace ts { factory.createIdentifier(localName) ) ])), - factory.createStringLiteral(getSpecifierForModuleSymbol(target.parent || target, context)) + factory.createStringLiteral(getSpecifierForModuleSymbol(target.parent || target, context)), + /*assertClause*/ undefined ), ModifierFlags.None); break; case SyntaxKind.ExportSpecifier: diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 3d1b6fdb9a7d3..6112446acb606 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -287,6 +287,10 @@ namespace ts { updateImportDeclaration, createImportClause, updateImportClause, + createAssertClause, + updateAssertClause, + createAssertEntry, + updateAssertEntry, createNamespaceImport, updateNamespaceImport, createNamespaceExport, @@ -3790,7 +3794,8 @@ namespace ts { decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, - moduleSpecifier: Expression + moduleSpecifier: Expression, + assertClause: AssertClause | undefined ): ImportDeclaration { const node = createBaseDeclaration( SyntaxKind.ImportDeclaration, @@ -3799,6 +3804,7 @@ namespace ts { ); node.importClause = importClause; node.moduleSpecifier = moduleSpecifier; + node.assertClause = assertClause; node.transformFlags |= propagateChildFlags(node.importClause) | propagateChildFlags(node.moduleSpecifier); @@ -3812,13 +3818,15 @@ namespace ts { decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, - moduleSpecifier: Expression + moduleSpecifier: Expression, + assertClause: AssertClause | undefined ) { return node.decorators !== decorators || node.modifiers !== modifiers || node.importClause !== importClause || node.moduleSpecifier !== moduleSpecifier - ? update(createImportDeclaration(decorators, modifiers, importClause, moduleSpecifier), node) + || node.assertClause !== assertClause + ? update(createImportDeclaration(decorators, modifiers, importClause, moduleSpecifier, assertClause), node) : node; } @@ -3847,6 +3855,38 @@ namespace ts { : node; } + // @api + function createAssertClause(elements: NodeArray | undefined): AssertClause { + const node = createBaseNode(SyntaxKind.AssertClause); + node.elements = elements; + node.transformFlags |= TransformFlags.ContainsESNext; + return node; + } + + // @api + function updateAssertClause(node: AssertClause, elements: NodeArray | undefined): AssertClause { + return node.elements !== elements + ? update(createAssertClause(elements), node) + : node; + } + + // @api + function createAssertEntry(name: AssertionKey, value: StringLiteral): AssertEntry { + const node = createBaseNode(SyntaxKind.AssertEntry); + node.name = name; + node.value = value; + node.transformFlags |= TransformFlags.ContainsESNext; + return node; + } + + // @api + function updateAssertEntry (node: AssertEntry, name: AssertionKey, value: StringLiteral): AssertEntry { + return node.name !== name + || node.value !== value + ? update(createAssertEntry(name, value), node) + : node; + } + // @api function createNamespaceImport(name: Identifier): NamespaceImport { const node = createBaseNode(SyntaxKind.NamespaceImport); @@ -3958,7 +3998,8 @@ namespace ts { modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, - moduleSpecifier?: Expression + moduleSpecifier?: Expression, + assertClause?: AssertClause ) { const node = createBaseDeclaration( SyntaxKind.ExportDeclaration, @@ -3968,6 +4009,7 @@ namespace ts { node.isTypeOnly = isTypeOnly; node.exportClause = exportClause; node.moduleSpecifier = moduleSpecifier; + node.assertClause = assertClause; node.transformFlags |= propagateChildFlags(node.exportClause) | propagateChildFlags(node.moduleSpecifier); @@ -3982,14 +4024,16 @@ namespace ts { modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, - moduleSpecifier: Expression | undefined + moduleSpecifier: Expression | undefined, + assertClause: AssertClause | undefined ) { return node.decorators !== decorators || node.modifiers !== modifiers || node.isTypeOnly !== isTypeOnly || node.exportClause !== exportClause || node.moduleSpecifier !== moduleSpecifier - ? update(createExportDeclaration(decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier), node) + || node.assertClause !== assertClause + ? update(createExportDeclaration(decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier, assertClause), node) : node; } @@ -5776,9 +5820,9 @@ namespace ts { isEnumDeclaration(node) ? updateEnumDeclaration(node, node.decorators, modifiers, node.name, node.members) : isModuleDeclaration(node) ? updateModuleDeclaration(node, node.decorators, modifiers, node.name, node.body) : isImportEqualsDeclaration(node) ? updateImportEqualsDeclaration(node, node.decorators, modifiers, node.name, node.moduleReference) : - isImportDeclaration(node) ? updateImportDeclaration(node, node.decorators, modifiers, node.importClause, node.moduleSpecifier) : + isImportDeclaration(node) ? updateImportDeclaration(node, node.decorators, modifiers, node.importClause, node.moduleSpecifier, node.assertClause) : isExportAssignment(node) ? updateExportAssignment(node, node.decorators, modifiers, node.expression) : - isExportDeclaration(node) ? updateExportDeclaration(node, node.decorators, modifiers, node.isTypeOnly, node.exportClause, node.moduleSpecifier) : + isExportDeclaration(node) ? updateExportDeclaration(node, node.decorators, modifiers, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.assertClause) : Debug.assertNever(node); } diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index b7da2127f2aae..3da83e29dce98 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -517,6 +517,14 @@ namespace ts { return node.kind === SyntaxKind.ImportClause; } + export function isAssertClause(node: Node): node is AssertClause { + return node.kind === SyntaxKind.AssertClause; + } + + export function isAssertEntry(node: Node): node is AssertEntry { + return node.kind === SyntaxKind.AssertEntry; + } + export function isNamespaceImport(node: Node): node is NamespaceImport { return node.kind === SyntaxKind.NamespaceImport; } diff --git a/src/compiler/factory/utilities.ts b/src/compiler/factory/utilities.ts index 770600d94b71d..59503923f692c 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -446,7 +446,8 @@ namespace ts { /*decorators*/ undefined, /*modifiers*/ undefined, nodeFactory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, namedBindings), - nodeFactory.createStringLiteral(externalHelpersModuleNameText) + nodeFactory.createStringLiteral(externalHelpersModuleNameText), + /*assertClause*/ undefined ); addEmitFlags(externalHelpersImportDeclaration, EmitFlags.NeverApplyImportHelper); return externalHelpersImportDeclaration; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a815a12db9a53..533b8699e3746 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1690,6 +1690,11 @@ namespace ts { token() === SyntaxKind.NumericLiteral; } + function isAssertionKey(): boolean { + return tokenIsIdentifierOrKeyword(token()) || + token() === SyntaxKind.StringLiteral; + } + function parsePropertyNameWorker(allowComputedPropertyNames: boolean): PropertyName { if (token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral) { const node = parseLiteralNode(); @@ -1854,6 +1859,8 @@ namespace ts { return isLiteralPropertyName(); case ParsingContext.ObjectBindingElements: return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.DotDotDotToken || isLiteralPropertyName(); + case ParsingContext.AssertEntries: + return isAssertionKey() case ParsingContext.HeritageClauseElement: // If we see `{ ... }` then only consume it as an expression if it is followed by `,` or `{` // That way we won't consume the body of a class in its heritage clause. @@ -1974,6 +1981,7 @@ namespace ts { case ParsingContext.ObjectLiteralMembers: case ParsingContext.ObjectBindingElements: case ParsingContext.ImportOrExportSpecifiers: + case ParsingContext.AssertEntries: return token() === SyntaxKind.CloseBraceToken; case ParsingContext.SwitchClauseStatements: return token() === SyntaxKind.CloseBraceToken || token() === SyntaxKind.CaseKeyword || token() === SyntaxKind.DefaultKeyword; @@ -6901,13 +6909,33 @@ namespace ts { importClause = parseImportClause(identifier, afterImportPos, isTypeOnly); parseExpected(SyntaxKind.FromKeyword); } - const moduleSpecifier = parseModuleSpecifier(); + const afterSpecifierPos = scanner.getStartPos(); + + let assertClause: AssertClause | undefined; + if (token() === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak()) { + assertClause = parseAssertClause(afterSpecifierPos); + } + parseSemicolon(); - const node = factory.createImportDeclaration(decorators, modifiers, importClause, moduleSpecifier); + const node = factory.createImportDeclaration(decorators, modifiers, importClause, moduleSpecifier, assertClause); return withJSDoc(finishNode(node, pos), hasJSDoc); } + function parseAssertEntry () { + const pos = getNodePos(); + const name = tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral; + parseExpected(SyntaxKind.ColonToken) + const value = parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral; + return finishNode(factory.createAssertEntry(name, value), pos); + } + + function parseAssertClause(pos: number) { + parseExpected(SyntaxKind.AssertKeyword) + const elements = parseList(ParsingContext.AssertEntries, parseAssertEntry) + return finishNode(factory.createAssertClause(elements), pos); + } + function tokenAfterImportDefinitelyProducesImportDeclaration() { return token() === SyntaxKind.AsteriskToken || token() === SyntaxKind.OpenBraceToken; } @@ -7058,6 +7086,7 @@ namespace ts { setAwaitContext(/*value*/ true); let exportClause: NamedExportBindings | undefined; let moduleSpecifier: Expression | undefined; + let assertClause: AssertClause | undefined; const isTypeOnly = parseOptional(SyntaxKind.TypeKeyword); const namespaceExportPos = getNodePos(); if (parseOptional(SyntaxKind.AsteriskToken)) { @@ -7077,9 +7106,13 @@ namespace ts { moduleSpecifier = parseModuleSpecifier(); } } + if (token() === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak()) { + const posAfterSpecifier = getNodePos(); + assertClause = parseAssertClause(posAfterSpecifier); + } parseSemicolon(); setAwaitContext(savedAwaitContext); - const node = factory.createExportDeclaration(decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier); + const node = factory.createExportDeclaration(decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier, assertClause); return withJSDoc(finishNode(node, pos), hasJSDoc); } @@ -7159,7 +7192,8 @@ namespace ts { TypeArguments, // Type arguments in type argument list TupleElementTypes, // Element types in tuple element type list HeritageClauses, // Heritage clauses for a class or interface declaration. - ImportOrExportSpecifiers, // Named import clause's import specifier list + ImportOrExportSpecifiers, // Named import clause's import specifier list, + AssertEntries, // Import entries list. Count // Number of parsing contexts } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 76fa4b62aab9c..297c0966f8c97 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2120,7 +2120,7 @@ namespace ts { && !file.isDeclarationFile) { // synthesize 'import "tslib"' declaration const externalHelpersModuleReference = factory.createStringLiteral(externalHelpersModuleNameText); - const importDecl = factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, /*importClause*/ undefined, externalHelpersModuleReference); + const importDecl = factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, /*importClause*/ undefined, externalHelpersModuleReference, /*assertClause*/ undefined); addEmitFlags(importDecl, EmitFlags.NeverApplyImportHelper); setParent(externalHelpersModuleReference, importDecl); setParent(importDecl, file); diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index af12fbe19258e..d1505304f85c7 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -702,7 +702,8 @@ namespace ts { /*decorators*/ undefined, decl.modifiers, decl.importClause, - rewriteModuleSpecifier(decl, decl.moduleSpecifier) + rewriteModuleSpecifier(decl, decl.moduleSpecifier), + decl.assertClause ); } // The `importClause` visibility corresponds to the default's visibility. @@ -714,7 +715,7 @@ namespace ts { decl.importClause.isTypeOnly, visibleDefaultBinding, /*namedBindings*/ undefined, - ), rewriteModuleSpecifier(decl, decl.moduleSpecifier)); + ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), decl.assertClause); } if (decl.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { // Namespace import (optionally with visible default) @@ -724,7 +725,7 @@ namespace ts { decl.importClause.isTypeOnly, visibleDefaultBinding, namedBindings, - ), rewriteModuleSpecifier(decl, decl.moduleSpecifier)) : undefined; + ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), decl.assertClause) : undefined; } // Named imports (optionally with visible default) const bindingList = mapDefined(decl.importClause.namedBindings.elements, b => resolver.isDeclarationVisible(b) ? b : undefined); @@ -739,7 +740,8 @@ namespace ts { visibleDefaultBinding, bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined, ), - rewriteModuleSpecifier(decl, decl.moduleSpecifier) + rewriteModuleSpecifier(decl, decl.moduleSpecifier), + decl.assertClause ); } // Augmentation of export depends on import @@ -749,7 +751,8 @@ namespace ts { /*decorators*/ undefined, decl.modifiers, /*importClause*/ undefined, - rewriteModuleSpecifier(decl, decl.moduleSpecifier) + rewriteModuleSpecifier(decl, decl.moduleSpecifier), + decl.assertClause ); } // Nothing visible @@ -1084,6 +1087,7 @@ namespace ts { input.isTypeOnly, input.exportClause, rewriteModuleSpecifier(input, input.moduleSpecifier), + input.assertClause ); } case SyntaxKind.ExportAssignment: { diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index 544275c6d201b..a802a7950512f 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -77,7 +77,7 @@ namespace ts { const specifier = `${currentFileState.importSpecifier}/${compilerOptions.jsx === JsxEmit.ReactJSXDev ? "jsx-dev-runtime" : "jsx-runtime"}`; if (isExternalModule(node)) { // Add `import` statement - const importStatement = factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createImportClause(/*typeOnly*/ false, /*name*/ undefined, factory.createNamedImports(arrayFrom(currentFileState.utilizedImplicitRuntimeImports.values()))), factory.createStringLiteral(specifier)); + const importStatement = factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createImportClause(/*typeOnly*/ false, /*name*/ undefined, factory.createNamedImports(arrayFrom(currentFileState.utilizedImplicitRuntimeImports.values()))), factory.createStringLiteral(specifier), /*assertClause*/ 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 24fd849e52bf2..b0dec59c55d89 100644 --- a/src/compiler/transformers/module/esnextAnd2015.ts +++ b/src/compiler/transformers/module/esnextAnd2015.ts @@ -96,6 +96,7 @@ namespace ts { ) ), node.moduleSpecifier, + node.assertClause ); setOriginalNode(importDecl, node.exportClause); diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 3e2e789259915..eb6a0f606609b 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2828,7 +2828,9 @@ namespace ts { /*decorators*/ undefined, /*modifiers*/ undefined, importClause, - node.moduleSpecifier) + node.moduleSpecifier, + node.assertClause + ) : undefined; } @@ -2919,7 +2921,8 @@ namespace ts { /*modifiers*/ undefined, node.isTypeOnly, exportClause, - node.moduleSpecifier) + node.moduleSpecifier, + node.assertClause) : undefined; } @@ -2984,6 +2987,7 @@ namespace ts { /*modifiers*/ undefined, /*importClause*/ undefined, node.moduleReference.expression, + /*assertClause*/ undefined ), node, ), diff --git a/src/compiler/types.ts b/src/compiler/types.ts index fbf308707a10d..e2c088a2f1509 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -159,6 +159,7 @@ namespace ts { AbstractKeyword, AsKeyword, AssertsKeyword, + AssertKeyword, AnyKeyword, AsyncKeyword, AwaitKeyword, @@ -337,6 +338,8 @@ namespace ts { DefaultClause, HeritageClause, CatchClause, + AssertClause, + AssertEntry, // Property assignments PropertyAssignment, @@ -536,6 +539,7 @@ namespace ts { | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword + | SyntaxKind.AssertKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword @@ -1006,6 +1010,7 @@ namespace ts { } export type AssertsKeyword = KeywordToken; + export type AssertKeyword = KeywordToken; export type AwaitKeyword = KeywordToken; /** @deprecated Use `AwaitKeyword` instead. */ @@ -1013,6 +1018,7 @@ namespace ts { /** @deprecated Use `AssertsKeyword` instead. */ export type AssertsToken = AssertsKeyword; + export type AssertToken = AssertKeyword; export interface ModifierToken extends KeywordToken { } @@ -2947,6 +2953,7 @@ namespace ts { readonly importClause?: ImportClause; /** If this is not a StringLiteral it will be a grammar error. */ readonly moduleSpecifier: Expression; + readonly assertClause?: AssertClause; } export type NamedImportBindings = @@ -2973,6 +2980,21 @@ namespace ts { readonly namedBindings?: NamedImportBindings; } + export type AssertionKey = Identifier | StringLiteral; + + export interface AssertEntry extends Node { + readonly kind: SyntaxKind.AssertEntry; + readonly parent: AssertClause; + readonly name: AssertionKey; + readonly value: StringLiteral; + } + + export interface AssertClause extends Node { + readonly kind: SyntaxKind.AssertClause; + readonly parent: ImportDeclaration | ExportDeclaration + readonly elements?: NodeArray + } + export interface NamespaceImport extends NamedDeclaration { readonly kind: SyntaxKind.NamespaceImport; readonly parent: ImportClause; @@ -3000,6 +3022,7 @@ namespace ts { readonly exportClause?: NamedExportBindings; /** If this is not a StringLiteral it will be a grammar error. */ readonly moduleSpecifier?: Expression; + readonly assertClause?: AssertClause; } export interface NamedImports extends Node { @@ -6982,10 +7005,14 @@ namespace ts { updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; - createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; - updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; + createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; + updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + createAssertClause(elements: NodeArray | undefined): AssertClause; + updateAssertClause(node: AssertClause, elements: NodeArray | undefined): AssertClause; + createAssertEntry(name: AssertionKey, value: StringLiteral): AssertEntry; + updateAssertEntry (node: AssertEntry, name: AssertionKey, value: StringLiteral): AssertEntry; createNamespaceImport(name: Identifier): NamespaceImport; updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; createNamespaceExport(name: Identifier): NamespaceExport; @@ -6996,8 +7023,8 @@ namespace ts { updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment; - createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression): ExportDeclaration; - updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; + createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, assertClause?: AssertClause): ExportDeclaration; + updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause: AssertClause | undefined): ExportDeclaration; createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 899936e5962b4..c0c8a0fad2e65 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -935,7 +935,8 @@ namespace ts { nodesVisitor((node).decorators, visitor, isDecorator), nodesVisitor((node).modifiers, visitor, isModifier), nodeVisitor((node).importClause, visitor, isImportClause), - nodeVisitor((node).moduleSpecifier, visitor, isExpression)); + nodeVisitor((node).moduleSpecifier, visitor, isExpression), + nodeVisitor((node).assertClause, visitor, isAssertClause)); case SyntaxKind.ImportClause: return factory.updateImportClause(node, @@ -972,7 +973,8 @@ namespace ts { nodesVisitor((node).modifiers, visitor, isModifier), (node as ExportDeclaration).isTypeOnly, nodeVisitor((node).exportClause, visitor, isNamedExportBindings), - nodeVisitor((node).moduleSpecifier, visitor, isExpression)); + nodeVisitor((node).moduleSpecifier, visitor, isExpression), + nodeVisitor((node).assertClause, visitor, isAssertClause)); case SyntaxKind.NamedExports: return factory.updateNamedExports(node, From 66d2273a912d9abbd99e5399b50a122655f4a85a Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Sep 2020 22:00:34 +0800 Subject: [PATCH 02/25] fix all api --- src/compat/deprecations.ts | 2 +- src/services/codefixes/convertToTypeOnlyExport.ts | 6 ++++-- src/services/codefixes/convertToTypeOnlyImport.ts | 3 ++- src/services/codefixes/importFixes.ts | 3 ++- src/services/codefixes/requireInTs.ts | 2 +- src/services/codefixes/splitTypeOnlyImport.ts | 6 ++++-- src/services/organizeImports.ts | 9 ++++++--- src/services/refactors/convertImport.ts | 2 +- src/services/refactors/moveToNewFile.ts | 5 +++-- src/services/utilities.ts | 3 ++- 10 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/compat/deprecations.ts b/src/compat/deprecations.ts index ed1034b7e6a1b..fb49b9f20ea7c 100644 --- a/src/compat/deprecations.ts +++ b/src/compat/deprecations.ts @@ -1211,7 +1211,7 @@ namespace ts { exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, isTypeOnly: boolean) { - return factory.updateExportDeclaration(node, decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier); + return factory.updateExportDeclaration(node, decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier, /*assertClause*/ undefined); }, factoryDeprecation); /** @deprecated Use `factory.createJSDocParameterTag` or the factory supplied by your transformation context instead. */ diff --git a/src/services/codefixes/convertToTypeOnlyExport.ts b/src/services/codefixes/convertToTypeOnlyExport.ts index cc36a7e7a8608..60029c9f45bff 100644 --- a/src/services/codefixes/convertToTypeOnlyExport.ts +++ b/src/services/codefixes/convertToTypeOnlyExport.ts @@ -44,7 +44,8 @@ namespace ts.codefix { exportDeclaration.modifiers, /*isTypeOnly*/ true, exportClause, - exportDeclaration.moduleSpecifier)); + exportDeclaration.moduleSpecifier, + /*assertClause*/ undefined)); } else { const valueExportDeclaration = factory.updateExportDeclaration( @@ -53,7 +54,8 @@ namespace ts.codefix { exportDeclaration.modifiers, /*isTypeOnly*/ false, factory.updateNamedExports(exportClause, filter(exportClause.elements, e => !contains(typeExportSpecifiers, e))), - exportDeclaration.moduleSpecifier); + exportDeclaration.moduleSpecifier, + /*assertClause*/ undefined); const typeExportDeclaration = factory.createExportDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, diff --git a/src/services/codefixes/convertToTypeOnlyImport.ts b/src/services/codefixes/convertToTypeOnlyImport.ts index 7079ee8d2ba22..9189c5d21c2db 100644 --- a/src/services/codefixes/convertToTypeOnlyImport.ts +++ b/src/services/codefixes/convertToTypeOnlyImport.ts @@ -46,7 +46,8 @@ namespace ts.codefix { /*isTypeOnly*/ true, importClause.name, /*namedBindings*/ undefined), - importDeclaration.moduleSpecifier)); + importDeclaration.moduleSpecifier, + /*assertClause*/ undefined)); } } } diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 291dbdf55144f..5add94bc18fcf 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -776,7 +776,8 @@ namespace ts.codefix { typeOnly, /*name*/ undefined, factory.createNamespaceImport(factory.createIdentifier(namespaceLikeImport.name))), - quotedModuleSpecifier); + quotedModuleSpecifier, + /*assertClause*/ undefined); statements = combine(statements, declaration); } return Debug.checkDefined(statements); diff --git a/src/services/codefixes/requireInTs.ts b/src/services/codefixes/requireInTs.ts index f990f5cadb260..58029657317ac 100644 --- a/src/services/codefixes/requireInTs.ts +++ b/src/services/codefixes/requireInTs.ts @@ -25,7 +25,7 @@ namespace ts.codefix { const { allowSyntheticDefaults, defaultImportName, namedImports, statement, required } = info; changes.replaceNode(sourceFile, statement, defaultImportName && !allowSyntheticDefaults ? factory.createImportEqualsDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, defaultImportName, factory.createExternalModuleReference(required)) - : factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports), required)); + : factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports), required, /*assertClause*/ undefined)); } interface Info { diff --git a/src/services/codefixes/splitTypeOnlyImport.ts b/src/services/codefixes/splitTypeOnlyImport.ts index 321ab03d31d1d..10f8d311a8fc4 100644 --- a/src/services/codefixes/splitTypeOnlyImport.ts +++ b/src/services/codefixes/splitTypeOnlyImport.ts @@ -32,12 +32,14 @@ namespace ts.codefix { importDeclaration.decorators, importDeclaration.modifiers, factory.updateImportClause(importClause, importClause.isTypeOnly, importClause.name, /*namedBindings*/ undefined), - importDeclaration.moduleSpecifier)); + importDeclaration.moduleSpecifier, + importDeclaration.assertClause)); changes.insertNodeAfter(context.sourceFile, importDeclaration, factory.createImportDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, factory.updateImportClause(importClause, importClause.isTypeOnly, /*name*/ undefined, importClause.namedBindings), - importDeclaration.moduleSpecifier)); + importDeclaration.moduleSpecifier, + importDeclaration.assertClause)); } } diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index 46eda4b00a916..c5117481fee4f 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -135,7 +135,8 @@ namespace ts.OrganizeImports { importDecl.decorators, importDecl.modifiers, /*importClause*/ undefined, - moduleSpecifier)); + moduleSpecifier, + /*assertClause*/ undefined)); } // If we’re not in a declaration file, we can’t remove the import clause even though // the imported symbols are unused, because removing them makes it look like the import @@ -346,7 +347,8 @@ namespace ts.OrganizeImports { factory.updateNamedExports(exportDecl.exportClause, sortedExportSpecifiers) : factory.updateNamespaceExport(exportDecl.exportClause, exportDecl.exportClause.name) ), - exportDecl.moduleSpecifier)); + exportDecl.moduleSpecifier, + exportDecl.assertClause)); } return coalescedExports; @@ -393,7 +395,8 @@ namespace ts.OrganizeImports { importDeclaration.decorators, importDeclaration.modifiers, factory.updateImportClause(importDeclaration.importClause!, importDeclaration.importClause!.isTypeOnly, name, namedBindings), // TODO: GH#18217 - importDeclaration.moduleSpecifier); + importDeclaration.moduleSpecifier, + importDeclaration.assertClause); } function sortSpecifiers(specifiers: readonly T[]) { diff --git a/src/services/refactors/convertImport.ts b/src/services/refactors/convertImport.ts index 1ad43126d5d20..1b7a93bea3dc4 100644 --- a/src/services/refactors/convertImport.ts +++ b/src/services/refactors/convertImport.ts @@ -156,6 +156,6 @@ namespace ts.refactor { function updateImport(old: ImportDeclaration, defaultImportName: Identifier | undefined, elements: readonly ImportSpecifier[] | undefined): ImportDeclaration { return factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, - factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, elements && elements.length ? factory.createNamedImports(elements) : undefined), old.moduleSpecifier); + factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, elements && elements.length ? factory.createNamedImports(elements) : undefined), old.moduleSpecifier, /*assertClause*/ undefined); } } diff --git a/src/services/refactors/moveToNewFile.ts b/src/services/refactors/moveToNewFile.ts index 8c3f4504925c1..c444820808576 100644 --- a/src/services/refactors/moveToNewFile.ts +++ b/src/services/refactors/moveToNewFile.ts @@ -243,7 +243,8 @@ namespace ts.refactor { return factory.createImportDeclaration( /*decorators*/ undefined, /*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamespaceImport(newNamespaceId)), - newModuleString); + newModuleString, + /*assertClause*/ undefined); case SyntaxKind.ImportEqualsDeclaration: return factory.createImportEqualsDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, newNamespaceId, factory.createExternalModuleReference(newModuleString)); case SyntaxKind.VariableDeclaration: @@ -573,7 +574,7 @@ namespace ts.refactor { const defaultImport = clause.name && keep(clause.name) ? clause.name : undefined; const namedBindings = clause.namedBindings && filterNamedBindings(clause.namedBindings, keep); return defaultImport || namedBindings - ? factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImport, namedBindings), moduleSpecifier) + ? factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImport, namedBindings), moduleSpecifier, /*assertClause*/ undefined) : undefined; } case SyntaxKind.ImportEqualsDeclaration: diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 0a2572f4d79a9..d32acd402354f 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1795,7 +1795,8 @@ namespace ts { defaultImport || namedImports ? factory.createImportClause(!!isTypeOnly, defaultImport, namedImports && namedImports.length ? factory.createNamedImports(namedImports) : undefined) : undefined, - typeof moduleSpecifier === "string" ? makeStringLiteral(moduleSpecifier, quotePreference) : moduleSpecifier); + typeof moduleSpecifier === "string" ? makeStringLiteral(moduleSpecifier, quotePreference) : moduleSpecifier, + /*assertClause*/ undefined); } export function makeStringLiteral(text: string, quotePreference: QuotePreference): StringLiteral { From 5f3cea6cc9953a562ba4bfd7bb3a7d5f77861675 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Sep 2020 22:19:21 +0800 Subject: [PATCH 03/25] check gramma of import call --- src/compiler/checker.ts | 21 ++++++++++++++++++--- src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 54934139c5bf1..0731366a2541e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39864,6 +39864,22 @@ namespace ts { return false; } + function checkGrammarImportCallArguments(node: ImportCall, nodeArguments: NodeArray): boolean { + const target = getEmitScriptTarget(compilerOptions); + if (target < ScriptTarget.ESNext) { + if (nodeArguments.length !== 1) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument); + } + checkGrammarForDisallowedTrailingComma(nodeArguments); + } + else { + if (nodeArguments.length > 2) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_a_specifier_as_arguments_and_an_optional_assertion); + } + } + return false + } + function checkGrammarImportCallExpression(node: ImportCall): boolean { if (moduleKind === ModuleKind.ES2015) { return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_or_umd); @@ -39874,10 +39890,9 @@ namespace ts { } const nodeArguments = node.arguments; - if (nodeArguments.length !== 1) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument); + if (checkGrammarImportCallArguments(node, nodeArguments)) { + return true; } - checkGrammarForDisallowedTrailingComma(nodeArguments); // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import. if (isSpreadElement(nodeArguments[0])) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9e53407c4373c..19f88f59301f0 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1196,6 +1196,10 @@ "category": "Error", "code": 1391 }, + "Dynamic import must have a specifier as arguments and an optional assertion": { + "category": "Error", + "code": 1392 + }, "The types of '{0}' are incompatible between these types.": { "category": "Error", "code": 2200 From 5a1af0456f8bc33579481848f62ae02a17f9d2ea Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 22 Sep 2020 22:45:00 +0800 Subject: [PATCH 04/25] Add more part of assertion --- src/compiler/checker.ts | 9 +++++++++ src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/emitter.ts | 27 +++++++++++++++++++++++++++ src/compiler/factory/nodeTests.ts | 4 ++++ src/compiler/parser.ts | 5 +++++ src/compiler/types.ts | 1 + src/compiler/visitorPublic.ts | 9 +++++++++ 7 files changed, 59 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0731366a2541e..b9957390b5202 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -35931,11 +35931,19 @@ namespace ts { } } + function checkGrammarImportAssertion(declaration: ImportDeclaration | ExportDeclaration) { + const target = getEmitScriptTarget(compilerOptions); + if (target < ScriptTarget.ESNext && declaration.assertClause) { + grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_are_not_available_when_targeting_lower_than_esnext); + } + } + function checkImportDeclaration(node: ImportDeclaration) { if (checkGrammarModuleElementContext(node, Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) { // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors. return; } + checkGrammarImportAssertion(node); if (!checkGrammarDecoratorsAndModifiers(node) && hasEffectiveModifiers(node)) { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } @@ -36007,6 +36015,7 @@ namespace ts { return; } + checkGrammarImportAssertion(node); if (!checkGrammarDecoratorsAndModifiers(node) && hasEffectiveModifiers(node)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 19f88f59301f0..e03d6c6b78596 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3055,6 +3055,10 @@ "category": "Error", "code": 2795 }, + "Import assertions are not available when targeting lower than esnext.": { + "category": "Error", + "code": 2796 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 237d3fee9cdc5..5945d7d77b509 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1472,6 +1472,10 @@ namespace ts { return emitImportDeclaration(node); case SyntaxKind.ImportClause: return emitImportClause(node); + case SyntaxKind.AssertClause: + return emitAssertClause(node); + case SyntaxKind.AssertEntry: + return emitAssertEntry(node); case SyntaxKind.NamespaceImport: return emitNamespaceImport(node); case SyntaxKind.NamespaceExport: @@ -3182,9 +3186,32 @@ namespace ts { writeSpace(); } emitExpression(node.moduleSpecifier); + if (node.assertClause) { + writeSpace(); + emit(node.assertClause) + } writeTrailingSemicolon(); } + function emitAssertClause(node: AssertClause) { + const elements = node.elements; + emitExpressionList(node, elements, ListFormat.ImportClauseEntries); + } + + function emitAssertEntry(node: AssertEntry) { + emit(node.name); + writePunctuation(":"); + writeSpace(); + + const value = node.value; + /** @see emitPropertyAssignment */ + if (emitTrailingCommentsOfPosition && (getEmitFlags(value) & EmitFlags.NoLeadingComments) === 0) { + const commentRange = getCommentRange(value); + emitTrailingCommentsOfPosition(commentRange.pos); + } + emit(value); + } + function emitImportClause(node: ImportClause) { if (node.isTypeOnly) { emitTokenWithComment(SyntaxKind.TypeKeyword, node.pos, writeKeyword, node); diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index 3da83e29dce98..64e6f841a6ddb 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -525,6 +525,10 @@ namespace ts { return node.kind === SyntaxKind.AssertEntry; } + export function isAssertionKey(node: Node): node is AssertionKey { + return isStringLiteral(node) || isIdentifier(node); + } + export function isNamespaceImport(node: Node): node is NamespaceImport { return node.kind === SyntaxKind.NamespaceImport; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 533b8699e3746..95fce59a61627 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -398,6 +398,11 @@ namespace ts { case SyntaxKind.ImportClause: return visitNode(cbNode, (node).name) || visitNode(cbNode, (node).namedBindings); + case SyntaxKind.AssertClause: + return visitNodes(cbNode, cbNodes, (node).elements); + case SyntaxKind.AssertEntry: + return visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).value); case SyntaxKind.NamespaceExportDeclaration: return visitNode(cbNode, (node).name); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e2c088a2f1509..01d087754c0fe 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7984,6 +7984,7 @@ namespace ts { ObjectBindingPatternElements = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings | NoSpaceIfEmpty, ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings | NoSpaceIfEmpty, ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces | NoSpaceIfEmpty, + ImportClauseEntries = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces | NoSpaceIfEmpty, ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets, CommaListElements = CommaDelimited | SpaceBetweenSiblings | SingleLine, CallExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis, diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index c0c8a0fad2e65..8253dbed6b8d2 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -944,6 +944,15 @@ namespace ts { nodeVisitor((node).name, visitor, isIdentifier), nodeVisitor((node).namedBindings, visitor, isNamedImportBindings)); + case SyntaxKind.AssertClause: + return factory.updateAssertClause(node, + nodesVisitor((node as AssertClause).elements, visitor, isAssertEntry)); + + case SyntaxKind.AssertEntry: + return factory.updateAssertEntry(node, + nodeVisitor((node).name, visitor, isAssertionKey), + nodeVisitor((node).value, visitor, isStringLiteral)); + case SyntaxKind.NamespaceImport: return factory.updateNamespaceImport(node, nodeVisitor((node).name, visitor, isIdentifier)); From 4b51ca9dd846e7bb657e1b11aed00193ee297d7b Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 23 Sep 2020 00:37:45 +0800 Subject: [PATCH 05/25] Add some case --- src/compiler/checker.ts | 6 +- src/compiler/emitter.ts | 12 +- src/compiler/factory/nodeFactory.ts | 10 +- src/compiler/parser.ts | 43 ++++--- src/compiler/scanner.ts | 1 + src/compiler/types.ts | 11 +- src/compiler/visitorPublic.ts | 5 +- src/testRunner/unittests/transform.ts | 5 +- ...importAssertion1(target=es2020).errors.txt | 66 ++++++++++ .../importAssertion1(target=es2020).js | 78 ++++++++++++ .../importAssertion1(target=es2020).symbols | 90 ++++++++++++++ .../importAssertion1(target=es2020).types | 114 ++++++++++++++++++ ...importAssertion1(target=esnext).errors.txt | 39 ++++++ .../importAssertion1(target=esnext).js | 78 ++++++++++++ .../importAssertion1(target=esnext).symbols | 90 ++++++++++++++ .../importAssertion1(target=esnext).types | 114 ++++++++++++++++++ ...importAssertion2(target=es2020).errors.txt | 34 ++++++ .../importAssertion2(target=es2020).js | 41 +++++++ .../importAssertion2(target=es2020).symbols | 28 +++++ .../importAssertion2(target=es2020).types | 39 ++++++ .../importAssertion2(target=esnext).js | 41 +++++++ .../importAssertion2(target=esnext).symbols | 28 +++++ .../importAssertion2(target=esnext).types | 39 ++++++ .../importAssertion/importAssertion1.ts | 34 ++++++ .../importAssertion/importAssertion2.ts | 16 +++ 25 files changed, 1028 insertions(+), 34 deletions(-) create mode 100644 tests/baselines/reference/importAssertion1(target=es2020).errors.txt create mode 100644 tests/baselines/reference/importAssertion1(target=es2020).js create mode 100644 tests/baselines/reference/importAssertion1(target=es2020).symbols create mode 100644 tests/baselines/reference/importAssertion1(target=es2020).types create mode 100644 tests/baselines/reference/importAssertion1(target=esnext).errors.txt create mode 100644 tests/baselines/reference/importAssertion1(target=esnext).js create mode 100644 tests/baselines/reference/importAssertion1(target=esnext).symbols create mode 100644 tests/baselines/reference/importAssertion1(target=esnext).types create mode 100644 tests/baselines/reference/importAssertion2(target=es2020).errors.txt create mode 100644 tests/baselines/reference/importAssertion2(target=es2020).js create mode 100644 tests/baselines/reference/importAssertion2(target=es2020).symbols create mode 100644 tests/baselines/reference/importAssertion2(target=es2020).types create mode 100644 tests/baselines/reference/importAssertion2(target=esnext).js create mode 100644 tests/baselines/reference/importAssertion2(target=esnext).symbols create mode 100644 tests/baselines/reference/importAssertion2(target=esnext).types create mode 100644 tests/cases/conformance/esnext/importAssertion/importAssertion1.ts create mode 100644 tests/cases/conformance/esnext/importAssertion/importAssertion2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b9957390b5202..7b6ac92c2df93 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39882,11 +39882,11 @@ namespace ts { checkGrammarForDisallowedTrailingComma(nodeArguments); } else { - if (nodeArguments.length > 2) { + if (nodeArguments.length !== 1 && nodeArguments.length !== 2) { return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_a_specifier_as_arguments_and_an_optional_assertion); } } - return false + return false; } function checkGrammarImportCallExpression(node: ImportCall): boolean { @@ -39904,7 +39904,7 @@ namespace ts { } // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import. - if (isSpreadElement(nodeArguments[0])) { + if (nodeArguments.length && isSpreadElement(nodeArguments[0])) { return grammarErrorOnNode(nodeArguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); } return false; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5945d7d77b509..f475f9252ceb9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3188,21 +3188,23 @@ namespace ts { emitExpression(node.moduleSpecifier); if (node.assertClause) { writeSpace(); - emit(node.assertClause) + emit(node.assertClause); } writeTrailingSemicolon(); } function emitAssertClause(node: AssertClause) { + emitTokenWithComment(SyntaxKind.AssertKeyword, node.pos, writeKeyword, node); + writeSpace(); const elements = node.elements; - emitExpressionList(node, elements, ListFormat.ImportClauseEntries); + emitNodeList(emitAssertEntry, node, elements, ListFormat.ImportClauseEntries); } function emitAssertEntry(node: AssertEntry) { emit(node.name); writePunctuation(":"); writeSpace(); - + const value = node.value; /** @see emitPropertyAssignment */ if (emitTrailingCommentsOfPosition && (getEmitFlags(value) & EmitFlags.NoLeadingComments) === 0) { @@ -3275,6 +3277,10 @@ namespace ts { writeSpace(); emitExpression(node.moduleSpecifier); } + if (node.assertClause) { + writeSpace(); + emit(node.assertClause); + } writeTrailingSemicolon(); } diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 6112446acb606..59e2e7574051f 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -3856,17 +3856,19 @@ namespace ts { } // @api - function createAssertClause(elements: NodeArray | undefined): AssertClause { + function createAssertClause(elements: NodeArray, multiLine?: boolean): AssertClause { const node = createBaseNode(SyntaxKind.AssertClause); node.elements = elements; + node.multiLine = multiLine; node.transformFlags |= TransformFlags.ContainsESNext; return node; } // @api - function updateAssertClause(node: AssertClause, elements: NodeArray | undefined): AssertClause { + function updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause { return node.elements !== elements - ? update(createAssertClause(elements), node) + || node.multiLine !== multiLine + ? update(createAssertClause(elements, multiLine), node) : node; } @@ -3880,7 +3882,7 @@ namespace ts { } // @api - function updateAssertEntry (node: AssertEntry, name: AssertionKey, value: StringLiteral): AssertEntry { + function updateAssertEntry(node: AssertEntry, name: AssertionKey, value: StringLiteral): AssertEntry { return node.name !== name || node.value !== value ? update(createAssertEntry(name, value), node) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 95fce59a61627..df95c3a394bbb 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -394,7 +394,8 @@ namespace ts { return visitNodes(cbNode, cbNodes, node.decorators) || visitNodes(cbNode, cbNodes, node.modifiers) || visitNode(cbNode, (node).importClause) || - visitNode(cbNode, (node).moduleSpecifier); + visitNode(cbNode, (node).moduleSpecifier) || + visitNode(cbNode, (node).assertClause); case SyntaxKind.ImportClause: return visitNode(cbNode, (node).name) || visitNode(cbNode, (node).namedBindings); @@ -417,7 +418,8 @@ namespace ts { return visitNodes(cbNode, cbNodes, node.decorators) || visitNodes(cbNode, cbNodes, node.modifiers) || visitNode(cbNode, (node).exportClause) || - visitNode(cbNode, (node).moduleSpecifier); + visitNode(cbNode, (node).moduleSpecifier) || + visitNode(cbNode, (node).assertClause); case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: return visitNode(cbNode, (node).propertyName) || @@ -1698,7 +1700,7 @@ namespace ts { function isAssertionKey(): boolean { return tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.StringLiteral; - } + } function parsePropertyNameWorker(allowComputedPropertyNames: boolean): PropertyName { if (token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral) { @@ -1865,7 +1867,7 @@ namespace ts { case ParsingContext.ObjectBindingElements: return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.DotDotDotToken || isLiteralPropertyName(); case ParsingContext.AssertEntries: - return isAssertionKey() + return isAssertionKey(); case ParsingContext.HeritageClauseElement: // If we see `{ ... }` then only consume it as an expression if it is followed by `,` or `{` // That way we won't consume the body of a class in its heritage clause. @@ -6915,11 +6917,10 @@ namespace ts { parseExpected(SyntaxKind.FromKeyword); } const moduleSpecifier = parseModuleSpecifier(); - const afterSpecifierPos = scanner.getStartPos(); let assertClause: AssertClause | undefined; if (token() === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak()) { - assertClause = parseAssertClause(afterSpecifierPos); + assertClause = parseAssertClause(); } parseSemicolon(); @@ -6927,18 +6928,31 @@ namespace ts { return withJSDoc(finishNode(node, pos), hasJSDoc); } - function parseAssertEntry () { + function parseAssertEntry() { const pos = getNodePos(); const name = tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral; - parseExpected(SyntaxKind.ColonToken) + parseExpected(SyntaxKind.ColonToken); const value = parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral; return finishNode(factory.createAssertEntry(name, value), pos); } - function parseAssertClause(pos: number) { - parseExpected(SyntaxKind.AssertKeyword) - const elements = parseList(ParsingContext.AssertEntries, parseAssertEntry) - return finishNode(factory.createAssertClause(elements), pos); + function parseAssertClause() { + const pos = getNodePos(); + parseExpected(SyntaxKind.AssertKeyword); + const openBracePosition = scanner.getTokenPos(); + parseExpected(SyntaxKind.OpenBraceToken); + const multiLine = scanner.hasPrecedingLineBreak(); + const elements = parseDelimitedList(ParsingContext.AssertEntries, parseAssertEntry, /*considerSemicolonAsDelimiter*/ true); + if (!parseExpected(SyntaxKind.CloseBraceToken)) { + const lastError = lastOrUndefined(parseDiagnostics); + if (lastError && lastError.code === Diagnostics._0_expected.code) { + addRelatedInfo( + lastError, + createDetachedDiagnostic(fileName, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_to_match_the_token_here) + ); + } + } + return finishNode(factory.createAssertClause(elements, multiLine), pos); } function tokenAfterImportDefinitelyProducesImportDeclaration() { @@ -7111,9 +7125,8 @@ namespace ts { moduleSpecifier = parseModuleSpecifier(); } } - if (token() === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak()) { - const posAfterSpecifier = getNodePos(); - assertClause = parseAssertClause(posAfterSpecifier); + if (moduleSpecifier && token() === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak()) { + assertClause = parseAssertClause(); } parseSemicolon(); setAwaitContext(savedAwaitContext); diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 35388e38b049f..ffc78c9ff41cb 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -80,6 +80,7 @@ namespace ts { any: SyntaxKind.AnyKeyword, as: SyntaxKind.AsKeyword, asserts: SyntaxKind.AssertsKeyword, + assert: SyntaxKind.AssertKeyword, bigint: SyntaxKind.BigIntKeyword, boolean: SyntaxKind.BooleanKeyword, break: SyntaxKind.BreakKeyword, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 01d087754c0fe..77f908e035352 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2987,12 +2987,13 @@ namespace ts { readonly parent: AssertClause; readonly name: AssertionKey; readonly value: StringLiteral; - } + } - export interface AssertClause extends Node { + export interface AssertClause extends Node { readonly kind: SyntaxKind.AssertClause; readonly parent: ImportDeclaration | ExportDeclaration - readonly elements?: NodeArray + readonly elements: NodeArray; + readonly multiLine?: boolean; } export interface NamespaceImport extends NamedDeclaration { @@ -7009,8 +7010,8 @@ namespace ts { updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; - createAssertClause(elements: NodeArray | undefined): AssertClause; - updateAssertClause(node: AssertClause, elements: NodeArray | undefined): AssertClause; + createAssertClause(elements: NodeArray, multiLine?: boolean): AssertClause; + updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause; createAssertEntry(name: AssertionKey, value: StringLiteral): AssertEntry; updateAssertEntry (node: AssertEntry, name: AssertionKey, value: StringLiteral): AssertEntry; createNamespaceImport(name: Identifier): NamespaceImport; diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 8253dbed6b8d2..e744db756e5cb 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -946,13 +946,14 @@ namespace ts { case SyntaxKind.AssertClause: return factory.updateAssertClause(node, - nodesVisitor((node as AssertClause).elements, visitor, isAssertEntry)); + nodesVisitor((node as AssertClause).elements, visitor, isAssertEntry), + (node as AssertClause).multiLine); case SyntaxKind.AssertEntry: return factory.updateAssertEntry(node, nodeVisitor((node).name, visitor, isAssertionKey), nodeVisitor((node).value, visitor, isStringLiteral)); - + case SyntaxKind.NamespaceImport: return factory.updateNamespaceImport(node, nodeVisitor((node).name, visitor, isIdentifier)); diff --git a/src/testRunner/unittests/transform.ts b/src/testRunner/unittests/transform.ts index e18dd33c92c3c..3d600056da8a2 100644 --- a/src/testRunner/unittests/transform.ts +++ b/src/testRunner/unittests/transform.ts @@ -256,7 +256,7 @@ namespace ts { const exports = [{ name: "x" }]; const exportSpecifiers = exports.map(e => factory.createExportSpecifier(e.name, e.name)); const exportClause = factory.createNamedExports(exportSpecifiers); - const newEd = factory.updateExportDeclaration(ed, ed.decorators, ed.modifiers, ed.isTypeOnly, exportClause, ed.moduleSpecifier); + const newEd = factory.updateExportDeclaration(ed, ed.decorators, ed.modifiers, ed.isTypeOnly, exportClause, ed.moduleSpecifier, ed.assertClause); return newEd as Node as T; } @@ -293,7 +293,8 @@ namespace ts { /*name*/ undefined, factory.createNamespaceImport(factory.createIdentifier("i0")) ), - /*moduleSpecifier*/ factory.createStringLiteral("./comp1")); + /*moduleSpecifier*/ factory.createStringLiteral("./comp1"), + /*assertClause*/ undefined); return factory.updateSourceFile(sf, [importStar]); } } diff --git a/tests/baselines/reference/importAssertion1(target=es2020).errors.txt b/tests/baselines/reference/importAssertion1(target=es2020).errors.txt new file mode 100644 index 0000000000000..845e88885908a --- /dev/null +++ b/tests/baselines/reference/importAssertion1(target=es2020).errors.txt @@ -0,0 +1,66 @@ +tests/cases/conformance/esnext/importAssertion/1.ts(1,14): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/3.ts(2,11): error TS1324: Dynamic import must have one specifier as an argument. +tests/cases/conformance/esnext/importAssertion/3.ts(3,11): error TS1324: Dynamic import must have one specifier as an argument. +tests/cases/conformance/esnext/importAssertion/3.ts(4,11): error TS1324: Dynamic import must have one specifier as an argument. +tests/cases/conformance/esnext/importAssertion/3.ts(6,11): error TS1324: Dynamic import must have one specifier as an argument. +tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1324: Dynamic import must have one specifier as an argument. +tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: Dynamic import must have one specifier as an argument. + + +==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/esnext/importAssertion/1.ts (3 errors) ==== + import './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + import { a, b } from './0' assert { "type": "json" } + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + import * as foo from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + a; + b; + foo.a; + foo.b; + +==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== + import { a, b } from './0' assert {} + ~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + a; + b; + c; + d; + +==== tests/cases/conformance/esnext/importAssertion/3.ts (6 errors) ==== + const a = import('./0') + const b = import('./0', { type: "json" }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic import must have one specifier as an argument. + const c = import('./0', { type: "json", ttype: "typo" }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic import must have one specifier as an argument. + const d = import('./0', { }) + ~~~~~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic import must have one specifier as an argument. + declare function foo(): any; + const e = import('./0', foo()) + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic import must have one specifier as an argument. + const f = import() + ~~~~~~~~ +!!! error TS1324: Dynamic import must have one specifier as an argument. + const g = import('./0', {}, {}) + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic import must have one specifier as an argument. + \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(target=es2020).js b/tests/baselines/reference/importAssertion1(target=es2020).js new file mode 100644 index 0000000000000..b123b2e01104e --- /dev/null +++ b/tests/baselines/reference/importAssertion1(target=es2020).js @@ -0,0 +1,78 @@ +//// [tests/cases/conformance/esnext/importAssertion/importAssertion1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +import './0' assert { type: "json" } +import { a, b } from './0' assert { "type": "json" } +import * as foo from './0' assert { type: "json" } +a; +b; +foo.a; +foo.b; + +//// [2.ts] +import { a, b } from './0' assert {} +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +a; +b; +c; +d; + +//// [3.ts] +const a = import('./0') +const b = import('./0', { type: "json" }) +const c = import('./0', { type: "json", ttype: "typo" }) +const d = import('./0', { }) +declare function foo(): any; +const e = import('./0', foo()) +const f = import() +const g = import('./0', {}, {}) + + +//// [0.js] +export const a = 1; +export const b = 2; +//// [1.js] +import './0' assert { type: "json" }; +import { a, b } from './0' assert { "type": "json" }; +import * as foo from './0' assert { type: "json" }; +a; +b; +foo.a; +foo.b; +//// [2.js] +import { a, b } from './0' assert {}; +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; +a; +b; +c; +d; +//// [3.js] +const a = import('./0'); +const b = import('./0', { type: "json" }); +const c = import('./0', { type: "json", ttype: "typo" }); +const d = import('./0', {}); +const e = import('./0', foo()); +const f = import(); +const g = import('./0', {}, {}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +import './0' assert { type: "json" }; +//// [2.d.ts] +export {}; +//// [3.d.ts] +declare const a: Promise; +declare const b: Promise; +declare const c: Promise; +declare const d: Promise; +declare function foo(): any; +declare const e: Promise; +declare const f: Promise; +declare const g: Promise; diff --git a/tests/baselines/reference/importAssertion1(target=es2020).symbols b/tests/baselines/reference/importAssertion1(target=es2020).symbols new file mode 100644 index 0000000000000..9d6fef3f0fc61 --- /dev/null +++ b/tests/baselines/reference/importAssertion1(target=es2020).symbols @@ -0,0 +1,90 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +import './0' assert { type: "json" } +import { a, b } from './0' assert { "type": "json" } +>a : Symbol(a, Decl(1.ts, 1, 8)) +>b : Symbol(b, Decl(1.ts, 1, 11)) + +import * as foo from './0' assert { type: "json" } +>foo : Symbol(foo, Decl(1.ts, 2, 6)) + +a; +>a : Symbol(a, Decl(1.ts, 1, 8)) + +b; +>b : Symbol(b, Decl(1.ts, 1, 11)) + +foo.a; +>foo.a : Symbol(a, Decl(0.ts, 0, 12)) +>foo : Symbol(foo, Decl(1.ts, 2, 6)) +>a : Symbol(a, Decl(0.ts, 0, 12)) + +foo.b; +>foo.b : Symbol(b, Decl(0.ts, 1, 12)) +>foo : Symbol(foo, Decl(1.ts, 2, 6)) +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +import { a, b } from './0' assert {} +>a : Symbol(a, Decl(2.ts, 0, 8)) +>b : Symbol(b, Decl(2.ts, 0, 11)) + +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : Symbol(a, Decl(0.ts, 0, 12)) +>c : Symbol(c, Decl(2.ts, 1, 8)) +>b : Symbol(b, Decl(0.ts, 1, 12)) +>d : Symbol(d, Decl(2.ts, 1, 16)) + +a; +>a : Symbol(a, Decl(2.ts, 0, 8)) + +b; +>b : Symbol(b, Decl(2.ts, 0, 11)) + +c; +>c : Symbol(c, Decl(2.ts, 1, 8)) + +d; +>d : Symbol(d, Decl(2.ts, 1, 16)) + +=== tests/cases/conformance/esnext/importAssertion/3.ts === +const a = import('./0') +>a : Symbol(a, Decl(3.ts, 0, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) + +const b = import('./0', { type: "json" }) +>b : Symbol(b, Decl(3.ts, 1, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>type : Symbol(type, Decl(3.ts, 1, 25)) + +const c = import('./0', { type: "json", ttype: "typo" }) +>c : Symbol(c, Decl(3.ts, 2, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>type : Symbol(type, Decl(3.ts, 2, 25)) +>ttype : Symbol(ttype, Decl(3.ts, 2, 39)) + +const d = import('./0', { }) +>d : Symbol(d, Decl(3.ts, 3, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) + +declare function foo(): any; +>foo : Symbol(foo, Decl(3.ts, 3, 28)) + +const e = import('./0', foo()) +>e : Symbol(e, Decl(3.ts, 5, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>foo : Symbol(foo, Decl(3.ts, 3, 28)) + +const f = import() +>f : Symbol(f, Decl(3.ts, 6, 5)) + +const g = import('./0', {}, {}) +>g : Symbol(g, Decl(3.ts, 7, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) + diff --git a/tests/baselines/reference/importAssertion1(target=es2020).types b/tests/baselines/reference/importAssertion1(target=es2020).types new file mode 100644 index 0000000000000..38975059069e9 --- /dev/null +++ b/tests/baselines/reference/importAssertion1(target=es2020).types @@ -0,0 +1,114 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +import './0' assert { type: "json" } +>type : any + +import { a, b } from './0' assert { "type": "json" } +>a : 1 +>b : 2 + +import * as foo from './0' assert { type: "json" } +>foo : typeof foo +>type : any + +a; +>a : 1 + +b; +>b : 2 + +foo.a; +>foo.a : 1 +>foo : typeof foo +>a : 1 + +foo.b; +>foo.b : 2 +>foo : typeof foo +>b : 2 + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +import { a, b } from './0' assert {} +>a : 1 +>b : 2 + +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : 1 +>c : 1 +>b : 2 +>d : 2 +>a : any +>b : any +>c : any + +a; +>a : 1 + +b; +>b : 2 + +c; +>c : 1 + +d; +>d : 2 + +=== tests/cases/conformance/esnext/importAssertion/3.ts === +const a = import('./0') +>a : Promise +>import('./0') : Promise +>'./0' : "./0" + +const b = import('./0', { type: "json" }) +>b : Promise +>import('./0', { type: "json" }) : Promise +>'./0' : "./0" +>{ type: "json" } : { type: string; } +>type : string +>"json" : "json" + +const c = import('./0', { type: "json", ttype: "typo" }) +>c : Promise +>import('./0', { type: "json", ttype: "typo" }) : Promise +>'./0' : "./0" +>{ type: "json", ttype: "typo" } : { type: string; ttype: string; } +>type : string +>"json" : "json" +>ttype : string +>"typo" : "typo" + +const d = import('./0', { }) +>d : Promise +>import('./0', { }) : Promise +>'./0' : "./0" +>{ } : {} + +declare function foo(): any; +>foo : () => any + +const e = import('./0', foo()) +>e : Promise +>import('./0', foo()) : Promise +>'./0' : "./0" +>foo() : any +>foo : () => any + +const f = import() +>f : Promise +>import() : Promise + +const g = import('./0', {}, {}) +>g : Promise +>import('./0', {}, {}) : Promise +>'./0' : "./0" +>{} : {} +>{} : {} + diff --git a/tests/baselines/reference/importAssertion1(target=esnext).errors.txt b/tests/baselines/reference/importAssertion1(target=esnext).errors.txt new file mode 100644 index 0000000000000..0e9b637b267cc --- /dev/null +++ b/tests/baselines/reference/importAssertion1(target=esnext).errors.txt @@ -0,0 +1,39 @@ +tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1392: Dynamic import must have a specifier as arguments and an optional assertion +tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1392: Dynamic import must have a specifier as arguments and an optional assertion + + +==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/esnext/importAssertion/1.ts (0 errors) ==== + import './0' assert { type: "json" } + import { a, b } from './0' assert { "type": "json" } + import * as foo from './0' assert { type: "json" } + a; + b; + foo.a; + foo.b; + +==== tests/cases/conformance/esnext/importAssertion/2.ts (0 errors) ==== + import { a, b } from './0' assert {} + import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } + a; + b; + c; + d; + +==== tests/cases/conformance/esnext/importAssertion/3.ts (2 errors) ==== + const a = import('./0') + const b = import('./0', { type: "json" }) + const c = import('./0', { type: "json", ttype: "typo" }) + const d = import('./0', { }) + declare function foo(): any; + const e = import('./0', foo()) + const f = import() + ~~~~~~~~ +!!! error TS1392: Dynamic import must have a specifier as arguments and an optional assertion + const g = import('./0', {}, {}) + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1392: Dynamic import must have a specifier as arguments and an optional assertion + \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(target=esnext).js b/tests/baselines/reference/importAssertion1(target=esnext).js new file mode 100644 index 0000000000000..b123b2e01104e --- /dev/null +++ b/tests/baselines/reference/importAssertion1(target=esnext).js @@ -0,0 +1,78 @@ +//// [tests/cases/conformance/esnext/importAssertion/importAssertion1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +import './0' assert { type: "json" } +import { a, b } from './0' assert { "type": "json" } +import * as foo from './0' assert { type: "json" } +a; +b; +foo.a; +foo.b; + +//// [2.ts] +import { a, b } from './0' assert {} +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +a; +b; +c; +d; + +//// [3.ts] +const a = import('./0') +const b = import('./0', { type: "json" }) +const c = import('./0', { type: "json", ttype: "typo" }) +const d = import('./0', { }) +declare function foo(): any; +const e = import('./0', foo()) +const f = import() +const g = import('./0', {}, {}) + + +//// [0.js] +export const a = 1; +export const b = 2; +//// [1.js] +import './0' assert { type: "json" }; +import { a, b } from './0' assert { "type": "json" }; +import * as foo from './0' assert { type: "json" }; +a; +b; +foo.a; +foo.b; +//// [2.js] +import { a, b } from './0' assert {}; +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; +a; +b; +c; +d; +//// [3.js] +const a = import('./0'); +const b = import('./0', { type: "json" }); +const c = import('./0', { type: "json", ttype: "typo" }); +const d = import('./0', {}); +const e = import('./0', foo()); +const f = import(); +const g = import('./0', {}, {}); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +import './0' assert { type: "json" }; +//// [2.d.ts] +export {}; +//// [3.d.ts] +declare const a: Promise; +declare const b: Promise; +declare const c: Promise; +declare const d: Promise; +declare function foo(): any; +declare const e: Promise; +declare const f: Promise; +declare const g: Promise; diff --git a/tests/baselines/reference/importAssertion1(target=esnext).symbols b/tests/baselines/reference/importAssertion1(target=esnext).symbols new file mode 100644 index 0000000000000..9d6fef3f0fc61 --- /dev/null +++ b/tests/baselines/reference/importAssertion1(target=esnext).symbols @@ -0,0 +1,90 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +import './0' assert { type: "json" } +import { a, b } from './0' assert { "type": "json" } +>a : Symbol(a, Decl(1.ts, 1, 8)) +>b : Symbol(b, Decl(1.ts, 1, 11)) + +import * as foo from './0' assert { type: "json" } +>foo : Symbol(foo, Decl(1.ts, 2, 6)) + +a; +>a : Symbol(a, Decl(1.ts, 1, 8)) + +b; +>b : Symbol(b, Decl(1.ts, 1, 11)) + +foo.a; +>foo.a : Symbol(a, Decl(0.ts, 0, 12)) +>foo : Symbol(foo, Decl(1.ts, 2, 6)) +>a : Symbol(a, Decl(0.ts, 0, 12)) + +foo.b; +>foo.b : Symbol(b, Decl(0.ts, 1, 12)) +>foo : Symbol(foo, Decl(1.ts, 2, 6)) +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +import { a, b } from './0' assert {} +>a : Symbol(a, Decl(2.ts, 0, 8)) +>b : Symbol(b, Decl(2.ts, 0, 11)) + +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : Symbol(a, Decl(0.ts, 0, 12)) +>c : Symbol(c, Decl(2.ts, 1, 8)) +>b : Symbol(b, Decl(0.ts, 1, 12)) +>d : Symbol(d, Decl(2.ts, 1, 16)) + +a; +>a : Symbol(a, Decl(2.ts, 0, 8)) + +b; +>b : Symbol(b, Decl(2.ts, 0, 11)) + +c; +>c : Symbol(c, Decl(2.ts, 1, 8)) + +d; +>d : Symbol(d, Decl(2.ts, 1, 16)) + +=== tests/cases/conformance/esnext/importAssertion/3.ts === +const a = import('./0') +>a : Symbol(a, Decl(3.ts, 0, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) + +const b = import('./0', { type: "json" }) +>b : Symbol(b, Decl(3.ts, 1, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>type : Symbol(type, Decl(3.ts, 1, 25)) + +const c = import('./0', { type: "json", ttype: "typo" }) +>c : Symbol(c, Decl(3.ts, 2, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>type : Symbol(type, Decl(3.ts, 2, 25)) +>ttype : Symbol(ttype, Decl(3.ts, 2, 39)) + +const d = import('./0', { }) +>d : Symbol(d, Decl(3.ts, 3, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) + +declare function foo(): any; +>foo : Symbol(foo, Decl(3.ts, 3, 28)) + +const e = import('./0', foo()) +>e : Symbol(e, Decl(3.ts, 5, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>foo : Symbol(foo, Decl(3.ts, 3, 28)) + +const f = import() +>f : Symbol(f, Decl(3.ts, 6, 5)) + +const g = import('./0', {}, {}) +>g : Symbol(g, Decl(3.ts, 7, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) + diff --git a/tests/baselines/reference/importAssertion1(target=esnext).types b/tests/baselines/reference/importAssertion1(target=esnext).types new file mode 100644 index 0000000000000..38975059069e9 --- /dev/null +++ b/tests/baselines/reference/importAssertion1(target=esnext).types @@ -0,0 +1,114 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +import './0' assert { type: "json" } +>type : any + +import { a, b } from './0' assert { "type": "json" } +>a : 1 +>b : 2 + +import * as foo from './0' assert { type: "json" } +>foo : typeof foo +>type : any + +a; +>a : 1 + +b; +>b : 2 + +foo.a; +>foo.a : 1 +>foo : typeof foo +>a : 1 + +foo.b; +>foo.b : 2 +>foo : typeof foo +>b : 2 + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +import { a, b } from './0' assert {} +>a : 1 +>b : 2 + +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : 1 +>c : 1 +>b : 2 +>d : 2 +>a : any +>b : any +>c : any + +a; +>a : 1 + +b; +>b : 2 + +c; +>c : 1 + +d; +>d : 2 + +=== tests/cases/conformance/esnext/importAssertion/3.ts === +const a = import('./0') +>a : Promise +>import('./0') : Promise +>'./0' : "./0" + +const b = import('./0', { type: "json" }) +>b : Promise +>import('./0', { type: "json" }) : Promise +>'./0' : "./0" +>{ type: "json" } : { type: string; } +>type : string +>"json" : "json" + +const c = import('./0', { type: "json", ttype: "typo" }) +>c : Promise +>import('./0', { type: "json", ttype: "typo" }) : Promise +>'./0' : "./0" +>{ type: "json", ttype: "typo" } : { type: string; ttype: string; } +>type : string +>"json" : "json" +>ttype : string +>"typo" : "typo" + +const d = import('./0', { }) +>d : Promise +>import('./0', { }) : Promise +>'./0' : "./0" +>{ } : {} + +declare function foo(): any; +>foo : () => any + +const e = import('./0', foo()) +>e : Promise +>import('./0', foo()) : Promise +>'./0' : "./0" +>foo() : any +>foo : () => any + +const f = import() +>f : Promise +>import() : Promise + +const g = import('./0', {}, {}) +>g : Promise +>import('./0', {}, {}) : Promise +>'./0' : "./0" +>{} : {} +>{} : {} + diff --git a/tests/baselines/reference/importAssertion2(target=es2020).errors.txt b/tests/baselines/reference/importAssertion2(target=es2020).errors.txt new file mode 100644 index 0000000000000..c2b30dd5f0673 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(target=es2020).errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/esnext/importAssertion/1.ts(1,22): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/1.ts(3,21): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/1.ts(4,27): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2796: Import assertions are not available when targeting lower than esnext. + + +==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/esnext/importAssertion/1.ts (4 errors) ==== + export {} from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + export { a, b } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + export * from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + export * as ns from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + +==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== + export { a, b } from './0' assert {} + ~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are not available when targeting lower than esnext. + \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion2(target=es2020).js b/tests/baselines/reference/importAssertion2(target=es2020).js new file mode 100644 index 0000000000000..19d22a66be4d7 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(target=es2020).js @@ -0,0 +1,41 @@ +//// [tests/cases/conformance/esnext/importAssertion/importAssertion2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export {} from './0' assert { type: "json" } +export { a, b } from './0' assert { type: "json" } +export * from './0' assert { type: "json" } +export * as ns from './0' assert { type: "json" } + +//// [2.ts] +export { a, b } from './0' assert {} +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } + + +//// [0.js] +export const a = 1; +export const b = 2; +//// [1.js] +export { a, b } from './0' assert { type: "json" }; +export * from './0' assert { type: "json" }; +import * as ns_1 from './0' assert { type: "json" }; +export { ns_1 as ns }; +//// [2.js] +export { a, b } from './0' assert {}; +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export {} from './0' assert { type: "json" }; +export { a, b } from './0' assert { type: "json" }; +export * from './0' assert { type: "json" }; +export * as ns from './0' assert { type: "json" }; +//// [2.d.ts] +export { a, b } from './0' assert {}; +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; diff --git a/tests/baselines/reference/importAssertion2(target=es2020).symbols b/tests/baselines/reference/importAssertion2(target=es2020).symbols new file mode 100644 index 0000000000000..818c5391cf50c --- /dev/null +++ b/tests/baselines/reference/importAssertion2(target=es2020).symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +export {} from './0' assert { type: "json" } +export { a, b } from './0' assert { type: "json" } +>a : Symbol(a, Decl(1.ts, 1, 8)) +>b : Symbol(b, Decl(1.ts, 1, 11)) + +export * from './0' assert { type: "json" } +export * as ns from './0' assert { type: "json" } +>ns : Symbol(ns, Decl(1.ts, 3, 6)) + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +export { a, b } from './0' assert {} +>a : Symbol(a, Decl(2.ts, 0, 8)) +>b : Symbol(b, Decl(2.ts, 0, 11)) + +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : Symbol(a, Decl(0.ts, 0, 12)) +>c : Symbol(c, Decl(2.ts, 1, 8)) +>b : Symbol(b, Decl(0.ts, 1, 12)) +>d : Symbol(d, Decl(2.ts, 1, 16)) + diff --git a/tests/baselines/reference/importAssertion2(target=es2020).types b/tests/baselines/reference/importAssertion2(target=es2020).types new file mode 100644 index 0000000000000..6dd54c956508d --- /dev/null +++ b/tests/baselines/reference/importAssertion2(target=es2020).types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +export {} from './0' assert { type: "json" } +>type : any + +export { a, b } from './0' assert { type: "json" } +>a : 1 +>b : 2 +>type : any + +export * from './0' assert { type: "json" } +>type : any + +export * as ns from './0' assert { type: "json" } +>ns : typeof ns +>type : any + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +export { a, b } from './0' assert {} +>a : 1 +>b : 2 + +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : 1 +>c : 1 +>b : 2 +>d : 2 +>a : any +>b : any +>c : any + diff --git a/tests/baselines/reference/importAssertion2(target=esnext).js b/tests/baselines/reference/importAssertion2(target=esnext).js new file mode 100644 index 0000000000000..19d22a66be4d7 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(target=esnext).js @@ -0,0 +1,41 @@ +//// [tests/cases/conformance/esnext/importAssertion/importAssertion2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export {} from './0' assert { type: "json" } +export { a, b } from './0' assert { type: "json" } +export * from './0' assert { type: "json" } +export * as ns from './0' assert { type: "json" } + +//// [2.ts] +export { a, b } from './0' assert {} +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } + + +//// [0.js] +export const a = 1; +export const b = 2; +//// [1.js] +export { a, b } from './0' assert { type: "json" }; +export * from './0' assert { type: "json" }; +import * as ns_1 from './0' assert { type: "json" }; +export { ns_1 as ns }; +//// [2.js] +export { a, b } from './0' assert {}; +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export {} from './0' assert { type: "json" }; +export { a, b } from './0' assert { type: "json" }; +export * from './0' assert { type: "json" }; +export * as ns from './0' assert { type: "json" }; +//// [2.d.ts] +export { a, b } from './0' assert {}; +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; diff --git a/tests/baselines/reference/importAssertion2(target=esnext).symbols b/tests/baselines/reference/importAssertion2(target=esnext).symbols new file mode 100644 index 0000000000000..818c5391cf50c --- /dev/null +++ b/tests/baselines/reference/importAssertion2(target=esnext).symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +export {} from './0' assert { type: "json" } +export { a, b } from './0' assert { type: "json" } +>a : Symbol(a, Decl(1.ts, 1, 8)) +>b : Symbol(b, Decl(1.ts, 1, 11)) + +export * from './0' assert { type: "json" } +export * as ns from './0' assert { type: "json" } +>ns : Symbol(ns, Decl(1.ts, 3, 6)) + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +export { a, b } from './0' assert {} +>a : Symbol(a, Decl(2.ts, 0, 8)) +>b : Symbol(b, Decl(2.ts, 0, 11)) + +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : Symbol(a, Decl(0.ts, 0, 12)) +>c : Symbol(c, Decl(2.ts, 1, 8)) +>b : Symbol(b, Decl(0.ts, 1, 12)) +>d : Symbol(d, Decl(2.ts, 1, 16)) + diff --git a/tests/baselines/reference/importAssertion2(target=esnext).types b/tests/baselines/reference/importAssertion2(target=esnext).types new file mode 100644 index 0000000000000..0d4fa28fe927c --- /dev/null +++ b/tests/baselines/reference/importAssertion2(target=esnext).types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +export {} from './0' assert { type: "json" } +>type : error + +export { a, b } from './0' assert { type: "json" } +>a : 1 +>b : 2 +>type : error + +export * from './0' assert { type: "json" } +>type : error + +export * as ns from './0' assert { type: "json" } +>ns : typeof ns +>type : error + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +export { a, b } from './0' assert {} +>a : 1 +>b : 2 + +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : 1 +>c : 1 +>b : 2 +>d : 2 +>a : error +>b : error +>c : error + diff --git a/tests/cases/conformance/esnext/importAssertion/importAssertion1.ts b/tests/cases/conformance/esnext/importAssertion/importAssertion1.ts new file mode 100644 index 0000000000000..18db235cc8520 --- /dev/null +++ b/tests/cases/conformance/esnext/importAssertion/importAssertion1.ts @@ -0,0 +1,34 @@ +// @target: esnext, es2020 +// @declaration: true +// @module: esnext + +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +import './0' assert { type: "json" } +import { a, b } from './0' assert { "type": "json" } +import * as foo from './0' assert { type: "json" } +a; +b; +foo.a; +foo.b; + +// @filename: 2.ts +import { a, b } from './0' assert {} +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +a; +b; +c; +d; + +// @filename: 3.ts +const a = import('./0') +const b = import('./0', { type: "json" }) +const c = import('./0', { type: "json", ttype: "typo" }) +const d = import('./0', { }) +declare function foo(): any; +const e = import('./0', foo()) +const f = import() +const g = import('./0', {}, {}) diff --git a/tests/cases/conformance/esnext/importAssertion/importAssertion2.ts b/tests/cases/conformance/esnext/importAssertion/importAssertion2.ts new file mode 100644 index 0000000000000..df2730e515a44 --- /dev/null +++ b/tests/cases/conformance/esnext/importAssertion/importAssertion2.ts @@ -0,0 +1,16 @@ +// @target: esnext, es2020 +// @declaration: true + +// @filename: 0.ts +export const a = 1; +export const b = 2; + +// @filename: 1.ts +export {} from './0' assert { type: "json" } +export { a, b } from './0' assert { type: "json" } +export * from './0' assert { type: "json" } +export * as ns from './0' assert { type: "json" } + +// @filename: 2.ts +export { a, b } from './0' assert {} +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } From 375b433e995fb7ff948e62594883c594f0ccbefe Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 23 Sep 2020 00:42:47 +0800 Subject: [PATCH 06/25] Add baseline --- .../reference/api/tsserverlibrary.d.ts | 492 +++++++++--------- tests/baselines/reference/api/typescript.d.ts | 492 +++++++++--------- 2 files changed, 520 insertions(+), 464 deletions(-) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 2b5ca8d1f18f6..a21af62706036 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -232,220 +232,223 @@ declare namespace ts { AbstractKeyword = 125, AsKeyword = 126, AssertsKeyword = 127, - AnyKeyword = 128, - AsyncKeyword = 129, - AwaitKeyword = 130, - BooleanKeyword = 131, - ConstructorKeyword = 132, - DeclareKeyword = 133, - GetKeyword = 134, - InferKeyword = 135, - IntrinsicKeyword = 136, - IsKeyword = 137, - KeyOfKeyword = 138, - ModuleKeyword = 139, - NamespaceKeyword = 140, - NeverKeyword = 141, - ReadonlyKeyword = 142, - RequireKeyword = 143, - NumberKeyword = 144, - ObjectKeyword = 145, - SetKeyword = 146, - StringKeyword = 147, - SymbolKeyword = 148, - TypeKeyword = 149, - UndefinedKeyword = 150, - UniqueKeyword = 151, - UnknownKeyword = 152, - FromKeyword = 153, - GlobalKeyword = 154, - BigIntKeyword = 155, - OfKeyword = 156, - QualifiedName = 157, - ComputedPropertyName = 158, - TypeParameter = 159, - Parameter = 160, - Decorator = 161, - PropertySignature = 162, - PropertyDeclaration = 163, - MethodSignature = 164, - MethodDeclaration = 165, - Constructor = 166, - GetAccessor = 167, - SetAccessor = 168, - CallSignature = 169, - ConstructSignature = 170, - IndexSignature = 171, - TypePredicate = 172, - TypeReference = 173, - FunctionType = 174, - ConstructorType = 175, - TypeQuery = 176, - TypeLiteral = 177, - ArrayType = 178, - TupleType = 179, - OptionalType = 180, - RestType = 181, - UnionType = 182, - IntersectionType = 183, - ConditionalType = 184, - InferType = 185, - ParenthesizedType = 186, - ThisType = 187, - TypeOperator = 188, - IndexedAccessType = 189, - MappedType = 190, - LiteralType = 191, - NamedTupleMember = 192, - TemplateLiteralType = 193, - TemplateLiteralTypeSpan = 194, - ImportType = 195, - ObjectBindingPattern = 196, - ArrayBindingPattern = 197, - BindingElement = 198, - ArrayLiteralExpression = 199, - ObjectLiteralExpression = 200, - PropertyAccessExpression = 201, - ElementAccessExpression = 202, - CallExpression = 203, - NewExpression = 204, - TaggedTemplateExpression = 205, - TypeAssertionExpression = 206, - ParenthesizedExpression = 207, - FunctionExpression = 208, - ArrowFunction = 209, - DeleteExpression = 210, - TypeOfExpression = 211, - VoidExpression = 212, - AwaitExpression = 213, - PrefixUnaryExpression = 214, - PostfixUnaryExpression = 215, - BinaryExpression = 216, - ConditionalExpression = 217, - TemplateExpression = 218, - YieldExpression = 219, - SpreadElement = 220, - ClassExpression = 221, - OmittedExpression = 222, - ExpressionWithTypeArguments = 223, - AsExpression = 224, - NonNullExpression = 225, - MetaProperty = 226, - SyntheticExpression = 227, - TemplateSpan = 228, - SemicolonClassElement = 229, - Block = 230, - EmptyStatement = 231, - VariableStatement = 232, - ExpressionStatement = 233, - IfStatement = 234, - DoStatement = 235, - WhileStatement = 236, - ForStatement = 237, - ForInStatement = 238, - ForOfStatement = 239, - ContinueStatement = 240, - BreakStatement = 241, - ReturnStatement = 242, - WithStatement = 243, - SwitchStatement = 244, - LabeledStatement = 245, - ThrowStatement = 246, - TryStatement = 247, - DebuggerStatement = 248, - VariableDeclaration = 249, - VariableDeclarationList = 250, - FunctionDeclaration = 251, - ClassDeclaration = 252, - InterfaceDeclaration = 253, - TypeAliasDeclaration = 254, - EnumDeclaration = 255, - ModuleDeclaration = 256, - ModuleBlock = 257, - CaseBlock = 258, - NamespaceExportDeclaration = 259, - ImportEqualsDeclaration = 260, - ImportDeclaration = 261, - ImportClause = 262, - NamespaceImport = 263, - NamedImports = 264, - ImportSpecifier = 265, - ExportAssignment = 266, - ExportDeclaration = 267, - NamedExports = 268, - NamespaceExport = 269, - ExportSpecifier = 270, - MissingDeclaration = 271, - ExternalModuleReference = 272, - JsxElement = 273, - JsxSelfClosingElement = 274, - JsxOpeningElement = 275, - JsxClosingElement = 276, - JsxFragment = 277, - JsxOpeningFragment = 278, - JsxClosingFragment = 279, - JsxAttribute = 280, - JsxAttributes = 281, - JsxSpreadAttribute = 282, - JsxExpression = 283, - CaseClause = 284, - DefaultClause = 285, - HeritageClause = 286, - CatchClause = 287, - PropertyAssignment = 288, - ShorthandPropertyAssignment = 289, - SpreadAssignment = 290, - EnumMember = 291, - UnparsedPrologue = 292, - UnparsedPrepend = 293, - UnparsedText = 294, - UnparsedInternalText = 295, - UnparsedSyntheticReference = 296, - SourceFile = 297, - Bundle = 298, - UnparsedSource = 299, - InputFiles = 300, - JSDocTypeExpression = 301, - JSDocNameReference = 302, - JSDocAllType = 303, - JSDocUnknownType = 304, - JSDocNullableType = 305, - JSDocNonNullableType = 306, - JSDocOptionalType = 307, - JSDocFunctionType = 308, - JSDocVariadicType = 309, - JSDocNamepathType = 310, - JSDocComment = 311, - JSDocTypeLiteral = 312, - JSDocSignature = 313, - JSDocTag = 314, - JSDocAugmentsTag = 315, - JSDocImplementsTag = 316, - JSDocAuthorTag = 317, - JSDocDeprecatedTag = 318, - JSDocClassTag = 319, - JSDocPublicTag = 320, - JSDocPrivateTag = 321, - JSDocProtectedTag = 322, - JSDocReadonlyTag = 323, - JSDocCallbackTag = 324, - JSDocEnumTag = 325, - JSDocParameterTag = 326, - JSDocReturnTag = 327, - JSDocThisTag = 328, - JSDocTypeTag = 329, - JSDocTemplateTag = 330, - JSDocTypedefTag = 331, - JSDocSeeTag = 332, - JSDocPropertyTag = 333, - SyntaxList = 334, - NotEmittedStatement = 335, - PartiallyEmittedExpression = 336, - CommaListExpression = 337, - MergeDeclarationMarker = 338, - EndOfDeclarationMarker = 339, - SyntheticReferenceExpression = 340, - Count = 341, + AssertKeyword = 128, + AnyKeyword = 129, + AsyncKeyword = 130, + AwaitKeyword = 131, + BooleanKeyword = 132, + ConstructorKeyword = 133, + DeclareKeyword = 134, + GetKeyword = 135, + InferKeyword = 136, + IntrinsicKeyword = 137, + IsKeyword = 138, + KeyOfKeyword = 139, + ModuleKeyword = 140, + NamespaceKeyword = 141, + NeverKeyword = 142, + ReadonlyKeyword = 143, + RequireKeyword = 144, + NumberKeyword = 145, + ObjectKeyword = 146, + SetKeyword = 147, + StringKeyword = 148, + SymbolKeyword = 149, + TypeKeyword = 150, + UndefinedKeyword = 151, + UniqueKeyword = 152, + UnknownKeyword = 153, + FromKeyword = 154, + GlobalKeyword = 155, + BigIntKeyword = 156, + OfKeyword = 157, + QualifiedName = 158, + ComputedPropertyName = 159, + TypeParameter = 160, + Parameter = 161, + Decorator = 162, + PropertySignature = 163, + PropertyDeclaration = 164, + MethodSignature = 165, + MethodDeclaration = 166, + Constructor = 167, + GetAccessor = 168, + SetAccessor = 169, + CallSignature = 170, + ConstructSignature = 171, + IndexSignature = 172, + TypePredicate = 173, + TypeReference = 174, + FunctionType = 175, + ConstructorType = 176, + TypeQuery = 177, + TypeLiteral = 178, + ArrayType = 179, + TupleType = 180, + OptionalType = 181, + RestType = 182, + UnionType = 183, + IntersectionType = 184, + ConditionalType = 185, + InferType = 186, + ParenthesizedType = 187, + ThisType = 188, + TypeOperator = 189, + IndexedAccessType = 190, + MappedType = 191, + LiteralType = 192, + NamedTupleMember = 193, + TemplateLiteralType = 194, + TemplateLiteralTypeSpan = 195, + ImportType = 196, + ObjectBindingPattern = 197, + ArrayBindingPattern = 198, + BindingElement = 199, + ArrayLiteralExpression = 200, + ObjectLiteralExpression = 201, + PropertyAccessExpression = 202, + ElementAccessExpression = 203, + CallExpression = 204, + NewExpression = 205, + TaggedTemplateExpression = 206, + TypeAssertionExpression = 207, + ParenthesizedExpression = 208, + FunctionExpression = 209, + ArrowFunction = 210, + DeleteExpression = 211, + TypeOfExpression = 212, + VoidExpression = 213, + AwaitExpression = 214, + PrefixUnaryExpression = 215, + PostfixUnaryExpression = 216, + BinaryExpression = 217, + ConditionalExpression = 218, + TemplateExpression = 219, + YieldExpression = 220, + SpreadElement = 221, + ClassExpression = 222, + OmittedExpression = 223, + ExpressionWithTypeArguments = 224, + AsExpression = 225, + NonNullExpression = 226, + MetaProperty = 227, + SyntheticExpression = 228, + TemplateSpan = 229, + SemicolonClassElement = 230, + Block = 231, + EmptyStatement = 232, + VariableStatement = 233, + ExpressionStatement = 234, + IfStatement = 235, + DoStatement = 236, + WhileStatement = 237, + ForStatement = 238, + ForInStatement = 239, + ForOfStatement = 240, + ContinueStatement = 241, + BreakStatement = 242, + ReturnStatement = 243, + WithStatement = 244, + SwitchStatement = 245, + LabeledStatement = 246, + ThrowStatement = 247, + TryStatement = 248, + DebuggerStatement = 249, + VariableDeclaration = 250, + VariableDeclarationList = 251, + FunctionDeclaration = 252, + ClassDeclaration = 253, + InterfaceDeclaration = 254, + TypeAliasDeclaration = 255, + EnumDeclaration = 256, + ModuleDeclaration = 257, + ModuleBlock = 258, + CaseBlock = 259, + NamespaceExportDeclaration = 260, + ImportEqualsDeclaration = 261, + ImportDeclaration = 262, + ImportClause = 263, + NamespaceImport = 264, + NamedImports = 265, + ImportSpecifier = 266, + ExportAssignment = 267, + ExportDeclaration = 268, + NamedExports = 269, + NamespaceExport = 270, + ExportSpecifier = 271, + MissingDeclaration = 272, + ExternalModuleReference = 273, + JsxElement = 274, + JsxSelfClosingElement = 275, + JsxOpeningElement = 276, + JsxClosingElement = 277, + JsxFragment = 278, + JsxOpeningFragment = 279, + JsxClosingFragment = 280, + JsxAttribute = 281, + JsxAttributes = 282, + JsxSpreadAttribute = 283, + JsxExpression = 284, + CaseClause = 285, + DefaultClause = 286, + HeritageClause = 287, + CatchClause = 288, + AssertClause = 289, + AssertEntry = 290, + PropertyAssignment = 291, + ShorthandPropertyAssignment = 292, + SpreadAssignment = 293, + EnumMember = 294, + UnparsedPrologue = 295, + UnparsedPrepend = 296, + UnparsedText = 297, + UnparsedInternalText = 298, + UnparsedSyntheticReference = 299, + SourceFile = 300, + Bundle = 301, + UnparsedSource = 302, + InputFiles = 303, + JSDocTypeExpression = 304, + JSDocNameReference = 305, + JSDocAllType = 306, + JSDocUnknownType = 307, + JSDocNullableType = 308, + JSDocNonNullableType = 309, + JSDocOptionalType = 310, + JSDocFunctionType = 311, + JSDocVariadicType = 312, + JSDocNamepathType = 313, + JSDocComment = 314, + JSDocTypeLiteral = 315, + JSDocSignature = 316, + JSDocTag = 317, + JSDocAugmentsTag = 318, + JSDocImplementsTag = 319, + JSDocAuthorTag = 320, + JSDocDeprecatedTag = 321, + JSDocClassTag = 322, + JSDocPublicTag = 323, + JSDocPrivateTag = 324, + JSDocProtectedTag = 325, + JSDocReadonlyTag = 326, + JSDocCallbackTag = 327, + JSDocEnumTag = 328, + JSDocParameterTag = 329, + JSDocReturnTag = 330, + JSDocThisTag = 331, + JSDocTypeTag = 332, + JSDocTemplateTag = 333, + JSDocTypedefTag = 334, + JSDocSeeTag = 335, + JSDocPropertyTag = 336, + SyntaxList = 337, + NotEmittedStatement = 338, + PartiallyEmittedExpression = 339, + CommaListExpression = 340, + MergeDeclarationMarker = 341, + EndOfDeclarationMarker = 342, + SyntheticReferenceExpression = 343, + Count = 344, FirstAssignment = 62, LastAssignment = 77, FirstCompoundAssignment = 63, @@ -453,15 +456,15 @@ declare namespace ts { FirstReservedWord = 80, LastReservedWord = 115, FirstKeyword = 80, - LastKeyword = 156, + LastKeyword = 157, FirstFutureReservedWord = 116, LastFutureReservedWord = 124, - FirstTypeNode = 172, - LastTypeNode = 195, + FirstTypeNode = 173, + LastTypeNode = 196, FirstPunctuation = 18, LastPunctuation = 77, FirstToken = 0, - LastToken = 156, + LastToken = 157, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -470,19 +473,19 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 77, - FirstStatement = 232, - LastStatement = 248, - FirstNode = 157, - FirstJSDocNode = 301, - LastJSDocNode = 333, - FirstJSDocTagNode = 314, - LastJSDocTagNode = 333, + FirstStatement = 233, + LastStatement = 249, + FirstNode = 158, + FirstJSDocNode = 304, + LastJSDocNode = 336, + FirstJSDocTagNode = 317, + LastJSDocTagNode = 336, } export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; export type PseudoLiteralSyntaxKind = SyntaxKind.TemplateHead | SyntaxKind.TemplateMiddle | SyntaxKind.TemplateTail; export type PunctuationSyntaxKind = SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.OpenParenToken | SyntaxKind.CloseParenToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.DotToken | SyntaxKind.DotDotDotToken | SyntaxKind.SemicolonToken | SyntaxKind.CommaToken | SyntaxKind.QuestionDotToken | SyntaxKind.LessThanToken | SyntaxKind.LessThanSlashToken | SyntaxKind.GreaterThanToken | SyntaxKind.LessThanEqualsToken | SyntaxKind.GreaterThanEqualsToken | SyntaxKind.EqualsEqualsToken | SyntaxKind.ExclamationEqualsToken | SyntaxKind.EqualsEqualsEqualsToken | SyntaxKind.ExclamationEqualsEqualsToken | SyntaxKind.EqualsGreaterThanToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.AsteriskToken | SyntaxKind.AsteriskAsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken | SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.LessThanLessThanToken | SyntaxKind.GreaterThanGreaterThanToken | SyntaxKind.GreaterThanGreaterThanGreaterThanToken | SyntaxKind.AmpersandToken | SyntaxKind.BarToken | SyntaxKind.CaretToken | SyntaxKind.ExclamationToken | SyntaxKind.TildeToken | SyntaxKind.AmpersandAmpersandToken | SyntaxKind.BarBarToken | SyntaxKind.QuestionQuestionToken | SyntaxKind.QuestionToken | SyntaxKind.ColonToken | SyntaxKind.AtToken | SyntaxKind.BacktickToken | SyntaxKind.EqualsToken | SyntaxKind.PlusEqualsToken | SyntaxKind.MinusEqualsToken | SyntaxKind.AsteriskEqualsToken | SyntaxKind.AsteriskAsteriskEqualsToken | SyntaxKind.SlashEqualsToken | SyntaxKind.PercentEqualsToken | SyntaxKind.LessThanLessThanEqualsToken | SyntaxKind.GreaterThanGreaterThanEqualsToken | SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken | SyntaxKind.AmpersandEqualsToken | SyntaxKind.BarEqualsToken | SyntaxKind.CaretEqualsToken; - export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; + export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AssertKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.StaticKeyword; export type KeywordTypeSyntaxKind = SyntaxKind.AnyKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; export type TokenSyntaxKind = SyntaxKind.Unknown | SyntaxKind.EndOfFileToken | TriviaSyntaxKind | LiteralSyntaxKind | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier | KeywordSyntaxKind; @@ -586,11 +589,13 @@ declare namespace ts { export interface KeywordToken extends Token { } export type AssertsKeyword = KeywordToken; + export type AssertKeyword = KeywordToken; export type AwaitKeyword = KeywordToken; /** @deprecated Use `AwaitKeyword` instead. */ export type AwaitKeywordToken = AwaitKeyword; /** @deprecated Use `AssertsKeyword` instead. */ export type AssertsToken = AssertsKeyword; + export type AssertToken = AssertKeyword; export interface ModifierToken extends KeywordToken { } export type AbstractKeyword = ModifierToken; @@ -1611,6 +1616,7 @@ declare namespace ts { readonly importClause?: ImportClause; /** If this is not a StringLiteral it will be a grammar error. */ readonly moduleSpecifier: Expression; + readonly assertClause?: AssertClause; } export type NamedImportBindings = NamespaceImport | NamedImports; export type NamedExportBindings = NamespaceExport | NamedExports; @@ -1621,6 +1627,19 @@ declare namespace ts { readonly name?: Identifier; readonly namedBindings?: NamedImportBindings; } + export type AssertionKey = Identifier | StringLiteral; + export interface AssertEntry extends Node { + readonly kind: SyntaxKind.AssertEntry; + readonly parent: AssertClause; + readonly name: AssertionKey; + readonly value: StringLiteral; + } + export interface AssertClause extends Node { + readonly kind: SyntaxKind.AssertClause; + readonly parent: ImportDeclaration | ExportDeclaration; + readonly elements: NodeArray; + readonly multiLine?: boolean; + } export interface NamespaceImport extends NamedDeclaration { readonly kind: SyntaxKind.NamespaceImport; readonly parent: ImportClause; @@ -1643,6 +1662,7 @@ declare namespace ts { readonly exportClause?: NamedExportBindings; /** If this is not a StringLiteral it will be a grammar error. */ readonly moduleSpecifier?: Expression; + readonly assertClause?: AssertClause; } export interface NamedImports extends Node { readonly kind: SyntaxKind.NamedImports; @@ -3407,10 +3427,14 @@ declare namespace ts { updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; - createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; - updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; + createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; + updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + createAssertClause(elements: NodeArray, multiLine?: boolean): AssertClause; + updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause; + createAssertEntry(name: AssertionKey, value: StringLiteral): AssertEntry; + updateAssertEntry(node: AssertEntry, name: AssertionKey, value: StringLiteral): AssertEntry; createNamespaceImport(name: Identifier): NamespaceImport; updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; createNamespaceExport(name: Identifier): NamespaceExport; @@ -3421,8 +3445,8 @@ declare namespace ts { updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment; - createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression): ExportDeclaration; - updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; + createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, assertClause?: AssertClause): ExportDeclaration; + updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause: AssertClause | undefined): ExportDeclaration; createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; @@ -3827,6 +3851,7 @@ declare namespace ts { ObjectBindingPatternElements = 525136, ArrayBindingPatternElements = 524880, ObjectLiteralExpressionProperties = 526226, + ImportClauseEntries = 526226, ArrayLiteralExpressionElements = 8914, CommaListElements = 528, CallExpressionArguments = 2576, @@ -4437,6 +4462,9 @@ declare namespace ts { function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; + function isAssertClause(node: Node): node is AssertClause; + function isAssertEntry(node: Node): node is AssertEntry; + function isAssertionKey(node: Node): node is AssertionKey; function isNamespaceImport(node: Node): node is NamespaceImport; function isNamespaceExport(node: Node): node is NamespaceExport; function isNamedImports(node: Node): node is NamedImports; @@ -10480,9 +10508,9 @@ declare namespace ts { /** @deprecated Use `factory.updateImportEqualsDeclaration` or the factory supplied by your transformation context instead. */ const updateImportEqualsDeclaration: (node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: Identifier, moduleReference: ModuleReference) => ImportEqualsDeclaration; /** @deprecated Use `factory.createImportDeclaration` or the factory supplied by your transformation context instead. */ - const createImportDeclaration: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression) => ImportDeclaration; + const createImportDeclaration: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined) => ImportDeclaration; /** @deprecated Use `factory.updateImportDeclaration` or the factory supplied by your transformation context instead. */ - const updateImportDeclaration: (node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression) => ImportDeclaration; + const updateImportDeclaration: (node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined) => ImportDeclaration; /** @deprecated Use `factory.createNamespaceImport` or the factory supplied by your transformation context instead. */ const createNamespaceImport: (name: Identifier) => NamespaceImport; /** @deprecated Use `factory.updateNamespaceImport` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 0df67772e6e09..79126e3e023cb 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -232,220 +232,223 @@ declare namespace ts { AbstractKeyword = 125, AsKeyword = 126, AssertsKeyword = 127, - AnyKeyword = 128, - AsyncKeyword = 129, - AwaitKeyword = 130, - BooleanKeyword = 131, - ConstructorKeyword = 132, - DeclareKeyword = 133, - GetKeyword = 134, - InferKeyword = 135, - IntrinsicKeyword = 136, - IsKeyword = 137, - KeyOfKeyword = 138, - ModuleKeyword = 139, - NamespaceKeyword = 140, - NeverKeyword = 141, - ReadonlyKeyword = 142, - RequireKeyword = 143, - NumberKeyword = 144, - ObjectKeyword = 145, - SetKeyword = 146, - StringKeyword = 147, - SymbolKeyword = 148, - TypeKeyword = 149, - UndefinedKeyword = 150, - UniqueKeyword = 151, - UnknownKeyword = 152, - FromKeyword = 153, - GlobalKeyword = 154, - BigIntKeyword = 155, - OfKeyword = 156, - QualifiedName = 157, - ComputedPropertyName = 158, - TypeParameter = 159, - Parameter = 160, - Decorator = 161, - PropertySignature = 162, - PropertyDeclaration = 163, - MethodSignature = 164, - MethodDeclaration = 165, - Constructor = 166, - GetAccessor = 167, - SetAccessor = 168, - CallSignature = 169, - ConstructSignature = 170, - IndexSignature = 171, - TypePredicate = 172, - TypeReference = 173, - FunctionType = 174, - ConstructorType = 175, - TypeQuery = 176, - TypeLiteral = 177, - ArrayType = 178, - TupleType = 179, - OptionalType = 180, - RestType = 181, - UnionType = 182, - IntersectionType = 183, - ConditionalType = 184, - InferType = 185, - ParenthesizedType = 186, - ThisType = 187, - TypeOperator = 188, - IndexedAccessType = 189, - MappedType = 190, - LiteralType = 191, - NamedTupleMember = 192, - TemplateLiteralType = 193, - TemplateLiteralTypeSpan = 194, - ImportType = 195, - ObjectBindingPattern = 196, - ArrayBindingPattern = 197, - BindingElement = 198, - ArrayLiteralExpression = 199, - ObjectLiteralExpression = 200, - PropertyAccessExpression = 201, - ElementAccessExpression = 202, - CallExpression = 203, - NewExpression = 204, - TaggedTemplateExpression = 205, - TypeAssertionExpression = 206, - ParenthesizedExpression = 207, - FunctionExpression = 208, - ArrowFunction = 209, - DeleteExpression = 210, - TypeOfExpression = 211, - VoidExpression = 212, - AwaitExpression = 213, - PrefixUnaryExpression = 214, - PostfixUnaryExpression = 215, - BinaryExpression = 216, - ConditionalExpression = 217, - TemplateExpression = 218, - YieldExpression = 219, - SpreadElement = 220, - ClassExpression = 221, - OmittedExpression = 222, - ExpressionWithTypeArguments = 223, - AsExpression = 224, - NonNullExpression = 225, - MetaProperty = 226, - SyntheticExpression = 227, - TemplateSpan = 228, - SemicolonClassElement = 229, - Block = 230, - EmptyStatement = 231, - VariableStatement = 232, - ExpressionStatement = 233, - IfStatement = 234, - DoStatement = 235, - WhileStatement = 236, - ForStatement = 237, - ForInStatement = 238, - ForOfStatement = 239, - ContinueStatement = 240, - BreakStatement = 241, - ReturnStatement = 242, - WithStatement = 243, - SwitchStatement = 244, - LabeledStatement = 245, - ThrowStatement = 246, - TryStatement = 247, - DebuggerStatement = 248, - VariableDeclaration = 249, - VariableDeclarationList = 250, - FunctionDeclaration = 251, - ClassDeclaration = 252, - InterfaceDeclaration = 253, - TypeAliasDeclaration = 254, - EnumDeclaration = 255, - ModuleDeclaration = 256, - ModuleBlock = 257, - CaseBlock = 258, - NamespaceExportDeclaration = 259, - ImportEqualsDeclaration = 260, - ImportDeclaration = 261, - ImportClause = 262, - NamespaceImport = 263, - NamedImports = 264, - ImportSpecifier = 265, - ExportAssignment = 266, - ExportDeclaration = 267, - NamedExports = 268, - NamespaceExport = 269, - ExportSpecifier = 270, - MissingDeclaration = 271, - ExternalModuleReference = 272, - JsxElement = 273, - JsxSelfClosingElement = 274, - JsxOpeningElement = 275, - JsxClosingElement = 276, - JsxFragment = 277, - JsxOpeningFragment = 278, - JsxClosingFragment = 279, - JsxAttribute = 280, - JsxAttributes = 281, - JsxSpreadAttribute = 282, - JsxExpression = 283, - CaseClause = 284, - DefaultClause = 285, - HeritageClause = 286, - CatchClause = 287, - PropertyAssignment = 288, - ShorthandPropertyAssignment = 289, - SpreadAssignment = 290, - EnumMember = 291, - UnparsedPrologue = 292, - UnparsedPrepend = 293, - UnparsedText = 294, - UnparsedInternalText = 295, - UnparsedSyntheticReference = 296, - SourceFile = 297, - Bundle = 298, - UnparsedSource = 299, - InputFiles = 300, - JSDocTypeExpression = 301, - JSDocNameReference = 302, - JSDocAllType = 303, - JSDocUnknownType = 304, - JSDocNullableType = 305, - JSDocNonNullableType = 306, - JSDocOptionalType = 307, - JSDocFunctionType = 308, - JSDocVariadicType = 309, - JSDocNamepathType = 310, - JSDocComment = 311, - JSDocTypeLiteral = 312, - JSDocSignature = 313, - JSDocTag = 314, - JSDocAugmentsTag = 315, - JSDocImplementsTag = 316, - JSDocAuthorTag = 317, - JSDocDeprecatedTag = 318, - JSDocClassTag = 319, - JSDocPublicTag = 320, - JSDocPrivateTag = 321, - JSDocProtectedTag = 322, - JSDocReadonlyTag = 323, - JSDocCallbackTag = 324, - JSDocEnumTag = 325, - JSDocParameterTag = 326, - JSDocReturnTag = 327, - JSDocThisTag = 328, - JSDocTypeTag = 329, - JSDocTemplateTag = 330, - JSDocTypedefTag = 331, - JSDocSeeTag = 332, - JSDocPropertyTag = 333, - SyntaxList = 334, - NotEmittedStatement = 335, - PartiallyEmittedExpression = 336, - CommaListExpression = 337, - MergeDeclarationMarker = 338, - EndOfDeclarationMarker = 339, - SyntheticReferenceExpression = 340, - Count = 341, + AssertKeyword = 128, + AnyKeyword = 129, + AsyncKeyword = 130, + AwaitKeyword = 131, + BooleanKeyword = 132, + ConstructorKeyword = 133, + DeclareKeyword = 134, + GetKeyword = 135, + InferKeyword = 136, + IntrinsicKeyword = 137, + IsKeyword = 138, + KeyOfKeyword = 139, + ModuleKeyword = 140, + NamespaceKeyword = 141, + NeverKeyword = 142, + ReadonlyKeyword = 143, + RequireKeyword = 144, + NumberKeyword = 145, + ObjectKeyword = 146, + SetKeyword = 147, + StringKeyword = 148, + SymbolKeyword = 149, + TypeKeyword = 150, + UndefinedKeyword = 151, + UniqueKeyword = 152, + UnknownKeyword = 153, + FromKeyword = 154, + GlobalKeyword = 155, + BigIntKeyword = 156, + OfKeyword = 157, + QualifiedName = 158, + ComputedPropertyName = 159, + TypeParameter = 160, + Parameter = 161, + Decorator = 162, + PropertySignature = 163, + PropertyDeclaration = 164, + MethodSignature = 165, + MethodDeclaration = 166, + Constructor = 167, + GetAccessor = 168, + SetAccessor = 169, + CallSignature = 170, + ConstructSignature = 171, + IndexSignature = 172, + TypePredicate = 173, + TypeReference = 174, + FunctionType = 175, + ConstructorType = 176, + TypeQuery = 177, + TypeLiteral = 178, + ArrayType = 179, + TupleType = 180, + OptionalType = 181, + RestType = 182, + UnionType = 183, + IntersectionType = 184, + ConditionalType = 185, + InferType = 186, + ParenthesizedType = 187, + ThisType = 188, + TypeOperator = 189, + IndexedAccessType = 190, + MappedType = 191, + LiteralType = 192, + NamedTupleMember = 193, + TemplateLiteralType = 194, + TemplateLiteralTypeSpan = 195, + ImportType = 196, + ObjectBindingPattern = 197, + ArrayBindingPattern = 198, + BindingElement = 199, + ArrayLiteralExpression = 200, + ObjectLiteralExpression = 201, + PropertyAccessExpression = 202, + ElementAccessExpression = 203, + CallExpression = 204, + NewExpression = 205, + TaggedTemplateExpression = 206, + TypeAssertionExpression = 207, + ParenthesizedExpression = 208, + FunctionExpression = 209, + ArrowFunction = 210, + DeleteExpression = 211, + TypeOfExpression = 212, + VoidExpression = 213, + AwaitExpression = 214, + PrefixUnaryExpression = 215, + PostfixUnaryExpression = 216, + BinaryExpression = 217, + ConditionalExpression = 218, + TemplateExpression = 219, + YieldExpression = 220, + SpreadElement = 221, + ClassExpression = 222, + OmittedExpression = 223, + ExpressionWithTypeArguments = 224, + AsExpression = 225, + NonNullExpression = 226, + MetaProperty = 227, + SyntheticExpression = 228, + TemplateSpan = 229, + SemicolonClassElement = 230, + Block = 231, + EmptyStatement = 232, + VariableStatement = 233, + ExpressionStatement = 234, + IfStatement = 235, + DoStatement = 236, + WhileStatement = 237, + ForStatement = 238, + ForInStatement = 239, + ForOfStatement = 240, + ContinueStatement = 241, + BreakStatement = 242, + ReturnStatement = 243, + WithStatement = 244, + SwitchStatement = 245, + LabeledStatement = 246, + ThrowStatement = 247, + TryStatement = 248, + DebuggerStatement = 249, + VariableDeclaration = 250, + VariableDeclarationList = 251, + FunctionDeclaration = 252, + ClassDeclaration = 253, + InterfaceDeclaration = 254, + TypeAliasDeclaration = 255, + EnumDeclaration = 256, + ModuleDeclaration = 257, + ModuleBlock = 258, + CaseBlock = 259, + NamespaceExportDeclaration = 260, + ImportEqualsDeclaration = 261, + ImportDeclaration = 262, + ImportClause = 263, + NamespaceImport = 264, + NamedImports = 265, + ImportSpecifier = 266, + ExportAssignment = 267, + ExportDeclaration = 268, + NamedExports = 269, + NamespaceExport = 270, + ExportSpecifier = 271, + MissingDeclaration = 272, + ExternalModuleReference = 273, + JsxElement = 274, + JsxSelfClosingElement = 275, + JsxOpeningElement = 276, + JsxClosingElement = 277, + JsxFragment = 278, + JsxOpeningFragment = 279, + JsxClosingFragment = 280, + JsxAttribute = 281, + JsxAttributes = 282, + JsxSpreadAttribute = 283, + JsxExpression = 284, + CaseClause = 285, + DefaultClause = 286, + HeritageClause = 287, + CatchClause = 288, + AssertClause = 289, + AssertEntry = 290, + PropertyAssignment = 291, + ShorthandPropertyAssignment = 292, + SpreadAssignment = 293, + EnumMember = 294, + UnparsedPrologue = 295, + UnparsedPrepend = 296, + UnparsedText = 297, + UnparsedInternalText = 298, + UnparsedSyntheticReference = 299, + SourceFile = 300, + Bundle = 301, + UnparsedSource = 302, + InputFiles = 303, + JSDocTypeExpression = 304, + JSDocNameReference = 305, + JSDocAllType = 306, + JSDocUnknownType = 307, + JSDocNullableType = 308, + JSDocNonNullableType = 309, + JSDocOptionalType = 310, + JSDocFunctionType = 311, + JSDocVariadicType = 312, + JSDocNamepathType = 313, + JSDocComment = 314, + JSDocTypeLiteral = 315, + JSDocSignature = 316, + JSDocTag = 317, + JSDocAugmentsTag = 318, + JSDocImplementsTag = 319, + JSDocAuthorTag = 320, + JSDocDeprecatedTag = 321, + JSDocClassTag = 322, + JSDocPublicTag = 323, + JSDocPrivateTag = 324, + JSDocProtectedTag = 325, + JSDocReadonlyTag = 326, + JSDocCallbackTag = 327, + JSDocEnumTag = 328, + JSDocParameterTag = 329, + JSDocReturnTag = 330, + JSDocThisTag = 331, + JSDocTypeTag = 332, + JSDocTemplateTag = 333, + JSDocTypedefTag = 334, + JSDocSeeTag = 335, + JSDocPropertyTag = 336, + SyntaxList = 337, + NotEmittedStatement = 338, + PartiallyEmittedExpression = 339, + CommaListExpression = 340, + MergeDeclarationMarker = 341, + EndOfDeclarationMarker = 342, + SyntheticReferenceExpression = 343, + Count = 344, FirstAssignment = 62, LastAssignment = 77, FirstCompoundAssignment = 63, @@ -453,15 +456,15 @@ declare namespace ts { FirstReservedWord = 80, LastReservedWord = 115, FirstKeyword = 80, - LastKeyword = 156, + LastKeyword = 157, FirstFutureReservedWord = 116, LastFutureReservedWord = 124, - FirstTypeNode = 172, - LastTypeNode = 195, + FirstTypeNode = 173, + LastTypeNode = 196, FirstPunctuation = 18, LastPunctuation = 77, FirstToken = 0, - LastToken = 156, + LastToken = 157, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -470,19 +473,19 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 77, - FirstStatement = 232, - LastStatement = 248, - FirstNode = 157, - FirstJSDocNode = 301, - LastJSDocNode = 333, - FirstJSDocTagNode = 314, - LastJSDocTagNode = 333, + FirstStatement = 233, + LastStatement = 249, + FirstNode = 158, + FirstJSDocNode = 304, + LastJSDocNode = 336, + FirstJSDocTagNode = 317, + LastJSDocTagNode = 336, } export type TriviaSyntaxKind = SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia | SyntaxKind.NewLineTrivia | SyntaxKind.WhitespaceTrivia | SyntaxKind.ShebangTrivia | SyntaxKind.ConflictMarkerTrivia; export type LiteralSyntaxKind = SyntaxKind.NumericLiteral | SyntaxKind.BigIntLiteral | SyntaxKind.StringLiteral | SyntaxKind.JsxText | SyntaxKind.JsxTextAllWhiteSpaces | SyntaxKind.RegularExpressionLiteral | SyntaxKind.NoSubstitutionTemplateLiteral; export type PseudoLiteralSyntaxKind = SyntaxKind.TemplateHead | SyntaxKind.TemplateMiddle | SyntaxKind.TemplateTail; export type PunctuationSyntaxKind = SyntaxKind.OpenBraceToken | SyntaxKind.CloseBraceToken | SyntaxKind.OpenParenToken | SyntaxKind.CloseParenToken | SyntaxKind.OpenBracketToken | SyntaxKind.CloseBracketToken | SyntaxKind.DotToken | SyntaxKind.DotDotDotToken | SyntaxKind.SemicolonToken | SyntaxKind.CommaToken | SyntaxKind.QuestionDotToken | SyntaxKind.LessThanToken | SyntaxKind.LessThanSlashToken | SyntaxKind.GreaterThanToken | SyntaxKind.LessThanEqualsToken | SyntaxKind.GreaterThanEqualsToken | SyntaxKind.EqualsEqualsToken | SyntaxKind.ExclamationEqualsToken | SyntaxKind.EqualsEqualsEqualsToken | SyntaxKind.ExclamationEqualsEqualsToken | SyntaxKind.EqualsGreaterThanToken | SyntaxKind.PlusToken | SyntaxKind.MinusToken | SyntaxKind.AsteriskToken | SyntaxKind.AsteriskAsteriskToken | SyntaxKind.SlashToken | SyntaxKind.PercentToken | SyntaxKind.PlusPlusToken | SyntaxKind.MinusMinusToken | SyntaxKind.LessThanLessThanToken | SyntaxKind.GreaterThanGreaterThanToken | SyntaxKind.GreaterThanGreaterThanGreaterThanToken | SyntaxKind.AmpersandToken | SyntaxKind.BarToken | SyntaxKind.CaretToken | SyntaxKind.ExclamationToken | SyntaxKind.TildeToken | SyntaxKind.AmpersandAmpersandToken | SyntaxKind.BarBarToken | SyntaxKind.QuestionQuestionToken | SyntaxKind.QuestionToken | SyntaxKind.ColonToken | SyntaxKind.AtToken | SyntaxKind.BacktickToken | SyntaxKind.EqualsToken | SyntaxKind.PlusEqualsToken | SyntaxKind.MinusEqualsToken | SyntaxKind.AsteriskEqualsToken | SyntaxKind.AsteriskAsteriskEqualsToken | SyntaxKind.SlashEqualsToken | SyntaxKind.PercentEqualsToken | SyntaxKind.LessThanLessThanEqualsToken | SyntaxKind.GreaterThanGreaterThanEqualsToken | SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken | SyntaxKind.AmpersandEqualsToken | SyntaxKind.BarEqualsToken | SyntaxKind.CaretEqualsToken; - export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; + export type KeywordSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword | SyntaxKind.AssertKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.BreakKeyword | SyntaxKind.CaseKeyword | SyntaxKind.CatchKeyword | SyntaxKind.ClassKeyword | SyntaxKind.ConstKeyword | SyntaxKind.ConstructorKeyword | SyntaxKind.ContinueKeyword | SyntaxKind.DebuggerKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.DeleteKeyword | SyntaxKind.DoKeyword | SyntaxKind.ElseKeyword | SyntaxKind.EnumKeyword | SyntaxKind.ExportKeyword | SyntaxKind.ExtendsKeyword | SyntaxKind.FalseKeyword | SyntaxKind.FinallyKeyword | SyntaxKind.ForKeyword | SyntaxKind.FromKeyword | SyntaxKind.FunctionKeyword | SyntaxKind.GetKeyword | SyntaxKind.GlobalKeyword | SyntaxKind.IfKeyword | SyntaxKind.ImplementsKeyword | SyntaxKind.ImportKeyword | SyntaxKind.InferKeyword | SyntaxKind.InKeyword | SyntaxKind.InstanceOfKeyword | SyntaxKind.InterfaceKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.IsKeyword | SyntaxKind.KeyOfKeyword | SyntaxKind.LetKeyword | SyntaxKind.ModuleKeyword | SyntaxKind.NamespaceKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NewKeyword | SyntaxKind.NullKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.OfKeyword | SyntaxKind.PackageKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.RequireKeyword | SyntaxKind.ReturnKeyword | SyntaxKind.SetKeyword | SyntaxKind.StaticKeyword | SyntaxKind.StringKeyword | SyntaxKind.SuperKeyword | SyntaxKind.SwitchKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.ThisKeyword | SyntaxKind.ThrowKeyword | SyntaxKind.TrueKeyword | SyntaxKind.TryKeyword | SyntaxKind.TypeKeyword | SyntaxKind.TypeOfKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UniqueKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VarKeyword | SyntaxKind.VoidKeyword | SyntaxKind.WhileKeyword | SyntaxKind.WithKeyword | SyntaxKind.YieldKeyword; export type ModifierSyntaxKind = SyntaxKind.AbstractKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.ConstKeyword | SyntaxKind.DeclareKeyword | SyntaxKind.DefaultKeyword | SyntaxKind.ExportKeyword | SyntaxKind.PrivateKeyword | SyntaxKind.ProtectedKeyword | SyntaxKind.PublicKeyword | SyntaxKind.ReadonlyKeyword | SyntaxKind.StaticKeyword; export type KeywordTypeSyntaxKind = SyntaxKind.AnyKeyword | SyntaxKind.BigIntKeyword | SyntaxKind.BooleanKeyword | SyntaxKind.IntrinsicKeyword | SyntaxKind.NeverKeyword | SyntaxKind.NumberKeyword | SyntaxKind.ObjectKeyword | SyntaxKind.StringKeyword | SyntaxKind.SymbolKeyword | SyntaxKind.UndefinedKeyword | SyntaxKind.UnknownKeyword | SyntaxKind.VoidKeyword; export type TokenSyntaxKind = SyntaxKind.Unknown | SyntaxKind.EndOfFileToken | TriviaSyntaxKind | LiteralSyntaxKind | PseudoLiteralSyntaxKind | PunctuationSyntaxKind | SyntaxKind.Identifier | KeywordSyntaxKind; @@ -586,11 +589,13 @@ declare namespace ts { export interface KeywordToken extends Token { } export type AssertsKeyword = KeywordToken; + export type AssertKeyword = KeywordToken; export type AwaitKeyword = KeywordToken; /** @deprecated Use `AwaitKeyword` instead. */ export type AwaitKeywordToken = AwaitKeyword; /** @deprecated Use `AssertsKeyword` instead. */ export type AssertsToken = AssertsKeyword; + export type AssertToken = AssertKeyword; export interface ModifierToken extends KeywordToken { } export type AbstractKeyword = ModifierToken; @@ -1611,6 +1616,7 @@ declare namespace ts { readonly importClause?: ImportClause; /** If this is not a StringLiteral it will be a grammar error. */ readonly moduleSpecifier: Expression; + readonly assertClause?: AssertClause; } export type NamedImportBindings = NamespaceImport | NamedImports; export type NamedExportBindings = NamespaceExport | NamedExports; @@ -1621,6 +1627,19 @@ declare namespace ts { readonly name?: Identifier; readonly namedBindings?: NamedImportBindings; } + export type AssertionKey = Identifier | StringLiteral; + export interface AssertEntry extends Node { + readonly kind: SyntaxKind.AssertEntry; + readonly parent: AssertClause; + readonly name: AssertionKey; + readonly value: StringLiteral; + } + export interface AssertClause extends Node { + readonly kind: SyntaxKind.AssertClause; + readonly parent: ImportDeclaration | ExportDeclaration; + readonly elements: NodeArray; + readonly multiLine?: boolean; + } export interface NamespaceImport extends NamedDeclaration { readonly kind: SyntaxKind.NamespaceImport; readonly parent: ImportClause; @@ -1643,6 +1662,7 @@ declare namespace ts { readonly exportClause?: NamedExportBindings; /** If this is not a StringLiteral it will be a grammar error. */ readonly moduleSpecifier?: Expression; + readonly assertClause?: AssertClause; } export interface NamedImports extends Node { readonly kind: SyntaxKind.NamedImports; @@ -3407,10 +3427,14 @@ declare namespace ts { updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; - createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; - updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression): ImportDeclaration; + createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; + updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; + createAssertClause(elements: NodeArray, multiLine?: boolean): AssertClause; + updateAssertClause(node: AssertClause, elements: NodeArray, multiLine?: boolean): AssertClause; + createAssertEntry(name: AssertionKey, value: StringLiteral): AssertEntry; + updateAssertEntry(node: AssertEntry, name: AssertionKey, value: StringLiteral): AssertEntry; createNamespaceImport(name: Identifier): NamespaceImport; updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport; createNamespaceExport(name: Identifier): NamespaceExport; @@ -3421,8 +3445,8 @@ declare namespace ts { updateImportSpecifier(node: ImportSpecifier, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier; createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment; - createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression): ExportDeclaration; - updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined): ExportDeclaration; + createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, assertClause?: AssertClause): ExportDeclaration; + updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause: AssertClause | undefined): ExportDeclaration; createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; @@ -3827,6 +3851,7 @@ declare namespace ts { ObjectBindingPatternElements = 525136, ArrayBindingPatternElements = 524880, ObjectLiteralExpressionProperties = 526226, + ImportClauseEntries = 526226, ArrayLiteralExpressionElements = 8914, CommaListElements = 528, CallExpressionArguments = 2576, @@ -4437,6 +4462,9 @@ declare namespace ts { function isImportEqualsDeclaration(node: Node): node is ImportEqualsDeclaration; function isImportDeclaration(node: Node): node is ImportDeclaration; function isImportClause(node: Node): node is ImportClause; + function isAssertClause(node: Node): node is AssertClause; + function isAssertEntry(node: Node): node is AssertEntry; + function isAssertionKey(node: Node): node is AssertionKey; function isNamespaceImport(node: Node): node is NamespaceImport; function isNamespaceExport(node: Node): node is NamespaceExport; function isNamedImports(node: Node): node is NamedImports; @@ -6854,9 +6882,9 @@ declare namespace ts { /** @deprecated Use `factory.updateImportEqualsDeclaration` or the factory supplied by your transformation context instead. */ const updateImportEqualsDeclaration: (node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, name: Identifier, moduleReference: ModuleReference) => ImportEqualsDeclaration; /** @deprecated Use `factory.createImportDeclaration` or the factory supplied by your transformation context instead. */ - const createImportDeclaration: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression) => ImportDeclaration; + const createImportDeclaration: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined) => ImportDeclaration; /** @deprecated Use `factory.updateImportDeclaration` or the factory supplied by your transformation context instead. */ - const updateImportDeclaration: (node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression) => ImportDeclaration; + const updateImportDeclaration: (node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined) => ImportDeclaration; /** @deprecated Use `factory.createNamespaceImport` or the factory supplied by your transformation context instead. */ const createNamespaceImport: (name: Identifier) => NamespaceImport; /** @deprecated Use `factory.updateNamespaceImport` or the factory supplied by your transformation context instead. */ From 41a881cf8a041e63567244c842a6f715afc26966 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 23 Sep 2020 19:46:29 +0800 Subject: [PATCH 07/25] use module insted of target --- src/compiler/checker.ts | 8 +- src/compiler/diagnosticMessages.json | 2 +- ...ortAssertion1(module=commonjs).errors.txt} | 20 +-- .../importAssertion1(module=commonjs).js | 85 +++++++++++++ ...importAssertion1(module=commonjs).symbols} | 0 ...> importAssertion1(module=commonjs).types} | 0 ...importAssertion1(module=es2015).errors.txt | 69 +++++++++++ ....js => importAssertion1(module=es2015).js} | 0 ...> importAssertion1(module=es2015).symbols} | 0 ... => importAssertion1(module=es2015).types} | 0 ...mportAssertion1(module=esnext).errors.txt} | 0 ....js => importAssertion1(module=esnext).js} | 0 .../importAssertion1(module=esnext).symbols | 90 ++++++++++++++ .../importAssertion1(module=esnext).types | 114 ++++++++++++++++++ ...ortAssertion2(module=commonjs).errors.txt} | 24 ++-- .../importAssertion2(module=commonjs).js | 65 ++++++++++ ...importAssertion2(module=commonjs).symbols} | 0 ...> importAssertion2(module=commonjs).types} | 0 ...importAssertion2(module=es2015).errors.txt | 34 ++++++ ....js => importAssertion2(module=es2015).js} | 0 ...> importAssertion2(module=es2015).symbols} | 0 .../importAssertion2(module=es2015).types | 39 ++++++ ....js => importAssertion2(module=esnext).js} | 3 +- .../importAssertion2(module=esnext).symbols | 28 +++++ ... => importAssertion2(module=esnext).types} | 0 .../importAssertion/importAssertion1.ts | 4 +- .../importAssertion/importAssertion2.ts | 3 +- 27 files changed, 555 insertions(+), 33 deletions(-) rename tests/baselines/reference/{importAssertion1(target=es2020).errors.txt => importAssertion1(module=commonjs).errors.txt} (74%) create mode 100644 tests/baselines/reference/importAssertion1(module=commonjs).js rename tests/baselines/reference/{importAssertion1(target=es2020).symbols => importAssertion1(module=commonjs).symbols} (100%) rename tests/baselines/reference/{importAssertion1(target=es2020).types => importAssertion1(module=commonjs).types} (100%) create mode 100644 tests/baselines/reference/importAssertion1(module=es2015).errors.txt rename tests/baselines/reference/{importAssertion1(target=es2020).js => importAssertion1(module=es2015).js} (100%) rename tests/baselines/reference/{importAssertion1(target=esnext).symbols => importAssertion1(module=es2015).symbols} (100%) rename tests/baselines/reference/{importAssertion1(target=esnext).types => importAssertion1(module=es2015).types} (100%) rename tests/baselines/reference/{importAssertion1(target=esnext).errors.txt => importAssertion1(module=esnext).errors.txt} (100%) rename tests/baselines/reference/{importAssertion1(target=esnext).js => importAssertion1(module=esnext).js} (100%) create mode 100644 tests/baselines/reference/importAssertion1(module=esnext).symbols create mode 100644 tests/baselines/reference/importAssertion1(module=esnext).types rename tests/baselines/reference/{importAssertion2(target=es2020).errors.txt => importAssertion2(module=commonjs).errors.txt} (52%) create mode 100644 tests/baselines/reference/importAssertion2(module=commonjs).js rename tests/baselines/reference/{importAssertion2(target=es2020).symbols => importAssertion2(module=commonjs).symbols} (100%) rename tests/baselines/reference/{importAssertion2(target=es2020).types => importAssertion2(module=commonjs).types} (100%) create mode 100644 tests/baselines/reference/importAssertion2(module=es2015).errors.txt rename tests/baselines/reference/{importAssertion2(target=es2020).js => importAssertion2(module=es2015).js} (100%) rename tests/baselines/reference/{importAssertion2(target=esnext).symbols => importAssertion2(module=es2015).symbols} (100%) create mode 100644 tests/baselines/reference/importAssertion2(module=es2015).types rename tests/baselines/reference/{importAssertion2(target=esnext).js => importAssertion2(module=esnext).js} (91%) create mode 100644 tests/baselines/reference/importAssertion2(module=esnext).symbols rename tests/baselines/reference/{importAssertion2(target=esnext).types => importAssertion2(module=esnext).types} (100%) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7b6ac92c2df93..f15689225d1f8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -35932,9 +35932,8 @@ namespace ts { } function checkGrammarImportAssertion(declaration: ImportDeclaration | ExportDeclaration) { - const target = getEmitScriptTarget(compilerOptions); - if (target < ScriptTarget.ESNext && declaration.assertClause) { - grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_are_not_available_when_targeting_lower_than_esnext); + if (declaration.assertClause && moduleKind !== ModuleKind.ESNext) { + grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_flag_is_set_to_esnext); } } @@ -39874,8 +39873,7 @@ namespace ts { } function checkGrammarImportCallArguments(node: ImportCall, nodeArguments: NodeArray): boolean { - const target = getEmitScriptTarget(compilerOptions); - if (target < ScriptTarget.ESNext) { + if (moduleKind !== ModuleKind.ESNext) { if (nodeArguments.length !== 1) { return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e03d6c6b78596..b4fb60d70c38b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3055,7 +3055,7 @@ "category": "Error", "code": 2795 }, - "Import assertions are not available when targeting lower than esnext.": { + "Import assertions are only supported when the '--module' flag is set to 'esnext'.": { "category": "Error", "code": 2796 }, diff --git a/tests/baselines/reference/importAssertion1(target=es2020).errors.txt b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt similarity index 74% rename from tests/baselines/reference/importAssertion1(target=es2020).errors.txt rename to tests/baselines/reference/importAssertion1(module=commonjs).errors.txt index 845e88885908a..488e1dcd78a4c 100644 --- a/tests/baselines/reference/importAssertion1(target=es2020).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/esnext/importAssertion/1.ts(1,14): error TS2796: Import assertions are not available when targeting lower than esnext. -tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2796: Import assertions are not available when targeting lower than esnext. -tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2796: Import assertions are not available when targeting lower than esnext. -tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2796: Import assertions are not available when targeting lower than esnext. -tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/1.ts(1,14): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. tests/cases/conformance/esnext/importAssertion/3.ts(2,11): error TS1324: Dynamic import must have one specifier as an argument. tests/cases/conformance/esnext/importAssertion/3.ts(3,11): error TS1324: Dynamic import must have one specifier as an argument. tests/cases/conformance/esnext/importAssertion/3.ts(4,11): error TS1324: Dynamic import must have one specifier as an argument. @@ -18,13 +18,13 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: Dynamic ==== tests/cases/conformance/esnext/importAssertion/1.ts (3 errors) ==== import './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. import { a, b } from './0' assert { "type": "json" } ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. import * as foo from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. a; b; foo.a; @@ -33,10 +33,10 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: Dynamic ==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== import { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. a; b; c; diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).js b/tests/baselines/reference/importAssertion1(module=commonjs).js new file mode 100644 index 0000000000000..54f43364d841c --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=commonjs).js @@ -0,0 +1,85 @@ +//// [tests/cases/conformance/esnext/importAssertion/importAssertion1.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +import './0' assert { type: "json" } +import { a, b } from './0' assert { "type": "json" } +import * as foo from './0' assert { type: "json" } +a; +b; +foo.a; +foo.b; + +//// [2.ts] +import { a, b } from './0' assert {} +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +a; +b; +c; +d; + +//// [3.ts] +const a = import('./0') +const b = import('./0', { type: "json" }) +const c = import('./0', { type: "json", ttype: "typo" }) +const d = import('./0', { }) +declare function foo(): any; +const e = import('./0', foo()) +const f = import() +const g = import('./0', {}, {}) + + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = 1; +exports.b = 2; +//// [1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +require("./0"); +const _0_1 = require("./0"); +const foo = require("./0"); +_0_1.a; +_0_1.b; +foo.a; +foo.b; +//// [2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const _0_1 = require("./0"); +const _0_2 = require("./0"); +_0_1.a; +_0_1.b; +_0_2.a; +_0_2.b; +//// [3.js] +const a = Promise.resolve().then(() => require('./0')); +const b = Promise.resolve().then(() => require('./0')); +const c = Promise.resolve().then(() => require('./0')); +const d = Promise.resolve().then(() => require('./0')); +const e = Promise.resolve().then(() => require('./0')); +const f = Promise.resolve().then(() => require()); +const g = Promise.resolve().then(() => require('./0')); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +import './0' assert { type: "json" }; +//// [2.d.ts] +export {}; +//// [3.d.ts] +declare const a: Promise; +declare const b: Promise; +declare const c: Promise; +declare const d: Promise; +declare function foo(): any; +declare const e: Promise; +declare const f: Promise; +declare const g: Promise; diff --git a/tests/baselines/reference/importAssertion1(target=es2020).symbols b/tests/baselines/reference/importAssertion1(module=commonjs).symbols similarity index 100% rename from tests/baselines/reference/importAssertion1(target=es2020).symbols rename to tests/baselines/reference/importAssertion1(module=commonjs).symbols diff --git a/tests/baselines/reference/importAssertion1(target=es2020).types b/tests/baselines/reference/importAssertion1(module=commonjs).types similarity index 100% rename from tests/baselines/reference/importAssertion1(target=es2020).types rename to tests/baselines/reference/importAssertion1(module=commonjs).types diff --git a/tests/baselines/reference/importAssertion1(module=es2015).errors.txt b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt new file mode 100644 index 0000000000000..f7ed3f5f1ef8a --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt @@ -0,0 +1,69 @@ +tests/cases/conformance/esnext/importAssertion/1.ts(1,14): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/3.ts(1,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/esnext/importAssertion/3.ts(2,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/esnext/importAssertion/3.ts(3,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/esnext/importAssertion/3.ts(4,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/esnext/importAssertion/3.ts(6,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + + +==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/esnext/importAssertion/1.ts (3 errors) ==== + import './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + import { a, b } from './0' assert { "type": "json" } + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + import * as foo from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + a; + b; + foo.a; + foo.b; + +==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== + import { a, b } from './0' assert {} + ~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + a; + b; + c; + d; + +==== tests/cases/conformance/esnext/importAssertion/3.ts (7 errors) ==== + const a = import('./0') + ~~~~~~~~~~~~~ +!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + const b = import('./0', { type: "json" }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + const c = import('./0', { type: "json", ttype: "typo" }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + const d = import('./0', { }) + ~~~~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + declare function foo(): any; + const e = import('./0', foo()) + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + const f = import() + ~~~~~~~~ +!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + const g = import('./0', {}, {}) + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(target=es2020).js b/tests/baselines/reference/importAssertion1(module=es2015).js similarity index 100% rename from tests/baselines/reference/importAssertion1(target=es2020).js rename to tests/baselines/reference/importAssertion1(module=es2015).js diff --git a/tests/baselines/reference/importAssertion1(target=esnext).symbols b/tests/baselines/reference/importAssertion1(module=es2015).symbols similarity index 100% rename from tests/baselines/reference/importAssertion1(target=esnext).symbols rename to tests/baselines/reference/importAssertion1(module=es2015).symbols diff --git a/tests/baselines/reference/importAssertion1(target=esnext).types b/tests/baselines/reference/importAssertion1(module=es2015).types similarity index 100% rename from tests/baselines/reference/importAssertion1(target=esnext).types rename to tests/baselines/reference/importAssertion1(module=es2015).types diff --git a/tests/baselines/reference/importAssertion1(target=esnext).errors.txt b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt similarity index 100% rename from tests/baselines/reference/importAssertion1(target=esnext).errors.txt rename to tests/baselines/reference/importAssertion1(module=esnext).errors.txt diff --git a/tests/baselines/reference/importAssertion1(target=esnext).js b/tests/baselines/reference/importAssertion1(module=esnext).js similarity index 100% rename from tests/baselines/reference/importAssertion1(target=esnext).js rename to tests/baselines/reference/importAssertion1(module=esnext).js diff --git a/tests/baselines/reference/importAssertion1(module=esnext).symbols b/tests/baselines/reference/importAssertion1(module=esnext).symbols new file mode 100644 index 0000000000000..9d6fef3f0fc61 --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=esnext).symbols @@ -0,0 +1,90 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +import './0' assert { type: "json" } +import { a, b } from './0' assert { "type": "json" } +>a : Symbol(a, Decl(1.ts, 1, 8)) +>b : Symbol(b, Decl(1.ts, 1, 11)) + +import * as foo from './0' assert { type: "json" } +>foo : Symbol(foo, Decl(1.ts, 2, 6)) + +a; +>a : Symbol(a, Decl(1.ts, 1, 8)) + +b; +>b : Symbol(b, Decl(1.ts, 1, 11)) + +foo.a; +>foo.a : Symbol(a, Decl(0.ts, 0, 12)) +>foo : Symbol(foo, Decl(1.ts, 2, 6)) +>a : Symbol(a, Decl(0.ts, 0, 12)) + +foo.b; +>foo.b : Symbol(b, Decl(0.ts, 1, 12)) +>foo : Symbol(foo, Decl(1.ts, 2, 6)) +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +import { a, b } from './0' assert {} +>a : Symbol(a, Decl(2.ts, 0, 8)) +>b : Symbol(b, Decl(2.ts, 0, 11)) + +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : Symbol(a, Decl(0.ts, 0, 12)) +>c : Symbol(c, Decl(2.ts, 1, 8)) +>b : Symbol(b, Decl(0.ts, 1, 12)) +>d : Symbol(d, Decl(2.ts, 1, 16)) + +a; +>a : Symbol(a, Decl(2.ts, 0, 8)) + +b; +>b : Symbol(b, Decl(2.ts, 0, 11)) + +c; +>c : Symbol(c, Decl(2.ts, 1, 8)) + +d; +>d : Symbol(d, Decl(2.ts, 1, 16)) + +=== tests/cases/conformance/esnext/importAssertion/3.ts === +const a = import('./0') +>a : Symbol(a, Decl(3.ts, 0, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) + +const b = import('./0', { type: "json" }) +>b : Symbol(b, Decl(3.ts, 1, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>type : Symbol(type, Decl(3.ts, 1, 25)) + +const c = import('./0', { type: "json", ttype: "typo" }) +>c : Symbol(c, Decl(3.ts, 2, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>type : Symbol(type, Decl(3.ts, 2, 25)) +>ttype : Symbol(ttype, Decl(3.ts, 2, 39)) + +const d = import('./0', { }) +>d : Symbol(d, Decl(3.ts, 3, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) + +declare function foo(): any; +>foo : Symbol(foo, Decl(3.ts, 3, 28)) + +const e = import('./0', foo()) +>e : Symbol(e, Decl(3.ts, 5, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>foo : Symbol(foo, Decl(3.ts, 3, 28)) + +const f = import() +>f : Symbol(f, Decl(3.ts, 6, 5)) + +const g = import('./0', {}, {}) +>g : Symbol(g, Decl(3.ts, 7, 5)) +>'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) + diff --git a/tests/baselines/reference/importAssertion1(module=esnext).types b/tests/baselines/reference/importAssertion1(module=esnext).types new file mode 100644 index 0000000000000..38975059069e9 --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=esnext).types @@ -0,0 +1,114 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +import './0' assert { type: "json" } +>type : any + +import { a, b } from './0' assert { "type": "json" } +>a : 1 +>b : 2 + +import * as foo from './0' assert { type: "json" } +>foo : typeof foo +>type : any + +a; +>a : 1 + +b; +>b : 2 + +foo.a; +>foo.a : 1 +>foo : typeof foo +>a : 1 + +foo.b; +>foo.b : 2 +>foo : typeof foo +>b : 2 + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +import { a, b } from './0' assert {} +>a : 1 +>b : 2 + +import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : 1 +>c : 1 +>b : 2 +>d : 2 +>a : any +>b : any +>c : any + +a; +>a : 1 + +b; +>b : 2 + +c; +>c : 1 + +d; +>d : 2 + +=== tests/cases/conformance/esnext/importAssertion/3.ts === +const a = import('./0') +>a : Promise +>import('./0') : Promise +>'./0' : "./0" + +const b = import('./0', { type: "json" }) +>b : Promise +>import('./0', { type: "json" }) : Promise +>'./0' : "./0" +>{ type: "json" } : { type: string; } +>type : string +>"json" : "json" + +const c = import('./0', { type: "json", ttype: "typo" }) +>c : Promise +>import('./0', { type: "json", ttype: "typo" }) : Promise +>'./0' : "./0" +>{ type: "json", ttype: "typo" } : { type: string; ttype: string; } +>type : string +>"json" : "json" +>ttype : string +>"typo" : "typo" + +const d = import('./0', { }) +>d : Promise +>import('./0', { }) : Promise +>'./0' : "./0" +>{ } : {} + +declare function foo(): any; +>foo : () => any + +const e = import('./0', foo()) +>e : Promise +>import('./0', foo()) : Promise +>'./0' : "./0" +>foo() : any +>foo : () => any + +const f = import() +>f : Promise +>import() : Promise + +const g = import('./0', {}, {}) +>g : Promise +>import('./0', {}, {}) : Promise +>'./0' : "./0" +>{} : {} +>{} : {} + diff --git a/tests/baselines/reference/importAssertion2(target=es2020).errors.txt b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt similarity index 52% rename from tests/baselines/reference/importAssertion2(target=es2020).errors.txt rename to tests/baselines/reference/importAssertion2(module=commonjs).errors.txt index c2b30dd5f0673..20091ac8bac56 100644 --- a/tests/baselines/reference/importAssertion2(target=es2020).errors.txt +++ b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/esnext/importAssertion/1.ts(1,22): error TS2796: Import assertions are not available when targeting lower than esnext. -tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2796: Import assertions are not available when targeting lower than esnext. -tests/cases/conformance/esnext/importAssertion/1.ts(3,21): error TS2796: Import assertions are not available when targeting lower than esnext. -tests/cases/conformance/esnext/importAssertion/1.ts(4,27): error TS2796: Import assertions are not available when targeting lower than esnext. -tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2796: Import assertions are not available when targeting lower than esnext. -tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2796: Import assertions are not available when targeting lower than esnext. +tests/cases/conformance/esnext/importAssertion/1.ts(1,22): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(3,21): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(4,27): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. ==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== @@ -13,22 +13,22 @@ tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2796: Import ==== tests/cases/conformance/esnext/importAssertion/1.ts (4 errors) ==== export {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. export { a, b } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. export * from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. export * as ns from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. ==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== export { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2796: Import assertions are not available when targeting lower than esnext. +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).js b/tests/baselines/reference/importAssertion2(module=commonjs).js new file mode 100644 index 0000000000000..f3ea3204eb652 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=commonjs).js @@ -0,0 +1,65 @@ +//// [tests/cases/conformance/esnext/importAssertion/importAssertion2.ts] //// + +//// [0.ts] +export const a = 1; +export const b = 2; + +//// [1.ts] +export {} from './0' assert { type: "json" } +export { a, b } from './0' assert { type: "json" } +export * from './0' assert { type: "json" } +export * as ns from './0' assert { type: "json" } + +//// [2.ts] +export { a, b } from './0' assert {} +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } + + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.b = exports.a = void 0; +exports.a = 1; +exports.b = 2; +//// [1.js] +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ns = exports.b = exports.a = void 0; +var _0_1 = require("./0"); +Object.defineProperty(exports, "a", { enumerable: true, get: function () { return _0_1.a; } }); +Object.defineProperty(exports, "b", { enumerable: true, get: function () { return _0_1.b; } }); +__exportStar(require("./0"), exports); +exports.ns = require("./0"); +//// [2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.d = exports.c = exports.b = exports.a = void 0; +var _0_1 = require("./0"); +Object.defineProperty(exports, "a", { enumerable: true, get: function () { return _0_1.a; } }); +Object.defineProperty(exports, "b", { enumerable: true, get: function () { return _0_1.b; } }); +var _0_2 = require("./0"); +Object.defineProperty(exports, "c", { enumerable: true, get: function () { return _0_2.a; } }); +Object.defineProperty(exports, "d", { enumerable: true, get: function () { return _0_2.b; } }); + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export {} from './0' assert { type: "json" }; +export { a, b } from './0' assert { type: "json" }; +export * from './0' assert { type: "json" }; +export * as ns from './0' assert { type: "json" }; +//// [2.d.ts] +export { a, b } from './0' assert {}; +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; diff --git a/tests/baselines/reference/importAssertion2(target=es2020).symbols b/tests/baselines/reference/importAssertion2(module=commonjs).symbols similarity index 100% rename from tests/baselines/reference/importAssertion2(target=es2020).symbols rename to tests/baselines/reference/importAssertion2(module=commonjs).symbols diff --git a/tests/baselines/reference/importAssertion2(target=es2020).types b/tests/baselines/reference/importAssertion2(module=commonjs).types similarity index 100% rename from tests/baselines/reference/importAssertion2(target=es2020).types rename to tests/baselines/reference/importAssertion2(module=commonjs).types diff --git a/tests/baselines/reference/importAssertion2(module=es2015).errors.txt b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt new file mode 100644 index 0000000000000..20091ac8bac56 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/esnext/importAssertion/1.ts(1,22): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(3,21): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(4,27): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + + +==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/esnext/importAssertion/1.ts (4 errors) ==== + export {} from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + export { a, b } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + export * from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + export * as ns from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + +==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== + export { a, b } from './0' assert {} + ~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2796: Import assertions are only supported when the '--module' flag is set to 'esnext'. + \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion2(target=es2020).js b/tests/baselines/reference/importAssertion2(module=es2015).js similarity index 100% rename from tests/baselines/reference/importAssertion2(target=es2020).js rename to tests/baselines/reference/importAssertion2(module=es2015).js diff --git a/tests/baselines/reference/importAssertion2(target=esnext).symbols b/tests/baselines/reference/importAssertion2(module=es2015).symbols similarity index 100% rename from tests/baselines/reference/importAssertion2(target=esnext).symbols rename to tests/baselines/reference/importAssertion2(module=es2015).symbols diff --git a/tests/baselines/reference/importAssertion2(module=es2015).types b/tests/baselines/reference/importAssertion2(module=es2015).types new file mode 100644 index 0000000000000..6dd54c956508d --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=es2015).types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +export {} from './0' assert { type: "json" } +>type : any + +export { a, b } from './0' assert { type: "json" } +>a : 1 +>b : 2 +>type : any + +export * from './0' assert { type: "json" } +>type : any + +export * as ns from './0' assert { type: "json" } +>ns : typeof ns +>type : any + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +export { a, b } from './0' assert {} +>a : 1 +>b : 2 + +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : 1 +>c : 1 +>b : 2 +>d : 2 +>a : any +>b : any +>c : any + diff --git a/tests/baselines/reference/importAssertion2(target=esnext).js b/tests/baselines/reference/importAssertion2(module=esnext).js similarity index 91% rename from tests/baselines/reference/importAssertion2(target=esnext).js rename to tests/baselines/reference/importAssertion2(module=esnext).js index 19d22a66be4d7..a572b3ed06287 100644 --- a/tests/baselines/reference/importAssertion2(target=esnext).js +++ b/tests/baselines/reference/importAssertion2(module=esnext).js @@ -21,8 +21,7 @@ export const b = 2; //// [1.js] export { a, b } from './0' assert { type: "json" }; export * from './0' assert { type: "json" }; -import * as ns_1 from './0' assert { type: "json" }; -export { ns_1 as ns }; +export * as ns from './0' assert { type: "json" }; //// [2.js] export { a, b } from './0' assert {}; export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; diff --git a/tests/baselines/reference/importAssertion2(module=esnext).symbols b/tests/baselines/reference/importAssertion2(module=esnext).symbols new file mode 100644 index 0000000000000..818c5391cf50c --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=esnext).symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/esnext/importAssertion/0.ts === +export const a = 1; +>a : Symbol(a, Decl(0.ts, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(0.ts, 1, 12)) + +=== tests/cases/conformance/esnext/importAssertion/1.ts === +export {} from './0' assert { type: "json" } +export { a, b } from './0' assert { type: "json" } +>a : Symbol(a, Decl(1.ts, 1, 8)) +>b : Symbol(b, Decl(1.ts, 1, 11)) + +export * from './0' assert { type: "json" } +export * as ns from './0' assert { type: "json" } +>ns : Symbol(ns, Decl(1.ts, 3, 6)) + +=== tests/cases/conformance/esnext/importAssertion/2.ts === +export { a, b } from './0' assert {} +>a : Symbol(a, Decl(2.ts, 0, 8)) +>b : Symbol(b, Decl(2.ts, 0, 11)) + +export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } +>a : Symbol(a, Decl(0.ts, 0, 12)) +>c : Symbol(c, Decl(2.ts, 1, 8)) +>b : Symbol(b, Decl(0.ts, 1, 12)) +>d : Symbol(d, Decl(2.ts, 1, 16)) + diff --git a/tests/baselines/reference/importAssertion2(target=esnext).types b/tests/baselines/reference/importAssertion2(module=esnext).types similarity index 100% rename from tests/baselines/reference/importAssertion2(target=esnext).types rename to tests/baselines/reference/importAssertion2(module=esnext).types diff --git a/tests/cases/conformance/esnext/importAssertion/importAssertion1.ts b/tests/cases/conformance/esnext/importAssertion/importAssertion1.ts index 18db235cc8520..d938b44bbbf17 100644 --- a/tests/cases/conformance/esnext/importAssertion/importAssertion1.ts +++ b/tests/cases/conformance/esnext/importAssertion/importAssertion1.ts @@ -1,6 +1,6 @@ -// @target: esnext, es2020 // @declaration: true -// @module: esnext +// @target: es2015 +// @module: es2015, commonjs, esnext // @filename: 0.ts export const a = 1; diff --git a/tests/cases/conformance/esnext/importAssertion/importAssertion2.ts b/tests/cases/conformance/esnext/importAssertion/importAssertion2.ts index df2730e515a44..42a26af43eb7c 100644 --- a/tests/cases/conformance/esnext/importAssertion/importAssertion2.ts +++ b/tests/cases/conformance/esnext/importAssertion/importAssertion2.ts @@ -1,5 +1,6 @@ -// @target: esnext, es2020 // @declaration: true +// @target: es2015 +// @module: es2015, commonjs, esnext // @filename: 0.ts export const a = 1; From 46a3eb1bafa4f035bda6b4a738990b914b9e7900 Mon Sep 17 00:00:00 2001 From: kingwl Date: Wed, 23 Sep 2020 21:56:35 +0800 Subject: [PATCH 08/25] strip assertion in d.ts --- src/compiler/transformers/declarations.ts | 12 ++++++------ .../reference/importAssertion1(module=commonjs).js | 2 +- .../reference/importAssertion1(module=es2015).js | 2 +- .../reference/importAssertion1(module=esnext).js | 2 +- .../reference/importAssertion2(module=commonjs).js | 12 ++++++------ .../reference/importAssertion2(module=es2015).js | 12 ++++++------ .../reference/importAssertion2(module=esnext).js | 12 ++++++------ 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index d1505304f85c7..51a76f50440c7 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -703,7 +703,7 @@ namespace ts { decl.modifiers, decl.importClause, rewriteModuleSpecifier(decl, decl.moduleSpecifier), - decl.assertClause + /*assertClause*/ undefined ); } // The `importClause` visibility corresponds to the default's visibility. @@ -715,7 +715,7 @@ namespace ts { decl.importClause.isTypeOnly, visibleDefaultBinding, /*namedBindings*/ undefined, - ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), decl.assertClause); + ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), /*assertClause*/ undefined); } if (decl.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { // Namespace import (optionally with visible default) @@ -725,7 +725,7 @@ namespace ts { decl.importClause.isTypeOnly, visibleDefaultBinding, namedBindings, - ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), decl.assertClause) : undefined; + ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), /*assertClause*/ undefined) : undefined; } // Named imports (optionally with visible default) const bindingList = mapDefined(decl.importClause.namedBindings.elements, b => resolver.isDeclarationVisible(b) ? b : undefined); @@ -741,7 +741,7 @@ namespace ts { bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined, ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), - decl.assertClause + /*assertClause*/ undefined ); } // Augmentation of export depends on import @@ -752,7 +752,7 @@ namespace ts { decl.modifiers, /*importClause*/ undefined, rewriteModuleSpecifier(decl, decl.moduleSpecifier), - decl.assertClause + /*assertClause*/ undefined ); } // Nothing visible @@ -1087,7 +1087,7 @@ namespace ts { input.isTypeOnly, input.exportClause, rewriteModuleSpecifier(input, input.moduleSpecifier), - input.assertClause + /*assertClause*/ undefined ); } case SyntaxKind.ExportAssignment: { diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).js b/tests/baselines/reference/importAssertion1(module=commonjs).js index 54f43364d841c..1b580c8f3f2b0 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).js +++ b/tests/baselines/reference/importAssertion1(module=commonjs).js @@ -71,7 +71,7 @@ const g = Promise.resolve().then(() => require('./0')); export declare const a = 1; export declare const b = 2; //// [1.d.ts] -import './0' assert { type: "json" }; +import './0'; //// [2.d.ts] export {}; //// [3.d.ts] diff --git a/tests/baselines/reference/importAssertion1(module=es2015).js b/tests/baselines/reference/importAssertion1(module=es2015).js index b123b2e01104e..cdc99083e8c54 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).js +++ b/tests/baselines/reference/importAssertion1(module=es2015).js @@ -64,7 +64,7 @@ const g = import('./0', {}, {}); export declare const a = 1; export declare const b = 2; //// [1.d.ts] -import './0' assert { type: "json" }; +import './0'; //// [2.d.ts] export {}; //// [3.d.ts] diff --git a/tests/baselines/reference/importAssertion1(module=esnext).js b/tests/baselines/reference/importAssertion1(module=esnext).js index b123b2e01104e..cdc99083e8c54 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).js +++ b/tests/baselines/reference/importAssertion1(module=esnext).js @@ -64,7 +64,7 @@ const g = import('./0', {}, {}); export declare const a = 1; export declare const b = 2; //// [1.d.ts] -import './0' assert { type: "json" }; +import './0'; //// [2.d.ts] export {}; //// [3.d.ts] diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).js b/tests/baselines/reference/importAssertion2(module=commonjs).js index f3ea3204eb652..3fd1dd70a0afe 100644 --- a/tests/baselines/reference/importAssertion2(module=commonjs).js +++ b/tests/baselines/reference/importAssertion2(module=commonjs).js @@ -56,10 +56,10 @@ Object.defineProperty(exports, "d", { enumerable: true, get: function () { retur export declare const a = 1; export declare const b = 2; //// [1.d.ts] -export {} from './0' assert { type: "json" }; -export { a, b } from './0' assert { type: "json" }; -export * from './0' assert { type: "json" }; -export * as ns from './0' assert { type: "json" }; +export {} from './0'; +export { a, b } from './0'; +export * from './0'; +export * as ns from './0'; //// [2.d.ts] -export { a, b } from './0' assert {}; -export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; +export { a, b } from './0'; +export { a as c, b as d } from './0'; diff --git a/tests/baselines/reference/importAssertion2(module=es2015).js b/tests/baselines/reference/importAssertion2(module=es2015).js index 19d22a66be4d7..a929a99e4d0df 100644 --- a/tests/baselines/reference/importAssertion2(module=es2015).js +++ b/tests/baselines/reference/importAssertion2(module=es2015).js @@ -32,10 +32,10 @@ export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; export declare const a = 1; export declare const b = 2; //// [1.d.ts] -export {} from './0' assert { type: "json" }; -export { a, b } from './0' assert { type: "json" }; -export * from './0' assert { type: "json" }; -export * as ns from './0' assert { type: "json" }; +export {} from './0'; +export { a, b } from './0'; +export * from './0'; +export * as ns from './0'; //// [2.d.ts] -export { a, b } from './0' assert {}; -export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; +export { a, b } from './0'; +export { a as c, b as d } from './0'; diff --git a/tests/baselines/reference/importAssertion2(module=esnext).js b/tests/baselines/reference/importAssertion2(module=esnext).js index a572b3ed06287..ed362d4a2c314 100644 --- a/tests/baselines/reference/importAssertion2(module=esnext).js +++ b/tests/baselines/reference/importAssertion2(module=esnext).js @@ -31,10 +31,10 @@ export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; export declare const a = 1; export declare const b = 2; //// [1.d.ts] -export {} from './0' assert { type: "json" }; -export { a, b } from './0' assert { type: "json" }; -export * from './0' assert { type: "json" }; -export * as ns from './0' assert { type: "json" }; +export {} from './0'; +export { a, b } from './0'; +export * from './0'; +export * as ns from './0'; //// [2.d.ts] -export { a, b } from './0' assert {}; -export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }; +export { a, b } from './0'; +export { a as c, b as d } from './0'; From adcfd1b0bbeaf1556ed30dbc57b1439228c752e0 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 7 Jan 2021 17:40:48 +0800 Subject: [PATCH 09/25] Update new baseline --- .../reference/importAssertion1(module=esnext).errors.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt index 0e9b637b267cc..ddc2bcaeb2919 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1392: Dynamic import must have a specifier as arguments and an optional assertion -tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1392: Dynamic import must have a specifier as arguments and an optional assertion +tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1431: Dynamic import must have a specifier as arguments and an optional assertion +tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1431: Dynamic import must have a specifier as arguments and an optional assertion ==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== @@ -32,8 +32,8 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1392: Dynamic const e = import('./0', foo()) const f = import() ~~~~~~~~ -!!! error TS1392: Dynamic import must have a specifier as arguments and an optional assertion +!!! error TS1431: Dynamic import must have a specifier as arguments and an optional assertion const g = import('./0', {}, {}) ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1392: Dynamic import must have a specifier as arguments and an optional assertion +!!! error TS1431: Dynamic import must have a specifier as arguments and an optional assertion \ No newline at end of file From 4f22a601157fbe9306eb1c04c7f4c89b4771333f Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 8 Mar 2021 16:30:10 +0800 Subject: [PATCH 10/25] accept baseline --- src/compiler/emitter.ts | 8 ++++ .../awaitInNonAsyncFunction.errors.txt | 4 +- .../excessivelyLargeTupleSpread.errors.txt | 12 +++--- .../mixinAbstractClasses.2.errors.txt | 4 +- .../parser.forAwait.es2018.errors.txt | 16 ++++---- ....1(module=esnext,target=es2015).errors.txt | 4 +- ....1(module=system,target=es2015).errors.txt | 4 +- .../topLevelAwaitNonModule.errors.txt | 4 +- .../reference/typedArrays-es5.errors.txt | 40 +++++++++---------- 9 files changed, 52 insertions(+), 44 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f7030ca5dc979..50feb7ac793be 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3216,6 +3216,10 @@ namespace ts { writeSpace(); } emit(node.moduleSpecifier); + if (node.assertClause) { + writeSpace(); + emit(node.assertClause); + } writeTrailingSemicolon(); } @@ -3282,6 +3286,10 @@ namespace ts { writeSpace(); emit(node.moduleSpecifier); } + if (node.assertClause) { + writeSpace(); + emit(node.assertClause); + } writeTrailingSemicolon(); } diff --git a/tests/baselines/reference/awaitInNonAsyncFunction.errors.txt b/tests/baselines/reference/awaitInNonAsyncFunction.errors.txt index ee1aa75d3cc74..9c99d4cc1e10a 100644 --- a/tests/baselines/reference/awaitInNonAsyncFunction.errors.txt +++ b/tests/baselines/reference/awaitInNonAsyncFunction.errors.txt @@ -12,7 +12,7 @@ tests/cases/compiler/awaitInNonAsyncFunction.ts(30,9): error TS1103: 'for await' tests/cases/compiler/awaitInNonAsyncFunction.ts(31,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules. tests/cases/compiler/awaitInNonAsyncFunction.ts(34,7): error TS1103: 'for await' loops are only allowed within async functions and at the top levels of modules. tests/cases/compiler/awaitInNonAsyncFunction.ts(35,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules. -tests/cases/compiler/awaitInNonAsyncFunction.ts(39,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/compiler/awaitInNonAsyncFunction.ts(39,5): error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. tests/cases/compiler/awaitInNonAsyncFunction.ts(40,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. @@ -97,7 +97,7 @@ tests/cases/compiler/awaitInNonAsyncFunction.ts(40,1): error TS1378: Top-level ' for await (const _ of []); ~~~~~ -!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +!!! error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. await null; ~~~~~ !!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. \ No newline at end of file diff --git a/tests/baselines/reference/excessivelyLargeTupleSpread.errors.txt b/tests/baselines/reference/excessivelyLargeTupleSpread.errors.txt index 0b5e44369c7d6..7be7f0cb06513 100644 --- a/tests/baselines/reference/excessivelyLargeTupleSpread.errors.txt +++ b/tests/baselines/reference/excessivelyLargeTupleSpread.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/excessivelyLargeTupleSpread.ts(6,10): error TS2589: Type instantiation is excessively deep and possibly infinite. -tests/cases/compiler/excessivelyLargeTupleSpread.ts(6,10): error TS2799: Type produces a tuple type that is too large to represent. -tests/cases/compiler/excessivelyLargeTupleSpread.ts(22,12): error TS2799: Type produces a tuple type that is too large to represent. -tests/cases/compiler/excessivelyLargeTupleSpread.ts(38,13): error TS2800: Expression produces a tuple type that is too large to represent. +tests/cases/compiler/excessivelyLargeTupleSpread.ts(6,10): error TS2800: Type produces a tuple type that is too large to represent. +tests/cases/compiler/excessivelyLargeTupleSpread.ts(22,12): error TS2800: Type produces a tuple type that is too large to represent. +tests/cases/compiler/excessivelyLargeTupleSpread.ts(38,13): error TS2801: Expression produces a tuple type that is too large to represent. ==== tests/cases/compiler/excessivelyLargeTupleSpread.ts (4 errors) ==== @@ -14,7 +14,7 @@ tests/cases/compiler/excessivelyLargeTupleSpread.ts(38,13): error TS2800: Expres ~~~~~~~~~~~~~ !!! error TS2589: Type instantiation is excessively deep and possibly infinite. ~~~~~~~~~~~~~ -!!! error TS2799: Type produces a tuple type that is too large to represent. +!!! error TS2800: Type produces a tuple type that is too large to represent. type T0 = [any]; type T1 = [...T0, ...T0]; @@ -32,7 +32,7 @@ tests/cases/compiler/excessivelyLargeTupleSpread.ts(38,13): error TS2800: Expres type T13 = [...T12, ...T12]; type T14 = [...T13, ...T13]; // 2^14 > 10,000 ~~~~~~~~~~~~~~~~ -!!! error TS2799: Type produces a tuple type that is too large to represent. +!!! error TS2800: Type produces a tuple type that is too large to represent. const a0 = [0] as const; const a1 = [...a0, ...a0] as const; @@ -50,5 +50,5 @@ tests/cases/compiler/excessivelyLargeTupleSpread.ts(38,13): error TS2800: Expres const a13 = [...a12, ...a12] as const; const a14 = [...a13, ...a13] as const; // 2^14 > 10,000 ~~~~~~~~~~~~~~~~ -!!! error TS2800: Expression produces a tuple type that is too large to represent. +!!! error TS2801: Expression produces a tuple type that is too large to represent. \ No newline at end of file diff --git a/tests/baselines/reference/mixinAbstractClasses.2.errors.txt b/tests/baselines/reference/mixinAbstractClasses.2.errors.txt index 99a92c854628c..6186f19af4a92 100644 --- a/tests/baselines/reference/mixinAbstractClasses.2.errors.txt +++ b/tests/baselines/reference/mixinAbstractClasses.2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/mixinAbstractClasses.2.ts(7,11): error TS2797: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. +tests/cases/conformance/classes/mixinAbstractClasses.2.ts(7,11): error TS2798: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. tests/cases/conformance/classes/mixinAbstractClasses.2.ts(21,7): error TS2515: Non-abstract class 'DerivedFromAbstract' does not implement inherited abstract member 'abstractBaseMethod' from class 'AbstractBase & Mixin'. tests/cases/conformance/classes/mixinAbstractClasses.2.ts(25,1): error TS2511: Cannot create an instance of an abstract class. @@ -12,7 +12,7 @@ tests/cases/conformance/classes/mixinAbstractClasses.2.ts(25,1): error TS2511: C // error expected: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. class MixinClass extends baseClass implements Mixin { ~~~~~~~~~~ -!!! error TS2797: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. +!!! error TS2798: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. mixinMethod() { } } diff --git a/tests/baselines/reference/parser.forAwait.es2018.errors.txt b/tests/baselines/reference/parser.forAwait.es2018.errors.txt index cc70ef748d0a7..cfc346fbb8a17 100644 --- a/tests/baselines/reference/parser.forAwait.es2018.errors.txt +++ b/tests/baselines/reference/parser.forAwait.es2018.errors.txt @@ -7,11 +7,11 @@ tests/cases/conformance/parser/ecmascript2018/forAwait/inFunctionDeclWithDeclIsE tests/cases/conformance/parser/ecmascript2018/forAwait/inFunctionDeclWithExprIsError.ts(3,9): error TS1103: 'for await' loops are only allowed within async functions and at the top levels of modules. tests/cases/conformance/parser/ecmascript2018/forAwait/inGeneratorWithDeclIsError.ts(3,9): error TS1103: 'for await' loops are only allowed within async functions and at the top levels of modules. tests/cases/conformance/parser/ecmascript2018/forAwait/inGeneratorWithExprIsError.ts(3,9): error TS1103: 'for await' loops are only allowed within async functions and at the top levels of modules. -tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. -tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,23): error TS2304: Cannot find name 'y'. -tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. -tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,12): error TS2304: Cannot find name 'x'. tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,17): error TS2304: Cannot find name 'y'. @@ -19,18 +19,18 @@ tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.t ==== tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts (3 errors) ==== for await (const x of y) { ~~~~~ -!!! error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +!!! error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. ~~~~~ -!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +!!! error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. ~ !!! error TS2304: Cannot find name 'y'. } ==== tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts (4 errors) ==== for await (x of y) { ~~~~~ -!!! error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +!!! error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. ~~~~~ -!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +!!! error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. ~ !!! error TS2304: Cannot find name 'x'. ~ diff --git a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt index aeea7ac641fa2..a09b9ec79f9a2 100644 --- a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt +++ b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/externalModules/index.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/externalModules/index.ts(46,3): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. -tests/cases/conformance/externalModules/other.ts(9,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/conformance/externalModules/other.ts(9,5): error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. ==== tests/cases/conformance/externalModules/index.ts (2 errors) ==== @@ -84,7 +84,7 @@ tests/cases/conformance/externalModules/other.ts(9,5): error TS1432: Top-level ' for await (const item of arr) { ~~~~~ -!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +!!! error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. item; } \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt index aeea7ac641fa2..a09b9ec79f9a2 100644 --- a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt +++ b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/externalModules/index.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/externalModules/index.ts(46,3): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. -tests/cases/conformance/externalModules/other.ts(9,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/conformance/externalModules/other.ts(9,5): error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. ==== tests/cases/conformance/externalModules/index.ts (2 errors) ==== @@ -84,7 +84,7 @@ tests/cases/conformance/externalModules/other.ts(9,5): error TS1432: Top-level ' for await (const item of arr) { ~~~~~ -!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +!!! error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. item; } \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitNonModule.errors.txt b/tests/baselines/reference/topLevelAwaitNonModule.errors.txt index fd039af1ea0d0..b618569391815 100644 --- a/tests/baselines/reference/topLevelAwaitNonModule.errors.txt +++ b/tests/baselines/reference/topLevelAwaitNonModule.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(1,1): error TS1375: 'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(1,7): error TS2304: Cannot find name 'x'. -tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(5,5): error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(5,5): error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. ==== tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts (3 errors) ==== @@ -14,7 +14,7 @@ tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(5,5): error TS for await (const item of arr) { ~~~~~ -!!! error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +!!! error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. item; } \ No newline at end of file diff --git a/tests/baselines/reference/typedArrays-es5.errors.txt b/tests/baselines/reference/typedArrays-es5.errors.txt index c46b46566f815..b80d279951f13 100644 --- a/tests/baselines/reference/typedArrays-es5.errors.txt +++ b/tests/baselines/reference/typedArrays-es5.errors.txt @@ -1,65 +1,65 @@ -tests/cases/compiler/typedArrays-es5.ts(2,5): error TS2802: Type 'Float32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(5,5): error TS2802: Type 'Float64Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(8,5): error TS2802: Type 'Int16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(11,5): error TS2802: Type 'Int32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(14,5): error TS2802: Type 'Int8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(17,5): error TS2802: Type 'NodeList' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(20,5): error TS2802: Type 'Uint16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(23,5): error TS2802: Type 'Uint32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(26,5): error TS2802: Type 'Uint8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(29,5): error TS2802: Type 'Uint8ClampedArray' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(2,5): error TS2803: Type 'Float32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(5,5): error TS2803: Type 'Float64Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(8,5): error TS2803: Type 'Int16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(11,5): error TS2803: Type 'Int32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(14,5): error TS2803: Type 'Int8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(17,5): error TS2803: Type 'NodeList' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(20,5): error TS2803: Type 'Uint16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(23,5): error TS2803: Type 'Uint32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(26,5): error TS2803: Type 'Uint8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(29,5): error TS2803: Type 'Uint8ClampedArray' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. ==== tests/cases/compiler/typedArrays-es5.ts (10 errors) ==== const float32Array = new Float32Array(1); [...float32Array]; ~~~~~~~~~~~~ -!!! error TS2802: Type 'Float32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2803: Type 'Float32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const float64Array = new Float64Array(1); [...float64Array]; ~~~~~~~~~~~~ -!!! error TS2802: Type 'Float64Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2803: Type 'Float64Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const int16Array = new Int16Array(1); [...int16Array]; ~~~~~~~~~~ -!!! error TS2802: Type 'Int16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2803: Type 'Int16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const int32Array = new Int32Array(1); [...int32Array]; ~~~~~~~~~~ -!!! error TS2802: Type 'Int32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2803: Type 'Int32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const int8Array = new Int8Array(1); [...int8Array]; ~~~~~~~~~ -!!! error TS2802: Type 'Int8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2803: Type 'Int8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const nodeList = new NodeList(); [...nodeList]; ~~~~~~~~ -!!! error TS2802: Type 'NodeList' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2803: Type 'NodeList' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const uint16Array = new Uint16Array(1); [...uint16Array]; ~~~~~~~~~~~ -!!! error TS2802: Type 'Uint16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2803: Type 'Uint16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const uint32Array = new Uint32Array(1); [...uint32Array]; ~~~~~~~~~~~ -!!! error TS2802: Type 'Uint32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2803: Type 'Uint32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const uint8Array = new Uint8Array(1); [...uint8Array]; ~~~~~~~~~~ -!!! error TS2802: Type 'Uint8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2803: Type 'Uint8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const uint8ClampedArray = new Uint8ClampedArray(1); [...uint8ClampedArray]; ~~~~~~~~~~~~~~~~~ -!!! error TS2802: Type 'Uint8ClampedArray' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2803: Type 'Uint8ClampedArray' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. \ No newline at end of file From f5e594dbd103bbed2e4ec11d4fc3bf3c2947da7f Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 9 Mar 2021 11:49:30 +0800 Subject: [PATCH 11/25] Revert error number changes --- src/compiler/diagnosticMessages.json | 20 +++++----- .../awaitInNonAsyncFunction.errors.txt | 4 +- .../excessivelyLargeTupleSpread.errors.txt | 12 +++--- ...portAssertion1(module=commonjs).errors.txt | 20 +++++----- ...importAssertion1(module=es2015).errors.txt | 20 +++++----- ...importAssertion1(module=esnext).errors.txt | 8 ++-- ...portAssertion2(module=commonjs).errors.txt | 24 +++++------ ...importAssertion2(module=es2015).errors.txt | 24 +++++------ .../mixinAbstractClasses.2.errors.txt | 4 +- .../parser.forAwait.es2018.errors.txt | 16 ++++---- ....1(module=esnext,target=es2015).errors.txt | 4 +- ....1(module=system,target=es2015).errors.txt | 4 +- .../topLevelAwaitNonModule.errors.txt | 4 +- .../reference/typedArrays-es5.errors.txt | 40 +++++++++---------- 14 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7ae7b4255ac8e..8b46c77c2f96e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1352,15 +1352,15 @@ "category": "Message", "code": 1430 }, - "Dynamic import must have a specifier as arguments and an optional assertion": { + "'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.": { "category": "Error", "code": 1431 }, - "'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.": { + "Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.": { "category": "Error", "code": 1432 }, - "Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher.": { + "Dynamic import must have a specifier as arguments and an optional assertion": { "category": "Error", "code": 1433 }, @@ -3244,31 +3244,31 @@ "category": "Error", "code": 2796 }, - "Import assertions are only supported when the '--module' flag is set to 'esnext'.": { + "A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'.": { "category": "Error", "code": 2797 }, - "A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'.": { + "The declaration was marked as deprecated here.": { "category": "Error", "code": 2798 }, - "The declaration was marked as deprecated here.": { + "Type produces a tuple type that is too large to represent.": { "category": "Error", "code": 2799 }, - "Type produces a tuple type that is too large to represent.": { + "Expression produces a tuple type that is too large to represent.": { "category": "Error", "code": 2800 }, - "Expression produces a tuple type that is too large to represent.": { + "This condition will always return true since the Promise is always truthy.": { "category": "Error", "code": 2801 }, - "This condition will always return true since the Promise is always truthy.": { + "Type '{0}' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.": { "category": "Error", "code": 2802 }, - "Type '{0}' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher.": { + "Import assertions are only supported when the '--module' flag is set to 'esnext'.": { "category": "Error", "code": 2803 }, diff --git a/tests/baselines/reference/awaitInNonAsyncFunction.errors.txt b/tests/baselines/reference/awaitInNonAsyncFunction.errors.txt index 9c99d4cc1e10a..ee1aa75d3cc74 100644 --- a/tests/baselines/reference/awaitInNonAsyncFunction.errors.txt +++ b/tests/baselines/reference/awaitInNonAsyncFunction.errors.txt @@ -12,7 +12,7 @@ tests/cases/compiler/awaitInNonAsyncFunction.ts(30,9): error TS1103: 'for await' tests/cases/compiler/awaitInNonAsyncFunction.ts(31,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules. tests/cases/compiler/awaitInNonAsyncFunction.ts(34,7): error TS1103: 'for await' loops are only allowed within async functions and at the top levels of modules. tests/cases/compiler/awaitInNonAsyncFunction.ts(35,5): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules. -tests/cases/compiler/awaitInNonAsyncFunction.ts(39,5): error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/compiler/awaitInNonAsyncFunction.ts(39,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. tests/cases/compiler/awaitInNonAsyncFunction.ts(40,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. @@ -97,7 +97,7 @@ tests/cases/compiler/awaitInNonAsyncFunction.ts(40,1): error TS1378: Top-level ' for await (const _ of []); ~~~~~ -!!! error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. await null; ~~~~~ !!! error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. \ No newline at end of file diff --git a/tests/baselines/reference/excessivelyLargeTupleSpread.errors.txt b/tests/baselines/reference/excessivelyLargeTupleSpread.errors.txt index 7be7f0cb06513..0b5e44369c7d6 100644 --- a/tests/baselines/reference/excessivelyLargeTupleSpread.errors.txt +++ b/tests/baselines/reference/excessivelyLargeTupleSpread.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/excessivelyLargeTupleSpread.ts(6,10): error TS2589: Type instantiation is excessively deep and possibly infinite. -tests/cases/compiler/excessivelyLargeTupleSpread.ts(6,10): error TS2800: Type produces a tuple type that is too large to represent. -tests/cases/compiler/excessivelyLargeTupleSpread.ts(22,12): error TS2800: Type produces a tuple type that is too large to represent. -tests/cases/compiler/excessivelyLargeTupleSpread.ts(38,13): error TS2801: Expression produces a tuple type that is too large to represent. +tests/cases/compiler/excessivelyLargeTupleSpread.ts(6,10): error TS2799: Type produces a tuple type that is too large to represent. +tests/cases/compiler/excessivelyLargeTupleSpread.ts(22,12): error TS2799: Type produces a tuple type that is too large to represent. +tests/cases/compiler/excessivelyLargeTupleSpread.ts(38,13): error TS2800: Expression produces a tuple type that is too large to represent. ==== tests/cases/compiler/excessivelyLargeTupleSpread.ts (4 errors) ==== @@ -14,7 +14,7 @@ tests/cases/compiler/excessivelyLargeTupleSpread.ts(38,13): error TS2801: Expres ~~~~~~~~~~~~~ !!! error TS2589: Type instantiation is excessively deep and possibly infinite. ~~~~~~~~~~~~~ -!!! error TS2800: Type produces a tuple type that is too large to represent. +!!! error TS2799: Type produces a tuple type that is too large to represent. type T0 = [any]; type T1 = [...T0, ...T0]; @@ -32,7 +32,7 @@ tests/cases/compiler/excessivelyLargeTupleSpread.ts(38,13): error TS2801: Expres type T13 = [...T12, ...T12]; type T14 = [...T13, ...T13]; // 2^14 > 10,000 ~~~~~~~~~~~~~~~~ -!!! error TS2800: Type produces a tuple type that is too large to represent. +!!! error TS2799: Type produces a tuple type that is too large to represent. const a0 = [0] as const; const a1 = [...a0, ...a0] as const; @@ -50,5 +50,5 @@ tests/cases/compiler/excessivelyLargeTupleSpread.ts(38,13): error TS2801: Expres const a13 = [...a12, ...a12] as const; const a14 = [...a13, ...a13] as const; // 2^14 > 10,000 ~~~~~~~~~~~~~~~~ -!!! error TS2801: Expression produces a tuple type that is too large to represent. +!!! error TS2800: Expression produces a tuple type that is too large to represent. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt index 04a7ae13647fb..3b136ad4c4252 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/esnext/importAssertion/1.ts(1,14): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. tests/cases/conformance/esnext/importAssertion/3.ts(2,11): error TS1324: Dynamic import must have one specifier as an argument. tests/cases/conformance/esnext/importAssertion/3.ts(3,11): error TS1324: Dynamic import must have one specifier as an argument. tests/cases/conformance/esnext/importAssertion/3.ts(4,11): error TS1324: Dynamic import must have one specifier as an argument. @@ -18,13 +18,13 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: Dynamic ==== tests/cases/conformance/esnext/importAssertion/1.ts (3 errors) ==== import './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. import { a, b } from './0' assert { "type": "json" } ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. import * as foo from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. a; b; foo.a; @@ -33,10 +33,10 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: Dynamic ==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== import { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. a; b; c; diff --git a/tests/baselines/reference/importAssertion1(module=es2015).errors.txt b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt index 07dadf3fa0a7d..8fb0b79c6c5cc 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/esnext/importAssertion/1.ts(1,14): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. tests/cases/conformance/esnext/importAssertion/3.ts(1,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. tests/cases/conformance/esnext/importAssertion/3.ts(2,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. tests/cases/conformance/esnext/importAssertion/3.ts(3,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. @@ -19,13 +19,13 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1323: Dynamic ==== tests/cases/conformance/esnext/importAssertion/1.ts (3 errors) ==== import './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. import { a, b } from './0' assert { "type": "json" } ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. import * as foo from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. a; b; foo.a; @@ -34,10 +34,10 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1323: Dynamic ==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== import { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. a; b; c; diff --git a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt index ddc2bcaeb2919..2ee8c7a42334b 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1431: Dynamic import must have a specifier as arguments and an optional assertion -tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1431: Dynamic import must have a specifier as arguments and an optional assertion +tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1433: Dynamic import must have a specifier as arguments and an optional assertion +tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1433: Dynamic import must have a specifier as arguments and an optional assertion ==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== @@ -32,8 +32,8 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1431: Dynamic const e = import('./0', foo()) const f = import() ~~~~~~~~ -!!! error TS1431: Dynamic import must have a specifier as arguments and an optional assertion +!!! error TS1433: Dynamic import must have a specifier as arguments and an optional assertion const g = import('./0', {}, {}) ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1431: Dynamic import must have a specifier as arguments and an optional assertion +!!! error TS1433: Dynamic import must have a specifier as arguments and an optional assertion \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt index fdce0cd132928..053c6ea0bce06 100644 --- a/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt +++ b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/esnext/importAssertion/1.ts(1,22): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(3,21): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(4,27): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. ==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== @@ -13,22 +13,22 @@ tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2797: Import ==== tests/cases/conformance/esnext/importAssertion/1.ts (4 errors) ==== export {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. export { a, b } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. export * from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. export * as ns from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. ==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== export { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion2(module=es2015).errors.txt b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt index fdce0cd132928..053c6ea0bce06 100644 --- a/tests/baselines/reference/importAssertion2(module=es2015).errors.txt +++ b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/esnext/importAssertion/1.ts(1,22): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(3,21): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(4,27): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. ==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== @@ -13,22 +13,22 @@ tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2797: Import ==== tests/cases/conformance/esnext/importAssertion/1.ts (4 errors) ==== export {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. export { a, b } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. export * from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. export * as ns from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. ==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== export { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2797: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. \ No newline at end of file diff --git a/tests/baselines/reference/mixinAbstractClasses.2.errors.txt b/tests/baselines/reference/mixinAbstractClasses.2.errors.txt index 6186f19af4a92..99a92c854628c 100644 --- a/tests/baselines/reference/mixinAbstractClasses.2.errors.txt +++ b/tests/baselines/reference/mixinAbstractClasses.2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/mixinAbstractClasses.2.ts(7,11): error TS2798: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. +tests/cases/conformance/classes/mixinAbstractClasses.2.ts(7,11): error TS2797: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. tests/cases/conformance/classes/mixinAbstractClasses.2.ts(21,7): error TS2515: Non-abstract class 'DerivedFromAbstract' does not implement inherited abstract member 'abstractBaseMethod' from class 'AbstractBase & Mixin'. tests/cases/conformance/classes/mixinAbstractClasses.2.ts(25,1): error TS2511: Cannot create an instance of an abstract class. @@ -12,7 +12,7 @@ tests/cases/conformance/classes/mixinAbstractClasses.2.ts(25,1): error TS2511: C // error expected: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. class MixinClass extends baseClass implements Mixin { ~~~~~~~~~~ -!!! error TS2798: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. +!!! error TS2797: A mixin class that extends from a type variable containing an abstract construct signature must also be declared 'abstract'. mixinMethod() { } } diff --git a/tests/baselines/reference/parser.forAwait.es2018.errors.txt b/tests/baselines/reference/parser.forAwait.es2018.errors.txt index cfc346fbb8a17..cc70ef748d0a7 100644 --- a/tests/baselines/reference/parser.forAwait.es2018.errors.txt +++ b/tests/baselines/reference/parser.forAwait.es2018.errors.txt @@ -7,11 +7,11 @@ tests/cases/conformance/parser/ecmascript2018/forAwait/inFunctionDeclWithDeclIsE tests/cases/conformance/parser/ecmascript2018/forAwait/inFunctionDeclWithExprIsError.ts(3,9): error TS1103: 'for await' loops are only allowed within async functions and at the top levels of modules. tests/cases/conformance/parser/ecmascript2018/forAwait/inGeneratorWithDeclIsError.ts(3,9): error TS1103: 'for await' loops are only allowed within async functions and at the top levels of modules. tests/cases/conformance/parser/ecmascript2018/forAwait/inGeneratorWithExprIsError.ts(3,9): error TS1103: 'for await' loops are only allowed within async functions and at the top levels of modules. -tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. -tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts(1,23): error TS2304: Cannot find name 'y'. -tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. -tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,12): error TS2304: Cannot find name 'x'. tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts(1,17): error TS2304: Cannot find name 'y'. @@ -19,18 +19,18 @@ tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.t ==== tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithDeclIsError.ts (3 errors) ==== for await (const x of y) { ~~~~~ -!!! error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +!!! error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. ~~~~~ -!!! error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. ~ !!! error TS2304: Cannot find name 'y'. } ==== tests/cases/conformance/parser/ecmascript2018/forAwait/topLevelWithExprIsError.ts (4 errors) ==== for await (x of y) { ~~~~~ -!!! error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +!!! error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. ~~~~~ -!!! error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. ~ !!! error TS2304: Cannot find name 'x'. ~ diff --git a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt index a09b9ec79f9a2..aeea7ac641fa2 100644 --- a/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt +++ b/tests/baselines/reference/topLevelAwait.1(module=esnext,target=es2015).errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/externalModules/index.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/externalModules/index.ts(46,3): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. -tests/cases/conformance/externalModules/other.ts(9,5): error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/conformance/externalModules/other.ts(9,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. ==== tests/cases/conformance/externalModules/index.ts (2 errors) ==== @@ -84,7 +84,7 @@ tests/cases/conformance/externalModules/other.ts(9,5): error TS1433: Top-level ' for await (const item of arr) { ~~~~~ -!!! error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. item; } \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt index a09b9ec79f9a2..aeea7ac641fa2 100644 --- a/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt +++ b/tests/baselines/reference/topLevelAwait.1(module=system,target=es2015).errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/externalModules/index.ts(2,1): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. tests/cases/conformance/externalModules/index.ts(46,3): error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. -tests/cases/conformance/externalModules/other.ts(9,5): error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +tests/cases/conformance/externalModules/other.ts(9,5): error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. ==== tests/cases/conformance/externalModules/index.ts (2 errors) ==== @@ -84,7 +84,7 @@ tests/cases/conformance/externalModules/other.ts(9,5): error TS1433: Top-level ' for await (const item of arr) { ~~~~~ -!!! error TS1433: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. +!!! error TS1432: Top-level 'for await' loops are only allowed when the 'module' option is set to 'esnext' or 'system', and the 'target' option is set to 'es2017' or higher. item; } \ No newline at end of file diff --git a/tests/baselines/reference/topLevelAwaitNonModule.errors.txt b/tests/baselines/reference/topLevelAwaitNonModule.errors.txt index b618569391815..fd039af1ea0d0 100644 --- a/tests/baselines/reference/topLevelAwaitNonModule.errors.txt +++ b/tests/baselines/reference/topLevelAwaitNonModule.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(1,1): error TS1375: 'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(1,7): error TS2304: Cannot find name 'x'. -tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(5,5): error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(5,5): error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. ==== tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts (3 errors) ==== @@ -14,7 +14,7 @@ tests/cases/conformance/externalModules/topLevelAwaitNonModule.ts(5,5): error TS for await (const item of arr) { ~~~~~ -!!! error TS1432: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. +!!! error TS1431: 'for await' loops are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. item; } \ No newline at end of file diff --git a/tests/baselines/reference/typedArrays-es5.errors.txt b/tests/baselines/reference/typedArrays-es5.errors.txt index b80d279951f13..c46b46566f815 100644 --- a/tests/baselines/reference/typedArrays-es5.errors.txt +++ b/tests/baselines/reference/typedArrays-es5.errors.txt @@ -1,65 +1,65 @@ -tests/cases/compiler/typedArrays-es5.ts(2,5): error TS2803: Type 'Float32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(5,5): error TS2803: Type 'Float64Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(8,5): error TS2803: Type 'Int16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(11,5): error TS2803: Type 'Int32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(14,5): error TS2803: Type 'Int8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(17,5): error TS2803: Type 'NodeList' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(20,5): error TS2803: Type 'Uint16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(23,5): error TS2803: Type 'Uint32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(26,5): error TS2803: Type 'Uint8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. -tests/cases/compiler/typedArrays-es5.ts(29,5): error TS2803: Type 'Uint8ClampedArray' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(2,5): error TS2802: Type 'Float32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(5,5): error TS2802: Type 'Float64Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(8,5): error TS2802: Type 'Int16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(11,5): error TS2802: Type 'Int32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(14,5): error TS2802: Type 'Int8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(17,5): error TS2802: Type 'NodeList' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(20,5): error TS2802: Type 'Uint16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(23,5): error TS2802: Type 'Uint32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(26,5): error TS2802: Type 'Uint8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +tests/cases/compiler/typedArrays-es5.ts(29,5): error TS2802: Type 'Uint8ClampedArray' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. ==== tests/cases/compiler/typedArrays-es5.ts (10 errors) ==== const float32Array = new Float32Array(1); [...float32Array]; ~~~~~~~~~~~~ -!!! error TS2803: Type 'Float32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2802: Type 'Float32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const float64Array = new Float64Array(1); [...float64Array]; ~~~~~~~~~~~~ -!!! error TS2803: Type 'Float64Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2802: Type 'Float64Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const int16Array = new Int16Array(1); [...int16Array]; ~~~~~~~~~~ -!!! error TS2803: Type 'Int16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2802: Type 'Int16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const int32Array = new Int32Array(1); [...int32Array]; ~~~~~~~~~~ -!!! error TS2803: Type 'Int32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2802: Type 'Int32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const int8Array = new Int8Array(1); [...int8Array]; ~~~~~~~~~ -!!! error TS2803: Type 'Int8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2802: Type 'Int8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const nodeList = new NodeList(); [...nodeList]; ~~~~~~~~ -!!! error TS2803: Type 'NodeList' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2802: Type 'NodeList' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const uint16Array = new Uint16Array(1); [...uint16Array]; ~~~~~~~~~~~ -!!! error TS2803: Type 'Uint16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2802: Type 'Uint16Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const uint32Array = new Uint32Array(1); [...uint32Array]; ~~~~~~~~~~~ -!!! error TS2803: Type 'Uint32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2802: Type 'Uint32Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const uint8Array = new Uint8Array(1); [...uint8Array]; ~~~~~~~~~~ -!!! error TS2803: Type 'Uint8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2802: Type 'Uint8Array' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. const uint8ClampedArray = new Uint8ClampedArray(1); [...uint8ClampedArray]; ~~~~~~~~~~~~~~~~~ -!!! error TS2803: Type 'Uint8ClampedArray' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. +!!! error TS2802: Type 'Uint8ClampedArray' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. \ No newline at end of file From 60434d13b9558ccda8d9363016fac0c7e2f34a58 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 9 Mar 2021 14:10:56 +0800 Subject: [PATCH 12/25] Update diagnostic message --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- ...portAssertion1(module=commonjs).errors.txt | 24 +++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b0b9db589f66a..0ca2a2a35efc9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -41329,7 +41329,7 @@ namespace ts { function checkGrammarImportCallArguments(node: ImportCall, nodeArguments: NodeArray): boolean { if (moduleKind !== ModuleKind.ESNext) { if (nodeArguments.length !== 1) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument); + return grammarErrorOnNode(node, Diagnostics.The_second_argument_of_an_import_call_is_only_supported_when_the_module_flag_is_not_available_in_the_current_module_flag); } checkGrammarForDisallowedTrailingComma(nodeArguments); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 8b46c77c2f96e..54c0d19e99804 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -936,7 +936,7 @@ "category": "Error", "code": 1323 }, - "Dynamic import must have one specifier as an argument.": { + "The second argument of an import call is only supported when the module flag is not available in the current module flag.": { "category": "Error", "code": 1324 }, diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt index 3b136ad4c4252..23b5793bdcbb7 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt @@ -3,12 +3,12 @@ tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2803: Import tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/3.ts(2,11): error TS1324: Dynamic import must have one specifier as an argument. -tests/cases/conformance/esnext/importAssertion/3.ts(3,11): error TS1324: Dynamic import must have one specifier as an argument. -tests/cases/conformance/esnext/importAssertion/3.ts(4,11): error TS1324: Dynamic import must have one specifier as an argument. -tests/cases/conformance/esnext/importAssertion/3.ts(6,11): error TS1324: Dynamic import must have one specifier as an argument. -tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1324: Dynamic import must have one specifier as an argument. -tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: Dynamic import must have one specifier as an argument. +tests/cases/conformance/esnext/importAssertion/3.ts(2,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/esnext/importAssertion/3.ts(3,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/esnext/importAssertion/3.ts(4,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/esnext/importAssertion/3.ts(6,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. ==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== @@ -46,21 +46,21 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: Dynamic const a = import('./0') const b = import('./0', { type: "json" }) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. +!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. const c = import('./0', { type: "json", ttype: "typo" }) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. +!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. const d = import('./0', { }) ~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. +!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. declare function foo(): any; const e = import('./0', foo()) ~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. +!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. const f = import() ~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. +!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. const g = import('./0', {}, {}) ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. +!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. \ No newline at end of file From ff87d3ed4cb0480d479ac32728cc746c0e07c240 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 9 Mar 2021 14:27:28 +0800 Subject: [PATCH 13/25] Accept baseline --- .../reference/importCallExpressionGrammarError.errors.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt index bc90a5042ba7f..3bba2fb464eae 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt +++ b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1325: Specifier of dynamic import cannot be spread element. tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1324: Dynamic import must have one specifier as an argument. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,12): error TS1324: Dynamic import must have one specifier as an argument. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,12): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations. @@ -19,9 +19,9 @@ tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): !!! error TS1325: Specifier of dynamic import cannot be spread element. const p2 = import(); ~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. +!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. const p4 = import("pathToModule", "secondModule"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. +!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations. \ No newline at end of file From c69a05bb254bdb08765c74901dc6b8e3676c473d Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 15 Mar 2021 16:31:30 +0800 Subject: [PATCH 14/25] rename path --- ...portAssertion1(module=commonjs).errors.txt | 31 ++++++++--------- .../importAssertion1(module=commonjs).js | 3 +- .../importAssertion1(module=commonjs).symbols | 21 ++++++------ .../importAssertion1(module=commonjs).types | 33 ++++++++++--------- ...importAssertion1(module=es2015).errors.txt | 33 ++++++++++--------- .../importAssertion1(module=es2015).js | 3 +- .../importAssertion1(module=es2015).symbols | 21 ++++++------ .../importAssertion1(module=es2015).types | 33 ++++++++++--------- ...importAssertion1(module=esnext).errors.txt | 13 ++++---- .../importAssertion1(module=esnext).js | 3 +- .../importAssertion1(module=esnext).symbols | 21 ++++++------ .../importAssertion1(module=esnext).types | 33 ++++++++++--------- ...portAssertion2(module=commonjs).errors.txt | 18 +++++----- .../importAssertion2(module=commonjs).js | 2 +- .../importAssertion2(module=commonjs).symbols | 6 ++-- .../importAssertion2(module=commonjs).types | 6 ++-- ...importAssertion2(module=es2015).errors.txt | 18 +++++----- .../importAssertion2(module=es2015).js | 2 +- .../importAssertion2(module=es2015).symbols | 6 ++-- .../importAssertion2(module=es2015).types | 6 ++-- .../importAssertion2(module=esnext).js | 2 +- .../importAssertion2(module=esnext).symbols | 6 ++-- .../importAssertion2(module=esnext).types | 6 ++-- .../importAssertion/importAssertion1.ts | 0 .../importAssertion/importAssertion2.ts | 0 25 files changed, 169 insertions(+), 157 deletions(-) rename tests/cases/conformance/{es2021 => }/importAssertion/importAssertion1.ts (100%) rename tests/cases/conformance/{es2021 => }/importAssertion/importAssertion2.ts (100%) diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt index 23b5793bdcbb7..355be2cc5ce8a 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt @@ -1,21 +1,21 @@ -tests/cases/conformance/esnext/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/3.ts(2,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/esnext/importAssertion/3.ts(3,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/esnext/importAssertion/3.ts(4,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/esnext/importAssertion/3.ts(6,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(2,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/importAssertion/3.ts(3,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/importAssertion/3.ts(4,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/importAssertion/3.ts(6,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/importAssertion/3.ts(7,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/importAssertion/3.ts(8,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== +==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== export const a = 1; export const b = 2; -==== tests/cases/conformance/esnext/importAssertion/1.ts (3 errors) ==== +==== tests/cases/conformance/importAssertion/1.ts (3 errors) ==== import './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. @@ -30,7 +30,7 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: The sec foo.a; foo.b; -==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== +==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== import { a, b } from './0' assert {} ~~~~~~~~~ !!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. @@ -42,7 +42,7 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: The sec c; d; -==== tests/cases/conformance/esnext/importAssertion/3.ts (6 errors) ==== +==== tests/cases/conformance/importAssertion/3.ts (6 errors) ==== const a = import('./0') const b = import('./0', { type: "json" }) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -63,4 +63,5 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1324: The sec const g = import('./0', {}, {}) ~~~~~~~~~~~~~~~~~~~~~ !!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. + \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).js b/tests/baselines/reference/importAssertion1(module=commonjs).js index 1b580c8f3f2b0..aa69df4ad7807 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).js +++ b/tests/baselines/reference/importAssertion1(module=commonjs).js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/esnext/importAssertion/importAssertion1.ts] //// +//// [tests/cases/conformance/importAssertion/importAssertion1.ts] //// //// [0.ts] export const a = 1; @@ -30,6 +30,7 @@ declare function foo(): any; const e = import('./0', foo()) const f = import() const g = import('./0', {}, {}) + //// [0.js] diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).symbols b/tests/baselines/reference/importAssertion1(module=commonjs).symbols index 9d6fef3f0fc61..2f4ba50fb11f1 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).symbols +++ b/tests/baselines/reference/importAssertion1(module=commonjs).symbols @@ -1,11 +1,11 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : Symbol(a, Decl(0.ts, 0, 12)) export const b = 2; >b : Symbol(b, Decl(0.ts, 1, 12)) -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === import './0' assert { type: "json" } import { a, b } from './0' assert { "type": "json" } >a : Symbol(a, Decl(1.ts, 1, 8)) @@ -30,7 +30,7 @@ foo.b; >foo : Symbol(foo, Decl(1.ts, 2, 6)) >b : Symbol(b, Decl(0.ts, 1, 12)) -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === import { a, b } from './0' assert {} >a : Symbol(a, Decl(2.ts, 0, 8)) >b : Symbol(b, Decl(2.ts, 0, 11)) @@ -53,32 +53,32 @@ c; d; >d : Symbol(d, Decl(2.ts, 1, 16)) -=== tests/cases/conformance/esnext/importAssertion/3.ts === +=== tests/cases/conformance/importAssertion/3.ts === const a = import('./0') >a : Symbol(a, Decl(3.ts, 0, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) const b = import('./0', { type: "json" }) >b : Symbol(b, Decl(3.ts, 1, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) >type : Symbol(type, Decl(3.ts, 1, 25)) const c = import('./0', { type: "json", ttype: "typo" }) >c : Symbol(c, Decl(3.ts, 2, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) >type : Symbol(type, Decl(3.ts, 2, 25)) >ttype : Symbol(ttype, Decl(3.ts, 2, 39)) const d = import('./0', { }) >d : Symbol(d, Decl(3.ts, 3, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) declare function foo(): any; >foo : Symbol(foo, Decl(3.ts, 3, 28)) const e = import('./0', foo()) >e : Symbol(e, Decl(3.ts, 5, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) >foo : Symbol(foo, Decl(3.ts, 3, 28)) const f = import() @@ -86,5 +86,6 @@ const f = import() const g = import('./0', {}, {}) >g : Symbol(g, Decl(3.ts, 7, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) + diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).types b/tests/baselines/reference/importAssertion1(module=commonjs).types index 38975059069e9..8d9881d53bfa6 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).types +++ b/tests/baselines/reference/importAssertion1(module=commonjs).types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : 1 >1 : 1 @@ -7,7 +7,7 @@ export const b = 2; >b : 2 >2 : 2 -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === import './0' assert { type: "json" } >type : any @@ -35,7 +35,7 @@ foo.b; >foo : typeof foo >b : 2 -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === import { a, b } from './0' assert {} >a : 1 >b : 2 @@ -61,23 +61,23 @@ c; d; >d : 2 -=== tests/cases/conformance/esnext/importAssertion/3.ts === +=== tests/cases/conformance/importAssertion/3.ts === const a = import('./0') ->a : Promise ->import('./0') : Promise +>a : Promise +>import('./0') : Promise >'./0' : "./0" const b = import('./0', { type: "json" }) ->b : Promise ->import('./0', { type: "json" }) : Promise +>b : Promise +>import('./0', { type: "json" }) : Promise >'./0' : "./0" >{ type: "json" } : { type: string; } >type : string >"json" : "json" const c = import('./0', { type: "json", ttype: "typo" }) ->c : Promise ->import('./0', { type: "json", ttype: "typo" }) : Promise +>c : Promise +>import('./0', { type: "json", ttype: "typo" }) : Promise >'./0' : "./0" >{ type: "json", ttype: "typo" } : { type: string; ttype: string; } >type : string @@ -86,8 +86,8 @@ const c = import('./0', { type: "json", ttype: "typo" }) >"typo" : "typo" const d = import('./0', { }) ->d : Promise ->import('./0', { }) : Promise +>d : Promise +>import('./0', { }) : Promise >'./0' : "./0" >{ } : {} @@ -95,8 +95,8 @@ declare function foo(): any; >foo : () => any const e = import('./0', foo()) ->e : Promise ->import('./0', foo()) : Promise +>e : Promise +>import('./0', foo()) : Promise >'./0' : "./0" >foo() : any >foo : () => any @@ -106,9 +106,10 @@ const f = import() >import() : Promise const g = import('./0', {}, {}) ->g : Promise ->import('./0', {}, {}) : Promise +>g : Promise +>import('./0', {}, {}) : Promise >'./0' : "./0" >{} : {} >{} : {} + diff --git a/tests/baselines/reference/importAssertion1(module=es2015).errors.txt b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt index 8fb0b79c6c5cc..c420e45affd3a 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt @@ -1,22 +1,22 @@ -tests/cases/conformance/esnext/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/3.ts(1,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. -tests/cases/conformance/esnext/importAssertion/3.ts(2,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. -tests/cases/conformance/esnext/importAssertion/3.ts(3,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. -tests/cases/conformance/esnext/importAssertion/3.ts(4,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. -tests/cases/conformance/esnext/importAssertion/3.ts(6,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. -tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. -tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(1,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/importAssertion/3.ts(2,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/importAssertion/3.ts(3,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/importAssertion/3.ts(4,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/importAssertion/3.ts(6,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/importAssertion/3.ts(7,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/importAssertion/3.ts(8,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. -==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== +==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== export const a = 1; export const b = 2; -==== tests/cases/conformance/esnext/importAssertion/1.ts (3 errors) ==== +==== tests/cases/conformance/importAssertion/1.ts (3 errors) ==== import './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. @@ -31,7 +31,7 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1323: Dynamic foo.a; foo.b; -==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== +==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== import { a, b } from './0' assert {} ~~~~~~~~~ !!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. @@ -43,7 +43,7 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1323: Dynamic c; d; -==== tests/cases/conformance/esnext/importAssertion/3.ts (7 errors) ==== +==== tests/cases/conformance/importAssertion/3.ts (7 errors) ==== const a = import('./0') ~~~~~~~~~~~~~ !!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. @@ -66,4 +66,5 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1323: Dynamic const g = import('./0', {}, {}) ~~~~~~~~~~~~~~~~~~~~~ !!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(module=es2015).js b/tests/baselines/reference/importAssertion1(module=es2015).js index cdc99083e8c54..d7e751e638f72 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).js +++ b/tests/baselines/reference/importAssertion1(module=es2015).js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/esnext/importAssertion/importAssertion1.ts] //// +//// [tests/cases/conformance/importAssertion/importAssertion1.ts] //// //// [0.ts] export const a = 1; @@ -30,6 +30,7 @@ declare function foo(): any; const e = import('./0', foo()) const f = import() const g = import('./0', {}, {}) + //// [0.js] diff --git a/tests/baselines/reference/importAssertion1(module=es2015).symbols b/tests/baselines/reference/importAssertion1(module=es2015).symbols index 9d6fef3f0fc61..2f4ba50fb11f1 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).symbols +++ b/tests/baselines/reference/importAssertion1(module=es2015).symbols @@ -1,11 +1,11 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : Symbol(a, Decl(0.ts, 0, 12)) export const b = 2; >b : Symbol(b, Decl(0.ts, 1, 12)) -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === import './0' assert { type: "json" } import { a, b } from './0' assert { "type": "json" } >a : Symbol(a, Decl(1.ts, 1, 8)) @@ -30,7 +30,7 @@ foo.b; >foo : Symbol(foo, Decl(1.ts, 2, 6)) >b : Symbol(b, Decl(0.ts, 1, 12)) -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === import { a, b } from './0' assert {} >a : Symbol(a, Decl(2.ts, 0, 8)) >b : Symbol(b, Decl(2.ts, 0, 11)) @@ -53,32 +53,32 @@ c; d; >d : Symbol(d, Decl(2.ts, 1, 16)) -=== tests/cases/conformance/esnext/importAssertion/3.ts === +=== tests/cases/conformance/importAssertion/3.ts === const a = import('./0') >a : Symbol(a, Decl(3.ts, 0, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) const b = import('./0', { type: "json" }) >b : Symbol(b, Decl(3.ts, 1, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) >type : Symbol(type, Decl(3.ts, 1, 25)) const c = import('./0', { type: "json", ttype: "typo" }) >c : Symbol(c, Decl(3.ts, 2, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) >type : Symbol(type, Decl(3.ts, 2, 25)) >ttype : Symbol(ttype, Decl(3.ts, 2, 39)) const d = import('./0', { }) >d : Symbol(d, Decl(3.ts, 3, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) declare function foo(): any; >foo : Symbol(foo, Decl(3.ts, 3, 28)) const e = import('./0', foo()) >e : Symbol(e, Decl(3.ts, 5, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) >foo : Symbol(foo, Decl(3.ts, 3, 28)) const f = import() @@ -86,5 +86,6 @@ const f = import() const g = import('./0', {}, {}) >g : Symbol(g, Decl(3.ts, 7, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) + diff --git a/tests/baselines/reference/importAssertion1(module=es2015).types b/tests/baselines/reference/importAssertion1(module=es2015).types index 38975059069e9..8d9881d53bfa6 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).types +++ b/tests/baselines/reference/importAssertion1(module=es2015).types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : 1 >1 : 1 @@ -7,7 +7,7 @@ export const b = 2; >b : 2 >2 : 2 -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === import './0' assert { type: "json" } >type : any @@ -35,7 +35,7 @@ foo.b; >foo : typeof foo >b : 2 -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === import { a, b } from './0' assert {} >a : 1 >b : 2 @@ -61,23 +61,23 @@ c; d; >d : 2 -=== tests/cases/conformance/esnext/importAssertion/3.ts === +=== tests/cases/conformance/importAssertion/3.ts === const a = import('./0') ->a : Promise ->import('./0') : Promise +>a : Promise +>import('./0') : Promise >'./0' : "./0" const b = import('./0', { type: "json" }) ->b : Promise ->import('./0', { type: "json" }) : Promise +>b : Promise +>import('./0', { type: "json" }) : Promise >'./0' : "./0" >{ type: "json" } : { type: string; } >type : string >"json" : "json" const c = import('./0', { type: "json", ttype: "typo" }) ->c : Promise ->import('./0', { type: "json", ttype: "typo" }) : Promise +>c : Promise +>import('./0', { type: "json", ttype: "typo" }) : Promise >'./0' : "./0" >{ type: "json", ttype: "typo" } : { type: string; ttype: string; } >type : string @@ -86,8 +86,8 @@ const c = import('./0', { type: "json", ttype: "typo" }) >"typo" : "typo" const d = import('./0', { }) ->d : Promise ->import('./0', { }) : Promise +>d : Promise +>import('./0', { }) : Promise >'./0' : "./0" >{ } : {} @@ -95,8 +95,8 @@ declare function foo(): any; >foo : () => any const e = import('./0', foo()) ->e : Promise ->import('./0', foo()) : Promise +>e : Promise +>import('./0', foo()) : Promise >'./0' : "./0" >foo() : any >foo : () => any @@ -106,9 +106,10 @@ const f = import() >import() : Promise const g = import('./0', {}, {}) ->g : Promise ->import('./0', {}, {}) : Promise +>g : Promise +>import('./0', {}, {}) : Promise >'./0' : "./0" >{} : {} >{} : {} + diff --git a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt index 2ee8c7a42334b..c957cf1cee4a9 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/esnext/importAssertion/3.ts(7,11): error TS1433: Dynamic import must have a specifier as arguments and an optional assertion -tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1433: Dynamic import must have a specifier as arguments and an optional assertion +tests/cases/conformance/importAssertion/3.ts(7,11): error TS1433: Dynamic import must have a specifier as arguments and an optional assertion +tests/cases/conformance/importAssertion/3.ts(8,11): error TS1433: Dynamic import must have a specifier as arguments and an optional assertion -==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== +==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== export const a = 1; export const b = 2; -==== tests/cases/conformance/esnext/importAssertion/1.ts (0 errors) ==== +==== tests/cases/conformance/importAssertion/1.ts (0 errors) ==== import './0' assert { type: "json" } import { a, b } from './0' assert { "type": "json" } import * as foo from './0' assert { type: "json" } @@ -15,7 +15,7 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1433: Dynamic foo.a; foo.b; -==== tests/cases/conformance/esnext/importAssertion/2.ts (0 errors) ==== +==== tests/cases/conformance/importAssertion/2.ts (0 errors) ==== import { a, b } from './0' assert {} import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } a; @@ -23,7 +23,7 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1433: Dynamic c; d; -==== tests/cases/conformance/esnext/importAssertion/3.ts (2 errors) ==== +==== tests/cases/conformance/importAssertion/3.ts (2 errors) ==== const a = import('./0') const b = import('./0', { type: "json" }) const c = import('./0', { type: "json", ttype: "typo" }) @@ -36,4 +36,5 @@ tests/cases/conformance/esnext/importAssertion/3.ts(8,11): error TS1433: Dynamic const g = import('./0', {}, {}) ~~~~~~~~~~~~~~~~~~~~~ !!! error TS1433: Dynamic import must have a specifier as arguments and an optional assertion + \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(module=esnext).js b/tests/baselines/reference/importAssertion1(module=esnext).js index cdc99083e8c54..d7e751e638f72 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).js +++ b/tests/baselines/reference/importAssertion1(module=esnext).js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/esnext/importAssertion/importAssertion1.ts] //// +//// [tests/cases/conformance/importAssertion/importAssertion1.ts] //// //// [0.ts] export const a = 1; @@ -30,6 +30,7 @@ declare function foo(): any; const e = import('./0', foo()) const f = import() const g = import('./0', {}, {}) + //// [0.js] diff --git a/tests/baselines/reference/importAssertion1(module=esnext).symbols b/tests/baselines/reference/importAssertion1(module=esnext).symbols index 9d6fef3f0fc61..2f4ba50fb11f1 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).symbols +++ b/tests/baselines/reference/importAssertion1(module=esnext).symbols @@ -1,11 +1,11 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : Symbol(a, Decl(0.ts, 0, 12)) export const b = 2; >b : Symbol(b, Decl(0.ts, 1, 12)) -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === import './0' assert { type: "json" } import { a, b } from './0' assert { "type": "json" } >a : Symbol(a, Decl(1.ts, 1, 8)) @@ -30,7 +30,7 @@ foo.b; >foo : Symbol(foo, Decl(1.ts, 2, 6)) >b : Symbol(b, Decl(0.ts, 1, 12)) -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === import { a, b } from './0' assert {} >a : Symbol(a, Decl(2.ts, 0, 8)) >b : Symbol(b, Decl(2.ts, 0, 11)) @@ -53,32 +53,32 @@ c; d; >d : Symbol(d, Decl(2.ts, 1, 16)) -=== tests/cases/conformance/esnext/importAssertion/3.ts === +=== tests/cases/conformance/importAssertion/3.ts === const a = import('./0') >a : Symbol(a, Decl(3.ts, 0, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) const b = import('./0', { type: "json" }) >b : Symbol(b, Decl(3.ts, 1, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) >type : Symbol(type, Decl(3.ts, 1, 25)) const c = import('./0', { type: "json", ttype: "typo" }) >c : Symbol(c, Decl(3.ts, 2, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) >type : Symbol(type, Decl(3.ts, 2, 25)) >ttype : Symbol(ttype, Decl(3.ts, 2, 39)) const d = import('./0', { }) >d : Symbol(d, Decl(3.ts, 3, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) declare function foo(): any; >foo : Symbol(foo, Decl(3.ts, 3, 28)) const e = import('./0', foo()) >e : Symbol(e, Decl(3.ts, 5, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) >foo : Symbol(foo, Decl(3.ts, 3, 28)) const f = import() @@ -86,5 +86,6 @@ const f = import() const g = import('./0', {}, {}) >g : Symbol(g, Decl(3.ts, 7, 5)) ->'./0' : Symbol("tests/cases/conformance/esnext/importAssertion/0", Decl(0.ts, 0, 0)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) + diff --git a/tests/baselines/reference/importAssertion1(module=esnext).types b/tests/baselines/reference/importAssertion1(module=esnext).types index 38975059069e9..8d9881d53bfa6 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).types +++ b/tests/baselines/reference/importAssertion1(module=esnext).types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : 1 >1 : 1 @@ -7,7 +7,7 @@ export const b = 2; >b : 2 >2 : 2 -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === import './0' assert { type: "json" } >type : any @@ -35,7 +35,7 @@ foo.b; >foo : typeof foo >b : 2 -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === import { a, b } from './0' assert {} >a : 1 >b : 2 @@ -61,23 +61,23 @@ c; d; >d : 2 -=== tests/cases/conformance/esnext/importAssertion/3.ts === +=== tests/cases/conformance/importAssertion/3.ts === const a = import('./0') ->a : Promise ->import('./0') : Promise +>a : Promise +>import('./0') : Promise >'./0' : "./0" const b = import('./0', { type: "json" }) ->b : Promise ->import('./0', { type: "json" }) : Promise +>b : Promise +>import('./0', { type: "json" }) : Promise >'./0' : "./0" >{ type: "json" } : { type: string; } >type : string >"json" : "json" const c = import('./0', { type: "json", ttype: "typo" }) ->c : Promise ->import('./0', { type: "json", ttype: "typo" }) : Promise +>c : Promise +>import('./0', { type: "json", ttype: "typo" }) : Promise >'./0' : "./0" >{ type: "json", ttype: "typo" } : { type: string; ttype: string; } >type : string @@ -86,8 +86,8 @@ const c = import('./0', { type: "json", ttype: "typo" }) >"typo" : "typo" const d = import('./0', { }) ->d : Promise ->import('./0', { }) : Promise +>d : Promise +>import('./0', { }) : Promise >'./0' : "./0" >{ } : {} @@ -95,8 +95,8 @@ declare function foo(): any; >foo : () => any const e = import('./0', foo()) ->e : Promise ->import('./0', foo()) : Promise +>e : Promise +>import('./0', foo()) : Promise >'./0' : "./0" >foo() : any >foo : () => any @@ -106,9 +106,10 @@ const f = import() >import() : Promise const g = import('./0', {}, {}) ->g : Promise ->import('./0', {}, {}) : Promise +>g : Promise +>import('./0', {}, {}) : Promise >'./0' : "./0" >{} : {} >{} : {} + diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt index 053c6ea0bce06..d93864a65782b 100644 --- a/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt +++ b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt @@ -1,16 +1,16 @@ -tests/cases/conformance/esnext/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== +==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== export const a = 1; export const b = 2; -==== tests/cases/conformance/esnext/importAssertion/1.ts (4 errors) ==== +==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== export {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. @@ -24,7 +24,7 @@ tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== +==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== export { a, b } from './0' assert {} ~~~~~~~~~ !!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).js b/tests/baselines/reference/importAssertion2(module=commonjs).js index 3fd1dd70a0afe..067291329ba82 100644 --- a/tests/baselines/reference/importAssertion2(module=commonjs).js +++ b/tests/baselines/reference/importAssertion2(module=commonjs).js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/esnext/importAssertion/importAssertion2.ts] //// +//// [tests/cases/conformance/importAssertion/importAssertion2.ts] //// //// [0.ts] export const a = 1; diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).symbols b/tests/baselines/reference/importAssertion2(module=commonjs).symbols index 818c5391cf50c..6d4a43cd6c641 100644 --- a/tests/baselines/reference/importAssertion2(module=commonjs).symbols +++ b/tests/baselines/reference/importAssertion2(module=commonjs).symbols @@ -1,11 +1,11 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : Symbol(a, Decl(0.ts, 0, 12)) export const b = 2; >b : Symbol(b, Decl(0.ts, 1, 12)) -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === export {} from './0' assert { type: "json" } export { a, b } from './0' assert { type: "json" } >a : Symbol(a, Decl(1.ts, 1, 8)) @@ -15,7 +15,7 @@ export * from './0' assert { type: "json" } export * as ns from './0' assert { type: "json" } >ns : Symbol(ns, Decl(1.ts, 3, 6)) -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === export { a, b } from './0' assert {} >a : Symbol(a, Decl(2.ts, 0, 8)) >b : Symbol(b, Decl(2.ts, 0, 11)) diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).types b/tests/baselines/reference/importAssertion2(module=commonjs).types index 6dd54c956508d..131c25077dccd 100644 --- a/tests/baselines/reference/importAssertion2(module=commonjs).types +++ b/tests/baselines/reference/importAssertion2(module=commonjs).types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : 1 >1 : 1 @@ -7,7 +7,7 @@ export const b = 2; >b : 2 >2 : 2 -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === export {} from './0' assert { type: "json" } >type : any @@ -23,7 +23,7 @@ export * as ns from './0' assert { type: "json" } >ns : typeof ns >type : any -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === export { a, b } from './0' assert {} >a : 1 >b : 2 diff --git a/tests/baselines/reference/importAssertion2(module=es2015).errors.txt b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt index 053c6ea0bce06..d93864a65782b 100644 --- a/tests/baselines/reference/importAssertion2(module=es2015).errors.txt +++ b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt @@ -1,16 +1,16 @@ -tests/cases/conformance/esnext/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -==== tests/cases/conformance/esnext/importAssertion/0.ts (0 errors) ==== +==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== export const a = 1; export const b = 2; -==== tests/cases/conformance/esnext/importAssertion/1.ts (4 errors) ==== +==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== export {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. @@ -24,7 +24,7 @@ tests/cases/conformance/esnext/importAssertion/2.ts(2,38): error TS2803: Import ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -==== tests/cases/conformance/esnext/importAssertion/2.ts (2 errors) ==== +==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== export { a, b } from './0' assert {} ~~~~~~~~~ !!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. diff --git a/tests/baselines/reference/importAssertion2(module=es2015).js b/tests/baselines/reference/importAssertion2(module=es2015).js index a929a99e4d0df..01804f2b0de3b 100644 --- a/tests/baselines/reference/importAssertion2(module=es2015).js +++ b/tests/baselines/reference/importAssertion2(module=es2015).js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/esnext/importAssertion/importAssertion2.ts] //// +//// [tests/cases/conformance/importAssertion/importAssertion2.ts] //// //// [0.ts] export const a = 1; diff --git a/tests/baselines/reference/importAssertion2(module=es2015).symbols b/tests/baselines/reference/importAssertion2(module=es2015).symbols index 818c5391cf50c..6d4a43cd6c641 100644 --- a/tests/baselines/reference/importAssertion2(module=es2015).symbols +++ b/tests/baselines/reference/importAssertion2(module=es2015).symbols @@ -1,11 +1,11 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : Symbol(a, Decl(0.ts, 0, 12)) export const b = 2; >b : Symbol(b, Decl(0.ts, 1, 12)) -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === export {} from './0' assert { type: "json" } export { a, b } from './0' assert { type: "json" } >a : Symbol(a, Decl(1.ts, 1, 8)) @@ -15,7 +15,7 @@ export * from './0' assert { type: "json" } export * as ns from './0' assert { type: "json" } >ns : Symbol(ns, Decl(1.ts, 3, 6)) -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === export { a, b } from './0' assert {} >a : Symbol(a, Decl(2.ts, 0, 8)) >b : Symbol(b, Decl(2.ts, 0, 11)) diff --git a/tests/baselines/reference/importAssertion2(module=es2015).types b/tests/baselines/reference/importAssertion2(module=es2015).types index 6dd54c956508d..131c25077dccd 100644 --- a/tests/baselines/reference/importAssertion2(module=es2015).types +++ b/tests/baselines/reference/importAssertion2(module=es2015).types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : 1 >1 : 1 @@ -7,7 +7,7 @@ export const b = 2; >b : 2 >2 : 2 -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === export {} from './0' assert { type: "json" } >type : any @@ -23,7 +23,7 @@ export * as ns from './0' assert { type: "json" } >ns : typeof ns >type : any -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === export { a, b } from './0' assert {} >a : 1 >b : 2 diff --git a/tests/baselines/reference/importAssertion2(module=esnext).js b/tests/baselines/reference/importAssertion2(module=esnext).js index ed362d4a2c314..f57ec44cc1546 100644 --- a/tests/baselines/reference/importAssertion2(module=esnext).js +++ b/tests/baselines/reference/importAssertion2(module=esnext).js @@ -1,4 +1,4 @@ -//// [tests/cases/conformance/esnext/importAssertion/importAssertion2.ts] //// +//// [tests/cases/conformance/importAssertion/importAssertion2.ts] //// //// [0.ts] export const a = 1; diff --git a/tests/baselines/reference/importAssertion2(module=esnext).symbols b/tests/baselines/reference/importAssertion2(module=esnext).symbols index 818c5391cf50c..6d4a43cd6c641 100644 --- a/tests/baselines/reference/importAssertion2(module=esnext).symbols +++ b/tests/baselines/reference/importAssertion2(module=esnext).symbols @@ -1,11 +1,11 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : Symbol(a, Decl(0.ts, 0, 12)) export const b = 2; >b : Symbol(b, Decl(0.ts, 1, 12)) -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === export {} from './0' assert { type: "json" } export { a, b } from './0' assert { type: "json" } >a : Symbol(a, Decl(1.ts, 1, 8)) @@ -15,7 +15,7 @@ export * from './0' assert { type: "json" } export * as ns from './0' assert { type: "json" } >ns : Symbol(ns, Decl(1.ts, 3, 6)) -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === export { a, b } from './0' assert {} >a : Symbol(a, Decl(2.ts, 0, 8)) >b : Symbol(b, Decl(2.ts, 0, 11)) diff --git a/tests/baselines/reference/importAssertion2(module=esnext).types b/tests/baselines/reference/importAssertion2(module=esnext).types index 0d4fa28fe927c..6b28d870ab018 100644 --- a/tests/baselines/reference/importAssertion2(module=esnext).types +++ b/tests/baselines/reference/importAssertion2(module=esnext).types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/esnext/importAssertion/0.ts === +=== tests/cases/conformance/importAssertion/0.ts === export const a = 1; >a : 1 >1 : 1 @@ -7,7 +7,7 @@ export const b = 2; >b : 2 >2 : 2 -=== tests/cases/conformance/esnext/importAssertion/1.ts === +=== tests/cases/conformance/importAssertion/1.ts === export {} from './0' assert { type: "json" } >type : error @@ -23,7 +23,7 @@ export * as ns from './0' assert { type: "json" } >ns : typeof ns >type : error -=== tests/cases/conformance/esnext/importAssertion/2.ts === +=== tests/cases/conformance/importAssertion/2.ts === export { a, b } from './0' assert {} >a : 1 >b : 2 diff --git a/tests/cases/conformance/es2021/importAssertion/importAssertion1.ts b/tests/cases/conformance/importAssertion/importAssertion1.ts similarity index 100% rename from tests/cases/conformance/es2021/importAssertion/importAssertion1.ts rename to tests/cases/conformance/importAssertion/importAssertion1.ts diff --git a/tests/cases/conformance/es2021/importAssertion/importAssertion2.ts b/tests/cases/conformance/importAssertion/importAssertion2.ts similarity index 100% rename from tests/cases/conformance/es2021/importAssertion/importAssertion2.ts rename to tests/cases/conformance/importAssertion/importAssertion2.ts From d1c48b502e36a0c45a6ed131e57d870baad7b066 Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 15 Mar 2021 17:07:04 +0800 Subject: [PATCH 15/25] Fix cr issues --- src/compiler/checker.ts | 23 +++--- src/compiler/diagnosticMessages.json | 8 +- src/compiler/factory/nodeTests.ts | 4 - src/compiler/transformers/ts.ts | 3 +- src/compiler/types.ts | 1 - src/compiler/utilitiesPublic.ts | 5 ++ src/deprecatedCompat/deprecations.ts | 3 +- ...portAssertion1(module=commonjs).errors.txt | 73 +++++++++++-------- .../importAssertion1(module=commonjs).js | 12 ++- .../importAssertion1(module=commonjs).symbols | 35 ++++++--- .../importAssertion1(module=commonjs).types | 36 +++++++-- ...importAssertion1(module=es2015).errors.txt | 44 ++++++----- .../importAssertion1(module=es2015).js | 18 +++-- .../importAssertion1(module=es2015).symbols | 35 ++++++--- .../importAssertion1(module=es2015).types | 36 +++++++-- ...importAssertion1(module=esnext).errors.txt | 36 +++++++-- .../importAssertion1(module=esnext).js | 18 +++-- .../importAssertion1(module=esnext).symbols | 35 ++++++--- .../importAssertion1(module=esnext).types | 36 +++++++-- ...portAssertion2(module=commonjs).errors.txt | 24 +++--- ...importAssertion2(module=es2015).errors.txt | 24 +++--- .../importAssertion/importAssertion1.ts | 8 +- 22 files changed, 340 insertions(+), 177 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f9b48b9dc6732..ade750d41097b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37443,9 +37443,9 @@ namespace ts { } } - function checkGrammarImportAssertion(declaration: ImportDeclaration | ExportDeclaration) { + function checkGrammarAssertClause(declaration: ImportDeclaration | ExportDeclaration) { if (declaration.assertClause && moduleKind !== ModuleKind.ESNext) { - grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_flag_is_set_to_esnext); + grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext); } } @@ -37454,7 +37454,6 @@ namespace ts { // If we hit an import declaration in an illegal context, just bail out to avoid cascading errors. return; } - checkGrammarImportAssertion(node); if (!checkGrammarDecoratorsAndModifiers(node) && hasEffectiveModifiers(node)) { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } @@ -37481,7 +37480,7 @@ namespace ts { } } } - + checkGrammarAssertClause(node); } function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { @@ -37529,7 +37528,6 @@ namespace ts { return; } - checkGrammarImportAssertion(node); if (!checkGrammarDecoratorsAndModifiers(node) && hasEffectiveModifiers(node)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers); } @@ -37577,6 +37575,7 @@ namespace ts { } } } + checkGrammarAssertClause(node); } function checkGrammarExportDeclaration(node: ExportDeclaration): boolean { @@ -41422,16 +41421,16 @@ namespace ts { function checkGrammarImportCallArguments(node: ImportCall, nodeArguments: NodeArray): boolean { if (moduleKind !== ModuleKind.ESNext) { - if (nodeArguments.length !== 1) { - return grammarErrorOnNode(node, Diagnostics.The_second_argument_of_an_import_call_is_only_supported_when_the_module_flag_is_not_available_in_the_current_module_flag); - } checkGrammarForDisallowedTrailingComma(nodeArguments); - } - else { - if (nodeArguments.length !== 1 && nodeArguments.length !== 2) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_a_specifier_as_arguments_and_an_optional_assertion); + + if (nodeArguments.length > 1) { + const assertionArgument = nodeArguments[1]; + return grammarErrorOnNode(assertionArgument, Diagnostics.Dynamic_import_only_supports_a_second_argument_when_the_module_option_is_set_to_esnext); } } + if (nodeArguments.length !== 1) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_only_have_a_specifier_and_an_optional_assertion_as_arguments); + } return false; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 43168a680fc0f..b6bbc3e045018 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -936,7 +936,7 @@ "category": "Error", "code": 1323 }, - "The second argument of an import call is only supported when the module flag is not available in the current module flag.": { + "Dynamic import only supports a second argument when the '--module' option is set to 'esnext'.": { "category": "Error", "code": 1324 }, @@ -1360,8 +1360,8 @@ "category": "Error", "code": 1432 }, - "Dynamic import must have a specifier as arguments and an optional assertion": { - "category": "Error", + "Dynamic import must only have a specifier and an optional assertion as arguments": { + "category": "Message", "code": 1433 }, @@ -3288,7 +3288,7 @@ "category": "Error", "code": 2802 }, - "Import assertions are only supported when the '--module' flag is set to 'esnext'.": { + "Import assertions are only supported when the '--module' option is set to 'esnext'.": { "category": "Error", "code": 2803 }, diff --git a/src/compiler/factory/nodeTests.ts b/src/compiler/factory/nodeTests.ts index a0eb64f4a6a2b..c67265b3e6f26 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -596,10 +596,6 @@ namespace ts { return node.kind === SyntaxKind.AssertEntry; } - export function isAssertionKey(node: Node): node is AssertionKey { - return isStringLiteral(node) || isIdentifier(node); - } - export function isNamespaceImport(node: Node): node is NamespaceImport { return node.kind === SyntaxKind.NamespaceImport; } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 006d832d9889e..a011089f2e41a 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2828,8 +2828,7 @@ namespace ts { /*modifiers*/ undefined, importClause, node.moduleSpecifier, - node.assertClause - ) + node.assertClause) : undefined; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c14fda8652b77..1601f3375a4b8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1016,7 +1016,6 @@ namespace ts { /** @deprecated Use `AssertsKeyword` instead. */ export type AssertsToken = AssertsKeyword; - export type AssertToken = AssertKeyword; export interface ModifierToken extends KeywordToken { } diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 12cf6652ad71c..688868bbb80e6 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1129,6 +1129,10 @@ namespace ts { } } + export function isAssertionKey(node: Node): node is AssertionKey { + return isStringLiteral(node) || isIdentifier(node); + } + export function isStringTextContainingNode(node: Node): node is StringLiteral | TemplateLiteralToken { return node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind); } @@ -1350,6 +1354,7 @@ namespace ts { /* @internal */ export function isAssignmentPattern(node: Node): node is AssignmentPattern { const kind = node.kind; + return kind === SyntaxKind.ArrayLiteralExpression || kind === SyntaxKind.ObjectLiteralExpression; } diff --git a/src/deprecatedCompat/deprecations.ts b/src/deprecatedCompat/deprecations.ts index 93bf4fc5a8e5b..f8d53b309b923 100644 --- a/src/deprecatedCompat/deprecations.ts +++ b/src/deprecatedCompat/deprecations.ts @@ -1223,8 +1223,9 @@ namespace ts { modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, + assertClause: AssertClause | undefined, isTypeOnly: boolean) { - return factory.updateExportDeclaration(node, decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier, /*assertClause*/ undefined); + return factory.updateExportDeclaration(node, decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier, assertClause); }, factoryDeprecation); /** @deprecated Use `factory.createJSDocParameterTag` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt index 355be2cc5ce8a..0882579681a55 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt @@ -1,14 +1,17 @@ -tests/cases/conformance/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/3.ts(2,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/importAssertion/3.ts(3,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/importAssertion/3.ts(4,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/importAssertion/3.ts(6,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/importAssertion/3.ts(7,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/importAssertion/3.ts(8,11): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(2,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(3,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(4,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(5,26): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(7,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(8,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(9,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(10,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comma not allowed. ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -18,13 +21,13 @@ tests/cases/conformance/importAssertion/3.ts(8,11): error TS1324: The second arg ==== tests/cases/conformance/importAssertion/1.ts (3 errors) ==== import './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. import { a, b } from './0' assert { "type": "json" } ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. import * as foo from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. a; b; foo.a; @@ -33,35 +36,43 @@ tests/cases/conformance/importAssertion/3.ts(8,11): error TS1324: The second arg ==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== import { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. a; b; c; d; -==== tests/cases/conformance/importAssertion/3.ts (6 errors) ==== +==== tests/cases/conformance/importAssertion/3.ts (9 errors) ==== const a = import('./0') - const b = import('./0', { type: "json" }) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. - const c = import('./0', { type: "json", ttype: "typo" }) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. - const d = import('./0', { }) - ~~~~~~~~~~~~~~~~~~ -!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. + const b = import('./0', { assert: { type: "json" } }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. + const c = import('./0', { assert: { type: "json", ttype: "typo" } }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. + const d = import('./0', { assert: {} }) + ~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. + const dd = import('./0', {}) + ~~ +!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. declare function foo(): any; const e = import('./0', foo()) - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. + ~~~~~ +!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. const f = import() ~~~~~~~~ -!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments const g = import('./0', {}, {}) - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. + ~~ +!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. + const h = import('./0', { assert: { type: "json" }},) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. + ~ +!!! error TS1009: Trailing comma not allowed. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).js b/tests/baselines/reference/importAssertion1(module=commonjs).js index aa69df4ad7807..233a0a293b6e5 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).js +++ b/tests/baselines/reference/importAssertion1(module=commonjs).js @@ -23,13 +23,15 @@ d; //// [3.ts] const a = import('./0') -const b = import('./0', { type: "json" }) -const c = import('./0', { type: "json", ttype: "typo" }) -const d = import('./0', { }) +const b = import('./0', { assert: { type: "json" } }) +const c = import('./0', { assert: { type: "json", ttype: "typo" } }) +const d = import('./0', { assert: {} }) +const dd = import('./0', {}) declare function foo(): any; const e = import('./0', foo()) const f = import() const g = import('./0', {}, {}) +const h = import('./0', { assert: { type: "json" }},) @@ -63,9 +65,11 @@ const a = Promise.resolve().then(() => require('./0')); const b = Promise.resolve().then(() => require('./0')); const c = Promise.resolve().then(() => require('./0')); const d = Promise.resolve().then(() => require('./0')); +const dd = Promise.resolve().then(() => require('./0')); const e = Promise.resolve().then(() => require('./0')); const f = Promise.resolve().then(() => require()); const g = Promise.resolve().then(() => require('./0')); +const h = Promise.resolve().then(() => require('./0')); //// [0.d.ts] @@ -80,7 +84,9 @@ declare const a: Promise; declare const b: Promise; declare const c: Promise; declare const d: Promise; +declare const dd: Promise; declare function foo(): any; declare const e: Promise; declare const f: Promise; declare const g: Promise; +declare const h: Promise; diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).symbols b/tests/baselines/reference/importAssertion1(module=commonjs).symbols index 2f4ba50fb11f1..f7b77b135a91a 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).symbols +++ b/tests/baselines/reference/importAssertion1(module=commonjs).symbols @@ -58,34 +58,47 @@ const a = import('./0') >a : Symbol(a, Decl(3.ts, 0, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) -const b = import('./0', { type: "json" }) +const b = import('./0', { assert: { type: "json" } }) >b : Symbol(b, Decl(3.ts, 1, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) ->type : Symbol(type, Decl(3.ts, 1, 25)) +>assert : Symbol(assert, Decl(3.ts, 1, 25)) +>type : Symbol(type, Decl(3.ts, 1, 35)) -const c = import('./0', { type: "json", ttype: "typo" }) +const c = import('./0', { assert: { type: "json", ttype: "typo" } }) >c : Symbol(c, Decl(3.ts, 2, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) ->type : Symbol(type, Decl(3.ts, 2, 25)) ->ttype : Symbol(ttype, Decl(3.ts, 2, 39)) +>assert : Symbol(assert, Decl(3.ts, 2, 25)) +>type : Symbol(type, Decl(3.ts, 2, 35)) +>ttype : Symbol(ttype, Decl(3.ts, 2, 49)) -const d = import('./0', { }) +const d = import('./0', { assert: {} }) >d : Symbol(d, Decl(3.ts, 3, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) +>assert : Symbol(assert, Decl(3.ts, 3, 25)) + +const dd = import('./0', {}) +>dd : Symbol(dd, Decl(3.ts, 4, 5)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) declare function foo(): any; ->foo : Symbol(foo, Decl(3.ts, 3, 28)) +>foo : Symbol(foo, Decl(3.ts, 4, 28)) const e = import('./0', foo()) ->e : Symbol(e, Decl(3.ts, 5, 5)) +>e : Symbol(e, Decl(3.ts, 6, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) ->foo : Symbol(foo, Decl(3.ts, 3, 28)) +>foo : Symbol(foo, Decl(3.ts, 4, 28)) const f = import() ->f : Symbol(f, Decl(3.ts, 6, 5)) +>f : Symbol(f, Decl(3.ts, 7, 5)) const g = import('./0', {}, {}) ->g : Symbol(g, Decl(3.ts, 7, 5)) +>g : Symbol(g, Decl(3.ts, 8, 5)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) + +const h = import('./0', { assert: { type: "json" }},) +>h : Symbol(h, Decl(3.ts, 9, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) +>assert : Symbol(assert, Decl(3.ts, 9, 25)) +>type : Symbol(type, Decl(3.ts, 9, 35)) diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).types b/tests/baselines/reference/importAssertion1(module=commonjs).types index 8d9881d53bfa6..ca1a8b3f24ffc 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).types +++ b/tests/baselines/reference/importAssertion1(module=commonjs).types @@ -67,29 +67,41 @@ const a = import('./0') >import('./0') : Promise >'./0' : "./0" -const b = import('./0', { type: "json" }) +const b = import('./0', { assert: { type: "json" } }) >b : Promise ->import('./0', { type: "json" }) : Promise +>import('./0', { assert: { type: "json" } }) : Promise >'./0' : "./0" +>{ assert: { type: "json" } } : { assert: { type: string; }; } +>assert : { type: string; } >{ type: "json" } : { type: string; } >type : string >"json" : "json" -const c = import('./0', { type: "json", ttype: "typo" }) +const c = import('./0', { assert: { type: "json", ttype: "typo" } }) >c : Promise ->import('./0', { type: "json", ttype: "typo" }) : Promise +>import('./0', { assert: { type: "json", ttype: "typo" } }) : Promise >'./0' : "./0" +>{ assert: { type: "json", ttype: "typo" } } : { assert: { type: string; ttype: string; }; } +>assert : { type: string; ttype: string; } >{ type: "json", ttype: "typo" } : { type: string; ttype: string; } >type : string >"json" : "json" >ttype : string >"typo" : "typo" -const d = import('./0', { }) +const d = import('./0', { assert: {} }) >d : Promise ->import('./0', { }) : Promise +>import('./0', { assert: {} }) : Promise >'./0' : "./0" ->{ } : {} +>{ assert: {} } : { assert: {}; } +>assert : {} +>{} : {} + +const dd = import('./0', {}) +>dd : Promise +>import('./0', {}) : Promise +>'./0' : "./0" +>{} : {} declare function foo(): any; >foo : () => any @@ -112,4 +124,14 @@ const g = import('./0', {}, {}) >{} : {} >{} : {} +const h = import('./0', { assert: { type: "json" }},) +>h : Promise +>import('./0', { assert: { type: "json" }},) : Promise +>'./0' : "./0" +>{ assert: { type: "json" }} : { assert: { type: string; }; } +>assert : { type: string; } +>{ type: "json" } : { type: string; } +>type : string +>"json" : "json" + diff --git a/tests/baselines/reference/importAssertion1(module=es2015).errors.txt b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt index c420e45affd3a..d9a2a4c804d3b 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt @@ -1,15 +1,17 @@ -tests/cases/conformance/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/3.ts(1,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. tests/cases/conformance/importAssertion/3.ts(2,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. tests/cases/conformance/importAssertion/3.ts(3,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. tests/cases/conformance/importAssertion/3.ts(4,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. -tests/cases/conformance/importAssertion/3.ts(6,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/importAssertion/3.ts(5,12): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. tests/cases/conformance/importAssertion/3.ts(7,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. tests/cases/conformance/importAssertion/3.ts(8,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/importAssertion/3.ts(9,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. +tests/cases/conformance/importAssertion/3.ts(10,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -19,13 +21,13 @@ tests/cases/conformance/importAssertion/3.ts(8,11): error TS1323: Dynamic import ==== tests/cases/conformance/importAssertion/1.ts (3 errors) ==== import './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. import { a, b } from './0' assert { "type": "json" } ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. import * as foo from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. a; b; foo.a; @@ -34,27 +36,30 @@ tests/cases/conformance/importAssertion/3.ts(8,11): error TS1323: Dynamic import ==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== import { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. a; b; c; d; -==== tests/cases/conformance/importAssertion/3.ts (7 errors) ==== +==== tests/cases/conformance/importAssertion/3.ts (9 errors) ==== const a = import('./0') ~~~~~~~~~~~~~ !!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. - const b = import('./0', { type: "json" }) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + const b = import('./0', { assert: { type: "json" } }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. - const c = import('./0', { type: "json", ttype: "typo" }) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + const c = import('./0', { assert: { type: "json", ttype: "typo" } }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. - const d = import('./0', { }) - ~~~~~~~~~~~~~~~~~~ + const d = import('./0', { assert: {} }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + const dd = import('./0', {}) + ~~~~~~~~~~~~~~~~~ !!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. declare function foo(): any; const e = import('./0', foo()) @@ -66,5 +71,8 @@ tests/cases/conformance/importAssertion/3.ts(8,11): error TS1323: Dynamic import const g = import('./0', {}, {}) ~~~~~~~~~~~~~~~~~~~~~ !!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. + const h = import('./0', { assert: { type: "json" }},) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(module=es2015).js b/tests/baselines/reference/importAssertion1(module=es2015).js index d7e751e638f72..0dcd0888aed9d 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).js +++ b/tests/baselines/reference/importAssertion1(module=es2015).js @@ -23,13 +23,15 @@ d; //// [3.ts] const a = import('./0') -const b = import('./0', { type: "json" }) -const c = import('./0', { type: "json", ttype: "typo" }) -const d = import('./0', { }) +const b = import('./0', { assert: { type: "json" } }) +const c = import('./0', { assert: { type: "json", ttype: "typo" } }) +const d = import('./0', { assert: {} }) +const dd = import('./0', {}) declare function foo(): any; const e = import('./0', foo()) const f = import() const g = import('./0', {}, {}) +const h = import('./0', { assert: { type: "json" }},) @@ -53,12 +55,14 @@ c; d; //// [3.js] const a = import('./0'); -const b = import('./0', { type: "json" }); -const c = import('./0', { type: "json", ttype: "typo" }); -const d = import('./0', {}); +const b = import('./0', { assert: { type: "json" } }); +const c = import('./0', { assert: { type: "json", ttype: "typo" } }); +const d = import('./0', { assert: {} }); +const dd = import('./0', {}); const e = import('./0', foo()); const f = import(); const g = import('./0', {}, {}); +const h = import('./0', { assert: { type: "json" } }); //// [0.d.ts] @@ -73,7 +77,9 @@ declare const a: Promise; declare const b: Promise; declare const c: Promise; declare const d: Promise; +declare const dd: Promise; declare function foo(): any; declare const e: Promise; declare const f: Promise; declare const g: Promise; +declare const h: Promise; diff --git a/tests/baselines/reference/importAssertion1(module=es2015).symbols b/tests/baselines/reference/importAssertion1(module=es2015).symbols index 2f4ba50fb11f1..f7b77b135a91a 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).symbols +++ b/tests/baselines/reference/importAssertion1(module=es2015).symbols @@ -58,34 +58,47 @@ const a = import('./0') >a : Symbol(a, Decl(3.ts, 0, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) -const b = import('./0', { type: "json" }) +const b = import('./0', { assert: { type: "json" } }) >b : Symbol(b, Decl(3.ts, 1, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) ->type : Symbol(type, Decl(3.ts, 1, 25)) +>assert : Symbol(assert, Decl(3.ts, 1, 25)) +>type : Symbol(type, Decl(3.ts, 1, 35)) -const c = import('./0', { type: "json", ttype: "typo" }) +const c = import('./0', { assert: { type: "json", ttype: "typo" } }) >c : Symbol(c, Decl(3.ts, 2, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) ->type : Symbol(type, Decl(3.ts, 2, 25)) ->ttype : Symbol(ttype, Decl(3.ts, 2, 39)) +>assert : Symbol(assert, Decl(3.ts, 2, 25)) +>type : Symbol(type, Decl(3.ts, 2, 35)) +>ttype : Symbol(ttype, Decl(3.ts, 2, 49)) -const d = import('./0', { }) +const d = import('./0', { assert: {} }) >d : Symbol(d, Decl(3.ts, 3, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) +>assert : Symbol(assert, Decl(3.ts, 3, 25)) + +const dd = import('./0', {}) +>dd : Symbol(dd, Decl(3.ts, 4, 5)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) declare function foo(): any; ->foo : Symbol(foo, Decl(3.ts, 3, 28)) +>foo : Symbol(foo, Decl(3.ts, 4, 28)) const e = import('./0', foo()) ->e : Symbol(e, Decl(3.ts, 5, 5)) +>e : Symbol(e, Decl(3.ts, 6, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) ->foo : Symbol(foo, Decl(3.ts, 3, 28)) +>foo : Symbol(foo, Decl(3.ts, 4, 28)) const f = import() ->f : Symbol(f, Decl(3.ts, 6, 5)) +>f : Symbol(f, Decl(3.ts, 7, 5)) const g = import('./0', {}, {}) ->g : Symbol(g, Decl(3.ts, 7, 5)) +>g : Symbol(g, Decl(3.ts, 8, 5)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) + +const h = import('./0', { assert: { type: "json" }},) +>h : Symbol(h, Decl(3.ts, 9, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) +>assert : Symbol(assert, Decl(3.ts, 9, 25)) +>type : Symbol(type, Decl(3.ts, 9, 35)) diff --git a/tests/baselines/reference/importAssertion1(module=es2015).types b/tests/baselines/reference/importAssertion1(module=es2015).types index 8d9881d53bfa6..ca1a8b3f24ffc 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).types +++ b/tests/baselines/reference/importAssertion1(module=es2015).types @@ -67,29 +67,41 @@ const a = import('./0') >import('./0') : Promise >'./0' : "./0" -const b = import('./0', { type: "json" }) +const b = import('./0', { assert: { type: "json" } }) >b : Promise ->import('./0', { type: "json" }) : Promise +>import('./0', { assert: { type: "json" } }) : Promise >'./0' : "./0" +>{ assert: { type: "json" } } : { assert: { type: string; }; } +>assert : { type: string; } >{ type: "json" } : { type: string; } >type : string >"json" : "json" -const c = import('./0', { type: "json", ttype: "typo" }) +const c = import('./0', { assert: { type: "json", ttype: "typo" } }) >c : Promise ->import('./0', { type: "json", ttype: "typo" }) : Promise +>import('./0', { assert: { type: "json", ttype: "typo" } }) : Promise >'./0' : "./0" +>{ assert: { type: "json", ttype: "typo" } } : { assert: { type: string; ttype: string; }; } +>assert : { type: string; ttype: string; } >{ type: "json", ttype: "typo" } : { type: string; ttype: string; } >type : string >"json" : "json" >ttype : string >"typo" : "typo" -const d = import('./0', { }) +const d = import('./0', { assert: {} }) >d : Promise ->import('./0', { }) : Promise +>import('./0', { assert: {} }) : Promise >'./0' : "./0" ->{ } : {} +>{ assert: {} } : { assert: {}; } +>assert : {} +>{} : {} + +const dd = import('./0', {}) +>dd : Promise +>import('./0', {}) : Promise +>'./0' : "./0" +>{} : {} declare function foo(): any; >foo : () => any @@ -112,4 +124,14 @@ const g = import('./0', {}, {}) >{} : {} >{} : {} +const h = import('./0', { assert: { type: "json" }},) +>h : Promise +>import('./0', { assert: { type: "json" }},) : Promise +>'./0' : "./0" +>{ assert: { type: "json" }} : { assert: { type: string; }; } +>assert : { type: string; } +>{ type: "json" } : { type: string; } +>type : string +>"json" : "json" + diff --git a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt index c957cf1cee4a9..293d6b38a4d35 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt @@ -1,5 +1,11 @@ -tests/cases/conformance/importAssertion/3.ts(7,11): error TS1433: Dynamic import must have a specifier as arguments and an optional assertion -tests/cases/conformance/importAssertion/3.ts(8,11): error TS1433: Dynamic import must have a specifier as arguments and an optional assertion +tests/cases/conformance/importAssertion/3.ts(2,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(3,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(4,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(5,12): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(7,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(8,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(9,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(10,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -23,18 +29,32 @@ tests/cases/conformance/importAssertion/3.ts(8,11): error TS1433: Dynamic import c; d; -==== tests/cases/conformance/importAssertion/3.ts (2 errors) ==== +==== tests/cases/conformance/importAssertion/3.ts (8 errors) ==== const a = import('./0') - const b = import('./0', { type: "json" }) - const c = import('./0', { type: "json", ttype: "typo" }) - const d = import('./0', { }) + const b = import('./0', { assert: { type: "json" } }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments + const c = import('./0', { assert: { type: "json", ttype: "typo" } }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments + const d = import('./0', { assert: {} }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments + const dd = import('./0', {}) + ~~~~~~~~~~~~~~~~~ +!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments declare function foo(): any; const e = import('./0', foo()) + ~~~~~~~~~~~~~~~~~~~~ +!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments const f = import() ~~~~~~~~ -!!! error TS1433: Dynamic import must have a specifier as arguments and an optional assertion +!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments const g = import('./0', {}, {}) ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1433: Dynamic import must have a specifier as arguments and an optional assertion +!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments + const h = import('./0', { assert: { type: "json" }},) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(module=esnext).js b/tests/baselines/reference/importAssertion1(module=esnext).js index d7e751e638f72..0dcd0888aed9d 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).js +++ b/tests/baselines/reference/importAssertion1(module=esnext).js @@ -23,13 +23,15 @@ d; //// [3.ts] const a = import('./0') -const b = import('./0', { type: "json" }) -const c = import('./0', { type: "json", ttype: "typo" }) -const d = import('./0', { }) +const b = import('./0', { assert: { type: "json" } }) +const c = import('./0', { assert: { type: "json", ttype: "typo" } }) +const d = import('./0', { assert: {} }) +const dd = import('./0', {}) declare function foo(): any; const e = import('./0', foo()) const f = import() const g = import('./0', {}, {}) +const h = import('./0', { assert: { type: "json" }},) @@ -53,12 +55,14 @@ c; d; //// [3.js] const a = import('./0'); -const b = import('./0', { type: "json" }); -const c = import('./0', { type: "json", ttype: "typo" }); -const d = import('./0', {}); +const b = import('./0', { assert: { type: "json" } }); +const c = import('./0', { assert: { type: "json", ttype: "typo" } }); +const d = import('./0', { assert: {} }); +const dd = import('./0', {}); const e = import('./0', foo()); const f = import(); const g = import('./0', {}, {}); +const h = import('./0', { assert: { type: "json" } }); //// [0.d.ts] @@ -73,7 +77,9 @@ declare const a: Promise; declare const b: Promise; declare const c: Promise; declare const d: Promise; +declare const dd: Promise; declare function foo(): any; declare const e: Promise; declare const f: Promise; declare const g: Promise; +declare const h: Promise; diff --git a/tests/baselines/reference/importAssertion1(module=esnext).symbols b/tests/baselines/reference/importAssertion1(module=esnext).symbols index 2f4ba50fb11f1..f7b77b135a91a 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).symbols +++ b/tests/baselines/reference/importAssertion1(module=esnext).symbols @@ -58,34 +58,47 @@ const a = import('./0') >a : Symbol(a, Decl(3.ts, 0, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) -const b = import('./0', { type: "json" }) +const b = import('./0', { assert: { type: "json" } }) >b : Symbol(b, Decl(3.ts, 1, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) ->type : Symbol(type, Decl(3.ts, 1, 25)) +>assert : Symbol(assert, Decl(3.ts, 1, 25)) +>type : Symbol(type, Decl(3.ts, 1, 35)) -const c = import('./0', { type: "json", ttype: "typo" }) +const c = import('./0', { assert: { type: "json", ttype: "typo" } }) >c : Symbol(c, Decl(3.ts, 2, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) ->type : Symbol(type, Decl(3.ts, 2, 25)) ->ttype : Symbol(ttype, Decl(3.ts, 2, 39)) +>assert : Symbol(assert, Decl(3.ts, 2, 25)) +>type : Symbol(type, Decl(3.ts, 2, 35)) +>ttype : Symbol(ttype, Decl(3.ts, 2, 49)) -const d = import('./0', { }) +const d = import('./0', { assert: {} }) >d : Symbol(d, Decl(3.ts, 3, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) +>assert : Symbol(assert, Decl(3.ts, 3, 25)) + +const dd = import('./0', {}) +>dd : Symbol(dd, Decl(3.ts, 4, 5)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) declare function foo(): any; ->foo : Symbol(foo, Decl(3.ts, 3, 28)) +>foo : Symbol(foo, Decl(3.ts, 4, 28)) const e = import('./0', foo()) ->e : Symbol(e, Decl(3.ts, 5, 5)) +>e : Symbol(e, Decl(3.ts, 6, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) ->foo : Symbol(foo, Decl(3.ts, 3, 28)) +>foo : Symbol(foo, Decl(3.ts, 4, 28)) const f = import() ->f : Symbol(f, Decl(3.ts, 6, 5)) +>f : Symbol(f, Decl(3.ts, 7, 5)) const g = import('./0', {}, {}) ->g : Symbol(g, Decl(3.ts, 7, 5)) +>g : Symbol(g, Decl(3.ts, 8, 5)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) + +const h = import('./0', { assert: { type: "json" }},) +>h : Symbol(h, Decl(3.ts, 9, 5)) >'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) +>assert : Symbol(assert, Decl(3.ts, 9, 25)) +>type : Symbol(type, Decl(3.ts, 9, 35)) diff --git a/tests/baselines/reference/importAssertion1(module=esnext).types b/tests/baselines/reference/importAssertion1(module=esnext).types index 8d9881d53bfa6..ca1a8b3f24ffc 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).types +++ b/tests/baselines/reference/importAssertion1(module=esnext).types @@ -67,29 +67,41 @@ const a = import('./0') >import('./0') : Promise >'./0' : "./0" -const b = import('./0', { type: "json" }) +const b = import('./0', { assert: { type: "json" } }) >b : Promise ->import('./0', { type: "json" }) : Promise +>import('./0', { assert: { type: "json" } }) : Promise >'./0' : "./0" +>{ assert: { type: "json" } } : { assert: { type: string; }; } +>assert : { type: string; } >{ type: "json" } : { type: string; } >type : string >"json" : "json" -const c = import('./0', { type: "json", ttype: "typo" }) +const c = import('./0', { assert: { type: "json", ttype: "typo" } }) >c : Promise ->import('./0', { type: "json", ttype: "typo" }) : Promise +>import('./0', { assert: { type: "json", ttype: "typo" } }) : Promise >'./0' : "./0" +>{ assert: { type: "json", ttype: "typo" } } : { assert: { type: string; ttype: string; }; } +>assert : { type: string; ttype: string; } >{ type: "json", ttype: "typo" } : { type: string; ttype: string; } >type : string >"json" : "json" >ttype : string >"typo" : "typo" -const d = import('./0', { }) +const d = import('./0', { assert: {} }) >d : Promise ->import('./0', { }) : Promise +>import('./0', { assert: {} }) : Promise >'./0' : "./0" ->{ } : {} +>{ assert: {} } : { assert: {}; } +>assert : {} +>{} : {} + +const dd = import('./0', {}) +>dd : Promise +>import('./0', {}) : Promise +>'./0' : "./0" +>{} : {} declare function foo(): any; >foo : () => any @@ -112,4 +124,14 @@ const g = import('./0', {}, {}) >{} : {} >{} : {} +const h = import('./0', { assert: { type: "json" }},) +>h : Promise +>import('./0', { assert: { type: "json" }},) : Promise +>'./0' : "./0" +>{ assert: { type: "json" }} : { assert: { type: string; }; } +>assert : { type: string; } +>{ type: "json" } : { type: string; } +>type : string +>"json" : "json" + diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt index d93864a65782b..6660595493ab5 100644 --- a/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt +++ b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -13,22 +13,22 @@ tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import asserti ==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== export {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. export { a, b } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. export * from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. export * as ns from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. ==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== export { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion2(module=es2015).errors.txt b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt index d93864a65782b..6660595493ab5 100644 --- a/tests/baselines/reference/importAssertion2(module=es2015).errors.txt +++ b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -13,22 +13,22 @@ tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import asserti ==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== export {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. export { a, b } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. export * from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. export * as ns from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. ==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== export { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' flag is set to 'esnext'. +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. \ No newline at end of file diff --git a/tests/cases/conformance/importAssertion/importAssertion1.ts b/tests/cases/conformance/importAssertion/importAssertion1.ts index 9aa960d9a3406..b547158cf14cc 100644 --- a/tests/cases/conformance/importAssertion/importAssertion1.ts +++ b/tests/cases/conformance/importAssertion/importAssertion1.ts @@ -25,11 +25,13 @@ d; // @filename: 3.ts const a = import('./0') -const b = import('./0', { type: "json" }) -const c = import('./0', { type: "json", ttype: "typo" }) -const d = import('./0', { }) +const b = import('./0', { assert: { type: "json" } }) +const c = import('./0', { assert: { type: "json", ttype: "typo" } }) +const d = import('./0', { assert: {} }) +const dd = import('./0', {}) declare function foo(): any; const e = import('./0', foo()) const f = import() const g = import('./0', {}, {}) +const h = import('./0', { assert: { type: "json" }},) From d14f93af14138582db68d7b5438e0c8e0d21588b Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 15 Mar 2021 17:13:12 +0800 Subject: [PATCH 16/25] Accept baseline --- src/deprecatedCompat/deprecations.ts | 3 +-- tests/baselines/reference/api/tsserverlibrary.d.ts | 3 +-- tests/baselines/reference/api/typescript.d.ts | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/deprecatedCompat/deprecations.ts b/src/deprecatedCompat/deprecations.ts index f8d53b309b923..dbf37d5886672 100644 --- a/src/deprecatedCompat/deprecations.ts +++ b/src/deprecatedCompat/deprecations.ts @@ -1223,9 +1223,8 @@ namespace ts { modifiers: readonly Modifier[] | undefined, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, - assertClause: AssertClause | undefined, isTypeOnly: boolean) { - return factory.updateExportDeclaration(node, decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier, assertClause); + return factory.updateExportDeclaration(node, decorators, modifiers, isTypeOnly, exportClause, moduleSpecifier, node.assertClause); }, factoryDeprecation); /** @deprecated Use `factory.createJSDocParameterTag` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 7f676b1f02f47..6380a7537dcf4 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -595,7 +595,6 @@ declare namespace ts { export type AwaitKeywordToken = AwaitKeyword; /** @deprecated Use `AssertsKeyword` instead. */ export type AssertsToken = AssertsKeyword; - export type AssertToken = AssertKeyword; export interface ModifierToken extends KeywordToken { } export type AbstractKeyword = ModifierToken; @@ -4270,6 +4269,7 @@ declare namespace ts { function isTemplateMiddleOrTemplateTail(node: Node): node is TemplateMiddle | TemplateTail; function isImportOrExportSpecifier(node: Node): node is ImportSpecifier | ExportSpecifier; function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnlyCompatibleAliasDeclaration; + function isAssertionKey(node: Node): node is AssertionKey; function isStringTextContainingNode(node: Node): node is StringLiteral | TemplateLiteralToken; function isModifier(node: Node): node is Modifier; function isEntityName(node: Node): node is EntityName; @@ -4517,7 +4517,6 @@ declare namespace ts { function isImportClause(node: Node): node is ImportClause; function isAssertClause(node: Node): node is AssertClause; function isAssertEntry(node: Node): node is AssertEntry; - function isAssertionKey(node: Node): node is AssertionKey; function isNamespaceImport(node: Node): node is NamespaceImport; function isNamespaceExport(node: Node): node is NamespaceExport; function isNamedImports(node: Node): node is NamedImports; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 4fee759caca99..33b0455cddc8e 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -595,7 +595,6 @@ declare namespace ts { export type AwaitKeywordToken = AwaitKeyword; /** @deprecated Use `AssertsKeyword` instead. */ export type AssertsToken = AssertsKeyword; - export type AssertToken = AssertKeyword; export interface ModifierToken extends KeywordToken { } export type AbstractKeyword = ModifierToken; @@ -4270,6 +4269,7 @@ declare namespace ts { function isTemplateMiddleOrTemplateTail(node: Node): node is TemplateMiddle | TemplateTail; function isImportOrExportSpecifier(node: Node): node is ImportSpecifier | ExportSpecifier; function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnlyCompatibleAliasDeclaration; + function isAssertionKey(node: Node): node is AssertionKey; function isStringTextContainingNode(node: Node): node is StringLiteral | TemplateLiteralToken; function isModifier(node: Node): node is Modifier; function isEntityName(node: Node): node is EntityName; @@ -4517,7 +4517,6 @@ declare namespace ts { function isImportClause(node: Node): node is ImportClause; function isAssertClause(node: Node): node is AssertClause; function isAssertEntry(node: Node): node is AssertEntry; - function isAssertionKey(node: Node): node is AssertionKey; function isNamespaceImport(node: Node): node is NamespaceImport; function isNamespaceExport(node: Node): node is NamespaceExport; function isNamedImports(node: Node): node is NamedImports; From aa8b856a5543f806b9892c0d7db5ebfa447e3bc7 Mon Sep 17 00:00:00 2001 From: kingwl Date: Mon, 15 Mar 2021 17:32:35 +0800 Subject: [PATCH 17/25] Accept baseline --- .../importCallExpressionGrammarError.errors.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt index 3bba2fb464eae..02a17ef9ed6e7 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt +++ b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1325: Specifier of dynamic import cannot be spread element. tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(8,12): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,12): error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(8,12): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,35): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. ==== tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts (5 errors) ==== @@ -19,9 +19,9 @@ tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): !!! error TS1325: Specifier of dynamic import cannot be spread element. const p2 = import(); ~~~~~~~~ -!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. +!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments const p4 = import("pathToModule", "secondModule"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: The second argument of an import call is only supported when the module flag is not available in the current module flag. ~~~~~~~~~~~~~~ -!!! error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations. \ No newline at end of file +!!! error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations. + ~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. \ No newline at end of file From 9cea9cf6c71694a3726c371c1118f47138d4af79 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 18 Mar 2021 18:20:32 +0800 Subject: [PATCH 18/25] Error if assertion and typeonly import --- src/compiler/checker.ts | 16 +++++--- src/compiler/diagnosticMessages.json | 4 ++ ...importAssertion3(module=es2015).errors.txt | 38 +++++++++++++++++++ .../importAssertion3(module=es2015).js | 31 +++++++++++++++ .../importAssertion3(module=es2015).symbols | 17 +++++++++ .../importAssertion3(module=es2015).types | 21 ++++++++++ ...importAssertion3(module=esnext).errors.txt | 26 +++++++++++++ .../importAssertion3(module=esnext).js | 31 +++++++++++++++ .../importAssertion3(module=esnext).symbols | 17 +++++++++ .../importAssertion3(module=esnext).types | 21 ++++++++++ .../importAssertion/importAssertion3.ts | 15 ++++++++ 11 files changed, 232 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/importAssertion3(module=es2015).errors.txt create mode 100644 tests/baselines/reference/importAssertion3(module=es2015).js create mode 100644 tests/baselines/reference/importAssertion3(module=es2015).symbols create mode 100644 tests/baselines/reference/importAssertion3(module=es2015).types create mode 100644 tests/baselines/reference/importAssertion3(module=esnext).errors.txt create mode 100644 tests/baselines/reference/importAssertion3(module=esnext).js create mode 100644 tests/baselines/reference/importAssertion3(module=esnext).symbols create mode 100644 tests/baselines/reference/importAssertion3(module=esnext).types create mode 100644 tests/cases/conformance/importAssertion/importAssertion3.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 32f00541044a3..ad43f2e500822 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -37443,9 +37443,15 @@ namespace ts { } } - function checkGrammarAssertClause(declaration: ImportDeclaration | ExportDeclaration) { - if (declaration.assertClause && moduleKind !== ModuleKind.ESNext) { - grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext); + function checkAssertClause(declaration: ImportDeclaration | ExportDeclaration) { + if (declaration.assertClause) { + if (moduleKind !== ModuleKind.ESNext) { + error(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext); + } + + if (isImportDeclaration(declaration) ? declaration.importClause?.isTypeOnly : declaration.isTypeOnly) { + error(declaration.assertClause, Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports); + } } } @@ -37480,7 +37486,7 @@ namespace ts { } } } - checkGrammarAssertClause(node); + checkAssertClause(node); } function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { @@ -37575,7 +37581,7 @@ namespace ts { } } } - checkGrammarAssertClause(node); + checkAssertClause(node); } function checkGrammarExportDeclaration(node: ExportDeclaration): boolean { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b6bbc3e045018..13e262e373a9d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3292,6 +3292,10 @@ "category": "Error", "code": 2803 }, + "Import assertions cannot be used with type-only imports or exports.": { + "category": "Error", + "code": 2804 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/tests/baselines/reference/importAssertion3(module=es2015).errors.txt b/tests/baselines/reference/importAssertion3(module=es2015).errors.txt new file mode 100644 index 0000000000000..dbdd8f5c53bba --- /dev/null +++ b/tests/baselines/reference/importAssertion3(module=es2015).errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/importAssertion/1.ts(1,27): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,27): error TS2804: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/1.ts(2,30): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,30): error TS2804: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/2.ts(1,31): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,31): error TS2804: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/2.ts(2,33): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,33): error TS2804: Import assertions cannot be used with type-only imports or exports. + + +==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== + export interface I { } + +==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== + export type {} from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2804: Import assertions cannot be used with type-only imports or exports. + export type { I } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2804: Import assertions cannot be used with type-only imports or exports. + +==== tests/cases/conformance/importAssertion/2.ts (4 errors) ==== + import type { I } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2804: Import assertions cannot be used with type-only imports or exports. + import type * as foo from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2804: Import assertions cannot be used with type-only imports or exports. + + \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion3(module=es2015).js b/tests/baselines/reference/importAssertion3(module=es2015).js new file mode 100644 index 0000000000000..2044e3ed0500d --- /dev/null +++ b/tests/baselines/reference/importAssertion3(module=es2015).js @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/importAssertion/importAssertion3.ts] //// + +//// [0.ts] +export interface I { } + +//// [1.ts] +export type {} from './0' assert { type: "json" } +export type { I } from './0' assert { type: "json" } + +//// [2.ts] +import type { I } from './0' assert { type: "json" } +import type * as foo from './0' assert { type: "json" } + + + +//// [0.js] +export {}; +//// [1.js] +export {}; +//// [2.js] +export {}; + + +//// [0.d.ts] +export interface I { +} +//// [1.d.ts] +export type {} from './0'; +export type { I } from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/importAssertion3(module=es2015).symbols b/tests/baselines/reference/importAssertion3(module=es2015).symbols new file mode 100644 index 0000000000000..f2ceb4a9cf3cc --- /dev/null +++ b/tests/baselines/reference/importAssertion3(module=es2015).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/importAssertion/0.ts === +export interface I { } +>I : Symbol(I, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/importAssertion/1.ts === +export type {} from './0' assert { type: "json" } +export type { I } from './0' assert { type: "json" } +>I : Symbol(I, Decl(1.ts, 1, 13)) + +=== tests/cases/conformance/importAssertion/2.ts === +import type { I } from './0' assert { type: "json" } +>I : Symbol(I, Decl(2.ts, 0, 13)) + +import type * as foo from './0' assert { type: "json" } +>foo : Symbol(foo, Decl(2.ts, 1, 11)) + + diff --git a/tests/baselines/reference/importAssertion3(module=es2015).types b/tests/baselines/reference/importAssertion3(module=es2015).types new file mode 100644 index 0000000000000..664ec54ac4a2b --- /dev/null +++ b/tests/baselines/reference/importAssertion3(module=es2015).types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/importAssertion/0.ts === +export interface I { } +No type information for this code. +No type information for this code.=== tests/cases/conformance/importAssertion/1.ts === +export type {} from './0' assert { type: "json" } +>type : any + +export type { I } from './0' assert { type: "json" } +>I : import("tests/cases/conformance/importAssertion/0").I +>type : any + +=== tests/cases/conformance/importAssertion/2.ts === +import type { I } from './0' assert { type: "json" } +>I : I +>type : any + +import type * as foo from './0' assert { type: "json" } +>foo : typeof foo +>type : any + + diff --git a/tests/baselines/reference/importAssertion3(module=esnext).errors.txt b/tests/baselines/reference/importAssertion3(module=esnext).errors.txt new file mode 100644 index 0000000000000..20b3109a17651 --- /dev/null +++ b/tests/baselines/reference/importAssertion3(module=esnext).errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/importAssertion/1.ts(1,27): error TS2804: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/1.ts(2,30): error TS2804: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/2.ts(1,31): error TS2804: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/2.ts(2,33): error TS2804: Import assertions cannot be used with type-only imports or exports. + + +==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== + export interface I { } + +==== tests/cases/conformance/importAssertion/1.ts (2 errors) ==== + export type {} from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2804: Import assertions cannot be used with type-only imports or exports. + export type { I } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2804: Import assertions cannot be used with type-only imports or exports. + +==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== + import type { I } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2804: Import assertions cannot be used with type-only imports or exports. + import type * as foo from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2804: Import assertions cannot be used with type-only imports or exports. + + \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion3(module=esnext).js b/tests/baselines/reference/importAssertion3(module=esnext).js new file mode 100644 index 0000000000000..2044e3ed0500d --- /dev/null +++ b/tests/baselines/reference/importAssertion3(module=esnext).js @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/importAssertion/importAssertion3.ts] //// + +//// [0.ts] +export interface I { } + +//// [1.ts] +export type {} from './0' assert { type: "json" } +export type { I } from './0' assert { type: "json" } + +//// [2.ts] +import type { I } from './0' assert { type: "json" } +import type * as foo from './0' assert { type: "json" } + + + +//// [0.js] +export {}; +//// [1.js] +export {}; +//// [2.js] +export {}; + + +//// [0.d.ts] +export interface I { +} +//// [1.d.ts] +export type {} from './0'; +export type { I } from './0'; +//// [2.d.ts] +export {}; diff --git a/tests/baselines/reference/importAssertion3(module=esnext).symbols b/tests/baselines/reference/importAssertion3(module=esnext).symbols new file mode 100644 index 0000000000000..f2ceb4a9cf3cc --- /dev/null +++ b/tests/baselines/reference/importAssertion3(module=esnext).symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/importAssertion/0.ts === +export interface I { } +>I : Symbol(I, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/importAssertion/1.ts === +export type {} from './0' assert { type: "json" } +export type { I } from './0' assert { type: "json" } +>I : Symbol(I, Decl(1.ts, 1, 13)) + +=== tests/cases/conformance/importAssertion/2.ts === +import type { I } from './0' assert { type: "json" } +>I : Symbol(I, Decl(2.ts, 0, 13)) + +import type * as foo from './0' assert { type: "json" } +>foo : Symbol(foo, Decl(2.ts, 1, 11)) + + diff --git a/tests/baselines/reference/importAssertion3(module=esnext).types b/tests/baselines/reference/importAssertion3(module=esnext).types new file mode 100644 index 0000000000000..664ec54ac4a2b --- /dev/null +++ b/tests/baselines/reference/importAssertion3(module=esnext).types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/importAssertion/0.ts === +export interface I { } +No type information for this code. +No type information for this code.=== tests/cases/conformance/importAssertion/1.ts === +export type {} from './0' assert { type: "json" } +>type : any + +export type { I } from './0' assert { type: "json" } +>I : import("tests/cases/conformance/importAssertion/0").I +>type : any + +=== tests/cases/conformance/importAssertion/2.ts === +import type { I } from './0' assert { type: "json" } +>I : I +>type : any + +import type * as foo from './0' assert { type: "json" } +>foo : typeof foo +>type : any + + diff --git a/tests/cases/conformance/importAssertion/importAssertion3.ts b/tests/cases/conformance/importAssertion/importAssertion3.ts new file mode 100644 index 0000000000000..28479378b162d --- /dev/null +++ b/tests/cases/conformance/importAssertion/importAssertion3.ts @@ -0,0 +1,15 @@ +// @declaration: true +// @target: es2015 +// @module: es2015, esnext + +// @filename: 0.ts +export interface I { } + +// @filename: 1.ts +export type {} from './0' assert { type: "json" } +export type { I } from './0' assert { type: "json" } + +// @filename: 2.ts +import type { I } from './0' assert { type: "json" } +import type * as foo from './0' assert { type: "json" } + From eee2cab6160146f6dc9f4080699cd90731a5bf56 Mon Sep 17 00:00:00 2001 From: kingwl Date: Thu, 17 Jun 2021 11:17:04 +0800 Subject: [PATCH 19/25] Accept baseline --- ...portAssertion1(module=commonjs).errors.txt | 24 +++++++------- ...importAssertion1(module=es2015).errors.txt | 20 ++++++------ ...importAssertion1(module=esnext).errors.txt | 32 +++++++++---------- ...portAssertion2(module=commonjs).errors.txt | 24 +++++++------- .../importAssertion2(module=commonjs).types | 2 +- ...importAssertion2(module=es2015).errors.txt | 24 +++++++------- .../importAssertion2(module=es2015).types | 2 +- .../importAssertion2(module=esnext).types | 2 +- ...importAssertion3(module=es2015).errors.txt | 32 +++++++++---------- ...importAssertion3(module=esnext).errors.txt | 16 +++++----- 10 files changed, 89 insertions(+), 89 deletions(-) diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt index 0882579681a55..9b9dbdd5f5e85 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,14): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,28): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/3.ts(2,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/3.ts(3,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/3.ts(4,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/3.ts(5,26): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/3.ts(7,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/3.ts(8,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(8,11): message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments tests/cases/conformance/importAssertion/3.ts(9,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/3.ts(10,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comma not allowed. @@ -21,13 +21,13 @@ tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comm ==== tests/cases/conformance/importAssertion/1.ts (3 errors) ==== import './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. import { a, b } from './0' assert { "type": "json" } ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. import * as foo from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. a; b; foo.a; @@ -36,10 +36,10 @@ tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comm ==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== import { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. a; b; c; @@ -65,7 +65,7 @@ tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comm !!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. const f = import() ~~~~~~~~ -!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments const g = import('./0', {}, {}) ~~ !!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. diff --git a/tests/baselines/reference/importAssertion1(module=es2015).errors.txt b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt index d9a2a4c804d3b..56bcf11686791 100644 --- a/tests/baselines/reference/importAssertion1(module=es2015).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/importAssertion/1.ts(1,14): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(3,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,14): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,28): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/3.ts(1,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. tests/cases/conformance/importAssertion/3.ts(2,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. tests/cases/conformance/importAssertion/3.ts(3,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'esnext', 'commonjs', 'amd', 'system', or 'umd'. @@ -21,13 +21,13 @@ tests/cases/conformance/importAssertion/3.ts(10,11): error TS1323: Dynamic impor ==== tests/cases/conformance/importAssertion/1.ts (3 errors) ==== import './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. import { a, b } from './0' assert { "type": "json" } ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. import * as foo from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. a; b; foo.a; @@ -36,10 +36,10 @@ tests/cases/conformance/importAssertion/3.ts(10,11): error TS1323: Dynamic impor ==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== import { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. a; b; c; diff --git a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt index 293d6b38a4d35..2f8cd4dd7e4d5 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/importAssertion/3.ts(2,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(3,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(4,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(5,12): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(7,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(8,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(9,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(10,11): message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(2,11): message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(3,11): message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(4,11): message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(5,12): message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(7,11): message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(8,11): message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(9,11): message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(10,11): message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -33,28 +33,28 @@ tests/cases/conformance/importAssertion/3.ts(10,11): message TS1433: Dynamic imp const a = import('./0') const b = import('./0', { assert: { type: "json" } }) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments const c = import('./0', { assert: { type: "json", ttype: "typo" } }) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments const d = import('./0', { assert: {} }) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments const dd = import('./0', {}) ~~~~~~~~~~~~~~~~~ -!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments declare function foo(): any; const e = import('./0', foo()) ~~~~~~~~~~~~~~~~~~~~ -!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments const f = import() ~~~~~~~~ -!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments const g = import('./0', {}, {}) ~~~~~~~~~~~~~~~~~~~~~ -!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments const h = import('./0', { assert: { type: "json" }},) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! message TS1433: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1434: Dynamic import must only have a specifier and an optional assertion as arguments \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt index 6660595493ab5..0941bd8455043 100644 --- a/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt +++ b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,22): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,21): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(4,27): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -13,22 +13,22 @@ tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import asserti ==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== export {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. export { a, b } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. export * from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. export * as ns from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. ==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== export { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).types b/tests/baselines/reference/importAssertion2(module=commonjs).types index 131c25077dccd..cc912547f7693 100644 --- a/tests/baselines/reference/importAssertion2(module=commonjs).types +++ b/tests/baselines/reference/importAssertion2(module=commonjs).types @@ -20,7 +20,7 @@ export * from './0' assert { type: "json" } >type : any export * as ns from './0' assert { type: "json" } ->ns : typeof ns +>ns : typeof import("tests/cases/conformance/importAssertion/0") >type : any === tests/cases/conformance/importAssertion/2.ts === diff --git a/tests/baselines/reference/importAssertion2(module=es2015).errors.txt b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt index 6660595493ab5..0941bd8455043 100644 --- a/tests/baselines/reference/importAssertion2(module=es2015).errors.txt +++ b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/importAssertion/1.ts(1,22): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(2,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(3,21): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(4,27): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(1,28): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,22): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,21): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(4,27): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -13,22 +13,22 @@ tests/cases/conformance/importAssertion/2.ts(2,38): error TS2803: Import asserti ==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== export {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. export { a, b } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. export * from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. export * as ns from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. ==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== export { a, b } from './0' assert {} ~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion2(module=es2015).types b/tests/baselines/reference/importAssertion2(module=es2015).types index 131c25077dccd..cc912547f7693 100644 --- a/tests/baselines/reference/importAssertion2(module=es2015).types +++ b/tests/baselines/reference/importAssertion2(module=es2015).types @@ -20,7 +20,7 @@ export * from './0' assert { type: "json" } >type : any export * as ns from './0' assert { type: "json" } ->ns : typeof ns +>ns : typeof import("tests/cases/conformance/importAssertion/0") >type : any === tests/cases/conformance/importAssertion/2.ts === diff --git a/tests/baselines/reference/importAssertion2(module=esnext).types b/tests/baselines/reference/importAssertion2(module=esnext).types index 6b28d870ab018..3fa4d2bb27271 100644 --- a/tests/baselines/reference/importAssertion2(module=esnext).types +++ b/tests/baselines/reference/importAssertion2(module=esnext).types @@ -20,7 +20,7 @@ export * from './0' assert { type: "json" } >type : error export * as ns from './0' assert { type: "json" } ->ns : typeof ns +>ns : typeof import("tests/cases/conformance/importAssertion/0") >type : error === tests/cases/conformance/importAssertion/2.ts === diff --git a/tests/baselines/reference/importAssertion3(module=es2015).errors.txt b/tests/baselines/reference/importAssertion3(module=es2015).errors.txt index dbdd8f5c53bba..32768c1e1d1d0 100644 --- a/tests/baselines/reference/importAssertion3(module=es2015).errors.txt +++ b/tests/baselines/reference/importAssertion3(module=es2015).errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/importAssertion/1.ts(1,27): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(1,27): error TS2804: Import assertions cannot be used with type-only imports or exports. -tests/cases/conformance/importAssertion/1.ts(2,30): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(2,30): error TS2804: Import assertions cannot be used with type-only imports or exports. -tests/cases/conformance/importAssertion/2.ts(1,31): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(1,31): error TS2804: Import assertions cannot be used with type-only imports or exports. -tests/cases/conformance/importAssertion/2.ts(2,33): error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(2,33): error TS2804: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/1.ts(1,27): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(1,27): error TS2816: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/1.ts(2,30): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,30): error TS2816: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/2.ts(1,31): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,31): error TS2816: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/2.ts(2,33): error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,33): error TS2816: Import assertions cannot be used with type-only imports or exports. ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -14,25 +14,25 @@ tests/cases/conformance/importAssertion/2.ts(2,33): error TS2804: Import asserti ==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== export type {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2804: Import assertions cannot be used with type-only imports or exports. +!!! error TS2816: Import assertions cannot be used with type-only imports or exports. export type { I } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2804: Import assertions cannot be used with type-only imports or exports. +!!! error TS2816: Import assertions cannot be used with type-only imports or exports. ==== tests/cases/conformance/importAssertion/2.ts (4 errors) ==== import type { I } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2804: Import assertions cannot be used with type-only imports or exports. +!!! error TS2816: Import assertions cannot be used with type-only imports or exports. import type * as foo from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2803: Import assertions are only supported when the '--module' option is set to 'esnext'. +!!! error TS2815: Import assertions are only supported when the '--module' option is set to 'esnext'. ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2804: Import assertions cannot be used with type-only imports or exports. +!!! error TS2816: Import assertions cannot be used with type-only imports or exports. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion3(module=esnext).errors.txt b/tests/baselines/reference/importAssertion3(module=esnext).errors.txt index 20b3109a17651..99f6c111910ef 100644 --- a/tests/baselines/reference/importAssertion3(module=esnext).errors.txt +++ b/tests/baselines/reference/importAssertion3(module=esnext).errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/importAssertion/1.ts(1,27): error TS2804: Import assertions cannot be used with type-only imports or exports. -tests/cases/conformance/importAssertion/1.ts(2,30): error TS2804: Import assertions cannot be used with type-only imports or exports. -tests/cases/conformance/importAssertion/2.ts(1,31): error TS2804: Import assertions cannot be used with type-only imports or exports. -tests/cases/conformance/importAssertion/2.ts(2,33): error TS2804: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/1.ts(1,27): error TS2816: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/1.ts(2,30): error TS2816: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/2.ts(1,31): error TS2816: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/2.ts(2,33): error TS2816: Import assertions cannot be used with type-only imports or exports. ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -10,17 +10,17 @@ tests/cases/conformance/importAssertion/2.ts(2,33): error TS2804: Import asserti ==== tests/cases/conformance/importAssertion/1.ts (2 errors) ==== export type {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2804: Import assertions cannot be used with type-only imports or exports. +!!! error TS2816: Import assertions cannot be used with type-only imports or exports. export type { I } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2804: Import assertions cannot be used with type-only imports or exports. +!!! error TS2816: Import assertions cannot be used with type-only imports or exports. ==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== import type { I } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2804: Import assertions cannot be used with type-only imports or exports. +!!! error TS2816: Import assertions cannot be used with type-only imports or exports. import type * as foo from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2804: Import assertions cannot be used with type-only imports or exports. +!!! error TS2816: Import assertions cannot be used with type-only imports or exports. \ No newline at end of file From 88e39d570596fe31ac2e9d47a7aaa47704c026de Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Fri, 9 Jul 2021 16:24:50 +0800 Subject: [PATCH 20/25] Make lint happy --- src/compiler/parser.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 026d093b2ed3e..eabe490d1cdba 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -400,17 +400,14 @@ namespace ts { visitNode(cbNode, (node as ImportDeclaration).importClause) || visitNode(cbNode, (node as ImportDeclaration).moduleSpecifier) || visitNode(cbNode, (node as ImportDeclaration).assertClause); - case SyntaxKind.ImportClause: - return visitNode(cbNode, (node).name) || - visitNode(cbNode, (node).namedBindings); - case SyntaxKind.AssertClause: - return visitNodes(cbNode, cbNodes, (node).elements); - case SyntaxKind.AssertEntry: - return visitNode(cbNode, (node).name) || - visitNode(cbNode, (node).value); case SyntaxKind.ImportClause: return visitNode(cbNode, (node as ImportClause).name) || visitNode(cbNode, (node as ImportClause).namedBindings); + case SyntaxKind.AssertClause: + return visitNodes(cbNode, cbNodes, (node as AssertClause).elements); + case SyntaxKind.AssertEntry: + return visitNode(cbNode, (node as AssertEntry).name) || + visitNode(cbNode, (node as AssertEntry).value); case SyntaxKind.NamespaceExportDeclaration: return visitNode(cbNode, (node as NamespaceExportDeclaration).name); case SyntaxKind.NamespaceImport: From 106ff06ee32702ddd8bb5db0f5d79d6315d3f7f0 Mon Sep 17 00:00:00 2001 From: Wenlu Wang Date: Fri, 13 Aug 2021 16:00:07 +0800 Subject: [PATCH 21/25] Add some comment --- src/compiler/checker.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ef4a18264bbba..3d9a4fcb8f563 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -42792,6 +42792,7 @@ namespace ts { function checkGrammarImportCallArguments(node: ImportCall, nodeArguments: NodeArray): boolean { if (moduleKind !== ModuleKind.ESNext) { + // We are allowed trailing comma after proposal-import-assertions. checkGrammarForDisallowedTrailingComma(nodeArguments); if (nodeArguments.length > 1) { From 6ea3c55c921ab7247b48940bf2b56c0c6b981079 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 14 Sep 2021 19:55:42 +0800 Subject: [PATCH 22/25] Fix cr issues --- src/compiler/checker.ts | 33 ++++++++----------- src/compiler/emitter.ts | 6 ++-- src/compiler/types.ts | 6 ++-- src/compiler/utilitiesPublic.ts | 1 - ...importAssertion1(module=esnext).errors.txt | 20 +---------- ...importAssertion3(module=es2015).errors.txt | 16 ++------- 6 files changed, 22 insertions(+), 60 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8d580883db14f..e91ca978242c2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -39000,11 +39000,11 @@ namespace ts { function checkAssertClause(declaration: ImportDeclaration | ExportDeclaration) { if (declaration.assertClause) { if (moduleKind !== ModuleKind.ESNext) { - error(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext); + return grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext); } if (isImportDeclaration(declaration) ? declaration.importClause?.isTypeOnly : declaration.isTypeOnly) { - error(declaration.assertClause, Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports); + return grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports); } } } @@ -43162,7 +43162,16 @@ namespace ts { return false; } - function checkGrammarImportCallArguments(node: ImportCall, nodeArguments: NodeArray): boolean { + function checkGrammarImportCallExpression(node: ImportCall): boolean { + if (moduleKind === ModuleKind.ES2015) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_or_umd); + } + + if (node.typeArguments) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_have_type_arguments); + } + + const nodeArguments = node.arguments; if (moduleKind !== ModuleKind.ESNext) { // We are allowed trailing comma after proposal-import-assertions. checkGrammarForDisallowedTrailingComma(nodeArguments); @@ -43172,25 +43181,11 @@ namespace ts { return grammarErrorOnNode(assertionArgument, Diagnostics.Dynamic_import_only_supports_a_second_argument_when_the_module_option_is_set_to_esnext); } } - if (nodeArguments.length !== 1) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_only_have_a_specifier_and_an_optional_assertion_as_arguments); - } - return false; - } - - function checkGrammarImportCallExpression(node: ImportCall): boolean { - if (moduleKind === ModuleKind.ES2015) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_are_only_supported_when_the_module_flag_is_set_to_es2020_esnext_commonjs_amd_system_or_umd); - } - if (node.typeArguments) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_cannot_have_type_arguments); + if (nodeArguments.length === 0 || nodeArguments.length > 2) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_only_have_a_specifier_and_an_optional_assertion_as_arguments); } - const nodeArguments = node.arguments; - if (checkGrammarImportCallArguments(node, nodeArguments)) { - return true; - } // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import. if (nodeArguments.length && isSpreadElement(nodeArguments[0])) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6bfa6995ff973..23cdda71a2ac1 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3327,8 +3327,7 @@ namespace ts { } emitExpression(node.moduleSpecifier); if (node.assertClause) { - writeSpace(); - emit(node.assertClause); + emitWithLeadingSpace(node.assertClause); } writeTrailingSemicolon(); } @@ -3399,8 +3398,7 @@ namespace ts { emitExpression(node.moduleSpecifier); } if (node.assertClause) { - writeSpace(); - emit(node.assertClause); + emitWithLeadingSpace(node.assertClause); } writeTrailingSemicolon(); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4744df3e32cd9..ce4b23b3a515c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7341,8 +7341,8 @@ namespace ts { updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; - createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; - updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; + createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause): ImportDeclaration; + updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause): ImportDeclaration; createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; createAssertClause(elements: NodeArray, multiLine?: boolean): AssertClause; @@ -7360,7 +7360,7 @@ namespace ts { createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment; createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, assertClause?: AssertClause): ExportDeclaration; - updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause: AssertClause | undefined): ExportDeclaration; + updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause?: AssertClause): ExportDeclaration; createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; diff --git a/src/compiler/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index e95667ec86fbd..a5c0f9296d350 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1378,7 +1378,6 @@ namespace ts { /* @internal */ export function isAssignmentPattern(node: Node): node is AssignmentPattern { const kind = node.kind; - return kind === SyntaxKind.ArrayLiteralExpression || kind === SyntaxKind.ObjectLiteralExpression; } diff --git a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt index 35b858921691a..b88632c3afbdb 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt @@ -1,11 +1,5 @@ -tests/cases/conformance/importAssertion/3.ts(2,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(3,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(4,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(5,12): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(7,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments tests/cases/conformance/importAssertion/3.ts(8,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments tests/cases/conformance/importAssertion/3.ts(9,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(10,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -29,24 +23,14 @@ tests/cases/conformance/importAssertion/3.ts(10,11): message TS1450: Dynamic imp c; d; -==== tests/cases/conformance/importAssertion/3.ts (8 errors) ==== +==== tests/cases/conformance/importAssertion/3.ts (2 errors) ==== const a = import('./0') const b = import('./0', { assert: { type: "json" } }) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments const c = import('./0', { assert: { type: "json", ttype: "typo" } }) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments const d = import('./0', { assert: {} }) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments const dd = import('./0', {}) - ~~~~~~~~~~~~~~~~~ -!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments declare function foo(): any; const e = import('./0', foo()) - ~~~~~~~~~~~~~~~~~~~~ -!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments const f = import() ~~~~~~~~ !!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments @@ -54,7 +38,5 @@ tests/cases/conformance/importAssertion/3.ts(10,11): message TS1450: Dynamic imp ~~~~~~~~~~~~~~~~~~~~~ !!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments const h = import('./0', { assert: { type: "json" }},) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion3(module=es2015).errors.txt b/tests/baselines/reference/importAssertion3(module=es2015).errors.txt index 73abec1ae98c9..3303de71fd183 100644 --- a/tests/baselines/reference/importAssertion3(module=es2015).errors.txt +++ b/tests/baselines/reference/importAssertion3(module=es2015).errors.txt @@ -1,38 +1,26 @@ tests/cases/conformance/importAssertion/1.ts(1,27): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(1,27): error TS2821: Import assertions cannot be used with type-only imports or exports. tests/cases/conformance/importAssertion/1.ts(2,30): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/1.ts(2,30): error TS2821: Import assertions cannot be used with type-only imports or exports. tests/cases/conformance/importAssertion/2.ts(1,31): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(1,31): error TS2821: Import assertions cannot be used with type-only imports or exports. tests/cases/conformance/importAssertion/2.ts(2,33): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/2.ts(2,33): error TS2821: Import assertions cannot be used with type-only imports or exports. ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== export interface I { } -==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== +==== tests/cases/conformance/importAssertion/1.ts (2 errors) ==== export type {} from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2821: Import assertions cannot be used with type-only imports or exports. export type { I } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2821: Import assertions cannot be used with type-only imports or exports. -==== tests/cases/conformance/importAssertion/2.ts (4 errors) ==== +==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== import type { I } from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2821: Import assertions cannot be used with type-only imports or exports. import type * as foo from './0' assert { type: "json" } ~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. - ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2821: Import assertions cannot be used with type-only imports or exports. \ No newline at end of file From fc51c42c96ca38e16020adf215b3ebd339458a40 Mon Sep 17 00:00:00 2001 From: kingwl Date: Tue, 14 Sep 2021 20:02:09 +0800 Subject: [PATCH 23/25] Fix more issue --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e91ca978242c2..a295eb92edaca 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -43188,7 +43188,8 @@ namespace ts { // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import. - if (nodeArguments.length && isSpreadElement(nodeArguments[0])) { + const spreadElement = forEach(nodeArguments, isSpreadElement); + if (spreadElement) { return grammarErrorOnNode(nodeArguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); } return false; From bf7ca71053fdd89dfc3ff13b5eebdd619531ae11 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 17 Sep 2021 15:20:01 -0700 Subject: [PATCH 24/25] Incorporate PR feedback, fix module resolution for import() --- src/compiler/checker.ts | 26 +++++++++++---- src/compiler/diagnosticMessages.json | 6 ++-- src/compiler/program.ts | 4 +-- src/compiler/types.ts | 4 +-- src/harness/fourslashInterfaceImpl.ts | 2 ++ src/lib/es5.d.ts | 17 ++++++++++ .../reference/api/tsserverlibrary.d.ts | 4 +-- tests/baselines/reference/api/typescript.d.ts | 4 +-- ...tructuringParameterDeclaration4.errors.txt | 2 +- .../duplicateNumericIndexers.errors.txt | 2 +- .../reference/externModule.errors.txt | 8 ++--- ...portAssertion1(module=commonjs).errors.txt | 32 +++++++++---------- ...importAssertion1(module=esnext).errors.txt | 8 ++--- ...mportCallExpressionGrammarError.errors.txt | 21 ++++++------ ...ithAsClauseAndLateBoundProperty.errors.txt | 2 +- ...wExceptionVariableInCatchClause.errors.txt | 2 +- .../narrowFromAnyWithInstanceof.errors.txt | 4 +-- .../narrowFromAnyWithTypePredicate.errors.txt | 4 +-- .../reference/parserS7.2_A1.5_T2.errors.txt | 4 +-- .../reference/parserS7.3_A1.1_T2.errors.txt | 2 +- .../reference/parserS7.6_A4.2_T1.errors.txt | 20 ++++++------ .../reference/parserUnicode1.errors.txt | 4 +-- .../reference/promisePermutations.errors.txt | 2 +- .../reference/promisePermutations2.errors.txt | 2 +- .../reference/promisePermutations3.errors.txt | 4 +-- .../reference/redefineArray.errors.txt | 2 +- .../reference/scannerS7.2_A1.5_T2.errors.txt | 4 +-- .../reference/scannerS7.3_A1.1_T2.errors.txt | 2 +- .../reference/scannerS7.6_A4.2_T1.errors.txt | 20 ++++++------ 29 files changed, 127 insertions(+), 91 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a295eb92edaca..46a382e84bcd4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -933,6 +933,7 @@ namespace ts { let deferredGlobalTemplateStringsArrayType: ObjectType | undefined; let deferredGlobalImportMetaType: ObjectType; let deferredGlobalImportMetaExpressionType: ObjectType; + let deferredGlobalImportCallOptionsType: ObjectType | undefined; let deferredGlobalExtractSymbol: Symbol | undefined; let deferredGlobalOmitSymbol: Symbol | undefined; let deferredGlobalAwaitedSymbol: Symbol | undefined; @@ -13460,6 +13461,11 @@ namespace ts { return deferredGlobalImportMetaExpressionType; } + function getGlobalImportCallOptionsType(reportErrors: boolean) { + // We always report an error, so store a result in the event we could not resolve the symbol to prevent reporting it multiple times + return (deferredGlobalImportCallOptionsType ||= getGlobalType("ImportCallOptions" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType; + } + function getGlobalESSymbolConstructorSymbol(reportErrors: boolean): Symbol | undefined { return deferredGlobalESSymbolConstructorSymbol ||= getGlobalValueSymbol("Symbol" as __String, reportErrors); } @@ -30587,8 +30593,9 @@ namespace ts { } const specifier = node.arguments[0]; const specifierType = checkExpressionCached(specifier); + const optionsType = node.arguments.length > 1 ? checkExpressionCached(node.arguments[1]) : undefined; // Even though multiple arguments is grammatically incorrect, type-check extra arguments for completion - for (let i = 1; i < node.arguments.length; ++i) { + for (let i = 2; i < node.arguments.length; ++i) { checkExpressionCached(node.arguments[i]); } @@ -30596,6 +30603,13 @@ namespace ts { error(specifier, Diagnostics.Dynamic_import_s_specifier_must_be_of_type_string_but_here_has_type_0, typeToString(specifierType)); } + if (optionsType) { + const importCallOptionsType = getGlobalImportCallOptionsType(/*reportErrors*/ true); + if (importCallOptionsType !== emptyObjectType) { + checkTypeAssignableTo(optionsType, getNullableType(importCallOptionsType, TypeFlags.Undefined), node.arguments[1]); + } + } + // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal const moduleSymbol = resolveExternalModuleName(node, specifier); if (moduleSymbol) { @@ -43178,19 +43192,19 @@ namespace ts { if (nodeArguments.length > 1) { const assertionArgument = nodeArguments[1]; - return grammarErrorOnNode(assertionArgument, Diagnostics.Dynamic_import_only_supports_a_second_argument_when_the_module_option_is_set_to_esnext); + return grammarErrorOnNode(assertionArgument, Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext); } } - if (nodeArguments.length === 0 || nodeArguments.length > 2) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_only_have_a_specifier_and_an_optional_assertion_as_arguments); + if (nodeArguments.length === 0 || nodeArguments.length > 2) { + return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments); } // see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import. // parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import. - const spreadElement = forEach(nodeArguments, isSpreadElement); + const spreadElement = find(nodeArguments, isSpreadElement); if (spreadElement) { - return grammarErrorOnNode(nodeArguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); + return grammarErrorOnNode(spreadElement, Diagnostics.Argument_of_dynamic_import_cannot_be_spread_element); } return false; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index f05383e680521..c73376c2eee6e 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -924,11 +924,11 @@ "category": "Error", "code": 1323 }, - "Dynamic import only supports a second argument when the '--module' option is set to 'esnext'.": { + "Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.": { "category": "Error", "code": 1324 }, - "Specifier of dynamic import cannot be spread element.": { + "Argument of dynamic import cannot be spread element.": { "category": "Error", "code": 1325 }, @@ -1388,7 +1388,7 @@ "category": "Message", "code": 1449 }, - "Dynamic import must only have a specifier and an optional assertion as arguments": { + "Dynamic imports can only accept a module specifier and an optional assertion as arguments": { "category": "Message", "code": 1450 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 36e445790699c..4293dea62cf37 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2374,8 +2374,8 @@ namespace ts { if (isJavaScriptFile && isRequireCall(node, /*checkArgumentIsStringLiteralLike*/ true)) { imports = append(imports, node.arguments[0]); } - // we have to check the argument list has length of 1. We will still have to process these even though we have parsing error. - else if (isImportCall(node) && node.arguments.length === 1 && isStringLiteralLike(node.arguments[0])) { + // we have to check the argument list has length of at least 1. We will still have to process these even though we have parsing error. + else if (isImportCall(node) && node.arguments.length >= 1 && isStringLiteralLike(node.arguments[0])) { imports = append(imports, node.arguments[0]); } else if (isLiteralImportTypeNode(node)) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ce4b23b3a515c..65bb43f624670 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7342,7 +7342,7 @@ namespace ts { createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause): ImportDeclaration; - updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause): ImportDeclaration; + updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; createAssertClause(elements: NodeArray, multiLine?: boolean): AssertClause; @@ -7360,7 +7360,7 @@ namespace ts { createExportAssignment(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment; updateExportAssignment(node: ExportAssignment, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, expression: Expression): ExportAssignment; createExportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, assertClause?: AssertClause): ExportDeclaration; - updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause?: AssertClause): ExportDeclaration; + updateExportDeclaration(node: ExportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause: AssertClause | undefined): ExportDeclaration; createNamedExports(elements: readonly ExportSpecifier[]): NamedExports; updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports; createExportSpecifier(propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier; diff --git a/src/harness/fourslashInterfaceImpl.ts b/src/harness/fourslashInterfaceImpl.ts index f1a92013fb8f5..557b41f6c2fa2 100644 --- a/src/harness/fourslashInterfaceImpl.ts +++ b/src/harness/fourslashInterfaceImpl.ts @@ -1061,6 +1061,8 @@ namespace FourSlashInterface { interfaceEntry("NumberConstructor"), interfaceEntry("TemplateStringsArray"), interfaceEntry("ImportMeta"), + interfaceEntry("ImportCallOptions"), + interfaceEntry("ImportAssertions"), varEntry("Math"), varEntry("Date"), interfaceEntry("DateConstructor"), diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 93fd3986e8c38..caf24fe95ed94 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -597,6 +597,23 @@ interface TemplateStringsArray extends ReadonlyArray { interface ImportMeta { } +/** + * The type for the optional second argument to `import()`. + * + * If your host environment supports additional options, this type may be + * augmented via interface merging. + */ +interface ImportCallOptions { + assert?: ImportAssertions; +} + +/** + * The type for the `assert` property of the optional second argument to `import()`. + */ +interface ImportAssertions { + [key: string]: string; +} + interface Math { /** The mathematical constant e. This is Euler's number, the base of natural logarithms. */ readonly E: number; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 96cec106d861a..7790ee6679637 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3538,7 +3538,7 @@ declare namespace ts { updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; - createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; + createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause): ImportDeclaration; updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; @@ -10988,7 +10988,7 @@ declare namespace ts { /** @deprecated Use `factory.updateImportEqualsDeclaration` or the factory supplied by your transformation context instead. */ const updateImportEqualsDeclaration: (node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference) => ImportEqualsDeclaration; /** @deprecated Use `factory.createImportDeclaration` or the factory supplied by your transformation context instead. */ - const createImportDeclaration: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined) => ImportDeclaration; + const createImportDeclaration: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause | undefined) => ImportDeclaration; /** @deprecated Use `factory.updateImportDeclaration` or the factory supplied by your transformation context instead. */ const updateImportDeclaration: (node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined) => ImportDeclaration; /** @deprecated Use `factory.createNamespaceImport` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index a5867dbe619f7..6b1a94c4ea926 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3538,7 +3538,7 @@ declare namespace ts { updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration; createImportEqualsDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; updateImportEqualsDeclaration(node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration; - createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; + createImportDeclaration(decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause): ImportDeclaration; updateImportDeclaration(node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration; createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause; @@ -7188,7 +7188,7 @@ declare namespace ts { /** @deprecated Use `factory.updateImportEqualsDeclaration` or the factory supplied by your transformation context instead. */ const updateImportEqualsDeclaration: (node: ImportEqualsDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference) => ImportEqualsDeclaration; /** @deprecated Use `factory.createImportDeclaration` or the factory supplied by your transformation context instead. */ - const createImportDeclaration: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined) => ImportDeclaration; + const createImportDeclaration: (decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause | undefined) => ImportDeclaration; /** @deprecated Use `factory.updateImportDeclaration` or the factory supplied by your transformation context instead. */ const updateImportDeclaration: (node: ImportDeclaration, decorators: readonly Decorator[] | undefined, modifiers: readonly Modifier[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined) => ImportDeclaration; /** @deprecated Use `factory.createNamespaceImport` or the factory supplied by your transformation context instead. */ diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index cc8a0a61196d9..44baff6fd37b9 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -41,7 +41,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( a1(...array2); // Error parameter type is (number|string)[] ~~~~~~ !!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'? -!!! related TS2728 /.ts/lib.es5.d.ts:1447:13: 'Array' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1464:13: 'Array' is declared here. a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] ~~~~~~~~ !!! error TS2322: Type 'string' is not assignable to type '[[any]]'. diff --git a/tests/baselines/reference/duplicateNumericIndexers.errors.txt b/tests/baselines/reference/duplicateNumericIndexers.errors.txt index a0558284060de..0d7c6f4eca64e 100644 --- a/tests/baselines/reference/duplicateNumericIndexers.errors.txt +++ b/tests/baselines/reference/duplicateNumericIndexers.errors.txt @@ -11,7 +11,7 @@ tests/cases/conformance/types/members/duplicateNumericIndexers.ts(25,5): error T tests/cases/conformance/types/members/duplicateNumericIndexers.ts(29,5): error TS2374: Duplicate index signature for type 'number'. tests/cases/conformance/types/members/duplicateNumericIndexers.ts(30,5): error TS2374: Duplicate index signature for type 'number'. lib.es5.d.ts(517,5): error TS2374: Duplicate index signature for type 'number'. -lib.es5.d.ts(1433,5): error TS2374: Duplicate index signature for type 'number'. +lib.es5.d.ts(1450,5): error TS2374: Duplicate index signature for type 'number'. ==== tests/cases/conformance/types/members/duplicateNumericIndexers.ts (12 errors) ==== diff --git a/tests/baselines/reference/externModule.errors.txt b/tests/baselines/reference/externModule.errors.txt index afcc73a1c26f3..616371995b236 100644 --- a/tests/baselines/reference/externModule.errors.txt +++ b/tests/baselines/reference/externModule.errors.txt @@ -66,20 +66,20 @@ tests/cases/compiler/externModule.ts(37,3): error TS2552: Cannot find name 'XDat var d=new XDate(); ~~~~~ !!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'? -!!! related TS2728 /.ts/lib.es5.d.ts:910:13: 'Date' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:927:13: 'Date' is declared here. d.getDay(); d=new XDate(1978,2); ~~~~~ !!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'? -!!! related TS2728 /.ts/lib.es5.d.ts:910:13: 'Date' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:927:13: 'Date' is declared here. d.getXDate(); var n=XDate.parse("3/2/2004"); ~~~~~ !!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'? -!!! related TS2728 /.ts/lib.es5.d.ts:910:13: 'Date' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:927:13: 'Date' is declared here. n=XDate.UTC(1964,2,1); ~~~~~ !!! error TS2552: Cannot find name 'XDate'. Did you mean 'Date'? -!!! related TS2728 /.ts/lib.es5.d.ts:910:13: 'Date' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:927:13: 'Date' is declared here. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt index e611ff1c806c3..52dd04889fc1d 100644 --- a/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt @@ -3,14 +3,14 @@ tests/cases/conformance/importAssertion/1.ts(2,28): error TS2820: Import asserti tests/cases/conformance/importAssertion/1.ts(3,28): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/2.ts(1,28): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/2.ts(2,38): error TS2820: Import assertions are only supported when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/3.ts(2,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/3.ts(3,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/3.ts(4,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/3.ts(5,26): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/3.ts(7,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/3.ts(8,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(9,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. -tests/cases/conformance/importAssertion/3.ts(10,25): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(2,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(3,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(4,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(5,26): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(7,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(8,11): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(9,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/3.ts(10,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comma not allowed. @@ -49,29 +49,29 @@ tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comm const a = import('./0') const b = import('./0', { assert: { type: "json" } }) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. const c = import('./0', { assert: { type: "json", ttype: "typo" } }) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. const d = import('./0', { assert: {} }) ~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. const dd = import('./0', {}) ~~ -!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. declare function foo(): any; const e = import('./0', foo()) ~~~~~ -!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. const f = import() ~~~~~~~~ -!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments const g = import('./0', {}, {}) ~~ -!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. const h = import('./0', { assert: { type: "json" }},) ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. ~ !!! error TS1009: Trailing comma not allowed. diff --git a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt index b88632c3afbdb..8dd6d05aaab4b 100644 --- a/tests/baselines/reference/importAssertion1(module=esnext).errors.txt +++ b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/importAssertion/3.ts(8,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments -tests/cases/conformance/importAssertion/3.ts(9,11): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(8,11): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments +tests/cases/conformance/importAssertion/3.ts(9,11): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments ==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== @@ -33,10 +33,10 @@ tests/cases/conformance/importAssertion/3.ts(9,11): message TS1450: Dynamic impo const e = import('./0', foo()) const f = import() ~~~~~~~~ -!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments const g = import('./0', {}, {}) ~~~~~~~~~~~~~~~~~~~~~ -!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments const h = import('./0', { assert: { type: "json" }},) \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt index 37130fa273ed0..57e3866b8f149 100644 --- a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt +++ b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt @@ -1,27 +1,30 @@ -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1325: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Specifier of dynamic import cannot be spread element. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(8,12): message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(5,8): error TS1325: Argument of dynamic import cannot be spread element. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Argument of dynamic import cannot be spread element. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(8,12): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations. -tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,35): error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,35): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. +tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,35): error TS2559: Type '"secondModule"' has no properties in common with type 'ImportCallOptions'. -==== tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts (5 errors) ==== +==== tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts (6 errors) ==== declare function getSpecifier(): string; declare var whatToLoad: boolean; var a = ["./0"]; import(...["PathModule"]); ~~~~~~~~~~~~~~~~~ -!!! error TS1325: Specifier of dynamic import cannot be spread element. +!!! error TS1325: Argument of dynamic import cannot be spread element. var p1 = import(...a); ~~~~ -!!! error TS1325: Specifier of dynamic import cannot be spread element. +!!! error TS1325: Argument of dynamic import cannot be spread element. const p2 = import(); ~~~~~~~~ -!!! message TS1450: Dynamic import must only have a specifier and an optional assertion as arguments +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments const p4 = import("pathToModule", "secondModule"); ~~~~~~~~~~~~~~ !!! error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations. ~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import only supports a second argument when the '--module' option is set to 'esnext'. \ No newline at end of file +!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. + ~~~~~~~~~~~~~~ +!!! error TS2559: Type '"secondModule"' has no properties in common with type 'ImportCallOptions'. \ No newline at end of file diff --git a/tests/baselines/reference/mappedTypeWithAsClauseAndLateBoundProperty.errors.txt b/tests/baselines/reference/mappedTypeWithAsClauseAndLateBoundProperty.errors.txt index f443baac49c4b..011b1b3c190b7 100644 --- a/tests/baselines/reference/mappedTypeWithAsClauseAndLateBoundProperty.errors.txt +++ b/tests/baselines/reference/mappedTypeWithAsClauseAndLateBoundProperty.errors.txt @@ -7,5 +7,5 @@ tests/cases/compiler/mappedTypeWithAsClauseAndLateBoundProperty.ts(3,1): error T tgt2 = src2; // Should error ~~~~ !!! error TS2741: Property 'length' is missing in type '{ [x: number]: number; toString: () => string; toLocaleString: () => string; pop: () => number; push: (...items: number[]) => number; concat: { (...items: ConcatArray[]): number[]; (...items: (number | ConcatArray)[]): number[]; }; join: (separator?: string) => string; reverse: () => number[]; shift: () => number; slice: (start?: number, end?: number) => number[]; sort: (compareFn?: (a: number, b: number) => number) => number[]; splice: { (start: number, deleteCount?: number): number[]; (start: number, deleteCount: number, ...items: number[]): number[]; }; unshift: (...items: number[]) => number; indexOf: (searchElement: number, fromIndex?: number) => number; lastIndexOf: (searchElement: number, fromIndex?: number) => number; every: { (predicate: (value: number, index: number, array: number[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: number, index: number, array: number[]) => unknown, thisArg?: any): boolean; }; some: (predicate: (value: number, index: number, array: number[]) => unknown, thisArg?: any) => boolean; forEach: (callbackfn: (value: number, index: number, array: number[]) => void, thisArg?: any) => void; map: (callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any) => U[]; filter: { (predicate: (value: number, index: number, array: number[]) => value is S, thisArg?: any): S[]; (predicate: (value: number, index: number, array: number[]) => unknown, thisArg?: any): number[]; }; reduce: { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }; reduceRight: { (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number): number; (callbackfn: (previousValue: number, currentValue: number, currentIndex: number, array: number[]) => number, initialValue: number): number; (callbackfn: (previousValue: U, currentValue: number, currentIndex: number, array: number[]) => U, initialValue: U): U; }; find: { (predicate: (this: void, value: number, index: number, obj: number[]) => value is S, thisArg?: any): S; (predicate: (value: number, index: number, obj: number[]) => unknown, thisArg?: any): number; }; findIndex: (predicate: (value: number, index: number, obj: number[]) => unknown, thisArg?: any) => number; fill: (value: number, start?: number, end?: number) => number[]; copyWithin: (target: number, start: number, end?: number) => number[]; entries: () => IterableIterator<[number, number]>; keys: () => IterableIterator; values: () => IterableIterator; includes: (searchElement: number, fromIndex?: number) => boolean; flatMap: (callback: (this: This, value: number, index: number, array: number[]) => U | readonly U[], thisArg?: This) => U[]; flat: (this: A, depth?: D) => FlatArray[]; [iterator]: () => IterableIterator; [unscopables]: () => { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }; }' but required in type 'number[]'. -!!! related TS2728 /.ts/lib.es5.d.ts:1256:5: 'length' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1273:5: 'length' is declared here. \ No newline at end of file diff --git a/tests/baselines/reference/narrowExceptionVariableInCatchClause.errors.txt b/tests/baselines/reference/narrowExceptionVariableInCatchClause.errors.txt index ce0410aece272..a5d4692930533 100644 --- a/tests/baselines/reference/narrowExceptionVariableInCatchClause.errors.txt +++ b/tests/baselines/reference/narrowExceptionVariableInCatchClause.errors.txt @@ -24,7 +24,7 @@ tests/cases/conformance/types/any/narrowExceptionVariableInCatchClause.ts(16,17) err.massage; // ERROR: Property 'massage' does not exist on type 'Error' ~~~~~~~ !!! error TS2551: Property 'massage' does not exist on type 'Error'. Did you mean 'message'? -!!! related TS2728 /.ts/lib.es5.d.ts:1006:5: 'message' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1023:5: 'message' is declared here. } else { diff --git a/tests/baselines/reference/narrowFromAnyWithInstanceof.errors.txt b/tests/baselines/reference/narrowFromAnyWithInstanceof.errors.txt index 6661db76c5e03..daf8ca72c39a4 100644 --- a/tests/baselines/reference/narrowFromAnyWithInstanceof.errors.txt +++ b/tests/baselines/reference/narrowFromAnyWithInstanceof.errors.txt @@ -22,7 +22,7 @@ tests/cases/conformance/types/any/narrowFromAnyWithInstanceof.ts(22,7): error TS x.mesage; ~~~~~~ !!! error TS2551: Property 'mesage' does not exist on type 'Error'. Did you mean 'message'? -!!! related TS2728 /.ts/lib.es5.d.ts:1006:5: 'message' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1023:5: 'message' is declared here. } if (x instanceof Date) { @@ -30,6 +30,6 @@ tests/cases/conformance/types/any/narrowFromAnyWithInstanceof.ts(22,7): error TS x.getHuors(); ~~~~~~~~ !!! error TS2551: Property 'getHuors' does not exist on type 'Date'. Did you mean 'getHours'? -!!! related TS2728 /.ts/lib.es5.d.ts:766:5: 'getHours' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:783:5: 'getHours' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/narrowFromAnyWithTypePredicate.errors.txt b/tests/baselines/reference/narrowFromAnyWithTypePredicate.errors.txt index 56cf384f28ac0..795bc68b93275 100644 --- a/tests/baselines/reference/narrowFromAnyWithTypePredicate.errors.txt +++ b/tests/baselines/reference/narrowFromAnyWithTypePredicate.errors.txt @@ -41,7 +41,7 @@ tests/cases/conformance/types/any/narrowFromAnyWithTypePredicate.ts(33,7): error x.mesage; ~~~~~~ !!! error TS2551: Property 'mesage' does not exist on type 'Error'. Did you mean 'message'? -!!! related TS2728 /.ts/lib.es5.d.ts:1006:5: 'message' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1023:5: 'message' is declared here. } if (isDate(x)) { @@ -49,6 +49,6 @@ tests/cases/conformance/types/any/narrowFromAnyWithTypePredicate.ts(33,7): error x.getHuors(); ~~~~~~~~ !!! error TS2551: Property 'getHuors' does not exist on type 'Date'. Did you mean 'getHours'? -!!! related TS2728 /.ts/lib.es5.d.ts:766:5: 'getHours' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:783:5: 'getHours' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/parserS7.2_A1.5_T2.errors.txt b/tests/baselines/reference/parserS7.2_A1.5_T2.errors.txt index 5634185a0a5d3..606a01be28e2c 100644 --- a/tests/baselines/reference/parserS7.2_A1.5_T2.errors.txt +++ b/tests/baselines/reference/parserS7.2_A1.5_T2.errors.txt @@ -19,7 +19,7 @@ tests/cases/conformance/parser/ecmascript5/parserS7.2_A1.5_T2.ts(20,3): error TS $ERROR('#1: eval("\\u00A0var x\\u00A0= 1\\u00A0"); x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } //CHECK#2 @@ -28,7 +28,7 @@ tests/cases/conformance/parser/ecmascript5/parserS7.2_A1.5_T2.ts(20,3): error TS $ERROR('#2:  var x = 1 ; x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } diff --git a/tests/baselines/reference/parserS7.3_A1.1_T2.errors.txt b/tests/baselines/reference/parserS7.3_A1.1_T2.errors.txt index 7a853ce7d164f..ced7ccf72105b 100644 --- a/tests/baselines/reference/parserS7.3_A1.1_T2.errors.txt +++ b/tests/baselines/reference/parserS7.3_A1.1_T2.errors.txt @@ -21,7 +21,7 @@ tests/cases/conformance/parser/ecmascript5/parserS7.3_A1.1_T2.ts(17,3): error TS $ERROR('#1: var\\nx\\n=\\n1\\n; x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/parserS7.6_A4.2_T1.errors.txt b/tests/baselines/reference/parserS7.6_A4.2_T1.errors.txt index b40fe10b5ac66..3ef7caa748676 100644 --- a/tests/baselines/reference/parserS7.6_A4.2_T1.errors.txt +++ b/tests/baselines/reference/parserS7.6_A4.2_T1.errors.txt @@ -50,70 +50,70 @@ tests/cases/conformance/parser/ecmascript5/parserS7.6_A4.2_T1.ts(142,3): error T $ERROR('#А'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0411 = 1; if (Б !== 1) { $ERROR('#Б'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0412 = 1; if (В !== 1) { $ERROR('#В'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0413 = 1; if (Г !== 1) { $ERROR('#Г'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0414 = 1; if (Д !== 1) { $ERROR('#Д'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0415 = 1; if (Е !== 1) { $ERROR('#Е'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0416 = 1; if (Ж !== 1) { $ERROR('#Ж'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0417 = 1; if (З !== 1) { $ERROR('#З'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0418 = 1; if (И !== 1) { $ERROR('#И'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0419 = 1; if (Й !== 1) { $ERROR('#Й'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u041A = 1; if (К !== 1) { diff --git a/tests/baselines/reference/parserUnicode1.errors.txt b/tests/baselines/reference/parserUnicode1.errors.txt index 5b5c079b5f07a..1ce7dee0ff21f 100644 --- a/tests/baselines/reference/parserUnicode1.errors.txt +++ b/tests/baselines/reference/parserUnicode1.errors.txt @@ -11,13 +11,13 @@ tests/cases/conformance/parser/ecmascript5/parserUnicode1.ts(10,5): error TS2552 $ERROR('#6.1: var \\u0078x = 1; xx === 6. Actual: ' + (xx)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } } catch (e) { $ERROR('#6.2: var \\u0078x = 1; xx === 6. Actual: ' + (xx)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index 6d804846c3e72..b5e02539b4805 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -447,7 +447,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2769: No overload m !!! error TS2769: The last overload gave the following error. !!! error TS2769: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2769: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1492:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1509:5: 'catch' is declared here. !!! related TS2771 tests/cases/compiler/promisePermutations.ts:5:5: The last overload is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index 36d5ada335abe..8de6ad217d058 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -351,7 +351,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of ~~~~~~~~~ !!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1492:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1509:5: 'catch' is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index c5089759822ba..23690f42545f2 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -398,7 +398,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2769: The last overload gave the following error. !!! error TS2769: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2769: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1492:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1509:5: 'catch' is declared here. !!! related TS2771 tests/cases/compiler/promisePermutations3.ts:7:5: The last overload is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok @@ -445,5 +445,5 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1492:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1509:5: 'catch' is declared here. var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok \ No newline at end of file diff --git a/tests/baselines/reference/redefineArray.errors.txt b/tests/baselines/reference/redefineArray.errors.txt index 2173143e72563..af387e7d09b97 100644 --- a/tests/baselines/reference/redefineArray.errors.txt +++ b/tests/baselines/reference/redefineArray.errors.txt @@ -5,4 +5,4 @@ tests/cases/compiler/redefineArray.ts(1,1): error TS2741: Property 'isArray' is Array = function (n:number, s:string) {return n;}; ~~~~~ !!! error TS2741: Property 'isArray' is missing in type '(n: number, s: string) => number' but required in type 'ArrayConstructor'. -!!! related TS2728 /.ts/lib.es5.d.ts:1443:5: 'isArray' is declared here. \ No newline at end of file +!!! related TS2728 /.ts/lib.es5.d.ts:1460:5: 'isArray' is declared here. \ No newline at end of file diff --git a/tests/baselines/reference/scannerS7.2_A1.5_T2.errors.txt b/tests/baselines/reference/scannerS7.2_A1.5_T2.errors.txt index e7e7d66bb0eb3..244af99699e6b 100644 --- a/tests/baselines/reference/scannerS7.2_A1.5_T2.errors.txt +++ b/tests/baselines/reference/scannerS7.2_A1.5_T2.errors.txt @@ -19,7 +19,7 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.2_A1.5_T2.ts(20,3): error $ERROR('#1: eval("\\u00A0var x\\u00A0= 1\\u00A0"); x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } //CHECK#2 @@ -28,7 +28,7 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.2_A1.5_T2.ts(20,3): error $ERROR('#2:  var x = 1 ; x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } diff --git a/tests/baselines/reference/scannerS7.3_A1.1_T2.errors.txt b/tests/baselines/reference/scannerS7.3_A1.1_T2.errors.txt index 0eb5cb3182219..0ed5806a67b8c 100644 --- a/tests/baselines/reference/scannerS7.3_A1.1_T2.errors.txt +++ b/tests/baselines/reference/scannerS7.3_A1.1_T2.errors.txt @@ -21,7 +21,7 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.3_A1.1_T2.ts(17,3): error $ERROR('#1: var\\nx\\n=\\n1\\n; x === 1. Actual: ' + (x)); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/scannerS7.6_A4.2_T1.errors.txt b/tests/baselines/reference/scannerS7.6_A4.2_T1.errors.txt index 66fcc455b095c..b527106b5b91d 100644 --- a/tests/baselines/reference/scannerS7.6_A4.2_T1.errors.txt +++ b/tests/baselines/reference/scannerS7.6_A4.2_T1.errors.txt @@ -50,70 +50,70 @@ tests/cases/conformance/scanner/ecmascript5/scannerS7.6_A4.2_T1.ts(142,3): error $ERROR('#А'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0411 = 1; if (Б !== 1) { $ERROR('#Б'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0412 = 1; if (В !== 1) { $ERROR('#В'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0413 = 1; if (Г !== 1) { $ERROR('#Г'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0414 = 1; if (Д !== 1) { $ERROR('#Д'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0415 = 1; if (Е !== 1) { $ERROR('#Е'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0416 = 1; if (Ж !== 1) { $ERROR('#Ж'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0417 = 1; if (З !== 1) { $ERROR('#З'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0418 = 1; if (И !== 1) { $ERROR('#И'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u0419 = 1; if (Й !== 1) { $ERROR('#Й'); ~~~~~~ !!! error TS2552: Cannot find name '$ERROR'. Did you mean 'Error'? -!!! related TS2728 /.ts/lib.es5.d.ts:1016:13: 'Error' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1033:13: 'Error' is declared here. } var \u041A = 1; if (К !== 1) { From b07c6e99b563776cdcbe5d486163bd90fa14519e Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 20 Sep 2021 13:25:44 -0700 Subject: [PATCH 25/25] Add contextual type and completions for ImportCall options argument --- src/compiler/checker.ts | 12 +- .../completionImportCallAssertion.baseline | 140 ++++++++++++++++++ .../completionImportCallAssertion.ts | 13 ++ 3 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/completionImportCallAssertion.baseline create mode 100644 tests/cases/fourslash/completionImportCallAssertion.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3d3f356626b56..6858fdabc8a1f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13462,7 +13462,6 @@ namespace ts { } function getGlobalImportCallOptionsType(reportErrors: boolean) { - // We always report an error, so store a result in the event we could not resolve the symbol to prevent reporting it multiple times return (deferredGlobalImportCallOptionsType ||= getGlobalType("ImportCallOptions" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType; } @@ -25558,6 +25557,12 @@ namespace ts { } function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number): Type { + if (isImportCall(callTarget)) { + return argIndex === 0 ? stringType : + argIndex === 1 ? getGlobalImportCallOptionsType(/*reportErrors*/ false) : + anyType; + } + // If we're already in the process of resolving the given signature, don't resolve again as // that could cause infinite recursion. Instead, return anySignature. const signature = getNodeLinks(callTarget).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(callTarget); @@ -26018,10 +26023,6 @@ namespace ts { case SyntaxKind.AwaitExpression: return getContextualTypeForAwaitOperand(parent as AwaitExpression, contextFlags); case SyntaxKind.CallExpression: - if ((parent as CallExpression).expression.kind === SyntaxKind.ImportKeyword) { - return stringType; - } - /* falls through */ case SyntaxKind.NewExpression: return getContextualTypeForArgument(parent as CallExpression | NewExpression, node); case SyntaxKind.TypeAssertionExpression: @@ -30617,6 +30618,7 @@ namespace ts { if (node.arguments.length === 0) { return createPromiseReturnType(node, anyType); } + const specifier = node.arguments[0]; const specifierType = checkExpressionCached(specifier); const optionsType = node.arguments.length > 1 ? checkExpressionCached(node.arguments[1]) : undefined; diff --git a/tests/baselines/reference/completionImportCallAssertion.baseline b/tests/baselines/reference/completionImportCallAssertion.baseline new file mode 100644 index 0000000000000..6009fb9e67f87 --- /dev/null +++ b/tests/baselines/reference/completionImportCallAssertion.baseline @@ -0,0 +1,140 @@ +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/main.ts", + "position": 24, + "name": "0" + }, + "completionList": { + "isGlobalCompletion": false, + "isMemberCompletion": true, + "isNewIdentifierLocation": false, + "entries": [ + { + "name": "assert", + "kind": "property", + "kindModifiers": "declare,optional", + "sortText": "12", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "ImportCallOptions", + "kind": "interfaceName" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "assert", + "kind": "propertyName" + }, + { + "text": "?", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "ImportAssertions", + "kind": "interfaceName" + } + ], + "documentation": [] + } + ] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/main.ts", + "position": 57, + "name": "1" + }, + "completionList": { + "isGlobalCompletion": false, + "isMemberCompletion": true, + "isNewIdentifierLocation": false, + "optionalReplacementSpan": { + "start": 53, + "length": 4 + }, + "entries": [ + { + "name": "assert", + "kind": "property", + "kindModifiers": "declare,optional", + "sortText": "12", + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "ImportCallOptions", + "kind": "interfaceName" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "assert", + "kind": "propertyName" + }, + { + "text": "?", + "kind": "punctuation" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "ImportAssertions", + "kind": "interfaceName" + } + ], + "documentation": [] + } + ] + } + } +] \ No newline at end of file diff --git a/tests/cases/fourslash/completionImportCallAssertion.ts b/tests/cases/fourslash/completionImportCallAssertion.ts new file mode 100644 index 0000000000000..650629155186a --- /dev/null +++ b/tests/cases/fourslash/completionImportCallAssertion.ts @@ -0,0 +1,13 @@ +/// + +// @target: esnext +// @module: esnext + +// @filename: main.ts +////import("./other.json", {/*0*/}); +////import("./other.json", { asse/*1*/}); + +// @filename: other.json +////{} + +verify.baselineCompletions();