mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 10:40:34 -05:00
Allow import assertions on esm imports under module: nodenext (#46630)
* Allow import assertions on esm imports under module: nodenext * Changes to copy Co-authored-by: Andrew Branch <andrew@wheream.io>
This commit is contained in:
@@ -39695,8 +39695,12 @@ namespace ts {
|
||||
|
||||
function checkAssertClause(declaration: ImportDeclaration | ExportDeclaration) {
|
||||
if (declaration.assertClause) {
|
||||
if (moduleKind !== ModuleKind.ESNext) {
|
||||
return grammarErrorOnNode(declaration.assertClause, Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext);
|
||||
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);
|
||||
}
|
||||
|
||||
if (isImportDeclaration(declaration) ? declaration.importClause?.isTypeOnly : declaration.isTypeOnly) {
|
||||
@@ -43906,13 +43910,13 @@ namespace ts {
|
||||
}
|
||||
|
||||
const nodeArguments = node.arguments;
|
||||
if (moduleKind !== ModuleKind.ESNext) {
|
||||
if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.NodeNext) {
|
||||
// We are allowed trailing comma after proposal-import-assertions.
|
||||
checkGrammarForDisallowedTrailingComma(nodeArguments);
|
||||
|
||||
if (nodeArguments.length > 1) {
|
||||
const assertionArgument = nodeArguments[1];
|
||||
return grammarErrorOnNode(assertionArgument, Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext);
|
||||
return grammarErrorOnNode(assertionArgument, Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext_or_nodenext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -924,7 +924,7 @@
|
||||
"category": "Error",
|
||||
"code": 1323
|
||||
},
|
||||
"Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.": {
|
||||
"Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.": {
|
||||
"category": "Error",
|
||||
"code": 1324
|
||||
},
|
||||
@@ -3333,7 +3333,7 @@
|
||||
"category": "Error",
|
||||
"code": 2820
|
||||
},
|
||||
"Import assertions are only supported when the '--module' option is set to 'esnext'.": {
|
||||
"Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.": {
|
||||
"category": "Error",
|
||||
"code": 2821
|
||||
},
|
||||
@@ -3353,6 +3353,10 @@
|
||||
"category": "Error",
|
||||
"code": 2835
|
||||
},
|
||||
"Import assertions are not allowed on statements that transpile to commonjs 'require' calls.": {
|
||||
"category": "Error",
|
||||
"code": 2836
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
|
||||
Reference in New Issue
Block a user