Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

requirejs-react-jsx

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

requirejs-react-jsx - npm Package Compare versions

Comparing version 0.16.2 to 1.0.0

babel-5.8.34.min.js

184

jsx.js
define(function () {
'use strict';
var isNode = typeof process !== "undefined" &&
process.versions &&
!!process.versions.node;
var buildMap = {};
var transform = {
/**
* Reads the .jsx file synchronously and requires react-tools
* to perform the transform when compiling using r.js
*/
ReactTools: function (name, parentRequire, onLoadNative, config) {
var fs = require.nodeRequire('fs'),
ReactTools = require.nodeRequire('react-tools'),
compiled = void 0;
function getSourceMapConfig(config) {
var fallback = config.isBuild ? false : 'inline';
var path = parentRequire.toUrl(ensureJSXFileExtension(name, config));
var oldOptions = config.jsx && config.jsx.transformOptions || {}; // @deprecated
var options = config.config && config.config.jsx && config.config.jsx.transformOptions || oldOptions || {
harmony: true // enable harmony by default
};
if (config && config.babel && 'sourceMaps' in config.babel) {
return config.babel.sourceMaps;
} else {
return fallback;
}
}
try {
var content = fs.readFileSync(path, {encoding: 'utf8'});
function babelSync(name, parentRequire, onLoadNative, config) {
var babel = require.nodeRequire('babel');
var path = parentRequire.toUrl(ensureJSXFileExtension(name, config));
try {
compiled = ReactTools.transform(ensureJSXPragma(content, config), options);
try {
var result = babel.transformFileSync(path, {
sourceFileName: config.baseUrl + name,
sourceMaps: getSourceMapConfig(config),
filename: config.baseUrl + name
});
if (process.env.running_under_istanbul) {
var istanbul = require.nodeRequire('istanbul');
var coverageVariable = Object.keys(global).filter(function (key) { return key.indexOf('$$cov_') === 0 })[0];
var instrumenter = new istanbul.Instrumenter({
coverageVariable: coverageVariable
});
var compiled = result.code;
compiled = instrumenter.instrumentSync(compiled, path);
}
} catch (err) {
throw new Error('jsx.js - Error while running JSXTransformer on ' + path + '\n' + err.message);
}
if (process.env.running_under_istanbul) {
var istanbul = require.nodeRequire('istanbul');
var coverageVariable = Object.keys(global).filter(function (key) { return key.indexOf('$$cov_') === 0 })[0];
var instrumenter = new istanbul.Instrumenter({
coverageVariable: coverageVariable
});
} catch (err) {
onLoadNative.error(err);
compiled = instrumenter.instrumentSync(compiled, path);
}
if (config.isBuild) {
buildMap[name] = compiled;
}
buildMap[name] = compiled;
onLoadNative.fromText(compiled);
},
/**
* Dynamically requires Babel and the text plugin async
* and transforms the JSX in the browser.
* The configproperty 'babelOptions' will be passed to Babel.
*/
babel: function (name, parentRequire, onLoadNative, config) {
name = ensureJSXFileExtension(name, config);
} catch (err) {
onLoadNative.error(err);
}
}
var options = config.jsx && config.jsx.babelOptions || {};
function babelAsync(name, parentRequire, onLoadNative, config) {
name = ensureJSXFileExtension(name, config);
var onLoad = function(content, babel) {
parentRequire(['babel', 'text'], function (babel, text) {
text.load(name, parentRequire, function (content) {
try {
var transform = babel.transform(ensureJSXPragma(content, config), options);
var result = babel.transform(content, {
sourceFileName: config.baseUrl + name,
sourceMaps: getSourceMapConfig(config),
filename: config.baseUrl + name
});
content = transform.code;
if (transform.map) {
content += "\n//# sourceURL=" + config.baseUrl + name;
}
onLoadNative.fromText(result.code);
} catch (err) {
onLoadNative.error(err);
}
onLoadNative.fromText(content);
};
parentRequire(['babel', 'text'], function (babel, text) {
text.load(name, parentRequire, function (content) {
onLoad(content, babel);
}, config);
});
},
});
}
/**
* Dynamically requires JSXTransformer and the text plugin async
* and transforms the JSX in the browser
*/
JSXTransformer: function (name, parentRequire, onLoadNative, config) {
name = ensureJSXFileExtension(name, config);
var oldOptions = config.jsx && config.jsx.transformOptions || {}; // @deprecated
var options = config.config && config.config.jsx && config.config.jsx.transformOptions || oldOptions || {
harmony: true // enable harmony by default
};
if (options.inlineSourceMap) {
options.sourceMap = true;
}
var onLoad = function(content, JSXTransformer) {
try {
var transform = JSXTransformer.transform(ensureJSXPragma(content, config), options);
content = transform.code;
if (options.inlineSourceMap && transform.sourceMap) {
var sourceMap = transform.sourceMap;
if (typeof transform.sourceMap.toJSON === 'function') {
sourceMap = transform.sourceMap.toJSON();
}
sourceMap.file = name;
sourceMap.sources[0] = config.baseUrl + name;
content += "\n//# sourceMappingURL=data:application/json;base64," + btoa(JSON.stringify(sourceMap));
} else {
content += "\n//# sourceURL=" + config.baseUrl + name;
}
} catch (err) {
onLoadNative.error(err);
}
onLoadNative.fromText(content);
};
parentRequire(['JSXTransformer', 'text'], function (JSXTransformer, text) {
text.load(name, parentRequire, function (content) {
onLoad(content, JSXTransformer);
}, config);
});
}
};
function ensureJSXFileExtension(name, config) {
var fileExtension = config.jsx && config.jsx.fileExtension || '.jsx';
var fileExtension = config && config.jsx && config.jsx.fileExtension || '.jsx';

@@ -149,26 +82,9 @@ if (name.indexOf(fileExtension) === -1) {

function ensureJSXPragma(content, config){
if (config.usePragma && content.indexOf('@jsx React.DOM') === -1) {
content = "/** @jsx React.DOM */\n" + content;
}
return content;
}
var isNode = typeof process !== "undefined" &&
process.versions &&
!!process.versions.node;
var jsx = {
version: '0.1.1',
load: isNode ? babelSync : babelAsync,
load: function (name, parentRequire, onLoadNative, config) {
var method = isNode ? 'ReactTools' : (config.jsx.transformer || 'JSXTransformer');
transform[method].call(this, name, parentRequire, onLoadNative, config);
},
write: function (pluginName, name, write) {
if (buildMap.hasOwnProperty(name)) {
if (typeof buildMap[name] === 'text') {
var text = buildMap[name];
write.asModule(pluginName + "!" + name, text);

@@ -175,0 +91,0 @@ }

{
"name": "requirejs-react-jsx",
"version": "0.16.2",
"version": "1.0.0",
"description": "A RequireJS plugin for loading jsx in require.js and r.js",

@@ -5,0 +5,0 @@ "main": "jsx.js",

@@ -30,3 +30,3 @@ # requirejs-react-jsx

`app.js`
`app.jsx`

@@ -65,3 +65,3 @@ ```js

"react": "bower_components/react/react-with-addons",
"JSXTransformer": "bower_components/react/JSXTransformer",
"babel": "bower_components/requirejs-react-jsx/babel-5.8.34.min",
"jsx": "bower_components/requirejs-react-jsx/jsx",

@@ -74,15 +74,9 @@ "text": "bower_components/requirejs-text/text"

"exports": "React"
},
"JSXTransformer": "JSXTransformer"
}
},
config: {
jsx: {
fileExtension: ".jsx",
transformOptions: {
harmony: true,
stripTypes: false,
inlineSourceMap: true
},
usePragma: false
babel: {
sourceMaps: "inline", // One of [false, 'inline', 'both']. See https://babeljs.io/docs/usage/options/
fileExtension: ".jsx" // Can be set to anything, like .es6 or .js. Defaults to .jsx
}

@@ -100,14 +94,2 @@ }

Can also be configured with Babel:
```javascript
config: {
jsx: {
transformer: "babel",
babelOptions: {
sourceMaps: 'inline'
}
}
}
```
### Building

@@ -166,4 +148,8 @@

# Changelog
**1.0** - Eliminated all other transformer options than Babel. Switched config variable from `jsx` to `babel`. Added browser compatible babel 5.x build to repository to use for in-browser compilations
# License
[MIT](LICENSE)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc