From 3f39e07f31a70e72acb0245f0b8211fbb19ca897 Mon Sep 17 00:00:00 2001 From: James Ide Date: Fri, 13 Feb 2015 19:29:40 -0800 Subject: [PATCH 1/2] Add check for "react-native" to the file type regex Check for `require('react-native')` in addition to `require('react')`. Tested the regex to make sure it matches both. --- lib/atom-react.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/atom-react.coffee b/lib/atom-react.coffee index 586544b..38fb3a8 100644 --- a/lib/atom-react.coffee +++ b/lib/atom-react.coffee @@ -93,7 +93,7 @@ class AtomReact isReact: (text) -> if not contentCheckRegex? - match = (atom.config.get('react.detectReactFilePattern') || '/require\\([\'"]react[\'"]\\)/').match(new RegExp('^/(.*?)/([gimy]*)$')); + match = (atom.config.get('react.detectReactFilePattern') || '/require\\([\'"]react(?:-native)?[\'"]\\)/').match(new RegExp('^/(.*?)/([gimy]*)$')); contentCheckRegex = new RegExp(match[1], match[2]) return text.match(contentCheckRegex)? @@ -105,7 +105,7 @@ class AtomReact path = require 'path' - # Check if file extension is .jsx or the file has require React + # Check if file extension is .jsx or the file requires React extName = path.extname(editor.getPath()) if extName is ".jsx" or (extName is ".js" and @isReact(editor.getText())) jsxGrammar = atom.grammars.grammarsByScopeName["source.js.jsx"] From cc01f5f66fdf05dd7b236662f5bff79bb8779f1f Mon Sep 17 00:00:00 2001 From: James Ide Date: Fri, 13 Feb 2015 19:34:47 -0800 Subject: [PATCH 2/2] Add test to check that `require('react-native')` is checked --- spec/atom-react-spec.coffee | 7 +++++++ spec/fixtures/sample-correct-native.js | 1 + 2 files changed, 8 insertions(+) create mode 100644 spec/fixtures/sample-correct-native.js diff --git a/spec/atom-react-spec.coffee b/spec/atom-react-spec.coffee index 27d7c71..9946d4b 100644 --- a/spec/atom-react-spec.coffee +++ b/spec/atom-react-spec.coffee @@ -1,5 +1,6 @@ describe "React tests", -> sampleCorrectFile = require.resolve './fixtures/sample-correct.js' + sampleCorrectNativeFile = require.resolve './fixtures/sample-correct-native.js' sampleInvalidFile = require.resolve './fixtures/sample-invalid.js' beforeEach -> @@ -20,6 +21,12 @@ describe "React tests", -> expect(editor.getGrammar().scopeName).toEqual 'source.js.jsx' editor.destroy() + it "should select source.js.jsx if file has require('react-native')", -> + waitsForPromise -> + atom.workspace.open(sampleCorrectNativeFile, autoIndent: false).then (editor) -> + expect(editor.getGrammar().scopeName).toEqual 'source.js.jsx' + editor.destroy() + it "should select source.js if file doesnt have require('react')", -> waitsForPromise -> atom.workspace.open(sampleInvalidFile, autoIndent: false).then (editor) -> diff --git a/spec/fixtures/sample-correct-native.js b/spec/fixtures/sample-correct-native.js new file mode 100644 index 0000000..72b4cb3 --- /dev/null +++ b/spec/fixtures/sample-correct-native.js @@ -0,0 +1 @@ +var React = require('react-native');