mirror of https://github.com/tc39/test262.git
Improve printing of property key names in observer helpers
These should be formatted in the same way that they'd be entered in source code.
This commit is contained in:
parent
dd47e4e248
commit
63e0986803
|
@ -7,6 +7,8 @@ defines: [TemporalHelpers]
|
|||
features: [Symbol.species, Symbol.iterator, Temporal]
|
||||
---*/
|
||||
|
||||
const IDENTIFIER = /^[$_\p{ID_Start}][$\u200C\u200D\p{ID_Continue}]*$/u;
|
||||
|
||||
function formatPropertyName(propertyKey, objectName = "") {
|
||||
switch (typeof propertyKey) {
|
||||
case "symbol":
|
||||
|
@ -17,13 +19,20 @@ function formatPropertyName(propertyKey, objectName = "") {
|
|||
} else {
|
||||
return `${objectName}[Symbol('${propertyKey.description}')]`
|
||||
}
|
||||
case "number":
|
||||
return `${objectName}[${propertyKey}]`;
|
||||
case "string":
|
||||
if (propertyKey !== String(Number(propertyKey))) {
|
||||
if (IDENTIFIER.test(propertyKey)) {
|
||||
return objectName ? `${objectName}.${propertyKey}` : propertyKey;
|
||||
}
|
||||
return `${objectName}['${propertyKey.replace(/'/g, "\\'")}']`
|
||||
}
|
||||
// fall through
|
||||
default:
|
||||
// TODO: check if propertyKey is an integer index.
|
||||
return objectName ? `${objectName}.${propertyKey}` : propertyKey;
|
||||
// integer or string integer-index
|
||||
return `${objectName}[${propertyKey}]`;
|
||||
}
|
||||
}
|
||||
|
||||
const SKIP_SYMBOL = Symbol("Skip");
|
||||
|
||||
var TemporalHelpers = {
|
||||
|
|
|
@ -25,7 +25,7 @@ asyncTest(async function () {
|
|||
"get items.length",
|
||||
"get items.length.valueOf",
|
||||
"call items.length.valueOf",
|
||||
"get items.0",
|
||||
"get items.1",
|
||||
"get items[0]",
|
||||
"get items[1]",
|
||||
]);
|
||||
});
|
||||
|
|
|
@ -21,8 +21,8 @@ const expected = [
|
|||
"get fields.extra",
|
||||
// CopyDataProperties on additionalFields
|
||||
"ownKeys additionalFields",
|
||||
"getOwnPropertyDescriptor additionalFields.3",
|
||||
"get additionalFields.3",
|
||||
"getOwnPropertyDescriptor additionalFields[3]",
|
||||
"get additionalFields[3]",
|
||||
"getOwnPropertyDescriptor additionalFields.monthCode",
|
||||
"get additionalFields.monthCode",
|
||||
"getOwnPropertyDescriptor additionalFields[Symbol('extra')]",
|
||||
|
|
Loading…
Reference in New Issue