Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes #246
  • Loading branch information
gaearon committed Apr 18, 2016
1 parent 68b9f02 commit 8bdeaa0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = function(args) {
}
}

const DEFAULT_EXPORT = Symbol();
const REGISTRATIONS = Symbol();
return {
visitor: {
ExportDefaultDeclaration(path) {
Expand All @@ -84,34 +84,31 @@ module.exports = function(args) {
])
)
path.node.declaration = id;
path.parent[DEFAULT_EXPORT] = id;
path.parent[REGISTRATIONS].push(
buildRegistration({
ID: id,
NAME: t.stringLiteral('default')
})
);
},

Program: {
enter({ node }) {
node[DEFAULT_EXPORT] = null;
},

exit({ node, scope }, { file }) {
let registrations = [];

enter({ node, scope }) {
node[REGISTRATIONS] = [];
for (let id in scope.bindings) {
const binding = scope.bindings[id];
if (shouldRegisterBinding(binding)) {
registrations.push(buildRegistration({
node[REGISTRATIONS].push(buildRegistration({
ID: binding.identifier,
NAME: t.stringLiteral(id)
}));
}
}
},

if (node[DEFAULT_EXPORT]) {
registrations.push(buildRegistration({
ID: node[DEFAULT_EXPORT],
NAME: t.stringLiteral('default')
}));
}

exit({ node, scope }, { file }) {
let registrations = node[REGISTRATIONS];
node[REGISTRATIONS] = null;
node.body.push(
buildTagger({
FILENAME: t.stringLiteral(file.opts.filename),
Expand Down
4 changes: 4 additions & 0 deletions test/babel/fixtures/issue-246/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["../../../../src/babel"]
}
3 changes: 3 additions & 0 deletions test/babel/fixtures/issue-246/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function spread(...args) {
return args.push(1)
}
38 changes: 38 additions & 0 deletions test/babel/fixtures/issue-246/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.spread = spread;
function spread() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}

return args.push(1);
}

(function () {
function tagSource(fn, localName) {
if (typeof fn !== "function") {
return;
}

if (fn.hasOwnProperty("__source")) {
return;
}

try {
Object.defineProperty(fn, "__source", {
enumerable: false,
configurable: true,
value: {
fileName: __FILENAME__,
localName: localName
}
});
} catch (err) {}
}

tagSource(spread, "spread");
})();

0 comments on commit 8bdeaa0

Please sign in to comment.