royriojas / esformatter-jsx

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

JSX replaced to <__JSXExpression_0_0 /> #97

Closed wKich closed 7 years ago

wKich commented 7 years ago

Here is the link to online demo. I think it's close to #60, but has something different behavior.

royriojas commented 7 years ago

oh @wKich thanks for reporting this. Can you check if this is happening on latest version? (demo is not using the latest, will have to update it soon)

wKich commented 7 years ago

Checked on latest version, output the same.

wKich commented 7 years ago

I did some research and we can fixed this problem modify RegExp in this line to

new RegExp(`<__JSXExpression_0_${  idx  }\\s*\\/>`);

Because js-beautify insert new line character here if JSXExpression placeholder tag follow by unformatted html tag and line length bigger then wrap_line_length option.

wKich commented 7 years ago

I try to make PR. But I think somewhere in options reading there is another bug. If I specify for my test case htmlOptions.unformatted default array from js-beautify package, then the some other test cases after my will fail. It easily check if specify this in the first test case options json

"unformatted": [
  "a", "abbr", "area", "audio", "b", "bdi", "bdo", "br", "button", "canvas", "cite",
  "code", "data", "datalist", "del", "dfn", "em", "embed", "i", "iframe", "img",
  "input", "ins", "kbd", "keygen", "label", "map", "mark", "math", "meter", "noscript",
  "object", "output", "progress", "q", "ruby", "s", "samp", "select", "small",
  "span", "strong", "sub", "sup", "svg", "template", "textarea", "time", "u", "var",
  "video", "wbr", "text",
  "acronym", "address", "big", "dt", "ins", "small", "strike", "tt",
  "pre"
]