Skip to content

Commit

Permalink
copy tests to reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
boopathi committed Jan 31, 2017
1 parent 6b46809 commit eedcf45
Showing 1 changed file with 59 additions and 1 deletion.
Expand Up @@ -1132,21 +1132,79 @@ describe("mangle-names", () => {
expect(transformWithSimplify(source)).toBe(expected);
});

it("should work with object destructuring", () => {
it("should fix #326, #369 - destructuring", () => {
const source = unpad(`
// issue#326
function a() {
let foo, bar, baz;
({foo, bar, baz} = {});
return {foo, bar, baz};
}
// issue#369
function decodeMessage(message){
let namespace;
let name;
let value = null;
[, namespace, name, value] = message.split(',') || [];
console.log(name);
}
`);
const expected = unpad(`
// issue#326
function a() {
let a, b, c;
({ foo: a, bar: b, baz: c } = {});
return { foo: a, bar: b, baz: c };
}
// issue#369
function decodeMessage(a) {
let b;
let c;
let d = null;
[, b, c, d] = a.split(',') || [];
console.log(c);
}
`);
expect(transform(source)).toBe(expected);
});

it("should mangle topLevel when topLevel option is true", () => {
const source = unpad(`
function foo() {
if (FOO_ENV === "production") {
HELLO_WORLD.call();
}
}
const FOO_ENV = "production";
var HELLO_WORLD = function bar() {
new AbstractClass({
[FOO_ENV]: "foo",
a: foo(HELLO_WORLD)
});
};
class AbstractClass {}
foo();
`);

const expected = unpad(`
function a() {
if (b === "production") {
c.call();
}
}
const b = "production";
var c = function e() {
new d({
[b]: "foo",
a: a(c)
});
};
class d {}
a();
`);

expect(transform(source, { topLevel: true })).toBe(expected);
});
});

0 comments on commit eedcf45

Please sign in to comment.