fix(es/compat): Fix computed_properties (#3120)

swc_ecma_transforms_compat:
 - `computed_properties`: Fix handling of getter/setter properties. (Closes #2680)
This commit is contained in:
magic-akari 2021-12-28 16:07:30 +08:00 committed by GitHub
parent 61cd7da265
commit 27d3fd93b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 285 additions and 171 deletions

View File

@ -11,10 +11,10 @@ function _defineProperty(obj, key, value) {
}
return obj;
}
var _obj;
function f() {
var t;
var k;
var _obj;
var v = (_obj = {
}, _defineProperty(_obj, t, 0), _defineProperty(_obj, k, 1), _obj);
}

View File

@ -11,11 +11,11 @@ function _defineProperty(obj, key, value) {
}
return obj;
}
var _obj;
// @target: es6
function f() {
var t;
var k;
var _obj;
var v = (_obj = {
}, _defineProperty(_obj, t, 0), _defineProperty(_obj, k, 1), _obj);
}

View File

@ -11,11 +11,11 @@ function _defineProperty(obj, key, value) {
}
return obj;
}
var _obj;
// @target: es5
function f() {
var t;
var u;
var _obj;
var v = (_obj = {
}, _defineProperty(_obj, t, 0), _defineProperty(_obj, u, 1), _obj);
}

View File

@ -11,11 +11,11 @@ function _defineProperty(obj, key, value) {
}
return obj;
}
var _obj;
// @target: es6
function f() {
var t;
var u;
var _obj;
var v = (_obj = {
}, _defineProperty(_obj, t, 0), _defineProperty(_obj, u, 1), _obj);
}

View File

@ -14,8 +14,8 @@ function _defineProperty(obj, key, value) {
// @target: es5,esnext
var a = "a";
var b = "b";
var _obj;
var ref = function() {
var _obj;
return _obj = {
}, _defineProperty(_obj, a, 1), _defineProperty(_obj, b, 1), _obj;
}(), aVal = ref[a], bVal = ref[b];

View File

@ -6,6 +6,9 @@ function _defineProperty(obj, key, value) {
writable: !0
}) : obj[key] = value, obj;
}
var _obj, ref = (_defineProperty(_obj = {
}, "a", 1), _defineProperty(_obj, "b", 1), _obj), aVal = ref.a, bVal = ref.b;
var ref = function() {
var _obj;
return _defineProperty(_obj = {
}, "a", 1), _defineProperty(_obj, "b", 1), _obj;
}(), aVal = ref.a, bVal = ref.b;
console.log(aVal, bVal);

View File

@ -18,8 +18,8 @@ K;
K["b"] = "b";
})(K || (K = {
}));
var _obj;
var ref = function() {
var _obj;
return _obj = {
}, _defineProperty(_obj, K.a, 1), _defineProperty(_obj, K.b, 1), _obj;
}(), aVal = ref[K.a], bVal = ref[K.b];

View File

@ -8,6 +8,9 @@ function _defineProperty(obj, key, value) {
}
(K = K || (K = {
})).a = "a", K.b = "b";
var K, K, _obj, ref = (_defineProperty(_obj = {
}, K.a, 1), _defineProperty(_obj, K.b, 1), _obj), aVal = ref[K.a], bVal = ref[K.b];
var K, K, ref = function() {
var _obj;
return _defineProperty(_obj = {
}, K.a, 1), _defineProperty(_obj, K.b, 1), _obj;
}(), aVal = ref[K.a], bVal = ref[K.b];
console.log(aVal, bVal);

View File

@ -16,8 +16,8 @@ var K = {
a: "a",
b: "b"
};
var _obj;
var ref = function() {
var _obj;
return _obj = {
}, _defineProperty(_obj, K.a, 1), _defineProperty(_obj, K.b, 1), _obj;
}(), aVal = ref[K.a], bVal = ref[K.b];

View File

@ -6,9 +6,12 @@ function _defineProperty(obj, key, value) {
writable: !0
}) : obj[key] = value, obj;
}
var _obj, K = {
var K = {
a: "a",
b: "b"
}, ref = (_defineProperty(_obj = {
}, K.a, 1), _defineProperty(_obj, K.b, 1), _obj), aVal = ref[K.a], bVal = ref[K.b];
}, ref = function() {
var _obj;
return _defineProperty(_obj = {
}, K.a, 1), _defineProperty(_obj, K.b, 1), _obj;
}(), aVal = ref[K.a], bVal = ref[K.b];
console.log(aVal, bVal);

View File

@ -19,43 +19,43 @@ function _defineEnumerableProperties(obj, descs) {
return obj;
}
var _marked = regeneratorRuntime.mark(g);
var _obj, _mutatorMap = {
};
//@target: ES6
function g() {
var x;
var _obj, _mutatorMap, x;
return regeneratorRuntime.wrap(function g$(_ctx) {
while(1)switch(_ctx.prev = _ctx.next){
case 0:
({
});
_ctx.next = 3;
_mutatorMap = {
};
_obj = {
};
_ctx.next = 4;
return 0;
case 3:
case 4:
_ctx.t0 = _ctx.sent;
_ctx.next = 6;
_ctx.next = 7;
return 0;
case 6:
case 7:
_ctx.t2 = _ctx.sent;
_ctx.t1 = _mutatorMap[_ctx.t2];
if (_ctx.t1) {
_ctx.next = 10;
_ctx.next = 11;
break;
}
_ctx.t1 = {
};
case 10:
case 11:
_mutatorMap[_ctx.t0] = _ctx.t1;
_ctx.next = 13;
_ctx.next = 14;
return 0;
case 13:
case 14:
_ctx.t3 = _ctx.sent;
_mutatorMap[_ctx.t3].get = function() {
return 0;
};
_defineEnumerableProperties(_obj, _mutatorMap);
x = (0, _obj);
case 17:
case 18:
case "end":
return _ctx.stop();
}

View File

@ -10,31 +10,32 @@ function _defineEnumerableProperties(obj, descs) {
}
return obj;
}
var _obj, _marked = regeneratorRuntime.mark(function() {
var x;
var _marked = regeneratorRuntime.mark(function() {
var _obj, _mutatorMap, x;
return regeneratorRuntime.wrap(function(_ctx) {
for(;;)switch(_ctx.prev = _ctx.next){
case 0:
return _ctx.next = 3, 0;
case 3:
return _ctx.t0 = _ctx.sent, _ctx.next = 6, 0;
case 6:
return _mutatorMap = {
}, _obj = {
}, _ctx.next = 4, 0;
case 4:
return _ctx.t0 = _ctx.sent, _ctx.next = 7, 0;
case 7:
if (_ctx.t2 = _ctx.sent, _ctx.t1 = _mutatorMap[_ctx.t2], _ctx.t1) {
_ctx.next = 10;
_ctx.next = 11;
break;
}
_ctx.t1 = {
};
case 10:
return _mutatorMap[_ctx.t0] = _ctx.t1, _ctx.next = 13, 0;
case 13:
case 11:
return _mutatorMap[_ctx.t0] = _ctx.t1, _ctx.next = 14, 0;
case 14:
_ctx.t3 = _ctx.sent, _mutatorMap[_ctx.t3].get = function() {
return 0;
}, _defineEnumerableProperties(_obj, _mutatorMap), x = _obj;
case 17:
case 18:
case "end":
return _ctx.stop();
}
}, _marked);
}), _mutatorMap = {
};
});

View File

@ -20,7 +20,7 @@ function _defineEnumerableProperties(obj, descs) {
var _obj, _mutatorMap = {
};
//@target: ES6
var v = ({
var v = (_obj = {
}, _mutatorMap[e] = _mutatorMap[e] || {
}, _mutatorMap[e].set = function(v) {
}, _defineEnumerableProperties(_obj, _mutatorMap), _obj);

View File

@ -1,6 +1,7 @@
var _obj, _mutatorMap = {
};
_mutatorMap[e] = _mutatorMap[e] || {
_obj = {
}, _mutatorMap[e] = _mutatorMap[e] || {
}, _mutatorMap[e].set = function(v) {
}, (function(obj, descs) {
for(var key in descs){

View File

@ -20,7 +20,7 @@ function _defineEnumerableProperties(obj, descs) {
var _obj, _mutatorMap = {
};
//@target: ES6
var v = ({
var v = (_obj = {
}, _mutatorMap[e] = _mutatorMap[e] || {
}, _mutatorMap[e].get = function() {
}, _defineEnumerableProperties(_obj, _mutatorMap), _obj);

View File

@ -1,6 +1,7 @@
var _obj, _mutatorMap = {
};
_mutatorMap[e] = _mutatorMap[e] || {
_obj = {
}, _mutatorMap[e] = _mutatorMap[e] || {
}, _mutatorMap[e].get = function() {
}, (function(obj, descs) {
for(var key in descs){

View File

@ -20,7 +20,7 @@ function _defineEnumerableProperties(obj, descs) {
var _obj, _mutatorMap = {
};
//@target: ES5
var v = ({
var v = (_obj = {
}, _mutatorMap[e] = _mutatorMap[e] || {
}, _mutatorMap[e].get = function() {
}, _defineEnumerableProperties(_obj, _mutatorMap), _obj);

View File

@ -1,6 +1,7 @@
var _obj, _mutatorMap = {
};
_mutatorMap[e] = _mutatorMap[e] || {
_obj = {
}, _mutatorMap[e] = _mutatorMap[e] || {
}, _mutatorMap[e].get = function() {
}, (function(obj, descs) {
for(var key in descs){

View File

@ -8,49 +8,49 @@ import g from "./version";
function h(a) {
"function" == typeof a.addAlgoliaAgent && (a.addAlgoliaAgent("react (".concat(f, ")")), a.addAlgoliaAgent("react-instantsearch (".concat(g, ")")));
}
var i, j = function(a) {
var i = function(a) {
return e({
ais: a.props.contextValue,
multiIndexContext: a.props.indexContextValue
});
}, k = function(a, b) {
}, j = function(a, b) {
return a.props.indexContextValue.targetedIndex === b;
}, l = function(a) {
}, k = function(a) {
return Boolean(a.props.indexId);
}, m = function(a, b) {
}, l = function(a, b) {
return a.props.indexId === b;
}, n = function(a, b) {
var c = l(a), d = l(b);
}, m = function(a, b) {
var c = k(a), d = k(b);
return c && !d ? -1 : !c && d ? 1 : 0;
};
export default function e(f) {
var g = f.indexName, p = f.initialState, q = f.searchClient, r = f.resultsState, s = f.stalledSearchDelay, t = function(a) {
return E.getWidgets().filter(function(a) {
var g = f.indexName, o = f.initialState, p = f.searchClient, q = f.resultsState, r = f.stalledSearchDelay, s = function(a) {
return D.getWidgets().filter(function(a) {
return Boolean(a.getMetadata);
}).map(function(b) {
return b.getMetadata(a);
});
}, u = function() {
var b = E.getWidgets().filter(function(a) {
}, t = function() {
var b = D.getWidgets().filter(function(a) {
return Boolean(a.getSearchParameters);
}).filter(function(a) {
return !j(a) && !l(a);
return !i(a) && !k(a);
}).reduce(function(a, b) {
return b.getSearchParameters(a);
}, D), c = E.getWidgets().filter(function(a) {
}, C), c = D.getWidgets().filter(function(a) {
return Boolean(a.getSearchParameters);
}).filter(function(a) {
var b = j(a) && k(a, g), c = l(a) && m(a, g);
var b = i(a) && j(a, g), c = k(a) && l(a, g);
return b || c;
}).sort(n).reduce(function(a, b) {
}).sort(m).reduce(function(a, b) {
return b.getSearchParameters(a);
}, b), d = E.getWidgets().filter(function(a) {
}, b), d = D.getWidgets().filter(function(a) {
return Boolean(a.getSearchParameters);
}).filter(function(a) {
var b = j(a) && !k(a, g), c = l(a) && !m(a, g);
var b = i(a) && !j(a, g), c = k(a) && !l(a, g);
return b || c;
}).sort(n).reduce(function(b, c) {
var d = j(c) ? c.props.indexContextValue.targetedIndex : c.props.indexId, e = b[d] || [];
}).sort(m).reduce(function(b, c) {
var d = i(c) ? c.props.indexContextValue.targetedIndex : c.props.indexId, e = b[d] || [];
return a.objectSpread({
}, b, a.defineProperty({
}, d, e.concat(c)));
@ -67,35 +67,35 @@ export default function e(f) {
mainParameters: c,
derivedParameters: e
};
}, v = function() {
if (!B) {
var a = u(A.state), b = a.mainParameters, c = a.derivedParameters;
A.derivedHelpers.slice().forEach(function(a) {
}, u = function() {
if (!A) {
var a = t(z.state), b = a.mainParameters, c = a.derivedParameters;
z.derivedHelpers.slice().forEach(function(a) {
a.detach();
}), c.forEach(function(a) {
var b = a.indexId, c = a.parameters, d = A.derive(function() {
var b = a.indexId, c = a.parameters, d = z.derive(function() {
return c;
});
d.on("result", w({
d.on("result", v({
indexId: b
})).on("error", x);
}), A.setState(b), A.search();
})).on("error", w);
}), z.setState(b), z.search();
}
}, w = function(b) {
}, v = function(b) {
var c = b.indexId;
return function(b) {
var d = I.getState(), e = !A.derivedHelpers.length, f = d.results ? d.results : {
var d = H.getState(), e = !z.derivedHelpers.length, f = d.results ? d.results : {
};
f = !e && f.getFacetByName ? {
} : f, f = e ? b.results : a.objectSpread({
}, f, a.defineProperty({
}, c, b.results));
var g = I.getState(), h = g.isSearchStalled;
A.hasPendingRequests() || (clearTimeout(C), C = null, h = !1), g.resultsFacetValues;
var g = H.getState(), h = g.isSearchStalled;
z.hasPendingRequests() || (clearTimeout(B), B = null, h = !1), g.resultsFacetValues;
var i = a.objectWithoutProperties(g, [
"resultsFacetValues"
]);
I.setState(a.objectSpread({
H.setState(a.objectSpread({
}, i, {
results: f,
isSearchStalled: h,
@ -103,19 +103,19 @@ export default function e(f) {
error: null
}));
};
}, x = function(b) {
var c = b.error, d = I.getState(), e = d.isSearchStalled;
A.hasPendingRequests() || (clearTimeout(C), e = !1), d.resultsFacetValues;
}, w = function(b) {
var c = b.error, d = H.getState(), e = d.isSearchStalled;
z.hasPendingRequests() || (clearTimeout(B), e = !1), d.resultsFacetValues;
var f = a.objectWithoutProperties(d, [
"resultsFacetValues"
]);
I.setState(a.objectSpread({
H.setState(a.objectSpread({
}, f, {
isSearchStalled: e,
error: c,
searching: !1
}));
}, y = function(b, c) {
}, x = function(b, c) {
if (b.transporter) {
b.transporter.responsesCache.set({
method: "search",
@ -153,7 +153,7 @@ export default function e(f) {
return a.concat(b.rawResults);
}, [])
})));
}, z = function(b, c) {
}, y = function(b, c) {
if (b.transporter) {
b.transporter.responsesCache.set({
method: "search",
@ -183,28 +183,28 @@ export default function e(f) {
}, d, JSON.stringify({
results: c.rawResults
})));
}, A = b(q, g, a.objectSpread({
}, z = b(p, g, a.objectSpread({
}, d));
h(q), A.on("search", function() {
C || (C = setTimeout(function() {
var b = I.getState(), c = b.resultsFacetValues, d = a.objectWithoutProperties(b, [
h(p), z.on("search", function() {
B || (B = setTimeout(function() {
var b = H.getState(), c = b.resultsFacetValues, d = a.objectWithoutProperties(b, [
"resultsFacetValues"
]);
I.setState(a.objectSpread({
H.setState(a.objectSpread({
}, d, {
isSearchStalled: !0
}));
}, s));
}).on("result", w({
}, r));
}).on("result", v({
indexId: g
})).on("error", x);
var B = !1, C = null, D = A.state, E = c(function() {
var b = t(I.getState().widgets);
I.setState(a.objectSpread({
}, I.getState(), {
})).on("error", w);
var A = !1, B = null, C = z.state, D = c(function() {
var b = s(H.getState().widgets);
H.setState(a.objectSpread({
}, H.getState(), {
metadata: b,
searching: !0
})), v();
})), u();
});
!function(b, c) {
if (c && (b.transporter && !b._cacheHydrated || b._useCache && "function" == typeof b.addAlgoliaAgent)) {
@ -244,67 +244,68 @@ export default function e(f) {
};
}
if (Array.isArray(c.results)) {
y(b, c.results);
x(b, c.results);
return;
}
z(b, c);
y(b, c);
}
}(q, r);
var F, G, H, I = (G = {
widgets: void 0 === p ? {
} : p,
metadata: o(r),
results: (F = r) ? Array.isArray(F.results) ? F.results.reduce(function(c, d) {
}(p, q);
var E, F, G, H = (F = {
widgets: void 0 === o ? {
} : o,
metadata: n(q),
results: (E = q) ? Array.isArray(E.results) ? E.results.reduce(function(c, d) {
return a.objectSpread({
}, c, a.defineProperty({
}, d._internalIndexId, new b.SearchResults(new b.SearchParameters(d.state), d.rawResults)));
}, {
}) : new b.SearchResults(new b.SearchParameters(F.state), F.rawResults) : null,
}) : new b.SearchResults(new b.SearchParameters(E.state), E.rawResults) : null,
error: null,
searching: !1,
isSearchStalled: !0,
searchingForFacetValues: !1
}, H = [], {
}, G = [], {
getState: function() {
return G;
return F;
},
setState: function(a) {
G = a, H.forEach(function(a) {
F = a, G.forEach(function(a) {
return a();
});
},
subscribe: function(a) {
return H.push(a), function() {
H.splice(H.indexOf(a), 1);
return G.push(a), function() {
G.splice(G.indexOf(a), 1);
};
}
});
return {
store: I,
widgetsManager: E,
store: H,
widgetsManager: D,
getWidgetsIds: function() {
return I.getState().metadata.reduce(function(a, b) {
return H.getState().metadata.reduce(function(a, b) {
return void 0 !== b.id ? a.concat(b.id) : a;
}, []);
},
getSearchParameters: u,
getSearchParameters: t,
onSearchForFacetValues: function(b) {
var c = b.facetName, d = b.query, e = b.maxFacetHits;
I.setState(a.objectSpread({
}, I.getState(), {
H.setState(a.objectSpread({
}, H.getState(), {
searchingForFacetValues: !0
})), A.searchForFacetValues(c, d, Math.max(1, Math.min(void 0 === e ? 10 : e, 100))).then(function(b) {
I.setState(a.objectSpread({
}, I.getState(), {
})), z.searchForFacetValues(c, d, Math.max(1, Math.min(void 0 === e ? 10 : e, 100))).then(function(b) {
var e;
H.setState(a.objectSpread({
}, H.getState(), {
error: null,
searchingForFacetValues: !1,
resultsFacetValues: a.objectSpread({
}, I.getState().resultsFacetValues, (i = {
}, a.defineProperty(i, c, b.facetHits), a.defineProperty(i, "query", d), i))
}, H.getState().resultsFacetValues, (e = {
}, a.defineProperty(e, c, b.facetHits), a.defineProperty(e, "query", d), e))
}));
}, function(b) {
I.setState(a.objectSpread({
}, I.getState(), {
H.setState(a.objectSpread({
}, H.getState(), {
searchingForFacetValues: !1,
error: b
}));
@ -315,37 +316,37 @@ export default function e(f) {
});
},
onExternalStateUpdate: function(b) {
var c = t(b);
I.setState(a.objectSpread({
}, I.getState(), {
var c = s(b);
H.setState(a.objectSpread({
}, H.getState(), {
widgets: b,
metadata: c,
searching: !0
})), v();
})), u();
},
transitionState: function(a) {
var b = I.getState().widgets;
return E.getWidgets().filter(function(a) {
var b = H.getState().widgets;
return D.getWidgets().filter(function(a) {
return Boolean(a.transitionState);
}).reduce(function(a, c) {
return c.transitionState(b, a);
}, a);
},
updateClient: function(a) {
h(a), A.setClient(a), v();
h(a), z.setClient(a), u();
},
updateIndex: function(a) {
D = D.setIndex(a);
C = C.setIndex(a);
},
clearCache: function() {
A.clearCache(), v();
z.clearCache(), u();
},
skipSearch: function() {
B = !0;
A = !0;
}
};
};
function o(b) {
function n(b) {
return b ? b.metadata.map(function(b) {
return a.objectSpread({
value: function() {

View File

@ -59,7 +59,6 @@ function serializeQueryParameters(parameters) {
return encode('%s=%s', key, isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]);
}).join('&');
}
var _obj;
/**
* Creates a new instance of the InstantSearchManager which controls the widgets and
* trigger the search when the widgets are updated.
@ -454,6 +453,7 @@ var _obj;
searchingForFacetValues: true
}));
helper.searchForFacetValues(facetName, query, maxFacetHitsWithinRange).then(function(content) {
var _obj;
store.setState(swcHelpers.objectSpread({
}, store.getState(), {
error: null,

View File

@ -39,7 +39,10 @@ use swc_ecma_visit::{
/// TODO(kdy1): cache reference like (_f = f, mutatorMap[_f].get = function(){})
/// instead of (mutatorMap[f].get = function(){}
pub fn computed_properties(c: Config) -> impl Fold {
as_folder(ComputedProps { c })
as_folder(ComputedProps {
c,
..Default::default()
})
}
#[derive(Debug, Clone, Copy, Default, Deserialize)]
@ -49,20 +52,24 @@ pub struct Config {
pub loose: bool,
}
struct ComputedProps {
c: Config,
}
#[derive(Default)]
struct ObjectLitFolder {
struct ComputedProps {
vars: Vec<VarDeclarator>,
used_define_enum_props: bool,
c: Config,
}
impl VisitMut for ObjectLitFolder {
impl VisitMut for ComputedProps {
noop_visit_mut_type!();
fn visit_mut_module_items(&mut self, n: &mut Vec<ModuleItem>) {
self.visit_mut_stmt_like(n);
}
fn visit_mut_stmts(&mut self, n: &mut Vec<Stmt>) {
self.visit_mut_stmt_like(n);
}
fn visit_mut_expr(&mut self, expr: &mut Expr) {
expr.visit_mut_children_with(self);
@ -87,22 +94,29 @@ impl VisitMut for ObjectLitFolder {
let props_cnt = props.len();
exprs.push(if !self.c.loose && props_cnt == 1 {
Box::new(Expr::Object(ObjectLit {
span: DUMMY_SP,
props: obj_props,
}))
} else {
Box::new(Expr::Assign(AssignExpr {
span: DUMMY_SP,
left: PatOrExpr::Pat(Box::new(Pat::Ident(obj_ident.clone().into()))),
op: op!("="),
right: Box::new(Expr::Object(ObjectLit {
self.used_define_enum_props = props.iter().any(|pp| match *pp {
PropOrSpread::Prop(ref p) if p.is_getter() || p.is_setter() => true,
_ => false,
});
exprs.push(
if !self.c.loose && props_cnt == 1 && !self.used_define_enum_props {
Box::new(Expr::Object(ObjectLit {
span: DUMMY_SP,
props: obj_props,
})),
}))
});
}))
} else {
Box::new(Expr::Assign(AssignExpr {
span: DUMMY_SP,
left: PatOrExpr::Pat(Box::new(Pat::Ident(obj_ident.clone().into()))),
op: op!("="),
right: Box::new(Expr::Object(ObjectLit {
span: DUMMY_SP,
props: obj_props,
})),
}))
},
);
let mut single_cnt_prop = None;
@ -330,22 +344,10 @@ impl Visit for ComplexVisitor {
}
}
impl VisitMut for ComputedProps {
noop_visit_mut_type!();
fn visit_mut_module_items(&mut self, n: &mut Vec<ModuleItem>) {
self.visit_mut_stmt_like(n);
}
fn visit_mut_stmts(&mut self, n: &mut Vec<Stmt>) {
self.visit_mut_stmt_like(n);
}
}
impl ComputedProps {
fn visit_mut_stmt_like<T>(&mut self, stmts: &mut Vec<T>)
where
T: StmtLike + VisitWith<ShouldWork> + VisitMutWith<Self> + VisitMutWith<ObjectLitFolder>,
T: StmtLike + VisitWith<ShouldWork> + VisitMutWith<Self>,
Vec<T>: VisitWith<ShouldWork>,
{
let mut stmts_updated = Vec::with_capacity(stmts.len());
@ -356,7 +358,7 @@ impl ComputedProps {
continue;
}
let mut folder = ObjectLitFolder {
let mut folder = Self {
c: self.c,
..Default::default()
};

View File

@ -75,6 +75,104 @@ var obj = ( _obj = {
}, _defineEnumerableProperties(_obj, _mutatorMap), _obj);"#
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(()),
issue_2680,
r#"
const obj = {
get [1]() {}
};
"#,
"
var _obj, _mutatorMap = {};
const obj = (
_obj = {},
_mutatorMap[1] = _mutatorMap[1] || {},
_mutatorMap[1].get = function() {},
_defineEnumerableProperties(_obj, _mutatorMap),
_obj
);
"
);
test_exec!(
::swc_ecma_parser::Syntax::default(),
|_| tr(()),
issue_2680_2,
r#"
let a = "outside";
const obj = {
get [{
get [a]() {
let a = "inside";
return a;
},
}.outside]() {
let a = "middle";
return a;
},
};
expect(obj.inside).toBe("middle");
"#
);
test_exec!(
::swc_ecma_parser::Syntax::default(),
|_| tr(()),
issue_2680_3,
r#"
const obj = {
foo() {
const obj2 = {
get [1]() {
return 42;
},
};
return obj2;
},
};
expect(obj.foo()[1]).toBe(42);
"#
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(()),
issue_2680_4,
r#"
const obj = {
foo() {
const obj2 = {
get [1]() {
return 42;
},
};
return obj2;
},
};
"#,
"
const obj = {
foo() {
var _obj, _mutatorMap = {};
const obj2 = (
_obj = {},
_mutatorMap[1] = _mutatorMap[1] || {},
_mutatorMap[1].get = function () {
return 42;
},
_defineEnumerableProperties(_obj, _mutatorMap),
_obj
);
return obj2;
},
};
"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| computed_properties(Default::default()),