Allow line break before import attributes with keyword (#62593)

This commit is contained in:
Mateusz Burzyński 2025-10-14 18:51:33 +02:00 committed by GitHub
parent 0b6a241886
commit d3be7e171b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 77 additions and 1 deletions

View File

@ -8435,7 +8435,7 @@ namespace Parser {
function tryParseImportAttributes() {
const currentToken = token();
if ((currentToken === SyntaxKind.WithKeyword || currentToken === SyntaxKind.AssertKeyword) && !scanner.hasPrecedingLineBreak()) {
if (currentToken === SyntaxKind.WithKeyword || (currentToken === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak())) {
return parseImportAttributes(currentToken);
}
}

View File

@ -0,0 +1,24 @@
//// [tests/cases/conformance/importAttributes/importAttributes11.ts] ////
=== ./a.json ===
{ "key": "value" }
>"key" : Symbol("key", Decl(a.json, 0, 1))
=== ./b.mts ===
declare global {
>global : Symbol(global, Decl(b.mts, 0, 0))
interface ImportAttributes {
>ImportAttributes : Symbol(ImportAttributes, Decl(lib.es5.d.ts, --, --), Decl(b.mts, 0, 16))
type: "json"
>type : Symbol(ImportAttributes.type, Decl(b.mts, 1, 32))
}
}
import a
>a : Symbol(a, Decl(b.mts, 6, 6))
from "./a.json"
with {type: "json"}

View File

@ -0,0 +1,31 @@
//// [tests/cases/conformance/importAttributes/importAttributes11.ts] ////
=== ./a.json ===
{ "key": "value" }
>{ "key": "value" } : { key: string; }
> : ^^^^^^^^^^^^^^^^
>"key" : string
> : ^^^^^^
>"value" : "value"
> : ^^^^^^^
=== ./b.mts ===
declare global {
>global : any
> : ^^^
interface ImportAttributes {
type: "json"
>type : "json"
> : ^^^^^^
}
}
import a
>a : { key: string; }
> : ^^^^^^^^^^^^^^^^
from "./a.json"
with {type: "json"}
>type : error

View File

@ -0,0 +1,21 @@
// @strict: true
// @target: esnext
// @module: nodenext
// @moduleResolution: nodenext
// @noEmit: true
// https://github.com/microsoft/TypeScript/issues/62590
// @filename: ./a.json
{ "key": "value" }
// @filename: ./b.mts
declare global {
interface ImportAttributes {
type: "json"
}
}
import a
from "./a.json"
with {type: "json"}