mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-11 09:24:19 -06:00
Allow trailing commas after import attributes in ImportType (#61920)
This commit is contained in:
parent
78c16795cd
commit
50b93bc803
@ -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) {
|
||||
|
||||
49
tests/baselines/reference/importAttributes10.errors.txt
Normal file
49
tests/baselines/reference/importAttributes10.errors.txt
Normal 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.
|
||||
}
|
||||
});
|
||||
|
||||
41
tests/baselines/reference/importAttributes10.js
Normal file
41
tests/baselines/reference/importAttributes10.js
Normal 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 });
|
||||
;
|
||||
50
tests/baselines/reference/importAttributes10.symbols
Normal file
50
tests/baselines/reference/importAttributes10.symbols
Normal 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",,
|
||||
}
|
||||
});
|
||||
|
||||
69
tests/baselines/reference/importAttributes10.types
Normal file
69
tests/baselines/reference/importAttributes10.types
Normal 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
|
||||
> : ^^^
|
||||
}
|
||||
});
|
||||
|
||||
@ -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",,
|
||||
}
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user