Skip to content

Let --js code declare the names of the numbers and groups with let and const to close #815 - #831

Merged
mathiasrw merged 14 commits into
mainfrom
fix/815
Oct 23, 2026
Merged

mathiasrw merged 14 commits into
mainfrom
fix/815

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #815

Stacked on #830.

Change

The numbers of #791, the groups and the named groups of #799 are made with var in front of the --js code. Code that declared one of those names itself with let or const did not run:

> echo -n foo | rexreplace o 'let $t = "T"; $t' --js
 ❌ The code of --js failed for the piped data: SyntaxError: Cannot declare a let variable twice: '$t'.

Now the code of the user is put in a block of its own, so its let and const are in their own scope, and it gives fTT again. The value of a block is the value of its last statement, so the code works as before. A line break goes before the end of the block, so a // comment at the end of the code does not hide it.

Tests

test/fix/815.test.js is new, and its tests with let and const fail without the fix. yarn test-ci passes.

From the review of 23 October.

Follow-up

test/fix/815.test.js also covers a cousin with const ($n00), a function named like a number, and that var $t still works. The var and comment tests pass without the fix too, as guards.

@mathiasrw
mathiasrw added this pull request to stack #841 October 23, 2026 13:56
@mathiasrw
mathiasrw marked this pull request as draft October 23, 2026 15:38
@mathiasrw
mathiasrw marked this pull request as ready for review October 23, 2026 15:42
@mathiasrw
mathiasrw removed this pull request from stack #841 October 23, 2026 15:57
@mathiasrw
mathiasrw added this pull request to stack #849 October 23, 2026 16:12
@mathiasrw
mathiasrw removed this pull request from stack #849 October 23, 2026 16:12
@mathiasrw
mathiasrw added this pull request to stack #850 October 23, 2026 16:17
Base automatically changed from fix/814 to main October 23, 2026 16:41
@mathiasrw
mathiasrw removed this pull request from stack #850 October 23, 2026 16:47
@mathiasrw
mathiasrw added this pull request to stack #853 October 23, 2026 16:51
@mathiasrw
mathiasrw merged commit 5f12454 into main Oct 23, 2026
7 checks passed
@mathiasrw
mathiasrw deleted the fix/815 branch October 23, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix --js code that declares $t or _name with let or const

1 participant