diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 89057dd2939a9..dec6b7cc48568 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -863,24 +863,6 @@ namespace ts { return result; } - /** - * Reduce the properties defined on a map-like (but not from its prototype chain). - * - * NOTE: This is intended for use with MapLike objects. For Map objects, use - * reduceProperties instead as it offers better performance. - * - * @param map The map-like to reduce - * @param callback An aggregation function that is called for each entry in the map - * @param initial The initial value for the reduction. - */ - export function reduceOwnProperties(map: MapLike, callback: (aggregate: U, value: T, key: string) => U, initial: U): U { - let result = initial; - for (const key in map) if (hasOwnProperty.call(map, key)) { - result = callback(result, map[key], String(key)); - } - return result; - } - /** * Performs a shallow equality comparison of the contents of two map-likes. * diff --git a/src/compiler/sourcemap.ts b/src/compiler/sourcemap.ts index 46db5188e339c..650b9b0ef02b2 100644 --- a/src/compiler/sourcemap.ts +++ b/src/compiler/sourcemap.ts @@ -427,7 +427,7 @@ namespace ts { encodeLastRecordedSourceMapSpan(); - return stringify({ + return JSON.stringify({ version: 3, file: sourceMapData.sourceMapFile, sourceRoot: sourceMapData.sourceMapSourceRoot, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ddfa85bc31170..3dd7054a40530 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3189,55 +3189,6 @@ namespace ts { return output; } - /** - * Serialize an object graph into a JSON string. This is intended only for use on an acyclic graph - * as the fallback implementation does not check for circular references by default. - */ - export const stringify: (value: any) => string = typeof JSON !== "undefined" && JSON.stringify - ? JSON.stringify - : stringifyFallback; - - /** - * Serialize an object graph into a JSON string. - */ - function stringifyFallback(value: any): string { - // JSON.stringify returns `undefined` here, instead of the string "undefined". - return value === undefined ? undefined : stringifyValue(value); - } - - function stringifyValue(value: any): string { - return typeof value === "string" ? `"${escapeString(value)}"` - : typeof value === "number" ? isFinite(value) ? String(value) : "null" - : typeof value === "boolean" ? value ? "true" : "false" - : typeof value === "object" && value ? isArray(value) ? cycleCheck(stringifyArray, value) : cycleCheck(stringifyObject, value) - : /*fallback*/ "null"; - } - - function cycleCheck(cb: (value: any) => string, value: any) { - Debug.assert(!value.hasOwnProperty("__cycle"), "Converting circular structure to JSON"); - value.__cycle = true; - const result = cb(value); - delete value.__cycle; - return result; - } - - function stringifyArray(value: any) { - return `[${reduceLeft(value, stringifyElement, "")}]`; - } - - function stringifyElement(memo: string, value: any) { - return (memo ? memo + "," : memo) + stringifyValue(value); - } - - function stringifyObject(value: any) { - return `{${reduceOwnProperties(value, stringifyProperty, "")}}`; - } - - function stringifyProperty(memo: string, value: any, key: string) { - return value === undefined || typeof value === "function" || key === "__cycle" ? memo - : (memo ? memo + "," : memo) + `"${escapeString(key)}":${stringifyValue(value)}`; - } - const base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; /**