Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
24 changes: 24 additions & 0 deletions tests/baselines/reference/importAttributes11.symbols
Original file line number Diff line number Diff line change
@@ -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"}

31 changes: 31 additions & 0 deletions tests/baselines/reference/importAttributes11.types
Original file line number Diff line number Diff line change
@@ -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

21 changes: 21 additions & 0 deletions tests/cases/conformance/importAttributes/importAttributes11.ts
Original file line number Diff line number Diff line change
@@ -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"}