diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 51c5001204f02..6858fdabc8a1f 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; @@ -6568,7 +6569,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 => { @@ -6600,7 +6601,8 @@ namespace ts { exportDecl.exportClause, replacements ), - exportDecl.moduleSpecifier + exportDecl.moduleSpecifier, + exportDecl.assertClause ); } } @@ -7260,7 +7262,8 @@ namespace ts { propertyName && isIdentifier(propertyName) ? factory.createIdentifier(idText(propertyName)) : undefined, factory.createIdentifier(localName) )])), - factory.createStringLiteral(specifier) + factory.createStringLiteral(specifier), + /*importClause*/ undefined ), ModifierFlags.None); break; } @@ -7336,7 +7339,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: @@ -7344,7 +7348,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: @@ -7369,7 +7374,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: @@ -13455,6 +13461,10 @@ namespace ts { return deferredGlobalImportMetaExpressionType; } + function getGlobalImportCallOptionsType(reportErrors: boolean) { + return (deferredGlobalImportCallOptionsType ||= getGlobalType("ImportCallOptions" as __String, /*arity*/ 0, reportErrors)) || emptyObjectType; + } + function getGlobalESSymbolConstructorSymbol(reportErrors: boolean): Symbol | undefined { return deferredGlobalESSymbolConstructorSymbol ||= getGlobalValueSymbol("Symbol" as __String, reportErrors); } @@ -25547,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); @@ -26007,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: @@ -30606,10 +30618,12 @@ 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; // 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]); } @@ -30617,6 +30631,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) { @@ -39039,6 +39060,18 @@ namespace ts { } } + function checkAssertClause(declaration: ImportDeclaration | ExportDeclaration) { + if (declaration.assertClause) { + if (moduleKind !== ModuleKind.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) { + return grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports); + } + } + } + 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. @@ -39070,7 +39103,7 @@ namespace ts { } } } - + checkAssertClause(node); } function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { @@ -39165,6 +39198,7 @@ namespace ts { } } } + checkAssertClause(node); } function checkGrammarExportDeclaration(node: ExportDeclaration): boolean { @@ -43201,14 +43235,25 @@ namespace ts { } const nodeArguments = node.arguments; - if (nodeArguments.length !== 1) { - return grammarErrorOnNode(node, Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument); + if (moduleKind !== ModuleKind.ESNext) { + // We are allowed trailing comma after proposal-import-assertions. + checkGrammarForDisallowedTrailingComma(nodeArguments); + + if (nodeArguments.length > 1) { + const assertionArgument = nodeArguments[1]; + return grammarErrorOnNode(assertionArgument, Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext); + } } - checkGrammarForDisallowedTrailingComma(nodeArguments); + + 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. - if (isSpreadElement(nodeArguments[0])) { - return grammarErrorOnNode(nodeArguments[0], Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element); + const spreadElement = find(nodeArguments, isSpreadElement); + if (spreadElement) { + 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 b68a1b6ba23a1..c2778dd5da9fa 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -924,11 +924,11 @@ "category": "Error", "code": 1323 }, - "Dynamic import must have one specifier as an argument.": { + "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,6 +1388,10 @@ "category": "Message", "code": 1449 }, + "Dynamic imports can only accept a module specifier and an optional assertion as arguments": { + "category": "Message", + "code": 1450 + }, "The types of '{0}' are incompatible between these types.": { "category": "Error", @@ -3304,6 +3308,14 @@ "category": "Error", "code": 2820 }, + "Import assertions are only supported when the '--module' option is set to 'esnext'.": { + "category": "Error", + "code": 2821 + }, + "Import assertions cannot be used with type-only imports or exports.": { + "category": "Error", + "code": 2822 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 5667e792b4606..23cdda71a2ac1 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1515,6 +1515,10 @@ namespace ts { return emitNamedExports(node as NamedExports); case SyntaxKind.ExportSpecifier: return emitExportSpecifier(node as ExportSpecifier); + case SyntaxKind.AssertClause: + return emitAssertClause(node as AssertClause); + case SyntaxKind.AssertEntry: + return emitAssertEntry(node as AssertEntry); case SyntaxKind.MissingDeclaration: return; @@ -3322,6 +3326,9 @@ namespace ts { writeSpace(); } emitExpression(node.moduleSpecifier); + if (node.assertClause) { + emitWithLeadingSpace(node.assertClause); + } writeTrailingSemicolon(); } @@ -3390,9 +3397,33 @@ namespace ts { writeSpace(); emitExpression(node.moduleSpecifier); } + if (node.assertClause) { + emitWithLeadingSpace(node.assertClause); + } writeTrailingSemicolon(); } + function emitAssertClause(node: AssertClause) { + emitTokenWithComment(SyntaxKind.AssertKeyword, node.pos, writeKeyword, node); + writeSpace(); + const elements = node.elements; + emitList(node, elements, ListFormat.ImportClauseEntries); + } + + function emitAssertEntry(node: AssertEntry) { + emit(node.name); + writePunctuation(":"); + writeSpace(); + + const value = node.value; + /** @see {emitPropertyAssignment} */ + if ((getEmitFlags(value) & EmitFlags.NoLeadingComments) === 0) { + const commentRange = getCommentRange(value); + emitTrailingCommentsOfPosition(commentRange.pos); + } + emit(value); + } + function emitNamespaceExportDeclaration(node: NamespaceExportDeclaration) { let nextPos = emitTokenWithComment(SyntaxKind.ExportKeyword, node.pos, writeKeyword, node); writeSpace(); diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index c697a04860b71..975e0934c9320 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -289,6 +289,10 @@ namespace ts { updateImportDeclaration, createImportClause, updateImportClause, + createAssertClause, + updateAssertClause, + createAssertEntry, + updateAssertEntry, createNamespaceImport, updateNamespaceImport, createNamespaceExport, @@ -3939,7 +3943,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, @@ -3948,6 +3953,7 @@ namespace ts { ); node.importClause = importClause; node.moduleSpecifier = moduleSpecifier; + node.assertClause = assertClause; node.transformFlags |= propagateChildFlags(node.importClause) | propagateChildFlags(node.moduleSpecifier); @@ -3961,13 +3967,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; } @@ -3996,6 +4004,40 @@ namespace ts { : node; } + // @api + 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, multiLine?: boolean): AssertClause { + return node.elements !== elements + || node.multiLine !== multiLine + ? update(createAssertClause(elements, multiLine), 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); @@ -4107,7 +4149,8 @@ namespace ts { modifiers: readonly Modifier[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, - moduleSpecifier?: Expression + moduleSpecifier?: Expression, + assertClause?: AssertClause ) { const node = createBaseDeclaration( SyntaxKind.ExportDeclaration, @@ -4117,6 +4160,7 @@ namespace ts { node.isTypeOnly = isTypeOnly; node.exportClause = exportClause; node.moduleSpecifier = moduleSpecifier; + node.assertClause = assertClause; node.transformFlags |= propagateChildFlags(node.exportClause) | propagateChildFlags(node.moduleSpecifier); @@ -4131,14 +4175,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; } @@ -6050,9 +6096,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.isTypeOnly, 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 7f5fda1994c60..274ade1886dfc 100644 --- a/src/compiler/factory/nodeTests.ts +++ b/src/compiler/factory/nodeTests.ts @@ -597,6 +597,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 fdd3200d572aa..93851ccbba011 100644 --- a/src/compiler/factory/utilities.ts +++ b/src/compiler/factory/utilities.ts @@ -522,7 +522,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 dbe5394908d48..7c031ae3a8c03 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -398,13 +398,18 @@ namespace ts { return visitNodes(cbNode, cbNodes, node.decorators) || visitNodes(cbNode, cbNodes, node.modifiers) || visitNode(cbNode, (node as ImportDeclaration).importClause) || - visitNode(cbNode, (node as ImportDeclaration).moduleSpecifier); + visitNode(cbNode, (node as ImportDeclaration).moduleSpecifier) || + visitNode(cbNode, (node as ImportDeclaration).assertClause); 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: return visitNode(cbNode, (node as NamespaceImport).name); case SyntaxKind.NamespaceExport: @@ -416,7 +421,8 @@ namespace ts { return visitNodes(cbNode, cbNodes, node.decorators) || visitNodes(cbNode, cbNodes, node.modifiers) || visitNode(cbNode, (node as ExportDeclaration).exportClause) || - visitNode(cbNode, (node as ExportDeclaration).moduleSpecifier); + visitNode(cbNode, (node as ExportDeclaration).moduleSpecifier) || + visitNode(cbNode, (node as ExportDeclaration).assertClause); case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: return visitNode(cbNode, (node as ImportOrExportSpecifier).propertyName) || @@ -1886,6 +1892,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() as StringLiteral | NumericLiteral; @@ -2051,6 +2062,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. @@ -2171,6 +2184,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; @@ -7234,13 +7248,45 @@ namespace ts { importClause = parseImportClause(identifier, afterImportPos, isTypeOnly); parseExpected(SyntaxKind.FromKeyword); } - const moduleSpecifier = parseModuleSpecifier(); + + let assertClause: AssertClause | undefined; + if (token() === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak()) { + assertClause = parseAssertClause(); + } + 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() { + 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() { return token() === SyntaxKind.AsteriskToken || token() === SyntaxKind.OpenBraceToken; } @@ -7388,6 +7434,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)) { @@ -7407,9 +7454,12 @@ namespace ts { moduleSpecifier = parseModuleSpecifier(); } } + if (moduleSpecifier && token() === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak()) { + assertClause = parseAssertClause(); + } 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); } @@ -7489,7 +7539,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 9dd6db37790a0..58affcfdb13ee 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2269,7 +2269,7 @@ namespace ts { function createSyntheticImport(text: string, file: SourceFile) { const externalHelpersModuleReference = factory.createStringLiteral(text); - 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); @@ -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/scanner.ts b/src/compiler/scanner.ts index 8e31a88589bf9..0c4c087e6edc5 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -83,6 +83,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/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index e76debaa78557..cc34205944eb6 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -732,7 +732,8 @@ namespace ts { /*decorators*/ undefined, decl.modifiers, decl.importClause, - rewriteModuleSpecifier(decl, decl.moduleSpecifier) + rewriteModuleSpecifier(decl, decl.moduleSpecifier), + /*assertClause*/ undefined ); } // The `importClause` visibility corresponds to the default's visibility. @@ -744,7 +745,7 @@ namespace ts { decl.importClause.isTypeOnly, visibleDefaultBinding, /*namedBindings*/ undefined, - ), rewriteModuleSpecifier(decl, decl.moduleSpecifier)); + ), rewriteModuleSpecifier(decl, decl.moduleSpecifier), /*assertClause*/ undefined); } if (decl.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { // Namespace import (optionally with visible default) @@ -754,7 +755,7 @@ namespace ts { decl.importClause.isTypeOnly, visibleDefaultBinding, namedBindings, - ), rewriteModuleSpecifier(decl, decl.moduleSpecifier)) : 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); @@ -769,7 +770,8 @@ namespace ts { visibleDefaultBinding, bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined, ), - rewriteModuleSpecifier(decl, decl.moduleSpecifier) + rewriteModuleSpecifier(decl, decl.moduleSpecifier), + /*assertClause*/ undefined ); } // Augmentation of export depends on import @@ -779,7 +781,8 @@ namespace ts { /*decorators*/ undefined, decl.modifiers, /*importClause*/ undefined, - rewriteModuleSpecifier(decl, decl.moduleSpecifier) + rewriteModuleSpecifier(decl, decl.moduleSpecifier), + /*assertClause*/ undefined ); } // Nothing visible @@ -1114,6 +1117,7 @@ namespace ts { input.isTypeOnly, input.exportClause, rewriteModuleSpecifier(input, input.moduleSpecifier), + /*assertClause*/ undefined ); } case SyntaxKind.ExportAssignment: { diff --git a/src/compiler/transformers/jsx.ts b/src/compiler/transformers/jsx.ts index 55c606f883218..018e2ad2cb411 100644 --- a/src/compiler/transformers/jsx.ts +++ b/src/compiler/transformers/jsx.ts @@ -85,7 +85,7 @@ namespace ts { for (const [importSource, importSpecifiersMap] of arrayFrom(currentFileState.utilizedImplicitRuntimeImports.entries())) { if (isExternalModule(node)) { // Add `import` statement - const importStatement = factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createImportClause(/*typeOnly*/ false, /*name*/ undefined, factory.createNamedImports(arrayFrom(importSpecifiersMap.values()))), factory.createStringLiteral(importSource)); + const importStatement = factory.createImportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, factory.createImportClause(/*typeOnly*/ false, /*name*/ undefined, factory.createNamedImports(arrayFrom(importSpecifiersMap.values()))), factory.createStringLiteral(importSource), /*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 4a7e297722e86..ee08ed77b9871 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 012be39dadbdd..9dae42e335196 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -2816,7 +2816,8 @@ namespace ts { /*decorators*/ undefined, /*modifiers*/ undefined, importClause, - node.moduleSpecifier) + node.moduleSpecifier, + node.assertClause) : undefined; } @@ -2903,7 +2904,8 @@ namespace ts { /*modifiers*/ undefined, node.isTypeOnly, exportClause, - node.moduleSpecifier) + node.moduleSpecifier, + node.assertClause) : undefined; } @@ -2973,6 +2975,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 f263c53a64961..b6a6258b21a24 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -161,6 +161,7 @@ namespace ts { AbstractKeyword, AsKeyword, AssertsKeyword, + AssertKeyword, AnyKeyword, AsyncKeyword, AwaitKeyword, @@ -341,6 +342,8 @@ namespace ts { DefaultClause, HeritageClause, CatchClause, + AssertClause, + AssertEntry, // Property assignments PropertyAssignment, @@ -544,6 +547,7 @@ namespace ts { | SyntaxKind.AnyKeyword | SyntaxKind.AsKeyword | SyntaxKind.AssertsKeyword + | SyntaxKind.AssertKeyword | SyntaxKind.AsyncKeyword | SyntaxKind.AwaitKeyword | SyntaxKind.BigIntKeyword @@ -1039,6 +1043,7 @@ namespace ts { } export type AssertsKeyword = KeywordToken; + export type AssertKeyword = KeywordToken; export type AwaitKeyword = KeywordToken; /** @deprecated Use `AwaitKeyword` instead. */ @@ -3014,6 +3019,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 = @@ -3040,6 +3046,22 @@ 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; + readonly multiLine?: boolean; + } + export interface NamespaceImport extends NamedDeclaration { readonly kind: SyntaxKind.NamespaceImport; readonly parent: ImportClause; @@ -3067,6 +3089,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 { @@ -7318,10 +7341,14 @@ 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): 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): 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; @@ -7332,8 +7359,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; @@ -8355,6 +8382,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/utilitiesPublic.ts b/src/compiler/utilitiesPublic.ts index 91b0a1cc9a9cc..a5c0f9296d350 100644 --- a/src/compiler/utilitiesPublic.ts +++ b/src/compiler/utilitiesPublic.ts @@ -1141,6 +1141,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); } diff --git a/src/compiler/visitorPublic.ts b/src/compiler/visitorPublic.ts index 94ab1afbb8aa0..511d3b5c7eeba 100644 --- a/src/compiler/visitorPublic.ts +++ b/src/compiler/visitorPublic.ts @@ -1076,7 +1076,20 @@ 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.AssertClause: + Debug.type(node); + return factory.updateAssertClause(node, + nodesVisitor(node.elements, visitor, isAssertEntry), + node.multiLine); + + case SyntaxKind.AssertEntry: + Debug.type(node); + return factory.updateAssertEntry(node, + nodeVisitor(node.name, visitor, isAssertionKey), + nodeVisitor(node.value, visitor, isStringLiteral)); case SyntaxKind.ImportClause: Debug.type(node); @@ -1120,7 +1133,8 @@ namespace ts { nodesVisitor(node.modifiers, visitor, isModifier), node.isTypeOnly, nodeVisitor(node.exportClause, visitor, isNamedExportBindings), - nodeVisitor(node.moduleSpecifier, visitor, isExpression)); + nodeVisitor(node.moduleSpecifier, visitor, isExpression), + nodeVisitor(node.assertClause, visitor, isAssertClause)); case SyntaxKind.NamedExports: Debug.type(node); diff --git a/src/deprecatedCompat/deprecations.ts b/src/deprecatedCompat/deprecations.ts index a70db0d344298..292840166b36f 100644 --- a/src/deprecatedCompat/deprecations.ts +++ b/src/deprecatedCompat/deprecations.ts @@ -1224,7 +1224,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, node.assertClause); }, factoryDeprecation); /** @deprecated Use `factory.createJSDocParameterTag` or the factory supplied by your transformation context instead. */ 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 8f803453c1689..859eb0e77d708 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/src/services/codefixes/convertToTypeOnlyExport.ts b/src/services/codefixes/convertToTypeOnlyExport.ts index 3f7a0d0983db1..8ff0b57ea099d 100644 --- a/src/services/codefixes/convertToTypeOnlyExport.ts +++ b/src/services/codefixes/convertToTypeOnlyExport.ts @@ -44,13 +44,17 @@ 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, /*isTypeOnly*/ true, factory.createNamedExports(typeExportSpecifiers), - exportDeclaration.moduleSpecifier); + exportDeclaration.moduleSpecifier, + /*assertClause*/ undefined + ); changes.replaceNode(context.sourceFile, exportDeclaration, valueExportDeclaration, { leadingTriviaOption: textChanges.LeadingTriviaOption.IncludeAll, diff --git a/src/services/codefixes/convertToTypeOnlyImport.ts b/src/services/codefixes/convertToTypeOnlyImport.ts index daa163250df2c..51d34a885fb06 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 b92db09bd6235..646b6e7c9d5ec 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -857,7 +857,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 c1ee73013fae8..2dc09cc955677 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, /*isTypeOnly*/ false, 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 6c2dcc74d74e1..243cda647e432 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -146,7 +146,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 @@ -358,7 +359,8 @@ namespace ts.OrganizeImports { factory.updateNamedExports(exportDecl.exportClause, sortedExportSpecifiers) : factory.updateNamespaceExport(exportDecl.exportClause, exportDecl.exportClause.name) ), - exportDecl.moduleSpecifier)); + exportDecl.moduleSpecifier, + exportDecl.assertClause)); } return coalescedExports; @@ -405,7 +407,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 042c4a37149c0..abe3c02d95781 100644 --- a/src/services/refactors/convertImport.ts +++ b/src/services/refactors/convertImport.ts @@ -198,6 +198,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 fda2aa291247b..5fd34d348c62c 100644 --- a/src/services/refactors/moveToNewFile.ts +++ b/src/services/refactors/moveToNewFile.ts @@ -258,7 +258,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, /*isTypeOnly*/ false, newNamespaceId, factory.createExternalModuleReference(newModuleString)); case SyntaxKind.VariableDeclaration: @@ -591,7 +592,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 533b816b8b380..851d6c91d04d9 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1880,7 +1880,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 { diff --git a/src/testRunner/unittests/transform.ts b/src/testRunner/unittests/transform.ts index 13de003fd31ca..6d8aa0afa4bbc 100644 --- a/src/testRunner/unittests/transform.ts +++ b/src/testRunner/unittests/transform.ts @@ -277,7 +277,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; } @@ -314,7 +314,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/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 345ee175a1f7e..baa075cbd9a71 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -234,228 +234,231 @@ declare namespace ts { AbstractKeyword = 126, AsKeyword = 127, AssertsKeyword = 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, - OverrideKeyword = 157, - OfKeyword = 158, - QualifiedName = 159, - ComputedPropertyName = 160, - TypeParameter = 161, - Parameter = 162, - Decorator = 163, - PropertySignature = 164, - PropertyDeclaration = 165, - MethodSignature = 166, - MethodDeclaration = 167, - ClassStaticBlockDeclaration = 168, - Constructor = 169, - GetAccessor = 170, - SetAccessor = 171, - CallSignature = 172, - ConstructSignature = 173, - IndexSignature = 174, - TypePredicate = 175, - TypeReference = 176, - FunctionType = 177, - ConstructorType = 178, - TypeQuery = 179, - TypeLiteral = 180, - ArrayType = 181, - TupleType = 182, - OptionalType = 183, - RestType = 184, - UnionType = 185, - IntersectionType = 186, - ConditionalType = 187, - InferType = 188, - ParenthesizedType = 189, - ThisType = 190, - TypeOperator = 191, - IndexedAccessType = 192, - MappedType = 193, - LiteralType = 194, - NamedTupleMember = 195, - TemplateLiteralType = 196, - TemplateLiteralTypeSpan = 197, - ImportType = 198, - ObjectBindingPattern = 199, - ArrayBindingPattern = 200, - BindingElement = 201, - ArrayLiteralExpression = 202, - ObjectLiteralExpression = 203, - PropertyAccessExpression = 204, - ElementAccessExpression = 205, - CallExpression = 206, - NewExpression = 207, - TaggedTemplateExpression = 208, - TypeAssertionExpression = 209, - ParenthesizedExpression = 210, - FunctionExpression = 211, - ArrowFunction = 212, - DeleteExpression = 213, - TypeOfExpression = 214, - VoidExpression = 215, - AwaitExpression = 216, - PrefixUnaryExpression = 217, - PostfixUnaryExpression = 218, - BinaryExpression = 219, - ConditionalExpression = 220, - TemplateExpression = 221, - YieldExpression = 222, - SpreadElement = 223, - ClassExpression = 224, - OmittedExpression = 225, - ExpressionWithTypeArguments = 226, - AsExpression = 227, - NonNullExpression = 228, - MetaProperty = 229, - SyntheticExpression = 230, - TemplateSpan = 231, - SemicolonClassElement = 232, - Block = 233, - EmptyStatement = 234, - VariableStatement = 235, - ExpressionStatement = 236, - IfStatement = 237, - DoStatement = 238, - WhileStatement = 239, - ForStatement = 240, - ForInStatement = 241, - ForOfStatement = 242, - ContinueStatement = 243, - BreakStatement = 244, - ReturnStatement = 245, - WithStatement = 246, - SwitchStatement = 247, - LabeledStatement = 248, - ThrowStatement = 249, - TryStatement = 250, - DebuggerStatement = 251, - VariableDeclaration = 252, - VariableDeclarationList = 253, - FunctionDeclaration = 254, - ClassDeclaration = 255, - InterfaceDeclaration = 256, - TypeAliasDeclaration = 257, - EnumDeclaration = 258, - ModuleDeclaration = 259, - ModuleBlock = 260, - CaseBlock = 261, - NamespaceExportDeclaration = 262, - ImportEqualsDeclaration = 263, - ImportDeclaration = 264, - ImportClause = 265, - NamespaceImport = 266, - NamedImports = 267, - ImportSpecifier = 268, - ExportAssignment = 269, - ExportDeclaration = 270, - NamedExports = 271, - NamespaceExport = 272, - ExportSpecifier = 273, - MissingDeclaration = 274, - ExternalModuleReference = 275, - JsxElement = 276, - JsxSelfClosingElement = 277, - JsxOpeningElement = 278, - JsxClosingElement = 279, - JsxFragment = 280, - JsxOpeningFragment = 281, - JsxClosingFragment = 282, - JsxAttribute = 283, - JsxAttributes = 284, - JsxSpreadAttribute = 285, - JsxExpression = 286, - CaseClause = 287, - DefaultClause = 288, - HeritageClause = 289, - CatchClause = 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, - JSDocMemberName = 306, - JSDocAllType = 307, - JSDocUnknownType = 308, - JSDocNullableType = 309, - JSDocNonNullableType = 310, - JSDocOptionalType = 311, - JSDocFunctionType = 312, - JSDocVariadicType = 313, - JSDocNamepathType = 314, - JSDocComment = 315, - JSDocText = 316, - JSDocTypeLiteral = 317, - JSDocSignature = 318, - JSDocLink = 319, - JSDocLinkCode = 320, - JSDocLinkPlain = 321, - JSDocTag = 322, - JSDocAugmentsTag = 323, - JSDocImplementsTag = 324, - JSDocAuthorTag = 325, - JSDocDeprecatedTag = 326, - JSDocClassTag = 327, - JSDocPublicTag = 328, - JSDocPrivateTag = 329, - JSDocProtectedTag = 330, - JSDocReadonlyTag = 331, - JSDocOverrideTag = 332, - JSDocCallbackTag = 333, - JSDocEnumTag = 334, - JSDocParameterTag = 335, - JSDocReturnTag = 336, - JSDocThisTag = 337, - JSDocTypeTag = 338, - JSDocTemplateTag = 339, - JSDocTypedefTag = 340, - JSDocSeeTag = 341, - JSDocPropertyTag = 342, - SyntaxList = 343, - NotEmittedStatement = 344, - PartiallyEmittedExpression = 345, - CommaListExpression = 346, - MergeDeclarationMarker = 347, - EndOfDeclarationMarker = 348, - SyntheticReferenceExpression = 349, - Count = 350, + AssertKeyword = 129, + AnyKeyword = 130, + AsyncKeyword = 131, + AwaitKeyword = 132, + BooleanKeyword = 133, + ConstructorKeyword = 134, + DeclareKeyword = 135, + GetKeyword = 136, + InferKeyword = 137, + IntrinsicKeyword = 138, + IsKeyword = 139, + KeyOfKeyword = 140, + ModuleKeyword = 141, + NamespaceKeyword = 142, + NeverKeyword = 143, + ReadonlyKeyword = 144, + RequireKeyword = 145, + NumberKeyword = 146, + ObjectKeyword = 147, + SetKeyword = 148, + StringKeyword = 149, + SymbolKeyword = 150, + TypeKeyword = 151, + UndefinedKeyword = 152, + UniqueKeyword = 153, + UnknownKeyword = 154, + FromKeyword = 155, + GlobalKeyword = 156, + BigIntKeyword = 157, + OverrideKeyword = 158, + OfKeyword = 159, + QualifiedName = 160, + ComputedPropertyName = 161, + TypeParameter = 162, + Parameter = 163, + Decorator = 164, + PropertySignature = 165, + PropertyDeclaration = 166, + MethodSignature = 167, + MethodDeclaration = 168, + ClassStaticBlockDeclaration = 169, + Constructor = 170, + GetAccessor = 171, + SetAccessor = 172, + CallSignature = 173, + ConstructSignature = 174, + IndexSignature = 175, + TypePredicate = 176, + TypeReference = 177, + FunctionType = 178, + ConstructorType = 179, + TypeQuery = 180, + TypeLiteral = 181, + ArrayType = 182, + TupleType = 183, + OptionalType = 184, + RestType = 185, + UnionType = 186, + IntersectionType = 187, + ConditionalType = 188, + InferType = 189, + ParenthesizedType = 190, + ThisType = 191, + TypeOperator = 192, + IndexedAccessType = 193, + MappedType = 194, + LiteralType = 195, + NamedTupleMember = 196, + TemplateLiteralType = 197, + TemplateLiteralTypeSpan = 198, + ImportType = 199, + ObjectBindingPattern = 200, + ArrayBindingPattern = 201, + BindingElement = 202, + ArrayLiteralExpression = 203, + ObjectLiteralExpression = 204, + PropertyAccessExpression = 205, + ElementAccessExpression = 206, + CallExpression = 207, + NewExpression = 208, + TaggedTemplateExpression = 209, + TypeAssertionExpression = 210, + ParenthesizedExpression = 211, + FunctionExpression = 212, + ArrowFunction = 213, + DeleteExpression = 214, + TypeOfExpression = 215, + VoidExpression = 216, + AwaitExpression = 217, + PrefixUnaryExpression = 218, + PostfixUnaryExpression = 219, + BinaryExpression = 220, + ConditionalExpression = 221, + TemplateExpression = 222, + YieldExpression = 223, + SpreadElement = 224, + ClassExpression = 225, + OmittedExpression = 226, + ExpressionWithTypeArguments = 227, + AsExpression = 228, + NonNullExpression = 229, + MetaProperty = 230, + SyntheticExpression = 231, + TemplateSpan = 232, + SemicolonClassElement = 233, + Block = 234, + EmptyStatement = 235, + VariableStatement = 236, + ExpressionStatement = 237, + IfStatement = 238, + DoStatement = 239, + WhileStatement = 240, + ForStatement = 241, + ForInStatement = 242, + ForOfStatement = 243, + ContinueStatement = 244, + BreakStatement = 245, + ReturnStatement = 246, + WithStatement = 247, + SwitchStatement = 248, + LabeledStatement = 249, + ThrowStatement = 250, + TryStatement = 251, + DebuggerStatement = 252, + VariableDeclaration = 253, + VariableDeclarationList = 254, + FunctionDeclaration = 255, + ClassDeclaration = 256, + InterfaceDeclaration = 257, + TypeAliasDeclaration = 258, + EnumDeclaration = 259, + ModuleDeclaration = 260, + ModuleBlock = 261, + CaseBlock = 262, + NamespaceExportDeclaration = 263, + ImportEqualsDeclaration = 264, + ImportDeclaration = 265, + ImportClause = 266, + NamespaceImport = 267, + NamedImports = 268, + ImportSpecifier = 269, + ExportAssignment = 270, + ExportDeclaration = 271, + NamedExports = 272, + NamespaceExport = 273, + ExportSpecifier = 274, + MissingDeclaration = 275, + ExternalModuleReference = 276, + JsxElement = 277, + JsxSelfClosingElement = 278, + JsxOpeningElement = 279, + JsxClosingElement = 280, + JsxFragment = 281, + JsxOpeningFragment = 282, + JsxClosingFragment = 283, + JsxAttribute = 284, + JsxAttributes = 285, + JsxSpreadAttribute = 286, + JsxExpression = 287, + CaseClause = 288, + DefaultClause = 289, + HeritageClause = 290, + CatchClause = 291, + AssertClause = 292, + AssertEntry = 293, + PropertyAssignment = 294, + ShorthandPropertyAssignment = 295, + SpreadAssignment = 296, + EnumMember = 297, + UnparsedPrologue = 298, + UnparsedPrepend = 299, + UnparsedText = 300, + UnparsedInternalText = 301, + UnparsedSyntheticReference = 302, + SourceFile = 303, + Bundle = 304, + UnparsedSource = 305, + InputFiles = 306, + JSDocTypeExpression = 307, + JSDocNameReference = 308, + JSDocMemberName = 309, + JSDocAllType = 310, + JSDocUnknownType = 311, + JSDocNullableType = 312, + JSDocNonNullableType = 313, + JSDocOptionalType = 314, + JSDocFunctionType = 315, + JSDocVariadicType = 316, + JSDocNamepathType = 317, + JSDocComment = 318, + JSDocText = 319, + JSDocTypeLiteral = 320, + JSDocSignature = 321, + JSDocLink = 322, + JSDocLinkCode = 323, + JSDocLinkPlain = 324, + JSDocTag = 325, + JSDocAugmentsTag = 326, + JSDocImplementsTag = 327, + JSDocAuthorTag = 328, + JSDocDeprecatedTag = 329, + JSDocClassTag = 330, + JSDocPublicTag = 331, + JSDocPrivateTag = 332, + JSDocProtectedTag = 333, + JSDocReadonlyTag = 334, + JSDocOverrideTag = 335, + JSDocCallbackTag = 336, + JSDocEnumTag = 337, + JSDocParameterTag = 338, + JSDocReturnTag = 339, + JSDocThisTag = 340, + JSDocTypeTag = 341, + JSDocTemplateTag = 342, + JSDocTypedefTag = 343, + JSDocSeeTag = 344, + JSDocPropertyTag = 345, + SyntaxList = 346, + NotEmittedStatement = 347, + PartiallyEmittedExpression = 348, + CommaListExpression = 349, + MergeDeclarationMarker = 350, + EndOfDeclarationMarker = 351, + SyntheticReferenceExpression = 352, + Count = 353, FirstAssignment = 63, LastAssignment = 78, FirstCompoundAssignment = 64, @@ -463,15 +466,15 @@ declare namespace ts { FirstReservedWord = 81, LastReservedWord = 116, FirstKeyword = 81, - LastKeyword = 158, + LastKeyword = 159, FirstFutureReservedWord = 117, LastFutureReservedWord = 125, - FirstTypeNode = 175, - LastTypeNode = 198, + FirstTypeNode = 176, + LastTypeNode = 199, FirstPunctuation = 18, LastPunctuation = 78, FirstToken = 0, - LastToken = 158, + LastToken = 159, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -480,19 +483,19 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 78, - FirstStatement = 235, - LastStatement = 251, - FirstNode = 159, - FirstJSDocNode = 304, - LastJSDocNode = 342, - FirstJSDocTagNode = 322, - LastJSDocTagNode = 342, + FirstStatement = 236, + LastStatement = 252, + FirstNode = 160, + FirstJSDocNode = 307, + LastJSDocNode = 345, + FirstJSDocTagNode = 325, + LastJSDocTagNode = 345, } 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.HashToken | 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.OverrideKeyword | 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.OverrideKeyword | 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.OverrideKeyword | 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; @@ -597,6 +600,7 @@ 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; @@ -1630,6 +1634,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; @@ -1640,6 +1645,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; @@ -1662,6 +1680,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; @@ -3519,10 +3538,14 @@ 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): 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): 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; @@ -3533,8 +3556,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; @@ -3951,6 +3974,7 @@ declare namespace ts { ObjectBindingPatternElements = 525136, ArrayBindingPatternElements = 524880, ObjectLiteralExpressionProperties = 526226, + ImportClauseEntries = 526226, ArrayLiteralExpressionElements = 8914, CommaListElements = 528, CallExpressionArguments = 2576, @@ -4345,6 +4369,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 TypeOnlyAliasDeclaration; + 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; @@ -4592,6 +4617,8 @@ 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 isNamespaceImport(node: Node): node is NamespaceImport; function isNamespaceExport(node: Node): node is NamespaceExport; function isNamedImports(node: Node): node is NamedImports; @@ -10961,9 +10988,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, 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) => 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 dc6b0f2787f76..da759028a5b98 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -234,228 +234,231 @@ declare namespace ts { AbstractKeyword = 126, AsKeyword = 127, AssertsKeyword = 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, - OverrideKeyword = 157, - OfKeyword = 158, - QualifiedName = 159, - ComputedPropertyName = 160, - TypeParameter = 161, - Parameter = 162, - Decorator = 163, - PropertySignature = 164, - PropertyDeclaration = 165, - MethodSignature = 166, - MethodDeclaration = 167, - ClassStaticBlockDeclaration = 168, - Constructor = 169, - GetAccessor = 170, - SetAccessor = 171, - CallSignature = 172, - ConstructSignature = 173, - IndexSignature = 174, - TypePredicate = 175, - TypeReference = 176, - FunctionType = 177, - ConstructorType = 178, - TypeQuery = 179, - TypeLiteral = 180, - ArrayType = 181, - TupleType = 182, - OptionalType = 183, - RestType = 184, - UnionType = 185, - IntersectionType = 186, - ConditionalType = 187, - InferType = 188, - ParenthesizedType = 189, - ThisType = 190, - TypeOperator = 191, - IndexedAccessType = 192, - MappedType = 193, - LiteralType = 194, - NamedTupleMember = 195, - TemplateLiteralType = 196, - TemplateLiteralTypeSpan = 197, - ImportType = 198, - ObjectBindingPattern = 199, - ArrayBindingPattern = 200, - BindingElement = 201, - ArrayLiteralExpression = 202, - ObjectLiteralExpression = 203, - PropertyAccessExpression = 204, - ElementAccessExpression = 205, - CallExpression = 206, - NewExpression = 207, - TaggedTemplateExpression = 208, - TypeAssertionExpression = 209, - ParenthesizedExpression = 210, - FunctionExpression = 211, - ArrowFunction = 212, - DeleteExpression = 213, - TypeOfExpression = 214, - VoidExpression = 215, - AwaitExpression = 216, - PrefixUnaryExpression = 217, - PostfixUnaryExpression = 218, - BinaryExpression = 219, - ConditionalExpression = 220, - TemplateExpression = 221, - YieldExpression = 222, - SpreadElement = 223, - ClassExpression = 224, - OmittedExpression = 225, - ExpressionWithTypeArguments = 226, - AsExpression = 227, - NonNullExpression = 228, - MetaProperty = 229, - SyntheticExpression = 230, - TemplateSpan = 231, - SemicolonClassElement = 232, - Block = 233, - EmptyStatement = 234, - VariableStatement = 235, - ExpressionStatement = 236, - IfStatement = 237, - DoStatement = 238, - WhileStatement = 239, - ForStatement = 240, - ForInStatement = 241, - ForOfStatement = 242, - ContinueStatement = 243, - BreakStatement = 244, - ReturnStatement = 245, - WithStatement = 246, - SwitchStatement = 247, - LabeledStatement = 248, - ThrowStatement = 249, - TryStatement = 250, - DebuggerStatement = 251, - VariableDeclaration = 252, - VariableDeclarationList = 253, - FunctionDeclaration = 254, - ClassDeclaration = 255, - InterfaceDeclaration = 256, - TypeAliasDeclaration = 257, - EnumDeclaration = 258, - ModuleDeclaration = 259, - ModuleBlock = 260, - CaseBlock = 261, - NamespaceExportDeclaration = 262, - ImportEqualsDeclaration = 263, - ImportDeclaration = 264, - ImportClause = 265, - NamespaceImport = 266, - NamedImports = 267, - ImportSpecifier = 268, - ExportAssignment = 269, - ExportDeclaration = 270, - NamedExports = 271, - NamespaceExport = 272, - ExportSpecifier = 273, - MissingDeclaration = 274, - ExternalModuleReference = 275, - JsxElement = 276, - JsxSelfClosingElement = 277, - JsxOpeningElement = 278, - JsxClosingElement = 279, - JsxFragment = 280, - JsxOpeningFragment = 281, - JsxClosingFragment = 282, - JsxAttribute = 283, - JsxAttributes = 284, - JsxSpreadAttribute = 285, - JsxExpression = 286, - CaseClause = 287, - DefaultClause = 288, - HeritageClause = 289, - CatchClause = 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, - JSDocMemberName = 306, - JSDocAllType = 307, - JSDocUnknownType = 308, - JSDocNullableType = 309, - JSDocNonNullableType = 310, - JSDocOptionalType = 311, - JSDocFunctionType = 312, - JSDocVariadicType = 313, - JSDocNamepathType = 314, - JSDocComment = 315, - JSDocText = 316, - JSDocTypeLiteral = 317, - JSDocSignature = 318, - JSDocLink = 319, - JSDocLinkCode = 320, - JSDocLinkPlain = 321, - JSDocTag = 322, - JSDocAugmentsTag = 323, - JSDocImplementsTag = 324, - JSDocAuthorTag = 325, - JSDocDeprecatedTag = 326, - JSDocClassTag = 327, - JSDocPublicTag = 328, - JSDocPrivateTag = 329, - JSDocProtectedTag = 330, - JSDocReadonlyTag = 331, - JSDocOverrideTag = 332, - JSDocCallbackTag = 333, - JSDocEnumTag = 334, - JSDocParameterTag = 335, - JSDocReturnTag = 336, - JSDocThisTag = 337, - JSDocTypeTag = 338, - JSDocTemplateTag = 339, - JSDocTypedefTag = 340, - JSDocSeeTag = 341, - JSDocPropertyTag = 342, - SyntaxList = 343, - NotEmittedStatement = 344, - PartiallyEmittedExpression = 345, - CommaListExpression = 346, - MergeDeclarationMarker = 347, - EndOfDeclarationMarker = 348, - SyntheticReferenceExpression = 349, - Count = 350, + AssertKeyword = 129, + AnyKeyword = 130, + AsyncKeyword = 131, + AwaitKeyword = 132, + BooleanKeyword = 133, + ConstructorKeyword = 134, + DeclareKeyword = 135, + GetKeyword = 136, + InferKeyword = 137, + IntrinsicKeyword = 138, + IsKeyword = 139, + KeyOfKeyword = 140, + ModuleKeyword = 141, + NamespaceKeyword = 142, + NeverKeyword = 143, + ReadonlyKeyword = 144, + RequireKeyword = 145, + NumberKeyword = 146, + ObjectKeyword = 147, + SetKeyword = 148, + StringKeyword = 149, + SymbolKeyword = 150, + TypeKeyword = 151, + UndefinedKeyword = 152, + UniqueKeyword = 153, + UnknownKeyword = 154, + FromKeyword = 155, + GlobalKeyword = 156, + BigIntKeyword = 157, + OverrideKeyword = 158, + OfKeyword = 159, + QualifiedName = 160, + ComputedPropertyName = 161, + TypeParameter = 162, + Parameter = 163, + Decorator = 164, + PropertySignature = 165, + PropertyDeclaration = 166, + MethodSignature = 167, + MethodDeclaration = 168, + ClassStaticBlockDeclaration = 169, + Constructor = 170, + GetAccessor = 171, + SetAccessor = 172, + CallSignature = 173, + ConstructSignature = 174, + IndexSignature = 175, + TypePredicate = 176, + TypeReference = 177, + FunctionType = 178, + ConstructorType = 179, + TypeQuery = 180, + TypeLiteral = 181, + ArrayType = 182, + TupleType = 183, + OptionalType = 184, + RestType = 185, + UnionType = 186, + IntersectionType = 187, + ConditionalType = 188, + InferType = 189, + ParenthesizedType = 190, + ThisType = 191, + TypeOperator = 192, + IndexedAccessType = 193, + MappedType = 194, + LiteralType = 195, + NamedTupleMember = 196, + TemplateLiteralType = 197, + TemplateLiteralTypeSpan = 198, + ImportType = 199, + ObjectBindingPattern = 200, + ArrayBindingPattern = 201, + BindingElement = 202, + ArrayLiteralExpression = 203, + ObjectLiteralExpression = 204, + PropertyAccessExpression = 205, + ElementAccessExpression = 206, + CallExpression = 207, + NewExpression = 208, + TaggedTemplateExpression = 209, + TypeAssertionExpression = 210, + ParenthesizedExpression = 211, + FunctionExpression = 212, + ArrowFunction = 213, + DeleteExpression = 214, + TypeOfExpression = 215, + VoidExpression = 216, + AwaitExpression = 217, + PrefixUnaryExpression = 218, + PostfixUnaryExpression = 219, + BinaryExpression = 220, + ConditionalExpression = 221, + TemplateExpression = 222, + YieldExpression = 223, + SpreadElement = 224, + ClassExpression = 225, + OmittedExpression = 226, + ExpressionWithTypeArguments = 227, + AsExpression = 228, + NonNullExpression = 229, + MetaProperty = 230, + SyntheticExpression = 231, + TemplateSpan = 232, + SemicolonClassElement = 233, + Block = 234, + EmptyStatement = 235, + VariableStatement = 236, + ExpressionStatement = 237, + IfStatement = 238, + DoStatement = 239, + WhileStatement = 240, + ForStatement = 241, + ForInStatement = 242, + ForOfStatement = 243, + ContinueStatement = 244, + BreakStatement = 245, + ReturnStatement = 246, + WithStatement = 247, + SwitchStatement = 248, + LabeledStatement = 249, + ThrowStatement = 250, + TryStatement = 251, + DebuggerStatement = 252, + VariableDeclaration = 253, + VariableDeclarationList = 254, + FunctionDeclaration = 255, + ClassDeclaration = 256, + InterfaceDeclaration = 257, + TypeAliasDeclaration = 258, + EnumDeclaration = 259, + ModuleDeclaration = 260, + ModuleBlock = 261, + CaseBlock = 262, + NamespaceExportDeclaration = 263, + ImportEqualsDeclaration = 264, + ImportDeclaration = 265, + ImportClause = 266, + NamespaceImport = 267, + NamedImports = 268, + ImportSpecifier = 269, + ExportAssignment = 270, + ExportDeclaration = 271, + NamedExports = 272, + NamespaceExport = 273, + ExportSpecifier = 274, + MissingDeclaration = 275, + ExternalModuleReference = 276, + JsxElement = 277, + JsxSelfClosingElement = 278, + JsxOpeningElement = 279, + JsxClosingElement = 280, + JsxFragment = 281, + JsxOpeningFragment = 282, + JsxClosingFragment = 283, + JsxAttribute = 284, + JsxAttributes = 285, + JsxSpreadAttribute = 286, + JsxExpression = 287, + CaseClause = 288, + DefaultClause = 289, + HeritageClause = 290, + CatchClause = 291, + AssertClause = 292, + AssertEntry = 293, + PropertyAssignment = 294, + ShorthandPropertyAssignment = 295, + SpreadAssignment = 296, + EnumMember = 297, + UnparsedPrologue = 298, + UnparsedPrepend = 299, + UnparsedText = 300, + UnparsedInternalText = 301, + UnparsedSyntheticReference = 302, + SourceFile = 303, + Bundle = 304, + UnparsedSource = 305, + InputFiles = 306, + JSDocTypeExpression = 307, + JSDocNameReference = 308, + JSDocMemberName = 309, + JSDocAllType = 310, + JSDocUnknownType = 311, + JSDocNullableType = 312, + JSDocNonNullableType = 313, + JSDocOptionalType = 314, + JSDocFunctionType = 315, + JSDocVariadicType = 316, + JSDocNamepathType = 317, + JSDocComment = 318, + JSDocText = 319, + JSDocTypeLiteral = 320, + JSDocSignature = 321, + JSDocLink = 322, + JSDocLinkCode = 323, + JSDocLinkPlain = 324, + JSDocTag = 325, + JSDocAugmentsTag = 326, + JSDocImplementsTag = 327, + JSDocAuthorTag = 328, + JSDocDeprecatedTag = 329, + JSDocClassTag = 330, + JSDocPublicTag = 331, + JSDocPrivateTag = 332, + JSDocProtectedTag = 333, + JSDocReadonlyTag = 334, + JSDocOverrideTag = 335, + JSDocCallbackTag = 336, + JSDocEnumTag = 337, + JSDocParameterTag = 338, + JSDocReturnTag = 339, + JSDocThisTag = 340, + JSDocTypeTag = 341, + JSDocTemplateTag = 342, + JSDocTypedefTag = 343, + JSDocSeeTag = 344, + JSDocPropertyTag = 345, + SyntaxList = 346, + NotEmittedStatement = 347, + PartiallyEmittedExpression = 348, + CommaListExpression = 349, + MergeDeclarationMarker = 350, + EndOfDeclarationMarker = 351, + SyntheticReferenceExpression = 352, + Count = 353, FirstAssignment = 63, LastAssignment = 78, FirstCompoundAssignment = 64, @@ -463,15 +466,15 @@ declare namespace ts { FirstReservedWord = 81, LastReservedWord = 116, FirstKeyword = 81, - LastKeyword = 158, + LastKeyword = 159, FirstFutureReservedWord = 117, LastFutureReservedWord = 125, - FirstTypeNode = 175, - LastTypeNode = 198, + FirstTypeNode = 176, + LastTypeNode = 199, FirstPunctuation = 18, LastPunctuation = 78, FirstToken = 0, - LastToken = 158, + LastToken = 159, FirstTriviaToken = 2, LastTriviaToken = 7, FirstLiteralToken = 8, @@ -480,19 +483,19 @@ declare namespace ts { LastTemplateToken = 17, FirstBinaryOperator = 29, LastBinaryOperator = 78, - FirstStatement = 235, - LastStatement = 251, - FirstNode = 159, - FirstJSDocNode = 304, - LastJSDocNode = 342, - FirstJSDocTagNode = 322, - LastJSDocTagNode = 342, + FirstStatement = 236, + LastStatement = 252, + FirstNode = 160, + FirstJSDocNode = 307, + LastJSDocNode = 345, + FirstJSDocTagNode = 325, + LastJSDocTagNode = 345, } 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.HashToken | 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.OverrideKeyword | 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.OverrideKeyword | 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.OverrideKeyword | 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; @@ -597,6 +600,7 @@ 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; @@ -1630,6 +1634,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; @@ -1640,6 +1645,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; @@ -1662,6 +1680,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; @@ -3519,10 +3538,14 @@ 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): 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): 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; @@ -3533,8 +3556,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; @@ -3951,6 +3974,7 @@ declare namespace ts { ObjectBindingPatternElements = 525136, ArrayBindingPatternElements = 524880, ObjectLiteralExpressionProperties = 526226, + ImportClauseEntries = 526226, ArrayLiteralExpressionElements = 8914, CommaListElements = 528, CallExpressionArguments = 2576, @@ -4345,6 +4369,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 TypeOnlyAliasDeclaration; + 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; @@ -4592,6 +4617,8 @@ 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 isNamespaceImport(node: Node): node is NamespaceImport; function isNamespaceExport(node: Node): node is NamespaceExport; function isNamedImports(node: Node): node is NamedImports; @@ -7161,9 +7188,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, 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) => 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/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/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 new file mode 100644 index 0000000000000..11bbc5c2504f2 --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=commonjs).errors.txt @@ -0,0 +1,78 @@ +tests/cases/conformance/importAssertion/1.ts(1,14): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported 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. + + +==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/importAssertion/1.ts (3 errors) ==== + import './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + import { a, b } from './0' assert { "type": "json" } + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + import * as foo from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + a; + b; + foo.a; + foo.b; + +==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== + import { a, b } from './0' assert {} + ~~~~~~~~~ +!!! error TS2821: 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 TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + a; + b; + c; + d; + +==== tests/cases/conformance/importAssertion/3.ts (9 errors) ==== + const a = import('./0') + const b = import('./0', { assert: { type: "json" } }) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! 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 imports only support a second argument when the '--module' option is set to 'esnext'. + const d = import('./0', { assert: {} }) + ~~~~~~~~~~~~~~ +!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'. + const dd = import('./0', {}) + ~~ +!!! 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 imports only support a second argument when the '--module' option is set to 'esnext'. + const f = import() + ~~~~~~~~ +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments + const g = import('./0', {}, {}) + ~~ +!!! 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 imports only support 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 new file mode 100644 index 0000000000000..233a0a293b6e5 --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=commonjs).js @@ -0,0 +1,92 @@ +//// [tests/cases/conformance/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', { 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" }},) + + + +//// [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 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] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +import './0'; +//// [2.d.ts] +export {}; +//// [3.d.ts] +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 new file mode 100644 index 0000000000000..f7b77b135a91a --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=commonjs).symbols @@ -0,0 +1,104 @@ +=== 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/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/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/importAssertion/3.ts === +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', { assert: { type: "json" } }) +>b : Symbol(b, Decl(3.ts, 1, 5)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) +>assert : Symbol(assert, Decl(3.ts, 1, 25)) +>type : Symbol(type, Decl(3.ts, 1, 35)) + +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)) +>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', { 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, 4, 28)) + +const e = import('./0', foo()) +>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, 4, 28)) + +const f = import() +>f : Symbol(f, Decl(3.ts, 7, 5)) + +const g = import('./0', {}, {}) +>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 new file mode 100644 index 0000000000000..ca1a8b3f24ffc --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=commonjs).types @@ -0,0 +1,137 @@ +=== tests/cases/conformance/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/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/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/importAssertion/3.ts === +const a = import('./0') +>a : Promise +>import('./0') : Promise +>'./0' : "./0" + +const b = import('./0', { assert: { type: "json" } }) +>b : 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', { assert: { type: "json", ttype: "typo" } }) +>c : 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', { assert: {} }) +>d : 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 + +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" +>{} : {} +>{} : {} + +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 new file mode 100644 index 0000000000000..f9603006232bb --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=es2015).errors.txt @@ -0,0 +1,78 @@ +tests/cases/conformance/importAssertion/1.ts(1,14): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: 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(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) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/importAssertion/1.ts (3 errors) ==== + import './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + import { a, b } from './0' assert { "type": "json" } + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + import * as foo from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + a; + b; + foo.a; + foo.b; + +==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== + import { a, b } from './0' assert {} + ~~~~~~~~~ +!!! error TS2821: 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 TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + a; + b; + c; + d; + +==== 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', { 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', { 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', { 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()) + ~~~~~~~~~~~~~~~~~~~~ +!!! 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'. + 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 new file mode 100644 index 0000000000000..0dcd0888aed9d --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=es2015).js @@ -0,0 +1,85 @@ +//// [tests/cases/conformance/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', { 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" }},) + + + +//// [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', { 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] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +import './0'; +//// [2.d.ts] +export {}; +//// [3.d.ts] +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 new file mode 100644 index 0000000000000..f7b77b135a91a --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=es2015).symbols @@ -0,0 +1,104 @@ +=== 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/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/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/importAssertion/3.ts === +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', { assert: { type: "json" } }) +>b : Symbol(b, Decl(3.ts, 1, 5)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) +>assert : Symbol(assert, Decl(3.ts, 1, 25)) +>type : Symbol(type, Decl(3.ts, 1, 35)) + +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)) +>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', { 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, 4, 28)) + +const e = import('./0', foo()) +>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, 4, 28)) + +const f = import() +>f : Symbol(f, Decl(3.ts, 7, 5)) + +const g = import('./0', {}, {}) +>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 new file mode 100644 index 0000000000000..ca1a8b3f24ffc --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=es2015).types @@ -0,0 +1,137 @@ +=== tests/cases/conformance/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/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/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/importAssertion/3.ts === +const a = import('./0') +>a : Promise +>import('./0') : Promise +>'./0' : "./0" + +const b = import('./0', { assert: { type: "json" } }) +>b : 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', { assert: { type: "json", ttype: "typo" } }) +>c : 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', { assert: {} }) +>d : 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 + +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" +>{} : {} +>{} : {} + +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 new file mode 100644 index 0000000000000..8dd6d05aaab4b --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=esnext).errors.txt @@ -0,0 +1,42 @@ +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) ==== + export const a = 1; + export const b = 2; + +==== 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" } + a; + b; + foo.a; + foo.b; + +==== 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; + b; + c; + d; + +==== tests/cases/conformance/importAssertion/3.ts (2 errors) ==== + const a = 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() + ~~~~~~~~ +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments + const g = import('./0', {}, {}) + ~~~~~~~~~~~~~~~~~~~~~ +!!! 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/importAssertion1(module=esnext).js b/tests/baselines/reference/importAssertion1(module=esnext).js new file mode 100644 index 0000000000000..0dcd0888aed9d --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=esnext).js @@ -0,0 +1,85 @@ +//// [tests/cases/conformance/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', { 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" }},) + + + +//// [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', { 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] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +import './0'; +//// [2.d.ts] +export {}; +//// [3.d.ts] +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 new file mode 100644 index 0000000000000..f7b77b135a91a --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=esnext).symbols @@ -0,0 +1,104 @@ +=== 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/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/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/importAssertion/3.ts === +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', { assert: { type: "json" } }) +>b : Symbol(b, Decl(3.ts, 1, 5)) +>'./0' : Symbol("tests/cases/conformance/importAssertion/0", Decl(0.ts, 0, 0)) +>assert : Symbol(assert, Decl(3.ts, 1, 25)) +>type : Symbol(type, Decl(3.ts, 1, 35)) + +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)) +>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', { 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, 4, 28)) + +const e = import('./0', foo()) +>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, 4, 28)) + +const f = import() +>f : Symbol(f, Decl(3.ts, 7, 5)) + +const g = import('./0', {}, {}) +>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 new file mode 100644 index 0000000000000..ca1a8b3f24ffc --- /dev/null +++ b/tests/baselines/reference/importAssertion1(module=esnext).types @@ -0,0 +1,137 @@ +=== tests/cases/conformance/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/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/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/importAssertion/3.ts === +const a = import('./0') +>a : Promise +>import('./0') : Promise +>'./0' : "./0" + +const b = import('./0', { assert: { type: "json" } }) +>b : 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', { assert: { type: "json", ttype: "typo" } }) +>c : 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', { assert: {} }) +>d : 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 + +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" +>{} : {} +>{} : {} + +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 new file mode 100644 index 0000000000000..d3617f72bb06d --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=commonjs).errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/importAssertion/1.ts(1,22): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,21): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(4,27): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + + +==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== + export {} from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + export { a, b } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + export * from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + export * as ns from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: 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 TS2821: 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 TS2821: 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).js b/tests/baselines/reference/importAssertion2(module=commonjs).js new file mode 100644 index 0000000000000..067291329ba82 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=commonjs).js @@ -0,0 +1,65 @@ +//// [tests/cases/conformance/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'; +export { a, b } from './0'; +export * from './0'; +export * as ns from './0'; +//// [2.d.ts] +export { a, b } from './0'; +export { a as c, b as d } from './0'; diff --git a/tests/baselines/reference/importAssertion2(module=commonjs).symbols b/tests/baselines/reference/importAssertion2(module=commonjs).symbols new file mode 100644 index 0000000000000..6d4a43cd6c641 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=commonjs).symbols @@ -0,0 +1,28 @@ +=== 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/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/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(module=commonjs).types b/tests/baselines/reference/importAssertion2(module=commonjs).types new file mode 100644 index 0000000000000..cc912547f7693 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=commonjs).types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/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 import("tests/cases/conformance/importAssertion/0") +>type : any + +=== tests/cases/conformance/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(module=es2015).errors.txt b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt new file mode 100644 index 0000000000000..d3617f72bb06d --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=es2015).errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/importAssertion/1.ts(1,22): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(3,21): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/1.ts(4,27): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + + +==== tests/cases/conformance/importAssertion/0.ts (0 errors) ==== + export const a = 1; + export const b = 2; + +==== tests/cases/conformance/importAssertion/1.ts (4 errors) ==== + export {} from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + export { a, b } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + export * from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + export * as ns from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: 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 TS2821: 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 TS2821: 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).js b/tests/baselines/reference/importAssertion2(module=es2015).js new file mode 100644 index 0000000000000..01804f2b0de3b --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=es2015).js @@ -0,0 +1,41 @@ +//// [tests/cases/conformance/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'; +export { a, b } from './0'; +export * from './0'; +export * as ns from './0'; +//// [2.d.ts] +export { a, b } from './0'; +export { a as c, b as d } from './0'; diff --git a/tests/baselines/reference/importAssertion2(module=es2015).symbols b/tests/baselines/reference/importAssertion2(module=es2015).symbols new file mode 100644 index 0000000000000..6d4a43cd6c641 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=es2015).symbols @@ -0,0 +1,28 @@ +=== 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/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/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(module=es2015).types b/tests/baselines/reference/importAssertion2(module=es2015).types new file mode 100644 index 0000000000000..cc912547f7693 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=es2015).types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/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 import("tests/cases/conformance/importAssertion/0") +>type : any + +=== tests/cases/conformance/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(module=esnext).js b/tests/baselines/reference/importAssertion2(module=esnext).js new file mode 100644 index 0000000000000..f57ec44cc1546 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=esnext).js @@ -0,0 +1,40 @@ +//// [tests/cases/conformance/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" }; +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" }; + + +//// [0.d.ts] +export declare const a = 1; +export declare const b = 2; +//// [1.d.ts] +export {} from './0'; +export { a, b } from './0'; +export * from './0'; +export * as ns from './0'; +//// [2.d.ts] +export { a, b } from './0'; +export { a as c, b as d } from './0'; diff --git a/tests/baselines/reference/importAssertion2(module=esnext).symbols b/tests/baselines/reference/importAssertion2(module=esnext).symbols new file mode 100644 index 0000000000000..6d4a43cd6c641 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=esnext).symbols @@ -0,0 +1,28 @@ +=== 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/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/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(module=esnext).types b/tests/baselines/reference/importAssertion2(module=esnext).types new file mode 100644 index 0000000000000..3fa4d2bb27271 --- /dev/null +++ b/tests/baselines/reference/importAssertion2(module=esnext).types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/importAssertion/0.ts === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +=== tests/cases/conformance/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 import("tests/cases/conformance/importAssertion/0") +>type : error + +=== tests/cases/conformance/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/baselines/reference/importAssertion3(module=es2015).errors.txt b/tests/baselines/reference/importAssertion3(module=es2015).errors.txt new file mode 100644 index 0000000000000..fade981ac769f --- /dev/null +++ b/tests/baselines/reference/importAssertion3(module=es2015).errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/importAssertion/1.ts(1,27): error TS2821: 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 are only supported when the '--module' option is set to 'esnext'. +tests/cases/conformance/importAssertion/2.ts(1,31): error TS2821: 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 are only supported when the '--module' option is set to 'esnext'. + + +==== 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 TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + export type { I } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + +==== tests/cases/conformance/importAssertion/2.ts (2 errors) ==== + import type { I } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'. + import type * as foo from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2821: 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/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..6f11adbe4e897 --- /dev/null +++ b/tests/baselines/reference/importAssertion3(module=esnext).errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/importAssertion/1.ts(1,27): error TS2822: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/1.ts(2,30): error TS2822: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/2.ts(1,31): error TS2822: Import assertions cannot be used with type-only imports or exports. +tests/cases/conformance/importAssertion/2.ts(2,33): error TS2822: 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 TS2822: Import assertions cannot be used with type-only imports or exports. + export type { I } from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2822: 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 TS2822: Import assertions cannot be used with type-only imports or exports. + import type * as foo from './0' assert { type: "json" } + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2822: 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/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt index bc90a5042ba7f..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): 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(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 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(); ~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. +!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments const p4 = import("pathToModule", "secondModule"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1324: Dynamic import must have one specifier as an argument. ~~~~~~~~~~~~~~ -!!! 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 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) { diff --git a/tests/cases/conformance/importAssertion/importAssertion1.ts b/tests/cases/conformance/importAssertion/importAssertion1.ts new file mode 100644 index 0000000000000..b547158cf14cc --- /dev/null +++ b/tests/cases/conformance/importAssertion/importAssertion1.ts @@ -0,0 +1,37 @@ +// @declaration: true +// @target: es2015 +// @module: es2015, commonjs, 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', { 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" }},) + diff --git a/tests/cases/conformance/importAssertion/importAssertion2.ts b/tests/cases/conformance/importAssertion/importAssertion2.ts new file mode 100644 index 0000000000000..42a26af43eb7c --- /dev/null +++ b/tests/cases/conformance/importAssertion/importAssertion2.ts @@ -0,0 +1,17 @@ +// @declaration: true +// @target: es2015 +// @module: es2015, commonjs, esnext + +// @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" } 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" } + 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(); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy