Skip to content

Fix bad JSON syntax in tests, use JSON.parse first for perf #61901

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7715,9 +7715,18 @@ export function base64decode(host: { base64decode?(input: string): string; } | u
export function readJsonOrUndefined(path: string, hostOrText: { readFile(fileName: string): string | undefined; } | string): object | undefined {
const jsonText = isString(hostOrText) ? hostOrText : hostOrText.readFile(path);
if (!jsonText) return undefined;
// gracefully handle if readFile fails or returns not JSON
const result = parseConfigFileTextToJson(path, jsonText);
return !result.error ? result.config : undefined;
// Try strictly parsing first, then fall back to our (slower)
// parser that is resilient to comments/trailing commas.
// package.json files should never have these, but we
// have no way to communicate these issues in the first place.
let result = tryParseJson(jsonText);
if (result === undefined) {
const looseResult = parseConfigFileTextToJson(path, jsonText);
if (!looseResult.error) {
result = looseResult.config;
}
}
return result;
}

/** @internal */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolut
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts",
"types": "./dist/index.d.ts"
}
}
}
Expand All @@ -26,4 +26,5 @@ error TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolut
// Should be an untyped resolution to dep/dist/index.mjs,
// but the first search is only for TS files, and when
// there's no dist/index.d.mts, it continues looking for
// matching conditions and resolves via `types`.
// matching conditions and resolves via `types`.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResol
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts",
"types": "./dist/index.d.ts"
}
}
}
Expand All @@ -26,4 +26,5 @@ error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResol
// Should be an untyped resolution to dep/dist/index.mjs,
// but the first search is only for TS files, and when
// there's no dist/index.d.mts, it continues looking for
// matching conditions and resolves via `types`.
// matching conditions and resolves via `types`.

Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
"./types": {
"types": {
"import": "./index.d.mts",
"require": "./index.d.cts",
"require": "./index.d.cts"
},
"node": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ export const cjsSource = true;
"./types": {
"types": {
"import": "./index.d.mts",
"require": "./index.d.cts",
"require": "./index.d.cts"
},
"node": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
}
}
}


//// [index.mjs]
// esm format file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
"./types": {
"types": {
"import": "./index.d.mts",
"require": "./index.d.cts",
"require": "./index.d.cts"
},
"node": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ export const cjsSource = true;
"./types": {
"types": {
"import": "./index.d.mts",
"require": "./index.d.cts",
"require": "./index.d.cts"
},
"node": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
}
}
}


//// [index.mjs]
// esm format file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
"./types": {
"types": {
"import": "./index.d.mts",
"require": "./index.d.cts",
"require": "./index.d.cts"
},
"node": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ export const cjsSource = true;
"./types": {
"types": {
"import": "./index.d.mts",
"require": "./index.d.cts",
"require": "./index.d.cts"
},
"node": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
}
}
}


//// [index.mjs]
// esm format file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,13 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
"./types": {
"types": {
"import": "./index.d.mts",
"require": "./index.d.cts",
"require": "./index.d.cts"
},
"node": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ export const cjsSource = true;
"./types": {
"types": {
"import": "./index.d.mts",
"require": "./index.d.cts",
"require": "./index.d.cts"
},
"node": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
}
}
}


//// [index.mjs]
// esm format file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ
{
"name": "package",
"private": true,
"type": "module",
"type": "module"
}
==== node_modules/inner/package.json (0 errors) ====
{
Expand All @@ -75,4 +75,5 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ
"./mjs/*": "./*.mjs",
"./js/*": "./*.js"
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export { type };
{
"name": "package",
"private": true,
"type": "module",
"type": "module"
}
//// [package.json]
{
Expand All @@ -63,7 +63,8 @@ export { type };
"./mjs/*": "./*.mjs",
"./js/*": "./*.js"
}
}
}


//// [index.js]
// esm format file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ
{
"name": "package",
"private": true,
"type": "module",
"type": "module"
}
==== node_modules/inner/package.json (0 errors) ====
{
Expand All @@ -75,4 +75,5 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ
"./mjs/*": "./*.mjs",
"./js/*": "./*.js"
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export { type };
{
"name": "package",
"private": true,
"type": "module",
"type": "module"
}
//// [package.json]
{
Expand All @@ -63,7 +63,8 @@ export { type };
"./mjs/*": "./*.mjs",
"./js/*": "./*.js"
}
}
}


//// [index.js]
// esm format file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
{
"name": "package",
"private": true,
"type": "module",
"type": "module"
}
==== node_modules/inner/package.json (0 errors) ====
{
Expand All @@ -66,4 +66,5 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
"./mjs/*": "./*.mjs",
"./js/*": "./*.js"
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export { type };
{
"name": "package",
"private": true,
"type": "module",
"type": "module"
}
//// [package.json]
{
Expand All @@ -63,7 +63,8 @@ export { type };
"./mjs/*": "./*.mjs",
"./js/*": "./*.js"
}
}
}


//// [index.js]
// esm format file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
{
"name": "package",
"private": true,
"type": "module",
"type": "module"
}
==== node_modules/inner/package.json (0 errors) ====
{
Expand All @@ -66,4 +66,5 @@ node_modules/inner/index.d.ts(2,13): error TS2303: Circular definition of import
"./mjs/*": "./*.mjs",
"./js/*": "./*.js"
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export { type };
{
"name": "package",
"private": true,
"type": "module",
"type": "module"
}
//// [package.json]
{
Expand All @@ -63,7 +63,8 @@ export { type };
"./mjs/*": "./*.mjs",
"./js/*": "./*.js"
}
}
}


//// [index.js]
// esm format file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ
{
"name": "package",
"private": true,
"type": "module",
"type": "module"
}
==== node_modules/inner/package.json (0 errors) ====
{
Expand All @@ -75,4 +75,5 @@ node_modules/inner/index.d.ts(3,22): error TS1479: The current file is a CommonJ
"./mjs/*.mjs": "./*.mjs",
"./js/*.js": "./*.js"
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export { type };
{
"name": "package",
"private": true,
"type": "module",
"type": "module"
}
//// [package.json]
{
Expand All @@ -63,7 +63,8 @@ export { type };
"./mjs/*.mjs": "./*.mjs",
"./js/*.js": "./*.js"
}
}
}


//// [index.js]
// esm format file
Expand Down
Loading