Skip to content

Commit aaaf1e1

Browse files
committed
Improve bare-property detection
1 parent 715830d commit aaaf1e1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/jsonformatter.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ function jsString(s: string): string {
5858
}
5959

6060
/**
61-
* Is this a valid "bare" property name?
61+
* Is this a valid "bare" property name (e.g. a JS identifier name or a numeric
62+
* literal)? See https://mathiasbynens.be/notes/javascript-properties, though we
63+
* only support a subset of valid identifier names (no weird Unicode stuff).
6264
*/
6365
function isBareProp(prop: string): boolean {
64-
return /^[A-Za-z_$][A-Za-z0-9_\-$]*$/.test(prop);
66+
return /^([0-9]+|[A-Za-z_$][A-Za-z0-9_$]*)$/.test(prop);
6567
}
6668

6769
/**

0 commit comments

Comments
 (0)