fix module shadowing when using CommonJS-like module formatters - fixes #1544

This commit is contained in:
Sebastian McKenzie 2015-05-16 01:47:48 +01:00
parent 375689a1ff
commit ea510d09d0
5 changed files with 38 additions and 17 deletions

View File

@ -6,8 +6,8 @@ import * as util from "../../util";
import * as t from "../../types"; import * as t from "../../types";
export default class AMDFormatter extends DefaultFormatter { export default class AMDFormatter extends DefaultFormatter {
init() { setup() {
CommonFormatter.prototype._init.call(this, this.hasNonDefaultExports); CommonFormatter.prototype._setup.call(this, this.hasNonDefaultExports);
} }
buildDependencyLiterals() { buildDependencyLiterals() {

View File

@ -4,11 +4,11 @@ import * as util from "../../util";
import * as t from "../../types"; import * as t from "../../types";
export default class CommonJSFormatter extends DefaultFormatter { export default class CommonJSFormatter extends DefaultFormatter {
init() { setup() {
this._init(this.hasLocalExports); this._setup(this.hasLocalExports);
} }
_init(conditional) { _setup(conditional) {
var file = this.file; var file = this.file;
var scope = file.scope; var scope = file.scope;

View File

@ -85,18 +85,28 @@ export function ExportNamedDeclaration(node, parent, scope) {
} }
} }
export function Program(node) { export var Program = {
var imports = []; enter(node) {
var rest = []; var imports = [];
var rest = [];
for (var i = 0; i < node.body.length; i++) { for (var i = 0; i < node.body.length; i++) {
var bodyNode = node.body[i]; var bodyNode = node.body[i];
if (t.isImportDeclaration(bodyNode)) { if (t.isImportDeclaration(bodyNode)) {
imports.push(bodyNode); imports.push(bodyNode);
} else { } else {
rest.push(bodyNode); rest.push(bodyNode);
}
}
node.body = imports.concat(rest);
},
exit(node, parent, scope, file) {
if (!file.transformers["es6.modules"].canTransform()) return;
if (file.moduleFormatter.setup) {
file.moduleFormatter.setup();
} }
} }
};
node.body = imports.concat(rest);
}

View File

@ -0,0 +1,3 @@
export function module() {
}

View File

@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.module = _module;
function _module() {}