feat(53656): Add support for the updated import attributes proposal (#54242)

This commit is contained in:
Oleksandr T
2023-09-26 13:20:15 -07:00
committed by GitHub
parent b12af0fa2b
commit 2e9e9a292c
169 changed files with 32223 additions and 374 deletions
+76 -76
View File
@@ -340,7 +340,7 @@ import {
getPropertyNameForPropertyNameNode,
getPropertyNameFromType,
getResolutionDiagnostic,
getResolutionModeOverrideForClause,
getResolutionModeOverride,
getResolvedExternalModuleName,
getResolveJsonModule,
getRestParameterElementType,
@@ -393,6 +393,7 @@ import {
hasOverrideModifier,
hasPossibleExternalModuleReference,
hasQuestionToken,
hasResolutionModeOverride,
hasRestParameter,
hasScopeMarker,
hasStaticModifier,
@@ -405,6 +406,7 @@ import {
IdentifierTypePredicate,
idText,
IfStatement,
ImportAttributes,
ImportCall,
ImportClause,
ImportDeclaration,
@@ -412,7 +414,6 @@ import {
ImportOrExportSpecifier,
ImportsNotUsedAsValues,
ImportSpecifier,
ImportTypeAssertionContainer,
ImportTypeNode,
IndexedAccessType,
IndexedAccessTypeNode,
@@ -643,7 +644,6 @@ import {
isNamespaceExportDeclaration,
isNamespaceReexportDeclaration,
isNewExpression,
isNightly,
isNodeDescendantOf,
isNonNullAccess,
isNullishCoalesce,
@@ -5016,11 +5016,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
if (moduleResolutionKind === ModuleResolutionKind.Node16 || moduleResolutionKind === ModuleResolutionKind.NodeNext) {
const isSyncImport = (currentSourceFile.impliedNodeFormat === ModuleKind.CommonJS && !findAncestor(location, isImportCall)) || !!findAncestor(location, isImportEqualsDeclaration);
const overrideClauseHost = findAncestor(location, l => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l)) as ImportTypeNode | ImportDeclaration | ExportDeclaration | undefined;
const overrideClause = overrideClauseHost && isImportTypeNode(overrideClauseHost) ? overrideClauseHost.assertions?.assertClause : overrideClauseHost?.assertClause;
const overrideHost = findAncestor(location, l => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l)) as ImportTypeNode | ImportDeclaration | ExportDeclaration | undefined;
// An override clause will take effect for type-only imports and import types, and allows importing the types across formats, regardless of
// normal mode restrictions
if (isSyncImport && sourceFile.impliedNodeFormat === ModuleKind.ESNext && !getResolutionModeOverrideForClause(overrideClause)) {
if (isSyncImport && sourceFile.impliedNodeFormat === ModuleKind.ESNext && !hasResolutionModeOverride(overrideHost)) {
if (findAncestor(location, isImportEqualsDeclaration)) {
// ImportEquals in a ESM file resolving to another ESM file
error(errorNode, Diagnostics.Module_0_cannot_be_imported_using_this_construct_The_specifier_only_resolves_to_an_ES_module_which_cannot_be_imported_with_require_Use_an_ECMAScript_import_instead, moduleReference);
@@ -7147,7 +7146,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return factory.updateImportTypeNode(
root,
root.argument,
root.assertions,
root.attributes,
qualifier,
typeArguments,
root.isTypeOf,
@@ -7935,18 +7934,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const contextFile = getSourceFileOfNode(getOriginalNode(context.enclosingDeclaration));
const targetFile = getSourceFileOfModule(chain[0]);
let specifier: string | undefined;
let assertion: ImportTypeAssertionContainer | undefined;
let attributes: ImportAttributes | undefined;
if (getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Node16 || getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.NodeNext) {
// An `import` type directed at an esm format file is only going to resolve in esm mode - set the esm mode assertion
if (targetFile?.impliedNodeFormat === ModuleKind.ESNext && targetFile.impliedNodeFormat !== contextFile?.impliedNodeFormat) {
specifier = getSpecifierForModuleSymbol(chain[0], context, ModuleKind.ESNext);
assertion = factory.createImportTypeAssertionContainer(factory.createAssertClause(factory.createNodeArray([
factory.createAssertEntry(
factory.createStringLiteral("resolution-mode"),
factory.createStringLiteral("import"),
),
])));
context.tracker.reportImportTypeNodeResolutionModeOverride?.();
attributes = factory.createImportAttributes(
factory.createNodeArray([
factory.createImportAttribute(
factory.createStringLiteral("resolution-mode"),
factory.createStringLiteral("import"),
),
]),
);
}
}
if (!specifier) {
@@ -7964,17 +7964,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
specifier = oldSpecifier;
}
else {
assertion = factory.createImportTypeAssertionContainer(factory.createAssertClause(factory.createNodeArray([
factory.createAssertEntry(
factory.createStringLiteral("resolution-mode"),
factory.createStringLiteral(swappedMode === ModuleKind.ESNext ? "import" : "require"),
),
])));
context.tracker.reportImportTypeNodeResolutionModeOverride?.();
attributes = factory.createImportAttributes(
factory.createNodeArray([
factory.createImportAttribute(
factory.createStringLiteral("resolution-mode"),
factory.createStringLiteral(swappedMode === ModuleKind.ESNext ? "import" : "require"),
),
]),
);
}
}
if (!assertion) {
if (!attributes) {
// If ultimately we can only name the symbol with a reference that dives into a `node_modules` folder, we should error
// since declaration files with these kinds of references are liable to fail when published :(
context.encounteredError = true;
@@ -7991,12 +7992,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const lastId = isIdentifier(nonRootParts) ? nonRootParts : nonRootParts.right;
setIdentifierTypeArguments(lastId, /*typeArguments*/ undefined);
}
return factory.createImportTypeNode(lit, assertion, nonRootParts as EntityName, typeParameterNodes as readonly TypeNode[], isTypeOf);
return factory.createImportTypeNode(lit, attributes, nonRootParts as EntityName, typeParameterNodes as readonly TypeNode[], isTypeOf);
}
else {
const splitNode = getTopmostIndexedAccessType(nonRootParts);
const qualifier = (splitNode.objectType as TypeReferenceNode).typeName;
return factory.createIndexedAccessTypeNode(factory.createImportTypeNode(lit, assertion, qualifier, typeParameterNodes as readonly TypeNode[], isTypeOf), splitNode.indexType);
return factory.createIndexedAccessTypeNode(factory.createImportTypeNode(lit, attributes, qualifier, typeParameterNodes as readonly TypeNode[], isTypeOf), splitNode.indexType);
}
}
@@ -8504,7 +8505,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return factory.updateImportTypeNode(
node,
factory.updateLiteralTypeNode(node.argument, rewriteModuleSpecifier(node, node.argument.literal)),
node.assertions,
node.attributes,
node.qualifier,
visitNodes(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode),
node.isTypeOf,
@@ -8729,7 +8730,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
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.assertClause && !!d.exportClause && isNamedExports(d.exportClause));
const index = findIndex(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !d.attributes && !!d.exportClause && isNamedExports(d.exportClause));
if (index >= 0) {
const exportDecl = statements[index] as ExportDeclaration & { readonly exportClause: NamedExports; };
const replacements = mapDefined(exportDecl.exportClause.elements, e => {
@@ -8761,7 +8762,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
replacements,
),
exportDecl.moduleSpecifier,
exportDecl.assertClause,
exportDecl.attributes,
);
}
}
@@ -9483,7 +9484,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
)]),
),
factory.createStringLiteral(specifier),
/*assertClause*/ undefined,
/*attributes*/ undefined,
),
ModifierFlags.None,
);
@@ -9567,7 +9568,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
/*modifiers*/ undefined,
factory.createImportClause(/*isTypeOnly*/ false, factory.createIdentifier(localName), /*namedBindings*/ undefined),
specifier,
(node as ImportClause).parent.assertClause,
(node as ImportClause).parent.attributes,
),
ModifierFlags.None,
);
@@ -9581,7 +9582,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
/*modifiers*/ undefined,
factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamespaceImport(factory.createIdentifier(localName))),
specifier,
(node as NamespaceImport).parent.parent.assertClause,
(node as ImportClause).parent.attributes,
),
ModifierFlags.None,
);
@@ -9616,7 +9617,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
]),
),
specifier,
(node as ImportSpecifier).parent.parent.parent.assertClause,
(node as ImportSpecifier).parent.parent.parent.attributes,
),
ModifierFlags.None,
);
@@ -39764,18 +39765,18 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function checkImportType(node: ImportTypeNode) {
checkSourceElement(node.argument);
if (node.assertions) {
const override = getResolutionModeOverrideForClause(node.assertions.assertClause, grammarErrorOnNode);
if (override) {
if (!isNightly()) {
grammarErrorOnNode(node.assertions.assertClause, Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next);
}
if (getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) {
grammarErrorOnNode(node.assertions.assertClause, Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext);
}
if (node.attributes) {
const override = getResolutionModeOverride(node.attributes, grammarErrorOnNode);
const errorNode = node.attributes;
if (override && errorNode && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) {
grammarErrorOnNode(
errorNode,
node.attributes.token === SyntaxKind.WithKeyword
? Diagnostics.The_resolution_mode_attribute_is_only_supported_when_moduleResolution_is_node16_or_nodenext
: Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext,
);
}
}
checkTypeReferenceOrImport(node);
}
@@ -45014,12 +45015,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return false;
}
}
if (!isImportEqualsDeclaration(node) && node.assertClause) {
if (!isImportEqualsDeclaration(node) && node.attributes) {
const diagnostic = node.attributes.token === SyntaxKind.WithKeyword ? Diagnostics.Import_attribute_values_must_be_string_literal_expressions : Diagnostics.Import_assertion_values_must_be_string_literal_expressions;
let hasError = false;
for (const clause of node.assertClause.elements) {
if (!isStringLiteral(clause.value)) {
for (const attr of node.attributes.elements) {
if (!isStringLiteral(attr.value)) {
hasError = true;
error(clause.value, Diagnostics.Import_assertion_values_must_be_string_literal_expressions);
error(attr.value, diagnostic);
}
}
return !hasError;
@@ -45203,37 +45205,42 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
function checkAssertClause(declaration: ImportDeclaration | ExportDeclaration) {
if (declaration.assertClause) {
const validForTypeAssertions = isExclusivelyTypeOnlyImportOrExport(declaration);
const override = getResolutionModeOverrideForClause(declaration.assertClause, validForTypeAssertions ? grammarErrorOnNode : undefined);
if (validForTypeAssertions && override) {
if (!isNightly()) {
grammarErrorOnNode(declaration.assertClause, Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next);
}
function checkImportAttributes(declaration: ImportDeclaration | ExportDeclaration) {
const node = declaration.attributes;
if (node) {
const validForTypeAttributes = isExclusivelyTypeOnlyImportOrExport(declaration);
const override = getResolutionModeOverride(node, validForTypeAttributes ? grammarErrorOnNode : undefined);
const isImportAttributes = declaration.attributes.token === SyntaxKind.WithKeyword;
if (validForTypeAttributes && override) {
if (getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeNext) {
return grammarErrorOnNode(declaration.assertClause, Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext);
return grammarErrorOnNode(
node,
isImportAttributes
? Diagnostics.The_resolution_mode_attribute_is_only_supported_when_moduleResolution_is_node16_or_nodenext
: Diagnostics.resolution_mode_assertions_are_only_supported_when_moduleResolution_is_node16_or_nodenext,
);
}
return; // Other grammar checks do not apply to type-only imports with resolution mode assertions
}
const mode = (moduleKind === ModuleKind.NodeNext) && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier);
if (mode !== ModuleKind.ESNext && moduleKind !== ModuleKind.ESNext) {
return grammarErrorOnNode(
declaration.assertClause,
moduleKind === ModuleKind.NodeNext
? Diagnostics.Import_assertions_are_not_allowed_on_statements_that_transpile_to_CommonJS_require_calls
: Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext,
);
const message = isImportAttributes
? moduleKind === ModuleKind.NodeNext
? Diagnostics.Import_attributes_are_not_allowed_on_statements_that_transpile_to_CommonJS_require_calls
: Diagnostics.Import_attributes_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext
: moduleKind === ModuleKind.NodeNext
? Diagnostics.Import_assertions_are_not_allowed_on_statements_that_transpile_to_CommonJS_require_calls
: Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_or_nodenext;
return grammarErrorOnNode(node, message);
}
if (isImportDeclaration(declaration) ? declaration.importClause?.isTypeOnly : declaration.isTypeOnly) {
return grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports);
return grammarErrorOnNode(node, isImportAttributes ? Diagnostics.Import_attributes_cannot_be_used_with_type_only_imports_or_exports : Diagnostics.Import_assertions_cannot_be_used_with_type_only_imports_or_exports);
}
if (override) {
return grammarErrorOnNode(declaration.assertClause, Diagnostics.resolution_mode_can_only_be_set_for_type_only_imports);
return grammarErrorOnNode(node, Diagnostics.resolution_mode_can_only_be_set_for_type_only_imports);
}
}
}
@@ -45269,7 +45276,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
}
checkAssertClause(node);
checkImportAttributes(node);
}
function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) {
@@ -45365,7 +45372,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}
}
checkAssertClause(node);
checkImportAttributes(node);
}
function checkGrammarExportDeclaration(node: ExportDeclaration): boolean {
@@ -49907,13 +49914,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
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_node16_or_nodenext);
const importAttributesArgument = nodeArguments[1];
return grammarErrorOnNode(importAttributesArgument, Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext_node16_or_nodenext);
}
}
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);
return grammarErrorOnNode(node, Diagnostics.Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_set_of_attributes_as_arguments);
}
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
@@ -50244,13 +50251,6 @@ class SymbolTrackerImpl implements SymbolTracker {
}
}
reportImportTypeNodeResolutionModeOverride(): void {
if (this.inner?.reportImportTypeNodeResolutionModeOverride) {
this.onDiagnosticReported();
this.inner.reportImportTypeNodeResolutionModeOverride();
}
}
private onDiagnosticReported() {
this.context.reportedDiagnostic = true;
}
+33 -9
View File
@@ -1472,7 +1472,7 @@
"category": "Message",
"code": 1449
},
"Dynamic imports can only accept a module specifier and an optional assertion as arguments": {
"Dynamic imports can only accept a module specifier and an optional set of attributes as arguments": {
"category": "Message",
"code": 1450
},
@@ -1520,6 +1520,18 @@
"category": "Message",
"code": 1461
},
"The 'resolution-mode' attribute is only supported when 'moduleResolution' is 'node16' or 'nodenext'.": {
"category": "Error",
"code": 1462
},
"'resolution-mode' is the only valid key for type import attributes.": {
"category": "Error",
"code": 1463
},
"Type import attributes should have exactly one key - 'resolution-mode' - with value 'import' or 'require'.": {
"category": "Error",
"code": 1464
},
"The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.": {
"category": "Error",
@@ -1625,6 +1637,10 @@
"category": "Error",
"code": 1495
},
"Identifier, string literal, or number literal expected.": {
"category": "Error",
"code": 1496
},
"The types of '{0}' are incompatible between these types.": {
"category": "Error",
@@ -3579,6 +3595,10 @@
"category": "Error",
"code": 2822
},
"Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.": {
"category": "Error",
"code": 2823
},
"Cannot find namespace '{0}'. Did you mean '{1}'?": {
"category": "Error",
"code": 2833
@@ -3611,10 +3631,6 @@
"category": "Error",
"code": 2840
},
"The type of this expression cannot be named without a 'resolution-mode' assertion, which is an unstable feature. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.": {
"category": "Error",
"code": 2841
},
"'{0}' is an unused renaming of '{1}'. Did you intend to use it as a type annotation?": {
"category": "Error",
"code": 2842
@@ -3667,6 +3683,18 @@
"category": "Error",
"code": 2855
},
"Import attributes are not allowed on statements that transpile to CommonJS 'require' calls.": {
"category": "Error",
"code": 2856
},
"Import attributes cannot be used with type-only imports or exports.": {
"category": "Error",
"code": 2857
},
"Import attribute values must be string literal expressions.": {
"category": "Error",
"code": 2858
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
@@ -4100,10 +4128,6 @@
"category": "Error",
"code": 4124
},
"'resolution-mode' assertions are unstable. Use nightly TypeScript to silence this error. Try updating with 'npm install -D typescript@next'.": {
"category": "Error",
"code": 4125
},
"The current host does not support the '{0}' option.": {
"category": "Error",
+18 -18
View File
@@ -7,8 +7,6 @@ import {
ArrayTypeNode,
ArrowFunction,
AsExpression,
AssertClause,
AssertEntry,
AwaitExpression,
base64encode,
BigIntLiteral,
@@ -191,6 +189,8 @@ import {
Identifier,
idText,
IfStatement,
ImportAttribute,
ImportAttributes,
ImportClause,
ImportDeclaration,
ImportEqualsDeclaration,
@@ -2055,10 +2055,10 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
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.ImportAttributes:
return emitImportAttributes(node as ImportAttributes);
case SyntaxKind.ImportAttribute:
return emitImportAttribute(node as ImportAttribute);
case SyntaxKind.MissingDeclaration:
return;
@@ -2948,16 +2948,16 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
writeKeyword("import");
writePunctuation("(");
emit(node.argument);
if (node.assertions) {
if (node.attributes) {
writePunctuation(",");
writeSpace();
writePunctuation("{");
writeSpace();
writeKeyword("assert");
writeKeyword(node.attributes.token === SyntaxKind.AssertKeyword ? "assert" : "with");
writePunctuation(":");
writeSpace();
const elements = node.assertions.assertClause.elements;
emitList(node.assertions.assertClause, elements, ListFormat.ImportClauseEntries);
const elements = node.attributes.elements;
emitList(node.attributes, elements, ListFormat.ImportAttributes);
writeSpace();
writePunctuation("}");
}
@@ -4003,8 +4003,8 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
writeSpace();
}
emitExpression(node.moduleSpecifier);
if (node.assertClause) {
emitWithLeadingSpace(node.assertClause);
if (node.attributes) {
emitWithLeadingSpace(node.attributes);
}
writeTrailingSemicolon();
}
@@ -4078,20 +4078,20 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
writeSpace();
emitExpression(node.moduleSpecifier);
}
if (node.assertClause) {
emitWithLeadingSpace(node.assertClause);
if (node.attributes) {
emitWithLeadingSpace(node.attributes);
}
writeTrailingSemicolon();
}
function emitAssertClause(node: AssertClause) {
emitTokenWithComment(SyntaxKind.AssertKeyword, node.pos, writeKeyword, node);
function emitImportAttributes(node: ImportAttributes) {
emitTokenWithComment(node.token, node.pos, writeKeyword, node);
writeSpace();
const elements = node.elements;
emitList(node, elements, ListFormat.ImportClauseEntries);
emitList(node, elements, ListFormat.ImportAttributes);
}
function emitAssertEntry(node: AssertEntry) {
function emitImportAttribute(node: ImportAttribute) {
emit(node.name);
writePunctuation(":");
writeSpace();
+65 -17
View File
@@ -137,6 +137,9 @@ import {
IfStatement,
ImmediatelyInvokedArrowFunction,
ImmediatelyInvokedFunctionExpression,
ImportAttribute,
ImportAttributeName,
ImportAttributes,
ImportClause,
ImportDeclaration,
ImportEqualsDeclaration,
@@ -791,6 +794,10 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
updateAssertEntry,
createImportTypeAssertionContainer,
updateImportTypeAssertionContainer,
createImportAttributes,
updateImportAttributes,
createImportAttribute,
updateImportAttribute,
createNamespaceImport,
updateNamespaceImport,
createNamespaceExport,
@@ -2643,14 +2650,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
// @api
function createImportTypeNode(
argument: TypeNode,
assertions?: ImportTypeAssertionContainer,
attributes?: ImportAttributes,
qualifier?: EntityName,
typeArguments?: readonly TypeNode[],
isTypeOf = false,
): ImportTypeNode {
const node = createBaseNode<ImportTypeNode>(SyntaxKind.ImportType);
node.argument = argument;
node.assertions = assertions;
node.attributes = attributes;
if (node.assertions && node.assertions.assertClause && node.attributes) {
(node.assertions as Mutable<ImportTypeAssertionContainer>).assertClause = node.attributes;
}
node.qualifier = qualifier;
node.typeArguments = typeArguments && parenthesizerRules().parenthesizeTypeArguments(typeArguments);
node.isTypeOf = isTypeOf;
@@ -2662,17 +2672,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
function updateImportTypeNode(
node: ImportTypeNode,
argument: TypeNode,
assertions: ImportTypeAssertionContainer | undefined,
attributes: ImportAttributes | undefined,
qualifier: EntityName | undefined,
typeArguments: readonly TypeNode[] | undefined,
isTypeOf: boolean = node.isTypeOf,
): ImportTypeNode {
return node.argument !== argument
|| node.assertions !== assertions
|| node.attributes !== attributes
|| node.qualifier !== qualifier
|| node.typeArguments !== typeArguments
|| node.isTypeOf !== isTypeOf
? update(createImportTypeNode(argument, assertions, qualifier, typeArguments, isTypeOf), node)
? update(createImportTypeNode(argument, attributes, qualifier, typeArguments, isTypeOf), node)
: node;
}
@@ -4696,13 +4706,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
modifiers: readonly ModifierLike[] | undefined,
importClause: ImportClause | undefined,
moduleSpecifier: Expression,
assertClause: AssertClause | undefined,
attributes: ImportAttributes | undefined,
): ImportDeclaration {
const node = createBaseNode<ImportDeclaration>(SyntaxKind.ImportDeclaration);
node.modifiers = asNodeArray(modifiers);
node.importClause = importClause;
node.moduleSpecifier = moduleSpecifier;
node.assertClause = assertClause;
node.attributes = node.assertClause = attributes;
node.transformFlags |= propagateChildFlags(node.importClause) |
propagateChildFlags(node.moduleSpecifier);
node.transformFlags &= ~TransformFlags.ContainsPossibleTopLevelAwait; // always parsed in an Await context
@@ -4717,13 +4727,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
modifiers: readonly ModifierLike[] | undefined,
importClause: ImportClause | undefined,
moduleSpecifier: Expression,
assertClause: AssertClause | undefined,
attributes: ImportAttributes | undefined,
) {
return node.modifiers !== modifiers
|| node.importClause !== importClause
|| node.moduleSpecifier !== moduleSpecifier
|| node.assertClause !== assertClause
? update(createImportDeclaration(modifiers, importClause, moduleSpecifier, assertClause), node)
|| node.attributes !== attributes
? update(createImportDeclaration(modifiers, importClause, moduleSpecifier, attributes), node)
: node;
}
@@ -4756,6 +4766,7 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
const node = createBaseNode<AssertClause>(SyntaxKind.AssertClause);
node.elements = createNodeArray(elements);
node.multiLine = multiLine;
node.token = SyntaxKind.AssertKeyword;
node.transformFlags |= TransformFlags.ContainsESNext;
return node;
}
@@ -4801,6 +4812,43 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
: node;
}
// @api
function createImportAttributes(elements: readonly ImportAttribute[], multiLine?: boolean): ImportAttributes;
function createImportAttributes(elements: readonly ImportAttribute[], multiLine?: boolean, token?: ImportAttributes["token"]): ImportAttributes;
function createImportAttributes(elements: readonly ImportAttribute[], multiLine?: boolean, token?: ImportAttributes["token"]): ImportAttributes {
const node = createBaseNode<ImportAttributes>(SyntaxKind.ImportAttributes);
node.token = token ?? SyntaxKind.WithKeyword;
node.elements = createNodeArray(elements);
node.multiLine = multiLine;
node.transformFlags |= TransformFlags.ContainsESNext;
return node;
}
// @api
function updateImportAttributes(node: ImportAttributes, elements: readonly ImportAttribute[], multiLine?: boolean): ImportAttributes {
return node.elements !== elements
|| node.multiLine !== multiLine
? update(createImportAttributes(elements, multiLine, node.token), node)
: node;
}
// @api
function createImportAttribute(name: ImportAttributeName, value: Expression): ImportAttribute {
const node = createBaseNode<ImportAttribute>(SyntaxKind.ImportAttribute);
node.name = name;
node.value = value;
node.transformFlags |= TransformFlags.ContainsESNext;
return node;
}
// @api
function updateImportAttribute(node: ImportAttribute, name: ImportAttributeName, value: Expression): ImportAttribute {
return node.name !== name
|| node.value !== value
? update(createImportAttribute(name, value), node)
: node;
}
// @api
function createNamespaceImport(name: Identifier): NamespaceImport {
const node = createBaseDeclaration<NamespaceImport>(SyntaxKind.NamespaceImport);
@@ -4908,14 +4956,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
isTypeOnly: boolean,
exportClause: NamedExportBindings | undefined,
moduleSpecifier?: Expression,
assertClause?: AssertClause,
attributes?: ImportAttributes,
) {
const node = createBaseDeclaration<ExportDeclaration>(SyntaxKind.ExportDeclaration);
node.modifiers = asNodeArray(modifiers);
node.isTypeOnly = isTypeOnly;
node.exportClause = exportClause;
node.moduleSpecifier = moduleSpecifier;
node.assertClause = assertClause;
node.attributes = node.assertClause = attributes;
node.transformFlags |= propagateChildrenFlags(node.modifiers) |
propagateChildFlags(node.exportClause) |
propagateChildFlags(node.moduleSpecifier);
@@ -4932,14 +4980,14 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
isTypeOnly: boolean,
exportClause: NamedExportBindings | undefined,
moduleSpecifier: Expression | undefined,
assertClause: AssertClause | undefined,
attributes: ImportAttributes | undefined,
) {
return node.modifiers !== modifiers
|| node.isTypeOnly !== isTypeOnly
|| node.exportClause !== exportClause
|| node.moduleSpecifier !== moduleSpecifier
|| node.assertClause !== assertClause
? finishUpdateExportDeclaration(createExportDeclaration(modifiers, isTypeOnly, exportClause, moduleSpecifier, assertClause), node)
|| node.attributes !== attributes
? finishUpdateExportDeclaration(createExportDeclaration(modifiers, isTypeOnly, exportClause, moduleSpecifier, attributes), node)
: node;
}
@@ -7083,9 +7131,9 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
isEnumDeclaration(node) ? updateEnumDeclaration(node, modifierArray, node.name, node.members) :
isModuleDeclaration(node) ? updateModuleDeclaration(node, modifierArray, node.name, node.body) :
isImportEqualsDeclaration(node) ? updateImportEqualsDeclaration(node, modifierArray, node.isTypeOnly, node.name, node.moduleReference) :
isImportDeclaration(node) ? updateImportDeclaration(node, modifierArray, node.importClause, node.moduleSpecifier, node.assertClause) :
isImportDeclaration(node) ? updateImportDeclaration(node, modifierArray, node.importClause, node.moduleSpecifier, node.attributes) :
isExportAssignment(node) ? updateExportAssignment(node, modifierArray, node.expression) :
isExportDeclaration(node) ? updateExportDeclaration(node, modifierArray, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.assertClause) :
isExportDeclaration(node) ? updateExportDeclaration(node, modifierArray, node.isTypeOnly, node.exportClause, node.moduleSpecifier, node.attributes) :
Debug.assertNever(node);
}
+12
View File
@@ -67,6 +67,8 @@ import {
HeritageClause,
Identifier,
IfStatement,
ImportAttribute,
ImportAttributes,
ImportClause,
ImportDeclaration,
ImportEqualsDeclaration,
@@ -847,14 +849,24 @@ export function isImportTypeAssertionContainer(node: Node): node is ImportTypeAs
return node.kind === SyntaxKind.ImportTypeAssertionContainer;
}
/** @deprecated */
export function isAssertClause(node: Node): node is AssertClause {
return node.kind === SyntaxKind.AssertClause;
}
/** @deprecated */
export function isAssertEntry(node: Node): node is AssertEntry {
return node.kind === SyntaxKind.AssertEntry;
}
export function isImportAttributes(node: Node): node is ImportAttributes {
return node.kind === SyntaxKind.ImportAttributes;
}
export function isImportAttribute(node: Node): node is ImportAttribute {
return node.kind === SyntaxKind.ImportAttribute;
}
export function isNamespaceImport(node: Node): node is NamespaceImport {
return node.kind === SyntaxKind.NamespaceImport;
}
+1 -1
View File
@@ -754,7 +754,7 @@ export function createExternalHelpersImportDeclarationIfNeeded(nodeFactory: Node
/*modifiers*/ undefined,
nodeFactory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, namedBindings),
nodeFactory.createStringLiteral(externalHelpersModuleNameText),
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
addInternalEmitFlags(externalHelpersImportDeclaration, InternalEmitFlags.NeverApplyImportHelper);
return externalHelpersImportDeclaration;
+56 -58
View File
@@ -9,8 +9,6 @@ import {
ArrayTypeNode,
ArrowFunction,
AsExpression,
AssertClause,
AssertEntry,
AssertionLevel,
AsteriskToken,
attachFileToDiagnostics,
@@ -117,6 +115,8 @@ import {
Identifier,
idText,
IfStatement,
ImportAttribute,
ImportAttributes,
ImportClause,
ImportDeclaration,
ImportEqualsDeclaration,
@@ -689,7 +689,7 @@ const forEachChildTable: ForEachChildTable = {
},
[SyntaxKind.ImportType]: function forEachChildInImportType<T>(node: ImportTypeNode, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
return visitNode(cbNode, node.argument) ||
visitNode(cbNode, node.assertions) ||
visitNode(cbNode, node.attributes) ||
visitNode(cbNode, node.qualifier) ||
visitNodes(cbNode, cbNodes, node.typeArguments);
},
@@ -928,16 +928,16 @@ const forEachChildTable: ForEachChildTable = {
return visitNodes(cbNode, cbNodes, node.modifiers) ||
visitNode(cbNode, node.importClause) ||
visitNode(cbNode, node.moduleSpecifier) ||
visitNode(cbNode, node.assertClause);
visitNode(cbNode, node.attributes);
},
[SyntaxKind.ImportClause]: function forEachChildInImportClause<T>(node: ImportClause, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
return visitNode(cbNode, node.name) ||
visitNode(cbNode, node.namedBindings);
},
[SyntaxKind.AssertClause]: function forEachChildInAssertClause<T>(node: AssertClause, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
[SyntaxKind.ImportAttributes]: function forEachChildInImportAttributes<T>(node: ImportAttributes, cbNode: (node: Node) => T | undefined, cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
return visitNodes(cbNode, cbNodes, node.elements);
},
[SyntaxKind.AssertEntry]: function forEachChildInAssertEntry<T>(node: AssertEntry, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
[SyntaxKind.ImportAttribute]: function forEachChildInImportAttribute<T>(node: ImportAttribute, cbNode: (node: Node) => T | undefined, _cbNodes?: (nodes: NodeArray<Node>) => T | undefined): T | undefined {
return visitNode(cbNode, node.name) ||
visitNode(cbNode, node.value);
},
@@ -957,7 +957,7 @@ const forEachChildTable: ForEachChildTable = {
return visitNodes(cbNode, cbNodes, node.modifiers) ||
visitNode(cbNode, node.exportClause) ||
visitNode(cbNode, node.moduleSpecifier) ||
visitNode(cbNode, node.assertClause);
visitNode(cbNode, node.attributes);
},
[SyntaxKind.ImportSpecifier]: forEachChildInImportOrExportSpecifier,
[SyntaxKind.ExportSpecifier]: forEachChildInImportOrExportSpecifier,
@@ -2683,9 +2683,8 @@ namespace Parser {
token() === SyntaxKind.NumericLiteral;
}
function isAssertionKey(): boolean {
return tokenIsIdentifierOrKeyword(token()) ||
token() === SyntaxKind.StringLiteral;
function isImportAttributeName(): boolean {
return tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.StringLiteral;
}
function parsePropertyNameWorker(allowComputedPropertyNames: boolean): PropertyName {
@@ -2847,8 +2846,8 @@ namespace Parser {
return isLiteralPropertyName();
case ParsingContext.ObjectBindingElements:
return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.DotDotDotToken || isLiteralPropertyName();
case ParsingContext.AssertEntries:
return isAssertionKey();
case ParsingContext.ImportAttributes:
return isImportAttributeName();
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.
@@ -2979,7 +2978,7 @@ namespace Parser {
case ParsingContext.ObjectLiteralMembers:
case ParsingContext.ObjectBindingElements:
case ParsingContext.ImportOrExportSpecifiers:
case ParsingContext.AssertEntries:
case ParsingContext.ImportAttributes:
return token() === SyntaxKind.CloseBraceToken;
case ParsingContext.SwitchClauseStatements:
return token() === SyntaxKind.CloseBraceToken || token() === SyntaxKind.CaseKeyword || token() === SyntaxKind.DefaultKeyword;
@@ -3442,8 +3441,8 @@ namespace Parser {
return parseErrorAtCurrentToken(Diagnostics.Identifier_expected);
case ParsingContext.JsxChildren:
return parseErrorAtCurrentToken(Diagnostics.Identifier_expected);
case ParsingContext.AssertEntries:
return parseErrorAtCurrentToken(Diagnostics.Identifier_or_string_literal_expected); // AssertionKey.
case ParsingContext.ImportAttributes:
return parseErrorAtCurrentToken(Diagnostics.Identifier_or_string_literal_expected);
case ParsingContext.JSDocComment:
return parseErrorAtCurrentToken(Diagnostics.Identifier_expected);
case ParsingContext.Count:
@@ -4512,26 +4511,6 @@ namespace Parser {
return token() === SyntaxKind.ImportKeyword;
}
function parseImportTypeAssertions(): ImportTypeAssertionContainer {
const pos = getNodePos();
const openBracePosition = scanner.getTokenStart();
parseExpected(SyntaxKind.OpenBraceToken);
const multiLine = scanner.hasPrecedingLineBreak();
parseExpected(SyntaxKind.AssertKeyword);
parseExpected(SyntaxKind.ColonToken);
const clause = parseAssertClause(/*skipAssertKeyword*/ true);
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
const lastError = lastOrUndefined(parseDiagnostics);
if (lastError && lastError.code === Diagnostics._0_expected.code) {
addRelatedInfo(
lastError,
createDetachedDiagnostic(fileName, sourceText, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, "{", "}"),
);
}
}
return finishNode(factory.createImportTypeAssertionContainer(clause, multiLine), pos);
}
function parseImportType(): ImportTypeNode {
sourceFlags |= NodeFlags.PossiblyContainsDynamicImport;
const pos = getNodePos();
@@ -4539,14 +4518,33 @@ namespace Parser {
parseExpected(SyntaxKind.ImportKeyword);
parseExpected(SyntaxKind.OpenParenToken);
const type = parseType();
let assertions: ImportTypeAssertionContainer | undefined;
let attributes: ImportAttributes | undefined;
if (parseOptional(SyntaxKind.CommaToken)) {
assertions = parseImportTypeAssertions();
const openBracePosition = scanner.getTokenStart();
parseExpected(SyntaxKind.OpenBraceToken);
const currentToken = token();
if (currentToken === SyntaxKind.WithKeyword || currentToken === SyntaxKind.AssertKeyword) {
nextToken();
}
else {
parseErrorAtCurrentToken(Diagnostics._0_expected, tokenToString(SyntaxKind.WithKeyword));
}
parseExpected(SyntaxKind.ColonToken);
attributes = parseImportAttributes(currentToken as SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword, /*skipKeyword*/ true);
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
const lastError = lastOrUndefined(parseDiagnostics);
if (lastError && lastError.code === Diagnostics._0_expected.code) {
addRelatedInfo(
lastError,
createDetachedDiagnostic(fileName, sourceText, openBracePosition, 1, Diagnostics.The_parser_expected_to_find_a_1_to_match_the_0_token_here, "{", "}"),
);
}
}
}
parseExpected(SyntaxKind.CloseParenToken);
const qualifier = parseOptional(SyntaxKind.DotToken) ? parseEntityNameOfTypeReference() : undefined;
const typeArguments = parseTypeArgumentsOfTypeReference();
return finishNode(factory.createImportTypeNode(type, assertions, qualifier, typeArguments, isTypeOf), pos);
return finishNode(factory.createImportTypeNode(type, attributes, qualifier, typeArguments, isTypeOf), pos);
}
function nextTokenIsNumericOrBigIntLiteral() {
@@ -8358,34 +8356,33 @@ namespace Parser {
parseExpected(SyntaxKind.FromKeyword);
}
const moduleSpecifier = parseModuleSpecifier();
let assertClause: AssertClause | undefined;
if (token() === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak()) {
assertClause = parseAssertClause();
const currentToken = token();
let attributes: ImportAttributes | undefined;
if ((currentToken === SyntaxKind.WithKeyword || currentToken === SyntaxKind.AssertKeyword) && !scanner.hasPrecedingLineBreak()) {
attributes = parseImportAttributes(currentToken);
}
parseSemicolon();
const node = factory.createImportDeclaration(modifiers, importClause, moduleSpecifier, assertClause);
const node = factory.createImportDeclaration(modifiers, importClause, moduleSpecifier, attributes);
return withJSDoc(finishNode(node, pos), hasJSDoc);
}
function parseAssertEntry() {
function parseImportAttribute() {
const pos = getNodePos();
const name = tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral;
parseExpected(SyntaxKind.ColonToken);
const value = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
return finishNode(factory.createAssertEntry(name, value), pos);
return finishNode(factory.createImportAttribute(name, value), pos);
}
function parseAssertClause(skipAssertKeyword?: true) {
function parseImportAttributes(token: SyntaxKind.AssertKeyword | SyntaxKind.WithKeyword, skipKeyword?: true) {
const pos = getNodePos();
if (!skipAssertKeyword) {
parseExpected(SyntaxKind.AssertKeyword);
if (!skipKeyword) {
parseExpected(token);
}
const openBracePosition = scanner.getTokenStart();
if (parseExpected(SyntaxKind.OpenBraceToken)) {
const multiLine = scanner.hasPrecedingLineBreak();
const elements = parseDelimitedList(ParsingContext.AssertEntries, parseAssertEntry, /*considerSemicolonAsDelimiter*/ true);
const elements = parseDelimitedList(ParsingContext.ImportAttributes, parseImportAttribute, /*considerSemicolonAsDelimiter*/ true);
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
const lastError = lastOrUndefined(parseDiagnostics);
if (lastError && lastError.code === Diagnostics._0_expected.code) {
@@ -8395,11 +8392,11 @@ namespace Parser {
);
}
}
return finishNode(factory.createAssertClause(elements, multiLine), pos);
return finishNode(factory.createImportAttributes(elements, multiLine, token), pos);
}
else {
const elements = createNodeArray([], getNodePos(), /*end*/ undefined, /*hasTrailingComma*/ false);
return finishNode(factory.createAssertClause(elements, /*multiLine*/ false), pos);
return finishNode(factory.createImportAttributes(elements, /*multiLine*/ false, token), pos);
}
}
@@ -8602,7 +8599,7 @@ namespace Parser {
setAwaitContext(/*value*/ true);
let exportClause: NamedExportBindings | undefined;
let moduleSpecifier: Expression | undefined;
let assertClause: AssertClause | undefined;
let attributes: ImportAttributes | undefined;
const isTypeOnly = parseOptional(SyntaxKind.TypeKeyword);
const namespaceExportPos = getNodePos();
if (parseOptional(SyntaxKind.AsteriskToken)) {
@@ -8622,12 +8619,13 @@ namespace Parser {
moduleSpecifier = parseModuleSpecifier();
}
}
if (moduleSpecifier && token() === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak()) {
assertClause = parseAssertClause();
const currentToken = token();
if (moduleSpecifier && (currentToken === SyntaxKind.WithKeyword || currentToken === SyntaxKind.AssertKeyword) && !scanner.hasPrecedingLineBreak()) {
attributes = parseImportAttributes(currentToken);
}
parseSemicolon();
setAwaitContext(savedAwaitContext);
const node = factory.createExportDeclaration(modifiers, isTypeOnly, exportClause, moduleSpecifier, assertClause);
const node = factory.createExportDeclaration(modifiers, isTypeOnly, exportClause, moduleSpecifier, attributes);
return withJSDoc(finishNode(node, pos), hasJSDoc);
}
@@ -8674,9 +8672,9 @@ namespace Parser {
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,
AssertEntries, // Import entries list.
ImportAttributes, // Import attributes
JSDocComment, // Parsing via JSDocParser
Count, // Number of parsing contexts
Count, // Number of parsing contexts
}
const enum Tristate {
+21 -10
View File
@@ -167,6 +167,7 @@ import {
HeritageClause,
Identifier,
identity,
ImportAttributes,
ImportClause,
ImportDeclaration,
ImportOrExportSpecifier,
@@ -895,14 +896,14 @@ export function getModeForUsageLocation(file: { impliedNodeFormat?: ResolutionMo
if ((isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent))) {
const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent);
if (isTypeOnly) {
const override = getResolutionModeOverrideForClause(usage.parent.assertClause);
const override = getResolutionModeOverride(usage.parent.attributes);
if (override) {
return override;
}
}
}
if (usage.parent.parent && isImportTypeNode(usage.parent.parent)) {
const override = getResolutionModeOverrideForClause(usage.parent.parent.assertions?.assertClause);
const override = getResolutionModeOverride(usage.parent.parent.attributes);
if (override) {
return override;
}
@@ -918,16 +919,26 @@ export function getModeForUsageLocation(file: { impliedNodeFormat?: ResolutionMo
}
/** @internal */
export function getResolutionModeOverrideForClause(clause: AssertClause | undefined, grammarErrorOnNode?: (node: Node, diagnostic: DiagnosticMessage) => void) {
if (!clause) return undefined;
if (length(clause.elements) !== 1) {
grammarErrorOnNode?.(clause, Diagnostics.Type_import_assertions_should_have_exactly_one_key_resolution_mode_with_value_import_or_require);
export function getResolutionModeOverride(node: AssertClause | ImportAttributes | undefined, grammarErrorOnNode?: (node: Node, diagnostic: DiagnosticMessage) => void) {
if (!node) return undefined;
if (length(node.elements) !== 1) {
grammarErrorOnNode?.(
node,
node.token === SyntaxKind.WithKeyword
? Diagnostics.Type_import_attributes_should_have_exactly_one_key_resolution_mode_with_value_import_or_require
: Diagnostics.Type_import_assertions_should_have_exactly_one_key_resolution_mode_with_value_import_or_require,
);
return undefined;
}
const elem = clause.elements[0];
const elem = node.elements[0];
if (!isStringLiteralLike(elem.name)) return undefined;
if (elem.name.text !== "resolution-mode") {
grammarErrorOnNode?.(elem.name, Diagnostics.resolution_mode_is_the_only_valid_key_for_type_import_assertions);
grammarErrorOnNode?.(
elem.name,
node.token === SyntaxKind.WithKeyword
? Diagnostics.resolution_mode_is_the_only_valid_key_for_type_import_attributes
: Diagnostics.resolution_mode_is_the_only_valid_key_for_type_import_assertions,
);
return undefined;
}
if (!isStringLiteralLike(elem.value)) return undefined;
@@ -1393,7 +1404,7 @@ export const plainJSErrors = new Set<number>([
Diagnostics.Classes_may_not_have_a_field_named_constructor.code,
Diagnostics.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern.code,
Diagnostics.Duplicate_label_0.code,
Diagnostics.Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_assertion_as_arguments.code,
Diagnostics.Dynamic_imports_can_only_accept_a_module_specifier_and_an_optional_set_of_attributes_as_arguments.code,
Diagnostics.for_await_loops_cannot_be_used_inside_a_class_static_block.code,
Diagnostics.JSX_attributes_must_only_be_assigned_a_non_empty_expression.code,
Diagnostics.JSX_elements_cannot_have_multiple_attributes_with_the_same_name.code,
@@ -3294,7 +3305,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
function createSyntheticImport(text: string, file: SourceFile) {
const externalHelpersModuleReference = factory.createStringLiteral(text);
const importDecl = factory.createImportDeclaration(/*modifiers*/ undefined, /*importClause*/ undefined, externalHelpersModuleReference, /*assertClause*/ undefined);
const importDecl = factory.createImportDeclaration(/*modifiers*/ undefined, /*importClause*/ undefined, externalHelpersModuleReference, /*attributes*/ undefined);
addInternalEmitFlags(importDecl, InternalEmitFlags.NeverApplyImportHelper);
setParent(externalHelpersModuleReference, importDecl);
setParent(importDecl, file);
+12 -26
View File
@@ -6,7 +6,6 @@ import {
append,
ArrayBindingElement,
arrayFrom,
AssertClause,
BindingElement,
BindingName,
BindingPattern,
@@ -70,7 +69,7 @@ import {
getOutputPathsFor,
getParseTreeNode,
getRelativePathToDirectoryOrUrl,
getResolutionModeOverrideForClause,
getResolutionModeOverride,
getResolvedExternalModuleName,
getSetAccessorValueParameter,
getSourceFileOfNode,
@@ -86,6 +85,7 @@ import {
hasSyntacticModifier,
HeritageClause,
Identifier,
ImportAttributes,
ImportDeclaration,
ImportEqualsDeclaration,
ImportTypeNode,
@@ -130,7 +130,6 @@ import {
isMethodSignature,
isModifier,
isModuleDeclaration,
isNightly,
isOmittedExpression,
isPrivateIdentifier,
isPropertySignature,
@@ -312,7 +311,6 @@ export function transformDeclarations(context: TransformationContext) {
trackExternalModuleSymbolOfImportTypeNode,
reportNonlocalAugmentation,
reportNonSerializableProperty,
reportImportTypeNodeResolutionModeOverride,
};
let errorNameNode: DeclarationName | undefined;
let errorFallbackNode: Declaration | undefined;
@@ -456,12 +454,6 @@ export function transformDeclarations(context: TransformationContext) {
}
}
function reportImportTypeNodeResolutionModeOverride() {
if (!isNightly() && (errorNameNode || errorFallbackNode)) {
context.addDiagnostic(createDiagnosticForNode((errorNameNode || errorFallbackNode)!, Diagnostics.The_type_of_this_expression_cannot_be_named_without_a_resolution_mode_assertion_which_is_an_unstable_feature_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next));
}
}
function transformDeclarationsForJS(sourceFile: SourceFile, bundled?: boolean) {
const oldDiag = getSymbolAccessibilityDiagnostic;
getSymbolAccessibilityDiagnostic = s => (s.errorNode && canProduceDiagnostics(s.errorNode) ? createGetSymbolAccessibilityDiagnosticForNode(s.errorNode)(s) : ({
@@ -985,7 +977,7 @@ export function transformDeclarations(context: TransformationContext) {
decl.modifiers,
decl.importClause,
rewriteModuleSpecifier(decl, decl.moduleSpecifier),
getResolutionModeOverrideForClauseInNightly(decl.assertClause),
tryGetResolutionModeOverride(decl.attributes),
);
}
// The `importClause` visibility corresponds to the default's visibility.
@@ -1002,7 +994,7 @@ export function transformDeclarations(context: TransformationContext) {
/*namedBindings*/ undefined,
),
rewriteModuleSpecifier(decl, decl.moduleSpecifier),
getResolutionModeOverrideForClauseInNightly(decl.assertClause),
tryGetResolutionModeOverride(decl.attributes),
);
}
if (decl.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) {
@@ -1018,7 +1010,7 @@ export function transformDeclarations(context: TransformationContext) {
namedBindings,
),
rewriteModuleSpecifier(decl, decl.moduleSpecifier),
getResolutionModeOverrideForClauseInNightly(decl.assertClause),
tryGetResolutionModeOverride(decl.attributes),
) : undefined;
}
// Named imports (optionally with visible default)
@@ -1034,7 +1026,7 @@ export function transformDeclarations(context: TransformationContext) {
bindingList && bindingList.length ? factory.updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined,
),
rewriteModuleSpecifier(decl, decl.moduleSpecifier),
getResolutionModeOverrideForClauseInNightly(decl.assertClause),
tryGetResolutionModeOverride(decl.attributes),
);
}
// Augmentation of export depends on import
@@ -1044,21 +1036,15 @@ export function transformDeclarations(context: TransformationContext) {
decl.modifiers,
/*importClause*/ undefined,
rewriteModuleSpecifier(decl, decl.moduleSpecifier),
getResolutionModeOverrideForClauseInNightly(decl.assertClause),
tryGetResolutionModeOverride(decl.attributes),
);
}
// Nothing visible
}
function getResolutionModeOverrideForClauseInNightly(assertClause: AssertClause | undefined) {
const mode = getResolutionModeOverrideForClause(assertClause);
if (mode !== undefined) {
if (!isNightly()) {
context.addDiagnostic(createDiagnosticForNode(assertClause!, Diagnostics.resolution_mode_assertions_are_unstable_Use_nightly_TypeScript_to_silence_this_error_Try_updating_with_npm_install_D_typescript_next));
}
return assertClause;
}
return undefined;
function tryGetResolutionModeOverride(node: ImportAttributes | undefined) {
const mode = getResolutionModeOverride(node);
return node && mode !== undefined ? node : undefined;
}
function transformAndReplaceLatePaintedStatements(statements: NodeArray<Statement>): NodeArray<Statement> {
@@ -1329,7 +1315,7 @@ export function transformDeclarations(context: TransformationContext) {
return cleanup(factory.updateImportTypeNode(
input,
factory.updateLiteralTypeNode(input.argument, rewriteModuleSpecifier(input, input.argument.literal)),
input.assertions,
input.attributes,
input.qualifier,
visitNodes(input.typeArguments, visitDeclarationSubtree, isTypeNode),
input.isTypeOf,
@@ -1391,7 +1377,7 @@ export function transformDeclarations(context: TransformationContext) {
input.isTypeOnly,
input.exportClause,
rewriteModuleSpecifier(input, input.moduleSpecifier),
getResolutionModeOverrideForClause(input.assertClause) ? input.assertClause : undefined,
tryGetResolutionModeOverride(input.attributes),
);
}
case SyntaxKind.ExportAssignment: {
+1 -1
View File
@@ -170,7 +170,7 @@ export function transformJsx(context: TransformationContext): (x: SourceFile | B
for (const [importSource, importSpecifiersMap] of arrayFrom(currentFileState.utilizedImplicitRuntimeImports.entries())) {
if (isExternalModule(node)) {
// Add `import` statement
const importStatement = factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamedImports(arrayFrom(importSpecifiersMap.values()))), factory.createStringLiteral(importSource), /*assertClause*/ undefined);
const importStatement = factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamedImports(arrayFrom(importSpecifiersMap.values()))), factory.createStringLiteral(importSource), /*attributes*/ undefined);
setParentRecursive(importStatement, /*incremental*/ false);
statements = insertStatementAfterCustomPrologue(statements.slice(), importStatement);
}
@@ -159,6 +159,7 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S
]),
),
factory.createStringLiteral("module"),
/*attributes*/ undefined,
);
const requireHelperName = factory.createUniqueName("__require", GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.FileLevel);
const requireStatement = factory.createVariableStatement(
@@ -265,7 +266,7 @@ export function transformECMAScriptModule(context: TransformationContext): (x: S
),
),
node.moduleSpecifier,
node.assertClause,
node.attributes,
);
setOriginalNode(importDecl, node.exportClause);
+3 -3
View File
@@ -2227,7 +2227,7 @@ export function transformTypeScript(context: TransformationContext) {
/*modifiers*/ undefined,
importClause,
node.moduleSpecifier,
node.assertClause,
node.attributes,
)
: undefined;
}
@@ -2323,7 +2323,7 @@ export function transformTypeScript(context: TransformationContext) {
node.isTypeOnly,
exportClause,
node.moduleSpecifier,
node.assertClause,
node.attributes,
)
: undefined;
}
@@ -2393,7 +2393,7 @@ export function transformTypeScript(context: TransformationContext) {
/*modifiers*/ undefined,
/*importClause*/ undefined,
node.moduleReference.expression,
/*assertClause*/ undefined,
/*attributes*/ undefined,
),
node,
),
+53 -29
View File
@@ -375,9 +375,12 @@ export const enum SyntaxKind {
DefaultClause,
HeritageClause,
CatchClause,
AssertClause,
AssertEntry,
ImportTypeAssertionContainer,
ImportAttributes,
ImportAttribute,
/** @deprecated */ AssertClause = ImportAttributes,
/** @deprecated */ AssertEntry = ImportAttribute,
/** @deprecated */ ImportTypeAssertionContainer,
// Property assignments
PropertyAssignment,
@@ -1128,6 +1131,8 @@ export type HasChildren =
| ImportDeclaration
| AssertClause
| AssertEntry
| ImportAttributes
| ImportAttribute
| ImportClause
| NamespaceImport
| NamespaceExport
@@ -2140,10 +2145,11 @@ export interface KeywordTypeNode<TKind extends KeywordTypeSyntaxKind = KeywordTy
readonly kind: TKind;
}
/** @deprecated */
export interface ImportTypeAssertionContainer extends Node {
readonly kind: SyntaxKind.ImportTypeAssertionContainer;
readonly parent: ImportTypeNode;
readonly assertClause: AssertClause;
/** @deprecated */ readonly assertClause: AssertClause;
readonly multiLine?: boolean;
}
@@ -2151,7 +2157,8 @@ export interface ImportTypeNode extends NodeWithTypeArguments {
readonly kind: SyntaxKind.ImportType;
readonly isTypeOf: boolean;
readonly argument: TypeNode;
readonly assertions?: ImportTypeAssertionContainer;
/** @deprecated */ readonly assertions?: ImportTypeAssertionContainer;
readonly attributes?: ImportAttributes;
readonly qualifier?: EntityName;
}
@@ -3601,7 +3608,8 @@ export interface ImportDeclaration extends Statement {
readonly importClause?: ImportClause;
/** If this is not a StringLiteral it will be a grammar error. */
readonly moduleSpecifier: Expression;
readonly assertClause?: AssertClause;
/** @deprecated */ readonly assertClause?: AssertClause;
readonly attributes?: ImportAttributes;
}
export type NamedImportBindings =
@@ -3626,19 +3634,29 @@ export interface ImportClause extends NamedDeclaration {
readonly namedBindings?: NamedImportBindings;
}
export type AssertionKey = Identifier | StringLiteral;
/** @deprecated */
export type AssertionKey = ImportAttributeName;
export interface AssertEntry extends Node {
readonly kind: SyntaxKind.AssertEntry;
readonly parent: AssertClause;
readonly name: AssertionKey;
/** @deprecated */
export type AssertEntry = ImportAttribute;
/** @deprecated */
export type AssertClause = ImportAttributes;
export type ImportAttributeName = Identifier | StringLiteral;
export interface ImportAttribute extends Node {
readonly kind: SyntaxKind.ImportAttribute;
readonly parent: ImportAttributes;
readonly name: ImportAttributeName;
readonly value: Expression;
}
export interface AssertClause extends Node {
readonly kind: SyntaxKind.AssertClause;
export interface ImportAttributes extends Node {
readonly token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword;
readonly kind: SyntaxKind.ImportAttributes;
readonly parent: ImportDeclaration | ExportDeclaration;
readonly elements: NodeArray<AssertEntry>;
readonly elements: NodeArray<ImportAttribute>;
readonly multiLine?: boolean;
}
@@ -3671,7 +3689,8 @@ export interface ExportDeclaration extends DeclarationStatement, JSDocContainer
readonly exportClause?: NamedExportBindings;
/** If this is not a StringLiteral it will be a grammar error. */
readonly moduleSpecifier?: Expression;
readonly assertClause?: AssertClause;
/** @deprecated */ readonly assertClause?: AssertClause;
readonly attributes?: ImportAttributes;
}
export interface NamedImports extends Node {
@@ -8418,8 +8437,8 @@ export interface NodeFactory {
updateConditionalTypeNode(node: ConditionalTypeNode, checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode;
createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode;
updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode;
createImportTypeNode(argument: TypeNode, assertions?: ImportTypeAssertionContainer, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode;
updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, assertions: ImportTypeAssertionContainer | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode;
createImportTypeNode(argument: TypeNode, attributes?: ImportAttributes, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode;
updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, attributes: ImportAttributes | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode;
createParenthesizedType(type: TypeNode): ParenthesizedTypeNode;
updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode;
createThisTypeNode(): ThisTypeNode;
@@ -8599,16 +8618,21 @@ export interface NodeFactory {
updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration;
createImportEqualsDeclaration(modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration;
updateImportEqualsDeclaration(node: ImportEqualsDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration;
createImportDeclaration(modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause): ImportDeclaration;
updateImportDeclaration(node: ImportDeclaration, modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration;
createImportDeclaration(modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes?: ImportAttributes): ImportDeclaration;
updateImportDeclaration(node: ImportDeclaration, modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes: ImportAttributes | undefined): ImportDeclaration;
createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause;
updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause;
createAssertClause(elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
updateAssertClause(node: AssertClause, elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
createAssertEntry(name: AssertionKey, value: Expression): AssertEntry;
updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression): AssertEntry;
createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer;
updateImportTypeAssertionContainer(node: ImportTypeAssertionContainer, clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer;
/** @deprecated */ createAssertClause(elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
/** @deprecated */ updateAssertClause(node: AssertClause, elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
/** @deprecated */ createAssertEntry(name: AssertionKey, value: Expression): AssertEntry;
/** @deprecated */ updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression): AssertEntry;
/** @deprecated */ createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer;
/** @deprecated */ updateImportTypeAssertionContainer(node: ImportTypeAssertionContainer, clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer;
createImportAttributes(elements: NodeArray<ImportAttribute>, multiLine?: boolean): ImportAttributes;
/** @internal */ createImportAttributes(elements: NodeArray<ImportAttribute>, multiLine?: boolean, token?: ImportAttributes["token"]): ImportAttributes;
updateImportAttributes(node: ImportAttributes, elements: NodeArray<ImportAttribute>, multiLine?: boolean): ImportAttributes;
createImportAttribute(name: ImportAttributeName, value: Expression): ImportAttribute;
updateImportAttribute(node: ImportAttribute, name: ImportAttributeName, value: Expression): ImportAttribute;
createNamespaceImport(name: Identifier): NamespaceImport;
updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport;
createNamespaceExport(name: Identifier): NamespaceExport;
@@ -8619,8 +8643,8 @@ export interface NodeFactory {
updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
createExportAssignment(modifiers: readonly ModifierLike[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment;
updateExportAssignment(node: ExportAssignment, modifiers: readonly ModifierLike[] | undefined, expression: Expression): ExportAssignment;
createExportDeclaration(modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, assertClause?: AssertClause): ExportDeclaration;
updateExportDeclaration(node: ExportDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause: AssertClause | undefined): ExportDeclaration;
createExportDeclaration(modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, attributes?: ImportAttributes): ExportDeclaration;
updateExportDeclaration(node: ExportDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, attributes: ImportAttributes | undefined): ExportDeclaration;
createNamedExports(elements: readonly ExportSpecifier[]): NamedExports;
updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports;
createExportSpecifier(isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier;
@@ -9657,7 +9681,6 @@ export interface SymbolTracker {
trackExternalModuleSymbolOfImportTypeNode?(symbol: Symbol): void;
reportNonlocalAugmentation?(containingFile: SourceFile, parentSymbol: Symbol, augmentingSymbol: Symbol): void;
reportNonSerializableProperty?(propertyName: string): void;
reportImportTypeNodeResolutionModeOverride?(): void;
}
export interface TextSpan {
@@ -9750,7 +9773,8 @@ export const enum ListFormat {
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,
ImportAttributes = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces | NoSpaceIfEmpty,
/** @deprecated */ ImportClauseEntries = ImportAttributes,
ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets,
CommaListElements = CommaDelimited | SpaceBetweenSiblings | SingleLine,
CallExpressionArguments = CommaDelimited | SpaceBetweenSiblings | SingleLine | Parenthesis,
+9 -6
View File
@@ -194,6 +194,7 @@ import {
getPathComponents,
getPathFromPathComponents,
getRelativePathToDirectoryOrUrl,
getResolutionModeOverride,
getRootLength,
getSnippetElement,
getStringComparer,
@@ -553,7 +554,6 @@ import {
VariableDeclarationList,
VariableLikeDeclaration,
VariableStatement,
version,
WhileStatement,
WithStatement,
WrappedExpression,
@@ -5975,11 +5975,6 @@ export function getIndentSize() {
return indentStrings[1].length;
}
/** @internal */
export function isNightly() {
return version.includes("-dev") || version.includes("-insiders");
}
/** @internal */
export function createTextWriter(newLine: string): EmitTextWriter {
// Why var? It avoids TDZ checks in the runtime which can be costly.
@@ -10446,3 +10441,11 @@ export function getPropertyNameFromType(type: StringLiteralType | NumberLiteralT
export function isExpandoPropertyDeclaration(declaration: Declaration | undefined): declaration is PropertyAccessExpression | ElementAccessExpression | BinaryExpression {
return !!declaration && (isPropertyAccessExpression(declaration) || isElementAccessExpression(declaration) || isBinaryExpression(declaration));
}
/** @internal */
export function hasResolutionModeOverride(node: ImportTypeNode | ImportDeclaration | ExportDeclaration | undefined) {
if (node === undefined) {
return false;
}
return !!getResolutionModeOverride(node.attributes);
}
+5 -5
View File
@@ -6,7 +6,6 @@ import {
ArrayBindingOrAssignmentElement,
ArrayBindingOrAssignmentPattern,
AssertionExpression,
AssertionKey,
AssignmentDeclarationKind,
AssignmentPattern,
AutoAccessorPropertyDeclaration,
@@ -92,6 +91,7 @@ import {
hasSyntacticModifier,
HasType,
Identifier,
ImportAttributeName,
ImportClause,
ImportEqualsDeclaration,
ImportSpecifier,
@@ -1518,14 +1518,14 @@ export function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnl
return isTypeOnlyImportDeclaration(node) || isTypeOnlyExportDeclaration(node);
}
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);
}
export function isImportAttributeName(node: Node): node is ImportAttributeName {
return isStringLiteral(node) || isIdentifier(node);
}
// Identifiers
/** @internal */
+12 -12
View File
@@ -12,8 +12,6 @@ import {
isArray,
isArrayBindingElement,
isAssertClause,
isAssertEntry,
isAssertionKey,
isAssertsKeyword,
isAsteriskToken,
isAwaitKeyword,
@@ -42,9 +40,11 @@ import {
isHeritageClause,
isIdentifier,
isIdentifierOrThisTypeNode,
isImportAttribute,
isImportAttributeName,
isImportAttributes,
isImportClause,
isImportSpecifier,
isImportTypeAssertionContainer,
isJsxAttributeLike,
isJsxAttributeName,
isJsxAttributes,
@@ -894,7 +894,7 @@ const visitEachChildTable: VisitEachChildTable = {
return context.factory.updateImportTypeNode(
node,
Debug.checkDefined(nodeVisitor(node.argument, visitor, isTypeNode)),
nodeVisitor(node.assertions, visitor, isImportTypeAssertionContainer),
nodeVisitor(node.attributes, visitor, isImportAttributes),
nodeVisitor(node.qualifier, visitor, isEntityName),
nodesVisitor(node.typeArguments, visitor, isTypeNode),
node.isTypeOf,
@@ -1524,22 +1524,22 @@ const visitEachChildTable: VisitEachChildTable = {
nodesVisitor(node.modifiers, visitor, isModifierLike),
nodeVisitor(node.importClause, visitor, isImportClause),
Debug.checkDefined(nodeVisitor(node.moduleSpecifier, visitor, isExpression)),
nodeVisitor(node.assertClause, visitor, isAssertClause),
nodeVisitor(node.attributes, visitor, isImportAttributes),
);
},
[SyntaxKind.AssertClause]: function visitEachChildOfAssertClause(node, visitor, context, nodesVisitor, _nodeVisitor, _tokenVisitor) {
return context.factory.updateAssertClause(
[SyntaxKind.ImportAttributes]: function visitEachChildOfImportAttributes(node, visitor, context, nodesVisitor, _nodeVisitor, _tokenVisitor) {
return context.factory.updateImportAttributes(
node,
nodesVisitor(node.elements, visitor, isAssertEntry),
nodesVisitor(node.elements, visitor, isImportAttribute),
node.multiLine,
);
},
[SyntaxKind.AssertEntry]: function visitEachChildOfAssertEntry(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) {
return context.factory.updateAssertEntry(
[SyntaxKind.ImportAttribute]: function visitEachChildOfImportAttribute(node, visitor, context, _nodesVisitor, nodeVisitor, _tokenVisitor) {
return context.factory.updateImportAttribute(
node,
Debug.checkDefined(nodeVisitor(node.name, visitor, isAssertionKey)),
Debug.checkDefined(nodeVisitor(node.name, visitor, isImportAttributeName)),
Debug.checkDefined(nodeVisitor(node.value, visitor, isExpression)),
);
},
@@ -1598,7 +1598,7 @@ const visitEachChildTable: VisitEachChildTable = {
node.isTypeOnly,
nodeVisitor(node.exportClause, visitor, isNamedExportBindings),
nodeVisitor(node.moduleSpecifier, visitor, isExpression),
nodeVisitor(node.assertClause, visitor, isAssertClause),
nodeVisitor(node.attributes, visitor, isImportAttributes),
);
},
+1
View File
@@ -1133,6 +1133,7 @@ export namespace Completion {
interfaceEntry("ImportMeta"),
interfaceEntry("ImportCallOptions"),
interfaceEntry("ImportAssertions"),
interfaceEntry("ImportAttributes"),
varEntry("Math"),
varEntry("Date"),
interfaceEntry("DateConstructor"),
+9 -1
View File
@@ -620,7 +620,8 @@ interface ImportMeta {
* augmented via interface merging.
*/
interface ImportCallOptions {
assert?: ImportAssertions;
/** @deprecated*/ assert?: ImportAssertions;
with?: ImportAttributes;
}
/**
@@ -630,6 +631,13 @@ interface ImportAssertions {
[key: string]: string;
}
/**
* The type for the `with` property of the optional second argument to `import()`.
*/
interface ImportAttributes {
[key: string]: string;
}
interface Math {
/** The mathematical constant e. This is Euler's number, the base of natural logarithms. */
readonly E: number;
@@ -68,14 +68,14 @@ function fixSingleExportDeclaration(changes: textChanges.ChangeTracker, exportSp
/*isTypeOnly*/ false,
factory.updateNamedExports(exportClause, filter(exportClause.elements, e => !contains(typeExportSpecifiers, e))),
exportDeclaration.moduleSpecifier,
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
const typeExportDeclaration = factory.createExportDeclaration(
/*modifiers*/ undefined,
/*isTypeOnly*/ true,
factory.createNamedExports(typeExportSpecifiers),
exportDeclaration.moduleSpecifier,
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
changes.replaceNode(context.sourceFile, exportDeclaration, valueExportDeclaration, {
@@ -125,13 +125,13 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, de
getSynthesizedDeepClones(declaration.modifiers, /*includeTrivia*/ true),
factory.createImportClause(/*isTypeOnly*/ true, getSynthesizedDeepClone(importClause.name, /*includeTrivia*/ true), /*namedBindings*/ undefined),
getSynthesizedDeepClone(declaration.moduleSpecifier, /*includeTrivia*/ true),
getSynthesizedDeepClone(declaration.assertClause, /*includeTrivia*/ true),
getSynthesizedDeepClone(declaration.attributes, /*includeTrivia*/ true),
),
factory.createImportDeclaration(
getSynthesizedDeepClones(declaration.modifiers, /*includeTrivia*/ true),
factory.createImportClause(/*isTypeOnly*/ true, /*name*/ undefined, getSynthesizedDeepClone(importClause.namedBindings, /*includeTrivia*/ true)),
getSynthesizedDeepClone(declaration.moduleSpecifier, /*includeTrivia*/ true),
getSynthesizedDeepClone(declaration.assertClause, /*includeTrivia*/ true),
getSynthesizedDeepClone(declaration.attributes, /*includeTrivia*/ true),
),
]);
}
@@ -142,7 +142,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, de
sameMap(importClause.namedBindings.elements, e => factory.updateImportSpecifier(e, /*isTypeOnly*/ false, e.propertyName, e.name)),
)
: importClause.namedBindings;
const importDeclaration = factory.updateImportDeclaration(declaration, declaration.modifiers, factory.updateImportClause(importClause, /*isTypeOnly*/ true, importClause.name, newNamedBindings), declaration.moduleSpecifier, declaration.assertClause);
const importDeclaration = factory.updateImportDeclaration(declaration, declaration.modifiers, factory.updateImportClause(importClause, /*isTypeOnly*/ true, importClause.name, newNamedBindings), declaration.moduleSpecifier, declaration.attributes);
changes.replaceNode(sourceFile, declaration, importDeclaration);
}
}
@@ -38,6 +38,6 @@ function getImportTypeNode(sourceFile: SourceFile, pos: number): ImportTypeNode
}
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, importType: ImportTypeNode) {
const newTypeNode = factory.updateImportTypeNode(importType, importType.argument, importType.assertions, importType.qualifier, importType.typeArguments, /*isTypeOf*/ true);
const newTypeNode = factory.updateImportTypeNode(importType, importType.argument, importType.attributes, importType.qualifier, importType.typeArguments, /*isTypeOf*/ true);
changes.replaceNode(sourceFile, importType, newTypeNode);
}
@@ -184,13 +184,13 @@ function updateExport(changes: textChanges.ChangeTracker, program: Program, sour
factory.createNodeArray([...namedExports, ...createExportSpecifiers(names, allowTypeModifier)], /*hasTrailingComma*/ namedExports.hasTrailingComma),
),
node.moduleSpecifier,
node.assertClause,
node.attributes,
),
);
}
function createExport(changes: textChanges.ChangeTracker, program: Program, sourceFile: SourceFile, names: ExportName[]) {
changes.insertNodeAtEndOfScope(sourceFile, sourceFile, factory.createExportDeclaration(/*modifiers*/ undefined, /*isTypeOnly*/ false, factory.createNamedExports(createExportSpecifiers(names, /*allowTypeModifier*/ getIsolatedModules(program.getCompilerOptions()))), /*moduleSpecifier*/ undefined, /*assertClause*/ undefined));
changes.insertNodeAtEndOfScope(sourceFile, sourceFile, factory.createExportDeclaration(/*modifiers*/ undefined, /*isTypeOnly*/ false, factory.createNamedExports(createExportSpecifiers(names, /*allowTypeModifier*/ getIsolatedModules(program.getCompilerOptions()))), /*moduleSpecifier*/ undefined, /*attributes*/ undefined));
}
function createExportSpecifiers(names: ExportName[], allowTypeModifier: boolean) {
+1 -1
View File
@@ -1655,7 +1655,7 @@ function getNewImports(
factory.createNamespaceImport(factory.createIdentifier(namespaceLikeImport.name)),
),
quotedModuleSpecifier,
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
statements = combine(statements, declaration);
}
+1 -1
View File
@@ -57,7 +57,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, in
statement,
defaultImportName && !allowSyntheticDefaults
? factory.createImportEqualsDeclaration(/*modifiers*/ undefined, /*isTypeOnly*/ false, defaultImportName, factory.createExternalModuleReference(required))
: factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports), required, /*assertClause*/ undefined),
: factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports), required, /*attributes*/ undefined),
);
}
@@ -53,7 +53,7 @@ function splitTypeOnlyImport(changes: textChanges.ChangeTracker, importDeclarati
importDeclaration.modifiers,
factory.updateImportClause(importClause, importClause.isTypeOnly, importClause.name, /*namedBindings*/ undefined),
importDeclaration.moduleSpecifier,
importDeclaration.assertClause,
importDeclaration.attributes,
),
);
@@ -64,7 +64,7 @@ function splitTypeOnlyImport(changes: textChanges.ChangeTracker, importDeclarati
/*modifiers*/ undefined,
factory.updateImportClause(importClause, importClause.isTypeOnly, /*name*/ undefined, importClause.namedBindings),
importDeclaration.moduleSpecifier,
importDeclaration.assertClause,
importDeclaration.attributes,
),
);
}
+3 -3
View File
@@ -269,7 +269,7 @@ function removeUnusedImports(oldImports: readonly ImportDeclaration[], sourceFil
importDecl.modifiers,
/*importClause*/ undefined,
moduleSpecifier,
/*assertClause*/ undefined,
/*attributes*/ undefined,
));
}
// If we're not in a declaration file, we can't remove the import clause even though
@@ -530,7 +530,7 @@ function coalesceExportsWorker(exportGroup: readonly ExportDeclaration[], compar
factory.updateNamespaceExport(exportDecl.exportClause, exportDecl.exportClause.name)
),
exportDecl.moduleSpecifier,
exportDecl.assertClause,
exportDecl.attributes,
),
);
}
@@ -579,7 +579,7 @@ function updateImportDeclarationAndClause(
importDeclaration.modifiers,
factory.updateImportClause(importDeclaration.importClause!, importDeclaration.importClause!.isTypeOnly, name, namedBindings), // TODO: GH#18217
importDeclaration.moduleSpecifier,
importDeclaration.assertClause,
importDeclaration.attributes,
);
}
+4 -2
View File
@@ -12,6 +12,7 @@ import {
DefaultClause,
findChildOfKind,
getLeadingCommentRanges,
ImportAttributes,
isAnyImportSyntax,
isArrayLiteralExpression,
isBinaryExpression,
@@ -300,11 +301,12 @@ function getOutliningSpanForNode(n: Node, sourceFile: SourceFile): OutliningSpan
return spanForParenthesizedExpression(n as ParenthesizedExpression);
case SyntaxKind.NamedImports:
case SyntaxKind.NamedExports:
case SyntaxKind.ImportAttributes:
case SyntaxKind.AssertClause:
return spanForNamedImportsOrExportsOrAssertClause(n as NamedImports | NamedExports | AssertClause);
return spanForImportExportElements(n as NamedImports | NamedExports | AssertClause | ImportAttributes);
}
function spanForNamedImportsOrExportsOrAssertClause(node: NamedImports | NamedExports | AssertClause) {
function spanForImportExportElements(node: NamedImports | NamedExports | AssertClause | ImportAttributes) {
if (!node.elements.length) {
return undefined;
}
+1 -1
View File
@@ -275,7 +275,7 @@ function changeDefaultToNamedImport(importingSourceFile: SourceFile, ref: Identi
}
case SyntaxKind.ImportType:
const importTypeNode = parent as ImportTypeNode;
changes.replaceNode(importingSourceFile, parent, factory.createImportTypeNode(importTypeNode.argument, importTypeNode.assertions, factory.createIdentifier(exportName), importTypeNode.typeArguments, importTypeNode.isTypeOf));
changes.replaceNode(importingSourceFile, parent, factory.createImportTypeNode(importTypeNode.argument, importTypeNode.attributes, factory.createIdentifier(exportName), importTypeNode.typeArguments, importTypeNode.isTypeOf));
break;
default:
Debug.failBadSyntaxKind(parent);
+1 -1
View File
@@ -280,5 +280,5 @@ function isExportEqualsModule(moduleSpecifier: Expression, checker: TypeChecker)
}
function updateImport(old: ImportDeclaration, defaultImportName: Identifier | undefined, elements: readonly ImportSpecifier[] | undefined): ImportDeclaration {
return factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, elements && elements.length ? factory.createNamedImports(elements) : undefined), old.moduleSpecifier, /*assertClause*/ undefined);
return factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, elements && elements.length ? factory.createNamedImports(elements) : undefined), old.moduleSpecifier, /*attributes*/ undefined);
}
+3 -3
View File
@@ -479,7 +479,7 @@ function updateNamespaceLikeImportNode(node: SupportedImport, newNamespaceName:
/*modifiers*/ undefined,
factory.createImportClause(/*isTypeOnly*/ false, /*name*/ undefined, factory.createNamespaceImport(newNamespaceId)),
newModuleString,
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
case SyntaxKind.ImportEqualsDeclaration:
return factory.createImportEqualsDeclaration(/*modifiers*/ undefined, /*isTypeOnly*/ false, newNamespaceId, factory.createExternalModuleReference(newModuleString));
@@ -772,7 +772,7 @@ export function filterImport(i: SupportedImport, moduleSpecifier: StringLiteralL
const defaultImport = clause.name && keep(clause.name) ? clause.name : undefined;
const namedBindings = clause.namedBindings && filterNamedBindings(clause.namedBindings, keep);
return defaultImport || namedBindings
? factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(clause.isTypeOnly, defaultImport, namedBindings), getSynthesizedDeepClone(moduleSpecifier), /*assertClause*/ undefined)
? factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(clause.isTypeOnly, defaultImport, namedBindings), getSynthesizedDeepClone(moduleSpecifier), /*attributes*/ undefined)
: undefined;
}
case SyntaxKind.ImportEqualsDeclaration:
@@ -1198,7 +1198,7 @@ function moveStatementsToTargetFile(changes: textChanges.ChangeTracker, program:
}
if (length(updatedElements) < length(elements)) {
changes.replaceNode(targetFile, exportDeclaration, factory.updateExportDeclaration(exportDeclaration, exportDeclaration.modifiers, exportDeclaration.isTypeOnly, factory.updateNamedExports(exportDeclaration.exportClause, factory.createNodeArray(updatedElements, elements.hasTrailingComma)), exportDeclaration.moduleSpecifier, exportDeclaration.assertClause));
changes.replaceNode(targetFile, exportDeclaration, factory.updateExportDeclaration(exportDeclaration, exportDeclaration.modifiers, exportDeclaration.isTypeOnly, factory.updateNamedExports(exportDeclaration.exportClause, factory.createNodeArray(updatedElements, elements.hasTrailingComma)), exportDeclaration.moduleSpecifier, exportDeclaration.attributes));
}
}
}
+1 -1
View File
@@ -2501,7 +2501,7 @@ export function makeImport(defaultImport: Identifier | undefined, namedImports:
? factory.createImportClause(!!isTypeOnly, defaultImport, namedImports && namedImports.length ? factory.createNamedImports(namedImports) : undefined)
: undefined,
typeof moduleSpecifier === "string" ? makeStringLiteral(moduleSpecifier, quotePreference) : moduleSpecifier,
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
}
+2 -2
View File
@@ -309,7 +309,7 @@ describe("unittests:: TransformAPI", () => {
const exports = [{ name: "x" }];
const exportSpecifiers = exports.map(e => ts.factory.createExportSpecifier(/*isTypeOnly*/ false, e.name, e.name));
const exportClause = ts.factory.createNamedExports(exportSpecifiers);
const newEd = ts.factory.updateExportDeclaration(ed, ed.modifiers, ed.isTypeOnly, exportClause, ed.moduleSpecifier, ed.assertClause);
const newEd = ts.factory.updateExportDeclaration(ed, ed.modifiers, ed.isTypeOnly, exportClause, ed.moduleSpecifier, ed.attributes);
return newEd as ts.Node as T;
}
@@ -347,7 +347,7 @@ describe("unittests:: TransformAPI", () => {
ts.factory.createNamespaceImport(ts.factory.createIdentifier("i0")),
),
/*moduleSpecifier*/ ts.factory.createStringLiteral("./comp1"),
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
return ts.factory.updateSourceFile(sf, [importStar]);
}
@@ -376,6 +376,77 @@ describe("unittests:: tsc-watch:: moduleResolution", () => {
],
});
verifyTscWatch({
scenario: "moduleResolution",
subScenario: "module resolutions from files with partially used import attributes",
sys: () =>
createWatchedSystem([
{
path: `/user/username/projects/myproject/tsconfig.json`,
content: JSON.stringify({
compilerOptions: { moduleResolution: "node16" },
}),
},
{
path: `/user/username/projects/myproject/index.ts`,
content: Utils.dedent`
import type { ImportInterface } from "pkg" with { "resolution-mode": "import" };
import type { RequireInterface } from "pkg1" with { "resolution-mode": "require" };
import {x} from "./a";
`,
},
{
path: `/user/username/projects/myproject/a.ts`,
content: Utils.dedent`
export const x = 10;
`,
},
{
path: `/user/username/projects/myproject/node_modules/pkg/package.json`,
content: JSON.stringify({
name: "pkg",
version: "0.0.1",
exports: {
import: "./import.js",
require: "./require.js",
},
}),
},
{
path: `/user/username/projects/myproject/node_modules/pkg/import.d.ts`,
content: `export interface ImportInterface {}`,
},
{
path: `/user/username/projects/myproject/node_modules/pkg/require.d.ts`,
content: `export interface RequireInterface {}`,
},
{
path: `/user/username/projects/myproject/node_modules/pkg1/package.json`,
content: JSON.stringify({
name: "pkg1",
version: "0.0.1",
exports: {
import: "./import.js",
require: "./require.js",
},
}),
},
{
path: `/user/username/projects/myproject/node_modules/pkg1/import.d.ts`,
content: `export interface ImportInterface {}`,
},
libFile,
], { currentDirectory: "/user/username/projects/myproject" }),
commandLineArgs: ["-w", "--traceResolution"],
edits: [
{
caption: "modify aFile by adding import",
edit: sys => sys.appendFile(`/user/username/projects/myproject/a.ts`, `import type { ImportInterface } from "pkg" with { "resolution-mode": "import" }`),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
],
});
verifyTscWatch({
scenario: "moduleResolution",
subScenario: "type reference resolutions reuse",
+51 -29
View File
@@ -4464,9 +4464,11 @@ declare namespace ts {
DefaultClause = 297,
HeritageClause = 298,
CatchClause = 299,
AssertClause = 300,
AssertEntry = 301,
ImportTypeAssertionContainer = 302,
ImportAttributes = 300,
ImportAttribute = 301,
/** @deprecated */ AssertClause = 300,
/** @deprecated */ AssertEntry = 301,
/** @deprecated */ ImportTypeAssertionContainer = 302,
PropertyAssignment = 303,
ShorthandPropertyAssignment = 304,
SpreadAssignment = 305,
@@ -5197,17 +5199,19 @@ declare namespace ts {
interface KeywordTypeNode<TKind extends KeywordTypeSyntaxKind = KeywordTypeSyntaxKind> extends KeywordToken<TKind>, TypeNode {
readonly kind: TKind;
}
/** @deprecated */
interface ImportTypeAssertionContainer extends Node {
readonly kind: SyntaxKind.ImportTypeAssertionContainer;
readonly parent: ImportTypeNode;
readonly assertClause: AssertClause;
/** @deprecated */ readonly assertClause: AssertClause;
readonly multiLine?: boolean;
}
interface ImportTypeNode extends NodeWithTypeArguments {
readonly kind: SyntaxKind.ImportType;
readonly isTypeOf: boolean;
readonly argument: TypeNode;
readonly assertions?: ImportTypeAssertionContainer;
/** @deprecated */ readonly assertions?: ImportTypeAssertionContainer;
readonly attributes?: ImportAttributes;
readonly qualifier?: EntityName;
}
interface ThisTypeNode extends TypeNode {
@@ -5998,7 +6002,8 @@ declare namespace ts {
readonly importClause?: ImportClause;
/** If this is not a StringLiteral it will be a grammar error. */
readonly moduleSpecifier: Expression;
readonly assertClause?: AssertClause;
/** @deprecated */ readonly assertClause?: AssertClause;
readonly attributes?: ImportAttributes;
}
type NamedImportBindings = NamespaceImport | NamedImports;
type NamedExportBindings = NamespaceExport | NamedExports;
@@ -6009,17 +6014,24 @@ declare namespace ts {
readonly name?: Identifier;
readonly namedBindings?: NamedImportBindings;
}
type AssertionKey = Identifier | StringLiteral;
interface AssertEntry extends Node {
readonly kind: SyntaxKind.AssertEntry;
readonly parent: AssertClause;
readonly name: AssertionKey;
/** @deprecated */
type AssertionKey = ImportAttributeName;
/** @deprecated */
type AssertEntry = ImportAttribute;
/** @deprecated */
type AssertClause = ImportAttributes;
type ImportAttributeName = Identifier | StringLiteral;
interface ImportAttribute extends Node {
readonly kind: SyntaxKind.ImportAttribute;
readonly parent: ImportAttributes;
readonly name: ImportAttributeName;
readonly value: Expression;
}
interface AssertClause extends Node {
readonly kind: SyntaxKind.AssertClause;
interface ImportAttributes extends Node {
readonly token: SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword;
readonly kind: SyntaxKind.ImportAttributes;
readonly parent: ImportDeclaration | ExportDeclaration;
readonly elements: NodeArray<AssertEntry>;
readonly elements: NodeArray<ImportAttribute>;
readonly multiLine?: boolean;
}
interface NamespaceImport extends NamedDeclaration {
@@ -6045,7 +6057,8 @@ declare namespace ts {
readonly exportClause?: NamedExportBindings;
/** If this is not a StringLiteral it will be a grammar error. */
readonly moduleSpecifier?: Expression;
readonly assertClause?: AssertClause;
/** @deprecated */ readonly assertClause?: AssertClause;
readonly attributes?: ImportAttributes;
}
interface NamedImports extends Node {
readonly kind: SyntaxKind.NamedImports;
@@ -8008,8 +8021,8 @@ declare namespace ts {
updateConditionalTypeNode(node: ConditionalTypeNode, checkType: TypeNode, extendsType: TypeNode, trueType: TypeNode, falseType: TypeNode): ConditionalTypeNode;
createInferTypeNode(typeParameter: TypeParameterDeclaration): InferTypeNode;
updateInferTypeNode(node: InferTypeNode, typeParameter: TypeParameterDeclaration): InferTypeNode;
createImportTypeNode(argument: TypeNode, assertions?: ImportTypeAssertionContainer, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode;
updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, assertions: ImportTypeAssertionContainer | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode;
createImportTypeNode(argument: TypeNode, attributes?: ImportAttributes, qualifier?: EntityName, typeArguments?: readonly TypeNode[], isTypeOf?: boolean): ImportTypeNode;
updateImportTypeNode(node: ImportTypeNode, argument: TypeNode, attributes: ImportAttributes | undefined, qualifier: EntityName | undefined, typeArguments: readonly TypeNode[] | undefined, isTypeOf?: boolean): ImportTypeNode;
createParenthesizedType(type: TypeNode): ParenthesizedTypeNode;
updateParenthesizedType(node: ParenthesizedTypeNode, type: TypeNode): ParenthesizedTypeNode;
createThisTypeNode(): ThisTypeNode;
@@ -8166,16 +8179,20 @@ declare namespace ts {
updateNamespaceExportDeclaration(node: NamespaceExportDeclaration, name: Identifier): NamespaceExportDeclaration;
createImportEqualsDeclaration(modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, name: string | Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration;
updateImportEqualsDeclaration(node: ImportEqualsDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, name: Identifier, moduleReference: ModuleReference): ImportEqualsDeclaration;
createImportDeclaration(modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause?: AssertClause): ImportDeclaration;
updateImportDeclaration(node: ImportDeclaration, modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, assertClause: AssertClause | undefined): ImportDeclaration;
createImportDeclaration(modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes?: ImportAttributes): ImportDeclaration;
updateImportDeclaration(node: ImportDeclaration, modifiers: readonly ModifierLike[] | undefined, importClause: ImportClause | undefined, moduleSpecifier: Expression, attributes: ImportAttributes | undefined): ImportDeclaration;
createImportClause(isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause;
updateImportClause(node: ImportClause, isTypeOnly: boolean, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined): ImportClause;
createAssertClause(elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
updateAssertClause(node: AssertClause, elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
createAssertEntry(name: AssertionKey, value: Expression): AssertEntry;
updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression): AssertEntry;
createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer;
updateImportTypeAssertionContainer(node: ImportTypeAssertionContainer, clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer;
/** @deprecated */ createAssertClause(elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
/** @deprecated */ updateAssertClause(node: AssertClause, elements: NodeArray<AssertEntry>, multiLine?: boolean): AssertClause;
/** @deprecated */ createAssertEntry(name: AssertionKey, value: Expression): AssertEntry;
/** @deprecated */ updateAssertEntry(node: AssertEntry, name: AssertionKey, value: Expression): AssertEntry;
/** @deprecated */ createImportTypeAssertionContainer(clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer;
/** @deprecated */ updateImportTypeAssertionContainer(node: ImportTypeAssertionContainer, clause: AssertClause, multiLine?: boolean): ImportTypeAssertionContainer;
createImportAttributes(elements: NodeArray<ImportAttribute>, multiLine?: boolean): ImportAttributes;
updateImportAttributes(node: ImportAttributes, elements: NodeArray<ImportAttribute>, multiLine?: boolean): ImportAttributes;
createImportAttribute(name: ImportAttributeName, value: Expression): ImportAttribute;
updateImportAttribute(node: ImportAttribute, name: ImportAttributeName, value: Expression): ImportAttribute;
createNamespaceImport(name: Identifier): NamespaceImport;
updateNamespaceImport(node: NamespaceImport, name: Identifier): NamespaceImport;
createNamespaceExport(name: Identifier): NamespaceExport;
@@ -8186,8 +8203,8 @@ declare namespace ts {
updateImportSpecifier(node: ImportSpecifier, isTypeOnly: boolean, propertyName: Identifier | undefined, name: Identifier): ImportSpecifier;
createExportAssignment(modifiers: readonly ModifierLike[] | undefined, isExportEquals: boolean | undefined, expression: Expression): ExportAssignment;
updateExportAssignment(node: ExportAssignment, modifiers: readonly ModifierLike[] | undefined, expression: Expression): ExportAssignment;
createExportDeclaration(modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, assertClause?: AssertClause): ExportDeclaration;
updateExportDeclaration(node: ExportDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, assertClause: AssertClause | undefined): ExportDeclaration;
createExportDeclaration(modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier?: Expression, attributes?: ImportAttributes): ExportDeclaration;
updateExportDeclaration(node: ExportDeclaration, modifiers: readonly ModifierLike[] | undefined, isTypeOnly: boolean, exportClause: NamedExportBindings | undefined, moduleSpecifier: Expression | undefined, attributes: ImportAttributes | undefined): ExportDeclaration;
createNamedExports(elements: readonly ExportSpecifier[]): NamedExports;
updateNamedExports(node: NamedExports, elements: readonly ExportSpecifier[]): NamedExports;
createExportSpecifier(isTypeOnly: boolean, propertyName: string | Identifier | undefined, name: string | Identifier): ExportSpecifier;
@@ -8636,7 +8653,8 @@ declare namespace ts {
ObjectBindingPatternElements = 525136,
ArrayBindingPatternElements = 524880,
ObjectLiteralExpressionProperties = 526226,
ImportClauseEntries = 526226,
ImportAttributes = 526226,
/** @deprecated */ ImportClauseEntries = 526226,
ArrayLiteralExpressionElements = 8914,
CommaListElements = 528,
CallExpressionArguments = 2576,
@@ -9094,8 +9112,8 @@ declare namespace ts {
function isTypeOnlyImportDeclaration(node: Node): node is TypeOnlyImportDeclaration;
function isTypeOnlyExportDeclaration(node: Node): node is TypeOnlyExportDeclaration;
function isTypeOnlyImportOrExportDeclaration(node: Node): node is TypeOnlyAliasDeclaration;
function isAssertionKey(node: Node): node is AssertionKey;
function isStringTextContainingNode(node: Node): node is StringLiteral | TemplateLiteralToken;
function isImportAttributeName(node: Node): node is ImportAttributeName;
function isModifier(node: Node): node is Modifier;
function isEntityName(node: Node): node is EntityName;
function isPropertyName(node: Node): node is PropertyName;
@@ -9397,8 +9415,12 @@ declare namespace ts {
function isImportDeclaration(node: Node): node is ImportDeclaration;
function isImportClause(node: Node): node is ImportClause;
function isImportTypeAssertionContainer(node: Node): node is ImportTypeAssertionContainer;
/** @deprecated */
function isAssertClause(node: Node): node is AssertClause;
/** @deprecated */
function isAssertEntry(node: Node): node is AssertEntry;
function isImportAttributes(node: Node): node is ImportAttributes;
function isImportAttribute(node: Node): node is ImportAttribute;
function isNamespaceImport(node: Node): node is NamespaceImport;
function isNamespaceExport(node: Node): node is NamespaceExport;
function isNamedImports(node: Node): node is NamedImports;
@@ -0,0 +1,272 @@
=== /tests/cases/fourslash/main.ts ===
// import("./other.json", {});
// ^
// | ----------------------------------------------------------------------
// | (property) ImportCallOptions.with?: ImportAttributes
// | (property) ImportCallOptions.assert?: ImportAssertions
// | ----------------------------------------------------------------------
// import("./other.json", { wi});
// ^^
// | ----------------------------------------------------------------------
// | (property) ImportCallOptions.with?: ImportAttributes
// | (property) ImportCallOptions.assert?: ImportAssertions
// | ----------------------------------------------------------------------
[
{
"marker": {
"fileName": "/tests/cases/fourslash/main.ts",
"position": 24,
"name": "0"
},
"item": {
"flags": 0,
"isGlobalCompletion": false,
"isMemberCompletion": true,
"isNewIdentifierLocation": false,
"entries": [
{
"name": "with",
"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": "with",
"kind": "propertyName"
},
{
"text": "?",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "ImportAttributes",
"kind": "interfaceName"
}
],
"documentation": []
},
{
"name": "assert",
"kind": "property",
"kindModifiers": "deprecated,declare,optional",
"sortText": "z12",
"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": [],
"tags": [
{
"name": "deprecated"
}
]
}
]
}
},
{
"marker": {
"fileName": "/tests/cases/fourslash/main.ts",
"position": 55,
"name": "1"
},
"item": {
"flags": 0,
"isGlobalCompletion": false,
"isMemberCompletion": true,
"isNewIdentifierLocation": false,
"optionalReplacementSpan": {
"start": 53,
"length": 2
},
"entries": [
{
"name": "with",
"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": "with",
"kind": "propertyName"
},
{
"text": "?",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "ImportAttributes",
"kind": "interfaceName"
}
],
"documentation": []
},
{
"name": "assert",
"kind": "property",
"kindModifiers": "deprecated,declare,optional",
"sortText": "z12",
"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": [],
"tags": [
{
"name": "deprecated"
}
]
}
]
}
}
]
@@ -2,11 +2,13 @@
// import("./other.json", {});
// ^
// | ----------------------------------------------------------------------
// | (property) ImportCallOptions.with?: ImportAttributes
// | (property) ImportCallOptions.assert?: ImportAssertions
// | ----------------------------------------------------------------------
// import("./other.json", { asse});
// ^^^^
// | ----------------------------------------------------------------------
// | (property) ImportCallOptions.with?: ImportAttributes
// | (property) ImportCallOptions.assert?: ImportAssertions
// | ----------------------------------------------------------------------
@@ -24,10 +26,63 @@
"isNewIdentifierLocation": false,
"entries": [
{
"name": "assert",
"name": "with",
"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": "with",
"kind": "propertyName"
},
{
"text": "?",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "ImportAttributes",
"kind": "interfaceName"
}
],
"documentation": []
},
{
"name": "assert",
"kind": "property",
"kindModifiers": "deprecated,declare,optional",
"sortText": "z12",
"displayParts": [
{
"text": "(",
@@ -74,7 +129,12 @@
"kind": "interfaceName"
}
],
"documentation": []
"documentation": [],
"tags": [
{
"name": "deprecated"
}
]
}
]
}
@@ -96,10 +156,63 @@
},
"entries": [
{
"name": "assert",
"name": "with",
"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": "with",
"kind": "propertyName"
},
{
"text": "?",
"kind": "punctuation"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "ImportAttributes",
"kind": "interfaceName"
}
],
"documentation": []
},
{
"name": "assert",
"kind": "property",
"kindModifiers": "deprecated,declare,optional",
"sortText": "z12",
"displayParts": [
{
"text": "(",
@@ -146,7 +259,12 @@
"kind": "interfaceName"
}
],
"documentation": []
"documentation": [],
"tags": [
{
"name": "deprecated"
}
]
}
]
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,4 @@
// === documentHighlights ===
// === /tests/cases/fourslash/getOccurrencesNonStringImportAttributes.ts ===
// import * as react from "react" with { cache: /*HIGHLIGHTS*/0 };
// react.Children;
@@ -8,7 +8,7 @@
3.ts(4,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(5,26): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(7,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(8,11): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
3.ts(8,11): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
3.ts(9,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(10,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(10,52): error TS1009: Trailing comma not allowed.
@@ -65,7 +65,7 @@
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
const f = import()
~~~~~~~~
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
const g = import('./0', {}, {})
~~
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
@@ -1,5 +1,5 @@
3.ts(8,11): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
3.ts(9,11): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
3.ts(8,11): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
3.ts(9,11): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
==== 0.ts (0 errors) ====
@@ -33,10 +33,10 @@
const e = import('./0', foo())
const f = import()
~~~~~~~~
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
const g = import('./0', {}, {})
~~~~~~~~~~~~~~~~~~~~~
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
const h = import('./0', { assert: { type: "json" }},)
@@ -0,0 +1,75 @@
1.ts(1,14): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(2,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(3,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2.ts(1,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2.ts(2,38): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
3.ts(2,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(3,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(4,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(5,26): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(7,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(8,11): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
3.ts(9,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(10,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
3.ts(10,50): error TS1009: Trailing comma not allowed.
==== 0.ts (0 errors) ====
export const a = 1;
export const b = 2;
==== 1.ts (3 errors) ====
import './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
import { a, b } from './0' with { "type": "json" }
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
import * as foo from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
a;
b;
foo.a;
foo.b;
==== 2.ts (2 errors) ====
import { a, b } from './0' with {}
~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
import { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
a;
b;
c;
d;
==== 3.ts (9 errors) ====
const a = import('./0')
const b = import('./0', { with: { type: "json" } })
~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
const c = import('./0', { with: { type: "json", ttype: "typo" } })
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
const d = import('./0', { with: {} })
~~~~~~~~~~~~
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
const dd = import('./0', {})
~~
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
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', 'node16', or 'nodenext'.
const f = import()
~~~~~~~~
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
const g = import('./0', {}, {})
~~
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
const h = import('./0', { with: { type: "json" }},)
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
~
!!! error TS1009: Trailing comma not allowed.
@@ -0,0 +1,89 @@
//// [tests/cases/conformance/importAttributes/importAttributes1.ts] ////
//// [0.ts]
export const a = 1;
export const b = 2;
//// [1.ts]
import './0' with { type: "json" }
import { a, b } from './0' with { "type": "json" }
import * as foo from './0' with { type: "json" }
a;
b;
foo.a;
foo.b;
//// [2.ts]
import { a, b } from './0' with {}
import { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
a;
b;
c;
d;
//// [3.ts]
const a = import('./0')
const b = import('./0', { with: { type: "json" } })
const c = import('./0', { with: { type: "json", ttype: "typo" } })
const d = import('./0', { with: {} })
const dd = import('./0', {})
declare function foo(): any;
const e = import('./0', foo())
const f = import()
const g = import('./0', {}, {})
const h = import('./0', { with: { 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<typeof import("./0")>;
declare const b: Promise<typeof import("./0")>;
declare const c: Promise<typeof import("./0")>;
declare const d: Promise<typeof import("./0")>;
declare const dd: Promise<typeof import("./0")>;
declare function foo(): any;
declare const e: Promise<typeof import("./0")>;
declare const f: Promise<any>;
declare const g: Promise<typeof import("./0")>;
declare const h: Promise<typeof import("./0")>;
@@ -0,0 +1,105 @@
//// [tests/cases/conformance/importAttributes/importAttributes1.ts] ////
=== 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))
=== 1.ts ===
import './0' with { type: "json" }
import { a, b } from './0' with { "type": "json" }
>a : Symbol(a, Decl(1.ts, 1, 8))
>b : Symbol(b, Decl(1.ts, 1, 11))
import * as foo from './0' with { 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))
=== 2.ts ===
import { a, b } from './0' with {}
>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' with { 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))
=== 3.ts ===
const a = import('./0')
>a : Symbol(a, Decl(3.ts, 0, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
const b = import('./0', { with: { type: "json" } })
>b : Symbol(b, Decl(3.ts, 1, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 1, 25))
>type : Symbol(type, Decl(3.ts, 1, 33))
const c = import('./0', { with: { type: "json", ttype: "typo" } })
>c : Symbol(c, Decl(3.ts, 2, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 2, 25))
>type : Symbol(type, Decl(3.ts, 2, 33))
>ttype : Symbol(ttype, Decl(3.ts, 2, 47))
const d = import('./0', { with: {} })
>d : Symbol(d, Decl(3.ts, 3, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 3, 25))
const dd = import('./0', {})
>dd : Symbol(dd, Decl(3.ts, 4, 5))
>'./0' : Symbol("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("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("0", Decl(0.ts, 0, 0))
const h = import('./0', { with: { type: "json" }},)
>h : Symbol(h, Decl(3.ts, 9, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 9, 25))
>type : Symbol(type, Decl(3.ts, 9, 33))
@@ -0,0 +1,138 @@
//// [tests/cases/conformance/importAttributes/importAttributes1.ts] ////
=== 0.ts ===
export const a = 1;
>a : 1
>1 : 1
export const b = 2;
>b : 2
>2 : 2
=== 1.ts ===
import './0' with { type: "json" }
>type : any
import { a, b } from './0' with { "type": "json" }
>a : 1
>b : 2
import * as foo from './0' with { 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
=== 2.ts ===
import { a, b } from './0' with {}
>a : 1
>b : 2
import { a as c, b as d } from './0' with { 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
=== 3.ts ===
const a = import('./0')
>a : Promise<typeof import("0")>
>import('./0') : Promise<typeof import("0")>
>'./0' : "./0"
const b = import('./0', { with: { type: "json" } })
>b : Promise<typeof import("0")>
>import('./0', { with: { type: "json" } }) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: { type: "json" } } : { with: { type: string; }; }
>with : { type: string; }
>{ type: "json" } : { type: string; }
>type : string
>"json" : "json"
const c = import('./0', { with: { type: "json", ttype: "typo" } })
>c : Promise<typeof import("0")>
>import('./0', { with: { type: "json", ttype: "typo" } }) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: { type: "json", ttype: "typo" } } : { with: { type: string; ttype: string; }; }
>with : { type: string; ttype: string; }
>{ type: "json", ttype: "typo" } : { type: string; ttype: string; }
>type : string
>"json" : "json"
>ttype : string
>"typo" : "typo"
const d = import('./0', { with: {} })
>d : Promise<typeof import("0")>
>import('./0', { with: {} }) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: {} } : { with: {}; }
>with : {}
>{} : {}
const dd = import('./0', {})
>dd : Promise<typeof import("0")>
>import('./0', {}) : Promise<typeof import("0")>
>'./0' : "./0"
>{} : {}
declare function foo(): any;
>foo : () => any
const e = import('./0', foo())
>e : Promise<typeof import("0")>
>import('./0', foo()) : Promise<typeof import("0")>
>'./0' : "./0"
>foo() : any
>foo : () => any
const f = import()
>f : Promise<any>
>import() : Promise<any>
const g = import('./0', {}, {})
>g : Promise<typeof import("0")>
>import('./0', {}, {}) : Promise<typeof import("0")>
>'./0' : "./0"
>{} : {}
>{} : {}
const h = import('./0', { with: { type: "json" }},)
>h : Promise<typeof import("0")>
>import('./0', { with: { type: "json" }},) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: { type: "json" }} : { with: { type: string; }; }
>with : { type: string; }
>{ type: "json" } : { type: string; }
>type : string
>"json" : "json"
@@ -0,0 +1,75 @@
1.ts(1,14): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(2,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(3,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2.ts(1,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2.ts(2,38): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
3.ts(1,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
3.ts(2,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
3.ts(3,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
3.ts(4,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
3.ts(5,12): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
3.ts(7,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
3.ts(8,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
3.ts(9,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
3.ts(10,11): error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
==== 0.ts (0 errors) ====
export const a = 1;
export const b = 2;
==== 1.ts (3 errors) ====
import './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
import { a, b } from './0' with { "type": "json" }
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
import * as foo from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
a;
b;
foo.a;
foo.b;
==== 2.ts (2 errors) ====
import { a, b } from './0' with {}
~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
import { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
a;
b;
c;
d;
==== 3.ts (9 errors) ====
const a = import('./0')
~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
const b = import('./0', { with: { type: "json" } })
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
const c = import('./0', { with: { type: "json", ttype: "typo" } })
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
const d = import('./0', { with: {} })
~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
const dd = import('./0', {})
~~~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
declare function foo(): any;
const e = import('./0', foo())
~~~~~~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
const f = import()
~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
const g = import('./0', {}, {})
~~~~~~~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
const h = import('./0', { with: { type: "json" }},)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS1323: Dynamic imports are only supported when the '--module' flag is set to 'es2020', 'es2022', 'esnext', 'commonjs', 'amd', 'system', 'umd', 'node16', or 'nodenext'.
@@ -0,0 +1,82 @@
//// [tests/cases/conformance/importAttributes/importAttributes1.ts] ////
//// [0.ts]
export const a = 1;
export const b = 2;
//// [1.ts]
import './0' with { type: "json" }
import { a, b } from './0' with { "type": "json" }
import * as foo from './0' with { type: "json" }
a;
b;
foo.a;
foo.b;
//// [2.ts]
import { a, b } from './0' with {}
import { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
a;
b;
c;
d;
//// [3.ts]
const a = import('./0')
const b = import('./0', { with: { type: "json" } })
const c = import('./0', { with: { type: "json", ttype: "typo" } })
const d = import('./0', { with: {} })
const dd = import('./0', {})
declare function foo(): any;
const e = import('./0', foo())
const f = import()
const g = import('./0', {}, {})
const h = import('./0', { with: { type: "json" }},)
//// [0.js]
export const a = 1;
export const b = 2;
//// [1.js]
import './0' with { type: "json" };
import { a, b } from './0' with { "type": "json" };
import * as foo from './0' with { type: "json" };
a;
b;
foo.a;
foo.b;
//// [2.js]
import { a, b } from './0' with {};
import { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" };
a;
b;
c;
d;
//// [3.js]
const a = import('./0');
const b = import('./0', { with: { type: "json" } });
const c = import('./0', { with: { type: "json", ttype: "typo" } });
const d = import('./0', { with: {} });
const dd = import('./0', {});
const e = import('./0', foo());
const f = import();
const g = import('./0', {}, {});
const h = import('./0', { with: { 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<typeof import("./0")>;
declare const b: Promise<typeof import("./0")>;
declare const c: Promise<typeof import("./0")>;
declare const d: Promise<typeof import("./0")>;
declare const dd: Promise<typeof import("./0")>;
declare function foo(): any;
declare const e: Promise<typeof import("./0")>;
declare const f: Promise<any>;
declare const g: Promise<typeof import("./0")>;
declare const h: Promise<typeof import("./0")>;
@@ -0,0 +1,105 @@
//// [tests/cases/conformance/importAttributes/importAttributes1.ts] ////
=== 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))
=== 1.ts ===
import './0' with { type: "json" }
import { a, b } from './0' with { "type": "json" }
>a : Symbol(a, Decl(1.ts, 1, 8))
>b : Symbol(b, Decl(1.ts, 1, 11))
import * as foo from './0' with { 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))
=== 2.ts ===
import { a, b } from './0' with {}
>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' with { 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))
=== 3.ts ===
const a = import('./0')
>a : Symbol(a, Decl(3.ts, 0, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
const b = import('./0', { with: { type: "json" } })
>b : Symbol(b, Decl(3.ts, 1, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 1, 25))
>type : Symbol(type, Decl(3.ts, 1, 33))
const c = import('./0', { with: { type: "json", ttype: "typo" } })
>c : Symbol(c, Decl(3.ts, 2, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 2, 25))
>type : Symbol(type, Decl(3.ts, 2, 33))
>ttype : Symbol(ttype, Decl(3.ts, 2, 47))
const d = import('./0', { with: {} })
>d : Symbol(d, Decl(3.ts, 3, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 3, 25))
const dd = import('./0', {})
>dd : Symbol(dd, Decl(3.ts, 4, 5))
>'./0' : Symbol("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("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("0", Decl(0.ts, 0, 0))
const h = import('./0', { with: { type: "json" }},)
>h : Symbol(h, Decl(3.ts, 9, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 9, 25))
>type : Symbol(type, Decl(3.ts, 9, 33))
@@ -0,0 +1,138 @@
//// [tests/cases/conformance/importAttributes/importAttributes1.ts] ////
=== 0.ts ===
export const a = 1;
>a : 1
>1 : 1
export const b = 2;
>b : 2
>2 : 2
=== 1.ts ===
import './0' with { type: "json" }
>type : any
import { a, b } from './0' with { "type": "json" }
>a : 1
>b : 2
import * as foo from './0' with { 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
=== 2.ts ===
import { a, b } from './0' with {}
>a : 1
>b : 2
import { a as c, b as d } from './0' with { 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
=== 3.ts ===
const a = import('./0')
>a : Promise<typeof import("0")>
>import('./0') : Promise<typeof import("0")>
>'./0' : "./0"
const b = import('./0', { with: { type: "json" } })
>b : Promise<typeof import("0")>
>import('./0', { with: { type: "json" } }) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: { type: "json" } } : { with: { type: string; }; }
>with : { type: string; }
>{ type: "json" } : { type: string; }
>type : string
>"json" : "json"
const c = import('./0', { with: { type: "json", ttype: "typo" } })
>c : Promise<typeof import("0")>
>import('./0', { with: { type: "json", ttype: "typo" } }) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: { type: "json", ttype: "typo" } } : { with: { type: string; ttype: string; }; }
>with : { type: string; ttype: string; }
>{ type: "json", ttype: "typo" } : { type: string; ttype: string; }
>type : string
>"json" : "json"
>ttype : string
>"typo" : "typo"
const d = import('./0', { with: {} })
>d : Promise<typeof import("0")>
>import('./0', { with: {} }) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: {} } : { with: {}; }
>with : {}
>{} : {}
const dd = import('./0', {})
>dd : Promise<typeof import("0")>
>import('./0', {}) : Promise<typeof import("0")>
>'./0' : "./0"
>{} : {}
declare function foo(): any;
>foo : () => any
const e = import('./0', foo())
>e : Promise<typeof import("0")>
>import('./0', foo()) : Promise<typeof import("0")>
>'./0' : "./0"
>foo() : any
>foo : () => any
const f = import()
>f : Promise<any>
>import() : Promise<any>
const g = import('./0', {}, {})
>g : Promise<typeof import("0")>
>import('./0', {}, {}) : Promise<typeof import("0")>
>'./0' : "./0"
>{} : {}
>{} : {}
const h = import('./0', { with: { type: "json" }},)
>h : Promise<typeof import("0")>
>import('./0', { with: { type: "json" }},) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: { type: "json" }} : { with: { type: string; }; }
>with : { type: string; }
>{ type: "json" } : { type: string; }
>type : string
>"json" : "json"
@@ -0,0 +1,39 @@
3.ts(8,11): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
3.ts(9,11): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
==== 0.ts (0 errors) ====
export const a = 1;
export const b = 2;
==== 1.ts (0 errors) ====
import './0' with { type: "json" }
import { a, b } from './0' with { "type": "json" }
import * as foo from './0' with { type: "json" }
a;
b;
foo.a;
foo.b;
==== 2.ts (0 errors) ====
import { a, b } from './0' with {}
import { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
a;
b;
c;
d;
==== 3.ts (2 errors) ====
const a = import('./0')
const b = import('./0', { with: { type: "json" } })
const c = import('./0', { with: { type: "json", ttype: "typo" } })
const d = import('./0', { with: {} })
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 set of attributes as arguments
const g = import('./0', {}, {})
~~~~~~~~~~~~~~~~~~~~~
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
const h = import('./0', { with: { type: "json" }},)
@@ -0,0 +1,82 @@
//// [tests/cases/conformance/importAttributes/importAttributes1.ts] ////
//// [0.ts]
export const a = 1;
export const b = 2;
//// [1.ts]
import './0' with { type: "json" }
import { a, b } from './0' with { "type": "json" }
import * as foo from './0' with { type: "json" }
a;
b;
foo.a;
foo.b;
//// [2.ts]
import { a, b } from './0' with {}
import { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
a;
b;
c;
d;
//// [3.ts]
const a = import('./0')
const b = import('./0', { with: { type: "json" } })
const c = import('./0', { with: { type: "json", ttype: "typo" } })
const d = import('./0', { with: {} })
const dd = import('./0', {})
declare function foo(): any;
const e = import('./0', foo())
const f = import()
const g = import('./0', {}, {})
const h = import('./0', { with: { type: "json" }},)
//// [0.js]
export const a = 1;
export const b = 2;
//// [1.js]
import './0' with { type: "json" };
import { a, b } from './0' with { "type": "json" };
import * as foo from './0' with { type: "json" };
a;
b;
foo.a;
foo.b;
//// [2.js]
import { a, b } from './0' with {};
import { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" };
a;
b;
c;
d;
//// [3.js]
const a = import('./0');
const b = import('./0', { with: { type: "json" } });
const c = import('./0', { with: { type: "json", ttype: "typo" } });
const d = import('./0', { with: {} });
const dd = import('./0', {});
const e = import('./0', foo());
const f = import();
const g = import('./0', {}, {});
const h = import('./0', { with: { 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<typeof import("./0")>;
declare const b: Promise<typeof import("./0")>;
declare const c: Promise<typeof import("./0")>;
declare const d: Promise<typeof import("./0")>;
declare const dd: Promise<typeof import("./0")>;
declare function foo(): any;
declare const e: Promise<typeof import("./0")>;
declare const f: Promise<any>;
declare const g: Promise<typeof import("./0")>;
declare const h: Promise<typeof import("./0")>;
@@ -0,0 +1,105 @@
//// [tests/cases/conformance/importAttributes/importAttributes1.ts] ////
=== 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))
=== 1.ts ===
import './0' with { type: "json" }
import { a, b } from './0' with { "type": "json" }
>a : Symbol(a, Decl(1.ts, 1, 8))
>b : Symbol(b, Decl(1.ts, 1, 11))
import * as foo from './0' with { 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))
=== 2.ts ===
import { a, b } from './0' with {}
>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' with { 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))
=== 3.ts ===
const a = import('./0')
>a : Symbol(a, Decl(3.ts, 0, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
const b = import('./0', { with: { type: "json" } })
>b : Symbol(b, Decl(3.ts, 1, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 1, 25))
>type : Symbol(type, Decl(3.ts, 1, 33))
const c = import('./0', { with: { type: "json", ttype: "typo" } })
>c : Symbol(c, Decl(3.ts, 2, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 2, 25))
>type : Symbol(type, Decl(3.ts, 2, 33))
>ttype : Symbol(ttype, Decl(3.ts, 2, 47))
const d = import('./0', { with: {} })
>d : Symbol(d, Decl(3.ts, 3, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 3, 25))
const dd = import('./0', {})
>dd : Symbol(dd, Decl(3.ts, 4, 5))
>'./0' : Symbol("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("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("0", Decl(0.ts, 0, 0))
const h = import('./0', { with: { type: "json" }},)
>h : Symbol(h, Decl(3.ts, 9, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>with : Symbol(with, Decl(3.ts, 9, 25))
>type : Symbol(type, Decl(3.ts, 9, 33))
@@ -0,0 +1,138 @@
//// [tests/cases/conformance/importAttributes/importAttributes1.ts] ////
=== 0.ts ===
export const a = 1;
>a : 1
>1 : 1
export const b = 2;
>b : 2
>2 : 2
=== 1.ts ===
import './0' with { type: "json" }
>type : any
import { a, b } from './0' with { "type": "json" }
>a : 1
>b : 2
import * as foo from './0' with { 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
=== 2.ts ===
import { a, b } from './0' with {}
>a : 1
>b : 2
import { a as c, b as d } from './0' with { 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
=== 3.ts ===
const a = import('./0')
>a : Promise<typeof import("0")>
>import('./0') : Promise<typeof import("0")>
>'./0' : "./0"
const b = import('./0', { with: { type: "json" } })
>b : Promise<typeof import("0")>
>import('./0', { with: { type: "json" } }) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: { type: "json" } } : { with: { type: string; }; }
>with : { type: string; }
>{ type: "json" } : { type: string; }
>type : string
>"json" : "json"
const c = import('./0', { with: { type: "json", ttype: "typo" } })
>c : Promise<typeof import("0")>
>import('./0', { with: { type: "json", ttype: "typo" } }) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: { type: "json", ttype: "typo" } } : { with: { type: string; ttype: string; }; }
>with : { type: string; ttype: string; }
>{ type: "json", ttype: "typo" } : { type: string; ttype: string; }
>type : string
>"json" : "json"
>ttype : string
>"typo" : "typo"
const d = import('./0', { with: {} })
>d : Promise<typeof import("0")>
>import('./0', { with: {} }) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: {} } : { with: {}; }
>with : {}
>{} : {}
const dd = import('./0', {})
>dd : Promise<typeof import("0")>
>import('./0', {}) : Promise<typeof import("0")>
>'./0' : "./0"
>{} : {}
declare function foo(): any;
>foo : () => any
const e = import('./0', foo())
>e : Promise<typeof import("0")>
>import('./0', foo()) : Promise<typeof import("0")>
>'./0' : "./0"
>foo() : any
>foo : () => any
const f = import()
>f : Promise<any>
>import() : Promise<any>
const g = import('./0', {}, {})
>g : Promise<typeof import("0")>
>import('./0', {}, {}) : Promise<typeof import("0")>
>'./0' : "./0"
>{} : {}
>{} : {}
const h = import('./0', { with: { type: "json" }},)
>h : Promise<typeof import("0")>
>import('./0', { with: { type: "json" }},) : Promise<typeof import("0")>
>'./0' : "./0"
>{ with: { type: "json" }} : { with: { type: string; }; }
>with : { type: string; }
>{ type: "json" } : { type: string; }
>type : string
>"json" : "json"
@@ -0,0 +1,34 @@
1.ts(1,22): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(2,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(3,21): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(4,27): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2.ts(1,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2.ts(2,38): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
==== 0.ts (0 errors) ====
export const a = 1;
export const b = 2;
==== 1.ts (4 errors) ====
export {} from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
export { a, b } from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
export * from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
export * as ns from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
==== 2.ts (2 errors) ====
export { a, b } from './0' with {}
~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
export { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
@@ -0,0 +1,69 @@
//// [tests/cases/conformance/importAttributes/importAttributes2.ts] ////
//// [0.ts]
export const a = 1;
export const b = 2;
//// [1.ts]
export {} from './0' with { type: "json" }
export { a, b } from './0' with { type: "json" }
export * from './0' with { type: "json" }
export * as ns from './0' with { type: "json" }
//// [2.ts]
export { a, b } from './0' with {}
export { a as c, b as d } from './0' with { 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;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (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';
@@ -0,0 +1,30 @@
//// [tests/cases/conformance/importAttributes/importAttributes2.ts] ////
=== 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))
=== 1.ts ===
export {} from './0' with { type: "json" }
export { a, b } from './0' with { type: "json" }
>a : Symbol(a, Decl(1.ts, 1, 8))
>b : Symbol(b, Decl(1.ts, 1, 11))
export * from './0' with { type: "json" }
export * as ns from './0' with { type: "json" }
>ns : Symbol(ns, Decl(1.ts, 3, 6))
=== 2.ts ===
export { a, b } from './0' with {}
>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' with { 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))
@@ -0,0 +1,41 @@
//// [tests/cases/conformance/importAttributes/importAttributes2.ts] ////
=== 0.ts ===
export const a = 1;
>a : 1
>1 : 1
export const b = 2;
>b : 2
>2 : 2
=== 1.ts ===
export {} from './0' with { type: "json" }
>type : any
export { a, b } from './0' with { type: "json" }
>a : 1
>b : 2
>type : any
export * from './0' with { type: "json" }
>type : any
export * as ns from './0' with { type: "json" }
>ns : typeof import("0")
>type : any
=== 2.ts ===
export { a, b } from './0' with {}
>a : 1
>b : 2
export { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
>a : 1
>c : 1
>b : 2
>d : 2
>a : any
>b : any
>c : any
@@ -0,0 +1,34 @@
1.ts(1,22): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(2,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(3,21): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(4,27): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2.ts(1,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2.ts(2,38): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
==== 0.ts (0 errors) ====
export const a = 1;
export const b = 2;
==== 1.ts (4 errors) ====
export {} from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
export { a, b } from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
export * from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
export * as ns from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
==== 2.ts (2 errors) ====
export { a, b } from './0' with {}
~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
export { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
@@ -0,0 +1,41 @@
//// [tests/cases/conformance/importAttributes/importAttributes2.ts] ////
//// [0.ts]
export const a = 1;
export const b = 2;
//// [1.ts]
export {} from './0' with { type: "json" }
export { a, b } from './0' with { type: "json" }
export * from './0' with { type: "json" }
export * as ns from './0' with { type: "json" }
//// [2.ts]
export { a, b } from './0' with {}
export { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
//// [0.js]
export const a = 1;
export const b = 2;
//// [1.js]
export { a, b } from './0' with { type: "json" };
export * from './0' with { type: "json" };
import * as ns_1 from './0' with { type: "json" };
export { ns_1 as ns };
//// [2.js]
export { a, b } from './0' with {};
export { a as c, b as d } from './0' with { 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';
@@ -0,0 +1,30 @@
//// [tests/cases/conformance/importAttributes/importAttributes2.ts] ////
=== 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))
=== 1.ts ===
export {} from './0' with { type: "json" }
export { a, b } from './0' with { type: "json" }
>a : Symbol(a, Decl(1.ts, 1, 8))
>b : Symbol(b, Decl(1.ts, 1, 11))
export * from './0' with { type: "json" }
export * as ns from './0' with { type: "json" }
>ns : Symbol(ns, Decl(1.ts, 3, 6))
=== 2.ts ===
export { a, b } from './0' with {}
>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' with { 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))
@@ -0,0 +1,41 @@
//// [tests/cases/conformance/importAttributes/importAttributes2.ts] ////
=== 0.ts ===
export const a = 1;
>a : 1
>1 : 1
export const b = 2;
>b : 2
>2 : 2
=== 1.ts ===
export {} from './0' with { type: "json" }
>type : any
export { a, b } from './0' with { type: "json" }
>a : 1
>b : 2
>type : any
export * from './0' with { type: "json" }
>type : any
export * as ns from './0' with { type: "json" }
>ns : typeof import("0")
>type : any
=== 2.ts ===
export { a, b } from './0' with {}
>a : 1
>b : 2
export { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
>a : 1
>c : 1
>b : 2
>d : 2
>a : any
>b : any
>c : any
@@ -0,0 +1,40 @@
//// [tests/cases/conformance/importAttributes/importAttributes2.ts] ////
//// [0.ts]
export const a = 1;
export const b = 2;
//// [1.ts]
export {} from './0' with { type: "json" }
export { a, b } from './0' with { type: "json" }
export * from './0' with { type: "json" }
export * as ns from './0' with { type: "json" }
//// [2.ts]
export { a, b } from './0' with {}
export { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
//// [0.js]
export const a = 1;
export const b = 2;
//// [1.js]
export { a, b } from './0' with { type: "json" };
export * from './0' with { type: "json" };
export * as ns from './0' with { type: "json" };
//// [2.js]
export { a, b } from './0' with {};
export { a as c, b as d } from './0' with { 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';
@@ -0,0 +1,30 @@
//// [tests/cases/conformance/importAttributes/importAttributes2.ts] ////
=== 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))
=== 1.ts ===
export {} from './0' with { type: "json" }
export { a, b } from './0' with { type: "json" }
>a : Symbol(a, Decl(1.ts, 1, 8))
>b : Symbol(b, Decl(1.ts, 1, 11))
export * from './0' with { type: "json" }
export * as ns from './0' with { type: "json" }
>ns : Symbol(ns, Decl(1.ts, 3, 6))
=== 2.ts ===
export { a, b } from './0' with {}
>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' with { 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))
@@ -0,0 +1,41 @@
//// [tests/cases/conformance/importAttributes/importAttributes2.ts] ////
=== 0.ts ===
export const a = 1;
>a : 1
>1 : 1
export const b = 2;
>b : 2
>2 : 2
=== 1.ts ===
export {} from './0' with { type: "json" }
>type : error
export { a, b } from './0' with { type: "json" }
>a : 1
>b : 2
>type : error
export * from './0' with { type: "json" }
>type : error
export * as ns from './0' with { type: "json" }
>ns : typeof import("0")
>type : error
=== 2.ts ===
export { a, b } from './0' with {}
>a : 1
>b : 2
export { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
>a : 1
>c : 1
>b : 2
>d : 2
>a : error
>b : error
>c : error
@@ -0,0 +1,25 @@
1.ts(1,27): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
1.ts(2,30): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2.ts(1,31): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
2.ts(2,33): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
==== 0.ts (0 errors) ====
export interface I { }
==== 1.ts (2 errors) ====
export type {} from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
export type { I } from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
==== 2.ts (2 errors) ====
import type { I } from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
import type * as foo from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
@@ -0,0 +1,30 @@
//// [tests/cases/conformance/importAttributes/importAttributes3.ts] ////
//// [0.ts]
export interface I { }
//// [1.ts]
export type {} from './0' with { type: "json" }
export type { I } from './0' with { type: "json" }
//// [2.ts]
import type { I } from './0' with { type: "json" }
import type * as foo from './0' with { 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 {};
@@ -0,0 +1,18 @@
//// [tests/cases/conformance/importAttributes/importAttributes3.ts] ////
=== 0.ts ===
export interface I { }
>I : Symbol(I, Decl(0.ts, 0, 0))
=== 1.ts ===
export type {} from './0' with { type: "json" }
export type { I } from './0' with { type: "json" }
>I : Symbol(I, Decl(1.ts, 1, 13))
=== 2.ts ===
import type { I } from './0' with { type: "json" }
>I : Symbol(I, Decl(2.ts, 0, 13))
import type * as foo from './0' with { type: "json" }
>foo : Symbol(foo, Decl(2.ts, 1, 11))
@@ -0,0 +1,23 @@
//// [tests/cases/conformance/importAttributes/importAttributes3.ts] ////
=== 0.ts ===
export interface I { }
=== 1.ts ===
export type {} from './0' with { type: "json" }
>type : any
export type { I } from './0' with { type: "json" }
>I : import("0").I
>type : any
=== 2.ts ===
import type { I } from './0' with { type: "json" }
>I : I
>type : any
import type * as foo from './0' with { type: "json" }
>foo : typeof foo
>type : any
@@ -0,0 +1,25 @@
1.ts(1,27): error TS2857: Import attributes cannot be used with type-only imports or exports.
1.ts(2,30): error TS2857: Import attributes cannot be used with type-only imports or exports.
2.ts(1,31): error TS2857: Import attributes cannot be used with type-only imports or exports.
2.ts(2,33): error TS2857: Import attributes cannot be used with type-only imports or exports.
==== 0.ts (0 errors) ====
export interface I { }
==== 1.ts (2 errors) ====
export type {} from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2857: Import attributes cannot be used with type-only imports or exports.
export type { I } from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2857: Import attributes cannot be used with type-only imports or exports.
==== 2.ts (2 errors) ====
import type { I } from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2857: Import attributes cannot be used with type-only imports or exports.
import type * as foo from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2857: Import attributes cannot be used with type-only imports or exports.
@@ -0,0 +1,30 @@
//// [tests/cases/conformance/importAttributes/importAttributes3.ts] ////
//// [0.ts]
export interface I { }
//// [1.ts]
export type {} from './0' with { type: "json" }
export type { I } from './0' with { type: "json" }
//// [2.ts]
import type { I } from './0' with { type: "json" }
import type * as foo from './0' with { 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 {};
@@ -0,0 +1,18 @@
//// [tests/cases/conformance/importAttributes/importAttributes3.ts] ////
=== 0.ts ===
export interface I { }
>I : Symbol(I, Decl(0.ts, 0, 0))
=== 1.ts ===
export type {} from './0' with { type: "json" }
export type { I } from './0' with { type: "json" }
>I : Symbol(I, Decl(1.ts, 1, 13))
=== 2.ts ===
import type { I } from './0' with { type: "json" }
>I : Symbol(I, Decl(2.ts, 0, 13))
import type * as foo from './0' with { type: "json" }
>foo : Symbol(foo, Decl(2.ts, 1, 11))
@@ -0,0 +1,23 @@
//// [tests/cases/conformance/importAttributes/importAttributes3.ts] ////
=== 0.ts ===
export interface I { }
=== 1.ts ===
export type {} from './0' with { type: "json" }
>type : any
export type { I } from './0' with { type: "json" }
>I : import("0").I
>type : any
=== 2.ts ===
import type { I } from './0' with { type: "json" }
>I : I
>type : any
import type * as foo from './0' with { type: "json" }
>foo : typeof foo
>type : any
@@ -0,0 +1,10 @@
importAttributes4.ts(1,20): error TS2307: Cannot find module './first' or its corresponding type declarations.
importAttributes4.ts(1,34): error TS1005: '{' expected.
==== importAttributes4.ts (2 errors) ====
import * as f from "./first" with
~~~~~~~~~
!!! error TS2307: Cannot find module './first' or its corresponding type declarations.
!!! error TS1005: '{' expected.
@@ -0,0 +1,8 @@
//// [tests/cases/conformance/importAttributes/importAttributes4.ts] ////
//// [importAttributes4.ts]
import * as f from "./first" with
//// [importAttributes4.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
//// [tests/cases/conformance/importAttributes/importAttributes4.ts] ////
=== importAttributes4.ts ===
import * as f from "./first" with
>f : Symbol(f, Decl(importAttributes4.ts, 0, 6))
@@ -0,0 +1,6 @@
//// [tests/cases/conformance/importAttributes/importAttributes4.ts] ////
=== importAttributes4.ts ===
import * as f from "./first" with
>f : any
@@ -0,0 +1,11 @@
importAttributes5.ts(1,20): error TS2307: Cannot find module './first' or its corresponding type declarations.
importAttributes5.ts(1,36): error TS1005: '}' expected.
==== importAttributes5.ts (2 errors) ====
import * as f from "./first" with {
~~~~~~~~~
!!! error TS2307: Cannot find module './first' or its corresponding type declarations.
!!! error TS1005: '}' expected.
!!! related TS1007 importAttributes5.ts:1:35: The parser expected to find a '}' to match the '{' token here.
@@ -0,0 +1,8 @@
//// [tests/cases/conformance/importAttributes/importAttributes5.ts] ////
//// [importAttributes5.ts]
import * as f from "./first" with {
//// [importAttributes5.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
//// [tests/cases/conformance/importAttributes/importAttributes5.ts] ////
=== importAttributes5.ts ===
import * as f from "./first" with {
>f : Symbol(f, Decl(importAttributes5.ts, 0, 6))
@@ -0,0 +1,6 @@
//// [tests/cases/conformance/importAttributes/importAttributes5.ts] ////
=== importAttributes5.ts ===
import * as f from "./first" with {
>f : any
@@ -0,0 +1,28 @@
mod.mts(1,51): error TS2858: Import attribute values must be string literal expressions.
mod.mts(2,51): error TS2858: Import attribute values must be string literal expressions.
mod.mts(3,51): error TS2858: Import attribute values must be string literal expressions.
mod.mts(4,51): error TS2858: Import attribute values must be string literal expressions.
mod.mts(5,51): error TS2858: Import attribute values must be string literal expressions.
mod.mts(6,65): error TS2858: Import attribute values must be string literal expressions.
==== mod.mts (6 errors) ====
import * as thing1 from "./mod.mjs" with { field: 0 };
~
!!! error TS2858: Import attribute values must be string literal expressions.
import * as thing2 from "./mod.mjs" with { field: `a` };
~~~
!!! error TS2858: Import attribute values must be string literal expressions.
import * as thing3 from "./mod.mjs" with { field: /a/g };
~~~~
!!! error TS2858: Import attribute values must be string literal expressions.
import * as thing4 from "./mod.mjs" with { field: ["a"] };
~~~~~
!!! error TS2858: Import attribute values must be string literal expressions.
import * as thing5 from "./mod.mjs" with { field: { a: 0 } };
~~~~~~~~
!!! error TS2858: Import attribute values must be string literal expressions.
import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() };
~~~~~~~~~~~~~
!!! error TS2858: Import attribute values must be string literal expressions.
@@ -0,0 +1,13 @@
//// [tests/cases/conformance/importAttributes/importAttributes6.ts] ////
//// [mod.mts]
import * as thing1 from "./mod.mjs" with { field: 0 };
import * as thing2 from "./mod.mjs" with { field: `a` };
import * as thing3 from "./mod.mjs" with { field: /a/g };
import * as thing4 from "./mod.mjs" with { field: ["a"] };
import * as thing5 from "./mod.mjs" with { field: { a: 0 } };
import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() };
//// [mod.mjs]
export {};
@@ -0,0 +1,24 @@
//// [tests/cases/conformance/importAttributes/importAttributes6.ts] ////
=== mod.mts ===
import * as thing1 from "./mod.mjs" with { field: 0 };
>thing1 : Symbol(thing1, Decl(mod.mts, 0, 6))
import * as thing2 from "./mod.mjs" with { field: `a` };
>thing2 : Symbol(thing2, Decl(mod.mts, 1, 6))
import * as thing3 from "./mod.mjs" with { field: /a/g };
>thing3 : Symbol(thing3, Decl(mod.mts, 2, 6))
import * as thing4 from "./mod.mjs" with { field: ["a"] };
>thing4 : Symbol(thing4, Decl(mod.mts, 3, 6))
import * as thing5 from "./mod.mjs" with { field: { a: 0 } };
>thing5 : Symbol(thing5, Decl(mod.mts, 4, 6))
>a : Symbol(a, Decl(mod.mts, 4, 51))
import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() };
>thing6 : Symbol(thing6, Decl(mod.mts, 5, 6))
>0..toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
@@ -0,0 +1,38 @@
//// [tests/cases/conformance/importAttributes/importAttributes6.ts] ////
=== mod.mts ===
import * as thing1 from "./mod.mjs" with { field: 0 };
>thing1 : typeof thing1
>field : any
import * as thing2 from "./mod.mjs" with { field: `a` };
>thing2 : typeof thing1
>field : any
import * as thing3 from "./mod.mjs" with { field: /a/g };
>thing3 : typeof thing1
>field : any
>/a/g : RegExp
import * as thing4 from "./mod.mjs" with { field: ["a"] };
>thing4 : typeof thing1
>field : any
>["a"] : string[]
>"a" : "a"
import * as thing5 from "./mod.mjs" with { field: { a: 0 } };
>thing5 : typeof thing1
>field : any
>{ a: 0 } : { a: number; }
>a : number
>0 : 0
import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() };
>thing6 : typeof thing1
>type : any
>field : any
>0..toString() : string
>0..toString : (radix?: number) => string
>0. : 0
>toString : (radix?: number) => string
@@ -0,0 +1,75 @@
//// [tests/cases/conformance/importAttributes/importAttributes7.ts] ////
//// [a.ts]
export default {
a: "a",
b: "b",
1: "1",
}
//// [b.ts]
import a from "./a" with { a: "a", "b": "b" };
export async function f() {
const a = import("./a", {
with: { a: "a", "b": "b" },
});
a;
}
//// [a.js]
export default {
a: "a",
b: "b",
1: "1",
};
//// [b.js]
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
export function f() {
return __awaiter(this, void 0, void 0, function () {
var a;
return __generator(this, function (_a) {
a = import("./a", {
with: { a: "a", "b": "b" },
});
a;
return [2 /*return*/];
});
});
}
@@ -0,0 +1,35 @@
//// [tests/cases/conformance/importAttributes/importAttributes7.ts] ////
=== /a.ts ===
export default {
a: "a",
>a : Symbol(a, Decl(a.ts, 0, 16))
b: "b",
>b : Symbol(b, Decl(a.ts, 1, 11))
1: "1",
>1 : Symbol(1, Decl(a.ts, 2, 11))
}
=== /b.ts ===
import a from "./a" with { a: "a", "b": "b" };
>a : Symbol(a, Decl(b.ts, 0, 6))
export async function f() {
>f : Symbol(f, Decl(b.ts, 0, 46))
const a = import("./a", {
>a : Symbol(a, Decl(b.ts, 3, 9))
>"./a" : Symbol("/a", Decl(a.ts, 0, 0))
with: { a: "a", "b": "b" },
>with : Symbol(with, Decl(b.ts, 3, 29))
>a : Symbol(a, Decl(b.ts, 4, 15))
>"b" : Symbol("b", Decl(b.ts, 4, 23))
});
a;
>a : Symbol(a, Decl(b.ts, 3, 9))
}
@@ -0,0 +1,46 @@
//// [tests/cases/conformance/importAttributes/importAttributes7.ts] ////
=== /a.ts ===
export default {
>{ a: "a", b: "b", 1: "1",} : { a: string; b: string; 1: string; }
a: "a",
>a : string
>"a" : "a"
b: "b",
>b : string
>"b" : "b"
1: "1",
>1 : string
>"1" : "1"
}
=== /b.ts ===
import a from "./a" with { a: "a", "b": "b" };
>a : { a: string; b: string; 1: string; }
>a : error
export async function f() {
>f : () => Promise<void>
const a = import("./a", {
>a : Promise<typeof import("/a")>
>import("./a", { with: { a: "a", "b": "b" }, }) : Promise<typeof import("/a")>
>"./a" : "./a"
>{ with: { a: "a", "b": "b" }, } : { with: { a: string; b: string; }; }
with: { a: "a", "b": "b" },
>with : { a: string; b: string; }
>{ a: "a", "b": "b" } : { a: string; b: string; }
>a : string
>"a" : "a"
>"b" : string
>"b" : "b"
});
a;
>a : Promise<typeof import("/a")>
}
@@ -0,0 +1,19 @@
//// [tests/cases/conformance/importAttributes/importAttributes8.ts] ////
//// [a.ts]
export default {
a: "a",
b: "b",
}
//// [b.ts]
import a from "./a" with { a: "a", "b": "b" }; // ok
//// [a.js]
export default {
a: "a",
b: "b",
};
//// [b.js]
export {};
@@ -0,0 +1,15 @@
//// [tests/cases/conformance/importAttributes/importAttributes8.ts] ////
=== /a.ts ===
export default {
a: "a",
>a : Symbol(a, Decl(a.ts, 0, 16))
b: "b",
>b : Symbol(b, Decl(a.ts, 1, 11))
}
=== /b.ts ===
import a from "./a" with { a: "a", "b": "b" }; // ok
>a : Symbol(a, Decl(b.ts, 0, 6))
@@ -0,0 +1,20 @@
//// [tests/cases/conformance/importAttributes/importAttributes8.ts] ////
=== /a.ts ===
export default {
>{ a: "a", b: "b",} : { a: string; b: string; }
a: "a",
>a : string
>"a" : "a"
b: "b",
>b : string
>"b" : "b"
}
=== /b.ts ===
import a from "./a" with { a: "a", "b": "b" }; // ok
>a : { a: string; b: string; }
>a : error
@@ -1,6 +1,6 @@
importCallExpressionGrammarError.ts(5,8): error TS1325: Argument of dynamic import cannot be spread element.
importCallExpressionGrammarError.ts(7,17): error TS1325: Argument of dynamic import cannot be spread element.
importCallExpressionGrammarError.ts(8,12): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
importCallExpressionGrammarError.ts(8,12): message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
importCallExpressionGrammarError.ts(9,19): error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations.
importCallExpressionGrammarError.ts(9,35): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
importCallExpressionGrammarError.ts(9,35): error TS2559: Type '"secondModule"' has no properties in common with type 'ImportCallOptions'.
@@ -20,7 +20,7 @@ importCallExpressionGrammarError.ts(9,35): error TS2559: Type '"secondModule"' h
!!! error TS1325: Argument of dynamic import cannot be spread element.
const p2 = import();
~~~~~~~~
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional set of attributes as arguments
const p4 = import("pathToModule", "secondModule");
~~~~~~~~~~~~~~
!!! error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations.
@@ -157,8 +157,8 @@ export declare const e: typeof import("inner/mjs");
export declare const a: Promise<{
default: typeof import("./index.cjs");
}>;
export declare const b: Promise<typeof import("./index.mjs", { assert: { "resolution-mode": "import" } })>;
export declare const c: Promise<typeof import("./index.js", { assert: { "resolution-mode": "import" } })>;
export declare const b: Promise<typeof import("./index.mjs", { with: { "resolution-mode": "import" } })>;
export declare const c: Promise<typeof import("./index.js", { with: { "resolution-mode": "import" } })>;
export declare const f: Promise<{
default: typeof import("inner");
cjsMain: true;
@@ -168,4 +168,4 @@ export declare const d: Promise<{
default: typeof import("inner/cjs");
cjsNonmain: true;
}>;
export declare const e: Promise<typeof import("inner/mjs", { assert: { "resolution-mode": "import" } })>;
export declare const e: Promise<typeof import("inner/mjs", { with: { "resolution-mode": "import" } })>;
@@ -100,13 +100,13 @@ export const a = import("package/cjs");
>"package/cjs" : "package/cjs"
export const b = import("package/mjs");
>b : Promise<typeof import("index", { assert: { "resolution-mode": "import" } })>
>import("package/mjs") : Promise<typeof import("index", { assert: { "resolution-mode": "import" } })>
>b : Promise<typeof import("index", { with: { "resolution-mode": "import" } })>
>import("package/mjs") : Promise<typeof import("index", { with: { "resolution-mode": "import" } })>
>"package/mjs" : "package/mjs"
export const c = import("package");
>c : Promise<typeof import("index", { assert: { "resolution-mode": "import" } })>
>import("package") : Promise<typeof import("index", { assert: { "resolution-mode": "import" } })>
>c : Promise<typeof import("index", { with: { "resolution-mode": "import" } })>
>import("package") : Promise<typeof import("index", { with: { "resolution-mode": "import" } })>
>"package" : "package"
export const f = import("inner");
@@ -122,8 +122,8 @@ export const d = import("inner/cjs");
>"inner/cjs" : "inner/cjs"
export const e = import("inner/mjs");
>e : Promise<typeof import("node_modules/inner/index", { assert: { "resolution-mode": "import" } })>
>import("inner/mjs") : Promise<typeof import("node_modules/inner/index", { assert: { "resolution-mode": "import" } })>
>e : Promise<typeof import("node_modules/inner/index", { with: { "resolution-mode": "import" } })>
>import("inner/mjs") : Promise<typeof import("node_modules/inner/index", { with: { "resolution-mode": "import" } })>
>"inner/mjs" : "inner/mjs"
=== node_modules/inner/index.d.ts ===
@@ -0,0 +1,25 @@
error TS2468: Cannot find global value 'Promise'.
index.ts(1,35): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
otherc.cts(1,35): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
otherc.cts(2,15): error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
!!! error TS2468: Cannot find global value 'Promise'.
==== index.ts (1 errors) ====
import json from "./package.json" with { type: "json" };
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
==== otherc.cts (2 errors) ====
import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
const json2 = import("./package.json", { with: { type: "json" } }); // should be fine
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
==== package.json (0 errors) ====
{
"name": "pkg",
"private": true,
"type": "module"
}
@@ -0,0 +1,21 @@
//// [tests/cases/conformance/node/nodeModulesImportAttributes.ts] ////
//// [index.ts]
import json from "./package.json" with { type: "json" };
//// [otherc.cts]
import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes
const json2 = import("./package.json", { with: { type: "json" } }); // should be fine
//// [package.json]
{
"name": "pkg",
"private": true,
"type": "module"
}
//// [index.js]
export {};
//// [otherc.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var json2 = import("./package.json", { with: { type: "json" } }); // should be fine
@@ -0,0 +1,28 @@
//// [tests/cases/conformance/node/nodeModulesImportAttributes.ts] ////
=== index.ts ===
import json from "./package.json" with { type: "json" };
>json : Symbol(json, Decl(index.ts, 0, 6))
=== otherc.cts ===
import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes
>json : Symbol(json, Decl(otherc.cts, 0, 6))
const json2 = import("./package.json", { with: { type: "json" } }); // should be fine
>json2 : Symbol(json2, Decl(otherc.cts, 1, 5))
>"./package.json" : Symbol("package", Decl(package.json, 0, 0))
>with : Symbol(with, Decl(otherc.cts, 1, 40))
>type : Symbol(type, Decl(otherc.cts, 1, 48))
=== package.json ===
{
"name": "pkg",
>"name" : Symbol("name", Decl(package.json, 0, 1))
"private": true,
>"private" : Symbol("private", Decl(package.json, 1, 18))
"type": "module"
>"type" : Symbol("type", Decl(package.json, 2, 20))
}
@@ -0,0 +1,39 @@
//// [tests/cases/conformance/node/nodeModulesImportAttributes.ts] ////
=== index.ts ===
import json from "./package.json" with { type: "json" };
>json : { name: string; private: boolean; type: string; }
>type : any
=== otherc.cts ===
import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes
>json : { name: string; private: boolean; type: string; }
>type : any
const json2 = import("./package.json", { with: { type: "json" } }); // should be fine
>json2 : Promise<{ default: { name: string; private: boolean; type: string; }; }>
>import("./package.json", { with: { type: "json" } }) : Promise<{ default: { name: string; private: boolean; type: string; }; }>
>"./package.json" : "./package.json"
>{ with: { type: "json" } } : { with: { type: string; }; }
>with : { type: string; }
>{ type: "json" } : { type: string; }
>type : string
>"json" : "json"
=== package.json ===
{
>{ "name": "pkg", "private": true, "type": "module"} : { name: string; private: boolean; type: string; }
"name": "pkg",
>"name" : string
>"pkg" : "pkg"
"private": true,
>"private" : boolean
>true : true
"type": "module"
>"type" : string
>"module" : "module"
}
@@ -0,0 +1,22 @@
error TS2468: Cannot find global value 'Promise'.
otherc.cts(1,35): error TS2856: Import attributes are not allowed on statements that transpile to CommonJS 'require' calls.
otherc.cts(2,15): error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
!!! error TS2468: Cannot find global value 'Promise'.
==== index.ts (0 errors) ====
import json from "./package.json" with { type: "json" };
==== otherc.cts (2 errors) ====
import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2856: Import attributes are not allowed on statements that transpile to CommonJS 'require' calls.
const json2 = import("./package.json", { with: { type: "json" } }); // should be fine
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2712: A dynamic import call in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your '--lib' option.
==== package.json (0 errors) ====
{
"name": "pkg",
"private": true,
"type": "module"
}
@@ -0,0 +1,21 @@
//// [tests/cases/conformance/node/nodeModulesImportAttributes.ts] ////
//// [index.ts]
import json from "./package.json" with { type: "json" };
//// [otherc.cts]
import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes
const json2 = import("./package.json", { with: { type: "json" } }); // should be fine
//// [package.json]
{
"name": "pkg",
"private": true,
"type": "module"
}
//// [index.js]
export {};
//// [otherc.cjs]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var json2 = import("./package.json", { with: { type: "json" } }); // should be fine
@@ -0,0 +1,28 @@
//// [tests/cases/conformance/node/nodeModulesImportAttributes.ts] ////
=== index.ts ===
import json from "./package.json" with { type: "json" };
>json : Symbol(json, Decl(index.ts, 0, 6))
=== otherc.cts ===
import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes
>json : Symbol(json, Decl(otherc.cts, 0, 6))
const json2 = import("./package.json", { with: { type: "json" } }); // should be fine
>json2 : Symbol(json2, Decl(otherc.cts, 1, 5))
>"./package.json" : Symbol("package", Decl(package.json, 0, 0))
>with : Symbol(with, Decl(otherc.cts, 1, 40))
>type : Symbol(type, Decl(otherc.cts, 1, 48))
=== package.json ===
{
"name": "pkg",
>"name" : Symbol("name", Decl(package.json, 0, 1))
"private": true,
>"private" : Symbol("private", Decl(package.json, 1, 18))
"type": "module"
>"type" : Symbol("type", Decl(package.json, 2, 20))
}
@@ -0,0 +1,39 @@
//// [tests/cases/conformance/node/nodeModulesImportAttributes.ts] ////
=== index.ts ===
import json from "./package.json" with { type: "json" };
>json : { name: string; private: boolean; type: string; }
>type : any
=== otherc.cts ===
import json from "./package.json" with { type: "json" }; // should error, cjs mode imports don't support attributes
>json : { name: string; private: boolean; type: string; }
>type : any
const json2 = import("./package.json", { with: { type: "json" } }); // should be fine
>json2 : Promise<{ default: { name: string; private: boolean; type: string; }; }>
>import("./package.json", { with: { type: "json" } }) : Promise<{ default: { name: string; private: boolean; type: string; }; }>
>"./package.json" : "./package.json"
>{ with: { type: "json" } } : { with: { type: string; }; }
>with : { type: string; }
>{ type: "json" } : { type: string; }
>type : string
>"json" : "json"
=== package.json ===
{
>{ "name": "pkg", "private": true, "type": "module"} : { name: string; private: boolean; type: string; }
"name": "pkg",
>"name" : string
>"pkg" : "pkg"
"private": true,
>"private" : boolean
>true : true
"type": "module"
>"type" : string
>"module" : "module"
}

Some files were not shown because too many files have changed in this diff Show More