From 9c504f97ca0e1dada01ac0a904a9c3bd8da4e8b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 14 Oct 2025 11:06:24 +0200 Subject: [PATCH] Allow line break before import attributes `with` keyword --- src/compiler/parser.ts | 2 +- .../reference/importAttributes11.symbols | 24 ++++++++++++++ .../reference/importAttributes11.types | 31 +++++++++++++++++++ .../importAttributes/importAttributes11.ts | 21 +++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/importAttributes11.symbols create mode 100644 tests/baselines/reference/importAttributes11.types create mode 100644 tests/cases/conformance/importAttributes/importAttributes11.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1759f267cdce9..d641cbd4b65e7 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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); } } diff --git a/tests/baselines/reference/importAttributes11.symbols b/tests/baselines/reference/importAttributes11.symbols new file mode 100644 index 0000000000000..70150101f43cb --- /dev/null +++ b/tests/baselines/reference/importAttributes11.symbols @@ -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"} + diff --git a/tests/baselines/reference/importAttributes11.types b/tests/baselines/reference/importAttributes11.types new file mode 100644 index 0000000000000..96a95348002b9 --- /dev/null +++ b/tests/baselines/reference/importAttributes11.types @@ -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 + diff --git a/tests/cases/conformance/importAttributes/importAttributes11.ts b/tests/cases/conformance/importAttributes/importAttributes11.ts new file mode 100644 index 0000000000000..f3504d642b792 --- /dev/null +++ b/tests/cases/conformance/importAttributes/importAttributes11.ts @@ -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"}