2018-11-28 06:24:08 +03:00
|
|
|
use super::*;
|
|
|
|
|
2019-02-14 11:46:22 +03:00
|
|
|
test!(
|
|
|
|
::swc_ecma_parser::Syntax::default(),
|
|
|
|
|_| ComputedProps,
|
|
|
|
issue_210,
|
|
|
|
"
|
|
|
|
const b = {[a]: 1}
|
|
|
|
export const c = {[a]: 1}
|
|
|
|
",
|
|
|
|
"const b = _defineProperty({
|
|
|
|
}, a, 1);
|
|
|
|
export const c = _defineProperty({
|
|
|
|
}, a, 1);"
|
|
|
|
);
|
|
|
|
|
2018-11-28 06:24:08 +03:00
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
accessors,
|
|
|
|
r#"var obj = {
|
|
|
|
get [foobar]() {
|
|
|
|
return "foobar";
|
|
|
|
},
|
|
|
|
set [foobar](x) {
|
|
|
|
console.log(x);
|
|
|
|
},
|
|
|
|
get test() {
|
|
|
|
return "regular getter after computed property";
|
|
|
|
},
|
|
|
|
set "test"(x) {
|
|
|
|
console.log(x);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
"#,
|
|
|
|
r#"var _obj, _mutatorMap = {
|
|
|
|
};
|
|
|
|
var obj = ( _obj = {
|
|
|
|
}, _mutatorMap[foobar] = _mutatorMap[foobar] || {
|
|
|
|
}, _mutatorMap[foobar].get = function() {
|
|
|
|
return 'foobar';
|
|
|
|
}, _mutatorMap[foobar] = _mutatorMap[foobar] || {
|
|
|
|
}, _mutatorMap[foobar].set = function(x) {
|
|
|
|
console.log(x);
|
|
|
|
}, _mutatorMap['test'] = _mutatorMap['test'] || {
|
|
|
|
}, _mutatorMap['test'].get = function() {
|
|
|
|
return 'regular getter after computed property';
|
|
|
|
}, _mutatorMap['test'] = _mutatorMap['test'] || {
|
|
|
|
}, _mutatorMap['test'].set = function(x) {
|
|
|
|
console.log(x);
|
|
|
|
}, _defineEnumerableProperties(_obj, _mutatorMap), _obj);"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
argument,
|
|
|
|
r#"foo({
|
|
|
|
[bar]: "foobar"
|
|
|
|
});"#,
|
|
|
|
r#"foo(_defineProperty({}, bar, "foobar"));
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
assignment,
|
|
|
|
r#"foo = {
|
|
|
|
[bar]: "foobar"
|
|
|
|
};"#,
|
|
|
|
r#"foo = _defineProperty({}, bar, "foobar");"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
method,
|
|
|
|
r#"var obj = {
|
|
|
|
[foobar]() {
|
|
|
|
return "foobar";
|
|
|
|
},
|
|
|
|
test() {
|
|
|
|
return "regular method after computed property";
|
|
|
|
}
|
|
|
|
};"#,
|
|
|
|
r#"var _obj;
|
|
|
|
|
|
|
|
var obj = (_obj = {}, _defineProperty(_obj, foobar, function () {
|
|
|
|
return "foobar";
|
|
|
|
}), _defineProperty(_obj, "test", function () {
|
|
|
|
return "regular method after computed property";
|
|
|
|
}), _obj);"#
|
|
|
|
);
|
|
|
|
|
2019-01-08 10:34:35 +03:00
|
|
|
test!(::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
mixed,
|
|
|
|
r#"var obj = {
|
|
|
|
["x" + foo]: "heh",
|
|
|
|
["y" + bar]: "noo",
|
|
|
|
foo: "foo",
|
|
|
|
bar: "bar"
|
|
|
|
};"#,
|
|
|
|
r#"var _obj;
|
|
|
|
|
|
|
|
var obj = (_obj = {}, _defineProperty(_obj, "x" + foo, "heh"), _defineProperty(_obj,
|
|
|
|
"y" + bar, "noo"), _defineProperty(_obj, "foo", "foo"), _defineProperty(_obj, "bar", "bar"), _obj);"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
multiple,
|
|
|
|
r#"var obj = {
|
|
|
|
["x" + foo]: "heh",
|
|
|
|
["y" + bar]: "noo"
|
|
|
|
};"#,
|
|
|
|
r#"var _obj;
|
|
|
|
|
|
|
|
var obj = (_obj = {}, _defineProperty(_obj, "x" + foo, "heh"),
|
|
|
|
_defineProperty(_obj, "y" + bar, "noo"), _obj);"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
single,
|
|
|
|
r#"var obj = {
|
|
|
|
["x" + foo]: "heh"
|
|
|
|
};"#,
|
|
|
|
r#"var obj = _defineProperty({}, "x" + foo, "heh");"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
symbol,
|
|
|
|
r#"var k = Symbol();
|
|
|
|
var foo = {
|
|
|
|
[Symbol.iterator]: "foobar",
|
|
|
|
get [k]() {
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
"#,
|
|
|
|
r#"var k = Symbol();
|
|
|
|
var _obj, _mutatorMap = {
|
|
|
|
};
|
|
|
|
var foo = ( _obj = {
|
|
|
|
}, _defineProperty(_obj, Symbol.iterator, 'foobar'), _mutatorMap[k] = _mutatorMap[k] || {
|
|
|
|
}, _mutatorMap[k].get = function() {
|
|
|
|
return k;
|
|
|
|
}, _defineEnumerableProperties(_obj, _mutatorMap), _obj);"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test_exec!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
symbol_exec,
|
|
|
|
r#"
|
|
|
|
var k = Symbol();
|
|
|
|
var foo = {
|
|
|
|
[Symbol.iterator]: "foobar",
|
|
|
|
get [k]() {
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(foo[Symbol.iterator]).toBe("foobar")
|
|
|
|
expect(foo[k]).toBe(k)"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
this,
|
|
|
|
r#"var obj = {
|
|
|
|
["x" + foo.bar]: "heh"
|
|
|
|
};"#,
|
|
|
|
r#"var obj = _defineProperty({}, "x" + foo.bar, "heh");"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
two,
|
|
|
|
r#"var obj = {
|
|
|
|
first: "first",
|
|
|
|
["second"]: "second",
|
|
|
|
};"#,
|
|
|
|
r#"var _obj;
|
|
|
|
var obj = ( _obj = {
|
|
|
|
}, _defineProperty(_obj, 'first', 'first'), _defineProperty(_obj, 'second', 'second'), _obj);"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-02-05 08:15:38 +03:00
|
|
|
|_| ComputedProps,
|
2018-11-28 06:24:08 +03:00
|
|
|
variable,
|
|
|
|
r#"var foo = {
|
|
|
|
[bar]: "foobar"
|
|
|
|
};"#,
|
|
|
|
r#"var foo = _defineProperty({}, bar, "foobar");"#
|
|
|
|
);
|