Skip to content

Commit 2166364

Browse files
author
Andy
authored
Merge pull request #12721 from Microsoft/stringify_shim
Remove JSON.stringify shim
2 parents 91f0194 + 85545d9 commit 2166364

File tree

3 files changed

+1
-68
lines changed

3 files changed

+1
-68
lines changed

src/compiler/core.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -863,24 +863,6 @@ namespace ts {
863863
return result;
864864
}
865865

866-
/**
867-
* Reduce the properties defined on a map-like (but not from its prototype chain).
868-
*
869-
* NOTE: This is intended for use with MapLike<T> objects. For Map<T> objects, use
870-
* reduceProperties instead as it offers better performance.
871-
*
872-
* @param map The map-like to reduce
873-
* @param callback An aggregation function that is called for each entry in the map
874-
* @param initial The initial value for the reduction.
875-
*/
876-
export function reduceOwnProperties<T, U>(map: MapLike<T>, callback: (aggregate: U, value: T, key: string) => U, initial: U): U {
877-
let result = initial;
878-
for (const key in map) if (hasOwnProperty.call(map, key)) {
879-
result = callback(result, map[key], String(key));
880-
}
881-
return result;
882-
}
883-
884866
/**
885867
* Performs a shallow equality comparison of the contents of two map-likes.
886868
*

src/compiler/sourcemap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ namespace ts {
427427

428428
encodeLastRecordedSourceMapSpan();
429429

430-
return stringify({
430+
return JSON.stringify({
431431
version: 3,
432432
file: sourceMapData.sourceMapFile,
433433
sourceRoot: sourceMapData.sourceMapSourceRoot,

src/compiler/utilities.ts

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,55 +3189,6 @@ namespace ts {
31893189
return output;
31903190
}
31913191

3192-
/**
3193-
* Serialize an object graph into a JSON string. This is intended only for use on an acyclic graph
3194-
* as the fallback implementation does not check for circular references by default.
3195-
*/
3196-
export const stringify: (value: any) => string = typeof JSON !== "undefined" && JSON.stringify
3197-
? JSON.stringify
3198-
: stringifyFallback;
3199-
3200-
/**
3201-
* Serialize an object graph into a JSON string.
3202-
*/
3203-
function stringifyFallback(value: any): string {
3204-
// JSON.stringify returns `undefined` here, instead of the string "undefined".
3205-
return value === undefined ? undefined : stringifyValue(value);
3206-
}
3207-
3208-
function stringifyValue(value: any): string {
3209-
return typeof value === "string" ? `"${escapeString(value)}"`
3210-
: typeof value === "number" ? isFinite(value) ? String(value) : "null"
3211-
: typeof value === "boolean" ? value ? "true" : "false"
3212-
: typeof value === "object" && value ? isArray(value) ? cycleCheck(stringifyArray, value) : cycleCheck(stringifyObject, value)
3213-
: /*fallback*/ "null";
3214-
}
3215-
3216-
function cycleCheck(cb: (value: any) => string, value: any) {
3217-
Debug.assert(!value.hasOwnProperty("__cycle"), "Converting circular structure to JSON");
3218-
value.__cycle = true;
3219-
const result = cb(value);
3220-
delete value.__cycle;
3221-
return result;
3222-
}
3223-
3224-
function stringifyArray(value: any) {
3225-
return `[${reduceLeft(value, stringifyElement, "")}]`;
3226-
}
3227-
3228-
function stringifyElement(memo: string, value: any) {
3229-
return (memo ? memo + "," : memo) + stringifyValue(value);
3230-
}
3231-
3232-
function stringifyObject(value: any) {
3233-
return `{${reduceOwnProperties(value, stringifyProperty, "")}}`;
3234-
}
3235-
3236-
function stringifyProperty(memo: string, value: any, key: string) {
3237-
return value === undefined || typeof value === "function" || key === "__cycle" ? memo
3238-
: (memo ? memo + "," : memo) + `"${escapeString(key)}":${stringifyValue(value)}`;
3239-
}
3240-
32413192
const base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
32423193

32433194
/**

0 commit comments

Comments
 (0)