Title: Appears to be a scope resolution bug · Issue #1386 · javascript-obfuscator/javascript-obfuscator · GitHub
Open Graph Title: Appears to be a scope resolution bug · Issue #1386 · javascript-obfuscator/javascript-obfuscator
X Title: Appears to be a scope resolution bug · Issue #1386 · javascript-obfuscator/javascript-obfuscator
Description: Expected Behavior The obfuscated output should preserve the original binding semantics. A semantically correct result would be equivalent to: import { i as _imp } from './runtime.js'; function factory() { return 'factory-result'; } var P...
Open Graph Description: Expected Behavior The obfuscated output should preserve the original binding semantics. A semantically correct result would be equivalent to: import { i as _imp } from './runtime.js'; function fact...
X Description: Expected Behavior The obfuscated output should preserve the original binding semantics. A semantically correct result would be equivalent to: import { i as _imp } from './runtime.js'; funct...
Opengraph URL: https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1386
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Appears to be a scope resolution bug","articleBody":"\u003c!-- Love javascript-obfuscator? Please consider supporting our collective:\n👉 https://opencollective.com/javascript-obfuscator/donate --\u003e\n\n\u003c!--- Provide a general summary of the issue in the Title above --\u003e\n\n## Expected Behavior\n\u003c!--- Tell us what should happen --\u003e\n\nThe obfuscated output should preserve the original binding semantics.\n\nA semantically correct result would be equivalent to:\n\n```js\nimport { i as _imp } from './runtime.js';\n\nfunction factory() {\n return 'factory-result';\n}\n\nvar P = class _cls {\n static instance;\n\n static getInstance() {\n return _cls.instance ||= new _cls(), _cls.instance;\n }\n};\n\nvar x = _imp(factory(), 1);\n\nexport { P, x };\n```\n\nor:\n\n```js\nimport { i as _imp } from './runtime.js';\n\nfunction factory() {\n return 'factory-result';\n}\n\nvar _P = class {\n static instance;\n\n static getInstance() {\n return _P.instance ||= new _P(), _P.instance;\n }\n};\n\nvar x = _imp(factory(), 1);\n\nexport { _P as P, x };\n```\n\n## Current Behavior\n\u003c!--- Tell us what happens instead of the expected behavior --\u003e\n\nThe obfuscated output rewrites the class self-reference to the imported binding.\n\nIt becomes effectively:\n\n```js\nimport { i as _0x48e620 } from './runtime.js';\n\nfunction factory() {\n return 'factory-result';\n}\n\nvar P = class e {\n static ['instance'];\n static ['getInstance']() {\n return _0x48e620['instance'] ||= new _0x48e620(), _0x48e620['instance'];\n }\n};\n\nvar x = _0x48e620(factory(), 0x1);\n\nexport { P, x };\n```\n\nThis is incorrect because `_0x48e620` is the imported binding, not the class.\n\nIf the imported binding is a function or arrow function, runtime execution fails with:\n\n```text\nTypeError: function is not a constructor\n```\n\n## Steps to Reproduce\n\u003c!--- Provide a link to a live example, or an unambiguous set of steps to --\u003e\n\u003c!--- reproduce this bug. Include code to reproduce, if relevant --\u003e\n1. Open https://obfuscator.io/legacy-playground\n2. Paste `runtime.js` and the main module code below into the editor\n3. Use the obfuscator options listed below\n4. Run obfuscation\n5. Inspect the generated `getInstance()` method\n6. Notice that the class self-reference is rewritten to the imported binding\n\n## JavaScript Obfuscator Edition\n- JavaScript Obfuscator Open Source\n- JavaScript Obfuscator Pro via API or [http://obfuscator.io](http://obfuscator.io])\n\n## Your Environment\n\u003c!--- Include as many relevant details about the environment you experienced the bug in --\u003e\n- `javascript-obfuscator`: `4.2.2`\n - Also reproduced after testing newer versions, including `5.3.0`\n- Node.js: `20.x`\n- OS: macOS\n\n# Stack trace\n\u003c!--- Include stack trace --\u003e\n\n## Minimal working example that will help to reproduce issue\n\u003c!--- Include code --\u003e\n\n```js\n// runtime.js\nexport const i = (value, flag) =\u003e ({ value, flag });\n```\n\n```js\nimport { i as e } from './runtime.js';\n\nfunction factory() {\n return 'factory-result';\n}\n\nvar P = class e {\n static instance;\n\n static getInstance() {\n return e.instance ||= new e(), e.instance;\n }\n};\n\nvar x = e(factory(), 1);\n\nexport { P, x };\n```\n","author":{"url":"https://github.com/z0ffy","@type":"Person","name":"z0ffy"},"datePublished":"2026-03-19T16:47:11.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1386/javascript-obfuscator/issues/1386"}
| 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:4ce749db-c3ae-9514-79c5-bb960bec30c3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A4AA:17D6AA:27D78AC:28D3217:6A62F628 |
| html-safe-nonce | 6b3799514d7492952338c38c10c5d3208ba2ecd7b0ac025d3e906c820a1dbcbb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNEFBOjE3RDZBQToyN0Q3OEFDOjI4RDMyMTc6NkE2MkY2MjgiLCJ2aXNpdG9yX2lkIjoiNTM2MjgyOTAzNjY3ODczOTQ5NiIsInJlZ2lvbl9lZGdlIjoic2VhIiwicmVnaW9uX3JlbmRlciI6InNlYSJ9 |
| visitor-hmac | 61a0e7e9da5f56d524535b6c104616f3fc94d7b301c0799df8e0f6606f64da8f |
| hovercard-subject-tag | issue:4102923063 |
| 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/1386/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4f4d62ecf465caf1f38a294caaf9d23d81e0f89f417864671e515330fc6043cc/javascript-obfuscator/javascript-obfuscator/issues/1386 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4f4d62ecf465caf1f38a294caaf9d23d81e0f89f417864671e515330fc6043cc/javascript-obfuscator/javascript-obfuscator/issues/1386 |
| og:image:alt | Expected Behavior The obfuscated output should preserve the original binding semantics. A semantically correct result would be equivalent to: import { i as _imp } from './runtime.js'; function fact... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | z0ffy |
| hostname | github.com |
| expected-hostname | github.com |
| None | b415018e190e73858133ddcaa36acce7b3f3572fe54dda84bd3b21a6ec714c30 |
| 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 | 22f98521e99f504294ab0812b66104d50eb75a70 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width