Skip to content

Commit 199d256

Browse files
Increased flexibility for multiline comment parsing
1 parent 992441d commit 199d256

File tree

6 files changed

+172
-122
lines changed

6 files changed

+172
-122
lines changed

src/compiler/scanner.ts

+5-5
Large diffs are not rendered by default.
+24-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
tests/cases/conformance/directives/a.ts(10,1): error TS2578: Unused '@ts-expect-error' directive.
2-
tests/cases/conformance/directives/b.tsx(26,1): error TS2578: Unused '@ts-expect-error' directive.
1+
tests/cases/conformance/directives/a.ts(12,1): error TS2578: Unused '@ts-expect-error' directive.
2+
tests/cases/conformance/directives/b.tsx(32,1): error TS2578: Unused '@ts-expect-error' directive.
33

44

55
==== tests/cases/conformance/directives/a.ts (1 errors) ====
6+
export const texts: string[] = [];
7+
68
/**
79
@ts-ignore */
8-
export let x: string = 100;
10+
texts.push(100);
911

1012
/**
1113
@ts-expect-error */
12-
export let y: string = 100;
14+
texts.push(100);
1315

1416
/**
1517
@ts-expect-error */
1618
~~~~~~~~~~~~~~~~~~~~
1719
!!! error TS2578: Unused '@ts-expect-error' directive.
18-
export let ok = 100;
20+
texts.push("100");
1921

2022
==== tests/cases/conformance/directives/b.tsx (1 errors) ====
2123
import * as React from "react";
@@ -28,25 +30,31 @@ tests/cases/conformance/directives/b.tsx(26,1): error TS2578: Unused '@ts-expect
2830
<div>
2931
{/*
3032
@ts-ignore */}
31-
<MyComponent foo={100} />;
32-
</div>
33-
);
33+
<MyComponent foo={100} />
34+
35+
{/*@ts-ignore*/}
36+
<MyComponent foo={100} />
3437

35-
let y = (
36-
<div>
3738
{/*
3839
@ts-expect-error */}
39-
<MyComponent foo={100} />;
40-
</div>
41-
);
40+
<MyComponent foo={100} />
41+
42+
{/*
43+
// @ts-expect-error */}
44+
<MyComponent foo={100} />
45+
46+
{/*
47+
* @ts-expect-error */}
48+
<MyComponent foo={100} />
49+
50+
{/*@ts-expect-error*/}
51+
<MyComponent foo={100} />
4252

43-
let ok = (
44-
<div>
4553
{/*
4654
@ts-expect-error */}
4755
~~~~~~~~~~~~~~~~~~~~~~
4856
!!! error TS2578: Unused '@ts-expect-error' directive.
49-
<MyComponent foo={"hooray"} />;
57+
<MyComponent foo={"hooray"} />
5058
</div>
5159
);
5260

+32-24
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
//// [tests/cases/conformance/directives/multiline.tsx] ////
22

33
//// [a.ts]
4+
export const texts: string[] = [];
5+
46
/**
57
@ts-ignore */
6-
export let x: string = 100;
8+
texts.push(100);
79

810
/**
911
@ts-expect-error */
10-
export let y: string = 100;
12+
texts.push(100);
1113

1214
/**
1315
@ts-expect-error */
14-
export let ok = 100;
16+
texts.push("100");
1517

1618
//// [b.tsx]
1719
import * as React from "react";
@@ -24,40 +26,47 @@ let x = (
2426
<div>
2527
{/*
2628
@ts-ignore */}
27-
<MyComponent foo={100} />;
28-
</div>
29-
);
29+
<MyComponent foo={100} />
30+
31+
{/*@ts-ignore*/}
32+
<MyComponent foo={100} />
3033

31-
let y = (
32-
<div>
3334
{/*
3435
@ts-expect-error */}
35-
<MyComponent foo={100} />;
36-
</div>
37-
);
36+
<MyComponent foo={100} />
37+
38+
{/*
39+
// @ts-expect-error */}
40+
<MyComponent foo={100} />
41+
42+
{/*
43+
* @ts-expect-error */}
44+
<MyComponent foo={100} />
45+
46+
{/*@ts-expect-error*/}
47+
<MyComponent foo={100} />
3848

39-
let ok = (
40-
<div>
4149
{/*
4250
@ts-expect-error */}
43-
<MyComponent foo={"hooray"} />;
51+
<MyComponent foo={"hooray"} />
4452
</div>
4553
);
4654

4755

4856
//// [a.js]
4957
"use strict";
5058
exports.__esModule = true;
51-
exports.ok = exports.y = exports.x = void 0;
59+
exports.texts = void 0;
60+
exports.texts = [];
5261
/**
5362
@ts-ignore */
54-
exports.x = 100;
63+
exports.texts.push(100);
5564
/**
5665
@ts-expect-error */
57-
exports.y = 100;
66+
exports.texts.push(100);
5867
/**
5968
@ts-expect-error */
60-
exports.ok = 100;
69+
exports.texts.push("100");
6170
//// [b.js]
6271
"use strict";
6372
exports.__esModule = true;
@@ -69,10 +78,9 @@ function MyComponent(props) {
6978
exports.MyComponent = MyComponent;
7079
var x = (React.createElement("div", null,
7180
React.createElement(MyComponent, { foo: 100 }),
72-
";"));
73-
var y = (React.createElement("div", null,
7481
React.createElement(MyComponent, { foo: 100 }),
75-
";"));
76-
var ok = (React.createElement("div", null,
77-
React.createElement(MyComponent, { foo: "hooray" }),
78-
";"));
82+
React.createElement(MyComponent, { foo: 100 }),
83+
React.createElement(MyComponent, { foo: 100 }),
84+
React.createElement(MyComponent, { foo: 100 }),
85+
React.createElement(MyComponent, { foo: 100 }),
86+
React.createElement(MyComponent, { foo: "hooray" })));

tests/baselines/reference/multiline.symbols

+38-29
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
=== tests/cases/conformance/directives/a.ts ===
2+
export const texts: string[] = [];
3+
>texts : Symbol(texts, Decl(a.ts, 0, 12))
4+
25
/**
36
@ts-ignore */
4-
export let x: string = 100;
5-
>x : Symbol(x, Decl(a.ts, 2, 10))
7+
texts.push(100);
8+
>texts.push : Symbol(Array.push, Decl(lib.d.ts, --, --))
9+
>texts : Symbol(texts, Decl(a.ts, 0, 12))
10+
>push : Symbol(Array.push, Decl(lib.d.ts, --, --))
611

712
/**
813
@ts-expect-error */
9-
export let y: string = 100;
10-
>y : Symbol(y, Decl(a.ts, 6, 10))
14+
texts.push(100);
15+
>texts.push : Symbol(Array.push, Decl(lib.d.ts, --, --))
16+
>texts : Symbol(texts, Decl(a.ts, 0, 12))
17+
>push : Symbol(Array.push, Decl(lib.d.ts, --, --))
1118

1219
/**
1320
@ts-expect-error */
14-
export let ok = 100;
15-
>ok : Symbol(ok, Decl(a.ts, 10, 10))
21+
texts.push("100");
22+
>texts.push : Symbol(Array.push, Decl(lib.d.ts, --, --))
23+
>texts : Symbol(texts, Decl(a.ts, 0, 12))
24+
>push : Symbol(Array.push, Decl(lib.d.ts, --, --))
1625

1726
=== tests/cases/conformance/directives/b.tsx ===
1827
import * as React from "react";
@@ -35,43 +44,43 @@ let x = (
3544

3645
{/*
3746
@ts-ignore */}
38-
<MyComponent foo={100} />;
47+
<MyComponent foo={100} />
3948
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
4049
>foo : Symbol(foo, Decl(b.tsx, 10, 16))
4150

42-
</div>
43-
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
44-
45-
);
46-
47-
let y = (
48-
>y : Symbol(y, Decl(b.tsx, 14, 3))
49-
50-
<div>
51-
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
51+
{/*@ts-ignore*/}
52+
<MyComponent foo={100} />
53+
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
54+
>foo : Symbol(foo, Decl(b.tsx, 13, 16))
5255

5356
{/*
5457
@ts-expect-error */}
55-
<MyComponent foo={100} />;
58+
<MyComponent foo={100} />
5659
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
57-
>foo : Symbol(foo, Decl(b.tsx, 18, 16))
60+
>foo : Symbol(foo, Decl(b.tsx, 17, 16))
5861

59-
</div>
60-
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
61-
62-
);
62+
{/*
63+
// @ts-expect-error */}
64+
<MyComponent foo={100} />
65+
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
66+
>foo : Symbol(foo, Decl(b.tsx, 21, 16))
6367

64-
let ok = (
65-
>ok : Symbol(ok, Decl(b.tsx, 22, 3))
68+
{/*
69+
* @ts-expect-error */}
70+
<MyComponent foo={100} />
71+
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
72+
>foo : Symbol(foo, Decl(b.tsx, 25, 16))
6673

67-
<div>
68-
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))
74+
{/*@ts-expect-error*/}
75+
<MyComponent foo={100} />
76+
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
77+
>foo : Symbol(foo, Decl(b.tsx, 28, 16))
6978

7079
{/*
7180
@ts-expect-error */}
72-
<MyComponent foo={"hooray"} />;
81+
<MyComponent foo={"hooray"} />
7382
>MyComponent : Symbol(MyComponent, Decl(b.tsx, 0, 31))
74-
>foo : Symbol(foo, Decl(b.tsx, 26, 16))
83+
>foo : Symbol(foo, Decl(b.tsx, 32, 16))
7584

7685
</div>
7786
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 2400, 45))

0 commit comments

Comments
 (0)