Skip to content

Commit b856b07

Browse files
committed
Merge branch 'master' into multiple-export-as-default
2 parents f4ce058 + e8330b2 commit b856b07

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "babel-plugin-add-module-exports",
3-
"version": "1.0.0",
3+
"version": "1.0.2",
44
"description": "Fix babel/babel#2212",
55
"main": "lib",
66
"files": [

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ class ExportsFinder {
103103
}
104104

105105
const objectName = path.get(`${property}.left.object.name`).node
106-
const propertyName = path.get(`${property}.left.property.name`).node
106+
// Check name of MemberExpressions and values of StringLiterals
107+
const propertyName =
108+
path.get(`${property}.left.property.name`).node ||
109+
path.get(`${property}.left.property.value`).node
107110
if (objectName === 'exports' || objectName === '_exports') {
108111
if (propertyName === 'default') {
109112
this.hasExportsDefault = true

test/spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,28 @@ module.exports = [
209209
exports: 'default-entry'
210210
}
211211
},
212+
{
213+
name: 'handle a single quote string literal export',
214+
code: `
215+
Object.defineProperty(exports, '__esModule', {value: true});
216+
exports['default'] = 'foo';
217+
`,
218+
expected: {
219+
module: 'foo',
220+
exports: 'foo'
221+
}
222+
},
223+
{
224+
name: 'handle a double quote string literal export',
225+
code: `
226+
Object.defineProperty(exports, '__esModule', {value: true});
227+
exports["default"] = 'foo';
228+
`,
229+
expected: {
230+
module: 'foo',
231+
exports: 'foo'
232+
}
233+
},
212234
{
213235
name: 'export same var as default and named declarations',
214236
code: 'const foo="bar";export { foo, foo as default };',

0 commit comments

Comments
 (0)