"use strict";

const terser = require('terser');

test('normal object', () => {
  const code = `
    const student = {
    name: 'Sheldon',
    score: 100,
    grade: 'A',
    }
    console.log(student)
    delete student.score
    student.grade = 'F'
    console.log(student)
    student = {}
    `;
  return terser.minify(code).then(minify => {
    expect(minify.code).toBe('const student={name:"Sheldon",score:100,grade:"A"};console.log(student),delete student.score,student.grade="F",console.log(student),student={};');
  });
});
test('Assignment shorthand syntax takes extra space', () => {
  const code = `
    const person = {
    name: 'Tom',
    age: '22',
    };
    const {name, age} = person;
    console.log(name); // 'Tom'
    console.log(age);  // '22'
    `;
  return terser.minify(code).then(minify => {
    expect(minify.code).toBe('const person={name:"Tom",age:"22"},{name:name,age:age}=person;console.log(name),console.log(age);');
  });
});
test('minimize the name of parameter inside the class object', () => {
  const code = `
    class Dog {
    constructor(name) {
        this._name = name;
    }
    introduce() {
        console.log('This is ' + this._name + ' !');
    }
    static bark() {
        console.log('Woof!');
    }
    }
    const myDog = new Dog('Buster');
    myDog.introduce();
    Dog.bark();
    `;
  return terser.minify(code).then(minify => {
    expect(minify.code).toBe('class Dog{constructor(o){this._name=o}introduce(){console.log("This is "+this._name+" !")}static bark(){console.log("Woof!")}}const myDog=new Dog("Buster");myDog.introduce(),Dog.bark();');
  });
});