Skip to content

Commit a9f534f

Browse files
Correctly split line endings for // @testOption: value parsing (#62987)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 64d1978 commit a9f534f

13 files changed

+45
-59
lines changed

src/harness/harnessUtils.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@ export function evalFile(fileContents: string, fileName: string, nodeContext?: a
1515
}
1616
}
1717

18-
/** Splits the given string on \r\n, or on only \n if that fails, or on only \r if *that* fails. */
18+
const newlineRegex = /\r?\n/;
19+
20+
/**
21+
* Splits the given string on the two reasonable line terminators (\r\n or \n).
22+
* Does NOT split on `\r` alone, \u2028, or \u2029.
23+
*/
1924
export function splitContentByNewlines(content: string): string[] {
2025
// Split up the input file by line
21-
// Note: IE JS engine incorrectly handles consecutive delimiters here when using RegExp split, so
22-
// we have to use string-based splitting instead and try to figure out the delimiting chars
23-
let lines = content.split("\r\n");
24-
if (lines.length === 1) {
25-
lines = content.split("\n");
26-
27-
if (lines.length === 1) {
28-
lines = content.split("\r");
29-
}
30-
}
26+
const lines = content.split(newlineRegex);
3127
return lines;
3228
}
3329

tests/baselines/reference/decoratedClassExportsCommonJS1.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
//// [tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts] ////
22

3-
//// [decoratedClassExportsCommonJS1.ts]
3+
//// [a.ts]
4+
declare function forwardRef(x: any): any;
45
declare var Something: any;
56
@Something({ v: () => Testing123 })
67
export class Testing123 {
78
static prop0: string;
89
static prop1 = Testing123.prop0;
910
}
1011

11-
//// [decoratedClassExportsCommonJS1.js]
12+
//// [a.js]
1213
"use strict";
1314
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
1415
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
//// [tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts] ////
22

3-
=== decoratedClassExportsCommonJS1.ts ===
3+
=== a.ts ===
4+
declare function forwardRef(x: any): any;
5+
>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0))
6+
>x : Symbol(x, Decl(a.ts, 0, 28))
7+
48
declare var Something: any;
5-
>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11))
9+
>Something : Symbol(Something, Decl(a.ts, 1, 11))
610

711
@Something({ v: () => Testing123 })
8-
>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11))
9-
>v : Symbol(v, Decl(decoratedClassExportsCommonJS1.ts, 1, 12))
10-
>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27))
12+
>Something : Symbol(Something, Decl(a.ts, 1, 11))
13+
>v : Symbol(v, Decl(a.ts, 2, 12))
14+
>Testing123 : Symbol(Testing123, Decl(a.ts, 1, 27))
1115

1216
export class Testing123 {
13-
>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27))
17+
>Testing123 : Symbol(Testing123, Decl(a.ts, 1, 27))
1418

1519
static prop0: string;
16-
>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25))
20+
>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 3, 25))
1721

1822
static prop1 = Testing123.prop0;
19-
>prop1 : Symbol(Testing123.prop1, Decl(decoratedClassExportsCommonJS1.ts, 3, 25))
20-
>Testing123.prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25))
21-
>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27))
22-
>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25))
23+
>prop1 : Symbol(Testing123.prop1, Decl(a.ts, 4, 25))
24+
>Testing123.prop0 : Symbol(Testing123.prop0, Decl(a.ts, 3, 25))
25+
>Testing123 : Symbol(Testing123, Decl(a.ts, 1, 27))
26+
>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 3, 25))
2327
}

tests/baselines/reference/decoratedClassExportsCommonJS1.types

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
//// [tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts] ////
22

3-
=== decoratedClassExportsCommonJS1.ts ===
3+
=== a.ts ===
4+
declare function forwardRef(x: any): any;
5+
>forwardRef : (x: any) => any
6+
> : ^ ^^ ^^^^^
7+
>x : any
8+
49
declare var Something: any;
510
>Something : any
611

tests/baselines/reference/genericArray0.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//// [tests/cases/compiler/genericArray0.ts] ////
22

33
//// [genericArray0.ts]
4-
54
var x:number[];
65

76

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
//// [tests/cases/compiler/genericArray0.ts] ////
22

33
=== genericArray0.ts ===
4-
54
var x:number[];
6-
>x : Symbol(x, Decl(genericArray0.ts, 1, 3))
5+
>x : Symbol(x, Decl(genericArray0.ts, 0, 3))
76

87

98
var y = x;
10-
>y : Symbol(y, Decl(genericArray0.ts, 4, 3))
11-
>x : Symbol(x, Decl(genericArray0.ts, 1, 3))
9+
>y : Symbol(y, Decl(genericArray0.ts, 3, 3))
10+
>x : Symbol(x, Decl(genericArray0.ts, 0, 3))
1211

1312
function map<U>() {
14-
>map : Symbol(map, Decl(genericArray0.ts, 4, 10))
15-
>U : Symbol(U, Decl(genericArray0.ts, 6, 13))
13+
>map : Symbol(map, Decl(genericArray0.ts, 3, 10))
14+
>U : Symbol(U, Decl(genericArray0.ts, 5, 13))
1615

1716
var ys: U[] = [];
18-
>ys : Symbol(ys, Decl(genericArray0.ts, 7, 7))
19-
>U : Symbol(U, Decl(genericArray0.ts, 6, 13))
17+
>ys : Symbol(ys, Decl(genericArray0.ts, 6, 7))
18+
>U : Symbol(U, Decl(genericArray0.ts, 5, 13))
2019
}
2120

tests/baselines/reference/genericArray0.types

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//// [tests/cases/compiler/genericArray0.ts] ////
22

33
=== genericArray0.ts ===
4-
54
var x:number[];
65
>x : number[]
76
> : ^^^^^^^^

tests/baselines/reference/templateStringMultiline3.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
//// [tests/cases/conformance/es6/templates/templateStringMultiline3.ts] ////
22

33
//// [templateStringMultiline3.ts]
4-
// newlines are <CR>
5-
`
6-
\
7-
`
4+
// newlines are <CR>`\`
85

96
//// [templateStringMultiline3.js]
107
// newlines are <CR>

tests/baselines/reference/templateStringMultiline3.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
=== templateStringMultiline3.ts ===
44

5+
56
// newlines are <CR>
67
`
78
\

tests/baselines/reference/templateStringMultiline3.types

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//// [tests/cases/conformance/es6/templates/templateStringMultiline3.ts] ////
22

33
=== templateStringMultiline3.ts ===
4+
5+
46
// newlines are <CR>
57
`
6-
>`\` : "\n"
7-
> : ^^^^
8+
>`\` : "\n"
9+
> : ^^^^
810

911
\
1012
`

0 commit comments

Comments
 (0)