Skip to content

Commit

Permalink
Add missing reserved words to check in dump/dumps.
Browse files Browse the repository at this point in the history
When deciding whether to encode a key as an identifier instead of
a string, the encoding logic checks against a list of reserved words
to avoid conflicts.

The existing code is based on the list in section 7.6.1 of
EcmaScript 5.1. However, it turns out that I was missing some of
the future reserved words:

- implements
- interface
- let
- package
- private
- protected
- public
- static
- yield.

This CL adds them to the list. This fixes GitHub #87. Note that
this will introduce some backwards incompatibility (because now those
words will be quoted when encoded), but I think that's probably
better to do than to leave the bug open.

If this causes problems, we can revert this list and either add an option
to check for them or just wait until we can do a non-backwards-compatible
release.
  • Loading branch information
dpranke committed Nov 26, 2024
1 parent 0090020 commit d103b62
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions json5/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,20 @@ def is_reserved_word(self, key: str) -> bool:
'for',
'function',
'if',
'implements',
'import',
'in',
'instanceof',
'interface',
'let',
'new',
'null',
'package',
'private',
'protected',
'public',
'return',
'static',
'super',
'switch',
'this',
Expand All @@ -835,6 +843,7 @@ def is_reserved_word(self, key: str) -> bool:
'void',
'while',
'with',
'yield',
]
)
+ ')$'
Expand Down

0 comments on commit d103b62

Please sign in to comment.