millermedeiros / esformatter

ECMAScript code beautifier/formatter
MIT License
970 stars 91 forks source link

ES6 bug when formatting new object literal syntax #324

Closed seeekr closed 9 years ago

seeekr commented 9 years ago

file.es6.js

fn({
   m () {
   }
})

Using npm install -g standard && standard --format gives me this:

/Users/denis/.nvm/versions/io.js/v2.2.1/lib/node_modules/standard/node_modules/standard-format/node_modules/esformatter/node_modules/rocambole-whitespace/rocambole-whitespace.js:43
    typeOrValue, amount, token.value
                              ^
TypeError: Cannot read property 'value' of undefined
    at Object.limitBefore (/Users/denis/.nvm/versions/io.js/v2.2.1/lib/node_modules/standard/node_modules/standard-format/node_modules/esformatter/node_modules/rocambole-whitespace/rocambole-whitespace.js:43:31)
    at /Users/denis/.nvm/versions/io.js/v2.2.1/lib/node_modules/standard/node_modules/standard-format/node_modules/esformatter/lib/hooks/ObjectExpression.js:54:9
    at Array.forEach (native)
    at ObjectExpression [as format] (/Users/denis/.nvm/versions/io.js/v2.2.1/lib/node_modules/standard/node_modules/standard-format/node_modules/esformatter/lib/hooks/ObjectExpression.js:23:19)
    at transformNode (/Users/denis/.nvm/versions/io.js/v2.2.1/lib/node_modules/standard/node_modules/standard-format/node_modules/esformatter/lib/esformatter.js:137:10)
    at Array.forEach (native)
    at Object.moonwalk (/Users/denis/.nvm/versions/io.js/v2.2.1/lib/node_modules/standard/node_modules/standard-format/node_modules/esformatter/node_modules/rocambole/rocambole.js:428:11)
    at transform (/Users/denis/.nvm/versions/io.js/v2.2.1/lib/node_modules/standard/node_modules/standard-format/node_modules/esformatter/lib/esformatter.js:109:13)
    at doFormat (/Users/denis/.nvm/versions/io.js/v2.2.1/lib/node_modules/standard/node_modules/standard-format/node_modules/esformatter/lib/esformatter.js:93:3)
    at Object.format (/Users/denis/.nvm/versions/io.js/v2.2.1/lib/node_modules/standard/node_modules/standard-format/node_modules/esformatter/lib/esformatter.js:72:9)

On other instances of this issue I had checked with node versions 0.10.x and 0.12.x, too, and it didn't seem to matter that I'm using iojs.

And I think this bug originates somewhere in this project or below, not in the "standard" frontend that I use that brings a bunch of config settings for linting/formatting. If this is the wrong place to post this, then please direct me as I'm not familiar enough with these tools and projects in order to properly judge that! Thanks :)

(Also, ping #192)

millermedeiros commented 9 years ago

this is supposed to work on latest esformatter - we have tests for ES6 object literal methods.. (see https://github.com/millermedeiros/esformatter/commit/abd9365d99c28056e9b08d99caca785fc87c0247) maybe standard-format is still using an old version

seeekr commented 9 years ago

Hmm yeah, apparently we're still on ^0.6.0 there. Will post an issue there and link to this one. Thanks for helping!

feross commented 9 years ago

We updated to esformatter 0.7.0.