Allow trailing commas after import attributes in ImportType (#61920)

This commit is contained in:
Mateusz Burzyński 2025-06-24 18:49:37 +02:00 committed by GitHub
parent 78c16795cd
commit 50b93bc803
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 246 additions and 0 deletions

View File

@ -4564,6 +4564,7 @@ namespace Parser {
}
parseExpected(SyntaxKind.ColonToken);
attributes = parseImportAttributes(currentToken as SyntaxKind.WithKeyword | SyntaxKind.AssertKeyword, /*skipKeyword*/ true);
parseOptional(SyntaxKind.CommaToken);
if (!parseExpected(SyntaxKind.CloseBraceToken)) {
const lastError = lastOrUndefined(parseDiagnostics);
if (lastError && lastError.code === Diagnostics._0_expected.code) {

View File

@ -0,0 +1,49 @@
b.ts(22,5): error TS1005: '}' expected.
b.ts(23,1): error TS1128: Declaration or statement expected.
b.ts(23,2): error TS1128: Declaration or statement expected.
b.ts(27,18): error TS1478: Identifier or string literal expected.
==== ./a.json (0 errors) ====
{ "key": "value" }
==== ./b.ts (4 errors) ====
declare global {
interface ImportAttributes {
type: "json"
}
}
export type Test1 = typeof import("./a.json", {
with: {
type: "json"
},
});
export type Test2 = typeof import("./a.json", {
with: {
type: "json",
}
});
export type Test3 = typeof import("./a.json", {
with: {
type: "json"
},,
~
!!! error TS1005: '}' expected.
!!! related TS1007 b.ts:19:47: The parser expected to find a '}' to match the '{' token here.
});
~
!!! error TS1128: Declaration or statement expected.
~
!!! error TS1128: Declaration or statement expected.
export type Test4 = typeof import("./a.json", {
with: {
type: "json",,
~
!!! error TS1478: Identifier or string literal expected.
}
});

View File

@ -0,0 +1,41 @@
//// [tests/cases/conformance/importAttributes/importAttributes10.ts] ////
//// [a.json]
{ "key": "value" }
//// [b.ts]
declare global {
interface ImportAttributes {
type: "json"
}
}
export type Test1 = typeof import("./a.json", {
with: {
type: "json"
},
});
export type Test2 = typeof import("./a.json", {
with: {
type: "json",
}
});
export type Test3 = typeof import("./a.json", {
with: {
type: "json"
},,
});
export type Test4 = typeof import("./a.json", {
with: {
type: "json",,
}
});
//// [b.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;

View File

@ -0,0 +1,50 @@
//// [tests/cases/conformance/importAttributes/importAttributes10.ts] ////
=== ./a.json ===
{ "key": "value" }
>"key" : Symbol("key", Decl(a.json, 0, 1))
=== ./b.ts ===
declare global {
>global : Symbol(global, Decl(b.ts, 0, 0))
interface ImportAttributes {
>ImportAttributes : Symbol(ImportAttributes, Decl(lib.es5.d.ts, --, --), Decl(b.ts, 0, 16))
type: "json"
>type : Symbol(ImportAttributes.type, Decl(b.ts, 1, 32))
}
}
export type Test1 = typeof import("./a.json", {
>Test1 : Symbol(Test1, Decl(b.ts, 4, 1))
with: {
type: "json"
},
});
export type Test2 = typeof import("./a.json", {
>Test2 : Symbol(Test2, Decl(b.ts, 10, 3))
with: {
type: "json",
}
});
export type Test3 = typeof import("./a.json", {
>Test3 : Symbol(Test3, Decl(b.ts, 16, 3))
with: {
type: "json"
},,
});
export type Test4 = typeof import("./a.json", {
>Test4 : Symbol(Test4, Decl(b.ts, 22, 3))
with: {
type: "json",,
}
});

View File

@ -0,0 +1,69 @@
//// [tests/cases/conformance/importAttributes/importAttributes10.ts] ////
=== ./a.json ===
{ "key": "value" }
>{ "key": "value" } : { key: string; }
> : ^^^^^^^^^^^^^^^^
>"key" : string
> : ^^^^^^
>"value" : "value"
> : ^^^^^^^
=== ./b.ts ===
declare global {
>global : any
> : ^^^
interface ImportAttributes {
type: "json"
>type : "json"
> : ^^^^^^
}
}
export type Test1 = typeof import("./a.json", {
>Test1 : { key: string; }
> : ^^^^^^^^^^^^^^^^
with: {
type: "json"
>type : any
> : ^^^
},
});
export type Test2 = typeof import("./a.json", {
>Test2 : { key: string; }
> : ^^^^^^^^^^^^^^^^
with: {
type: "json",
>type : any
> : ^^^
}
});
export type Test3 = typeof import("./a.json", {
>Test3 : { key: string; }
> : ^^^^^^^^^^^^^^^^
with: {
type: "json"
>type : any
> : ^^^
},,
});
export type Test4 = typeof import("./a.json", {
>Test4 : { key: string; }
> : ^^^^^^^^^^^^^^^^
with: {
type: "json",,
>type : any
> : ^^^
}
});

View File

@ -0,0 +1,36 @@
// @module: nodenext
// @target: esnext
// @moduleResolution: nodenext
// @filename: ./a.json
{ "key": "value" }
// @filename: ./b.ts
declare global {
interface ImportAttributes {
type: "json"
}
}
export type Test1 = typeof import("./a.json", {
with: {
type: "json"
},
});
export type Test2 = typeof import("./a.json", {
with: {
type: "json",
}
});
export type Test3 = typeof import("./a.json", {
with: {
type: "json"
},,
});
export type Test4 = typeof import("./a.json", {
with: {
type: "json",,
}
});