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; return obj;
} }
var _obj;
function f() { function f() {
var t; var t;
var k; var k;
var _obj;
var v = (_obj = { var v = (_obj = {
}, _defineProperty(_obj, t, 0), _defineProperty(_obj, k, 1), _obj); }, _defineProperty(_obj, t, 0), _defineProperty(_obj, k, 1), _obj);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -39,7 +39,10 @@ use swc_ecma_visit::{
/// TODO(kdy1): cache reference like (_f = f, mutatorMap[_f].get = function(){}) /// TODO(kdy1): cache reference like (_f = f, mutatorMap[_f].get = function(){})
/// instead of (mutatorMap[f].get = function(){} /// instead of (mutatorMap[f].get = function(){}
pub fn computed_properties(c: Config) -> impl Fold { pub fn computed_properties(c: Config) -> impl Fold {
as_folder(ComputedProps { c }) as_folder(ComputedProps {
c,
..Default::default()
})
} }
#[derive(Debug, Clone, Copy, Default, Deserialize)] #[derive(Debug, Clone, Copy, Default, Deserialize)]
@ -49,20 +52,24 @@ pub struct Config {
pub loose: bool, pub loose: bool,
} }
struct ComputedProps {
c: Config,
}
#[derive(Default)] #[derive(Default)]
struct ObjectLitFolder { struct ComputedProps {
vars: Vec<VarDeclarator>, vars: Vec<VarDeclarator>,
used_define_enum_props: bool, used_define_enum_props: bool,
c: Config, c: Config,
} }
impl VisitMut for ObjectLitFolder { impl VisitMut for ComputedProps {
noop_visit_mut_type!(); 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) { fn visit_mut_expr(&mut self, expr: &mut Expr) {
expr.visit_mut_children_with(self); expr.visit_mut_children_with(self);
@ -87,7 +94,13 @@ impl VisitMut for ObjectLitFolder {
let props_cnt = props.len(); let props_cnt = props.len();
exprs.push(if !self.c.loose && props_cnt == 1 { 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 { Box::new(Expr::Object(ObjectLit {
span: DUMMY_SP, span: DUMMY_SP,
props: obj_props, props: obj_props,
@ -102,7 +115,8 @@ impl VisitMut for ObjectLitFolder {
props: obj_props, props: obj_props,
})), })),
})) }))
}); },
);
let mut single_cnt_prop = None; 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 { impl ComputedProps {
fn visit_mut_stmt_like<T>(&mut self, stmts: &mut Vec<T>) fn visit_mut_stmt_like<T>(&mut self, stmts: &mut Vec<T>)
where where
T: StmtLike + VisitWith<ShouldWork> + VisitMutWith<Self> + VisitMutWith<ObjectLitFolder>, T: StmtLike + VisitWith<ShouldWork> + VisitMutWith<Self>,
Vec<T>: VisitWith<ShouldWork>, Vec<T>: VisitWith<ShouldWork>,
{ {
let mut stmts_updated = Vec::with_capacity(stmts.len()); let mut stmts_updated = Vec::with_capacity(stmts.len());
@ -356,7 +358,7 @@ impl ComputedProps {
continue; continue;
} }
let mut folder = ObjectLitFolder { let mut folder = Self {
c: self.c, c: self.c,
..Default::default() ..Default::default()
}; };

View File

@ -75,6 +75,104 @@ var obj = ( _obj = {
}, _defineEnumerableProperties(_obj, _mutatorMap), _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!( test!(
::swc_ecma_parser::Syntax::default(), ::swc_ecma_parser::Syntax::default(),
|_| computed_properties(Default::default()), |_| computed_properties(Default::default()),