diff --git a/.babelrc b/.babelrc index e1d246c..164fc6b 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,4 @@ { - presets: ["es2015"] -} \ No newline at end of file + presets: ["es2015"], + plugins: ["transform-export-extensions"] +} diff --git a/fixtures/transformation/namedWildcardExport/expected.js b/fixtures/transformation/namedWildcardExport/expected.js new file mode 100644 index 0000000..2dba802 --- /dev/null +++ b/fixtures/transformation/namedWildcardExport/expected.js @@ -0,0 +1,2 @@ +import * as _namedThing from 'path/to/thing'; +export { _namedThing as namedThing }; diff --git a/fixtures/transformation/namedWildcardExport/input.js b/fixtures/transformation/namedWildcardExport/input.js new file mode 100644 index 0000000..4e3f85d --- /dev/null +++ b/fixtures/transformation/namedWildcardExport/input.js @@ -0,0 +1 @@ +export * as namedThing from 'path/to/thing'; diff --git a/package.json b/package.json index 478e2a5..b1c89bf 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "babel-plugin-transform-es2015-block-scoping": "^6.1.18", "babel-plugin-transform-es2015-template-literals": "^6.1.18", "babel-plugin-transform-es2015-typeof-symbol": "^6.1.18", + "babel-plugin-transform-export-extensions": "^6.5.0", "babel-plugin-transform-react-jsx": "^6.3.13", "babel-plugin-transform-regenerator": "^6.1.18", "babel-plugin-transform-runtime": "^6.1.18", diff --git a/samples/namedWildcardExport/sample.js b/samples/namedWildcardExport/sample.js new file mode 100644 index 0000000..8f2a2bf --- /dev/null +++ b/samples/namedWildcardExport/sample.js @@ -0,0 +1,10 @@ +import * as namedWildcardImport from './src/namedWildcardExport'; +import {test1, test2} from './src/namedExports'; +import expect from 'expect.js'; + +describe('named wildcard export of imported object', () => { + it('has objects exported from namedExports', () => { + expect(namedWildcardImport.namedWildcardExport.test1).to.equal(test1); + expect(namedWildcardImport.namedWildcardExport.test2).to.equal(test2); + }); +}); diff --git a/samples/namedWildcardExport/src/namedExports.js b/samples/namedWildcardExport/src/namedExports.js new file mode 100644 index 0000000..31aa689 --- /dev/null +++ b/samples/namedWildcardExport/src/namedExports.js @@ -0,0 +1,2 @@ +export const test1 = 'TEST1'; +export const test2 = 'TEST2'; diff --git a/samples/namedWildcardExport/src/namedWildcardExport.js b/samples/namedWildcardExport/src/namedWildcardExport.js new file mode 100644 index 0000000..9d810ab --- /dev/null +++ b/samples/namedWildcardExport/src/namedWildcardExport.js @@ -0,0 +1 @@ +export * as namedWildcardExport from './namedExports'; diff --git a/src/babel-plugin-rewire.js b/src/babel-plugin-rewire.js index e7cf3f5..d65fd7f 100644 --- a/src/babel-plugin-rewire.js +++ b/src/babel-plugin-rewire.js @@ -118,7 +118,8 @@ module.exports = function({ types: t }) { 'ExportNamedDeclaration|ExportAllDeclaration': function ({ node: { specifiers = [] } }, rewireInformation) { let hasDefaultExport = specifiers.some(function(specifier) { - return specifier.local.name === 'default'; + return ((specifier.local && specifier.local.name === 'default') || + (specifier.exported && specifier.exported.name === 'default')); }); rewireInformation.hasES6DefaultExport = rewireInformation.hasES6DefaultExport || hasDefaultExport; rewireInformation.isES6Module = true; diff --git a/test/BabelRewirePluginTransformTest.js b/test/BabelRewirePluginTransformTest.js index 1c4a4e4..c7a861c 100644 --- a/test/BabelRewirePluginTransformTest.js +++ b/test/BabelRewirePluginTransformTest.js @@ -13,7 +13,8 @@ describe('BabelRewirePluginTest', function() { babelPluginRewire, "syntax-async-functions", "syntax-flow", - "syntax-jsx" + "syntax-jsx", + "transform-export-extensions" ] }; @@ -26,6 +27,7 @@ describe('BabelRewirePluginTest', function() { "transform-es2015-block-scoping", "transform-es2015-template-literals", "transform-es2015-typeof-symbol", + "transform-export-extensions", "transform-regenerator" ] }; @@ -87,6 +89,7 @@ describe('BabelRewirePluginTest', function() { 'primitiveExportWithNamedFunctionExport', 'wildcardImport', 'wildcardExport', + 'namedWildcardExport', 'recursiveRewireCall', 'requireExports', 'requireMultiExports', diff --git a/usage-tests/BabelRewirePluginUsageTest.js b/usage-tests/BabelRewirePluginUsageTest.js index 42b7438..6834d3c 100644 --- a/usage-tests/BabelRewirePluginUsageTest.js +++ b/usage-tests/BabelRewirePluginUsageTest.js @@ -21,6 +21,7 @@ function transformSampleCodeToTestWithBabelPluginRewire(source, filename) { "transform-es2015-block-scoping", "transform-es2015-template-literals", "transform-es2015-typeof-symbol", + "transform-export-extensions", "transform-regenerator" ] }; @@ -66,5 +67,6 @@ require('../samples/rewireClasses/sample.js'); require('../samples/objectAssign/sample.js'); require('../samples/updateOperations/sample.js'); require('../samples/wildcardExport/sample.js'); +require('../samples/namedWildcardExport/sample.js'); require('../samples/assignmentOperations/sample.js'); hook.unhook('.js'); // removes your own transform