Title: Wrong interpretation of `{ a: 1 }['a']` in the REPL (BlockStatement v.s. ExpressionStatement) · Issue #45964 · nodejs/node · GitHub
Open Graph Title: Wrong interpretation of `{ a: 1 }['a']` in the REPL (BlockStatement v.s. ExpressionStatement) · Issue #45964 · nodejs/node
X Title: Wrong interpretation of `{ a: 1 }['a']` in the REPL (BlockStatement v.s. ExpressionStatement) · Issue #45964 · nodejs/node
Description: Version v19.2.0 Platform No response Subsystem No response What steps will reproduce the bug? Evaluate { a: 1 }['a'] in the REPL $ node > { a: 1 }['a'] How often does it reproduce? Is there a required condition? Always What is the expect...
Open Graph Description: Version v19.2.0 Platform No response Subsystem No response What steps will reproduce the bug? Evaluate { a: 1 }['a'] in the REPL $ node > { a: 1 }['a'] How often does it reproduce? Is there a requi...
X Description: Version v19.2.0 Platform No response Subsystem No response What steps will reproduce the bug? Evaluate { a: 1 }['a'] in the REPL $ node > { a: 1 }['a'] How often does it reproduc...
Opengraph URL: https://github.com/nodejs/node/issues/45964
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Wrong interpretation of `{ a: 1 }['a']` in the REPL (BlockStatement v.s. ExpressionStatement)","articleBody":"### Version\r\n\r\nv19.2.0\r\n\r\n### Platform\r\n\r\n_No response_\r\n\r\n### Subsystem\r\n\r\n_No response_\r\n\r\n### What steps will reproduce the bug?\r\n\r\nEvaluate `{ a: 1 }['a']` in the REPL\r\n\r\n```sh\r\n$ node\r\n\u003e { a: 1 }['a']\r\n```\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nAlways\r\n\r\n### What is the expected behavior?\r\n\r\n```sh\r\n$ node -p \"{ a: 1 }['a']\"\r\n[ 'a' ]\r\n$ node\r\n\u003e { a: 1 }['a']\r\n[ 'a' ]\r\n```\r\n\r\n### What do you see instead?\r\n\r\n```sh\r\n$ node -p \"{ a: 1 }['a']\"\r\n[ 'a' ]\r\n$ node\r\n\u003e { a: 1 }['a']\r\n1\r\n```\r\n\r\n### Additional information\r\n\r\nThe REPL tries to wrap the code that starts with `{` in parentheses eagerly ('eager wrapping' was introduced at https://github.com/nodejs/node/pull/31943) and `{ a: 1 }['a']` is converted into an ExpressionStatement `({ a: 1 }['a'])` that is evaluated to `1`. However, technically speaking, `{ a: 1 }['a']` should be parsed as the combination of a BlockStatement `{a:1}` and an ExpressionStatement `['a']`, yielding a result of `['a']`.\r\n\r\nThe results of `{ a: 1 }['a']` in other runtimes:\r\n- ChromeDevTools: `['a']`\r\n- Safari WebInspector: `['a']`\r\n- Deno REPL: `1`","author":{"url":"https://github.com/cola119","@type":"Person","name":"cola119"},"datePublished":"2022-12-24T15:21:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/45964/node/issues/45964"}
| 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:e73a166d-f02b-923e-017b-8aa728477f21 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C52A:1CCE98:98890F:D80AAA:6A4D1C5A |
| html-safe-nonce | b3f99af60804aa13df1a899515d423610e9c462ef04a4ed7808966879ec01757 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNTJBOjFDQ0U5ODo5ODg5MEY6RDgwQUFBOjZBNEQxQzVBIiwidmlzaXRvcl9pZCI6IjY4MzU2MzMxMTI3MTU0MzUwOTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 193d47b8e5ac03c6210168db0e5183666396a2e57ffe29bd2abdc7fabdefbbbd |
| hovercard-subject-tag | issue:1510124395 |
| 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/nodejs/node/45964/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc4b54ca751529e888202d1670a1b2e2e6801bfc43750f57c3f0c13cfdc601a5/nodejs/node/issues/45964 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc4b54ca751529e888202d1670a1b2e2e6801bfc43750f57c3f0c13cfdc601a5/nodejs/node/issues/45964 |
| og:image:alt | Version v19.2.0 Platform No response Subsystem No response What steps will reproduce the bug? Evaluate { a: 1 }['a'] in the REPL $ node > { a: 1 }['a'] How often does it reproduce? Is there a requi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cola119 |
| hostname | github.com |
| expected-hostname | github.com |
| None | bcb4661e6fb4fe8b394c51ea02ccdb2236d40dc59afc75a3bbba50bf6517134c |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| 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 | fb70bd3c4b2bec429781b65419e912c66e2d5581 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width