New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Leave trailing comments after handling a possible trailing comma #10445
Conversation
nicolo-ribaudo
commented
Sep 16, 2019
•
edited
edited
Q | A |
---|---|
Fixed Issues? | Fixes #10432, fixes #9102 |
Patch: Bug Fix? | |
Major: Breaking Change? | |
Minor: New Feature? | |
Tests Added + Pass? | Yes |
Documentation PR Link | |
Any Dependency Changes? | |
License | MIT |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11584/ |
} else { | ||
if (node.trailingComments === undefined) { | ||
node.trailingComments = []; | ||
} | ||
node.trailingComments.push(leadingComment); | ||
} | ||
} | ||
if (takeAllComments) this.state.leadingComments.length = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this.state.leadingComments = []
is more idiomatic and should be marginally faster than this.state.leadingComments.length = 0
by saving calls to StoreICTrampoline
.
The former is compiled to
-- </Users/jh/code/babel/packages/babel-parser/lib/index.js:6266:14> --
0x1fafdfb87845 545 48b8a92cd4eaa8090000 REX.W movq rax,0x9a8ead42ca9 ;; object: 0x09a8ead42ca9 <Map(PACKED_ELEMENTS)>
0x1fafdfb8784f 54f 498947ff REX.W movq [r15-0x1],rax
0x1fafdfb87853 553 498b9da0000000 REX.W movq rbx,[r13+0xa0] (root (empty_fixed_array))
0x1fafdfb8785a 55a 49895f07 REX.W movq [r15+0x7],rbx
0x1fafdfb8785e 55e 49895f0f REX.W movq [r15+0xf],rbx
0x1fafdfb87862 562 49c7471700000000 REX.W movq [r15+0x17],0x0
-- </Users/jh/code/babel/packages/babel-parser/lib/index.js:6266:37> --
0x1fafdfb8786a 56a 4d89b9cf000000 REX.W movq [r9+0xcf],r15
0x1fafdfb87871 571 48c7c30000fcff REX.W movq rbx,0xfffc0000
0x1fafdfb87878 578 4923d9 REX.W andq rbx,r9
0x1fafdfb8787b 57b f6430804 testb [rbx+0x8],0x4
The latter is compiled to
-- </Users/jh/code/babel/packages/babel-parser/lib/index.js:6268:44> --
0x1fafde852e4e 44e 33c0 xorl rax,rax
0x1fafde852e50 450 498b8d280a0000 REX.W movq rcx,[r13+0xa28] (root (length_string))
0x1fafde852e57 457 48bf000000002b000000 REX.W movq rdi,0x2b00000000
0x1fafde852e61 461 488b75e0 REX.W movq rsi,[rbp-0x20]
-- Inlined Trampoline to StoreICTrampoline --
0x1fafde852e65 465 49ba40fb6c0001000000 REX.W movq r10,0x1006cfb40 (StoreICTrampoline)
0x1fafde852e6f 46f 41ffd2 call r10
0x1fafdfb877aa 4aa 4c8b4518 REX.W movq r8,[rbp+0x18]
0x1fafdfb877ae 4ae 48b8a92cd4eaa8090000 REX.W movq rax,0x9a8ead42ca9 ;; object: 0x09a8ead42ca9 <Map(PACKED_ELEMENTS)>
0x1fafdfb877b8 4b8 49bce990a15ea8090000 REX.W movq r12,0x9a85ea190e9 ;; object: 0x09a85ea190e9 <Map(HOLEY_ELEMENTS)>
0x1fafdfb877c2 4c2 49bbf994a15ea8090000 REX.W movq r11,0x9a85ea194f9 ;; object: 0x09a85ea194f9 <Map(HOLEY_ELEMENTS)>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I thought that resetting the length was faster because it doesn't create a new array. Will update 👍
@banga Could you please review this PR if you have time? 🙏 |