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

Whitespace-induced bug #724

Closed
ralt opened this issue Sep 2, 2018 · 2 comments
Closed

Whitespace-induced bug #724

ralt opened this issue Sep 2, 2018 · 2 comments

Comments

@ralt
Copy link

ralt commented Sep 2, 2018

A simple reproducer:

const fs = require('fs');

const acorn = require('./node_modules/acorn/dist/acorn_loose.js');
const escodegen = require('escodegen');

console.log(escodegen.generate(acorn.parse_dammit(fs.readFileSync('foo.js'))));

Where foo.js is this file:

return new Foo({
    value: [
    new Foo({
    })]
})

It renders like this:

return new Foo({
    value: [],
    new,
    Foo({}) {
        ;
    }
});

Note that with this in foo.js:

return new Foo({
    value: [
        new Foo({
    })]
})

the bug does not occur. (Note the 2nd new Foo() indentation.)

@marijnh
Copy link
Member

marijnh commented Sep 3, 2018

The loose parser treats indentation as significant, so this is the expected behavior, What you should probably do is always try a regular parse first, and only when that fails, fall back on the loose parser. See also #199

@marijnh marijnh closed this as completed Sep 3, 2018
@ralt
Copy link
Author

ralt commented Sep 3, 2018

Ok, thanks!

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

No branches or pull requests

3 participants
@marijnh @ralt and others