Closed Bug 1102799 Opened 10 years ago Closed 10 years ago

WebIDE failed prettify JS with backtick enclosed multi-line strings

Categories

(DevTools :: Debugger, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 965141

People

(Reporter: ting, Unassigned)

References

()

Details

STR: 1. Plug in your device, I'm using Flame 2. cd gaia; DEVICE_DEBUG=1 make production 3. Launch WebIDE from Firefox Nightly 4. Open app vertical Homescreen, and select the file "gaia_build_defer_index.js", you'll find the JS is not prettified and from Firefox Nightly thre's an exception: Stack: SourceActor.prototype._sendToPrettyPrintWorker/</onReply@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/script.js:2907:27 Line: 2907, column: 26 togglePrettyPrint threw an exception: Error: Unexpected character '`' (421:499) raise@resource://gre/modules/devtools/acorn/acorn.js:231:15 readToken@resource://gre/modules/devtools/acorn/acorn.js:738:7 getToken@resource://gre/modules/devtools/acorn/acorn.js:146:7 prettyFast@resource://gre/modules/devtools/pretty-fast.js:777:15 self.onmessage@resource://gre/modules/devtools/server/actors/pretty-print-worker.js:37:24 The backtick is from here: http://lxr.mozilla.org/gaia/source/shared/elements/gaia_grid/script.js#237
Probably we need an upgrade of acorn, it is now v0.9.1 but we have v0.4.1.
I believe this is not specific to WebIDE, as there is one pretty print path. Nick, do we need an upgrade, or how would we handle this?
Component: Developer Tools: WebIDE → Developer Tools: Debugger
Flags: needinfo?(nfitzgerald)
The pretty printer only supports ES5 due to acorn only supporting ES5.
Depends on: 938203
Flags: needinfo?(nfitzgerald)
Nick, as I already wrote in other topics, ES6 support landed to Acorn few months ago.
Flags: needinfo?(nfitzgerald)
Ok, well then someone can go ahead and update our checkout of acorn and update pretty-fast to pretty print ES6 forms. I'm happy to review these patches/PRs.
Flags: needinfo?(nfitzgerald)
I just tried v0.9.1 and set defaultOptions.ecmaVersion 6, but it does not resolve the issue. There comes another exception: togglePrettyPrint threw an exception: Error: Unexpected character '@' (422:4) raise@resource://gre/modules/devtools/acorn/acorn.js:329:15 readToken@resource://gre/modules/devtools/acorn/acorn.js:912:7 getToken@resource://gre/modules/devtools/acorn/acorn.js:222:7 prettyFast@resource://gre/modules/devtools/pretty-fast.js:777:15 self.onmessage@resource://gre/modules/devtools/server/actors/pretty-print-worker.js:37:24 Which '@' is in http://lxr.mozilla.org/gaia/source/shared/elements/gaia_grid/script.js#238.
Have no idea what is this "@import". Probably internal feature of Mozilla's fork of Acorn or smth.
Ah, it's inside backtick. Well, I just checked with latest acorn and it parses fine for me.
I just tested with the latest acorn (51bc64a5), but still failed the tokenizing. I created an issue with the code for reproducing: https://github.com/marijnh/acorn/issues/169.
cc alex because this is about WebIDE.
RReverser proposed a solution [1] that tokenizer to return token literals as regular string tokens, as acorn seems is used for beautifying code only. But I am not really sure is this true, can someone please double confirm? [1] https://github.com/marijnh/acorn/issues/169#issuecomment-65766258
BTW, running |$ npm test| after set default option ecmaVersion 6 has some failed test cases (acorn v0.9.1): Normal parser: 843 tests run in 57ms; 20 failures. Loose parser: 815 tests run in 63ms; 1 failures. Total: 1658 tests run in 120ms; 21 failures. According to toolkit/devtools/acorn/UPGRADING.md, seems this is not ok to upgrade.
You shouldn't expect it to pass tests with `ecmaScript: 6` by default as some tests are specifically designed to check that some instructions **shouldn't** work in ES5 and those tests just have no `ecmaScript` specified, so they fail with different defaults.
(In reply to Ting-Yu Chou [:ting] from comment #11) > acorn seems is used for beautifying code only. But > I am not really sure is this true, can someone please double confirm? We use it in two places primarily: 1) Our pretty printer, which uses just the tokenizer. 2) We also use Marijn's tern.js for autocomplete-y stuff in the scratchpad. I believe this makes use of acorn's loose parser, but I haven't read tern's code or really looked at how we use tern, yet.
Tern is currently ES5-only, and will ignore ES6 syntax. (This will hopefully change in the future -- I'm looking for someone to hire me to work on it, maybe you can get Moz to do that?)
(In reply to Marijn Haverbeke from comment #15) > Tern is currently ES5-only, and will ignore ES6 syntax. (This will hopefully > change in the future -- I'm looking for someone to hire me to work on it, > maybe you can get Moz to do that?) Needinfo'ing dcamp on this because this should probably be his call.
Flags: needinfo?(dcamp)
I also just noticed that we already have a bug for supporting ES6 syntax in our pretty printer. Marking this as a duplicate.
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → DUPLICATE
Flags: needinfo?(dcamp)
Blocks: 938203
No longer depends on: 938203
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.