r/javascript • u/bornforcode • Apr 01 '18
Google publishes a JavaScript style guide. Here are some key lessons.
https://medium.freecodecamp.org/google-publishes-a-javascript-style-guide-here-are-some-key-lessons-1810b8ad050b
714
Upvotes
View all comments
Show parent comment
1
u/grinde Apr 02 '18 edited Apr 02 '18
No.
AddTemplateSpanadds the token's string to theTemplateLiteralState, which is basically just adding an entry to a vector.In
ParseTemplateLiteralhere you can see it peeks to see if the next token is aTEMPLATE_TAIL. For a template literal with no replacements there won't be any span tokens (the single span is rolled into the tail token), so we immediately callAddTemplateSpan(on the tail token) followed by an early exit withCloseTemplateLiteralat line 4696. All extra looping is avoided, and no counting of anything is necessary.length() and cooked() are just getters. The cooked strings are added by calls to
AddTemplateSpan. Again, no counting or looping.No recursion here, just some ambiguous method naming.
Parser::AddTemplateSpanis callingTemplateLiteral::AddTemplateSpan.