Correctly split line endings for // @testOption: value parsing (#62987)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Daniel Rosenwasser 2026-01-14 19:13:51 -08:00 committed by GitHub
parent 64d1978944
commit a9f534f271
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 45 additions and 59 deletions

View File

@ -15,19 +15,15 @@ export function evalFile(fileContents: string, fileName: string, nodeContext?: a
}
}
/** Splits the given string on \r\n, or on only \n if that fails, or on only \r if *that* fails. */
const newlineRegex = /\r?\n/;
/**
* Splits the given string on the two reasonable line terminators (\r\n or \n).
* Does NOT split on `\r` alone, \u2028, or \u2029.
*/
export function splitContentByNewlines(content: string): string[] {
// Split up the input file by line
// Note: IE JS engine incorrectly handles consecutive delimiters here when using RegExp split, so
// we have to use string-based splitting instead and try to figure out the delimiting chars
let lines = content.split("\r\n");
if (lines.length === 1) {
lines = content.split("\n");
if (lines.length === 1) {
lines = content.split("\r");
}
}
const lines = content.split(newlineRegex);
return lines;
}

View File

@ -1,6 +1,7 @@
//// [tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts] ////
//// [decoratedClassExportsCommonJS1.ts]
//// [a.ts]
declare function forwardRef(x: any): any;
declare var Something: any;
@Something({ v: () => Testing123 })
export class Testing123 {
@ -8,7 +9,7 @@ export class Testing123 {
static prop1 = Testing123.prop0;
}
//// [decoratedClassExportsCommonJS1.js]
//// [a.js]
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;

View File

@ -1,23 +1,27 @@
//// [tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts] ////
=== decoratedClassExportsCommonJS1.ts ===
=== a.ts ===
declare function forwardRef(x: any): any;
>forwardRef : Symbol(forwardRef, Decl(a.ts, 0, 0))
>x : Symbol(x, Decl(a.ts, 0, 28))
declare var Something: any;
>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11))
>Something : Symbol(Something, Decl(a.ts, 1, 11))
@Something({ v: () => Testing123 })
>Something : Symbol(Something, Decl(decoratedClassExportsCommonJS1.ts, 0, 11))
>v : Symbol(v, Decl(decoratedClassExportsCommonJS1.ts, 1, 12))
>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27))
>Something : Symbol(Something, Decl(a.ts, 1, 11))
>v : Symbol(v, Decl(a.ts, 2, 12))
>Testing123 : Symbol(Testing123, Decl(a.ts, 1, 27))
export class Testing123 {
>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27))
>Testing123 : Symbol(Testing123, Decl(a.ts, 1, 27))
static prop0: string;
>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25))
>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 3, 25))
static prop1 = Testing123.prop0;
>prop1 : Symbol(Testing123.prop1, Decl(decoratedClassExportsCommonJS1.ts, 3, 25))
>Testing123.prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25))
>Testing123 : Symbol(Testing123, Decl(decoratedClassExportsCommonJS1.ts, 0, 27))
>prop0 : Symbol(Testing123.prop0, Decl(decoratedClassExportsCommonJS1.ts, 2, 25))
>prop1 : Symbol(Testing123.prop1, Decl(a.ts, 4, 25))
>Testing123.prop0 : Symbol(Testing123.prop0, Decl(a.ts, 3, 25))
>Testing123 : Symbol(Testing123, Decl(a.ts, 1, 27))
>prop0 : Symbol(Testing123.prop0, Decl(a.ts, 3, 25))
}

View File

@ -1,6 +1,11 @@
//// [tests/cases/conformance/decorators/class/decoratedClassExportsCommonJS1.ts] ////
=== decoratedClassExportsCommonJS1.ts ===
=== a.ts ===
declare function forwardRef(x: any): any;
>forwardRef : (x: any) => any
> : ^ ^^ ^^^^^
>x : any
declare var Something: any;
>Something : any

View File

@ -1,7 +1,6 @@
//// [tests/cases/compiler/genericArray0.ts] ////
//// [genericArray0.ts]
var x:number[];

View File

@ -1,21 +1,20 @@
//// [tests/cases/compiler/genericArray0.ts] ////
=== genericArray0.ts ===
var x:number[];
>x : Symbol(x, Decl(genericArray0.ts, 1, 3))
>x : Symbol(x, Decl(genericArray0.ts, 0, 3))
var y = x;
>y : Symbol(y, Decl(genericArray0.ts, 4, 3))
>x : Symbol(x, Decl(genericArray0.ts, 1, 3))
>y : Symbol(y, Decl(genericArray0.ts, 3, 3))
>x : Symbol(x, Decl(genericArray0.ts, 0, 3))
function map<U>() {
>map : Symbol(map, Decl(genericArray0.ts, 4, 10))
>U : Symbol(U, Decl(genericArray0.ts, 6, 13))
>map : Symbol(map, Decl(genericArray0.ts, 3, 10))
>U : Symbol(U, Decl(genericArray0.ts, 5, 13))
var ys: U[] = [];
>ys : Symbol(ys, Decl(genericArray0.ts, 7, 7))
>U : Symbol(U, Decl(genericArray0.ts, 6, 13))
>ys : Symbol(ys, Decl(genericArray0.ts, 6, 7))
>U : Symbol(U, Decl(genericArray0.ts, 5, 13))
}

View File

@ -1,7 +1,6 @@
//// [tests/cases/compiler/genericArray0.ts] ////
=== genericArray0.ts ===
var x:number[];
>x : number[]
> : ^^^^^^^^

View File

@ -1,10 +1,7 @@
//// [tests/cases/conformance/es6/templates/templateStringMultiline3.ts] ////
//// [templateStringMultiline3.ts]
// newlines are <CR>
`
\
`
// newlines are <CR> ` \ `
//// [templateStringMultiline3.js]
// newlines are <CR>

View File

@ -2,6 +2,7 @@
=== templateStringMultiline3.ts ===
// newlines are <CR>
`
\

View File

@ -1,10 +1,12 @@
//// [tests/cases/conformance/es6/templates/templateStringMultiline3.ts] ////
=== templateStringMultiline3.ts ===
// newlines are <CR>
`
>`\` : "\n"
> : ^^^^
>` \ ` : "\n"
> : ^^^^
\
`

View File

@ -1,13 +1,6 @@
//// [tests/cases/conformance/es6/templates/templateStringMultiline3_ES6.ts] ////
//// [templateStringMultiline3_ES6.ts]
// newlines are <CR>
`
\
`
//// [templateStringMultiline3_ES6.js]
// newlines are <CR>
`
\
`;

View File

@ -2,7 +2,3 @@
=== templateStringMultiline3_ES6.ts ===
// newlines are <CR>
`
\
`

View File

@ -1,10 +1,4 @@
//// [tests/cases/conformance/es6/templates/templateStringMultiline3_ES6.ts] ////
=== templateStringMultiline3_ES6.ts ===
// newlines are <CR>
`
>`\` : "\n"
> : ^^^^
\
`