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"}