From ae81b7f3f23c5468c86fd0ea9c9c9c8a0e606cd1 Mon Sep 17 00:00:00 2001 From: Stuart Dotson Date: Mon, 20 Oct 2025 12:32:04 -0400 Subject: [PATCH 1/5] Fix #62179: Restrict import attribute values to string literals --- src/compiler/parser.ts | 2 +- .../importAssertionNonstring.errors.txt | 124 +++++++------- .../reference/importAssertionNonstring.js | 1 + .../importAssertionNonstring.symbols | 4 - .../reference/importAssertionNonstring.types | 38 ++--- ...mportAttributes6(module=node18).errors.txt | 108 ++++++------ .../importAttributes6(module=node18).js | 1 + .../importAttributes6(module=node18).symbols | 5 - .../importAttributes6(module=node18).types | 38 ++--- ...mportAttributes6(module=node20).errors.txt | 108 ++++++------ .../importAttributes6(module=node20).js | 1 + .../importAttributes6(module=node20).symbols | 5 - .../importAttributes6(module=node20).types | 38 ++--- ...ortAttributes6(module=nodenext).errors.txt | 108 ++++++------ .../importAttributes6(module=nodenext).js | 1 + ...importAttributes6(module=nodenext).symbols | 5 - .../importAttributes6(module=nodenext).types | 38 ++--- .../importTypeAttributesNonString.errors.txt | 155 ++++++++++++++++++ .../importTypeAttributesNonString.js | 69 ++++++++ .../importTypeAttributesNonString.symbols | 84 ++++++++++ .../importTypeAttributesNonString.types | 151 +++++++++++++++++ .../compiler/importTypeAttributesNonString.ts | 57 +++++++ .../fourslash/organizeImportsAttributes4.ts | 6 +- 23 files changed, 830 insertions(+), 317 deletions(-) create mode 100644 tests/baselines/reference/importTypeAttributesNonString.errors.txt create mode 100644 tests/baselines/reference/importTypeAttributesNonString.js create mode 100644 tests/baselines/reference/importTypeAttributesNonString.symbols create mode 100644 tests/baselines/reference/importTypeAttributesNonString.types create mode 100644 tests/cases/compiler/importTypeAttributesNonString.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index d641cbd4b65e7..0be53ecc19263 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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); } diff --git a/tests/baselines/reference/importAssertionNonstring.errors.txt b/tests/baselines/reference/importAssertionNonstring.errors.txt index a220b1f213eaa..d5eced978b901 100644 --- a/tests/baselines/reference/importAssertionNonstring.errors.txt +++ b/tests/baselines/reference/importAssertionNonstring.errors.txt @@ -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'. - ~~~~~~~~~~~~~~~~~~~~~ -!!! 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. \ No newline at end of file + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1005: ':' expected. + ~ +!!! error TS1005: ',' expected. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertionNonstring.js b/tests/baselines/reference/importAssertionNonstring.js index 5aa6284fc6d91..6ff319731f6fd 100644 --- a/tests/baselines/reference/importAssertionNonstring.js +++ b/tests/baselines/reference/importAssertionNonstring.js @@ -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 {}; diff --git a/tests/baselines/reference/importAssertionNonstring.symbols b/tests/baselines/reference/importAssertionNonstring.symbols index 6fe1aa4cff016..8950f153c20e0 100644 --- a/tests/baselines/reference/importAssertionNonstring.symbols +++ b/tests/baselines/reference/importAssertionNonstring.symbols @@ -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, --, --)) diff --git a/tests/baselines/reference/importAssertionNonstring.types b/tests/baselines/reference/importAssertionNonstring.types index 23f42c74e574a..e45cd4950f189 100644 --- a/tests/baselines/reference/importAssertionNonstring.types +++ b/tests/baselines/reference/importAssertionNonstring.types @@ -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 @@ -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 +> : ^^^ diff --git a/tests/baselines/reference/importAttributes6(module=node18).errors.txt b/tests/baselines/reference/importAttributes6(module=node18).errors.txt index f2f160a4bd0e1..ec1355721b5ea 100644 --- a/tests/baselines/reference/importAttributes6(module=node18).errors.txt +++ b/tests/baselines/reference/importAttributes6(module=node18).errors.txt @@ -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. \ No newline at end of file diff --git a/tests/baselines/reference/importAttributes6(module=node18).js b/tests/baselines/reference/importAttributes6(module=node18).js index 6d346c55c8e5a..a50b50b3b29a9 100644 --- a/tests/baselines/reference/importAttributes6(module=node18).js +++ b/tests/baselines/reference/importAttributes6(module=node18).js @@ -10,4 +10,5 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; //// [mod.mjs] +; export {}; diff --git a/tests/baselines/reference/importAttributes6(module=node18).symbols b/tests/baselines/reference/importAttributes6(module=node18).symbols index b46ae41350e9a..89bd4e9bffd72 100644 --- a/tests/baselines/reference/importAttributes6(module=node18).symbols +++ b/tests/baselines/reference/importAttributes6(module=node18).symbols @@ -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, --, --)) diff --git a/tests/baselines/reference/importAttributes6(module=node18).types b/tests/baselines/reference/importAttributes6(module=node18).types index bb218f496175f..2895395310cb4 100644 --- a/tests/baselines/reference/importAttributes6(module=node18).types +++ b/tests/baselines/reference/importAttributes6(module=node18).types @@ -18,30 +18,30 @@ import * as thing3 from "./mod.mjs" with { field: /a/g }; > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->/a/g : RegExp -> : ^^^^^^ +>a : any +> : ^^^ +>g : any +> : ^^^ import * as thing4 from "./mod.mjs" with { field: ["a"] }; ->thing4 : typeof thing1 -> : ^^^^^^^^^^^^^ +>import : any +> : ^^^ +>as : any +> : ^^^ +>from : any +> : ^^^ +>with : any +> : ^^^ >field : any > : ^^^ ->["a"] : string[] -> : ^^^^^^^^ ->"a" : "a" -> : ^^^ import * as thing5 from "./mod.mjs" with { field: { a: 0 } }; >thing5 : typeof thing1 > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->{ a: 0 } : { a: number; } -> : ^^^^^^^^^^^^^^ ->a : number -> : ^^^^^^ ->0 : 0 -> : ^ +>a : any +> : ^^^ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; >thing6 : typeof thing1 @@ -50,12 +50,6 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; > : ^^^ >field : any > : ^^^ ->0..toString() : string -> : ^^^^^^ ->0..toString : (radix?: number) => string -> : ^ ^^^ ^^^^^ ->0. : 0 -> : ^ ->toString : (radix?: number) => string -> : ^ ^^^ ^^^^^ +>toString : any +> : ^^^ diff --git a/tests/baselines/reference/importAttributes6(module=node20).errors.txt b/tests/baselines/reference/importAttributes6(module=node20).errors.txt index f2f160a4bd0e1..ec1355721b5ea 100644 --- a/tests/baselines/reference/importAttributes6(module=node20).errors.txt +++ b/tests/baselines/reference/importAttributes6(module=node20).errors.txt @@ -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. \ No newline at end of file diff --git a/tests/baselines/reference/importAttributes6(module=node20).js b/tests/baselines/reference/importAttributes6(module=node20).js index 6d346c55c8e5a..a50b50b3b29a9 100644 --- a/tests/baselines/reference/importAttributes6(module=node20).js +++ b/tests/baselines/reference/importAttributes6(module=node20).js @@ -10,4 +10,5 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; //// [mod.mjs] +; export {}; diff --git a/tests/baselines/reference/importAttributes6(module=node20).symbols b/tests/baselines/reference/importAttributes6(module=node20).symbols index b46ae41350e9a..89bd4e9bffd72 100644 --- a/tests/baselines/reference/importAttributes6(module=node20).symbols +++ b/tests/baselines/reference/importAttributes6(module=node20).symbols @@ -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, --, --)) diff --git a/tests/baselines/reference/importAttributes6(module=node20).types b/tests/baselines/reference/importAttributes6(module=node20).types index bb218f496175f..2895395310cb4 100644 --- a/tests/baselines/reference/importAttributes6(module=node20).types +++ b/tests/baselines/reference/importAttributes6(module=node20).types @@ -18,30 +18,30 @@ import * as thing3 from "./mod.mjs" with { field: /a/g }; > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->/a/g : RegExp -> : ^^^^^^ +>a : any +> : ^^^ +>g : any +> : ^^^ import * as thing4 from "./mod.mjs" with { field: ["a"] }; ->thing4 : typeof thing1 -> : ^^^^^^^^^^^^^ +>import : any +> : ^^^ +>as : any +> : ^^^ +>from : any +> : ^^^ +>with : any +> : ^^^ >field : any > : ^^^ ->["a"] : string[] -> : ^^^^^^^^ ->"a" : "a" -> : ^^^ import * as thing5 from "./mod.mjs" with { field: { a: 0 } }; >thing5 : typeof thing1 > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->{ a: 0 } : { a: number; } -> : ^^^^^^^^^^^^^^ ->a : number -> : ^^^^^^ ->0 : 0 -> : ^ +>a : any +> : ^^^ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; >thing6 : typeof thing1 @@ -50,12 +50,6 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; > : ^^^ >field : any > : ^^^ ->0..toString() : string -> : ^^^^^^ ->0..toString : (radix?: number) => string -> : ^ ^^^ ^^^^^ ->0. : 0 -> : ^ ->toString : (radix?: number) => string -> : ^ ^^^ ^^^^^ +>toString : any +> : ^^^ diff --git a/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt b/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt index f2f160a4bd0e1..ec1355721b5ea 100644 --- a/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt +++ b/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt @@ -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. \ No newline at end of file diff --git a/tests/baselines/reference/importAttributes6(module=nodenext).js b/tests/baselines/reference/importAttributes6(module=nodenext).js index 6d346c55c8e5a..a50b50b3b29a9 100644 --- a/tests/baselines/reference/importAttributes6(module=nodenext).js +++ b/tests/baselines/reference/importAttributes6(module=nodenext).js @@ -10,4 +10,5 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; //// [mod.mjs] +; export {}; diff --git a/tests/baselines/reference/importAttributes6(module=nodenext).symbols b/tests/baselines/reference/importAttributes6(module=nodenext).symbols index b46ae41350e9a..89bd4e9bffd72 100644 --- a/tests/baselines/reference/importAttributes6(module=nodenext).symbols +++ b/tests/baselines/reference/importAttributes6(module=nodenext).symbols @@ -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, --, --)) diff --git a/tests/baselines/reference/importAttributes6(module=nodenext).types b/tests/baselines/reference/importAttributes6(module=nodenext).types index bb218f496175f..2895395310cb4 100644 --- a/tests/baselines/reference/importAttributes6(module=nodenext).types +++ b/tests/baselines/reference/importAttributes6(module=nodenext).types @@ -18,30 +18,30 @@ import * as thing3 from "./mod.mjs" with { field: /a/g }; > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->/a/g : RegExp -> : ^^^^^^ +>a : any +> : ^^^ +>g : any +> : ^^^ import * as thing4 from "./mod.mjs" with { field: ["a"] }; ->thing4 : typeof thing1 -> : ^^^^^^^^^^^^^ +>import : any +> : ^^^ +>as : any +> : ^^^ +>from : any +> : ^^^ +>with : any +> : ^^^ >field : any > : ^^^ ->["a"] : string[] -> : ^^^^^^^^ ->"a" : "a" -> : ^^^ import * as thing5 from "./mod.mjs" with { field: { a: 0 } }; >thing5 : typeof thing1 > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->{ a: 0 } : { a: number; } -> : ^^^^^^^^^^^^^^ ->a : number -> : ^^^^^^ ->0 : 0 -> : ^ +>a : any +> : ^^^ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; >thing6 : typeof thing1 @@ -50,12 +50,6 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; > : ^^^ >field : any > : ^^^ ->0..toString() : string -> : ^^^^^^ ->0..toString : (radix?: number) => string -> : ^ ^^^ ^^^^^ ->0. : 0 -> : ^ ->toString : (radix?: number) => string -> : ^ ^^^ ^^^^^ +>toString : any +> : ^^^ diff --git a/tests/baselines/reference/importTypeAttributesNonString.errors.txt b/tests/baselines/reference/importTypeAttributesNonString.errors.txt new file mode 100644 index 0000000000000..bb62d1e6f0828 --- /dev/null +++ b/tests/baselines/reference/importTypeAttributesNonString.errors.txt @@ -0,0 +1,155 @@ +mod.mts(1,16): error TS2664: Invalid module name in augmentation, module 'wat' cannot be found. +mod.mts(4,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. +mod.mts(6,9): error TS1005: ',' expected. +mod.mts(8,6): error TS1005: ';' expected. +mod.mts(8,7): error TS2695: Left side of comma operator is unused and has no side effects. +mod.mts(8,8): error TS1109: Expression expected. +mod.mts(9,3): error TS1109: Expression expected. +mod.mts(10,1): error TS1128: Declaration or statement expected. +mod.mts(10,2): error TS1128: Declaration or statement expected. +mod.mts(13,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. +mod.mts(18,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. +mod.mts(23,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. +mod.mts(24,21): error TS1005: ',' expected. +mod.mts(24,22): error TS1005: ':' expected. +mod.mts(24,23): error TS1005: ',' expected. +mod.mts(24,25): error TS1005: ':' expected. +mod.mts(25,2): error TS1005: '}' expected. +mod.mts(28,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. +mod.mts(29,21): error TS1005: ',' expected. +mod.mts(29,24): error TS1005: ':' expected. +mod.mts(33,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. +mod.mts(34,22): error TS1005: ',' expected. +mod.mts(35,1): error TS1005: ')' expected. +mod.mts(35,2): error TS1128: Declaration or statement expected. +mod.mts(38,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. +mod.mts(39,22): error TS1005: ',' expected. +mod.mts(39,31): error TS1005: ':' expected. +mod.mts(39,32): error TS1005: ',' expected. +mod.mts(43,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. +mod.mts(48,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. +mod.mts(53,26): error TS2307: Cannot find module 'wat' or its corresponding type declarations. + + +==== mod.mts (31 errors) ==== + declare module "wat"; + ~~~~~ +!!! error TS2664: Invalid module name in augmentation, module 'wat' cannot be found. + + // Import type with function expression (should error) + type T1 = typeof import("wat", { + ~~~~~ +!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + assert: { + a: (() => { + ~ +!!! error TS1005: ',' expected. +!!! related TS1007 mod.mts:5:11: The parser expected to find a '}' to match the '{' token here. +!!! related TS1007 mod.mts:4:32: The parser expected to find a '}' to match the '{' token here. + console.log("why can you write js here????"); + })(), + ~ +!!! error TS1005: ';' expected. + ~~ +!!! error TS2695: Left side of comma operator is unused and has no side effects. + ~ +!!! error TS1109: Expression expected. + } + ~ +!!! error TS1109: Expression expected. + }); + ~ +!!! error TS1128: Declaration or statement expected. + ~ +!!! error TS1128: Declaration or statement expected. + + // Import type with number literal (should error) + type T2 = typeof import("wat", { + ~~~~~ +!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + assert: { field: 0 } + }); + + // Import type with template literal (should error) + type T3 = typeof import("wat", { + ~~~~~ +!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + assert: { field: `a` } + }); + + // Import type with regex (should error) + type T4 = typeof import("wat", { + ~~~~~ +!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + assert: { field: /a/g } + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1005: ':' expected. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1005: ':' expected. + }); + ~ +!!! error TS1005: '}' expected. +!!! related TS1007 mod.mts:23:32: The parser expected to find a '}' to match the '{' token here. + + // Import type with array (should error) + type T5 = typeof import("wat", { + ~~~~~ +!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + assert: { field: ["a"] } + ~~~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1005: ':' expected. + }); + + // Import type with object (should error) + type T6 = typeof import("wat", { + ~~~~~ +!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + assert: { field: { a: 0 } } + ~ +!!! error TS1005: ',' expected. + }); + ~ +!!! error TS1005: ')' expected. + ~ +!!! error TS1128: Declaration or statement expected. + + // Import type with method call (should error) + type T7 = typeof import("wat", { + ~~~~~ +!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + assert: { field: 0..toString() } + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS1005: ':' expected. + ~ +!!! error TS1005: ',' expected. + }); + + // Import type with valid string literal (should work) + type T8 = typeof import("wat", { + ~~~~~ +!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + assert: { type: "json" } + }); + + // Import type with 'with' keyword and valid string (should work) + type T9 = typeof import("wat", { + ~~~~~ +!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + with: { type: "json" } + }); + + // Import type with 'with' keyword and invalid expression (should error) + type T10 = typeof import("wat", { + ~~~~~ +!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + with: { field: 123 } + }); + \ No newline at end of file diff --git a/tests/baselines/reference/importTypeAttributesNonString.js b/tests/baselines/reference/importTypeAttributesNonString.js new file mode 100644 index 0000000000000..1943f8a24868f --- /dev/null +++ b/tests/baselines/reference/importTypeAttributesNonString.js @@ -0,0 +1,69 @@ +//// [tests/cases/compiler/importTypeAttributesNonString.ts] //// + +//// [mod.mts] +declare module "wat"; + +// Import type with function expression (should error) +type T1 = typeof import("wat", { + assert: { + a: (() => { + console.log("why can you write js here????"); + })(), + } +}); + +// Import type with number literal (should error) +type T2 = typeof import("wat", { + assert: { field: 0 } +}); + +// Import type with template literal (should error) +type T3 = typeof import("wat", { + assert: { field: `a` } +}); + +// Import type with regex (should error) +type T4 = typeof import("wat", { + assert: { field: /a/g } +}); + +// Import type with array (should error) +type T5 = typeof import("wat", { + assert: { field: ["a"] } +}); + +// Import type with object (should error) +type T6 = typeof import("wat", { + assert: { field: { a: 0 } } +}); + +// Import type with method call (should error) +type T7 = typeof import("wat", { + assert: { field: 0..toString() } +}); + +// Import type with valid string literal (should work) +type T8 = typeof import("wat", { + assert: { type: "json" } +}); + +// Import type with 'with' keyword and valid string (should work) +type T9 = typeof import("wat", { + with: { type: "json" } +}); + +// Import type with 'with' keyword and invalid expression (should error) +type T10 = typeof import("wat", { + with: { field: 123 } +}); + + +//// [mod.mjs] +() => { + console.log("why can you write js here????"); +}; +(), +; +; +; +export {}; diff --git a/tests/baselines/reference/importTypeAttributesNonString.symbols b/tests/baselines/reference/importTypeAttributesNonString.symbols new file mode 100644 index 0000000000000..ef180948424f1 --- /dev/null +++ b/tests/baselines/reference/importTypeAttributesNonString.symbols @@ -0,0 +1,84 @@ +//// [tests/cases/compiler/importTypeAttributesNonString.ts] //// + +=== mod.mts === +declare module "wat"; +>"wat" : Symbol("wat", Decl(mod.mts, 0, 0)) + +// Import type with function expression (should error) +type T1 = typeof import("wat", { +>T1 : Symbol(T1, Decl(mod.mts, 0, 21)) + + assert: { + a: (() => { + console.log("why can you write js here????"); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) + + })(), + } +}); + +// Import type with number literal (should error) +type T2 = typeof import("wat", { +>T2 : Symbol(T2, Decl(mod.mts, 9, 3)) + + assert: { field: 0 } +}); + +// Import type with template literal (should error) +type T3 = typeof import("wat", { +>T3 : Symbol(T3, Decl(mod.mts, 14, 3)) + + assert: { field: `a` } +}); + +// Import type with regex (should error) +type T4 = typeof import("wat", { +>T4 : Symbol(T4, Decl(mod.mts, 19, 3)) + + assert: { field: /a/g } +}); + +// Import type with array (should error) +type T5 = typeof import("wat", { +>T5 : Symbol(T5, Decl(mod.mts, 24, 3)) + + assert: { field: ["a"] } +}); + +// Import type with object (should error) +type T6 = typeof import("wat", { +>T6 : Symbol(T6, Decl(mod.mts, 29, 3)) + + assert: { field: { a: 0 } } +}); + +// Import type with method call (should error) +type T7 = typeof import("wat", { +>T7 : Symbol(T7, Decl(mod.mts, 34, 3)) + + assert: { field: 0..toString() } +}); + +// Import type with valid string literal (should work) +type T8 = typeof import("wat", { +>T8 : Symbol(T8, Decl(mod.mts, 39, 3)) + + assert: { type: "json" } +}); + +// Import type with 'with' keyword and valid string (should work) +type T9 = typeof import("wat", { +>T9 : Symbol(T9, Decl(mod.mts, 44, 3)) + + with: { type: "json" } +}); + +// Import type with 'with' keyword and invalid expression (should error) +type T10 = typeof import("wat", { +>T10 : Symbol(T10, Decl(mod.mts, 49, 3)) + + with: { field: 123 } +}); + diff --git a/tests/baselines/reference/importTypeAttributesNonString.types b/tests/baselines/reference/importTypeAttributesNonString.types new file mode 100644 index 0000000000000..abb4f29d7a8a4 --- /dev/null +++ b/tests/baselines/reference/importTypeAttributesNonString.types @@ -0,0 +1,151 @@ +//// [tests/cases/compiler/importTypeAttributesNonString.ts] //// + +=== mod.mts === +declare module "wat"; +>"wat" : any +> : ^^^ + +// Import type with function expression (should error) +type T1 = typeof import("wat", { +>T1 : any +> : ^^^ + + assert: { + a: (() => { +>a : any +> : ^^^ +>() => { console.log("why can you write js here????"); } : () => void +> : ^^^^^^^^^^ + + console.log("why can you write js here????"); +>console.log("why can you write js here????") : void +> : ^^^^ +>console.log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>console : Console +> : ^^^^^^^ +>log : (...data: any[]) => void +> : ^^^^ ^^ ^^^^^ +>"why can you write js here????" : "why can you write js here????" +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + })(), +>(), : any +> : ^^^ +>() : any +> : ^^^ +> : any +> : ^^^ + } +> : any +> : ^^^ + +}); + +// Import type with number literal (should error) +type T2 = typeof import("wat", { +>T2 : any +> : ^^^ + + assert: { field: 0 } +>field : any +> : ^^^ + +}); + +// Import type with template literal (should error) +type T3 = typeof import("wat", { +>T3 : any +> : ^^^ + + assert: { field: `a` } +>field : any +> : ^^^ + +}); + +// Import type with regex (should error) +type T4 = typeof import("wat", { +>T4 : any +> : ^^^ + + assert: { field: /a/g } +>field : any +> : ^^^ +>a : any +> : ^^^ +>g : any +> : ^^^ + +}); + +// Import type with array (should error) +type T5 = typeof import("wat", { +>T5 : any +> : ^^^ + + assert: { field: ["a"] } +>field : any +> : ^^^ + +}); + +// Import type with object (should error) +type T6 = typeof import("wat", { +>T6 : any +> : ^^^ + + assert: { field: { a: 0 } } +>field : any +> : ^^^ +>a : any +> : ^^^ + +}); + +// Import type with method call (should error) +type T7 = typeof import("wat", { +>T7 : any +> : ^^^ + + assert: { field: 0..toString() } +>field : any +> : ^^^ +>toString : any +> : ^^^ + +}); + +// Import type with valid string literal (should work) +type T8 = typeof import("wat", { +>T8 : any +> : ^^^ + + assert: { type: "json" } +>type : any +> : ^^^ + +}); + +// Import type with 'with' keyword and valid string (should work) +type T9 = typeof import("wat", { +>T9 : any +> : ^^^ + + with: { type: "json" } +>type : any +> : ^^^ + +}); + +// Import type with 'with' keyword and invalid expression (should error) +type T10 = typeof import("wat", { +>T10 : any +> : ^^^ + + with: { field: 123 } +>field : any +> : ^^^ + +}); + diff --git a/tests/cases/compiler/importTypeAttributesNonString.ts b/tests/cases/compiler/importTypeAttributesNonString.ts new file mode 100644 index 0000000000000..f93e1faf97660 --- /dev/null +++ b/tests/cases/compiler/importTypeAttributesNonString.ts @@ -0,0 +1,57 @@ +// @module: nodenext +// @filename: mod.mts +declare module "wat"; + +// Import type with function expression (should error) +type T1 = typeof import("wat", { + assert: { + a: (() => { + console.log("why can you write js here????"); + })(), + } +}); + +// Import type with number literal (should error) +type T2 = typeof import("wat", { + assert: { field: 0 } +}); + +// Import type with template literal (should error) +type T3 = typeof import("wat", { + assert: { field: `a` } +}); + +// Import type with regex (should error) +type T4 = typeof import("wat", { + assert: { field: /a/g } +}); + +// Import type with array (should error) +type T5 = typeof import("wat", { + assert: { field: ["a"] } +}); + +// Import type with object (should error) +type T6 = typeof import("wat", { + assert: { field: { a: 0 } } +}); + +// Import type with method call (should error) +type T7 = typeof import("wat", { + assert: { field: 0..toString() } +}); + +// Import type with valid string literal (should work) +type T8 = typeof import("wat", { + assert: { type: "json" } +}); + +// Import type with 'with' keyword and valid string (should work) +type T9 = typeof import("wat", { + with: { type: "json" } +}); + +// Import type with 'with' keyword and invalid expression (should error) +type T10 = typeof import("wat", { + with: { field: 123 } +}); diff --git a/tests/cases/fourslash/organizeImportsAttributes4.ts b/tests/cases/fourslash/organizeImportsAttributes4.ts index bded70d338c6b..a04661551ec3c 100644 --- a/tests/cases/fourslash/organizeImportsAttributes4.ts +++ b/tests/cases/fourslash/organizeImportsAttributes4.ts @@ -6,16 +6,14 @@ ////import { E } from "./a" assert { foo: 'bar', bar: "foo" }; ////import { C } from "./a" assert { foo: "bar", bar: "foo" }; ////import { F } from "./a" assert { foo: "42" }; -////import { Y } from "./a" assert { foo: 42 }; ////import { Z } from "./a" assert { foo: "42" }; //// -////export type G = A | B | C | D | E | F | Y | Z; +////export type G = A | B | C | D | E | F | Z; verify.organizeImports( `import { A, B } from "./a" assert { foo: "foo", bar: "bar" }; import { C, D, E } from "./a" assert { bar: "foo", foo: "bar" }; import { F, Z } from "./a" assert { foo: "42" }; -import { Y } from "./a" assert { foo: 42 }; -export type G = A | B | C | D | E | F | Y | Z;`); \ No newline at end of file +export type G = A | B | C | D | E | F | Z;`); \ No newline at end of file From 97d864d93ee1dcefaf28447cba464b5fa608e2c1 Mon Sep 17 00:00:00 2001 From: Stuart Dotson Date: Mon, 20 Oct 2025 15:47:13 -0400 Subject: [PATCH 2/5] rethink things to improve error messages/ --- src/compiler/parser.ts | 2 +- .../importAssertionNonstring.errors.txt | 124 +++++++++--------- .../reference/importAssertionNonstring.js | 1 - .../importAssertionNonstring.symbols | 4 + .../reference/importAssertionNonstring.types | 38 +++--- ...mportAttributes6(module=node18).errors.txt | 108 +++++++-------- .../importAttributes6(module=node18).js | 1 - .../importAttributes6(module=node18).symbols | 5 + .../importAttributes6(module=node18).types | 38 +++--- ...mportAttributes6(module=node20).errors.txt | 108 +++++++-------- .../importAttributes6(module=node20).js | 1 - .../importAttributes6(module=node20).symbols | 5 + .../importAttributes6(module=node20).types | 38 +++--- ...ortAttributes6(module=nodenext).errors.txt | 108 +++++++-------- .../importAttributes6(module=nodenext).js | 1 - ...importAttributes6(module=nodenext).symbols | 5 + .../importAttributes6(module=nodenext).types | 38 +++--- .../importTypeAttributesNonString.errors.txt | 65 +-------- .../importTypeAttributesNonString.js | 7 - .../importTypeAttributesNonString.symbols | 5 + .../importTypeAttributesNonString.types | 41 +++--- 21 files changed, 343 insertions(+), 400 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0be53ecc19263..d641cbd4b65e7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -8444,7 +8444,7 @@ namespace Parser { const pos = getNodePos(); const name = tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral; parseExpected(SyntaxKind.ColonToken); - const value = parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral; + const value = parseAssignmentExpressionOrHigher(/*allowReturnTypeInArrowFunction*/ true); return finishNode(factory.createImportAttribute(name, value), pos); } diff --git a/tests/baselines/reference/importAssertionNonstring.errors.txt b/tests/baselines/reference/importAssertionNonstring.errors.txt index d5eced978b901..a220b1f213eaa 100644 --- a/tests/baselines/reference/importAssertionNonstring.errors.txt +++ b/tests/baselines/reference/importAssertionNonstring.errors.txt @@ -1,74 +1,78 @@ -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(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 (20 errors) ==== +==== mod.mts (16 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 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'. + ~~~~~~~~~~~~~~~~~~~~ +!!! 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. 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 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'. + ~~~~~~~~~~~~~~~~~~~~~ +!!! 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. import * as thing5 from "./mod.mjs" assert {field: { a: 0 }}; - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1128: Declaration or statement expected. + ~~~~~~ +!!! 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. import * as thing6 from "./mod.mjs" assert {type: "json", field: 0..toString()} - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. \ No newline at end of file + ~~~~~~ +!!! 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. \ No newline at end of file diff --git a/tests/baselines/reference/importAssertionNonstring.js b/tests/baselines/reference/importAssertionNonstring.js index 6ff319731f6fd..5aa6284fc6d91 100644 --- a/tests/baselines/reference/importAssertionNonstring.js +++ b/tests/baselines/reference/importAssertionNonstring.js @@ -14,5 +14,4 @@ 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 {}; diff --git a/tests/baselines/reference/importAssertionNonstring.symbols b/tests/baselines/reference/importAssertionNonstring.symbols index 8950f153c20e0..6fe1aa4cff016 100644 --- a/tests/baselines/reference/importAssertionNonstring.symbols +++ b/tests/baselines/reference/importAssertionNonstring.symbols @@ -11,10 +11,14 @@ 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, --, --)) diff --git a/tests/baselines/reference/importAssertionNonstring.types b/tests/baselines/reference/importAssertionNonstring.types index e45cd4950f189..23f42c74e574a 100644 --- a/tests/baselines/reference/importAssertionNonstring.types +++ b/tests/baselines/reference/importAssertionNonstring.types @@ -18,30 +18,30 @@ import * as thing3 from "./mod.mjs" assert {field: /a/g}; > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->a : any -> : ^^^ ->g : any -> : ^^^ +>/a/g : RegExp +> : ^^^^^^ import * as thing4 from "./mod.mjs" assert {field: ["a"]}; ->import : any -> : ^^^ ->as : any -> : ^^^ ->from : any -> : ^^^ ->assert : any -> : ^^^ +>thing4 : typeof thing1 +> : ^^^^^^^^^^^^^ >field : any > : ^^^ +>["a"] : string[] +> : ^^^^^^^^ +>"a" : "a" +> : ^^^ import * as thing5 from "./mod.mjs" assert {field: { a: 0 }}; >thing5 : typeof thing1 > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->a : any -> : ^^^ +>{ a: 0 } : { a: number; } +> : ^^^^^^^^^^^^^^ +>a : number +> : ^^^^^^ +>0 : 0 +> : ^ import * as thing6 from "./mod.mjs" assert {type: "json", field: 0..toString()} >thing6 : typeof thing1 @@ -50,6 +50,12 @@ import * as thing6 from "./mod.mjs" assert {type: "json", field: 0..toString()} > : ^^^ >field : any > : ^^^ ->toString : any -> : ^^^ +>0..toString() : string +> : ^^^^^^ +>0..toString : (radix?: number) => string +> : ^ ^^^ ^^^^^ +>0. : 0 +> : ^ +>toString : (radix?: number) => string +> : ^ ^^^ ^^^^^ diff --git a/tests/baselines/reference/importAttributes6(module=node18).errors.txt b/tests/baselines/reference/importAttributes6(module=node18).errors.txt index ec1355721b5ea..f2f160a4bd0e1 100644 --- a/tests/baselines/reference/importAttributes6(module=node18).errors.txt +++ b/tests/baselines/reference/importAttributes6(module=node18).errors.txt @@ -1,70 +1,56 @@ -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(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 (20 errors) ==== +==== mod.mts (10 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 TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. + ~~~~~~~~~~~~~~~~~~~~ +!!! 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. import * as thing4 from "./mod.mjs" with { field: ["a"] }; - ~ -!!! 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. + ~~~~~~~~~~~~~~~~~~~~~ +!!! 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. import * as thing5 from "./mod.mjs" with { field: { a: 0 } }; - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! 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. import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. + ~~~~~~~~~~~~~ +!!! error TS2858: Import attribute values must be string literal expressions. \ No newline at end of file diff --git a/tests/baselines/reference/importAttributes6(module=node18).js b/tests/baselines/reference/importAttributes6(module=node18).js index a50b50b3b29a9..6d346c55c8e5a 100644 --- a/tests/baselines/reference/importAttributes6(module=node18).js +++ b/tests/baselines/reference/importAttributes6(module=node18).js @@ -10,5 +10,4 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; //// [mod.mjs] -; export {}; diff --git a/tests/baselines/reference/importAttributes6(module=node18).symbols b/tests/baselines/reference/importAttributes6(module=node18).symbols index 89bd4e9bffd72..b46ae41350e9a 100644 --- a/tests/baselines/reference/importAttributes6(module=node18).symbols +++ b/tests/baselines/reference/importAttributes6(module=node18).symbols @@ -11,9 +11,14 @@ 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, --, --)) diff --git a/tests/baselines/reference/importAttributes6(module=node18).types b/tests/baselines/reference/importAttributes6(module=node18).types index 2895395310cb4..bb218f496175f 100644 --- a/tests/baselines/reference/importAttributes6(module=node18).types +++ b/tests/baselines/reference/importAttributes6(module=node18).types @@ -18,30 +18,30 @@ import * as thing3 from "./mod.mjs" with { field: /a/g }; > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->a : any -> : ^^^ ->g : any -> : ^^^ +>/a/g : RegExp +> : ^^^^^^ import * as thing4 from "./mod.mjs" with { field: ["a"] }; ->import : any -> : ^^^ ->as : any -> : ^^^ ->from : any -> : ^^^ ->with : any -> : ^^^ +>thing4 : typeof thing1 +> : ^^^^^^^^^^^^^ >field : any > : ^^^ +>["a"] : string[] +> : ^^^^^^^^ +>"a" : "a" +> : ^^^ import * as thing5 from "./mod.mjs" with { field: { a: 0 } }; >thing5 : typeof thing1 > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->a : any -> : ^^^ +>{ a: 0 } : { a: number; } +> : ^^^^^^^^^^^^^^ +>a : number +> : ^^^^^^ +>0 : 0 +> : ^ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; >thing6 : typeof thing1 @@ -50,6 +50,12 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; > : ^^^ >field : any > : ^^^ ->toString : any -> : ^^^ +>0..toString() : string +> : ^^^^^^ +>0..toString : (radix?: number) => string +> : ^ ^^^ ^^^^^ +>0. : 0 +> : ^ +>toString : (radix?: number) => string +> : ^ ^^^ ^^^^^ diff --git a/tests/baselines/reference/importAttributes6(module=node20).errors.txt b/tests/baselines/reference/importAttributes6(module=node20).errors.txt index ec1355721b5ea..f2f160a4bd0e1 100644 --- a/tests/baselines/reference/importAttributes6(module=node20).errors.txt +++ b/tests/baselines/reference/importAttributes6(module=node20).errors.txt @@ -1,70 +1,56 @@ -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(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 (20 errors) ==== +==== mod.mts (10 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 TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. + ~~~~~~~~~~~~~~~~~~~~ +!!! 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. import * as thing4 from "./mod.mjs" with { field: ["a"] }; - ~ -!!! 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. + ~~~~~~~~~~~~~~~~~~~~~ +!!! 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. import * as thing5 from "./mod.mjs" with { field: { a: 0 } }; - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! 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. import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. + ~~~~~~~~~~~~~ +!!! error TS2858: Import attribute values must be string literal expressions. \ No newline at end of file diff --git a/tests/baselines/reference/importAttributes6(module=node20).js b/tests/baselines/reference/importAttributes6(module=node20).js index a50b50b3b29a9..6d346c55c8e5a 100644 --- a/tests/baselines/reference/importAttributes6(module=node20).js +++ b/tests/baselines/reference/importAttributes6(module=node20).js @@ -10,5 +10,4 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; //// [mod.mjs] -; export {}; diff --git a/tests/baselines/reference/importAttributes6(module=node20).symbols b/tests/baselines/reference/importAttributes6(module=node20).symbols index 89bd4e9bffd72..b46ae41350e9a 100644 --- a/tests/baselines/reference/importAttributes6(module=node20).symbols +++ b/tests/baselines/reference/importAttributes6(module=node20).symbols @@ -11,9 +11,14 @@ 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, --, --)) diff --git a/tests/baselines/reference/importAttributes6(module=node20).types b/tests/baselines/reference/importAttributes6(module=node20).types index 2895395310cb4..bb218f496175f 100644 --- a/tests/baselines/reference/importAttributes6(module=node20).types +++ b/tests/baselines/reference/importAttributes6(module=node20).types @@ -18,30 +18,30 @@ import * as thing3 from "./mod.mjs" with { field: /a/g }; > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->a : any -> : ^^^ ->g : any -> : ^^^ +>/a/g : RegExp +> : ^^^^^^ import * as thing4 from "./mod.mjs" with { field: ["a"] }; ->import : any -> : ^^^ ->as : any -> : ^^^ ->from : any -> : ^^^ ->with : any -> : ^^^ +>thing4 : typeof thing1 +> : ^^^^^^^^^^^^^ >field : any > : ^^^ +>["a"] : string[] +> : ^^^^^^^^ +>"a" : "a" +> : ^^^ import * as thing5 from "./mod.mjs" with { field: { a: 0 } }; >thing5 : typeof thing1 > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->a : any -> : ^^^ +>{ a: 0 } : { a: number; } +> : ^^^^^^^^^^^^^^ +>a : number +> : ^^^^^^ +>0 : 0 +> : ^ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; >thing6 : typeof thing1 @@ -50,6 +50,12 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; > : ^^^ >field : any > : ^^^ ->toString : any -> : ^^^ +>0..toString() : string +> : ^^^^^^ +>0..toString : (radix?: number) => string +> : ^ ^^^ ^^^^^ +>0. : 0 +> : ^ +>toString : (radix?: number) => string +> : ^ ^^^ ^^^^^ diff --git a/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt b/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt index ec1355721b5ea..f2f160a4bd0e1 100644 --- a/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt +++ b/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt @@ -1,70 +1,56 @@ -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(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 (20 errors) ==== +==== mod.mts (10 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 TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. + ~~~~~~~~~~~~~~~~~~~~ +!!! 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. import * as thing4 from "./mod.mjs" with { field: ["a"] }; - ~ -!!! 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. + ~~~~~~~~~~~~~~~~~~~~~ +!!! 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. import * as thing5 from "./mod.mjs" with { field: { a: 0 } }; - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1128: Declaration or statement expected. + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! 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. import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. + ~~~~~~~~~~~~~ +!!! error TS2858: Import attribute values must be string literal expressions. \ No newline at end of file diff --git a/tests/baselines/reference/importAttributes6(module=nodenext).js b/tests/baselines/reference/importAttributes6(module=nodenext).js index a50b50b3b29a9..6d346c55c8e5a 100644 --- a/tests/baselines/reference/importAttributes6(module=nodenext).js +++ b/tests/baselines/reference/importAttributes6(module=nodenext).js @@ -10,5 +10,4 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; //// [mod.mjs] -; export {}; diff --git a/tests/baselines/reference/importAttributes6(module=nodenext).symbols b/tests/baselines/reference/importAttributes6(module=nodenext).symbols index 89bd4e9bffd72..b46ae41350e9a 100644 --- a/tests/baselines/reference/importAttributes6(module=nodenext).symbols +++ b/tests/baselines/reference/importAttributes6(module=nodenext).symbols @@ -11,9 +11,14 @@ 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, --, --)) diff --git a/tests/baselines/reference/importAttributes6(module=nodenext).types b/tests/baselines/reference/importAttributes6(module=nodenext).types index 2895395310cb4..bb218f496175f 100644 --- a/tests/baselines/reference/importAttributes6(module=nodenext).types +++ b/tests/baselines/reference/importAttributes6(module=nodenext).types @@ -18,30 +18,30 @@ import * as thing3 from "./mod.mjs" with { field: /a/g }; > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->a : any -> : ^^^ ->g : any -> : ^^^ +>/a/g : RegExp +> : ^^^^^^ import * as thing4 from "./mod.mjs" with { field: ["a"] }; ->import : any -> : ^^^ ->as : any -> : ^^^ ->from : any -> : ^^^ ->with : any -> : ^^^ +>thing4 : typeof thing1 +> : ^^^^^^^^^^^^^ >field : any > : ^^^ +>["a"] : string[] +> : ^^^^^^^^ +>"a" : "a" +> : ^^^ import * as thing5 from "./mod.mjs" with { field: { a: 0 } }; >thing5 : typeof thing1 > : ^^^^^^^^^^^^^ >field : any > : ^^^ ->a : any -> : ^^^ +>{ a: 0 } : { a: number; } +> : ^^^^^^^^^^^^^^ +>a : number +> : ^^^^^^ +>0 : 0 +> : ^ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; >thing6 : typeof thing1 @@ -50,6 +50,12 @@ import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; > : ^^^ >field : any > : ^^^ ->toString : any -> : ^^^ +>0..toString() : string +> : ^^^^^^ +>0..toString : (radix?: number) => string +> : ^ ^^^ ^^^^^ +>0. : 0 +> : ^ +>toString : (radix?: number) => string +> : ^ ^^^ ^^^^^ diff --git a/tests/baselines/reference/importTypeAttributesNonString.errors.txt b/tests/baselines/reference/importTypeAttributesNonString.errors.txt index bb62d1e6f0828..2642e2a844691 100644 --- a/tests/baselines/reference/importTypeAttributesNonString.errors.txt +++ b/tests/baselines/reference/importTypeAttributesNonString.errors.txt @@ -1,37 +1,17 @@ mod.mts(1,16): error TS2664: Invalid module name in augmentation, module 'wat' cannot be found. mod.mts(4,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(6,9): error TS1005: ',' expected. -mod.mts(8,6): error TS1005: ';' expected. -mod.mts(8,7): error TS2695: Left side of comma operator is unused and has no side effects. -mod.mts(8,8): error TS1109: Expression expected. -mod.mts(9,3): error TS1109: Expression expected. -mod.mts(10,1): error TS1128: Declaration or statement expected. -mod.mts(10,2): error TS1128: Declaration or statement expected. mod.mts(13,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. mod.mts(18,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. mod.mts(23,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(24,21): error TS1005: ',' expected. -mod.mts(24,22): error TS1005: ':' expected. -mod.mts(24,23): error TS1005: ',' expected. -mod.mts(24,25): error TS1005: ':' expected. -mod.mts(25,2): error TS1005: '}' expected. mod.mts(28,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(29,21): error TS1005: ',' expected. -mod.mts(29,24): error TS1005: ':' expected. mod.mts(33,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(34,22): error TS1005: ',' expected. -mod.mts(35,1): error TS1005: ')' expected. -mod.mts(35,2): error TS1128: Declaration or statement expected. mod.mts(38,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(39,22): error TS1005: ',' expected. -mod.mts(39,31): error TS1005: ':' expected. -mod.mts(39,32): error TS1005: ',' expected. mod.mts(43,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. mod.mts(48,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. mod.mts(53,26): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -==== mod.mts (31 errors) ==== +==== mod.mts (11 errors) ==== declare module "wat"; ~~~~~ !!! error TS2664: Invalid module name in augmentation, module 'wat' cannot be found. @@ -42,26 +22,10 @@ mod.mts(53,26): error TS2307: Cannot find module 'wat' or its corresponding type !!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. assert: { a: (() => { - ~ -!!! error TS1005: ',' expected. -!!! related TS1007 mod.mts:5:11: The parser expected to find a '}' to match the '{' token here. -!!! related TS1007 mod.mts:4:32: The parser expected to find a '}' to match the '{' token here. console.log("why can you write js here????"); })(), - ~ -!!! error TS1005: ';' expected. - ~~ -!!! error TS2695: Left side of comma operator is unused and has no side effects. - ~ -!!! error TS1109: Expression expected. } - ~ -!!! error TS1109: Expression expected. }); - ~ -!!! error TS1128: Declaration or statement expected. - ~ -!!! error TS1128: Declaration or statement expected. // Import type with number literal (should error) type T2 = typeof import("wat", { @@ -82,28 +46,13 @@ mod.mts(53,26): error TS2307: Cannot find module 'wat' or its corresponding type ~~~~~ !!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. assert: { field: /a/g } - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. }); - ~ -!!! error TS1005: '}' expected. -!!! related TS1007 mod.mts:23:32: The parser expected to find a '}' to match the '{' token here. // Import type with array (should error) type T5 = typeof import("wat", { ~~~~~ !!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. assert: { field: ["a"] } - ~~~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. }); // Import type with object (should error) @@ -111,25 +60,13 @@ mod.mts(53,26): error TS2307: Cannot find module 'wat' or its corresponding type ~~~~~ !!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. assert: { field: { a: 0 } } - ~ -!!! error TS1005: ',' expected. }); - ~ -!!! error TS1005: ')' expected. - ~ -!!! error TS1128: Declaration or statement expected. // Import type with method call (should error) type T7 = typeof import("wat", { ~~~~~ !!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. assert: { field: 0..toString() } - ~ -!!! error TS1005: ',' expected. - ~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. }); // Import type with valid string literal (should work) diff --git a/tests/baselines/reference/importTypeAttributesNonString.js b/tests/baselines/reference/importTypeAttributesNonString.js index 1943f8a24868f..01ead3369d441 100644 --- a/tests/baselines/reference/importTypeAttributesNonString.js +++ b/tests/baselines/reference/importTypeAttributesNonString.js @@ -59,11 +59,4 @@ type T10 = typeof import("wat", { //// [mod.mjs] -() => { - console.log("why can you write js here????"); -}; -(), -; -; -; export {}; diff --git a/tests/baselines/reference/importTypeAttributesNonString.symbols b/tests/baselines/reference/importTypeAttributesNonString.symbols index ef180948424f1..6286be5c0ac9d 100644 --- a/tests/baselines/reference/importTypeAttributesNonString.symbols +++ b/tests/baselines/reference/importTypeAttributesNonString.symbols @@ -52,6 +52,8 @@ type T6 = typeof import("wat", { >T6 : Symbol(T6, Decl(mod.mts, 29, 3)) assert: { field: { a: 0 } } +>a : Symbol(a, Decl(mod.mts, 33, 20)) + }); // Import type with method call (should error) @@ -59,6 +61,9 @@ type T7 = typeof import("wat", { >T7 : Symbol(T7, Decl(mod.mts, 34, 3)) assert: { field: 0..toString() } +>0..toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) +>toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) + }); // Import type with valid string literal (should work) diff --git a/tests/baselines/reference/importTypeAttributesNonString.types b/tests/baselines/reference/importTypeAttributesNonString.types index abb4f29d7a8a4..a67f6a8e39e1e 100644 --- a/tests/baselines/reference/importTypeAttributesNonString.types +++ b/tests/baselines/reference/importTypeAttributesNonString.types @@ -14,6 +14,10 @@ type T1 = typeof import("wat", { a: (() => { >a : any > : ^^^ +>(() => { console.log("why can you write js here????"); })() : void +> : ^^^^ +>(() => { console.log("why can you write js here????"); }) : () => void +> : ^^^^^^^^^^ >() => { console.log("why can you write js here????"); } : () => void > : ^^^^^^^^^^ @@ -30,16 +34,7 @@ type T1 = typeof import("wat", { > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ })(), ->(), : any -> : ^^^ ->() : any -> : ^^^ -> : any -> : ^^^ } -> : any -> : ^^^ - }); // Import type with number literal (should error) @@ -72,10 +67,8 @@ type T4 = typeof import("wat", { assert: { field: /a/g } >field : any > : ^^^ ->a : any -> : ^^^ ->g : any -> : ^^^ +>/a/g : RegExp +> : ^^^^^^ }); @@ -87,6 +80,10 @@ type T5 = typeof import("wat", { assert: { field: ["a"] } >field : any > : ^^^ +>["a"] : string[] +> : ^^^^^^^^ +>"a" : "a" +> : ^^^ }); @@ -98,8 +95,12 @@ type T6 = typeof import("wat", { assert: { field: { a: 0 } } >field : any > : ^^^ ->a : any -> : ^^^ +>{ a: 0 } : { a: number; } +> : ^^^^^^^^^^^^^^ +>a : number +> : ^^^^^^ +>0 : 0 +> : ^ }); @@ -111,8 +112,14 @@ type T7 = typeof import("wat", { assert: { field: 0..toString() } >field : any > : ^^^ ->toString : any -> : ^^^ +>0..toString() : string +> : ^^^^^^ +>0..toString : (radix?: number) => string +> : ^ ^^^ ^^^^^ +>0. : 0 +> : ^ +>toString : (radix?: number) => string +> : ^ ^^^ ^^^^^ }); From 784aacbe8eb5bfcee9321ce0453e10dbe01aa25b Mon Sep 17 00:00:00 2001 From: Stuart Dotson Date: Mon, 20 Oct 2025 16:18:05 -0400 Subject: [PATCH 3/5] actually do something now --- src/compiler/checker.ts | 9 ++ .../importTypeAttributesNonString.errors.txt | 84 +++++++++---------- .../importTypeAttributesNonString.js | 27 +++--- .../importTypeAttributesNonString.symbols | 49 +++++------ .../importTypeAttributesNonString.types | 71 ++++++++-------- .../compiler/importTypeAttributesNonString.ts | 24 +++--- 6 files changed, 138 insertions(+), 126 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 48bc0da113816..30e52bd1d40ab 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19933,6 +19933,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { links.resolvedSymbol = unknownSymbol; return links.resolvedType = errorType; } + // Validate import attributes + if (node.attributes) { + const diagnostic = node.attributes.token === SyntaxKind.WithKeyword ? Diagnostics.Import_attribute_values_must_be_string_literal_expressions : Diagnostics.Import_assertion_values_must_be_string_literal_expressions; + for (const attr of node.attributes.elements) { + if (!isStringLiteral(attr.value)) { + error(attr.value, diagnostic); + } + } + } const targetMeaning = node.isTypeOf ? SymbolFlags.Value : node.flags & NodeFlags.JSDoc ? SymbolFlags.Value | SymbolFlags.Type : SymbolFlags.Type; // TODO: Future work: support unions/generics/whatever via a deferred import-type const innerModuleSymbol = resolveExternalModuleName(node, node.argument.literal); diff --git a/tests/baselines/reference/importTypeAttributesNonString.errors.txt b/tests/baselines/reference/importTypeAttributesNonString.errors.txt index 2642e2a844691..0794b7d7963fb 100644 --- a/tests/baselines/reference/importTypeAttributesNonString.errors.txt +++ b/tests/baselines/reference/importTypeAttributesNonString.errors.txt @@ -1,92 +1,86 @@ -mod.mts(1,16): error TS2664: Invalid module name in augmentation, module 'wat' cannot be found. -mod.mts(4,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(13,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(18,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(23,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(28,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(33,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(38,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(43,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(48,25): error TS2307: Cannot find module 'wat' or its corresponding type declarations. -mod.mts(53,26): error TS2307: Cannot find module 'wat' or its corresponding type declarations. +mod.mts(4,8): error TS2837: Import assertion values must be string literal expressions. +mod.mts(12,20): error TS2837: Import assertion values must be string literal expressions. +mod.mts(17,20): error TS2837: Import assertion values must be string literal expressions. +mod.mts(22,20): error TS2837: Import assertion values must be string literal expressions. +mod.mts(27,20): error TS2837: Import assertion values must be string literal expressions. +mod.mts(32,20): error TS2837: Import assertion values must be string literal expressions. +mod.mts(37,20): error TS2837: Import assertion values must be string literal expressions. +mod.mts(52,18): error TS2858: Import attribute values must be string literal expressions. -==== mod.mts (11 errors) ==== - declare module "wat"; - ~~~~~ -!!! error TS2664: Invalid module name in augmentation, module 'wat' cannot be found. +==== wat.mts (0 errors) ==== + export const x = 1; +==== mod.mts (8 errors) ==== // Import type with function expression (should error) - type T1 = typeof import("wat", { - ~~~~~ -!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + type T1 = typeof import("./wat.mjs", { assert: { a: (() => { + ~~~~~~~~ console.log("why can you write js here????"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ })(), + ~~~~~~~~ +!!! error TS2837: Import assertion values must be string literal expressions. } }); // Import type with number literal (should error) - type T2 = typeof import("wat", { - ~~~~~ -!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + type T2 = typeof import("./wat.mjs", { assert: { field: 0 } + ~ +!!! error TS2837: Import assertion values must be string literal expressions. }); // Import type with template literal (should error) - type T3 = typeof import("wat", { - ~~~~~ -!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + type T3 = typeof import("./wat.mjs", { assert: { field: `a` } + ~~~ +!!! error TS2837: Import assertion values must be string literal expressions. }); // Import type with regex (should error) - type T4 = typeof import("wat", { - ~~~~~ -!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + type T4 = typeof import("./wat.mjs", { assert: { field: /a/g } + ~~~~ +!!! error TS2837: Import assertion values must be string literal expressions. }); // Import type with array (should error) - type T5 = typeof import("wat", { - ~~~~~ -!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + type T5 = typeof import("./wat.mjs", { assert: { field: ["a"] } + ~~~~~ +!!! error TS2837: Import assertion values must be string literal expressions. }); // Import type with object (should error) - type T6 = typeof import("wat", { - ~~~~~ -!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + type T6 = typeof import("./wat.mjs", { assert: { field: { a: 0 } } + ~~~~~~~~ +!!! error TS2837: Import assertion values must be string literal expressions. }); // Import type with method call (should error) - type T7 = typeof import("wat", { - ~~~~~ -!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + type T7 = typeof import("./wat.mjs", { assert: { field: 0..toString() } + ~~~~~~~~~~~~~ +!!! error TS2837: Import assertion values must be string literal expressions. }); // Import type with valid string literal (should work) - type T8 = typeof import("wat", { - ~~~~~ -!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + type T8 = typeof import("./wat.mjs", { assert: { type: "json" } }); // Import type with 'with' keyword and valid string (should work) - type T9 = typeof import("wat", { - ~~~~~ -!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + type T9 = typeof import("./wat.mjs", { with: { type: "json" } }); // Import type with 'with' keyword and invalid expression (should error) - type T10 = typeof import("wat", { - ~~~~~ -!!! error TS2307: Cannot find module 'wat' or its corresponding type declarations. + type T10 = typeof import("./wat.mjs", { with: { field: 123 } + ~~~ +!!! error TS2858: Import attribute values must be string literal expressions. }); \ No newline at end of file diff --git a/tests/baselines/reference/importTypeAttributesNonString.js b/tests/baselines/reference/importTypeAttributesNonString.js index 01ead3369d441..590497bcee25e 100644 --- a/tests/baselines/reference/importTypeAttributesNonString.js +++ b/tests/baselines/reference/importTypeAttributesNonString.js @@ -1,10 +1,11 @@ //// [tests/cases/compiler/importTypeAttributesNonString.ts] //// +//// [wat.mts] +export const x = 1; + //// [mod.mts] -declare module "wat"; - // Import type with function expression (should error) -type T1 = typeof import("wat", { +type T1 = typeof import("./wat.mjs", { assert: { a: (() => { console.log("why can you write js here????"); @@ -13,50 +14,52 @@ type T1 = typeof import("wat", { }); // Import type with number literal (should error) -type T2 = typeof import("wat", { +type T2 = typeof import("./wat.mjs", { assert: { field: 0 } }); // Import type with template literal (should error) -type T3 = typeof import("wat", { +type T3 = typeof import("./wat.mjs", { assert: { field: `a` } }); // Import type with regex (should error) -type T4 = typeof import("wat", { +type T4 = typeof import("./wat.mjs", { assert: { field: /a/g } }); // Import type with array (should error) -type T5 = typeof import("wat", { +type T5 = typeof import("./wat.mjs", { assert: { field: ["a"] } }); // Import type with object (should error) -type T6 = typeof import("wat", { +type T6 = typeof import("./wat.mjs", { assert: { field: { a: 0 } } }); // Import type with method call (should error) -type T7 = typeof import("wat", { +type T7 = typeof import("./wat.mjs", { assert: { field: 0..toString() } }); // Import type with valid string literal (should work) -type T8 = typeof import("wat", { +type T8 = typeof import("./wat.mjs", { assert: { type: "json" } }); // Import type with 'with' keyword and valid string (should work) -type T9 = typeof import("wat", { +type T9 = typeof import("./wat.mjs", { with: { type: "json" } }); // Import type with 'with' keyword and invalid expression (should error) -type T10 = typeof import("wat", { +type T10 = typeof import("./wat.mjs", { with: { field: 123 } }); +//// [wat.mjs] +export const x = 1; //// [mod.mjs] export {}; diff --git a/tests/baselines/reference/importTypeAttributesNonString.symbols b/tests/baselines/reference/importTypeAttributesNonString.symbols index 6286be5c0ac9d..409b19a529c2d 100644 --- a/tests/baselines/reference/importTypeAttributesNonString.symbols +++ b/tests/baselines/reference/importTypeAttributesNonString.symbols @@ -1,12 +1,13 @@ //// [tests/cases/compiler/importTypeAttributesNonString.ts] //// -=== mod.mts === -declare module "wat"; ->"wat" : Symbol("wat", Decl(mod.mts, 0, 0)) +=== wat.mts === +export const x = 1; +>x : Symbol(x, Decl(wat.mts, 0, 12)) +=== mod.mts === // Import type with function expression (should error) -type T1 = typeof import("wat", { ->T1 : Symbol(T1, Decl(mod.mts, 0, 21)) +type T1 = typeof import("./wat.mjs", { +>T1 : Symbol(T1, Decl(mod.mts, 0, 0)) assert: { a: (() => { @@ -20,45 +21,45 @@ type T1 = typeof import("wat", { }); // Import type with number literal (should error) -type T2 = typeof import("wat", { ->T2 : Symbol(T2, Decl(mod.mts, 9, 3)) +type T2 = typeof import("./wat.mjs", { +>T2 : Symbol(T2, Decl(mod.mts, 7, 3)) assert: { field: 0 } }); // Import type with template literal (should error) -type T3 = typeof import("wat", { ->T3 : Symbol(T3, Decl(mod.mts, 14, 3)) +type T3 = typeof import("./wat.mjs", { +>T3 : Symbol(T3, Decl(mod.mts, 12, 3)) assert: { field: `a` } }); // Import type with regex (should error) -type T4 = typeof import("wat", { ->T4 : Symbol(T4, Decl(mod.mts, 19, 3)) +type T4 = typeof import("./wat.mjs", { +>T4 : Symbol(T4, Decl(mod.mts, 17, 3)) assert: { field: /a/g } }); // Import type with array (should error) -type T5 = typeof import("wat", { ->T5 : Symbol(T5, Decl(mod.mts, 24, 3)) +type T5 = typeof import("./wat.mjs", { +>T5 : Symbol(T5, Decl(mod.mts, 22, 3)) assert: { field: ["a"] } }); // Import type with object (should error) -type T6 = typeof import("wat", { ->T6 : Symbol(T6, Decl(mod.mts, 29, 3)) +type T6 = typeof import("./wat.mjs", { +>T6 : Symbol(T6, Decl(mod.mts, 27, 3)) assert: { field: { a: 0 } } ->a : Symbol(a, Decl(mod.mts, 33, 20)) +>a : Symbol(a, Decl(mod.mts, 31, 20)) }); // Import type with method call (should error) -type T7 = typeof import("wat", { ->T7 : Symbol(T7, Decl(mod.mts, 34, 3)) +type T7 = typeof import("./wat.mjs", { +>T7 : Symbol(T7, Decl(mod.mts, 32, 3)) assert: { field: 0..toString() } >0..toString : Symbol(Number.toString, Decl(lib.es5.d.ts, --, --)) @@ -67,22 +68,22 @@ type T7 = typeof import("wat", { }); // Import type with valid string literal (should work) -type T8 = typeof import("wat", { ->T8 : Symbol(T8, Decl(mod.mts, 39, 3)) +type T8 = typeof import("./wat.mjs", { +>T8 : Symbol(T8, Decl(mod.mts, 37, 3)) assert: { type: "json" } }); // Import type with 'with' keyword and valid string (should work) -type T9 = typeof import("wat", { ->T9 : Symbol(T9, Decl(mod.mts, 44, 3)) +type T9 = typeof import("./wat.mjs", { +>T9 : Symbol(T9, Decl(mod.mts, 42, 3)) with: { type: "json" } }); // Import type with 'with' keyword and invalid expression (should error) -type T10 = typeof import("wat", { ->T10 : Symbol(T10, Decl(mod.mts, 49, 3)) +type T10 = typeof import("./wat.mjs", { +>T10 : Symbol(T10, Decl(mod.mts, 47, 3)) with: { field: 123 } }); diff --git a/tests/baselines/reference/importTypeAttributesNonString.types b/tests/baselines/reference/importTypeAttributesNonString.types index a67f6a8e39e1e..271eb6aa46fdf 100644 --- a/tests/baselines/reference/importTypeAttributesNonString.types +++ b/tests/baselines/reference/importTypeAttributesNonString.types @@ -1,14 +1,17 @@ //// [tests/cases/compiler/importTypeAttributesNonString.ts] //// -=== mod.mts === -declare module "wat"; ->"wat" : any -> : ^^^ +=== wat.mts === +export const x = 1; +>x : 1 +> : ^ +>1 : 1 +> : ^ +=== mod.mts === // Import type with function expression (should error) -type T1 = typeof import("wat", { ->T1 : any -> : ^^^ +type T1 = typeof import("./wat.mjs", { +>T1 : typeof import("wat") +> : ^^^^^^^^^^^^^^^^^^^^ assert: { a: (() => { @@ -38,9 +41,9 @@ type T1 = typeof import("wat", { }); // Import type with number literal (should error) -type T2 = typeof import("wat", { ->T2 : any -> : ^^^ +type T2 = typeof import("./wat.mjs", { +>T2 : typeof import("wat") +> : ^^^^^^^^^^^^^^^^^^^^ assert: { field: 0 } >field : any @@ -49,9 +52,9 @@ type T2 = typeof import("wat", { }); // Import type with template literal (should error) -type T3 = typeof import("wat", { ->T3 : any -> : ^^^ +type T3 = typeof import("./wat.mjs", { +>T3 : typeof import("wat") +> : ^^^^^^^^^^^^^^^^^^^^ assert: { field: `a` } >field : any @@ -60,9 +63,9 @@ type T3 = typeof import("wat", { }); // Import type with regex (should error) -type T4 = typeof import("wat", { ->T4 : any -> : ^^^ +type T4 = typeof import("./wat.mjs", { +>T4 : typeof import("wat") +> : ^^^^^^^^^^^^^^^^^^^^ assert: { field: /a/g } >field : any @@ -73,9 +76,9 @@ type T4 = typeof import("wat", { }); // Import type with array (should error) -type T5 = typeof import("wat", { ->T5 : any -> : ^^^ +type T5 = typeof import("./wat.mjs", { +>T5 : typeof import("wat") +> : ^^^^^^^^^^^^^^^^^^^^ assert: { field: ["a"] } >field : any @@ -88,9 +91,9 @@ type T5 = typeof import("wat", { }); // Import type with object (should error) -type T6 = typeof import("wat", { ->T6 : any -> : ^^^ +type T6 = typeof import("./wat.mjs", { +>T6 : typeof import("wat") +> : ^^^^^^^^^^^^^^^^^^^^ assert: { field: { a: 0 } } >field : any @@ -105,9 +108,9 @@ type T6 = typeof import("wat", { }); // Import type with method call (should error) -type T7 = typeof import("wat", { ->T7 : any -> : ^^^ +type T7 = typeof import("./wat.mjs", { +>T7 : typeof import("wat") +> : ^^^^^^^^^^^^^^^^^^^^ assert: { field: 0..toString() } >field : any @@ -124,9 +127,9 @@ type T7 = typeof import("wat", { }); // Import type with valid string literal (should work) -type T8 = typeof import("wat", { ->T8 : any -> : ^^^ +type T8 = typeof import("./wat.mjs", { +>T8 : typeof import("wat") +> : ^^^^^^^^^^^^^^^^^^^^ assert: { type: "json" } >type : any @@ -135,9 +138,9 @@ type T8 = typeof import("wat", { }); // Import type with 'with' keyword and valid string (should work) -type T9 = typeof import("wat", { ->T9 : any -> : ^^^ +type T9 = typeof import("./wat.mjs", { +>T9 : typeof import("wat") +> : ^^^^^^^^^^^^^^^^^^^^ with: { type: "json" } >type : any @@ -146,9 +149,9 @@ type T9 = typeof import("wat", { }); // Import type with 'with' keyword and invalid expression (should error) -type T10 = typeof import("wat", { ->T10 : any -> : ^^^ +type T10 = typeof import("./wat.mjs", { +>T10 : typeof import("wat") +> : ^^^^^^^^^^^^^^^^^^^^ with: { field: 123 } >field : any diff --git a/tests/cases/compiler/importTypeAttributesNonString.ts b/tests/cases/compiler/importTypeAttributesNonString.ts index f93e1faf97660..bc117956e78af 100644 --- a/tests/cases/compiler/importTypeAttributesNonString.ts +++ b/tests/cases/compiler/importTypeAttributesNonString.ts @@ -1,9 +1,11 @@ // @module: nodenext +// @filename: wat.mts +export const x = 1; + // @filename: mod.mts -declare module "wat"; // Import type with function expression (should error) -type T1 = typeof import("wat", { +type T1 = typeof import("./wat.mjs", { assert: { a: (() => { console.log("why can you write js here????"); @@ -12,46 +14,46 @@ type T1 = typeof import("wat", { }); // Import type with number literal (should error) -type T2 = typeof import("wat", { +type T2 = typeof import("./wat.mjs", { assert: { field: 0 } }); // Import type with template literal (should error) -type T3 = typeof import("wat", { +type T3 = typeof import("./wat.mjs", { assert: { field: `a` } }); // Import type with regex (should error) -type T4 = typeof import("wat", { +type T4 = typeof import("./wat.mjs", { assert: { field: /a/g } }); // Import type with array (should error) -type T5 = typeof import("wat", { +type T5 = typeof import("./wat.mjs", { assert: { field: ["a"] } }); // Import type with object (should error) -type T6 = typeof import("wat", { +type T6 = typeof import("./wat.mjs", { assert: { field: { a: 0 } } }); // Import type with method call (should error) -type T7 = typeof import("wat", { +type T7 = typeof import("./wat.mjs", { assert: { field: 0..toString() } }); // Import type with valid string literal (should work) -type T8 = typeof import("wat", { +type T8 = typeof import("./wat.mjs", { assert: { type: "json" } }); // Import type with 'with' keyword and valid string (should work) -type T9 = typeof import("wat", { +type T9 = typeof import("./wat.mjs", { with: { type: "json" } }); // Import type with 'with' keyword and invalid expression (should error) -type T10 = typeof import("wat", { +type T10 = typeof import("./wat.mjs", { with: { field: 123 } }); From f80cada659d7a96b9b6466c28c56610fb0926cc9 Mon Sep 17 00:00:00 2001 From: Stuart Dotson Date: Tue, 21 Oct 2025 11:11:24 -0400 Subject: [PATCH 4/5] Validate import attribute values before type checking to avoid performance issues --- src/compiler/checker.ts | 18 +++++------ .../importAssertionNonstring.errors.txt | 30 +------------------ ...mportAttributes6(module=node18).errors.txt | 30 +------------------ ...mportAttributes6(module=node20).errors.txt | 30 +------------------ ...ortAttributes6(module=nodenext).errors.txt | 30 +------------------ .../importTypeAttributesNonString.types | 30 +++++++------------ 6 files changed, 23 insertions(+), 145 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 30e52bd1d40ab..7bf615735312c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19933,15 +19933,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { links.resolvedSymbol = unknownSymbol; return links.resolvedType = errorType; } - // Validate import attributes - if (node.attributes) { - const diagnostic = node.attributes.token === SyntaxKind.WithKeyword ? Diagnostics.Import_attribute_values_must_be_string_literal_expressions : Diagnostics.Import_assertion_values_must_be_string_literal_expressions; - for (const attr of node.attributes.elements) { - if (!isStringLiteral(attr.value)) { - error(attr.value, diagnostic); - } - } - } const targetMeaning = node.isTypeOf ? SymbolFlags.Value : node.flags & NodeFlags.JSDoc ? SymbolFlags.Value | SymbolFlags.Type : SymbolFlags.Type; // TODO: Future work: support unions/generics/whatever via a deferred import-type const innerModuleSymbol = resolveExternalModuleName(node, node.argument.literal); @@ -48573,6 +48564,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function checkImportAttribute(node: ImportAttribute) { + // Validate that the value is a string literal before type checking + if (!isStringLiteral(node.value)) { + const parent = node.parent; + const diagnostic = parent.token === SyntaxKind.WithKeyword + ? Diagnostics.Import_attribute_values_must_be_string_literal_expressions + : Diagnostics.Import_assertion_values_must_be_string_literal_expressions; + error(node.value, diagnostic); + return errorType; + } return getRegularTypeOfLiteralType(checkExpressionCached(node.value)); } diff --git a/tests/baselines/reference/importAssertionNonstring.errors.txt b/tests/baselines/reference/importAssertionNonstring.errors.txt index a220b1f213eaa..2112d47fd934a 100644 --- a/tests/baselines/reference/importAssertionNonstring.errors.txt +++ b/tests/baselines/reference/importAssertionNonstring.errors.txt @@ -1,37 +1,21 @@ 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 (16 errors) ==== +==== mod.mts (12 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. @@ -44,30 +28,18 @@ mod.mts(11,66): error TS2837: Import assertion values must be string literal exp 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. import * as thing4 from "./mod.mjs" assert {field: ["a"]}; ~~~~~~ !!! error TS2880: Import assertions have been replaced by import attributes. Use 'with' instead of 'assert'. - ~~~~~~~~~~~~~~~~~~~~~ -!!! 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. 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. diff --git a/tests/baselines/reference/importAttributes6(module=node18).errors.txt b/tests/baselines/reference/importAttributes6(module=node18).errors.txt index f2f160a4bd0e1..18fa0ba6b693d 100644 --- a/tests/baselines/reference/importAttributes6(module=node18).errors.txt +++ b/tests/baselines/reference/importAttributes6(module=node18).errors.txt @@ -1,53 +1,25 @@ -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 (10 errors) ==== +==== mod.mts (6 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. 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. 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. import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; diff --git a/tests/baselines/reference/importAttributes6(module=node20).errors.txt b/tests/baselines/reference/importAttributes6(module=node20).errors.txt index f2f160a4bd0e1..18fa0ba6b693d 100644 --- a/tests/baselines/reference/importAttributes6(module=node20).errors.txt +++ b/tests/baselines/reference/importAttributes6(module=node20).errors.txt @@ -1,53 +1,25 @@ -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 (10 errors) ==== +==== mod.mts (6 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. 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. 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. import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; diff --git a/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt b/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt index f2f160a4bd0e1..18fa0ba6b693d 100644 --- a/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt +++ b/tests/baselines/reference/importAttributes6(module=nodenext).errors.txt @@ -1,53 +1,25 @@ -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 (10 errors) ==== +==== mod.mts (6 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. 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. 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. import * as thing6 from "./mod.mjs" with { type: "json", field: 0..toString() }; diff --git a/tests/baselines/reference/importTypeAttributesNonString.types b/tests/baselines/reference/importTypeAttributesNonString.types index 271eb6aa46fdf..28ab29153f16f 100644 --- a/tests/baselines/reference/importTypeAttributesNonString.types +++ b/tests/baselines/reference/importTypeAttributesNonString.types @@ -15,8 +15,7 @@ type T1 = typeof import("./wat.mjs", { assert: { a: (() => { ->a : any -> : ^^^ +>a : error >(() => { console.log("why can you write js here????"); })() : void > : ^^^^ >(() => { console.log("why can you write js here????"); }) : () => void @@ -46,8 +45,7 @@ type T2 = typeof import("./wat.mjs", { > : ^^^^^^^^^^^^^^^^^^^^ assert: { field: 0 } ->field : any -> : ^^^ +>field : error }); @@ -57,8 +55,7 @@ type T3 = typeof import("./wat.mjs", { > : ^^^^^^^^^^^^^^^^^^^^ assert: { field: `a` } ->field : any -> : ^^^ +>field : error }); @@ -68,8 +65,7 @@ type T4 = typeof import("./wat.mjs", { > : ^^^^^^^^^^^^^^^^^^^^ assert: { field: /a/g } ->field : any -> : ^^^ +>field : error >/a/g : RegExp > : ^^^^^^ @@ -81,8 +77,7 @@ type T5 = typeof import("./wat.mjs", { > : ^^^^^^^^^^^^^^^^^^^^ assert: { field: ["a"] } ->field : any -> : ^^^ +>field : error >["a"] : string[] > : ^^^^^^^^ >"a" : "a" @@ -96,8 +91,7 @@ type T6 = typeof import("./wat.mjs", { > : ^^^^^^^^^^^^^^^^^^^^ assert: { field: { a: 0 } } ->field : any -> : ^^^ +>field : error >{ a: 0 } : { a: number; } > : ^^^^^^^^^^^^^^ >a : number @@ -113,8 +107,7 @@ type T7 = typeof import("./wat.mjs", { > : ^^^^^^^^^^^^^^^^^^^^ assert: { field: 0..toString() } ->field : any -> : ^^^ +>field : error >0..toString() : string > : ^^^^^^ >0..toString : (radix?: number) => string @@ -132,8 +125,7 @@ type T8 = typeof import("./wat.mjs", { > : ^^^^^^^^^^^^^^^^^^^^ assert: { type: "json" } ->type : any -> : ^^^ +>type : error }); @@ -143,8 +135,7 @@ type T9 = typeof import("./wat.mjs", { > : ^^^^^^^^^^^^^^^^^^^^ with: { type: "json" } ->type : any -> : ^^^ +>type : error }); @@ -154,8 +145,7 @@ type T10 = typeof import("./wat.mjs", { > : ^^^^^^^^^^^^^^^^^^^^ with: { field: 123 } ->field : any -> : ^^^ +>field : error }); From 58da68fc0aca7e85b3501959fccc87c9f33a944e Mon Sep 17 00:00:00 2001 From: Stuart Dotson Date: Tue, 21 Oct 2025 11:54:33 -0400 Subject: [PATCH 5/5] remove unused file --- .../importTypeAttributesNonString.errors.txt | 86 ------------------- 1 file changed, 86 deletions(-) delete mode 100644 tests/baselines/reference/importTypeAttributesNonString.errors.txt diff --git a/tests/baselines/reference/importTypeAttributesNonString.errors.txt b/tests/baselines/reference/importTypeAttributesNonString.errors.txt deleted file mode 100644 index 0794b7d7963fb..0000000000000 --- a/tests/baselines/reference/importTypeAttributesNonString.errors.txt +++ /dev/null @@ -1,86 +0,0 @@ -mod.mts(4,8): error TS2837: Import assertion values must be string literal expressions. -mod.mts(12,20): error TS2837: Import assertion values must be string literal expressions. -mod.mts(17,20): error TS2837: Import assertion values must be string literal expressions. -mod.mts(22,20): error TS2837: Import assertion values must be string literal expressions. -mod.mts(27,20): error TS2837: Import assertion values must be string literal expressions. -mod.mts(32,20): error TS2837: Import assertion values must be string literal expressions. -mod.mts(37,20): error TS2837: Import assertion values must be string literal expressions. -mod.mts(52,18): error TS2858: Import attribute values must be string literal expressions. - - -==== wat.mts (0 errors) ==== - export const x = 1; - -==== mod.mts (8 errors) ==== - // Import type with function expression (should error) - type T1 = typeof import("./wat.mjs", { - assert: { - a: (() => { - ~~~~~~~~ - console.log("why can you write js here????"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - })(), - ~~~~~~~~ -!!! error TS2837: Import assertion values must be string literal expressions. - } - }); - - // Import type with number literal (should error) - type T2 = typeof import("./wat.mjs", { - assert: { field: 0 } - ~ -!!! error TS2837: Import assertion values must be string literal expressions. - }); - - // Import type with template literal (should error) - type T3 = typeof import("./wat.mjs", { - assert: { field: `a` } - ~~~ -!!! error TS2837: Import assertion values must be string literal expressions. - }); - - // Import type with regex (should error) - type T4 = typeof import("./wat.mjs", { - assert: { field: /a/g } - ~~~~ -!!! error TS2837: Import assertion values must be string literal expressions. - }); - - // Import type with array (should error) - type T5 = typeof import("./wat.mjs", { - assert: { field: ["a"] } - ~~~~~ -!!! error TS2837: Import assertion values must be string literal expressions. - }); - - // Import type with object (should error) - type T6 = typeof import("./wat.mjs", { - assert: { field: { a: 0 } } - ~~~~~~~~ -!!! error TS2837: Import assertion values must be string literal expressions. - }); - - // Import type with method call (should error) - type T7 = typeof import("./wat.mjs", { - assert: { field: 0..toString() } - ~~~~~~~~~~~~~ -!!! error TS2837: Import assertion values must be string literal expressions. - }); - - // Import type with valid string literal (should work) - type T8 = typeof import("./wat.mjs", { - assert: { type: "json" } - }); - - // Import type with 'with' keyword and valid string (should work) - type T9 = typeof import("./wat.mjs", { - with: { type: "json" } - }); - - // Import type with 'with' keyword and invalid expression (should error) - type T10 = typeof import("./wat.mjs", { - with: { field: 123 } - ~~~ -!!! error TS2858: Import attribute values must be string literal expressions. - }); - \ No newline at end of file