mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 11:35:42 -06:00
Allow dynamic import attributes in --module preserve (#59005)
This commit is contained in:
parent
6c01f6c584
commit
fa4f2e5148
@ -51914,13 +51914,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
}
|
||||
|
||||
const nodeArguments = node.arguments;
|
||||
if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.NodeNext && moduleKind !== ModuleKind.Node16) {
|
||||
if (moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.NodeNext && moduleKind !== ModuleKind.Node16 && moduleKind !== ModuleKind.Preserve) {
|
||||
// We are allowed trailing comma after proposal-import-assertions.
|
||||
checkGrammarForDisallowedTrailingComma(nodeArguments);
|
||||
|
||||
if (nodeArguments.length > 1) {
|
||||
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);
|
||||
return grammarErrorOnNode(importAttributesArgument, Diagnostics.Dynamic_imports_only_support_a_second_argument_when_the_module_option_is_set_to_esnext_node16_nodenext_or_preserve);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1028,7 +1028,7 @@
|
||||
"category": "Error",
|
||||
"code": 1323
|
||||
},
|
||||
"Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.": {
|
||||
"Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.": {
|
||||
"category": "Error",
|
||||
"code": 1324
|
||||
},
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
1.ts(3,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'.
|
||||
2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'.
|
||||
2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'.
|
||||
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(2,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(3,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(4,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(5,26): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(7,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
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(9,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(10,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(10,52): error TS1009: Trailing comma not allowed.
|
||||
|
||||
|
||||
@ -49,29 +49,29 @@
|
||||
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', 'node16', or 'nodenext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
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', 'node16', or 'nodenext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
const d = import('./0', { assert: {} })
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
const dd = import('./0', {})
|
||||
~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
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'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
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'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
const h = import('./0', { assert: { type: "json" }},)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
~
|
||||
!!! error TS1009: Trailing comma not allowed.
|
||||
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
1.ts(3,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'.
|
||||
2.ts(1,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'.
|
||||
2.ts(2,38): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'nodenext', or 'preserve'.
|
||||
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(2,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(3,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(4,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(5,26): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(7,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
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(9,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(10,25): error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
3.ts(10,50): error TS1009: Trailing comma not allowed.
|
||||
|
||||
|
||||
@ -47,29 +47,29 @@
|
||||
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'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
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'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
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'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
const dd = import('./0', {})
|
||||
~~
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', or 'nodenext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
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'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
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'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
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 TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
~
|
||||
!!! error TS1009: Trailing comma not allowed.
|
||||
|
||||
@ -2,7 +2,7 @@ importCallExpressionGrammarError.ts(5,8): error TS1325: Argument of dynamic impo
|
||||
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 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 TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
importCallExpressionGrammarError.ts(9,35): error TS2559: Type '"secondModule"' has no properties in common with type 'ImportCallOptions'.
|
||||
|
||||
|
||||
@ -25,6 +25,6 @@ importCallExpressionGrammarError.ts(9,35): error TS2559: Type '"secondModule"' h
|
||||
~~~~~~~~~~~~~~
|
||||
!!! 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', 'node16', or 'nodenext'.
|
||||
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'nodenext', or 'preserve'.
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2559: Type '"secondModule"' has no properties in common with type 'ImportCallOptions'.
|
||||
12
tests/cases/compiler/modulePreserve5.ts
Normal file
12
tests/cases/compiler/modulePreserve5.ts
Normal file
@ -0,0 +1,12 @@
|
||||
// @module: preserve
|
||||
// @target: esnext
|
||||
// @resolveJsonModule: true
|
||||
// @noEmit: true
|
||||
// @noTypesAndSymbols: true
|
||||
|
||||
// @Filename: data.json
|
||||
{}
|
||||
|
||||
// @Filename: main.ts
|
||||
import data1 from "./data.json" with { type: "json" };
|
||||
const data2 = await import("./data.json", { with: { type: "json" } });
|
||||
Loading…
x
Reference in New Issue
Block a user