From 21b3f39c0b5a4a19b1fab5c6a6c6f70403f8c0b6 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Sun, 4 Feb 2018 10:42:21 -0800 Subject: [PATCH] [fix] babel-plugin require call for compiled modules require('module') => require('module').default Fix #786 --- .../__snapshots__/index-test.js.snap | 22 +++++++++---------- .../src/index.js | 14 ++++++++---- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/babel-plugin-react-native-web/src/__tests__/__snapshots__/index-test.js.snap b/packages/babel-plugin-react-native-web/src/__tests__/__snapshots__/index-test.js.snap index d21f45af..7c0cb841 100644 --- a/packages/babel-plugin-react-native-web/src/__tests__/__snapshots__/index-test.js.snap +++ b/packages/babel-plugin-react-native-web/src/__tests__/__snapshots__/index-test.js.snap @@ -74,13 +74,13 @@ const { StyleSheet, TouchableOpacity } = require('react-native'); ↓ ↓ ↓ ↓ ↓ ↓ -const ReactNative = require('react-native-web/dist/index'); +const ReactNative = require('react-native-web/dist/index').default; -const View = require('react-native-web/dist/exports/View'); +const View = require('react-native-web/dist/exports/View').default; -const StyleSheet = require('react-native-web/dist/exports/StyleSheet'); +const StyleSheet = require('react-native-web/dist/exports/StyleSheet').default; -const TouchableOpacity = require('react-native-web/dist/exports/TouchableOpacity'); +const TouchableOpacity = require('react-native-web/dist/exports/TouchableOpacity').default; " `; @@ -92,18 +92,18 @@ const { ColorPropType, StyleSheet, View, TouchableOpacity, processColor } = requ ↓ ↓ ↓ ↓ ↓ ↓ -const ReactNative = require('react-native-web/dist/index'); +const ReactNative = require('react-native-web/dist/index').default; -const createElement = require('react-native-web/dist/exports/createElement'); +const createElement = require('react-native-web/dist/exports/createElement').default; -const ColorPropType = require('react-native-web/dist/exports/ColorPropType'); +const ColorPropType = require('react-native-web/dist/exports/ColorPropType').default; -const StyleSheet = require('react-native-web/dist/exports/StyleSheet'); +const StyleSheet = require('react-native-web/dist/exports/StyleSheet').default; -const View = require('react-native-web/dist/exports/View'); +const View = require('react-native-web/dist/exports/View').default; -const TouchableOpacity = require('react-native-web/dist/exports/TouchableOpacity'); +const TouchableOpacity = require('react-native-web/dist/exports/TouchableOpacity').default; -const processColor = require('react-native-web/dist/exports/processColor'); +const processColor = require('react-native-web/dist/exports/processColor').default; " `; diff --git a/packages/babel-plugin-react-native-web/src/index.js b/packages/babel-plugin-react-native-web/src/index.js index 2d3fac4a..a8b86ac5 100644 --- a/packages/babel-plugin-react-native-web/src/index.js +++ b/packages/babel-plugin-react-native-web/src/index.js @@ -92,7 +92,10 @@ module.exports = function({ types: t }) { return t.variableDeclaration(path.node.kind, [ t.variableDeclarator( t.identifier(identifier.value.name), - t.callExpression(t.identifier('require'), [t.stringLiteral(distLocation)]) + t.memberExpression( + t.callExpression(t.identifier('require'), [t.stringLiteral(distLocation)]), + t.identifier('default') + ) ) ]); } @@ -105,9 +108,12 @@ module.exports = function({ types: t }) { const importIndex = t.variableDeclaration(path.node.kind, [ t.variableDeclarator( t.identifier(name), - t.callExpression(t.identifier('require'), [ - t.stringLiteral('react-native-web/dist/index') - ]) + t.memberExpression( + t.callExpression(t.identifier('require'), [ + t.stringLiteral('react-native-web/dist/index') + ]), + t.identifier('default') + ) ) ]);