Skip to content

Commit

Permalink
Improve bare-property detection
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Jun 16, 2024
1 parent 715830d commit aaaf1e1
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/jsonformatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ function jsString(s: string): string {
}

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

/**
Expand Down

0 comments on commit aaaf1e1

Please sign in to comment.