support export statements properly (#2126)
- mangle & compress correctly with `toplevel`
- retain non-toplevel import/export
- parse & output `export { variable as name }`
- remove extraneous spaces from `beautify`
fixes #2038
fixes #2124
This commit is contained in:
97
test/compress/export.js
Normal file
97
test/compress/export.js
Normal file
@@ -0,0 +1,97 @@
|
||||
issue_2038_1: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
export var V = 1;
|
||||
export let L = 2;
|
||||
export const C = 3;
|
||||
}
|
||||
expect: {
|
||||
export var V = 1;
|
||||
export let L = 2;
|
||||
export const C = 3;
|
||||
}
|
||||
}
|
||||
|
||||
issue_2038_2: {
|
||||
options = {
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
mangle = {
|
||||
toplevel: true,
|
||||
}
|
||||
input: {
|
||||
let LET = 1;
|
||||
const CONST = 2;
|
||||
var VAR = 3;
|
||||
export { LET, CONST, VAR };
|
||||
}
|
||||
expect: {
|
||||
let a = 1;
|
||||
const c = 2;
|
||||
var n = 3;
|
||||
export { a as LET, c as CONST, n as VAR };
|
||||
}
|
||||
}
|
||||
|
||||
issue_2124: {
|
||||
options = {
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
{
|
||||
export var V = 1;
|
||||
}
|
||||
{
|
||||
export let L = 2;
|
||||
}
|
||||
{
|
||||
export const C = 3;
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
{
|
||||
export var V = 1;
|
||||
}
|
||||
{
|
||||
export let L = 2;
|
||||
}
|
||||
{
|
||||
export const C = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
||||
}
|
||||
|
||||
beautify: {
|
||||
beautify = {
|
||||
beautify: true,
|
||||
}
|
||||
input: {
|
||||
export { A as B, C as D };
|
||||
}
|
||||
expect_exact: "export { A as B, C as D };"
|
||||
}
|
||||
Reference in New Issue
Block a user