Skip to content

Commit

Permalink
Merge pull request #99 from spncrlkt/master
Browse files Browse the repository at this point in the history
Fix for Stage-1 Named Wildcard Exports
  • Loading branch information
speedskater committed Mar 6, 2016
2 parents c4bdb52 + dcbb559 commit ddfea82
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
presets: ["es2015"]
}
presets: ["es2015"],
plugins: ["transform-export-extensions"]
}
2 changes: 2 additions & 0 deletions fixtures/transformation/namedWildcardExport/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as _namedThing from 'path/to/thing';
export { _namedThing as namedThing };
1 change: 1 addition & 0 deletions fixtures/transformation/namedWildcardExport/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as namedThing from 'path/to/thing';
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 10 additions & 0 deletions samples/namedWildcardExport/sample.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 2 additions & 0 deletions samples/namedWildcardExport/src/namedExports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const test1 = 'TEST1';
export const test2 = 'TEST2';
1 change: 1 addition & 0 deletions samples/namedWildcardExport/src/namedWildcardExport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * as namedWildcardExport from './namedExports';
3 changes: 2 additions & 1 deletion src/babel-plugin-rewire.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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;
Expand Down
5 changes: 4 additions & 1 deletion test/BabelRewirePluginTransformTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ describe('BabelRewirePluginTest', function() {
babelPluginRewire,
"syntax-async-functions",
"syntax-flow",
"syntax-jsx"
"syntax-jsx",
"transform-export-extensions"
]
};

Expand All @@ -26,6 +27,7 @@ describe('BabelRewirePluginTest', function() {
"transform-es2015-block-scoping",
"transform-es2015-template-literals",
"transform-es2015-typeof-symbol",
"transform-export-extensions",
"transform-regenerator"
]
};
Expand Down Expand Up @@ -87,6 +89,7 @@ describe('BabelRewirePluginTest', function() {
'primitiveExportWithNamedFunctionExport',
'wildcardImport',
'wildcardExport',
'namedWildcardExport',
'recursiveRewireCall',
'requireExports',
'requireMultiExports',
Expand Down
2 changes: 2 additions & 0 deletions usage-tests/BabelRewirePluginUsageTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
};
Expand Down Expand Up @@ -66,6 +67,7 @@ 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');
require('../samples/jsx-switch/sample.js');
hook.unhook('.js'); // removes your own transform

0 comments on commit ddfea82

Please sign in to comment.