Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8444,7 +8444,7 @@ namespace Parser {
const pos = getNodePos();
const name = tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral;
parseExpected(SyntaxKind.ColonToken);
const value = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true);
const value = parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral;
return finishNode(factory.createImportAttribute(name, value), pos);
}

Expand Down
124 changes: 60 additions & 64 deletions tests/baselines/reference/importAssertionNonstring.errors.txt
Original file line number Diff line number Diff line change
@@ -1,78 +1,74 @@
mod.mts(1,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(1,37): error TS2322: Type '{ field: 0; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type 'number' is not assignable to type 'string'.
mod.mts(1,52): error TS2837: Import assertion values must be string literal expressions.
mod.mts(3,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(3,52): error TS2837: Import assertion values must be string literal expressions.
mod.mts(5,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(5,37): error TS2322: Type '{ field: RegExp; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type 'RegExp' is not assignable to type 'string'.
mod.mts(5,52): error TS2837: Import assertion values must be string literal expressions.
mod.mts(7,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(7,37): error TS2322: Type '{ field: string[]; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type 'string[]' is not assignable to type 'string'.
mod.mts(7,52): error TS2837: Import assertion values must be string literal expressions.
mod.mts(9,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(9,37): error TS2322: Type '{ field: { a: number; }; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type '{ a: number; }' is not assignable to type 'string'.
mod.mts(9,52): error TS2837: Import assertion values must be string literal expressions.
mod.mts(11,37): error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
mod.mts(11,66): error TS2837: Import assertion values must be string literal expressions.
mod.mts(5,53): error TS1005: ',' expected.
mod.mts(5,54): error TS1005: ':' expected.
mod.mts(5,55): error TS1005: ',' expected.
mod.mts(5,56): error TS1005: ':' expected.
mod.mts(5,57): error TS1005: ',' expected.
mod.mts(7,8): error TS1005: ':' expected.
mod.mts(7,10): error TS1005: ',' expected.
mod.mts(7,13): error TS1005: ':' expected.
mod.mts(7,20): error TS1005: ',' expected.
mod.mts(7,25): error TS1005: ':' expected.
mod.mts(7,37): error TS1005: ',' expected.
mod.mts(7,44): error TS1005: ':' expected.
mod.mts(7,45): error TS1005: ',' expected.
mod.mts(7,53): error TS1005: ',' expected.
mod.mts(7,56): error TS1005: ':' expected.
mod.mts(9,54): error TS1005: ',' expected.
mod.mts(9,60): error TS1128: Declaration or statement expected.
mod.mts(11,68): error TS1005: ',' expected.
mod.mts(11,77): error TS1005: ':' expected.
mod.mts(11,78): error TS1005: ',' expected.


==== mod.mts (16 errors) ====
==== mod.mts (20 errors) ====
import * as thing1 from "./mod.mjs" assert {field: 0};
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: 0; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
~
!!! error TS2837: Import assertion values must be string literal expressions.

import * as thing2 from "./mod.mjs" assert {field: `a`};
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~
!!! error TS2837: Import assertion values must be string literal expressions.

import * as thing3 from "./mod.mjs" assert {field: /a/g};
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: RegExp; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
!!! error TS2322: Type 'RegExp' is not assignable to type 'string'.
~~~~
!!! error TS2837: Import assertion values must be string literal expressions.
~
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.
~
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.
~
!!! error TS1005: ',' expected.

import * as thing4 from "./mod.mjs" assert {field: ["a"]};
~
!!! error TS1005: ':' expected.
~~
!!! error TS1005: ',' expected.
~~~~~~
!!! error TS1005: ':' expected.
~~~~
!!! error TS1005: ',' expected.
~~~~~~~~~~~
!!! error TS1005: ':' expected.
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error messages in this test are much worse now

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they should be better now. Thank you for the review.

~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: string[]; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
!!! error TS2322: Type 'string[]' is not assignable to type 'string'.
~~~~~
!!! error TS2837: Import assertion values must be string literal expressions.
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.
~~~~~
!!! error TS1005: ',' expected.
~~~
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.

import * as thing5 from "./mod.mjs" assert {field: { a: 0 }};
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: { a: number; }; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
!!! error TS2322: Type '{ a: number; }' is not assignable to type 'string'.
~~~~~~~~
!!! error TS2837: Import assertion values must be string literal expressions.
~
!!! error TS1005: ',' expected.
~
!!! error TS1128: Declaration or statement expected.

import * as thing6 from "./mod.mjs" assert {type: "json", field: 0..toString()}
~~~~~~
!!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'.
~~~~~~~~~~~~~
!!! error TS2837: Import assertion values must be string literal expressions.
~
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.
~
!!! error TS1005: ',' expected.
1 change: 1 addition & 0 deletions tests/baselines/reference/importAssertionNonstring.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ import * as thing5 from "./mod.mjs" assert {field: { a: 0 }};
import * as thing6 from "./mod.mjs" assert {type: "json", field: 0..toString()}

//// [mod.mjs]
;
export {};
4 changes: 0 additions & 4 deletions tests/baselines/reference/importAssertionNonstring.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ import * as thing3 from "./mod.mjs" assert {field: /a/g};
>thing3 : Symbol(thing3, Decl(mod.mts, 4, 6))

import * as thing4 from "./mod.mjs" assert {field: ["a"]};
>thing4 : Symbol(thing4, Decl(mod.mts, 6, 6))

import * as thing5 from "./mod.mjs" assert {field: { a: 0 }};
>thing5 : Symbol(thing5, Decl(mod.mts, 8, 6))
>a : Symbol(a, Decl(mod.mts, 8, 52))

import * as thing6 from "./mod.mjs" assert {type: "json", field: 0..toString()}
>thing6 : Symbol(thing6, Decl(mod.mts, 10, 6))
>0..toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))
>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --))

38 changes: 16 additions & 22 deletions tests/baselines/reference/importAssertionNonstring.types
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,30 @@ import * as thing3 from "./mod.mjs" assert {field: /a/g};
> : ^^^^^^^^^^^^^
>field : any
> : ^^^
>/a/g : RegExp
> : ^^^^^^
>a : any
> : ^^^
>g : any
> : ^^^

import * as thing4 from "./mod.mjs" assert {field: ["a"]};
>thing4 : typeof thing1
> : ^^^^^^^^^^^^^
>import : any
> : ^^^
>as : any
> : ^^^
>from : any
> : ^^^
>assert : any
> : ^^^
>field : any
> : ^^^
>["a"] : string[]
> : ^^^^^^^^
>"a" : "a"
> : ^^^

import * as thing5 from "./mod.mjs" assert {field: { a: 0 }};
>thing5 : typeof thing1
> : ^^^^^^^^^^^^^
>field : any
> : ^^^
>{ a: 0 } : { a: number; }
> : ^^^^^^^^^^^^^^
>a : number
> : ^^^^^^
>0 : 0
> : ^
>a : any
> : ^^^

import * as thing6 from "./mod.mjs" assert {type: "json", field: 0..toString()}
>thing6 : typeof thing1
Expand All @@ -50,12 +50,6 @@ import * as thing6 from "./mod.mjs" assert {type: "json", field: 0..toString()}
> : ^^^
>field : any
> : ^^^
>0..toString() : string
> : ^^^^^^
>0..toString : (radix?: number) => string
> : ^ ^^^ ^^^^^
>0. : 0
> : ^
>toString : (radix?: number) => string
> : ^ ^^^ ^^^^^
>toString : any
> : ^^^

108 changes: 61 additions & 47 deletions tests/baselines/reference/importAttributes6(module=node18).errors.txt
Original file line number Diff line number Diff line change
@@ -1,56 +1,70 @@
mod.mts(1,37): error TS2322: Type '{ field: 0; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type 'number' is not assignable to type 'string'.
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,37): error TS2322: Type '{ field: RegExp; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type 'RegExp' is not assignable to type 'string'.
mod.mts(3,51): error TS2858: Import attribute values must be string literal expressions.
mod.mts(4,37): error TS2322: Type '{ field: string[]; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type 'string[]' is not assignable to type 'string'.
mod.mts(4,51): error TS2858: Import attribute values must be string literal expressions.
mod.mts(5,37): error TS2322: Type '{ field: { a: number; }; }' is not assignable to type 'ImportAttributes'.
Property 'field' is incompatible with index signature.
Type '{ a: number; }' is not assignable to type 'string'.
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(3,52): error TS1005: ',' expected.
mod.mts(3,53): error TS1005: ':' expected.
mod.mts(3,54): error TS1005: ',' expected.
mod.mts(3,56): error TS1005: ':' expected.
mod.mts(3,57): error TS1005: ',' expected.
mod.mts(4,8): error TS1005: ':' expected.
mod.mts(4,10): error TS1005: ',' expected.
mod.mts(4,13): error TS1005: ':' expected.
mod.mts(4,20): error TS1005: ',' expected.
mod.mts(4,25): error TS1005: ':' expected.
mod.mts(4,37): error TS1005: ',' expected.
mod.mts(4,42): error TS1005: ':' expected.
mod.mts(4,44): error TS1005: ',' expected.
mod.mts(4,52): error TS1005: ',' expected.
mod.mts(4,55): error TS1005: ':' expected.
mod.mts(5,53): error TS1005: ',' expected.
mod.mts(5,60): error TS1128: Declaration or statement expected.
mod.mts(6,67): error TS1005: ',' expected.
mod.mts(6,76): error TS1005: ':' expected.
mod.mts(6,77): error TS1005: ',' expected.


==== mod.mts (10 errors) ====
==== mod.mts (20 errors) ====
import * as thing1 from "./mod.mjs" with { field: 0 };
~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: 0; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
~
!!! 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 TS2322: Type '{ field: RegExp; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
!!! error TS2322: Type 'RegExp' is not assignable to type 'string'.
~~~~
!!! error TS2858: Import attribute values must be string literal expressions.
~
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.
~
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.
~
!!! error TS1005: ',' expected.
import * as thing4 from "./mod.mjs" with { field: ["a"] };
~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: string[]; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
!!! error TS2322: Type 'string[]' is not assignable to type 'string'.
~~~~~
!!! error TS2858: Import attribute values must be string literal expressions.
~
!!! error TS1005: ':' expected.
~~
!!! error TS1005: ',' expected.
~~~~~~
!!! error TS1005: ':' expected.
~~~~
!!! error TS1005: ',' expected.
~~~~~~~~~~~
!!! error TS1005: ':' expected.
~~~~
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.
~~~~~
!!! error TS1005: ',' expected.
~~~
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.
import * as thing5 from "./mod.mjs" with { field: { a: 0 } };
~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2322: Type '{ field: { a: number; }; }' is not assignable to type 'ImportAttributes'.
!!! error TS2322: Property 'field' is incompatible with index signature.
!!! error TS2322: Type '{ a: number; }' is not assignable to type 'string'.
~~~~~~~~
!!! error TS2858: Import attribute values must be string literal expressions.
~
!!! error TS1005: ',' expected.
~
!!! error TS1128: Declaration or statement expected.
import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() };
~~~~~~~~~~~~~
!!! error TS2858: Import attribute values must be string literal expressions.
~
!!! error TS1005: ',' expected.
~
!!! error TS1005: ':' expected.
~
!!! error TS1005: ',' expected.

Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() };


//// [mod.mjs]
;
export {};
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ 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, --, --))

Loading