Skip to content

Commit

Permalink
Add JSX support.
Browse files Browse the repository at this point in the history
  • Loading branch information
moll committed Jul 8, 2015
1 parent 46a3a8a commit f378e3e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
rather than when reading a file.
This allows you to manually set the filetype to JavaScript after opening
a file, for example, and still get Node.vim's mappings.
- Initializes Node.vim mappings for JSX (those with the `jsx` filetype) files.

## 0.8.1 (Apr 15, 2014)
- Updates the URL from which Node.vim downloads Node core module source files.
Expand Down
6 changes: 5 additions & 1 deletion autoload/node.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let node#suffixesadd = [".js", ".json"]
let node#suffixesadd = [".js", ".json", ".jsx"]

function! node#initialize(root)
let b:node_root = a:root
Expand All @@ -21,6 +21,10 @@ function! node#initialize(root)
endfunction

function! node#javascript()
" This might be called multiple times if multiple filetypes match.
if exists("b:node_javascript") && b:node_javascript | return | endif
let b:node_javascript = 1

setlocal path-=/usr/include
let &l:suffixesadd .= "," . join(g:node#suffixesadd, ",")
let &l:include = '\<require(\(["'']\)\zs[^\1]\+\ze\1'
Expand Down
2 changes: 1 addition & 1 deletion plugin/node.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if exists("g:loaded_node") || &cp || v:version < 700 | finish | endif
let g:loaded_node = 1

let s:filetypes = ["javascript", "json"]
let s:filetypes = ["javascript", "json", "jsx"]
if exists("g:node_filetypes") | let s:filetypes = g:node_filetypes | endif

function! s:detect(dir)
Expand Down
6 changes: 6 additions & 0 deletions test/autoload/lib_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def find(name)
find("./other").must_equal target
end

it "must return ./other.jsx given ./other" do
target = touch File.join(@dir, "other.jsx")
$vim.edit File.join(@dir, "index.js")
find("./other").must_equal target
end

it "must return ./other.js given ./other relative to file" do
target = touch File.join(@dir, "lib", "other.js")
$vim.edit File.join(@dir, "lib", "index.js")
Expand Down
13 changes: 13 additions & 0 deletions test/autoload_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,19 @@
$vim.echo(%(bufname("%"))).must_equal target
end

it "must find when filetype set to JSX after open" do
target = touch File.join(@dir, "node_modules", "foo", "index.js")

touch File.join(@dir, "index.react"), %(require("foo"))
$vim.edit File.join(@dir, "index.react")
$vim.echo("&filetype").must_equal ""
$vim.command("setfiletype jsx")
$vim.echo("&filetype").must_equal "jsx"

$vim.feedkeys "$hhgf"
$vim.echo(%(bufname("%"))).must_equal target
end

it "must find when filetype set to JavaScript and Foo after open" do
target = touch File.join(@dir, "node_modules", "foo", "index.js")

Expand Down

0 comments on commit f378e3e

Please sign in to comment.