js-emacs / js2-refactor.el

A JavaScript refactoring library for emacs
GNU General Public License v3.0
373 stars 47 forks source link

Any plan to support web-mode #99

Closed Qquanwei closed 6 years ago

Qquanwei commented 6 years ago

Due to js2-refactor depend on js2-mode AST, doesn't support web-mode, but I usually using web-mode to edit by jsx files and web-mode is so popular , so any plan to support web-mode ?

NicolasPetton commented 6 years ago

@Qquanwei Have you tried to turn on js2-minor-mode in web-mode?

NicolasPetton commented 6 years ago

@Qquanwei I confirm that with the following settings js2-refactor works in web-mode for javascript files:

(add-hook 'web-mode-hook #'js2-minor-mode)
(add-hook 'web-mode-hook #'js2-refactor-mode)
JJPandari commented 6 years ago

@NicolasPetton Great to know there's js2-minor-mode.

A little observation: I tried in a web-mode buffer, when the code is <script>function () {...}</script>, js2r says there's parse errors, when I removed the <script> </script>tags, js2-parsed-errors is nil and js2r works fine.

Thoughts on maybe-a-new-feature: The above is the most common situation when I want to use web-mode: an html or server side template file, with javascript codes wrapped in <script> tags. js2r doesn't work unless we extract the js codes for js2-mode to parse them alone, not the whole buffer. Is it a good idea to maybe have some configs like (setq js2-js-code-surrounding-tags '("<script>" "</script>")) (setq js2-js-code-matcher "<script>\\(.+\\)<\\/script>") (don't mind my elisp regex error if there's any), so users can easily use all js2 and js2r goodies in html files and so?

This feature shouldn't be too hard to implement with some with-temp-buffer thing I guess? But still a bit beyond my reach and it may fit in js2 so... Also this may not cover all server side template files like var <?=$name?> = "<?=$value?>"; (<?=$var?> is the .php file interpolation syntax) as js2 will have parse errors on them, but covering html files should still be quite a step.

Wait, should I open an issue for js2-mode?

NicolasPetton commented 6 years ago

潘俊杰 notifications@github.com writes:

Wait, should I open an issue for js2-mode?

I guess so. There's little we can do if there are js2 parse errors.