-
Notifications
You must be signed in to change notification settings - Fork 902
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
Failed tokenizing multiline template strings #169
Comments
Will fix, thanks. Same thing that prevented me from adding template strings to loose parser yet. |
Great, thank you :) |
Well, I investigated if a bit and a problem is that template literal tokens require external state on consumer (i.e. parser) side and without this state (particularly
As far as I understood from discussion in Bugzilla, you need tokenizer just for beautifying code, so this should work for your case pretty well. |
I am not so sure is acorn used only for beautifying, I just commented on bugzilla to have double confirm. |
Yeah, I'm tracking and replying in that issue as well :) |
So could you please tell if such solution would be sufficient for you? |
It wouldn't do for the loose parser, though. Would it be possible to have the tokenizer independently track 'embed depth' (by making |
@RReverser Is it okay if I start hacking at the code for a bit now, or are you looking into this at the moment? (Don't want to duplicate work.) |
This appears to be fixed by attached patch. Note that this changes the token structure, so if you wrote code against the old token style, which it sounds like you did, you'll have to update it -- there are now (I decided to break compatibility with the old tokens without any safety nets, since the old tokens had only existed in a situation where template tokenizing was too broken to use anyway.) |
Just got home. @marijnh Interesting solution, thanks for fixing it! The only thing I don't like is changes to TemplateElement locations which breaks both compatibility and expectations by including quotes in the cases when TemplateElement is on the one or another side of template string. Also I have a question - how will this work with loose parser (or other tokenizer consumer) in cases when it will call |
We include quotes in the location data for strings. I don't see a reason not to do so for template elements. As for |
Because TemplateElement is not TemplateLiteral itself, it's just part of it, so it's different case than with strings. For example, template literal: (ugh, those backquotes - can't inline with Markdown) `My name is ${name} and I am ${title}.` contains three template elements (== static parts):
and with current implementation we have quotes included into range of
|
Regarding template literals in loose parser - I saw that it works, was just wondering about error-recovery cases when |
That's a reasonable point I guess. It's somewhat awkward to do, now that the start of the TemplateElement is no longer a token boundary, but I've implemented it in the attached patch. |
Yeah, that's why initially I treated back quote as separate token (so boundaries of template element token and node matched). Thanks for fixing it! |
Here's the code for reproducing the issue:
Running the script got this:
SyntaxError: Unexpected character '@' (2:4)
at raise (/home/ting/w/fx/os/node_modules/acorn/acorn.js:329:15)
at readToken (/home/ting/w/fx/os/node_modules/acorn/acorn.js:912:7)
at getToken (/home/ting/w/fx/os/node_modules/acorn/acorn.js:222:7)
at Object. (/home/ting/w/fx/os/bug-1102799.js:13:11)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
The text was updated successfully, but these errors were encountered: