fix module shadowing when using CommonJS-like module formatters - fixes #1544
This commit is contained in:
parent
375689a1ff
commit
ea510d09d0
@ -6,8 +6,8 @@ import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default class AMDFormatter extends DefaultFormatter {
|
||||
init() {
|
||||
CommonFormatter.prototype._init.call(this, this.hasNonDefaultExports);
|
||||
setup() {
|
||||
CommonFormatter.prototype._setup.call(this, this.hasNonDefaultExports);
|
||||
}
|
||||
|
||||
buildDependencyLiterals() {
|
||||
|
||||
@ -4,11 +4,11 @@ import * as util from "../../util";
|
||||
import * as t from "../../types";
|
||||
|
||||
export default class CommonJSFormatter extends DefaultFormatter {
|
||||
init() {
|
||||
this._init(this.hasLocalExports);
|
||||
setup() {
|
||||
this._setup(this.hasLocalExports);
|
||||
}
|
||||
|
||||
_init(conditional) {
|
||||
_setup(conditional) {
|
||||
var file = this.file;
|
||||
var scope = file.scope;
|
||||
|
||||
|
||||
@ -85,18 +85,28 @@ export function ExportNamedDeclaration(node, parent, scope) {
|
||||
}
|
||||
}
|
||||
|
||||
export function Program(node) {
|
||||
var imports = [];
|
||||
var rest = [];
|
||||
export var Program = {
|
||||
enter(node) {
|
||||
var imports = [];
|
||||
var rest = [];
|
||||
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isImportDeclaration(bodyNode)) {
|
||||
imports.push(bodyNode);
|
||||
} else {
|
||||
rest.push(bodyNode);
|
||||
for (var i = 0; i < node.body.length; i++) {
|
||||
var bodyNode = node.body[i];
|
||||
if (t.isImportDeclaration(bodyNode)) {
|
||||
imports.push(bodyNode);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
export function module() {
|
||||
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.module = _module;
|
||||
|
||||
function _module() {}
|
||||
Loading…
x
Reference in New Issue
Block a user