Skip to content

🐛 fix(js): refuse literal tokens as property names - #2275

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/js-member-name-literal
Nov 16, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/js-member-name-literal

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

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 as a."b", a.`t`, new."x", o={`t`:1} and o={/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 ., ?. or new. must be an identifier name, and an object or class key takes a string, number or bigint literal through parse_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() raises ValueError for 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.

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
@gaborbernat
gaborbernat merged commit 1d5138a into tox-dev:main Nov 16, 2026
1 of 47 checks passed
@gaborbernat gaborbernat added the bug Something isn't working label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 fix(js): accept invalid literal tokens as property names

1 participant