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

estraverse breaking on comments inside conditions #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

evindor
Copy link

@evindor evindor commented Apr 8, 2014

Example:

if (a &&
    // We need to check b beacuse of IE   <<< BOOM
    b > 0 && c) {
    // code
}

Trace:

/Users/evindor/.nvm/v0.10.26/lib/node_modules/amd-to-closure/node_modules/escodegen/node_modules/estraverse/estraverse.js:646
                    if (node.range[1] < comment.extendedRange[0]) {
                                  ^
TypeError: Cannot read property '1' of undefined
    at Controller.traverse.leave (/Users/evindor/.nvm/v0.10.26/lib/node_modules/amd-to-closure/node_modules/escodegen/node_modules/estraverse/estraverse.js:646:35)
    at Controller.__execute (/Users/evindor/.nvm/v0.10.26/lib/node_modules/amd-to-closure/node_modules/escodegen/node_modules/estraverse/estraverse.js:313:31)
    at Controller.traverse (/Users/evindor/.nvm/v0.10.26/lib/node_modules/amd-to-closure/node_modules/escodegen/node_modules/estraverse/estraverse.js:379:28)
    at traverse (/Users/evindor/.nvm/v0.10.26/lib/node_modules/amd-to-closure/node_modules/escodegen/node_modules/estraverse/estraverse.js:551:27)
    at Object.attachComments (/Users/evindor/.nvm/v0.10.26/lib/node_modules/amd-to-closure/node_modules/escodegen/node_modules/estraverse/estraverse.js:640:9)
    at Stream.end (/Users/evindor/.nvm/v0.10.26/lib/node_modules/amd-to-closure/index.js:98:17)
    at _end (/Users/evindor/.nvm/v0.10.26/lib/node_modules/amd-to-closure/node_modules/through/index.js:65:9)
    at Stream.stream.end (/Users/evindor/.nvm/v0.10.26/lib/node_modules/amd-to-closure/node_modules/through/index.js:74:5)
    at ReadStream.onend (_stream_readable.js:483:10)
    at ReadStream.g (events.js:180:16)

I've just hacked it around, i guess this issue needs more deep exploration.

@Constellation
Copy link
Member

Hm.
Do you add range option to esprima? attachComments need range option.

@evindor
Copy link
Author

evindor commented Apr 13, 2014

Yes, range option was turned on.

@RReverser
Copy link
Member

@evindor Looks like the issue is you are calling attachComments(...) after modifying AST, which means absolute positions it relies on are broken at moment of attachment.

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