Skip to content

Commit e4e9fe7

Browse files
committed
Fix bad JSON syntax in tests, use JSON.parse first for perf (#61901)
1 parent d4a3126 commit e4e9fe7

File tree

57 files changed

+169
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+169
-119
lines changed

src/compiler/utilities.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7692,9 +7692,18 @@ export function base64decode(host: { base64decode?(input: string): string; } | u
76927692
export function readJsonOrUndefined(path: string, hostOrText: { readFile(fileName: string): string | undefined; } | string): object | undefined {
76937693
const jsonText = isString(hostOrText) ? hostOrText : hostOrText.readFile(path);
76947694
if (!jsonText) return undefined;
7695-
// gracefully handle if readFile fails or returns not JSON
7696-
const result = parseConfigFileTextToJson(path, jsonText);
7697-
return !result.error ? result.config : undefined;
7695+
// Try strictly parsing first, then fall back to our (slower)
7696+
// parser that is resilient to comments/trailing commas.
7697+
// package.json files should never have these, but we
7698+
// have no way to communicate these issues in the first place.
7699+
let result = tryParseJson(jsonText);
7700+
if (result === undefined) {
7701+
const looseResult = parseConfigFileTextToJson(path, jsonText);
7702+
if (!looseResult.error) {
7703+
result = looseResult.config;
7704+
}
7705+
}
7706+
return result;
76987707
}
76997708

77007709
/** @internal */

tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=node16).errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolut
1010
".": {
1111
"import": "./dist/index.mjs",
1212
"require": "./dist/index.js",
13-
"types": "./dist/index.d.ts",
13+
"types": "./dist/index.d.ts"
1414
}
1515
}
1616
}
@@ -26,4 +26,5 @@ error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolut
2626
// Should be an untyped resolution to dep/dist/index.mjs,
2727
// but the first search is only for TS files, and when
2828
// there's no dist/index.d.mts, it continues looking for
29-
// matching conditions and resolves via `types`.
29+
// matching conditions and resolves via `types`.
30+

tests/baselines/reference/conditionalExportsResolutionFallback(moduleresolution=nodenext).errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResol
1010
".": {
1111
"import": "./dist/index.mjs",
1212
"require": "./dist/index.js",
13-
"types": "./dist/index.d.ts",
13+
"types": "./dist/index.d.ts"
1414
}
1515
}
1616
}
@@ -26,4 +26,5 @@ error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResol
2626
// Should be an untyped resolution to dep/dist/index.mjs,
2727
// but the first search is only for TS files, and when
2828
// there's no dist/index.d.mts, it continues looking for
29-
// matching conditions and resolves via `types`.
29+
// matching conditions and resolves via `types`.
30+

tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node16).errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
126126
"./types": {
127127
"types": {
128128
"import": "./index.d.mts",
129-
"require": "./index.d.cts",
129+
"require": "./index.d.cts"
130130
},
131131
"node": {
132132
"import": "./index.mjs",
133133
"require": "./index.cjs"
134134
}
135135
}
136136
}
137-
}
137+
}
138+

tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node16).js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,16 @@ export const cjsSource = true;
112112
"./types": {
113113
"types": {
114114
"import": "./index.d.mts",
115-
"require": "./index.d.cts",
115+
"require": "./index.d.cts"
116116
},
117117
"node": {
118118
"import": "./index.mjs",
119119
"require": "./index.cjs"
120120
}
121121
}
122122
}
123-
}
123+
}
124+
124125

125126
//// [index.mjs]
126127
// esm format file

tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node18).errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,13 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
126126
"./types": {
127127
"types": {
128128
"import": "./index.d.mts",
129-
"require": "./index.d.cts",
129+
"require": "./index.d.cts"
130130
},
131131
"node": {
132132
"import": "./index.mjs",
133133
"require": "./index.cjs"
134134
}
135135
}
136136
}
137-
}
137+
}
138+

tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=node18).js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,16 @@ export const cjsSource = true;
112112
"./types": {
113113
"types": {
114114
"import": "./index.d.mts",
115-
"require": "./index.d.cts",
115+
"require": "./index.d.cts"
116116
},
117117
"node": {
118118
"import": "./index.mjs",
119119
"require": "./index.cjs"
120120
}
121121
}
122122
}
123-
}
123+
}
124+
124125

125126
//// [index.mjs]
126127
// esm format file

tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,13 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
120120
"./types": {
121121
"types": {
122122
"import": "./index.d.mts",
123-
"require": "./index.d.cts",
123+
"require": "./index.d.cts"
124124
},
125125
"node": {
126126
"import": "./index.mjs",
127127
"require": "./index.cjs"
128128
}
129129
}
130130
}
131-
}
131+
}
132+

tests/baselines/reference/nodeModulesAllowJsConditionalPackageExports(module=nodenext).js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,16 @@ export const cjsSource = true;
112112
"./types": {
113113
"types": {
114114
"import": "./index.d.mts",
115-
"require": "./index.d.cts",
115+
"require": "./index.d.cts"
116116
},
117117
"node": {
118118
"import": "./index.mjs",
119119
"require": "./index.cjs"
120120
}
121121
}
122122
}
123-
}
123+
}
124+
124125

125126
//// [index.mjs]
126127
// esm format file

tests/baselines/reference/nodeModulesAllowJsPackagePatternExports(module=node16).errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ
6464
{
6565
"name": "package",
6666
"private": true,
67-
"type": "module",
67+
"type": "module"
6868
}
6969
==== node_modules/inner/package.json (0 errors) ====
7070
{
@@ -75,4 +75,5 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ
7575
"./mjs/*": "./*.mjs",
7676
"./js/*": "./*.js"
7777
}
78-
}
78+
}
79+

0 commit comments

Comments
 (0)