diff --git a/src/test/adapter.ts b/src/test/adapter.ts index 7d0decfe..1b506aac 100644 --- a/src/test/adapter.ts +++ b/src/test/adapter.ts @@ -849,7 +849,7 @@ describe('PHP Debug Adapter', () => { { context: 'clipboard', expression: '$anArray', - result: 'array (\n 0 => 1,\n test => 2,\n test2 => \n array (\n t => 123,\n ),\n)', + result: "array (\n 0 => 1,\n 'test' => 2,\n 'test2' => \n array (\n 't' => 123,\n ),\n)", hasVariablesReference: false, }, { context: 'clipboard', expression: '$aBoolean', result: 'true', hasVariablesReference: false }, diff --git a/src/varExport.ts b/src/varExport.ts index 2632ce2b..421037b7 100644 --- a/src/varExport.ts +++ b/src/varExport.ts @@ -22,14 +22,12 @@ export async function varExportProperty(property: xdebug.Property, indent: strin displayValue = ( await Promise.all( properties.map(async property => { + const name = /^-?[0-9]+$/.test(property.name) ? `${property.name}` : `'${property.name}'` const indent2 = indent + ' ' if (property.hasChildren) { - return `${indent2}${property.name} => \n${indent2}${await varExportProperty( - property, - indent2 - )},` + return `${indent2}${name} => \n${indent2}${await varExportProperty(property, indent2)},` } else { - return `${indent2}${property.name} => ${await varExportProperty(property, indent2)},` + return `${indent2}${name} => ${await varExportProperty(property, indent2)},` } }) )