diff options
author | Aaron Power <theaaronepower@gmail.com> | 2018-08-27 16:46:00 +0100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-08-27 13:45:29 -0400 |
commit | 0f1db89aa664fe05efae2136d7456465403df30f (patch) | |
tree | b545c169b97d1d0e456394fbb988b90d785be197 /js/console.ts | |
parent | 224cfc8c74133a6b4fe6c9e96a90925ebaf066aa (diff) |
Fixed printing strings in arrays & objects without quotes
Diffstat (limited to 'js/console.ts')
-rw-r--r-- | js/console.ts | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/js/console.ts b/js/console.ts index 2eb5e27c0..c49a7621d 100644 --- a/js/console.ts +++ b/js/console.ts @@ -13,7 +13,7 @@ function getClassInstanceName(instance: any): string { } // tslint:disable-next-line:no-any -function stringify(ctx: ConsoleContext, value: any): string { +export function stringify(ctx: ConsoleContext, value: any): string { switch (typeof value) { case "string": return value; @@ -42,7 +42,7 @@ function stringify(ctx: ConsoleContext, value: any): string { if (Array.isArray(value)) { for (const el of value) { - entries.push(stringify(ctx, el)); + entries.push(stringifyWithQuotes(ctx, el)); } ctx.delete(value); @@ -61,7 +61,7 @@ function stringify(ctx: ConsoleContext, value: any): string { } for (const key of Object.keys(value)) { - entries.push(`${key}: ${stringify(ctx, value[key])}`); + entries.push(`${key}: ${stringifyWithQuotes(ctx, value[key])}`); } ctx.delete(value); @@ -83,6 +83,17 @@ function stringify(ctx: ConsoleContext, value: any): string { } } +// Print strings when they are inside of arrays or objects with quotes +// tslint:disable-next-line:no-any +function stringifyWithQuotes(ctx: ConsoleContext, value: any): string { + switch (typeof value) { + case "string": + return `"${value}"`; + default: + return stringify(ctx, value); + } +} + // tslint:disable-next-line:no-any function stringifyArgs(args: any[]): string { const out: string[] = []; |