Skip to content
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

Quote the error-causing text in parse errors #793

Closed
wants to merge 1 commit into from

Conversation

kripken
Copy link

@kripken kripken commented Jan 30, 2019

This makes parse errors look like this:

SyntaxError: Unexpected token (1433:40)
var ASM_CONSTS = [function() { var x = !<->5.; }];
                                         ^

That is, it adds a line that quotes the text with the error, and a line under it with ^ to point directly at the error.

kripken added a commit to emscripten-core/emscripten that referenced this pull request Feb 8, 2019
…#7973)

Fixes #6000

The key change here is to rewrite the JS optimizer passes that run in a normal `-O3` etc. build from the Uglify1 AST to ESTree. With ESTree we can use modern parsers etc. so that we support ES6+ inputs to js libraries, pre-jses, EM_ASM, etc.

Aside from that rewrite, the other changes are less critical and can be altered later. Specifically, this uses acorn for parsing and terser for outputting, but we could switch to anything using ESTree very easily. Acorn is nice for parsing since it's small and standalone. For outputting I experimented with astring, which is small and nice, and escodegen, which looks very robust, but neither could output compact-enough JS to not regress our JS code sizes. This is not truly critical since for minimal code size people should use closure anyhow, however, it's nice for default builds to be small (and we don't run closure by default), and I didn't want to regress anything. Using the terser outputter achieves that. (Since it uses the Uglify2 AST internally, this means using their tool to convert ESTree to Uglify2.) They may be some minor code size changes with this PR, just because we use a different outputter now, but nothing major in either direction. Most changes seem positive actually. Sizes after closure are unchanged.

This uses almost unmodified versions of acorn and terser, but they are stripped down to what we need, and I had to make two modifications, see these PRs: [acornjs/acorn#793](acornjs/acorn#793) (quote the error on parse exceptions) and [mishoo/UglifyJS#3323](mishoo/UglifyJS#3323) (preserve quoted properties).

This may very slightly regress compile times when using those passes, as Uglify1 was just very fast. However, the change should be very small.

This does _not_ rewrite every single JS optimizer pass. In particular the asm.js passes don't need to support ES6, and so don't need to be rewritten. There are also optional passes that do not run by default, that we can convert later depending on priority.
@RReverser
Copy link
Member

RReverser commented Feb 17, 2019

This seems like something that could be fairly easily done on top of Acorn? I imagine many people might have different preferences regarding error format...

@marijnh
Copy link
Member

marijnh commented Feb 18, 2019

I think I agree—this is quite invasive (see the failing tests, for example, but also expectations that existing client code may have), and can be implemented relatively easily in code that actually reports the error.

@kripken
Copy link
Author

kripken commented Feb 19, 2019

Fair enough, I thought this might be nice as a default error, but I understand. Closing.

@kripken kripken closed this Feb 19, 2019
yeputons added a commit to yeputons/emscripten that referenced this pull request Jul 26, 2019
…s on Windows

This fixes a patch applied to acorn.js for quoting error-causing text
in parse errors (acornjs/acorn#793).
Previously it splitted binary data on \n to get lines, which was
inconsistent with the rest of the parser and caused excess \r in
the error message on Windows. Now it uses the same regex as the rest
of acorn.js (e.g. getLineInfo used by error reporting).
pull bot pushed a commit to Pandinosaurus/emscripten that referenced this pull request Jul 26, 2019
* Fix emscripten-core#9068: get rid of malformed newlines in emcc errors on Windows

This fixes a patch applied to acorn.js for quoting error-causing text
in parse errors (acornjs/acorn#793).
Previously it splitted binary data on \n to get lines, which was
inconsistent with the rest of the parser and caused excess \r in
the error message on Windows. Now it uses the same regex as the rest
of acorn.js (e.g. getLineInfo used by error reporting).

* Fix emscripten-core#9057 by fixing by emscripten-core#9068
belraquib pushed a commit to belraquib/emscripten that referenced this pull request Dec 23, 2020
* Fix emscripten-core#9068: get rid of malformed newlines in emcc errors on Windows

This fixes a patch applied to acorn.js for quoting error-causing text
in parse errors (acornjs/acorn#793).
Previously it splitted binary data on \n to get lines, which was
inconsistent with the rest of the parser and caused excess \r in
the error message on Windows. Now it uses the same regex as the rest
of acorn.js (e.g. getLineInfo used by error reporting).

* Fix emscripten-core#9057 by fixing by emscripten-core#9068
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants