Skip to content

Commit d3be7e1

Browse files
authored
Allow line break before import attributes with keyword (#62593)
1 parent 0b6a241 commit d3be7e1

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8435,7 +8435,7 @@ namespace Parser {
84358435

84368436
function tryParseImportAttributes() {
84378437
const currentToken = token();
8438-
if ((currentToken === SyntaxKind.WithKeyword || currentToken === SyntaxKind.AssertKeyword) && !scanner.hasPrecedingLineBreak()) {
8438+
if (currentToken === SyntaxKind.WithKeyword || (currentToken === SyntaxKind.AssertKeyword && !scanner.hasPrecedingLineBreak())) {
84398439
return parseImportAttributes(currentToken);
84408440
}
84418441
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/conformance/importAttributes/importAttributes11.ts] ////
2+
3+
=== ./a.json ===
4+
{ "key": "value" }
5+
>"key" : Symbol("key", Decl(a.json, 0, 1))
6+
7+
=== ./b.mts ===
8+
declare global {
9+
>global : Symbol(global, Decl(b.mts, 0, 0))
10+
11+
interface ImportAttributes {
12+
>ImportAttributes : Symbol(ImportAttributes, Decl(lib.es5.d.ts, --, --), Decl(b.mts, 0, 16))
13+
14+
type: "json"
15+
>type : Symbol(ImportAttributes.type, Decl(b.mts, 1, 32))
16+
}
17+
}
18+
19+
import a
20+
>a : Symbol(a, Decl(b.mts, 6, 6))
21+
22+
from "./a.json"
23+
with {type: "json"}
24+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/conformance/importAttributes/importAttributes11.ts] ////
2+
3+
=== ./a.json ===
4+
{ "key": "value" }
5+
>{ "key": "value" } : { key: string; }
6+
> : ^^^^^^^^^^^^^^^^
7+
>"key" : string
8+
> : ^^^^^^
9+
>"value" : "value"
10+
> : ^^^^^^^
11+
12+
=== ./b.mts ===
13+
declare global {
14+
>global : any
15+
> : ^^^
16+
17+
interface ImportAttributes {
18+
type: "json"
19+
>type : "json"
20+
> : ^^^^^^
21+
}
22+
}
23+
24+
import a
25+
>a : { key: string; }
26+
> : ^^^^^^^^^^^^^^^^
27+
28+
from "./a.json"
29+
with {type: "json"}
30+
>type : error
31+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @strict: true
2+
// @target: esnext
3+
// @module: nodenext
4+
// @moduleResolution: nodenext
5+
// @noEmit: true
6+
7+
// https://github.com/microsoft/TypeScript/issues/62590
8+
9+
// @filename: ./a.json
10+
{ "key": "value" }
11+
12+
// @filename: ./b.mts
13+
declare global {
14+
interface ImportAttributes {
15+
type: "json"
16+
}
17+
}
18+
19+
import a
20+
from "./a.json"
21+
with {type: "json"}

0 commit comments

Comments
 (0)