Title: Generated code drops required parentheses around `in` inside a `for`-init arrow body → unparsable output ("Invalid left-hand side in for-loop") · Issue #1419 · javascript-obfuscator/javascript-obfuscator · GitHub
Open Graph Title: Generated code drops required parentheses around `in` inside a `for`-init arrow body → unparsable output ("Invalid left-hand side in for-loop") · Issue #1419 · javascript-obfuscator/javascript-obfuscator
X Title: Generated code drops required parentheses around `in` inside a `for`-init arrow body → unparsable output ("Invalid left-hand side in for-loop") · Issue #1419 · javascript-obfuscator/javascript-obfuscator
Description: Expected Behavior Obfuscating valid input should always produce syntactically valid output (or throw). Parentheses around an in expression inside a for statement's init are grammatically required (the "NoIn" restriction) and must be pres...
Open Graph Description: Expected Behavior Obfuscating valid input should always produce syntactically valid output (or throw). Parentheses around an in expression inside a for statement's init are grammatically required (...
X Description: Expected Behavior Obfuscating valid input should always produce syntactically valid output (or throw). Parentheses around an in expression inside a for statement's init are grammatically requir...
Opengraph URL: https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1419
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generated code drops required parentheses around `in` inside a `for`-init arrow body → unparsable output (\"Invalid left-hand side in for-loop\")","articleBody":"## Expected Behavior\n\nObfuscating valid input should always produce **syntactically valid** output (or throw). Parentheses around an `in` expression inside a `for` statement's init are grammatically required (the \"NoIn\" restriction) and must be preserved.\n\n## Current Behavior\n\nThe obfuscator silently emits **unparsable** JavaScript. It removes the parentheses around an `in` expression located in a `for` init, so the bare `in` is parsed as a `for-in` head and the code throws at parse time:\n\n- V8 / native: `SyntaxError: Invalid left-hand side in for-loop`\n- acorn: `Assigning to rvalue`\n\nNo exception is raised by `obfuscate()` — the invalid code is returned as-is, which can ship and break the application at load.\n\n## Steps to Reproduce\n\nInput (valid JS):\n\n```js\nfor(a=(t,e)=\u003e(t in e)?0:1;;){}\n```\n\n```js\nimport O from 'javascript-obfuscator'\nconst out = O.obfuscate(`for(a=(t,e)=\u003e(t in e)?0:1;;){}`, { compact: true }).getObfuscatedCode()\nconsole.log(out)\n// for(a=(_0x14502c,_0xcad55a)=\u003e_0x14502c in _0xcad55a?0x0:0x1;;){}\n// ^^^^^^^^^^^^^^^^^^^^^^^ parentheses around `(t in e)` dropped\nnew Function(out) // throws: Invalid left-hand side in for-loop\n```\n\nThe protective parentheses present in the input (`(t in e)`) are absent from the output.\n\n## Reproduces regardless of options\n\nSame broken output with **default options**, with `{ compact: true }` only, and even with `{ simplify: false }` — so this is in the code generator / parenthesization logic, not a specific transform:\n\n| Options | Result |\n|---|---|\n| `{}` (defaults) | ❌ Invalid left-hand side in for-loop |\n| `{ compact: true }` | ❌ |\n| `{ compact: true, simplify: false }` | ❌ |\n\n## Root cause\n\nInside a `for` statement's init, an unparenthesized `in` operator is interpreted as introducing a `for-in` loop (the ECMAScript \"NoIn\" grammar production). The input parenthesizes the `in` expression to opt out of that interpretation; the obfuscator's output omits those parentheses, so the parser consumes everything before `in` as the `for-in` binding target — which is not a valid assignment target — hence the parse error.\n\nFor comparison, the same `in` expression outside a `for` init (e.g. `var a = (b in c) ? 1 : 2;`) is correctly emitted without parentheses and stays valid — confirming the parentheses are only required in the `for`-init \"NoIn\" context, which the generator does not account for.\n\n## Real-world impact\n\nHit in a production bundle: obfuscating an app bundle that includes `@sentry`/`rrweb` code (a base64 char-code table built via `for (h = (e,t,n) =\u003e (t in e) ? define(e,t,…) : e[t]=n, i=0; i\u003cs.length; i++) …`) produced an unparsable bundle. On a single-file (inlined) native bundle this bricks the app at load — the JS never parses. Minimal reduction of that bundle yields the one-line repro above.\n\n## Your Environment\n\n- `javascript-obfuscator`: **5.4.3** (latest)\n- Node.js: 22.x\n- OS: Linux\n\n## Related\n\n- #328, #361 — destructuring assignment without declaration `({a} = obj)` (closed 2020). Same family (assignment-target handling) but those were *runtime-incorrect* output; this one is *parse-invalid* output, specific to the `for`-init NoIn context.","author":{"url":"https://github.com/VolatilCapital","@type":"Person","name":"VolatilCapital"},"datePublished":"2026-06-17T13:40:01.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1419/javascript-obfuscator/issues/1419"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2cdd8bb7-773e-612d-6a29-82de9caf3d63 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BACA:1E9DA0:70C5D5:98E280:6A62DED2 |
| html-safe-nonce | 2abcf4e3c5f57e35c76b7904ad69f8bb999f64493c44ac6eac3682b5879c3def |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQUNBOjFFOURBMDo3MEM1RDU6OThFMjgwOjZBNjJERUQyIiwidmlzaXRvcl9pZCI6IjU4NzY3NTgwNzE2Mjk1MDQyMTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 6934c129c79d4a70bc26e36588e3001c7053f49f31744ef6adddd1e393ae2fe4 |
| hovercard-subject-tag | issue:4683807404 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/javascript-obfuscator/javascript-obfuscator/1419/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d9028451b856aebeb991924dcd891e9b90de2d7409189d5d7a3396d75d080ff4/javascript-obfuscator/javascript-obfuscator/issues/1419 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d9028451b856aebeb991924dcd891e9b90de2d7409189d5d7a3396d75d080ff4/javascript-obfuscator/javascript-obfuscator/issues/1419 |
| og:image:alt | Expected Behavior Obfuscating valid input should always produce syntactically valid output (or throw). Parentheses around an in expression inside a for statement's init are grammatically required (... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | VolatilCapital |
| hostname | github.com |
| expected-hostname | github.com |
| None | df33b1b61ee7b9a0af988199bfc3503c9c1acafb1f1d40e1f140ea7c84f890dd |
| turbo-cache-control | no-preview |
| go-import | github.com/javascript-obfuscator/javascript-obfuscator git https://github.com/javascript-obfuscator/javascript-obfuscator.git |
| octolytics-dimension-user_id | 23015672 |
| octolytics-dimension-user_login | javascript-obfuscator |
| octolytics-dimension-repository_id | 58360147 |
| octolytics-dimension-repository_nwo | javascript-obfuscator/javascript-obfuscator |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 58360147 |
| octolytics-dimension-repository_network_root_nwo | javascript-obfuscator/javascript-obfuscator |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d41cd1bdb290013455c0ac430fa755621733f5eb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width