babel-plugin-react-require
Advanced tools
Comparing version 1.0.2 to 2.0.0
import React from 'react'; | ||
class Component { | ||
export default class Component { | ||
render() { | ||
return <div />; | ||
} | ||
} | ||
export default Component; | ||
} |
import React from "react"; | ||
class Component { | ||
export default class Component { | ||
render() { | ||
return <div />; | ||
} | ||
} | ||
export default Component; | ||
} |
@@ -1,7 +0,5 @@ | ||
class Component { | ||
export default class Component { | ||
render() { | ||
return null; | ||
} | ||
} | ||
export default Component; | ||
} |
@@ -1,38 +0,41 @@ | ||
module.exports = function (babel) { | ||
var t = babel.types | ||
'use strict'; | ||
var plugin = { | ||
JSXOpeningElement: { | ||
enter: function(node, parent, scope, file) { | ||
file.set('hasJSX', true) | ||
} | ||
}, | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Program: { | ||
enter: function(node, parent, scope, file) { | ||
file.set('hasJSX', false) | ||
exports.default = function (_ref) { | ||
let t = _ref.types; | ||
return { | ||
visitor: { | ||
JSXOpeningElement(path, _ref2) { | ||
let file = _ref2.file; | ||
file.set('hasJSX', true); | ||
}, | ||
exit: function(node, parent, scope, file) { | ||
var jsxPragma = file.opts.jsxPragma | ||
var hasJSX = file.get('hasJSX') | ||
Program: { | ||
enter(path, _ref3) { | ||
let file = _ref3.file; | ||
var shouldAddImport = jsxPragma === 'React.createElement' | ||
&& hasJSX | ||
&& !scope.hasBinding('React') | ||
file.set('hasJSX', false); | ||
}, | ||
if (!shouldAddImport) { | ||
return | ||
} | ||
exit(_ref4, _ref5) { | ||
let node = _ref4.node; | ||
let scope = _ref4.scope; | ||
let file = _ref5.file; | ||
var reactImportDeclaration = t.importDeclaration([ | ||
t.importDefaultSpecifier(t.identifier('React')) | ||
], t.literal('react')) | ||
if (!(file.get('hasJSX') && !scope.hasBinding('React'))) { | ||
return; | ||
} | ||
node.body.unshift(reactImportDeclaration) | ||
const reactImportDeclaration = t.importDeclaration([t.importDefaultSpecifier(t.identifier('React'))], t.stringLiteral('react')); | ||
node.body.unshift(reactImportDeclaration); | ||
} | ||
} | ||
} | ||
} | ||
return new babel.Transformer('react-require', plugin) | ||
} | ||
}; | ||
}; |
{ | ||
"name": "babel-plugin-react-require", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Babel plugin that adds React import declaration if file contains JSX tags.", | ||
@@ -22,7 +22,5 @@ "keywords": [ | ||
}, | ||
"contributors": [ | ||
], | ||
"contributors": [], | ||
"main": "lib", | ||
"bin": { | ||
}, | ||
"bin": {}, | ||
"repository": { | ||
@@ -33,28 +31,38 @@ "type": "git", | ||
"scripts": { | ||
"prepublish": "npm run build-examples", | ||
"build-examples": "babel examples -d built-examples" | ||
"clean": "rimraf lib", | ||
"build": "babel src -d lib", | ||
"build-examples": "babel examples -d built-examples", | ||
"lint": "eslint src examples test", | ||
"prepublish": "npm run clean && npm run build && npm run build-examples", | ||
"test": "mocha --compilers js:babel-core/register", | ||
"test-coverage": "npm run build && istanbul instrument --output lib-cov lib && mocha --reporter mocha-istanbul" | ||
}, | ||
"config": { | ||
}, | ||
"dependencies": { | ||
}, | ||
"config": {}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"babel": "5.5.6" | ||
"babel-cli": "^6.1.2", | ||
"babel-core": "^6.1.2", | ||
"babel-eslint": "3.1.17", | ||
"babel-plugin-syntax-jsx": "^6.0.14", | ||
"babel-plugin-transform-es2015-classes": "^6.1.2", | ||
"babel-plugin-transform-es2015-destructuring": "^6.0.18", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.1.3", | ||
"babel-plugin-transform-es2015-parameters": "^6.0.18", | ||
"chai": "3.0.0", | ||
"eslint": "0.23.0", | ||
"eslint-plugin-react": "2.5.2", | ||
"istanbul": "0.3.15", | ||
"mocha": "2.2.5", | ||
"mocha-istanbul": "0.2.0", | ||
"rimraf": "^2.4.3" | ||
}, | ||
"peerDependencies": { | ||
}, | ||
"bundledDependencies": [ | ||
], | ||
"optionalDependencies": { | ||
}, | ||
"engines": { | ||
}, | ||
"os": [ | ||
], | ||
"cpu": [ | ||
], | ||
"peerDependencies": {}, | ||
"bundledDependencies": [], | ||
"optionalDependencies": {}, | ||
"engines": {}, | ||
"os": [], | ||
"cpu": [], | ||
"preferGlobal": false, | ||
"private": false, | ||
"publishConfig": { | ||
} | ||
"publishConfig": {} | ||
} |
13135
17
119
15