Repository navigation
🐛 fix(js): refuse literal tokens as property names - #2275
Merged
Merged
Conversation
A property name was read from any token up to a template tail, so a string, number, template or regex token passed for a name. After `.`, `?.` and `new.` such a token is not a name, and as an object or class key a template or regex is not a key, so these forms were printed as written instead of being refused. A name now comes only from an identifier or a private name. Keys still take string, number and bigint literals and computed keys, and the end of input is refused like any other missing name. Fixes tox-dev#2270
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
minify_js()read a property name from any token that has text, so a string, number, template or regex token could stand for a name. Forms such asa."b",a.`t`,new."x",o={`t`:1}ando={/a/:1}are not valid JavaScript, and the minifier printed them as written. Fixes #2270.The name reader in
parser.c(leaf()) accepted every token up to the end of the template kinds. A name after.,?.ornew.must be an identifier name, and an object or class key takes a string, number or bigint literal throughparse_key(). The reader now accepts only an identifier or a private name, so every other token is refused before it is read.Inline scripts that contain one of these forms now stay unminified, as scripts with other invalid syntax do.
Behavior changes
minify_js()raisesValueErrorfor a string, template or regex token where a property name is required, and for the end of input in that position. Valid string, number, bigint and computed keys minify as before.