fix export name mapping syntax
This commit is contained in:
parent
0f80bc42d0
commit
6b7a9d33a2
|
|
@ -1297,16 +1297,25 @@ function OutputStream(options) {
|
||||||
});
|
});
|
||||||
|
|
||||||
DEFPRINT(AST_NameMapping, function(self, output) {
|
DEFPRINT(AST_NameMapping, function(self, output) {
|
||||||
|
var is_import = output.parent() instanceof AST_Import;
|
||||||
var definition = self.name.definition();
|
var definition = self.name.definition();
|
||||||
var names_are_different =
|
var names_are_different =
|
||||||
(definition && definition.mangled_name || self.name.name) !==
|
(definition && definition.mangled_name || self.name.name) !==
|
||||||
self.foreign_name.name;
|
self.foreign_name.name;
|
||||||
if (names_are_different) {
|
if (names_are_different) {
|
||||||
output.print(self.foreign_name.name);
|
if (is_import) {
|
||||||
|
output.print(self.foreign_name.name);
|
||||||
|
} else {
|
||||||
|
self.name.print(output);
|
||||||
|
}
|
||||||
output.space();
|
output.space();
|
||||||
output.print("as");
|
output.print("as");
|
||||||
output.space();
|
output.space();
|
||||||
self.name.print(output);
|
if (is_import) {
|
||||||
|
self.name.print(output);
|
||||||
|
} else {
|
||||||
|
output.print(self.foreign_name.name);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self.name.print(output);
|
self.name.print(output);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
lib/parse.js
24
lib/parse.js
|
|
@ -2333,18 +2333,22 @@ function parse($TEXT, options) {
|
||||||
var foreign_name;
|
var foreign_name;
|
||||||
var name;
|
var name;
|
||||||
|
|
||||||
if (peek().value === "as" && peek().type === "name") {
|
if (is_import) {
|
||||||
foreign_name = as_symbol(foreign_type);
|
foreign_name = as_symbol(foreign_type);
|
||||||
next(); // The "as" word
|
} else {
|
||||||
|
name = as_symbol(type);
|
||||||
}
|
}
|
||||||
name = as_symbol(type);
|
if (is("name", "as")) {
|
||||||
|
next(); // The "as" word
|
||||||
if (foreign_name === undefined) {
|
if (is_import) {
|
||||||
foreign_name = new foreign_type({
|
name = as_symbol(type);
|
||||||
name: name.name,
|
} else {
|
||||||
start: name.start,
|
foreign_name = as_symbol(foreign_type);
|
||||||
end: name.end,
|
}
|
||||||
});
|
} else if (is_import) {
|
||||||
|
name = new type(foreign_name);
|
||||||
|
} else {
|
||||||
|
foreign_name = new foreign_type(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new AST_NameMapping({
|
return new AST_NameMapping({
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ issue_2038_2: {
|
||||||
let a = 1;
|
let a = 1;
|
||||||
const c = 2;
|
const c = 2;
|
||||||
var n = 3;
|
var n = 3;
|
||||||
export { LET as a, CONST as c, VAR as n };
|
export { a as LET, c as CONST, n as VAR };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,3 +67,21 @@ issue_2124: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_2126: {
|
||||||
|
mangle = {
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
import { foo as bar, cat as dog } from "stuff";
|
||||||
|
console.log(bar, dog);
|
||||||
|
export { bar as qux };
|
||||||
|
export { dog };
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
import { foo as o, cat as f } from "stuff";
|
||||||
|
console.log(o, f);
|
||||||
|
export { o as qux };
|
||||||
|
export { f as dog };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,7 @@ var assert = require("assert");
|
||||||
var uglify = require("../node");
|
var uglify = require("../node");
|
||||||
|
|
||||||
describe("Export", function() {
|
describe("Export", function() {
|
||||||
it ("Should parse export directives", function() {
|
it("Should parse export directives", function() {
|
||||||
|
|
||||||
var inputs = [
|
var inputs = [
|
||||||
['export * from "a.js"', ['*'], "a.js"],
|
['export * from "a.js"', ['*'], "a.js"],
|
||||||
['export {A} from "a.js"', ['A'], "a.js"],
|
['export {A} from "a.js"', ['A'], "a.js"],
|
||||||
|
|
@ -12,17 +11,17 @@ describe("Export", function() {
|
||||||
['export {A, B} from "a.js"', ['A', 'B'], "a.js"],
|
['export {A, B} from "a.js"', ['A', 'B'], "a.js"],
|
||||||
];
|
];
|
||||||
|
|
||||||
var test = function(code) {
|
function test(code) {
|
||||||
return uglify.parse(code);
|
return uglify.parse(code);
|
||||||
};
|
}
|
||||||
|
|
||||||
var extractNames = function(symbols) {
|
function extractNames(symbols) {
|
||||||
var ret = [];
|
var ret = [];
|
||||||
for (var i = 0; i < symbols.length; i++) {
|
for (var i = 0; i < symbols.length; i++) {
|
||||||
ret.push(symbols[i].name.name)
|
ret.push(symbols[i].foreign_name.name);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
}
|
||||||
|
|
||||||
for (var i = 0; i < inputs.length; i++) {
|
for (var i = 0; i < inputs.length; i++) {
|
||||||
var ast = test(inputs[i][0]);
|
var ast = test(inputs[i][0]);
|
||||||
|
|
@ -34,7 +33,7 @@ describe("Export", function() {
|
||||||
assert(st instanceof uglify.AST_Export);
|
assert(st instanceof uglify.AST_Export);
|
||||||
var actualNames = extractNames(st.exported_names);
|
var actualNames = extractNames(st.exported_names);
|
||||||
assert.deepEqual(actualNames, names);
|
assert.deepEqual(actualNames, names);
|
||||||
assert.equal(st.module_name.value, filename)
|
assert.equal(st.module_name.value, filename);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user