mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00: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:
co-authored by
Andrew Branch
parent
b8f8fd7a3e
commit
de23842e45
@@ -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",
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
tests/cases/conformance/importAssertion/1.ts(1,14): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(3,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(2,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(3,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(4,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(5,26): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(7,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(1,14): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(3,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(2,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(3,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(4,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(5,26): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(7,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(8,11): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
|
||||
tests/cases/conformance/importAssertion/3.ts(9,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(10,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(9,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(10,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comma not allowed.
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@ tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comm
|
||||
==== tests/cases/conformance/importAssertion/1.ts (3 errors) ====
|
||||
import './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
import { a, b } from './0' assert { "type": "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
import * as foo from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
a;
|
||||
b;
|
||||
foo.a;
|
||||
@@ -36,10 +36,10 @@ tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comm
|
||||
==== tests/cases/conformance/importAssertion/2.ts (2 errors) ====
|
||||
import { a, b } from './0' assert {}
|
||||
~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
a;
|
||||
b;
|
||||
c;
|
||||
@@ -49,29 +49,29 @@ tests/cases/conformance/importAssertion/3.ts(10,52): error TS1009: Trailing comm
|
||||
const a = import('./0')
|
||||
const b = import('./0', { assert: { type: "json" } })
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
const c = import('./0', { assert: { type: "json", ttype: "typo" } })
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
const d = import('./0', { assert: {} })
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
const dd = import('./0', {})
|
||||
~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' 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'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
const f = import()
|
||||
~~~~~~~~
|
||||
!!! message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
|
||||
const g = import('./0', {}, {})
|
||||
~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
const h = import('./0', { assert: { type: "json" }},)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
~
|
||||
!!! error TS1009: Trailing comma not allowed.
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
tests/cases/conformance/importAssertion/1.ts(1,14): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(3,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(1,14): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(3,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/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', 'node12', or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/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', 'node12', or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/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', 'node12', or 'nodenext'.
|
||||
@@ -21,13 +21,13 @@ tests/cases/conformance/importAssertion/3.ts(10,11): error TS1323: Dynamic impor
|
||||
==== tests/cases/conformance/importAssertion/1.ts (3 errors) ====
|
||||
import './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
import { a, b } from './0' assert { "type": "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
import * as foo from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
a;
|
||||
b;
|
||||
foo.a;
|
||||
@@ -36,10 +36,10 @@ tests/cases/conformance/importAssertion/3.ts(10,11): error TS1323: Dynamic impor
|
||||
==== tests/cases/conformance/importAssertion/2.ts (2 errors) ====
|
||||
import { a, b } from './0' assert {}
|
||||
~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
a;
|
||||
b;
|
||||
c;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
tests/cases/conformance/importAssertion/1.ts(1,22): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(3,21): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(4,27): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(1,22): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(3,21): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(4,27): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/importAssertion/0.ts (0 errors) ====
|
||||
@@ -13,22 +13,22 @@ tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import asserti
|
||||
==== tests/cases/conformance/importAssertion/1.ts (4 errors) ====
|
||||
export {} from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
export { a, b } from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
export * from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
export * as ns from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
|
||||
==== tests/cases/conformance/importAssertion/2.ts (2 errors) ====
|
||||
export { a, b } from './0' assert {}
|
||||
~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
tests/cases/conformance/importAssertion/1.ts(1,22): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(3,21): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(4,27): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(1,22): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(3,21): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(4,27): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/importAssertion/0.ts (0 errors) ====
|
||||
@@ -13,22 +13,22 @@ tests/cases/conformance/importAssertion/2.ts(2,38): error TS2821: Import asserti
|
||||
==== tests/cases/conformance/importAssertion/1.ts (4 errors) ====
|
||||
export {} from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
export { a, b } from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
export * from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
export * as ns from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
|
||||
==== tests/cases/conformance/importAssertion/2.ts (2 errors) ====
|
||||
export { a, b } from './0' assert {}
|
||||
~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
export { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
tests/cases/conformance/importAssertion/1.ts(1,27): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(2,30): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(1,31): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(2,33): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(1,27): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/1.ts(2,30): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(1,31): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/importAssertion/2.ts(2,33): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/importAssertion/0.ts (0 errors) ====
|
||||
@@ -10,17 +10,17 @@ tests/cases/conformance/importAssertion/2.ts(2,33): error TS2821: Import asserti
|
||||
==== tests/cases/conformance/importAssertion/1.ts (2 errors) ====
|
||||
export type {} from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
export type { I } from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
|
||||
==== tests/cases/conformance/importAssertion/2.ts (2 errors) ====
|
||||
import type { I } from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
import type * as foo from './0' assert { type: "json" }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext'.
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(5,8):
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(7,17): error TS1325: Argument of dynamic import cannot be spread element.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(8,12): message TS1450: Dynamic imports can only accept a module specifier and an optional assertion as arguments
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,19): error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,35): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,35): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,35): error TS2559: Type '"secondModule"' has no properties in common with type 'ImportCallOptions'.
|
||||
|
||||
|
||||
@@ -25,6 +25,6 @@ tests/cases/conformance/dynamicImport/importCallExpressionGrammarError.ts(9,35):
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2307: Cannot find module 'pathToModule' or its corresponding type declarations.
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2559: Type '"secondModule"' has no properties in common with type 'ImportCallOptions'.
|
||||
@@ -0,0 +1,28 @@
|
||||
tests/cases/conformance/node/index.ts(1,18): error TS7062: JSON imports are experimental in ES module mode imports.
|
||||
tests/cases/conformance/node/index.ts(1,35): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/node/otherc.cts(1,35): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
tests/cases/conformance/node/otherc.cts(2,22): error TS7062: JSON imports are experimental in ES module mode imports.
|
||||
tests/cases/conformance/node/otherc.cts(2,40): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/node/index.ts (2 errors) ====
|
||||
import json from "./package.json" assert { type: "json" };
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! error TS7062: JSON imports are experimental in ES module mode imports.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
==== tests/cases/conformance/node/otherc.cts (3 errors) ====
|
||||
import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! error TS7062: JSON imports are experimental in ES module mode imports.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext' or 'nodenext'.
|
||||
==== tests/cases/conformance/node/package.json (0 errors) ====
|
||||
{
|
||||
"name": "pkg",
|
||||
"private": true,
|
||||
"type": "module"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/conformance/node/nodeModulesImportAssertions.ts] ////
|
||||
|
||||
//// [index.ts]
|
||||
import json from "./package.json" assert { type: "json" };
|
||||
//// [otherc.cts]
|
||||
import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
|
||||
const json2 = import("./package.json", { assert: { 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 });
|
||||
const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
|
||||
@@ -0,0 +1,25 @@
|
||||
=== tests/cases/conformance/node/index.ts ===
|
||||
import json from "./package.json" assert { type: "json" };
|
||||
>json : Symbol(json, Decl(index.ts, 0, 6))
|
||||
|
||||
=== tests/cases/conformance/node/otherc.cts ===
|
||||
import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
|
||||
>json : Symbol(json, Decl(otherc.cts, 0, 6))
|
||||
|
||||
const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
|
||||
>json2 : Symbol(json2, Decl(otherc.cts, 1, 5))
|
||||
>"./package.json" : Symbol("tests/cases/conformance/node/package", Decl(package.json, 0, 0))
|
||||
>assert : Symbol(assert, Decl(otherc.cts, 1, 40))
|
||||
>type : Symbol(type, Decl(otherc.cts, 1, 50))
|
||||
|
||||
=== tests/cases/conformance/node/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,36 @@
|
||||
=== tests/cases/conformance/node/index.ts ===
|
||||
import json from "./package.json" assert { type: "json" };
|
||||
>json : { name: string; private: boolean; type: string; }
|
||||
>type : any
|
||||
|
||||
=== tests/cases/conformance/node/otherc.cts ===
|
||||
import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
|
||||
>json : { name: string; private: boolean; type: string; }
|
||||
>type : any
|
||||
|
||||
const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
|
||||
>json2 : Promise<{ default: { name: string; private: boolean; type: string; }; }>
|
||||
>import("./package.json", { assert: { type: "json" } }) : Promise<{ default: { name: string; private: boolean; type: string; }; }>
|
||||
>"./package.json" : "./package.json"
|
||||
>{ assert: { type: "json" } } : { assert: { type: string; }; }
|
||||
>assert : { type: string; }
|
||||
>{ type: "json" } : { type: string; }
|
||||
>type : string
|
||||
>"json" : "json"
|
||||
|
||||
=== tests/cases/conformance/node/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 @@
|
||||
tests/cases/conformance/node/index.ts(1,18): error TS7062: JSON imports are experimental in ES module mode imports.
|
||||
tests/cases/conformance/node/otherc.cts(1,35): error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls.
|
||||
tests/cases/conformance/node/otherc.cts(2,22): error TS7062: JSON imports are experimental in ES module mode imports.
|
||||
|
||||
|
||||
==== tests/cases/conformance/node/index.ts (1 errors) ====
|
||||
import json from "./package.json" assert { type: "json" };
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! error TS7062: JSON imports are experimental in ES module mode imports.
|
||||
==== tests/cases/conformance/node/otherc.cts (2 errors) ====
|
||||
import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2836: Import assertions are not allowed on statements that transpile to commonjs 'require' calls.
|
||||
const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
|
||||
~~~~~~~~~~~~~~~~
|
||||
!!! error TS7062: JSON imports are experimental in ES module mode imports.
|
||||
==== tests/cases/conformance/node/package.json (0 errors) ====
|
||||
{
|
||||
"name": "pkg",
|
||||
"private": true,
|
||||
"type": "module"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/conformance/node/nodeModulesImportAssertions.ts] ////
|
||||
|
||||
//// [index.ts]
|
||||
import json from "./package.json" assert { type: "json" };
|
||||
//// [otherc.cts]
|
||||
import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
|
||||
const json2 = import("./package.json", { assert: { 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 });
|
||||
const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
|
||||
@@ -0,0 +1,25 @@
|
||||
=== tests/cases/conformance/node/index.ts ===
|
||||
import json from "./package.json" assert { type: "json" };
|
||||
>json : Symbol(json, Decl(index.ts, 0, 6))
|
||||
|
||||
=== tests/cases/conformance/node/otherc.cts ===
|
||||
import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
|
||||
>json : Symbol(json, Decl(otherc.cts, 0, 6))
|
||||
|
||||
const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
|
||||
>json2 : Symbol(json2, Decl(otherc.cts, 1, 5))
|
||||
>"./package.json" : Symbol("tests/cases/conformance/node/package", Decl(package.json, 0, 0))
|
||||
>assert : Symbol(assert, Decl(otherc.cts, 1, 40))
|
||||
>type : Symbol(type, Decl(otherc.cts, 1, 50))
|
||||
|
||||
=== tests/cases/conformance/node/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,36 @@
|
||||
=== tests/cases/conformance/node/index.ts ===
|
||||
import json from "./package.json" assert { type: "json" };
|
||||
>json : { name: string; private: boolean; type: string; }
|
||||
>type : any
|
||||
|
||||
=== tests/cases/conformance/node/otherc.cts ===
|
||||
import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
|
||||
>json : { name: string; private: boolean; type: string; }
|
||||
>type : any
|
||||
|
||||
const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
|
||||
>json2 : Promise<{ default: { name: string; private: boolean; type: string; }; }>
|
||||
>import("./package.json", { assert: { type: "json" } }) : Promise<{ default: { name: string; private: boolean; type: string; }; }>
|
||||
>"./package.json" : "./package.json"
|
||||
>{ assert: { type: "json" } } : { assert: { type: string; }; }
|
||||
>assert : { type: string; }
|
||||
>{ type: "json" } : { type: string; }
|
||||
>type : string
|
||||
>"json" : "json"
|
||||
|
||||
=== tests/cases/conformance/node/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,13 @@
|
||||
// @module: node12,nodenext
|
||||
// @resolveJsonModule: true
|
||||
// @filename: index.ts
|
||||
import json from "./package.json" assert { type: "json" };
|
||||
// @filename: otherc.cts
|
||||
import json from "./package.json" assert { type: "json" }; // should error, cjs mode imports don't support assertions
|
||||
const json2 = import("./package.json", { assert: { type: "json" } }); // should be fine
|
||||
// @filename: package.json
|
||||
{
|
||||
"name": "pkg",
|
||||
"private": true,
|
||||
"type": "module"
|
||||
}
|
||||
Reference in New Issue
Block a user