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

babel-plugin-react-native-web

Package Overview
Dependencies
Maintainers
1
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-react-native-web - npm Package Compare versions

Comparing version 0.3.0-rc.3 to 0.3.0-rc.4

2

package.json
{
"name": "babel-plugin-react-native-web",
"version": "0.3.0-rc.3",
"version": "0.3.0-rc.4",
"description": "Babel plugin for React Native for Web",

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

const plugin = require('..');
const pluginTester = require('babel-plugin-tester');
const tests = [
// import react-native
{
title: 'import from "native-native"',
code: `import ReactNative from 'react-native';
import { View } from 'react-native';
import { Invalid, View as MyView, ViewPropTypes } from 'react-native';
import * as ReactNativeModules from 'react-native';`,
snapshot: true
},
{
title: 'import from "react-native-web"',
code: `import { createElement } from 'react-native-web';
import { ColorPropType, StyleSheet, View, TouchableOpacity, processColor } from 'react-native-web';
import * as ReactNativeModules from 'react-native-web';`,
snapshot: true
},
{
title: 'export from "react-native"',
code: `export { View } from 'react-native';
export { ColorPropType, StyleSheet, Text, createElement } from 'react-native';`,
snapshot: true
},
{
title: 'export from "react-native-web"',
code: `export { View } from 'react-native-web';
export { ColorPropType, StyleSheet, Text, createElement } from 'react-native-web';`,
snapshot: true
},
{
title: 'require "react-native-web"',
code: `const ReactNative = require('react-native-web');
const { createElement } = require('react-native-web');
const { ColorPropType, StyleSheet, View, TouchableOpacity, processColor } = require('react-native-web');`,
snapshot: true
}
];
pluginTester({
plugin,
snapshot: true,
tests: [
// import react-native
"import { View } from 'react-native';",
"import { Switch, Text, View as MyView, ViewPropTypes } from 'react-native';",
"import { createElement, Switch, StyleSheet } from 'react-native';",
"import { InvalidThing, TouchableOpacity } from 'react-native';",
"import * as RNW from 'react-native';",
// import react-native-web
// "import { View } from 'react-native-web';",
// "import { Switch, Text, View as MyView } from 'react-native-web';",
// "import { createElement, Switch, StyleSheet } from 'react-native-web';",
// "import { InvalidThing, TouchableOpacity } from 'react-native-web';",
// "import * as RNW from 'react-native-web';",
// require react-native
"const { View } = require('react-native');",
"let { Switch, Text, View: MyView } = require('react-native');",
"var { createElement, Switch, StyleSheet } = require('react-native');",
"const { InvalidThing, TouchableOpacity } = require('react-native');",
// require react-native-web
// "const { View } = require('react-native-web');",
// "let { Switch, Text, View: MyView } = require('react-native-web');",
// "var { createElement, Switch, StyleSheet } = require('react-native-web');",
// "const { InvalidThing, TouchableOpacity } = require('react-native-web');",
// export react-native
"export { View } from 'react-native';",
"export { Switch, Text, View as MyView, ViewPropTypes } from 'react-native';",
"export { createElement, Switch, StyleSheet } from 'react-native';",
"export { InvalidThing, TouchableOpacity } from 'react-native';",
"export { default as RNW } from 'react-native';",
{
code: "const RNW = require('react-native');",
output: "const RNW = require('react-native');",
snapshot: false
}
]
tests
});

@@ -100,13 +100,18 @@ const getDistLocation = importName => {

init.arguments.length === 1 &&
init.arguments[0].value === 'react-native'
(init.arguments[0].value === 'react-native' || init.arguments[0].value === 'react-native-web')
);
};
const isReactNativeModule = ({ source, specifiers }) =>
source &&
(source.value === 'react-native' || source.value === 'react-native-web') &&
specifiers.length;
module.exports = function({ types: t }) {
return {
name: 'Rewrite react-native paths for react-native-web',
name: 'Rewrite react-native to react-native-web',
visitor: {
ImportDeclaration(path) {
const { source, specifiers } = path.node;
if (source && source.value === 'react-native' && specifiers.length) {
ImportDeclaration(path, state) {
const { specifiers } = path.node;
if (isReactNativeModule(path.node)) {
const imports = specifiers

@@ -125,3 +130,6 @@ .map(specifier => {

}
return t.importDeclaration([specifier], t.stringLiteral('react-native-web'));
return t.importDeclaration(
[specifier],
t.stringLiteral('react-native-web/dist/index')
);
})

@@ -133,5 +141,5 @@ .filter(Boolean);

},
ExportNamedDeclaration(path) {
const { source, specifiers } = path.node;
if (source && source.value === 'react-native' && specifiers.length) {
ExportNamedDeclaration(path, state) {
const { specifiers } = path.node;
if (isReactNativeModule(path.node)) {
const exports = specifiers

@@ -151,8 +159,8 @@ .map(specifier => {

}
return t.exportNamedDeclaration(
null,
[specifier],
t.stringLiteral('react-native-web')
);
}
return t.exportNamedDeclaration(
null,
[specifier],
t.stringLiteral('react-native-web/dist/index')
);
})

@@ -164,3 +172,3 @@ .filter(Boolean);

},
VariableDeclaration(path) {
VariableDeclaration(path, state) {
if (isReactNativeRequire(t, path.node)) {

@@ -167,0 +175,0 @@ const { id } = path.node.declarations[0];

Sorry, the diff of this file is not supported yet

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