royriojas / esformatter-jsx

esformatter plugin: format jsx files (or js files with Facebook React JSX Syntax)
MIT License
142 stars 25 forks source link

Can't get it to work in sublime: SyntaxError: Unexpected Token #79

Closed teknologist closed 8 years ago

teknologist commented 8 years ago

Hi,

Whatever JSX file I try, I always get this error:

JSFMT ==>
Error: /Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/jsfmt.js:31
        throw err;
        ^

SyntaxError: Unexpected token (3:21)
    at Parser.pp.raise (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/parser/location.js:24:13)
    at Parser.pp.unexpected (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/parser/util.js:91:8)
    at Parser.pp.expect (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/parser/util.js:85:33)
    at Parser.pp.jsxParseAttribute (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:304:10)
    at Parser.pp.jsxParseOpeningElementAt (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:321:31)
    at Parser.pp.jsxParseElementAt (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:343:29)
    at Parser.pp.jsxParseElementAt (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:356:30)
    at Parser.pp.jsxParseElement (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:392:15)
    at Parser.parseExprAtom (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:404:21)
    at Parser.pp.parseExprSubscripts (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/parser/expression.js:267:19)

Here is my jsfmt settings file:

{
    "alert-errors": true,
    "autoformat": true,
    "extensions":
    [
        "js",
        "jsx"
    ],
    "ignore-selection": false,
    "node-path": "/usr/local/bin/node",
    "options":
    {
        "indent":
        {
            "value": "    "
        },
        "jsx":
        {
            "JSXExpressionsSingleLine": true,
            "alignWithFirstAttribute": false,
            "attrsOnSameLineAsTag": false,
            "firstAttributeOnSameLine": true,
            "formatJSX": true,
            "formatJSXExpressions": true,
            "htmlOptions":
            {
                "indent_char": " ",
                "indent_size": 2,
                "max_preserve_newlines": 2,
                "preserve_newlines": true
            },
            "maxAttrsOnTag": 3,
            "removeSpaceBeforeClosingJSX": false,
            "spaceInJSXExpressionContainers": " "
        },
        "plugins":
        [
            "esformatter-jsx",
            "esformatter-quotes",
            "esformatter-semicolons",
            "esformatter-braces",
            "esformatter-dot-notation"
        ],
        "preset": "default"
    },
    "options-JSON":
    {
        "plugins":
        [
            "esformatter-quotes"
        ],
        "quotes":
        {
            "type": "double"
        }
    }
}

I am using latest versions as of today. Been struggling with this..

Can anyone help ?

royriojas commented 8 years ago

hi @teknologist can you try formatting your code here and see if it works?

http://royriojas.com/resources/esformatter-jsx/

Just to make sure it is something with the formatter and not with your configuration. If it works there it might be an issue with the configuration

teknologist commented 8 years ago

Hi @royriojas,

I have tested the code online and it works without a glitch....

royriojas commented 8 years ago

Hi @teknologist have you followed the instructions found here? https://github.com/royriojas/esformatter-jsx/wiki/Usage-with-jsfmt

teknologist commented 8 years ago

@royriojas Yes I did. That is when I hit the last line and opened the issue.. ;-)

eric@sentinel ~/L/A/S/P/jsfmt> ls -la node_modules/
total 0
drwxr-xr-x+  97 eric  staff   3298 15 jui 09:59 .
drwxr-xr-x+  15 eric  staff    510 15 jui 09:59 ..
drwxr-xr-x+  23 eric  staff    782 18 mai 14:00 .bin
drwxr-xr-x+  10 eric  staff    340 18 mai 13:59 abbrev
drwxr-xr-x+  14 eric  staff    476 18 mai 13:59 acorn
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 acorn-to-esprima
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 ansi-regex
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 ansi-styles
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 babel-code-frame
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 babel-messages
drwxr-xr-x+   9 eric  staff    306 18 mai 13:59 babel-runtime
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 babel-traverse
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 babel-types
drwxr-xr-x+  14 eric  staff    476 18 mai 13:59 babylon
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 balanced-match
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 brace-expansion
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 chalk
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 commander
drwxr-xr-x+   9 eric  staff    306 18 mai 13:59 concat-map
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 concat-stream
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 config-chain
drwxr-xr-x+  20 eric  staff    680 18 mai 13:59 core-js
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 core-util-is
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 debug
drwxr-xr-x+   5 eric  staff    170 18 mai 13:59 diff
drwxr-xr-x+  12 eric  staff    408 18 mai 13:59 disparity
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 escape-string-regexp
drwxr-xr-x+  15 eric  staff    510 15 jui 09:59 esformatter
drwxr-xr-x+   7 eric  staff    238 10 fév 17:04 esformatter-braces
drwxr-xr-x+   7 eric  staff    238 10 fév 17:04 esformatter-dot-notation
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 esformatter-ignore
drwxr-xr-x+   9 eric  staff    306 15 jui 09:59 esformatter-jsx
drwxr-xr-x+   7 eric  staff    238 15 jui 09:59 esformatter-parser
drwxr-xr-x+   7 eric  staff    238 15 jui 09:59 esformatter-quotes
drwxr-xr-x+  10 eric  staff    340 18 mai 13:58 esformatter-semicolons
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 esprima
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 esutils
drwxr-xr-x+  12 eric  staff    408 10 fév 17:04 extend
drwxr-xr-x+  10 eric  staff    340 18 mai 13:59 foreach
drwxr-xr-x+   9 eric  staff    306 18 mai 13:59 fresh-falafel
drwxr-xr-x+   5 eric  staff    170 10 fév 17:04 get-stdin
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 glob
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 globals
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 graceful-readlink
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 has-ansi
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 inflight
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 inherits
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 ini
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 invariant
drwxr-xr-x+  10 eric  staff    340 18 mai 13:59 isarray
drwxr-xr-x+  11 eric  staff    374 18 mai 13:59 isexe
drwxr-xr-x+  18 eric  staff    612 15 jui 09:59 js-beautify
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 js-tokens
drwxr-xr-x+   8 eric  staff    272 10 fév 17:04 jsfmt
drwxr-xr-x+ 582 eric  staff  19788 18 mai 13:59 lodash
drwxr-xr-x+  10 eric  staff    340 18 mai 13:59 loose-envify
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 minimatch
drwxr-xr-x+   9 eric  staff    306 18 mai 13:59 minimist
drwxr-xr-x+  11 eric  staff    374 18 mai 13:59 mkdirp
drwxr-xr-x+  38 eric  staff   1292 18 mai 13:59 mout
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 ms
drwxr-xr-x+  11 eric  staff    374 18 mai 13:59 nopt
drwxr-xr-x+  11 eric  staff    374 18 mai 13:59 npm-path
drwxr-xr-x+  11 eric  staff    374 18 mai 13:59 npm-run
drwxr-xr-x+  10 eric  staff    340 18 mai 13:59 npm-which
drwxr-xr-x+  14 eric  staff    476 18 mai 13:59 object-keys
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 once
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 os-homedir
drwxr-xr-x+  11 eric  staff    374 18 mai 13:59 os-shim
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 path-is-absolute
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 process-nextick-args
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 proto-list
drwxr-xr-x+  12 eric  staff    408 18 mai 13:59 protochain
drwxr-xr-x+  15 eric  staff    510 18 mai 13:59 readable-stream
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 repeat-string
drwxr-xr-x+  10 eric  staff    340 18 mai 13:59 resolve
drwxr-xr-x+  11 eric  staff    374 18 mai 13:59 rocambole
drwxr-xr-x+  10 eric  staff    340 18 mai 13:59 rocambole-indent
drwxr-xr-x+   8 eric  staff    272 15 jui 09:59 rocambole-linebreak
drwxr-xr-x+   5 eric  staff    170 18 mai 13:59 rocambole-node
drwxr-xr-x+  12 eric  staff    408 18 mai 13:59 rocambole-token
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 rocambole-whitespace
drwxr-xr-x+  17 eric  staff    578 18 mai 13:59 semver
drwxr-xr-x+   9 eric  staff    306 18 mai 13:59 serializerr
drwxr-xr-x+  12 eric  staff    408 18 mai 13:59 spawn-sync
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 stdin
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 string_decoder
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 strip-ansi
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 strip-json-comments
drwxr-xr-x+   7 eric  staff    238 18 mai 13:59 supports-color
drwxr-xr-x+  10 eric  staff    340 18 mai 13:59 sync-exec
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 to-fast-properties
drwxr-xr-x+   9 eric  staff    306 18 mai 13:59 typedarray
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 user-home
drwxr-xr-x+   8 eric  staff    272 18 mai 13:59 util-deprecate
drwxr-xr-x+   9 eric  staff    306 15 jui 09:59 which
drwxr-xr-x+   6 eric  staff    204 18 mai 13:59 wrappy
teknologist commented 8 years ago

@royriojas While doing an npm list I have this:

eric@sentinel ~/L/A/S/P/jsfmt> npm list
sublime-jsfmt@ /Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt
├── esformatter@0.9.5 extraneous
├─┬ esformatter-braces@1.2.1
│ └── rocambole-token@1.2.1
├─┬ esformatter-dot-notation@1.3.1
│ ├─┬ rocambole@0.6.0
│ │ └── esprima@2.6.0
│ ├── rocambole-token@1.2.1
│ └── unquoted-property-validator@1.0.0
├── esformatter-jsx@7.0.0 extraneous
├── esformatter-quotes@1.1.0
├── esformatter-semicolons@1.1.2
├── extend@3.0.0
├── get-stdin@4.0.1
└─┬ jsfmt@0.5.3
  ├── deep-extend@0.4.1
  ├── docopt@0.4.1
  ├─┬ escodegen@1.7.1
  │ ├── esprima@1.2.5
  │ ├── estraverse@1.9.3
  │ ├── esutils@2.0.2
  │ ├─┬ optionator@0.5.0
  │ │ ├── deep-is@0.1.3
  │ │ ├── fast-levenshtein@1.0.7
  │ │ ├── levn@0.2.5
  │ │ ├── prelude-ls@1.1.2
npm ERR! extraneous: esformatter@0.9.5 /Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter
npm ERR! extraneous: esformatter-jsx@7.0.0 /Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx
.2
  │ │ └── wordwrap@0.0.3
  │ └─┬ source-map@0.2.0
  │   └── amdefine@1.0.0
  ├─┬ esformatter@0.9.0
  │ ├── acorn-to-esprima@2.0.8
  │ ├─┬ babel-traverse@6.5.0
  │ │ ├─┬ babel-code-frame@6.5.0
  │ │ │ ├─┬ chalk@1.1.1
  │ │ │ │ ├── ansi-styles@2.1.0
  │ │ │ │ ├── escape-string-regexp@1.0.4
  │ │ │ │ ├─┬ has-ansi@2.0.0
  │ │ │ │ │ └── ansi-regex@2.0.0
  │ │ │ │ ├─┬ strip-ansi@3.0.0
  │ │ │ │ │ └── ansi-regex@2.0.0
  │ │ │ │ └── supports-color@2.0.0
  │ │ │ ├── esutils@2.0.2
  │ │ │ ├── js-tokens@1.0.2
  │ │ │ └─┬ line-numbers@0.2.0
  │ │ │   └── left-pad@0.0.3
  │ │ ├── babel-messages@6.5.0
  │ │ ├─┬ babel-runtime@5.8.35
  │ │ │ └── core-js@1.2.6
  │ │ ├─┬ babel-types@6.5.2
  │ │ │ ├── esutils@2.0.2
  │ │ │ └── to-fast-properties@1.0.1
  │ │ ├─┬ debug@2.2.0
  │ │ │ └── ms@0.7.1
  │ │ ├── globals@8.18.0
  │ │ ├─┬ invariant@2.2.0
  │ │ │ └─┬ loose-envify@1.1.0
  │ │ │   └── js-tokens@1.0.2
  │ │ ├── lodash@3.10.1
  │ │ └─┬ repeating@1.1.3
  │ │   └─┬ is-finite@1.0.1
  │ │     └── number-is-nan@1.0.0
  │ ├─┬ babylon@6.5.2
  │ │ └─┬ babel-runtime@5.8.35
  │ │   └── core-js@1.2.6
  │ ├── debug@0.7.4
  │ ├─┬ disparity@2.0.0
  │ │ ├── ansi-styles@2.1.0
  │ │ └── diff@1.4.0
  │ ├── minimist@1.2.0
  │ ├── mout@0.11.1
  │ ├─┬ npm-run@2.0.0
  │ │ ├─┬ npm-path@1.0.2
  │ │ │ └─┬ which@1.2.4
  │ │ │   ├─┬ is-absolute@0.1.7
  │ │ │   │ └── is-relative@0.1.3
  │ │ │   └── isexe@1.1.2
  │ │ ├─┬ npm-which@2.0.0
  │ │ │ ├─┬ commander@2.9.0
  │ │ │ │ └── graceful-readlink@1.0.1
  │ │ │ └─┬ which@1.2.4
  │ │ │   ├─┬ is-absolute@0.1.7
  │ │ │   │ └── is-relative@0.1.3
  │ │ │   └── isexe@1.1.2
  │ │ ├─┬ serializerr@1.0.2
  │ │ │ └── protochain@1.0.3
  │ │ ├─┬ spawn-sync@1.0.15
  │ │ │ ├─┬ concat-stream@1.5.1
  │ │ │ │ ├── inherits@2.0.1
  │ │ │ │ ├─┬ readable-stream@2.0.5
  │ │ │ │ │ ├── core-util-is@1.0.2
  │ │ │ │ │ ├── isarray@0.0.1
  │ │ │ │ │ ├── process-nextick-args@1.0.6
  │ │ │ │ │ ├── string_decoder@0.10.31
  │ │ │ │ │ └── util-deprecate@1.0.2
  │ │ │ │ └── typedarray@0.0.6
  │ │ │ └── os-shim@0.1.3
  │ │ └── sync-exec@0.5.0
  │ ├── resolve@1.1.7
  │ ├─┬ rocambole-indent@2.0.4
  │ │ └─┬ debug@2.2.0
  │ │   └── ms@0.7.1
  │ ├─┬ rocambole-linebreak@1.0.1
  │ │ ├─┬ debug@2.2.0
  │ │ │ └── ms@0.7.1
  │ │ └── semver@4.3.6
  │ ├── rocambole-node@1.0.0
  │ ├── rocambole-token@1.2.1
  │ ├─┬ rocambole-whitespace@1.0.0
  │ │ ├─┬ debug@2.2.0
  │ │ │ └── ms@0.7.1
  │ │ └── repeat-string@1.5.2
  │ ├── stdin@0.0.1
  │ ├── strip-json-comments@0.1.3
  │ ├── supports-color@1.3.1
  │ └─┬ user-home@2.0.0
  │   └── os-homedir@1.0.1
  ├─┬ esformatter-var-each@2.1.0
  │ ├─┬ rocambole@0.3.6
  │ │ └── esprima@1.0.4
  │ └── rocambole-token@1.2.1
  ├── esprima@2.7.2
  ├─┬ falafel@1.2.0
  │ ├── acorn@1.2.2
  │ ├── foreach@2.0.5
  │ ├── isarray@0.0.1
  │ └── object-keys@1.0.9
  ├─┬ glob@5.0.15
  │ ├─┬ inflight@1.0.4
  │ │ └── wrappy@1.0.1
  │ ├── inherits@2.0.1
  │ ├─┬ minimatch@3.0.0
  │ │ └─┬ brace-expansion@1.1.3
  │ │   ├── balanced-match@0.3.0
  │ │   └── concat-map@0.0.1
  │ ├─┬ once@1.3.3
  │ │ └── wrappy@1.0.1
  │ └── path-is-absolute@1.0.0
  ├─┬ rc@1.1.6
  │ ├── ini@1.3.4
  │ ├── minimist@1.2.0
  │ └── strip-json-comments@1.0.4
  ├── rocambole@0.7.0
  ├─┬ tmp@0.0.28
  │ └── os-tmpdir@1.0.1
  └── underscore@1.8.3
teknologist commented 8 years ago

@royriojas I just updated to 7.0.0

Same error:

error: The formatting failed please check the console for more details.

JSFMT ==>
Error: /Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/jsfmt.js:31
        throw err;
        ^

SyntaxError: Unexpected token (3:120)
    at Parser.pp.raise (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/parser/location.js:24:13)
    at Parser.pp.unexpected (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/parser/util.js:91:8)
    at Parser.pp.expect (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/parser/util.js:85:33)
    at Parser.pp.jsxParseExpressionContainer (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:295:8)
    at Parser.pp.jsxParseAttributeValue (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:258:19)
    at Parser.pp.jsxParseAttribute (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:310:58)
    at Parser.pp.jsxParseOpeningElementAt (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:321:31)
    at Parser.pp.jsxParseElementAt (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:343:29)
    at Parser.pp.jsxParseElement (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:392:15)
    at Parser.parseExprAtom (/Users/eric/Library/Application Support/Sublime Text 3/Packages/jsfmt/node_modules/esformatter-jsx/node_modules/babylon/lib/plugins/jsx/index.js:404:21)
teknologist commented 8 years ago

Hi @royriojas ,

Just thought I'd let you know I pinpointed the error to an incompatibility with esformatter-semicolons.

once I remove it from my esformatter plugins, the problem disappeared.

And by the way, that plugin breaks JSX anyways...

So I guess the bug is in esformatter-semicolons rather than the jsx plugin.

Closing this one!

Thanks for the help!