Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48552,6 +48552,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return grammarErrorOnFirstToken(node, Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert);
}

if (!isImportAttributes && compilerOptions.ignoreDeprecations !== "6.0") {
grammarErrorOnFirstToken(node, Diagnostics.Import_assertions_have_been_replaced_by_import_attributes_Use_with_instead_of_assert);
}

if (declaration.moduleSpecifier && getEmitSyntaxForModuleSpecifierExpression(declaration.moduleSpecifier) === ModuleKind.CommonJS) {
return grammarErrorOnNode(
node,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// === documentHighlights ===
// === /tests/cases/fourslash/getOccurrencesNonStringImportAssertion.ts ===
// import * as react from "react" assert { cache: /*HIGHLIGHTS*/0 };
// import * as react from "react" with { cache: /*HIGHLIGHTS*/0 };
// react.Children;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
1.ts(1,14): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
1.ts(2,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
1.ts(3,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
2.ts(1,28): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
2.ts(2,38): error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
1.ts(1,14): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
1.ts(2,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
1.ts(3,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
2.ts(1,28): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
2.ts(2,38): error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', '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', 'node18', 'node20', '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', 'node18', 'node20', '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', 'node18', 'node20', 'nodenext', or 'preserve'.
Expand All @@ -11,50 +11,50 @@
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', 'node18', 'node20', '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', 'node18', 'node20', 'nodenext', or 'preserve'.
3.ts(10,52): error TS1009: Trailing comma not allowed.
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' assert { type: "json" }
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
import { a, b } from './0' assert { "type": "json" }
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
import * as foo from './0' assert { type: "json" }
import './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
import { a, b } from './0' with { "type": "json" }
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2821: Import assertions are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
import * as foo from './0' with { type: "json" }
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
a;
b;
foo.a;
foo.b;

==== 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', 'node18', 'node20', 'nodenext', or 'preserve'.
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', 'node18', 'node20', 'nodenext', or 'preserve'.
import { a, b } from './0' with {}
~~~~~~~
!!! error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
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', 'node18', 'node20', 'nodenext', or 'preserve'.
a;
b;
c;
d;

==== 3.ts (9 errors) ====
const a = import('./0')
const b = import('./0', { assert: { type: "json" } })
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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', 'node18', 'node20', 'nodenext', or 'preserve'.
const c = import('./0', { assert: { type: "json", ttype: "typo" } })
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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', 'node18', 'node20', 'nodenext', or 'preserve'.
const d = import('./0', { assert: {} })
~~~~~~~~~~~~~~
const d = import('./0', { with: {} })
~~~~~~~~~~~~
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'.
const dd = import('./0', {})
~~
Expand All @@ -69,10 +69,10 @@
const g = import('./0', {}, {})
~~
!!! error TS1324: Dynamic imports only support a second argument when the '--module' option is set to 'esnext', 'node16', 'node18', 'node20', 'nodenext', or 'preserve'.
const h = import('./0', { assert: { type: "json" }},)
~~~~~~~~~~~~~~~~~~~~~~~~~~~
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', 'node18', 'node20', 'nodenext', or 'preserve'.
~
~
!!! error TS1009: Trailing comma not allowed.


18 changes: 9 additions & 9 deletions tests/baselines/reference/importAssertion1(module=commonjs).js
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ export const a = 1;
export const b = 2;

//// [1.ts]
import './0' assert { type: "json" }
import { a, b } from './0' assert { "type": "json" }
import * as foo from './0' assert { type: "json" }
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' assert {}
import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }
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', { assert: { type: "json" } })
const c = import('./0', { assert: { type: "json", ttype: "typo" } })
const d = import('./0', { assert: {} })
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', { assert: { type: "json" }},)
const h = import('./0', { with: { type: "json" }},)



Expand Down
34 changes: 17 additions & 17 deletions tests/baselines/reference/importAssertion1(module=commonjs).symbols
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export const b = 2;
>b : Symbol(b, Decl(0.ts, 1, 12))

=== 1.ts ===
import './0' assert { type: "json" }
import { a, b } from './0' assert { "type": "json" }
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' assert { type: "json" }
import * as foo from './0' with { type: "json" }
>foo : Symbol(foo, Decl(1.ts, 2, 6))

a;
Expand All @@ -33,11 +33,11 @@ foo.b;
>b : Symbol(b, Decl(0.ts, 1, 12))

=== 2.ts ===
import { a, b } from './0' assert {}
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' assert { a: "a", b: "b", c: "c" }
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))
Expand All @@ -60,23 +60,23 @@ const a = import('./0')
>a : Symbol(a, Decl(3.ts, 0, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))

const b = import('./0', { assert: { type: "json" } })
const b = import('./0', { with: { type: "json" } })
>b : Symbol(b, Decl(3.ts, 1, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>assert : Symbol(assert, Decl(3.ts, 1, 25))
>type : Symbol(type, Decl(3.ts, 1, 35))
>with : Symbol(with, Decl(3.ts, 1, 25))
>type : Symbol(type, Decl(3.ts, 1, 33))

const c = import('./0', { assert: { type: "json", ttype: "typo" } })
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))
>assert : Symbol(assert, Decl(3.ts, 2, 25))
>type : Symbol(type, Decl(3.ts, 2, 35))
>ttype : Symbol(ttype, Decl(3.ts, 2, 49))
>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', { assert: {} })
const d = import('./0', { with: {} })
>d : Symbol(d, Decl(3.ts, 3, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>assert : Symbol(assert, Decl(3.ts, 3, 25))
>with : Symbol(with, Decl(3.ts, 3, 25))

const dd = import('./0', {})
>dd : Symbol(dd, Decl(3.ts, 4, 5))
Expand All @@ -97,10 +97,10 @@ const g = import('./0', {}, {})
>g : Symbol(g, Decl(3.ts, 8, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))

const h = import('./0', { assert: { type: "json" }},)
const h = import('./0', { with: { type: "json" }},)
>h : Symbol(h, Decl(3.ts, 9, 5))
>'./0' : Symbol("0", Decl(0.ts, 0, 0))
>assert : Symbol(assert, Decl(3.ts, 9, 25))
>type : Symbol(type, Decl(3.ts, 9, 35))
>with : Symbol(with, Decl(3.ts, 9, 25))
>type : Symbol(type, Decl(3.ts, 9, 33))


66 changes: 33 additions & 33 deletions tests/baselines/reference/importAssertion1(module=commonjs).types
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ export const b = 2;
> : ^

=== 1.ts ===
import './0' assert { type: "json" }
import './0' with { type: "json" }
>type : any
> : ^^^

import { a, b } from './0' assert { "type": "json" }
import { a, b } from './0' with { "type": "json" }
>a : 1
> : ^
>b : 2
> : ^

import * as foo from './0' assert { type: "json" }
import * as foo from './0' with { type: "json" }
>foo : typeof foo
> : ^^^^^^^^^^
>type : any
Expand Down Expand Up @@ -55,13 +55,13 @@ foo.b;
> : ^

=== 2.ts ===
import { a, b } from './0' assert {}
import { a, b } from './0' with {}
>a : 1
> : ^
>b : 2
> : ^

import { a as c, b as d } from './0' assert { a: "a", b: "b", c: "c" }
import { a as c, b as d } from './0' with { a: "a", b: "b", c: "c" }
>a : 1
> : ^
>c : 1
Expand Down Expand Up @@ -102,35 +102,35 @@ const a = import('./0')
>'./0' : "./0"
> : ^^^^^

const b = import('./0', { assert: { type: "json" } })
const b = import('./0', { with: { type: "json" } })
>b : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import('./0', { assert: { type: "json" } }) : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import('./0', { with: { type: "json" } }) : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>'./0' : "./0"
> : ^^^^^
>{ assert: { type: "json" } } : { assert: { type: string; }; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>assert : { type: string; }
> : ^^^^^^^^^^^^^^^^^
>{ with: { type: "json" } } : { with: { type: string; }; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>with : { type: string; }
> : ^^^^^^^^^^^^^^^^^
>{ type: "json" } : { type: string; }
> : ^^^^^^^^^^^^^^^^^
>type : string
> : ^^^^^^
>"json" : "json"
> : ^^^^^^

const c = import('./0', { assert: { type: "json", ttype: "typo" } })
const c = import('./0', { with: { type: "json", ttype: "typo" } })
>c : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import('./0', { assert: { type: "json", ttype: "typo" } }) : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import('./0', { with: { type: "json", ttype: "typo" } }) : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>'./0' : "./0"
> : ^^^^^
>{ assert: { type: "json", ttype: "typo" } } : { assert: { type: string; ttype: string; }; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>assert : { type: string; ttype: string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>{ 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
Expand All @@ -142,17 +142,17 @@ const c = import('./0', { assert: { type: "json", ttype: "typo" } })
>"typo" : "typo"
> : ^^^^^^

const d = import('./0', { assert: {} })
const d = import('./0', { with: {} })
>d : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import('./0', { assert: {} }) : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import('./0', { with: {} }) : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>'./0' : "./0"
> : ^^^^^
>{ assert: {} } : { assert: {}; }
> : ^^^^^^^^^^^^^^^
>assert : {}
> : ^^
>{ with: {} } : { with: {}; }
> : ^^^^^^^^^^^^^
>with : {}
> : ^^
>{} : {}
> : ^^

Expand Down Expand Up @@ -200,17 +200,17 @@ const g = import('./0', {}, {})
>{} : {}
> : ^^

const h = import('./0', { assert: { type: "json" }},)
const h = import('./0', { with: { type: "json" }},)
>h : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import('./0', { assert: { type: "json" }},) : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>import('./0', { with: { type: "json" }},) : Promise<typeof import("0")>
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>'./0' : "./0"
> : ^^^^^
>{ assert: { type: "json" }} : { assert: { type: string; }; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>assert : { type: string; }
> : ^^^^^^^^^^^^^^^^^
>{ with: { type: "json" }} : { with: { type: string; }; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>with : { type: string; }
> : ^^^^^^^^^^^^^^^^^
>{ type: "json" } : { type: string; }
> : ^^^^^^^^^^^^^^^^^
>type : string
Expand Down
Loading
Loading