Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Stage-1 Named Wildcard Exports #99

Merged
merged 5 commits into from
Mar 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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;
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,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