├── .gitattributes
├── .gitignore
├── .travis.yml
├── ISSUE_TEMPLATE.md
├── LICENSE
├── Makefile
├── README.md
├── demo.png
├── js2-parser.md
├── js2-tests.el
├── key-demo.gif
├── rjsx-mode.el
└── rjsx-tests.el
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.png binary
2 | *.jpeg binary
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled
2 | *.elc
3 |
4 | # Packaging
5 | .cask
6 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # This config was adapted from flycheck/emacs-travis
2 | # Copyright © 2015 Sebastian Wiesner swiesner@lunaryorn.com
3 |
4 | # Permission is hereby granted, free of charge, to any person
5 | # obtaining a copy of this software and associated documentation files
6 | # (the "Software"), to deal in the Software without restriction,
7 | # including without limitation the rights to use, copy, modify, merge,
8 | # publish, distribute, sublicense, and/or sell copies of the Software,
9 | # and to permit persons to whom the Software is furnished to do so,
10 | # subject to the following conditions:
11 |
12 | # The above copyright notice and this permission notice shall be
13 | # included in all copies or substantial portions of the Software.
14 |
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 | # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 | # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | # SOFTWARE.
23 |
24 | language: emacs-lisp
25 | sudo: required
26 | dist: trusty
27 | group: deprecated-2017Q4
28 | cache:
29 | - directories:
30 | # Cache stable Emacs binaries (saves 1min per job)
31 | - "$HOME/emacs/"
32 | # Allow Emacs snapshot builds to fail and don’t wait for these as they can take
33 | # a looooong time
34 | matrix:
35 | fast_finish: true
36 | allow_failures:
37 | - env: EMACS_VERSION=snapshot
38 | env:
39 | - EMACS_VERSION=24.5
40 | - EMACS_VERSION=25.3
41 | - EMACS_VERSION=26.1
42 | - EMACS_VERSION=snapshot
43 | before_install:
44 | # Configure $PATH: Executables are installed to $HOME/bin
45 | - export PATH="$HOME/bin:$PATH"
46 | # Download the makefile to emacs-travis.mk
47 | - wget 'https://raw.githubusercontent.com/flycheck/emacs-travis/master/emacs-travis.mk'
48 | # Install Emacs (according to $EMACS_VERSION) and Cask
49 | - make -f emacs-travis.mk install_emacs
50 | install:
51 | - make install-deps
52 | script:
53 | - make test EMACS=${EMACS}
54 |
--------------------------------------------------------------------------------
/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Please check if the bug still exists when using `js2-jsx-mode` (if
2 | applicable). If so, it is most likely an upstream bug and should be
3 | reported there.
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Felipe
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | EMACS = emacs
2 |
3 | BATCHFLAGS = -batch -Q
4 |
5 | SRCS = rjsx-mode.el
6 | OBJS = rjsx-mode.elc
7 |
8 | JS2_LINK = https://raw.githubusercontent.com/mooz/js2-mode/master/js2-mode.el
9 | JS2_OLD_INDENT_LINK = https://raw.githubusercontent.com/mooz/js2-mode/master/js2-old-indent.el
10 |
11 |
12 | %.elc: %.el
13 | ${EMACS} $(BATCHFLAGS) -L . -f batch-byte-compile $^
14 |
15 | all: $(OBJS)
16 |
17 | clean:
18 | -rm -f $(OBJS)
19 |
20 | test:
21 | ${EMACS} $(BATCHFLAGS) -L . -l rjsx-mode.el -l js2-tests.el -l rjsx-tests.el\
22 | -f ert-run-tests-batch-and-exit
23 |
24 | install-deps:
25 | curl --silent '$(JS2_LINK)' > js2-mode.el
26 | curl --silent '$(JS2_OLD_INDENT_LINK)' > js2-old-indent.el
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # rjsx-mode: A major mode for editing JSX files
2 | [](https://melpa.org/#/rjsx-mode)
3 | [](https://stable.melpa.org/#/rjsx-mode)
4 | [](https://travis-ci.org/felipeochoa/rjsx-mode)
5 |
6 | This mode derives from `js2-mode`, extending its parser to support JSX syntax
7 | according to the [official spec](https://facebook.github.io/jsx/). This
8 | means you get all of the `js2` features plus proper syntax checking
9 | and highlighting of JSX code blocks.
10 |
11 | Here's a screenshot of it in action:
12 |
13 |
14 |
15 |
16 | ## Installing
17 |
18 | `rjsx-mode` is available on [Melpa](https://melpa.org/), so if you have that
19 | repository configured you can just `package-list-packages` and install it from there.
20 | (If not, you can follow [their guide](https://melpa.org/#/getting-started) on
21 | getting started). `rjsx-mode` automatically registers itself for `*.jsx` files,
22 | but you can use `(add-to-list 'auto-mode-alist '("components\\/.*\\.js\\'" . rjsx-mode))`
23 |
24 | Alternatively, you can download `rjsx-mode.el` from this repository and use
25 | `load-file` or similar to add it to your current session.
26 |
27 | ## Features
28 |
29 | `js2-mode` does not include a JSX parser, but rather an E4X parser, which
30 | means it gets confused with certain JSX constructs. This mode extends the
31 | `js2** parser to support all JSX constructs and proper syntax highlighting
32 | and **indentation**.
33 |
34 | `rjsx-mode` adds some electricity to `<` and `C-d` to make adding new
35 | JSX elements less repetitive:
36 |
37 | * `<` inserts `>` whenever it would start a new JSX node (and simply
38 | inserts `<` otherwise)
39 | * `>` or `C-d` right before the slash in a self-closing tag
40 | automatically inserts a closing tag and places point inside the
41 | element
42 |
43 | The result is you can do the following:
44 |
45 |
46 |
47 | * `C-c C-r` lets you rename the enclosing tag
48 |
49 | Some features that this mode adds to `js2`:
50 |
51 | * Proper indentation of JSX regardless of how you write it. (No need to wrap
52 | in parentheses!)
53 | * Highlighting JSX tag names and attributes (using the `rjsx-tag` and
54 | `rjsx-attr` faces)
55 | * Parsing the spread operator `{...otherProps}`
56 | * `&&` and `||` in child expressions `