From 90a62bb21528035eef02fe7fa99de6f6e014d0ca Mon Sep 17 00:00:00 2001 From: Austaras Date: Sun, 16 Jan 2022 20:35:32 -0800 Subject: [PATCH] refactor(es/utils): Merge the super field visitor with `FnEnvHoister` (#3279) --- Cargo.lock | 1 + .../shared/lib/router/1/output/index.ts | 85 +-- ...odWithSuperConflict_es6_es2015.1.normal.js | 60 +-- ...ethodWithSuperConflict_es6_es5.1.normal.js | 128 ++--- ...hodWithSuperConflict_es6_es5.2.minified.js | 67 +-- ...cMethodWithSuper_es2017_es2015.1.normal.js | 60 +-- ...syncMethodWithSuper_es2017_es5.1.normal.js | 128 ++--- ...ncMethodWithSuper_es2017_es5.2.minified.js | 67 +-- ...syncMethodWithSuper_es5_es2015.1.normal.js | 60 +-- .../asyncMethodWithSuper_es5_es5.1.normal.js | 128 ++--- ...asyncMethodWithSuper_es5_es5.2.minified.js | 67 +-- ...syncMethodWithSuper_es6_es2015.1.normal.js | 196 +++---- .../asyncMethodWithSuper_es6_es5.1.normal.js | 388 ++++--------- ...asyncMethodWithSuper_es6_es5.2.minified.js | 197 ++----- ...ors.classMethods.es2015_es2015.1.normal.js | 11 +- ...rators.classMethods.es2015_es5.1.normal.js | 44 +- ...tors.classMethods.es2015_es5.2.minified.js | 34 +- ...ors.classMethods.es2018_es2015.1.normal.js | 11 +- ...rators.classMethods.es2018_es5.1.normal.js | 44 +- ...tors.classMethods.es2018_es5.2.minified.js | 34 +- ...rators.classMethods.es5_es2015.1.normal.js | 11 +- ...enerators.classMethods.es5_es5.1.normal.js | 44 +- ...erators.classMethods.es5_es5.2.minified.js | 34 +- .../superMethodCall_es2015.1.normal.js | 8 +- .../superMethodCall_es5.1.normal.js | 8 +- .../superMethodCall_es5.2.minified.js | 8 +- crates/swc_ecma_ast/src/operators.rs | 24 + .../src/super_field.rs | 20 +- .../src/es2015/arrow.rs | 24 +- .../src/es2015/object_super.rs | 20 +- .../src/es2015/parameters.rs | 30 +- .../src/es2017/async_to_generator.rs | 376 +------------ .../es2022/class_properties/private_field.rs | 20 +- .../tests/es2017_async_to_generator.rs | 171 +++++- crates/swc_ecma_utils/Cargo.toml | 1 + crates/swc_ecma_utils/src/factory.rs | 22 + .../src/function/fn_env_hoister.rs | 508 ++++++++++++++++-- 37 files changed, 1281 insertions(+), 1858 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 47f2863a989..563836c0a6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3340,6 +3340,7 @@ dependencies = [ name = "swc_ecma_utils" version = "0.63.0" dependencies = [ + "indexmap", "once_cell", "rayon", "swc_atoms", diff --git a/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts b/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts index e1c3788203b..bf39045a465 100644 --- a/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts +++ b/crates/swc/tests/fixture/next.js/shared/lib/router/1/output/index.ts @@ -56,6 +56,7 @@ var Router = /*#__PURE__*/ function() { { key: "change", value: function change(method, url, as, options, forcedScroll) { + var _this = this; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var shouldResolveHref, prevLocale, parsedAs, localePathResult, didNavigate, ref, detectedDomain, asNoBasePath, _shallow, shallow, routeProps, cleanedAs, localeChange, parsed, pathname, query, pages, rewrites, ref1, resolvedAs, rewritesResult, route, parsedAs1, asPathname, routeRegex, routeMatch, shouldInterpolate, interpolatedAs, missingParams, ref2, ref3, routeInfo, error, props, __N_SSG, __N_SSP, destination, parsedHref, ref4, newUrl, newAs, notFoundRoute, isValidShallowRoute, _scroll, shouldScroll, resetScroll; return regeneratorRuntime.wrap(function _callee$(_ctx) { @@ -72,24 +73,24 @@ var Router = /*#__PURE__*/ function() { // for static pages with query params in the URL we delay // marking the router ready until after the query is updated if (options._h) { - this.isReady = true; + _this.isReady = true; } - prevLocale = this.locale; + prevLocale = _this.locale; if (!process.env.__NEXT_I18N_SUPPORT) { _ctx.next = 18; break; } - this.locale = options.locale === false ? this.defaultLocale : options.locale || this.locale; + _this.locale = options.locale === false ? _this.defaultLocale : options.locale || _this.locale; if (typeof options.locale === 'undefined') { - options.locale = this.locale; + options.locale = _this.locale; } parsedAs = parseRelativeUrl(hasBasePath(as) ? delBasePath(as) : as); - localePathResult = normalizeLocalePath(parsedAs.pathname, this.locales); + localePathResult = normalizeLocalePath(parsedAs.pathname, _this.locales); if (localePathResult.detectedLocale) { - this.locale = localePathResult.detectedLocale; + _this.locale = localePathResult.detectedLocale; parsedAs.pathname = addBasePath(parsedAs.pathname); as = formatWithValidation(parsedAs); - url = addBasePath(normalizeLocalePath(hasBasePath(url) ? delBasePath(url) : url, this.locales).pathname); + url = addBasePath(normalizeLocalePath(hasBasePath(url) ? delBasePath(url) : url, _this.locales).pathname); } didNavigate = false; // we need to wrap this in the env check again since regenerator runtime @@ -97,23 +98,23 @@ var Router = /*#__PURE__*/ function() { if (process.env.__NEXT_I18N_SUPPORT) { ; // if the locale isn't configured hard navigate to show 404 page - if (!((ref = this.locales) === null || ref === void 0 ? void 0 : ref.includes(this.locale))) { - parsedAs.pathname = addLocale(parsedAs.pathname, this.locale); + if (!((ref = _this.locales) === null || ref === void 0 ? void 0 : ref.includes(_this.locale))) { + parsedAs.pathname = addLocale(parsedAs.pathname, _this.locale); window.location.href = formatWithValidation(parsedAs); // this was previously a return but was removed in favor // of better dead code elimination with regenerator runtime didNavigate = true; } } - detectedDomain = detectDomainLocale(this.domainLocales, undefined, this.locale); + detectedDomain = detectDomainLocale(_this.domainLocales, undefined, _this.locale); // we need to wrap this in the env check again since regenerator runtime // moves this on its own due to the return if (process.env.__NEXT_I18N_SUPPORT) { // if we are navigating to a domain locale ensure we redirect to the // correct domain - if (!didNavigate && detectedDomain && this.isLocaleDomain && self.location.hostname !== detectedDomain.domain) { + if (!didNavigate && detectedDomain && _this.isLocaleDomain && self.location.hostname !== detectedDomain.domain) { asNoBasePath = delBasePath(as); - window.location.href = "http".concat(detectedDomain.http ? '' : 's', "://").concat(detectedDomain.domain).concat(addBasePath("".concat(this.locale === detectedDomain.defaultLocale ? '' : "/".concat(this.locale)).concat(asNoBasePath === '/' ? '' : asNoBasePath) || '/')); + window.location.href = "http".concat(detectedDomain.http ? '' : 's', "://").concat(detectedDomain.domain).concat(addBasePath("".concat(_this.locale === detectedDomain.defaultLocale ? '' : "/".concat(_this.locale)).concat(asNoBasePath === '/' ? '' : asNoBasePath) || '/')); // this was previously a return but was removed in favor // of better dead code elimination with regenerator runtime didNavigate = true; @@ -126,7 +127,7 @@ var Router = /*#__PURE__*/ function() { return _ctx.abrupt("return", new Promise(function() {})); case 18: if (!options._h) { - this.isSsr = false; + _this.isSsr = false; } // marking route changes as a navigation start entry if (ST) { @@ -136,23 +137,23 @@ var Router = /*#__PURE__*/ function() { routeProps = { shallow: shallow }; - if (this._inFlightRoute) { - this.abortComponentLoad(this._inFlightRoute, routeProps); + if (_this._inFlightRoute) { + _this.abortComponentLoad(_this._inFlightRoute, routeProps); } - as = addBasePath(addLocale(hasBasePath(as) ? delBasePath(as) : as, options.locale, this.defaultLocale)); - cleanedAs = delLocale(hasBasePath(as) ? delBasePath(as) : as, this.locale); - this._inFlightRoute = as; - localeChange = prevLocale !== this.locale; - if (!(!options._h && this.onlyAHashChange(cleanedAs) && !localeChange)) { + as = addBasePath(addLocale(hasBasePath(as) ? delBasePath(as) : as, options.locale, _this.defaultLocale)); + cleanedAs = delLocale(hasBasePath(as) ? delBasePath(as) : as, _this.locale); + _this._inFlightRoute = as; + localeChange = prevLocale !== _this.locale; + if (!(!options._h && _this.onlyAHashChange(cleanedAs) && !localeChange)) { _ctx.next = 35; break; } - this.asPath = cleanedAs; + _this.asPath = cleanedAs; Router.events.emit('hashChangeStart', as, routeProps); // TODO: do we need the resolved href when only a hash change? - this.changeState(method, url, as, options); - this.scrollToHash(cleanedAs); - this.notify(this.components[this.route], null); + _this.changeState(method, url, as, options); + _this.scrollToHash(cleanedAs); + _this.notify(_this.components[_this.route], null); Router.events.emit('hashChangeComplete', as, routeProps); return _ctx.abrupt("return", true); case 35: @@ -161,7 +162,7 @@ var Router = /*#__PURE__*/ function() { ; _ctx.prev = 38; _ctx.next = 41; - return this.pageLoader.getPageList(); + return _this.pageLoader.getPageList(); case 41: pages = _ctx.sent; ; @@ -186,7 +187,7 @@ var Router = /*#__PURE__*/ function() { // We also need to set the method = replaceState always // as this should not go into the history (That's how browsers work) // We should compare the new asPath to the current asPath, not the url - if (!this.urlIsNew(cleanedAs) && !localeChange) { + if (!_this.urlIsNew(cleanedAs) && !localeChange) { method = 'replaceState'; } resolvedAs = as; @@ -197,9 +198,9 @@ var Router = /*#__PURE__*/ function() { if (shouldResolveHref && pathname !== '/_error') { options._shouldResolveHref = true; if (process.env.__NEXT_HAS_REWRITES && as.startsWith('/')) { - rewritesResult = resolveRewrites(addBasePath(addLocale(cleanedAs, this.locale)), pages, rewrites, query, function(p) { + rewritesResult = resolveRewrites(addBasePath(addLocale(cleanedAs, _this.locale)), pages, rewrites, query, function(p) { return resolveDynamicRoute(p, pages); - }, this.locales); + }, _this.locales); resolvedAs = rewritesResult.asPath; if (rewritesResult.matchedPage && rewritesResult.resolvedHref) { // if this directly matches a page we need to update the href to @@ -231,7 +232,7 @@ var Router = /*#__PURE__*/ function() { window.location.href = as; return _ctx.abrupt("return", false); case 64: - resolvedAs = delLocale(delBasePath(resolvedAs), this.locale); + resolvedAs = delLocale(delBasePath(resolvedAs), _this.locale); if (!isDynamicRoute(route)) { _ctx.next = 80; break; @@ -275,7 +276,7 @@ var Router = /*#__PURE__*/ function() { _ctx.prev = 81; ; _ctx.next = 85; - return this.getRouteInfo(route, pathname, query, as, resolvedAs, routeProps); + return _this.getRouteInfo(route, pathname, query, as, resolvedAs, routeProps); case 85: routeInfo = _ctx.sent; error = routeInfo.error, props = routeInfo.props, __N_SSG = routeInfo.__N_SSG, __N_SSP = routeInfo.__N_SSP; @@ -294,13 +295,13 @@ var Router = /*#__PURE__*/ function() { } parsedHref = parseRelativeUrl(destination); parsedHref.pathname = resolveDynamicRoute(parsedHref.pathname, pages); - ref4 = prepareUrlAs(this, destination, destination), newUrl = ref4.url, newAs = ref4.as; - return _ctx.abrupt("return", this.change(method, newUrl, newAs, options)); + ref4 = prepareUrlAs(_this, destination, destination), newUrl = ref4.url, newAs = ref4.as; + return _ctx.abrupt("return", _this.change(method, newUrl, newAs, options)); case 95: window.location.href = destination; return _ctx.abrupt("return", new Promise(function() {})); case 97: - this.isPreview = !!props.__N_PREVIEW; + _this.isPreview = !!props.__N_PREVIEW; if (!(props.notFound === SSG_DATA_NOT_FOUND)) { _ctx.next = 112; break; @@ -308,7 +309,7 @@ var Router = /*#__PURE__*/ function() { ; _ctx.prev = 100; _ctx.next = 103; - return this.fetchComponent('/404'); + return _this.fetchComponent('/404'); case 103: notFoundRoute = '/404'; _ctx.next = 109; @@ -319,20 +320,20 @@ var Router = /*#__PURE__*/ function() { notFoundRoute = '/_error'; case 109: _ctx.next = 111; - return this.getRouteInfo(notFoundRoute, notFoundRoute, query, as, resolvedAs, { + return _this.getRouteInfo(notFoundRoute, notFoundRoute, query, as, resolvedAs, { shallow: false }); case 111: routeInfo = _ctx.sent; case 112: Router.events.emit('beforeHistoryChange', as, routeProps); - this.changeState(method, url, as, options); + _this.changeState(method, url, as, options); if (options._h && pathname === '/_error' && ((ref2 = self.__NEXT_DATA__.props) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.pageProps) === null || ref3 === void 0 ? void 0 : ref3.statusCode) === 500 && (props === null || props === void 0 ? void 0 : props.pageProps)) { // ensure statusCode is still correct for static 500 page // when updating query information props.pageProps.statusCode = 500; } - isValidShallowRoute = options.shallow && this.route === route; + isValidShallowRoute = options.shallow && _this.route === route; ; shouldScroll = (_scroll = options.scroll) !== null && _scroll !== void 0 ? _scroll : !isValidShallowRoute; resetScroll = shouldScroll ? { @@ -340,7 +341,7 @@ var Router = /*#__PURE__*/ function() { y: 0 } : null; _ctx.next = 121; - return this.set(route, pathname, query, cleanedAs, routeInfo, forcedScroll !== null && forcedScroll !== void 0 ? forcedScroll : resetScroll).catch(function(e) { + return _this.set(route, pathname, query, cleanedAs, routeInfo, forcedScroll !== null && forcedScroll !== void 0 ? forcedScroll : resetScroll).catch(function(e) { if (e.cancelled) error = error || e; else throw e; }); @@ -353,8 +354,8 @@ var Router = /*#__PURE__*/ function() { throw error; case 124: if (process.env.__NEXT_I18N_SUPPORT) { - if (this.locale) { - document.documentElement.lang = this.locale; + if (_this.locale) { + document.documentElement.lang = _this.locale; } } Router.events.emit('routeChangeComplete', as, routeProps); @@ -373,7 +374,7 @@ var Router = /*#__PURE__*/ function() { case "end": return _ctx.stop(); } - }, _callee, this, [ + }, _callee, null, [ [ 38, 50 @@ -387,7 +388,7 @@ var Router = /*#__PURE__*/ function() { 106 ] ]); - }).bind(this))(); + }))(); } } ]); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es2015.1.normal.js b/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es2015.1.normal.js index c89254d9105..48f6737ef94 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es2015.1.normal.js @@ -35,60 +35,54 @@ class A { class B extends A { // async method with only call/get on 'super' does not require a binding simple() { - var _super_x = (..._args)=>super.x(..._args) - , _super_y = (..._args)=>super.y(..._args) - , _super_method = (..._args)=>super["x"](..._args) - , _super_x1 = ()=>super.x - , _super_method1 = ()=>super["x"] + var _this = this, // call with property access + _superprop_get_x = ()=>super.x + , // call additional property. + _superprop_get_y = ()=>super.y + , // call with element access + _superprop_get = (_prop)=>super[_prop] ; return _asyncToGenerator(function*() { const _super = null; const _superIndex = null; - // call with property access - _super_x(); - // call additional property. - _super_y(); - // call with element access - _super_method(); + _superprop_get_x().call(_this); + _superprop_get_y().call(_this); + _superprop_get("x").call(_this); // property access (read) - const a = _super_x1(); + const a = _superprop_get_x(); // element access (read) - const b = _super_method1(); + const b = _superprop_get("x"); })(); } // async method with assignment/destructuring on 'super' requires a binding advanced() { - var _super_x = (..._args)=>super.x(..._args) - , _super_method = (..._args)=>super["x"](..._args) - , _super_x2 = ()=>super.x - , _super_method2 = ()=>super["x"] - , _super_x3 = (_args)=>// property access (assign) - super.x = _args - , _super_method3 = (_args)=>// element access (assign) - super["x"] = _args - , _super_x4 = ()=>super.x - , _super_method4 = ()=>super["x"] + var _this = this, // call with property access + _superprop_get_x = ()=>super.x + , // call with element access + _superprop_get = (_prop)=>super[_prop] + , // property access (assign) + _superprop_set_x = (_value)=>super.x = _value + , // element access (assign) + _superprop_set = (_prop, _value)=>super[_prop] = _value ; return _asyncToGenerator(function*() { const _super = null; const _superIndex = null; const f = ()=>{}; - // call with property access - _super_x(); - // call with element access - _super_method(); + _superprop_get_x().call(_this); + _superprop_get("x").call(_this); // property access (read) - const a = _super_x2(); + const a = _superprop_get_x(); // element access (read) - const b = _super_method2(); - _super_x3(f); - _super_method3(f); + const b = _superprop_get("x"); + _superprop_set_x(f); + _superprop_set("x", f); // destructuring assign with property access - ({ f: _super_x4() } = { + ({ f: _superprop_get_x() } = { f }); // destructuring assign with element access - ({ f: _super_method4() } = { + ({ f: _superprop_get("x") } = { f }); })(); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es5.1.normal.js b/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es5.1.normal.js index 2589a307133..044342481f2 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es5.1.normal.js @@ -1,12 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -} function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -109,12 +101,6 @@ function _inherits(subClass, superClass) { }); if (superClass) _setPrototypeOf(subClass, superClass); } -function _iterableToArray(iter) { - if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); -} -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; @@ -173,21 +159,10 @@ function _superPropBase(object, property) { } return object; } -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); -} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; -function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(n); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); -} function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; @@ -244,35 +219,15 @@ var B = /*#__PURE__*/ function(A) { value: // async method with only call/get on 'super' does not require a binding function simple() { var _this = this; - var // call with property access - _instance, // call additional property. - _instance1, // call with element access - _instance2; - var _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_y = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance1 = _get(_getPrototypeOf(B.prototype), "y", _this)).call.apply(_instance1, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance2 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance2, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x1 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method1 = function() { + var _this1 = this, // call with property access + _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, // call additional property. + _superprop_get_y = function() { + return _get(_getPrototypeOf(B.prototype), "y", _this); + }, // call with element access + _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var _super, _superIndex, a, b; @@ -281,11 +236,11 @@ var B = /*#__PURE__*/ function(A) { case 0: _super = null; _superIndex = null; - _super_x(); - _super_y(); - _super_method(); - a = _super_x1(); - b = _super_method1(); + _superprop_get_x().call(_this1); + _superprop_get_y().call(_this1); + _superprop_get("x").call(_this1); + a = _superprop_get_x(); + b = _superprop_get("x"); case 7: case "end": return _ctx.stop(); @@ -299,37 +254,18 @@ var B = /*#__PURE__*/ function(A) { value: // async method with assignment/destructuring on 'super' requires a binding function advanced() { var _this = this; - var // call with property access - _instance, // call with element access - _instance3; - var _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance3 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance3, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x2 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method2 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_x3 = function(_args) { - // property access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_method3 = function(_args) { - // element access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_x4 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method4 = function() { + var _this2 = this, // call with property access + _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, // call with element access + _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); + }, // property access (assign) + _superprop_set_x = function(_value) { + return _set(_getPrototypeOf(B.prototype), "x", _value, _this, true); + }, // element access (assign) + _superprop_set = function(_prop, _value) { + return _set(_getPrototypeOf(B.prototype), _prop, _value, _this, true); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var _super, _superIndex, f, a, b, ref, ref1; @@ -339,22 +275,22 @@ var B = /*#__PURE__*/ function(A) { _super = null; _superIndex = null; f = function() {}; - _super_x(); - _super_method(); - a = _super_x2(); - b = _super_method2(); - _super_x3(f); - _super_method3(f); + _superprop_get_x().call(_this2); + _superprop_get("x").call(_this2); + a = _superprop_get_x(); + b = _superprop_get("x"); + _superprop_set_x(f); + _superprop_set("x", f); ; // destructuring assign with property access (ref = { f: f - }, _super_x4() = ref.f, ref); + }, _superprop_get_x() = ref.f, ref); ; // destructuring assign with element access (ref1 = { f: f - }, _super_method4() = ref1.f, ref1); + }, _superprop_get("x") = ref1.f, ref1); case 13: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es5.2.minified.js index 66714495d2c..00ad962f24e 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuperConflict_es6_es5.2.minified.js @@ -1,9 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - (null == len || len > arr.length) && (len = arr.length); - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg), value = info.value; @@ -86,23 +81,6 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -function _toConsumableArray(arr) { - return (function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); - })(arr) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); - })(arr) || _unsupportedIterableToArray(arr) || (function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - })(); -} -function _unsupportedIterableToArray(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -} var A = function() { "use strict"; function A() { @@ -160,28 +138,17 @@ var A = function() { { key: "simple", value: function() { - var _instance, _instance1, _instance2, _this = this, _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_y = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance1 = _get(_getPrototypeOf(B.prototype), "y", _this)).call.apply(_instance1, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance2 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance2, [ - _this - ].concat(_toConsumableArray(_args))); + var _this = this, _this1 = this, _superprop_get_x = function() { + return _get(_getPrototypeOf(B.prototype), "x", _this); + }, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var _super, _superIndex, a, b; return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - _super = null, _superIndex = null, _super_x(), _super_y(), _super_method(), a = _get(_getPrototypeOf(B.prototype), "x", _this), b = _get(_getPrototypeOf(B.prototype), "x", _this); + _super = null, _superIndex = null, _superprop_get_x().call(_this1), _get(_getPrototypeOf(B.prototype), "y", _this).call(_this1), _superprop_get("x").call(_this1), a = _superprop_get_x(), b = _superprop_get("x"); case 7: case "end": return _ctx.stop(); @@ -193,32 +160,22 @@ var A = function() { { key: "advanced", value: function() { - var _instance, _instance3, _this = this, _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance3 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance3, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x1 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method1 = function() { + var _this = this, _this2 = this, _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var _super, _superIndex, f, a, b, ref, ref1; return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - var _args, _args1; - _super = null, _superIndex = null, f = function() {}, _super_x(), _super_method(), a = _get(_getPrototypeOf(B.prototype), "x", _this), b = _get(_getPrototypeOf(B.prototype), "x", _this), _args = f, _set(_getPrototypeOf(B.prototype), "x", _args, _this, !0), _args1 = f, _set(_getPrototypeOf(B.prototype), "x", _args1, _this, !0), ref = { + var _value, _value1; + _super = null, _superIndex = null, f = function() {}, _superprop_get_x().call(_this2), _superprop_get("x").call(_this2), a = _superprop_get_x(), b = _superprop_get("x"), _value = f, _set(_getPrototypeOf(B.prototype), "x", _value, _this, !0), _value1 = f, _set(_getPrototypeOf(B.prototype), "x", _value1, _this, !0), ref = { f: f - }, _super_x1() = ref.f, ref1 = { + }, _superprop_get_x() = ref.f, ref1 = { f: f - }, _super_method1() = ref1.f; + }, _superprop_get("x") = ref1.f; case 13: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es2015.1.normal.js b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es2015.1.normal.js index add7d0c311c..e3487ca4df2 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es2015.1.normal.js @@ -36,56 +36,50 @@ class A { class B extends A { // async method with only call/get on 'super' does not require a binding simple() { - var _super_x = (..._args)=>super.x(..._args) - , _super_y = (..._args)=>super.y(..._args) - , _super_method = (..._args)=>super["x"](..._args) - , _super_x1 = ()=>super.x - , _super_method1 = ()=>super["x"] + var _this = this, // call with property access + _superprop_get_x = ()=>super.x + , // call additional property. + _superprop_get_y = ()=>super.y + , // call with element access + _superprop_get = (_prop)=>super[_prop] ; return _asyncToGenerator(function*() { - // call with property access - _super_x(); - // call additional property. - _super_y(); - // call with element access - _super_method(); + _superprop_get_x().call(_this); + _superprop_get_y().call(_this); + _superprop_get("x").call(_this); // property access (read) - const a = _super_x1(); + const a = _superprop_get_x(); // element access (read) - const b = _super_method1(); + const b = _superprop_get("x"); })(); } // async method with assignment/destructuring on 'super' requires a binding advanced() { - var _super_x = (..._args)=>super.x(..._args) - , _super_method = (..._args)=>super["x"](..._args) - , _super_x2 = ()=>super.x - , _super_method2 = ()=>super["x"] - , _super_x3 = (_args)=>// property access (assign) - super.x = _args - , _super_method3 = (_args)=>// element access (assign) - super["x"] = _args - , _super_x4 = ()=>super.x - , _super_method4 = ()=>super["x"] + var _this = this, // call with property access + _superprop_get_x = ()=>super.x + , // call with element access + _superprop_get = (_prop)=>super[_prop] + , // property access (assign) + _superprop_set_x = (_value)=>super.x = _value + , // element access (assign) + _superprop_set = (_prop, _value)=>super[_prop] = _value ; return _asyncToGenerator(function*() { const f = ()=>{}; - // call with property access - _super_x(); - // call with element access - _super_method(); + _superprop_get_x().call(_this); + _superprop_get("x").call(_this); // property access (read) - const a = _super_x2(); + const a = _superprop_get_x(); // element access (read) - const b = _super_method2(); - _super_x3(f); - _super_method3(f); + const b = _superprop_get("x"); + _superprop_set_x(f); + _superprop_set("x", f); // destructuring assign with property access - ({ f: _super_x4() } = { + ({ f: _superprop_get_x() } = { f }); // destructuring assign with element access - ({ f: _super_method4() } = { + ({ f: _superprop_get("x") } = { f }); })(); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es5.1.normal.js b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es5.1.normal.js index 2957e7cc5ef..af1fcddcd3e 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es5.1.normal.js @@ -1,12 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -} function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -109,12 +101,6 @@ function _inherits(subClass, superClass) { }); if (superClass) _setPrototypeOf(subClass, superClass); } -function _iterableToArray(iter) { - if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); -} -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; @@ -173,21 +159,10 @@ function _superPropBase(object, property) { } return object; } -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); -} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; -function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(n); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); -} function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; @@ -245,46 +220,26 @@ var B = /*#__PURE__*/ function(A) { value: // async method with only call/get on 'super' does not require a binding function simple() { var _this = this; - var // call with property access - _instance, // call additional property. - _instance1, // call with element access - _instance2; - var _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_y = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance1 = _get(_getPrototypeOf(B.prototype), "y", _this)).call.apply(_instance1, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance2 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance2, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x1 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method1 = function() { + var _this1 = this, // call with property access + _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, // call additional property. + _superprop_get_y = function() { + return _get(_getPrototypeOf(B.prototype), "y", _this); + }, // call with element access + _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var a, b; return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - _super_x(); - _super_y(); - _super_method(); - a = _super_x1(); - b = _super_method1(); + _superprop_get_x().call(_this1); + _superprop_get_y().call(_this1); + _superprop_get("x").call(_this1); + a = _superprop_get_x(); + b = _superprop_get("x"); case 5: case "end": return _ctx.stop(); @@ -298,37 +253,18 @@ var B = /*#__PURE__*/ function(A) { value: // async method with assignment/destructuring on 'super' requires a binding function advanced() { var _this = this; - var // call with property access - _instance, // call with element access - _instance3; - var _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance3 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance3, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x2 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method2 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_x3 = function(_args) { - // property access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_method3 = function(_args) { - // element access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_x4 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method4 = function() { + var _this2 = this, // call with property access + _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, // call with element access + _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); + }, // property access (assign) + _superprop_set_x = function(_value) { + return _set(_getPrototypeOf(B.prototype), "x", _value, _this, true); + }, // element access (assign) + _superprop_set = function(_prop, _value) { + return _set(_getPrototypeOf(B.prototype), _prop, _value, _this, true); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var f, a, b, ref, ref1; @@ -336,22 +272,22 @@ var B = /*#__PURE__*/ function(A) { while(1)switch(_ctx.prev = _ctx.next){ case 0: f = function() {}; - _super_x(); - _super_method(); - a = _super_x2(); - b = _super_method2(); - _super_x3(f); - _super_method3(f); + _superprop_get_x().call(_this2); + _superprop_get("x").call(_this2); + a = _superprop_get_x(); + b = _superprop_get("x"); + _superprop_set_x(f); + _superprop_set("x", f); ; // destructuring assign with property access (ref = { f: f - }, _super_x4() = ref.f, ref); + }, _superprop_get_x() = ref.f, ref); ; // destructuring assign with element access (ref1 = { f: f - }, _super_method4() = ref1.f, ref1); + }, _superprop_get("x") = ref1.f, ref1); case 11: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es5.2.minified.js index 290d22a1e07..1f2aebea4fd 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es2017_es5.2.minified.js @@ -1,9 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - (null == len || len > arr.length) && (len = arr.length); - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg), value = info.value; @@ -86,23 +81,6 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -function _toConsumableArray(arr) { - return (function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); - })(arr) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); - })(arr) || _unsupportedIterableToArray(arr) || (function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - })(); -} -function _unsupportedIterableToArray(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -} var A = function() { "use strict"; function A() { @@ -160,28 +138,17 @@ var A = function() { { key: "simple", value: function() { - var _instance, _instance1, _instance2, _this = this, _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_y = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance1 = _get(_getPrototypeOf(B.prototype), "y", _this)).call.apply(_instance1, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance2 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance2, [ - _this - ].concat(_toConsumableArray(_args))); + var _this = this, _this1 = this, _superprop_get_x = function() { + return _get(_getPrototypeOf(B.prototype), "x", _this); + }, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var a, b; return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - _super_x(), _super_y(), _super_method(), a = _get(_getPrototypeOf(B.prototype), "x", _this), b = _get(_getPrototypeOf(B.prototype), "x", _this); + _superprop_get_x().call(_this1), _get(_getPrototypeOf(B.prototype), "y", _this).call(_this1), _superprop_get("x").call(_this1), a = _superprop_get_x(), b = _superprop_get("x"); case 5: case "end": return _ctx.stop(); @@ -193,32 +160,22 @@ var A = function() { { key: "advanced", value: function() { - var _instance, _instance3, _this = this, _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance3 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance3, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x1 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method1 = function() { + var _this = this, _this2 = this, _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var f, a, b, ref, ref1; return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - var _args, _args1; - f = function() {}, _super_x(), _super_method(), a = _get(_getPrototypeOf(B.prototype), "x", _this), b = _get(_getPrototypeOf(B.prototype), "x", _this), _args = f, _set(_getPrototypeOf(B.prototype), "x", _args, _this, !0), _args1 = f, _set(_getPrototypeOf(B.prototype), "x", _args1, _this, !0), ref = { + var _value, _value1; + f = function() {}, _superprop_get_x().call(_this2), _superprop_get("x").call(_this2), a = _superprop_get_x(), b = _superprop_get("x"), _value = f, _set(_getPrototypeOf(B.prototype), "x", _value, _this, !0), _value1 = f, _set(_getPrototypeOf(B.prototype), "x", _value1, _this, !0), ref = { f: f - }, _super_x1() = ref.f, ref1 = { + }, _superprop_get_x() = ref.f, ref1 = { f: f - }, _super_method1() = ref1.f; + }, _superprop_get("x") = ref1.f; case 11: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es2015.1.normal.js b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es2015.1.normal.js index f54f445d35f..883be76baf2 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es2015.1.normal.js @@ -37,56 +37,50 @@ class A { class B extends A { // async method with only call/get on 'super' does not require a binding simple() { - var _super_x = (..._args)=>super.x(..._args) - , _super_y = (..._args)=>super.y(..._args) - , _super_method = (..._args)=>super["x"](..._args) - , _super_x1 = ()=>super.x - , _super_method1 = ()=>super["x"] + var _this = this, // call with property access + _superprop_get_x = ()=>super.x + , // call additional property. + _superprop_get_y = ()=>super.y + , // call with element access + _superprop_get = (_prop)=>super[_prop] ; return _asyncToGenerator(function*() { - // call with property access - _super_x(); - // call additional property. - _super_y(); - // call with element access - _super_method(); + _superprop_get_x().call(_this); + _superprop_get_y().call(_this); + _superprop_get("x").call(_this); // property access (read) - const a = _super_x1(); + const a = _superprop_get_x(); // element access (read) - const b = _super_method1(); + const b = _superprop_get("x"); })(); } // async method with assignment/destructuring on 'super' requires a binding advanced() { - var _super_x = (..._args)=>super.x(..._args) - , _super_method = (..._args)=>super["x"](..._args) - , _super_x2 = ()=>super.x - , _super_method2 = ()=>super["x"] - , _super_x3 = (_args)=>// property access (assign) - super.x = _args - , _super_method3 = (_args)=>// element access (assign) - super["x"] = _args - , _super_x4 = ()=>super.x - , _super_method4 = ()=>super["x"] + var _this = this, // call with property access + _superprop_get_x = ()=>super.x + , // call with element access + _superprop_get = (_prop)=>super[_prop] + , // property access (assign) + _superprop_set_x = (_value)=>super.x = _value + , // element access (assign) + _superprop_set = (_prop, _value)=>super[_prop] = _value ; return _asyncToGenerator(function*() { const f = ()=>{}; - // call with property access - _super_x(); - // call with element access - _super_method(); + _superprop_get_x().call(_this); + _superprop_get("x").call(_this); // property access (read) - const a = _super_x2(); + const a = _superprop_get_x(); // element access (read) - const b = _super_method2(); - _super_x3(f); - _super_method3(f); + const b = _superprop_get("x"); + _superprop_set_x(f); + _superprop_set("x", f); // destructuring assign with property access - ({ f: _super_x4() } = { + ({ f: _superprop_get_x() } = { f }); // destructuring assign with element access - ({ f: _super_method4() } = { + ({ f: _superprop_get("x") } = { f }); })(); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es5.1.normal.js b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es5.1.normal.js index c75a56f00de..71715984a11 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es5.1.normal.js @@ -1,12 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -} function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -109,12 +101,6 @@ function _inherits(subClass, superClass) { }); if (superClass) _setPrototypeOf(subClass, superClass); } -function _iterableToArray(iter) { - if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); -} -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; @@ -173,21 +159,10 @@ function _superPropBase(object, property) { } return object; } -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); -} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; -function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(n); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); -} function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; @@ -246,46 +221,26 @@ var B = /*#__PURE__*/ function(A) { value: // async method with only call/get on 'super' does not require a binding function simple() { var _this = this; - var // call with property access - _instance, // call additional property. - _instance1, // call with element access - _instance2; - var _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_y = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance1 = _get(_getPrototypeOf(B.prototype), "y", _this)).call.apply(_instance1, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance2 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance2, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x1 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method1 = function() { + var _this1 = this, // call with property access + _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, // call additional property. + _superprop_get_y = function() { + return _get(_getPrototypeOf(B.prototype), "y", _this); + }, // call with element access + _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var a, b; return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - _super_x(); - _super_y(); - _super_method(); - a = _super_x1(); - b = _super_method1(); + _superprop_get_x().call(_this1); + _superprop_get_y().call(_this1); + _superprop_get("x").call(_this1); + a = _superprop_get_x(); + b = _superprop_get("x"); case 5: case "end": return _ctx.stop(); @@ -299,37 +254,18 @@ var B = /*#__PURE__*/ function(A) { value: // async method with assignment/destructuring on 'super' requires a binding function advanced() { var _this = this; - var // call with property access - _instance, // call with element access - _instance3; - var _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance3 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance3, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x2 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method2 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_x3 = function(_args) { - // property access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_method3 = function(_args) { - // element access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_x4 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method4 = function() { + var _this2 = this, // call with property access + _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, // call with element access + _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); + }, // property access (assign) + _superprop_set_x = function(_value) { + return _set(_getPrototypeOf(B.prototype), "x", _value, _this, true); + }, // element access (assign) + _superprop_set = function(_prop, _value) { + return _set(_getPrototypeOf(B.prototype), _prop, _value, _this, true); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var f, a, b, ref, ref1; @@ -337,22 +273,22 @@ var B = /*#__PURE__*/ function(A) { while(1)switch(_ctx.prev = _ctx.next){ case 0: f = function() {}; - _super_x(); - _super_method(); - a = _super_x2(); - b = _super_method2(); - _super_x3(f); - _super_method3(f); + _superprop_get_x().call(_this2); + _superprop_get("x").call(_this2); + a = _superprop_get_x(); + b = _superprop_get("x"); + _superprop_set_x(f); + _superprop_set("x", f); ; // destructuring assign with property access (ref = { f: f - }, _super_x4() = ref.f, ref); + }, _superprop_get_x() = ref.f, ref); ; // destructuring assign with element access (ref1 = { f: f - }, _super_method4() = ref1.f, ref1); + }, _superprop_get("x") = ref1.f, ref1); case 11: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es5.2.minified.js index 290d22a1e07..1f2aebea4fd 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es5_es5.2.minified.js @@ -1,9 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - (null == len || len > arr.length) && (len = arr.length); - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg), value = info.value; @@ -86,23 +81,6 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -function _toConsumableArray(arr) { - return (function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); - })(arr) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); - })(arr) || _unsupportedIterableToArray(arr) || (function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - })(); -} -function _unsupportedIterableToArray(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -} var A = function() { "use strict"; function A() { @@ -160,28 +138,17 @@ var A = function() { { key: "simple", value: function() { - var _instance, _instance1, _instance2, _this = this, _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_y = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance1 = _get(_getPrototypeOf(B.prototype), "y", _this)).call.apply(_instance1, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance2 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance2, [ - _this - ].concat(_toConsumableArray(_args))); + var _this = this, _this1 = this, _superprop_get_x = function() { + return _get(_getPrototypeOf(B.prototype), "x", _this); + }, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var a, b; return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - _super_x(), _super_y(), _super_method(), a = _get(_getPrototypeOf(B.prototype), "x", _this), b = _get(_getPrototypeOf(B.prototype), "x", _this); + _superprop_get_x().call(_this1), _get(_getPrototypeOf(B.prototype), "y", _this).call(_this1), _superprop_get("x").call(_this1), a = _superprop_get_x(), b = _superprop_get("x"); case 5: case "end": return _ctx.stop(); @@ -193,32 +160,22 @@ var A = function() { { key: "advanced", value: function() { - var _instance, _instance3, _this = this, _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance3 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance3, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x1 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method1 = function() { + var _this = this, _this2 = this, _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var f, a, b, ref, ref1; return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - var _args, _args1; - f = function() {}, _super_x(), _super_method(), a = _get(_getPrototypeOf(B.prototype), "x", _this), b = _get(_getPrototypeOf(B.prototype), "x", _this), _args = f, _set(_getPrototypeOf(B.prototype), "x", _args, _this, !0), _args1 = f, _set(_getPrototypeOf(B.prototype), "x", _args1, _this, !0), ref = { + var _value, _value1; + f = function() {}, _superprop_get_x().call(_this2), _superprop_get("x").call(_this2), a = _superprop_get_x(), b = _superprop_get("x"), _value = f, _set(_getPrototypeOf(B.prototype), "x", _value, _this, !0), _value1 = f, _set(_getPrototypeOf(B.prototype), "x", _value1, _this, !0), ref = { f: f - }, _super_x1() = ref.f, ref1 = { + }, _superprop_get_x() = ref.f, ref1 = { f: f - }, _super_method1() = ref1.f; + }, _superprop_get("x") = ref1.f; case 11: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es2015.1.normal.js b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es2015.1.normal.js index 3fc4b4877ec..51b0344be8b 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es2015.1.normal.js @@ -126,247 +126,217 @@ class A { class B extends A { // async method with only call/get on 'super' does not require a binding simple() { - var _super_x = (..._args)=>super.x(..._args) - , _super_y = (..._args)=>super.y(..._args) - , _super_method = (..._args)=>super["x"](..._args) - , _super_x1 = ()=>super.x - , _super_method1 = ()=>super["x"] + var _this = this, // call with property access + _superprop_get_x = ()=>super.x + , // call additional property. + _superprop_get_y = ()=>super.y + , // call with element access + _superprop_get = (_prop)=>super[_prop] ; return _asyncToGenerator(function*() { - // call with property access - _super_x(); - // call additional property. - _super_y(); - // call with element access - _super_method(); + _superprop_get_x().call(_this); + _superprop_get_y().call(_this); + _superprop_get("x").call(_this); // property access (read) - const a = _super_x1(); + const a = _superprop_get_x(); // element access (read) - const b = _super_method1(); + const b = _superprop_get("x"); })(); } // async method with assignment/destructuring on 'super' requires a binding advanced() { - var _super_x = (..._args)=>super.x(..._args) - , _super_method = (..._args)=>super["x"](..._args) - , _super_x2 = ()=>super.x - , _super_method2 = ()=>super["x"] - , _super_x3 = (_args)=>// property access (assign) - super.x = _args - , _super_method3 = (_args)=>// element access (assign) - super["x"] = _args - , _super_x4 = ()=>super.x - , _super_method4 = ()=>super["x"] - , _super_x5 = (..._args)=>super.x(..._args) - , _super_method5 = (..._args)=>super["x"](..._args) - , _super_x6 = (..._args)=>super.x(..._args) - , _super_method6 = (..._args)=>super["x"](..._args) + var _this = this, // call with property access + _superprop_get_x = ()=>super.x + , // call with element access + _superprop_get = (_prop)=>super[_prop] + , // property access (assign) + _superprop_set_x = (_value)=>super.x = _value + , // element access (assign) + _superprop_set = (_prop, _value)=>super[_prop] = _value ; return _asyncToGenerator(function*() { const f = ()=>{}; - // call with property access - _super_x(); - // call with element access - _super_method(); + _superprop_get_x().call(_this); + _superprop_get("x").call(_this); // property access (read) - const a = _super_x2(); + const a = _superprop_get_x(); // element access (read) - const b = _super_method2(); - _super_x3(f); - _super_method3(f); + const b = _superprop_get("x"); + _superprop_set_x(f); + _superprop_set("x", f); // destructuring assign with property access - ({ f: _super_x4() } = { + ({ f: _superprop_get_x() } = { f }); // destructuring assign with element access - ({ f: _super_method4() } = { + ({ f: _superprop_get("x") } = { f }); // property access in arrow - (()=>_super_x5() + (()=>_superprop_get_x().call(_this) ); // element access in arrow - (()=>_super_method5() + (()=>_superprop_get("x").call(_this) ); // property access in async arrow _asyncToGenerator(function*() { - return _super_x6(); + return _superprop_get_x().call(_this); }); // element access in async arrow _asyncToGenerator(function*() { - return _super_method6(); + return _superprop_get("x").call(_this); }); })(); } property_access_only_read_only() { - var _super_x = (..._args)=>super.x(..._args) - , _super_x7 = ()=>super.x - , _super_x8 = (..._args)=>super.x(..._args) - , _super_x9 = (..._args)=>super.x(..._args) + var _this = this, // call with property access + _superprop_get_x = ()=>super.x ; return _asyncToGenerator(function*() { - // call with property access - _super_x(); + _superprop_get_x().call(_this); // property access (read) - const a = _super_x7(); + const a = _superprop_get_x(); // property access in arrow - (()=>_super_x8() + (()=>_superprop_get_x().call(_this) ); // property access in async arrow _asyncToGenerator(function*() { - return _super_x9(); + return _superprop_get_x().call(_this); }); })(); } property_access_only_write_only() { - var _super_x = (_args)=>// property access (assign) - super.x = _args - , _super_x10 = ()=>super.x - , _super_x11 = (_args)=>super.x = _args - , _super_x12 = (_args)=>super.x = _args + var _superprop_get_x = ()=>super.x + , // property access (assign) + _superprop_set_x = (_value)=>super.x = _value ; return _asyncToGenerator(function*() { const f = ()=>{}; - _super_x(f); + _superprop_set_x(f); // destructuring assign with property access - ({ f: _super_x10() } = { + ({ f: _superprop_get_x() } = { f }); // property access (assign) in arrow - (()=>_super_x11(f) + (()=>_superprop_set_x(f) ); // property access (assign) in async arrow _asyncToGenerator(function*() { - return _super_x12(f); + return _superprop_set_x(f); }); })(); } element_access_only_read_only() { - var _super_method = (..._args)=>super["x"](..._args) - , _super_method7 = ()=>super["x"] - , _super_method8 = (..._args)=>super["x"](..._args) - , _super_method9 = (..._args)=>super["x"](..._args) + var _this = this, // call with element access + _superprop_get = (_prop)=>super[_prop] ; return _asyncToGenerator(function*() { - // call with element access - _super_method(); + _superprop_get("x").call(_this); // element access (read) - const a = _super_method7(); + const a = _superprop_get("x"); // element access in arrow - (()=>_super_method8() + (()=>_superprop_get("x").call(_this) ); // element access in async arrow _asyncToGenerator(function*() { - return _super_method9(); + return _superprop_get("x").call(_this); }); })(); } element_access_only_write_only() { - var _super_method = (_args)=>// element access (assign) - super["x"] = _args - , _super_method10 = ()=>super["x"] - , _super_method11 = (_args)=>super["x"] = _args - , _super_method12 = (_args)=>super["x"] = _args + var _superprop_get = (_prop)=>super[_prop] + , // element access (assign) + _superprop_set = (_prop, _value)=>super[_prop] = _value ; return _asyncToGenerator(function*() { const f = ()=>{}; - _super_method(f); + _superprop_set("x", f); // destructuring assign with element access - ({ f: _super_method10() } = { + ({ f: _superprop_get("x") } = { f }); // element access (assign) in arrow - (()=>_super_method11(f) + (()=>_superprop_set("x", f) ); // element access (assign) in async arrow _asyncToGenerator(function*() { - return _super_method12(f); + return _superprop_set("x", f); }); })(); } property_access_only_read_only_in_generator() { - var _super_x = (..._args)=>super.x(..._args) - , _super_x13 = ()=>super.x - , _super_x14 = (..._args)=>super.x(..._args) - , _super_x15 = (..._args)=>super.x(..._args) + var _this = this, // call with property access + _superprop_get_x = ()=>super.x ; return _wrapAsyncGenerator(function*() { - // call with property access - _super_x(); + _superprop_get_x().call(_this); // property access (read) - const a = _super_x13(); + const a = _superprop_get_x(); // property access in arrow - (()=>_super_x14() + (()=>_superprop_get_x().call(_this) ); // property access in async arrow _asyncToGenerator(function*() { - return _super_x15(); + return _superprop_get_x().call(_this); }); })(); } property_access_only_write_only_in_generator() { - var _super_x = (_args)=>// property access (assign) - super.x = _args - , _super_x16 = ()=>super.x - , _super_x17 = (_args)=>super.x = _args - , _super_x18 = (_args)=>super.x = _args + var _superprop_get_x = ()=>super.x + , // property access (assign) + _superprop_set_x = (_value)=>super.x = _value ; return _wrapAsyncGenerator(function*() { const f = ()=>{}; - _super_x(f); + _superprop_set_x(f); // destructuring assign with property access - ({ f: _super_x16() } = { + ({ f: _superprop_get_x() } = { f }); // property access (assign) in arrow - (()=>_super_x17(f) + (()=>_superprop_set_x(f) ); // property access (assign) in async arrow _asyncToGenerator(function*() { - return _super_x18(f); + return _superprop_set_x(f); }); })(); } element_access_only_read_only_in_generator() { - var _super_method = (..._args)=>super["x"](..._args) - , _super_method13 = ()=>super["x"] - , _super_method14 = (..._args)=>super["x"](..._args) - , _super_method15 = (..._args)=>super["x"](..._args) + var _this = this, // call with element access + _superprop_get = (_prop)=>super[_prop] ; return _wrapAsyncGenerator(function*() { - // call with element access - _super_method(); + _superprop_get("x").call(_this); // element access (read) - const a = _super_method13(); + const a = _superprop_get("x"); // element access in arrow - (()=>_super_method14() + (()=>_superprop_get("x").call(_this) ); // element access in async arrow _asyncToGenerator(function*() { - return _super_method15(); + return _superprop_get("x").call(_this); }); })(); } element_access_only_write_only_in_generator() { - var _super_method = (_args)=>// element access (assign) - super["x"] = _args - , _super_method16 = ()=>super["x"] - , _super_method17 = (_args)=>super["x"] = _args - , _super_method18 = (_args)=>super["x"] = _args + var _superprop_get = (_prop)=>super[_prop] + , // element access (assign) + _superprop_set = (_prop, _value)=>super[_prop] = _value ; return _wrapAsyncGenerator(function*() { const f = ()=>{}; - _super_method(f); + _superprop_set("x", f); // destructuring assign with element access - ({ f: _super_method16() } = { + ({ f: _superprop_get("x") } = { f }); // element access (assign) in arrow - (()=>_super_method17(f) + (()=>_superprop_set("x", f) ); // element access (assign) in async arrow _asyncToGenerator(function*() { - return _super_method18(f); + return _superprop_set("x", f); }); })(); } diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es5.1.normal.js b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es5.1.normal.js index b22ac58e9c4..78fb6696803 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es5.1.normal.js @@ -1,12 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -} function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -193,12 +185,6 @@ function _inherits(subClass, superClass) { }); if (superClass) _setPrototypeOf(subClass, superClass); } -function _iterableToArray(iter) { - if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); -} -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; @@ -257,21 +243,10 @@ function _superPropBase(object, property) { } return object; } -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); -} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; -function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(n); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); -} function _wrapAsyncGenerator(fn) { return function() { return new AsyncGenerator(fn.apply(this, arguments)); @@ -335,46 +310,26 @@ var B = /*#__PURE__*/ function(A) { value: // async method with only call/get on 'super' does not require a binding function simple() { var _this = this; - var // call with property access - _instance, // call additional property. - _instance1, // call with element access - _instance2; - var _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_y = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance1 = _get(_getPrototypeOf(B.prototype), "y", _this)).call.apply(_instance1, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance2 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance2, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x1 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method1 = function() { + var _this1 = this, // call with property access + _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, // call additional property. + _superprop_get_y = function() { + return _get(_getPrototypeOf(B.prototype), "y", _this); + }, // call with element access + _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var a, b; return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - _super_x(); - _super_y(); - _super_method(); - a = _super_x1(); - b = _super_method1(); + _superprop_get_x().call(_this1); + _superprop_get_y().call(_this1); + _superprop_get("x").call(_this1); + a = _superprop_get_x(); + b = _superprop_get("x"); case 5: case "end": return _ctx.stop(); @@ -388,65 +343,18 @@ var B = /*#__PURE__*/ function(A) { value: // async method with assignment/destructuring on 'super' requires a binding function advanced() { var _this = this; - var // call with property access - _instance, // call with element access - _instance3, _instance4, _instance5, _instance6, _instance7; - var _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance3 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance3, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x2 = function() { + var _this2 = this, // call with property access + _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method2 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_x3 = function(_args) { - // property access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_method3 = function(_args) { - // element access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_x4 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method4 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_x5 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance4 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance4, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method5 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance5 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance5, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x6 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance6 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance6, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method6 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance7 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance7, [ - _this - ].concat(_toConsumableArray(_args))); + }, // call with element access + _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); + }, // property access (assign) + _superprop_set_x = function(_value) { + return _set(_getPrototypeOf(B.prototype), "x", _value, _this, true); + }, // element access (assign) + _superprop_set = function(_prop, _value) { + return _set(_getPrototypeOf(B.prototype), _prop, _value, _this, true); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee1() { var f, a, b, ref, ref1; @@ -454,36 +362,36 @@ var B = /*#__PURE__*/ function(A) { while(1)switch(_ctx1.prev = _ctx1.next){ case 0: f = function() {}; - _super_x(); - _super_method(); - a = _super_x2(); - b = _super_method2(); - _super_x3(f); - _super_method3(f); + _superprop_get_x().call(_this2); + _superprop_get("x").call(_this2); + a = _superprop_get_x(); + b = _superprop_get("x"); + _superprop_set_x(f); + _superprop_set("x", f); ; // destructuring assign with property access (ref = { f: f - }, _super_x4() = ref.f, ref); + }, _superprop_get_x() = ref.f, ref); ; // destructuring assign with element access (ref1 = { f: f - }, _super_method4() = ref1.f, ref1); + }, _superprop_get("x") = ref1.f, ref1); // property access in arrow (function() { - return _super_x5(); + return _superprop_get_x().call(_this2); }); // element access in arrow (function() { - return _super_method5(); + return _superprop_get("x").call(_this2); }); // property access in async arrow _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_x6()); + return _ctx.abrupt("return", _superprop_get_x().call(_this2)); case 1: case "end": return _ctx.stop(); @@ -495,7 +403,7 @@ var B = /*#__PURE__*/ function(A) { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_method6()); + return _ctx.abrupt("return", _superprop_get("x").call(_this2)); case 1: case "end": return _ctx.stop(); @@ -514,49 +422,27 @@ var B = /*#__PURE__*/ function(A) { key: "property_access_only_read_only", value: function property_access_only_read_only() { var _this = this; - var // call with property access - _instance, _instance8, _instance9; - var _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x7 = function() { + var _this3 = this, // call with property access + _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_x8 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance8 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance8, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x9 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance9 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance9, [ - _this - ].concat(_toConsumableArray(_args))); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee2() { var a; return regeneratorRuntime.wrap(function _callee$(_ctx2) { while(1)switch(_ctx2.prev = _ctx2.next){ case 0: - _super_x(); - a = _super_x7(); + _superprop_get_x().call(_this3); + a = _superprop_get_x(); // property access in arrow (function() { - return _super_x8(); + return _superprop_get_x().call(_this3); }); // property access in async arrow _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_x9()); + return _ctx.abrupt("return", _superprop_get_x().call(_this3)); case 1: case "end": return _ctx.stop(); @@ -575,15 +461,11 @@ var B = /*#__PURE__*/ function(A) { key: "property_access_only_write_only", value: function property_access_only_write_only() { var _this = this; - var _super_x = function(_args) { - // property access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_x10 = function() { + var _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_x11 = function(_args) { - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_x12 = function(_args) { - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); + }, // property access (assign) + _superprop_set_x = function(_value) { + return _set(_getPrototypeOf(B.prototype), "x", _value, _this, true); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee3() { var f, ref; @@ -591,22 +473,22 @@ var B = /*#__PURE__*/ function(A) { while(1)switch(_ctx3.prev = _ctx3.next){ case 0: f = function() {}; - _super_x(f); + _superprop_set_x(f); ; // destructuring assign with property access (ref = { f: f - }, _super_x10() = ref.f, ref); + }, _superprop_get_x() = ref.f, ref); // property access (assign) in arrow (function() { - return _super_x11(f); + return _superprop_set_x(f); }); // property access (assign) in async arrow _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_x12(f)); + return _ctx.abrupt("return", _superprop_set_x(f)); case 1: case "end": return _ctx.stop(); @@ -625,49 +507,27 @@ var B = /*#__PURE__*/ function(A) { key: "element_access_only_read_only", value: function element_access_only_read_only() { var _this = this; - var // call with element access - _instance, _instance10, _instance11; - var _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method7 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method8 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance10 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance10, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method9 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance11 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance11, [ - _this - ].concat(_toConsumableArray(_args))); + var _this4 = this, // call with element access + _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee4() { var a; return regeneratorRuntime.wrap(function _callee$(_ctx4) { while(1)switch(_ctx4.prev = _ctx4.next){ case 0: - _super_method(); - a = _super_method7(); + _superprop_get("x").call(_this4); + a = _superprop_get("x"); // element access in arrow (function() { - return _super_method8(); + return _superprop_get("x").call(_this4); }); // element access in async arrow _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_method9()); + return _ctx.abrupt("return", _superprop_get("x").call(_this4)); case 1: case "end": return _ctx.stop(); @@ -686,15 +546,11 @@ var B = /*#__PURE__*/ function(A) { key: "element_access_only_write_only", value: function element_access_only_write_only() { var _this = this; - var _super_method = function(_args) { - // element access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_method10 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method11 = function(_args) { - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_method12 = function(_args) { - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); + var _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); + }, // element access (assign) + _superprop_set = function(_prop, _value) { + return _set(_getPrototypeOf(B.prototype), _prop, _value, _this, true); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee5() { var f, ref; @@ -702,22 +558,22 @@ var B = /*#__PURE__*/ function(A) { while(1)switch(_ctx5.prev = _ctx5.next){ case 0: f = function() {}; - _super_method(f); + _superprop_set("x", f); ; // destructuring assign with element access (ref = { f: f - }, _super_method10() = ref.f, ref); + }, _superprop_get("x") = ref.f, ref); // element access (assign) in arrow (function() { - return _super_method11(f); + return _superprop_set("x", f); }); // element access (assign) in async arrow _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_method12(f)); + return _ctx.abrupt("return", _superprop_set("x", f)); case 1: case "end": return _ctx.stop(); @@ -736,49 +592,27 @@ var B = /*#__PURE__*/ function(A) { key: "property_access_only_read_only_in_generator", value: function property_access_only_read_only_in_generator() { var _this = this; - var // call with property access - _instance, _instance12, _instance13; - var _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x13 = function() { + var _this5 = this, // call with property access + _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_x14 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance12 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance12, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x15 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance13 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance13, [ - _this - ].concat(_toConsumableArray(_args))); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee6() { var a; return regeneratorRuntime.wrap(function _callee$(_ctx6) { while(1)switch(_ctx6.prev = _ctx6.next){ case 0: - _super_x(); - a = _super_x13(); + _superprop_get_x().call(_this5); + a = _superprop_get_x(); // property access in arrow (function() { - return _super_x14(); + return _superprop_get_x().call(_this5); }); // property access in async arrow _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_x15()); + return _ctx.abrupt("return", _superprop_get_x().call(_this5)); case 1: case "end": return _ctx.stop(); @@ -797,15 +631,11 @@ var B = /*#__PURE__*/ function(A) { key: "property_access_only_write_only_in_generator", value: function property_access_only_write_only_in_generator() { var _this = this; - var _super_x = function(_args) { - // property access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_x16 = function() { + var _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_x17 = function(_args) { - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_x18 = function(_args) { - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); + }, // property access (assign) + _superprop_set_x = function(_value) { + return _set(_getPrototypeOf(B.prototype), "x", _value, _this, true); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee7() { var f, ref; @@ -813,22 +643,22 @@ var B = /*#__PURE__*/ function(A) { while(1)switch(_ctx7.prev = _ctx7.next){ case 0: f = function() {}; - _super_x(f); + _superprop_set_x(f); ; // destructuring assign with property access (ref = { f: f - }, _super_x16() = ref.f, ref); + }, _superprop_get_x() = ref.f, ref); // property access (assign) in arrow (function() { - return _super_x17(f); + return _superprop_set_x(f); }); // property access (assign) in async arrow _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_x18(f)); + return _ctx.abrupt("return", _superprop_set_x(f)); case 1: case "end": return _ctx.stop(); @@ -847,49 +677,27 @@ var B = /*#__PURE__*/ function(A) { key: "element_access_only_read_only_in_generator", value: function element_access_only_read_only_in_generator() { var _this = this; - var // call with element access - _instance, _instance14, _instance15; - var _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method13 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method14 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance14 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance14, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method15 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance15 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance15, [ - _this - ].concat(_toConsumableArray(_args))); + var _this6 = this, // call with element access + _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee8() { var a; return regeneratorRuntime.wrap(function _callee$(_ctx8) { while(1)switch(_ctx8.prev = _ctx8.next){ case 0: - _super_method(); - a = _super_method13(); + _superprop_get("x").call(_this6); + a = _superprop_get("x"); // element access in arrow (function() { - return _super_method14(); + return _superprop_get("x").call(_this6); }); // element access in async arrow _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_method15()); + return _ctx.abrupt("return", _superprop_get("x").call(_this6)); case 1: case "end": return _ctx.stop(); @@ -908,15 +716,11 @@ var B = /*#__PURE__*/ function(A) { key: "element_access_only_write_only_in_generator", value: function element_access_only_write_only_in_generator() { var _this = this; - var _super_method = function(_args) { - // element access (assign) - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_method16 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method17 = function(_args) { - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); - }, _super_method18 = function(_args) { - return _set(_getPrototypeOf(B.prototype), "x", _args, _this, true); + var _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); + }, // element access (assign) + _superprop_set = function(_prop, _value) { + return _set(_getPrototypeOf(B.prototype), _prop, _value, _this, true); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee9() { var f, ref; @@ -924,22 +728,22 @@ var B = /*#__PURE__*/ function(A) { while(1)switch(_ctx9.prev = _ctx9.next){ case 0: f = function() {}; - _super_method(f); + _superprop_set("x", f); ; // destructuring assign with element access (ref = { f: f - }, _super_method16() = ref.f, ref); + }, _superprop_get("x") = ref.f, ref); // element access (assign) in arrow (function() { - return _super_method17(f); + return _superprop_set("x", f); }); // element access (assign) in async arrow _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_method18(f)); + return _ctx.abrupt("return", _superprop_set("x", f)); case 1: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es5.2.minified.js b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es5.2.minified.js index 7a049b5f6b3..728cf1e16db 100644 --- a/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/asyncMethodWithSuper_es6_es5.2.minified.js @@ -1,9 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - (null == len || len > arr.length) && (len = arr.length); - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} function AsyncGenerator(gen) { var front, back; function resume(key, arg) { @@ -140,23 +135,6 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -function _toConsumableArray(arr) { - return (function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); - })(arr) || (function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); - })(arr) || _unsupportedIterableToArray(arr) || (function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - })(); -} -function _unsupportedIterableToArray(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } -} function _wrapAsyncGenerator(fn) { return function() { return new AsyncGenerator(fn.apply(this, arguments)); @@ -228,28 +206,17 @@ var A = function() { { key: "simple", value: function() { - var _instance, _instance1, _instance2, _this = this, _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_y = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance1 = _get(_getPrototypeOf(B.prototype), "y", _this)).call.apply(_instance1, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance2 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance2, [ - _this - ].concat(_toConsumableArray(_args))); + var _this = this, _this1 = this, _superprop_get_x = function() { + return _get(_getPrototypeOf(B.prototype), "x", _this); + }, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { var a, b; return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - _super_x(), _super_y(), _super_method(), a = _get(_getPrototypeOf(B.prototype), "x", _this), b = _get(_getPrototypeOf(B.prototype), "x", _this); + _superprop_get_x().call(_this1), _get(_getPrototypeOf(B.prototype), "y", _this).call(_this1), _superprop_get("x").call(_this1), a = _superprop_get_x(), b = _superprop_get("x"); case 5: case "end": return _ctx.stop(); @@ -261,46 +228,26 @@ var A = function() { { key: "advanced", value: function() { - var _instance, _instance3, _instance4, _instance5, _this = this, _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance3 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance3, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x1 = function() { + var _this = this, _this2 = this, _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_method1 = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); - }, _super_x2 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance4 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance4, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method2 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance5 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance5, [ - _this - ].concat(_toConsumableArray(_args))); + }, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee1() { var f, a, b, ref, ref1; return regeneratorRuntime.wrap(function(_ctx1) { for(;;)switch(_ctx1.prev = _ctx1.next){ case 0: - var _args, _args1; - f = function() {}, _super_x(), _super_method(), a = _get(_getPrototypeOf(B.prototype), "x", _this), b = _get(_getPrototypeOf(B.prototype), "x", _this), _args = f, _set(_getPrototypeOf(B.prototype), "x", _args, _this, !0), _args1 = f, _set(_getPrototypeOf(B.prototype), "x", _args1, _this, !0), ref = { + var _value, _value1; + f = function() {}, _superprop_get_x().call(_this2), _superprop_get("x").call(_this2), a = _superprop_get_x(), b = _superprop_get("x"), _value = f, _set(_getPrototypeOf(B.prototype), "x", _value, _this, !0), _value1 = f, _set(_getPrototypeOf(B.prototype), "x", _value1, _this, !0), ref = { f: f - }, _super_x1() = ref.f, ref1 = { + }, _superprop_get_x() = ref.f, ref1 = { f: f - }, _super_method1() = ref1.f, _asyncToGenerator(regeneratorRuntime.mark(function _callee() { + }, _superprop_get("x") = ref1.f, _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_x2()); + return _ctx.abrupt("return", _superprop_get_x().call(_this2)); case 1: case "end": return _ctx.stop(); @@ -310,7 +257,7 @@ var A = function() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_method2()); + return _ctx.abrupt("return", _superprop_get("x").call(_this2)); case 1: case "end": return _ctx.stop(); @@ -328,27 +275,19 @@ var A = function() { { key: "property_access_only_read_only", value: function() { - var _instance, _instance6, _this = this, _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x3 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance6 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance6, [ - _this - ].concat(_toConsumableArray(_args))); + var _this = this, _this3 = this, _superprop_get_x = function() { + return _get(_getPrototypeOf(B.prototype), "x", _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee2() { var a; return regeneratorRuntime.wrap(function(_ctx2) { for(;;)switch(_ctx2.prev = _ctx2.next){ case 0: - _super_x(), a = _get(_getPrototypeOf(B.prototype), "x", _this), _asyncToGenerator(regeneratorRuntime.mark(function _callee() { + _superprop_get_x().call(_this3), a = _superprop_get_x(), _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_x3()); + return _ctx.abrupt("return", _superprop_get_x().call(_this3)); case 1: case "end": return _ctx.stop(); @@ -366,23 +305,23 @@ var A = function() { { key: "property_access_only_write_only", value: function() { - var _this = this, _super_x = function() { + var _this = this, _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, _superprop_set_x = function(_value) { + return _set(_getPrototypeOf(B.prototype), "x", _value, _this, !0); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee3() { var f, ref; return regeneratorRuntime.wrap(function(_ctx3) { for(;;)switch(_ctx3.prev = _ctx3.next){ case 0: - var _args2; - _args2 = f = function() {}, _set(_getPrototypeOf(B.prototype), "x", _args2, _this, !0), ref = { + _superprop_set_x(f = function() {}), ref = { f: f - }, _super_x() = ref.f, _asyncToGenerator(regeneratorRuntime.mark(function _callee() { + }, _superprop_get_x() = ref.f, _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - var _args; - return _ctx.abrupt("return", (_args = f, _set(_getPrototypeOf(B.prototype), "x", _args, _this, !0))); + return _ctx.abrupt("return", _superprop_set_x(f)); case 1: case "end": return _ctx.stop(); @@ -400,27 +339,19 @@ var A = function() { { key: "element_access_only_read_only", value: function() { - var _instance, _instance7, _this = this, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method3 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance7 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance7, [ - _this - ].concat(_toConsumableArray(_args))); + var _this = this, _this4 = this, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee4() { var a; return regeneratorRuntime.wrap(function(_ctx4) { for(;;)switch(_ctx4.prev = _ctx4.next){ case 0: - _super_method(), a = _get(_getPrototypeOf(B.prototype), "x", _this), _asyncToGenerator(regeneratorRuntime.mark(function _callee() { + _superprop_get("x").call(_this4), a = _superprop_get("x"), _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_method3()); + return _ctx.abrupt("return", _superprop_get("x").call(_this4)); case 1: case "end": return _ctx.stop(); @@ -438,23 +369,23 @@ var A = function() { { key: "element_access_only_write_only", value: function() { - var _this = this, _super_method = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); + var _this = this, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); + }, _superprop_set = function(_prop, _value) { + return _set(_getPrototypeOf(B.prototype), _prop, _value, _this, !0); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee5() { var f, ref; return regeneratorRuntime.wrap(function(_ctx5) { for(;;)switch(_ctx5.prev = _ctx5.next){ case 0: - var _args3; - _args3 = f = function() {}, _set(_getPrototypeOf(B.prototype), "x", _args3, _this, !0), ref = { + _superprop_set("x", f = function() {}), ref = { f: f - }, _super_method() = ref.f, _asyncToGenerator(regeneratorRuntime.mark(function _callee() { + }, _superprop_get("x") = ref.f, _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - var _args; - return _ctx.abrupt("return", (_args = f, _set(_getPrototypeOf(B.prototype), "x", _args, _this, !0))); + return _ctx.abrupt("return", _superprop_set("x", f)); case 1: case "end": return _ctx.stop(); @@ -472,27 +403,19 @@ var A = function() { { key: "property_access_only_read_only_in_generator", value: function() { - var _instance, _instance8, _this = this, _super_x = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_x4 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance8 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance8, [ - _this - ].concat(_toConsumableArray(_args))); + var _this = this, _this5 = this, _superprop_get_x = function() { + return _get(_getPrototypeOf(B.prototype), "x", _this); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee6() { var a; return regeneratorRuntime.wrap(function(_ctx6) { for(;;)switch(_ctx6.prev = _ctx6.next){ case 0: - _super_x(), a = _get(_getPrototypeOf(B.prototype), "x", _this), _asyncToGenerator(regeneratorRuntime.mark(function _callee() { + _superprop_get_x().call(_this5), a = _superprop_get_x(), _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_x4()); + return _ctx.abrupt("return", _superprop_get_x().call(_this5)); case 1: case "end": return _ctx.stop(); @@ -510,23 +433,23 @@ var A = function() { { key: "property_access_only_write_only_in_generator", value: function() { - var _this = this, _super_x = function() { + var _this = this, _superprop_get_x = function() { return _get(_getPrototypeOf(B.prototype), "x", _this); + }, _superprop_set_x = function(_value) { + return _set(_getPrototypeOf(B.prototype), "x", _value, _this, !0); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee7() { var f, ref; return regeneratorRuntime.wrap(function(_ctx7) { for(;;)switch(_ctx7.prev = _ctx7.next){ case 0: - var _args4; - _args4 = f = function() {}, _set(_getPrototypeOf(B.prototype), "x", _args4, _this, !0), ref = { + _superprop_set_x(f = function() {}), ref = { f: f - }, _super_x() = ref.f, _asyncToGenerator(regeneratorRuntime.mark(function _callee() { + }, _superprop_get_x() = ref.f, _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - var _args; - return _ctx.abrupt("return", (_args = f, _set(_getPrototypeOf(B.prototype), "x", _args, _this, !0))); + return _ctx.abrupt("return", _superprop_set_x(f)); case 1: case "end": return _ctx.stop(); @@ -544,27 +467,19 @@ var A = function() { { key: "element_access_only_read_only_in_generator", value: function() { - var _instance, _instance9, _this = this, _super_method = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); - }, _super_method4 = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance9 = _get(_getPrototypeOf(B.prototype), "x", _this)).call.apply(_instance9, [ - _this - ].concat(_toConsumableArray(_args))); + var _this = this, _this6 = this, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee8() { var a; return regeneratorRuntime.wrap(function(_ctx8) { for(;;)switch(_ctx8.prev = _ctx8.next){ case 0: - _super_method(), a = _get(_getPrototypeOf(B.prototype), "x", _this), _asyncToGenerator(regeneratorRuntime.mark(function _callee() { + _superprop_get("x").call(_this6), a = _superprop_get("x"), _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", _super_method4()); + return _ctx.abrupt("return", _superprop_get("x").call(_this6)); case 1: case "end": return _ctx.stop(); @@ -582,23 +497,23 @@ var A = function() { { key: "element_access_only_write_only_in_generator", value: function() { - var _this = this, _super_method = function() { - return _get(_getPrototypeOf(B.prototype), "x", _this); + var _this = this, _superprop_get = function(_prop) { + return _get(_getPrototypeOf(B.prototype), _prop, _this); + }, _superprop_set = function(_prop, _value) { + return _set(_getPrototypeOf(B.prototype), _prop, _value, _this, !0); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee9() { var f, ref; return regeneratorRuntime.wrap(function(_ctx9) { for(;;)switch(_ctx9.prev = _ctx9.next){ case 0: - var _args5; - _args5 = f = function() {}, _set(_getPrototypeOf(B.prototype), "x", _args5, _this, !0), ref = { + _superprop_set("x", f = function() {}), ref = { f: f - }, _super_method() = ref.f, _asyncToGenerator(regeneratorRuntime.mark(function _callee() { + }, _superprop_get("x") = ref.f, _asyncToGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - var _args; - return _ctx.abrupt("return", (_args = f, _set(_getPrototypeOf(B.prototype), "x", _args, _this, !0))); + return _ctx.abrupt("return", _superprop_set("x", f)); case 1: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es2015.1.normal.js index de6549f55b3..b1cef945dc4 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es2015.1.normal.js @@ -154,9 +154,10 @@ class C7 { class C8 { g() {} f() { - return _wrapAsyncGenerator((function*() { - this.g(); - }).bind(this))(); + var _this = this; + return _wrapAsyncGenerator(function*() { + _this.g(); + })(); } } // @filename: C9.ts @@ -165,10 +166,10 @@ class B9 { } class C9 extends B9 { f() { - var _super_g = (..._args)=>super.g(..._args) + var _this = this, _superprop_get_g = ()=>super.g ; return _wrapAsyncGenerator(function*() { - _super_g(); + _superprop_get_g().call(_this); })(); } } diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.1.normal.js index 3cdbc8c0d5f..991c528e0b9 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.1.normal.js @@ -1,12 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -} function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -154,12 +146,6 @@ function _inherits(subClass, superClass) { }); if (superClass) _setPrototypeOf(subClass, superClass); } -function _iterableToArray(iter) { - if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); -} -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; @@ -180,21 +166,10 @@ function _superPropBase(object, property) { } return object; } -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); -} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; -function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(n); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); -} function _wrapAsyncGenerator(fn) { return function() { return new AsyncGenerator(fn.apply(this, arguments)); @@ -451,17 +426,18 @@ var C8 = // @filename: C8.ts { key: "f", value: function f() { + var _this = this; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - this.g(); + _this.g(); case 1: case "end": return _ctx.stop(); } - }, _callee, this); - }).bind(this))(); + }, _callee); + }))(); } } ]); @@ -494,20 +470,14 @@ var C9 = /*#__PURE__*/ function(B9) { key: "f", value: function f() { var _this = this; - var _instance; - var _super_g = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(C9.prototype), "g", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); + var _this1 = this, _superprop_get_g = function() { + return _get(_getPrototypeOf(C9.prototype), "g", _this); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - _super_g(); + _superprop_get_g().call(_this1); case 1: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.2.minified.js index 25672986778..fc08169cb19 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2015_es5.2.minified.js @@ -1,9 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - (null == len || len > arr.length) && (len = arr.length); - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} function AsyncGenerator(gen) { var front, back; function resume(key, arg) { @@ -310,17 +305,18 @@ var C1 = function() { { key: "f", value: function() { + var _this = this; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - this.g(); + _this.g(); case 1: case "end": return _ctx.stop(); } - }, _callee, this); - }).bind(this))(); + }, _callee); + }))(); } } ]), C8; @@ -377,30 +373,12 @@ var C1 = function() { { key: "f", value: function() { - var _instance, _this = this, _super_g = function() { - for(var arr, _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(C9.prototype), "g", _this)).call.apply(_instance, [ - _this - ].concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); - }(arr = _args) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); - }(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } - }(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - }())); - }; + var _this = this, _this1 = this; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - _super_g(); + _get(_getPrototypeOf(C9.prototype), "g", _this).call(_this1); case 1: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es2015.1.normal.js index f2dc05780a0..09d9f8e1dc7 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es2015.1.normal.js @@ -154,9 +154,10 @@ class C7 { class C8 { g() {} f() { - return _wrapAsyncGenerator((function*() { - this.g(); - }).bind(this))(); + var _this = this; + return _wrapAsyncGenerator(function*() { + _this.g(); + })(); } } // @filename: C9.ts @@ -165,10 +166,10 @@ class B9 { } class C9 extends B9 { f() { - var _super_g = (..._args)=>super.g(..._args) + var _this = this, _superprop_get_g = ()=>super.g ; return _wrapAsyncGenerator(function*() { - _super_g(); + _superprop_get_g().call(_this); })(); } } diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.1.normal.js index 773e1ec2353..d0f2ab8d25b 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.1.normal.js @@ -1,12 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -} function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -154,12 +146,6 @@ function _inherits(subClass, superClass) { }); if (superClass) _setPrototypeOf(subClass, superClass); } -function _iterableToArray(iter) { - if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); -} -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; @@ -180,21 +166,10 @@ function _superPropBase(object, property) { } return object; } -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); -} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; -function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(n); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); -} function _wrapAsyncGenerator(fn) { return function() { return new AsyncGenerator(fn.apply(this, arguments)); @@ -451,17 +426,18 @@ var C8 = // @filename: C8.ts { key: "f", value: function f() { + var _this = this; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - this.g(); + _this.g(); case 1: case "end": return _ctx.stop(); } - }, _callee, this); - }).bind(this))(); + }, _callee); + }))(); } } ]); @@ -494,20 +470,14 @@ var C9 = /*#__PURE__*/ function(B9) { key: "f", value: function f() { var _this = this; - var _instance; - var _super_g = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(C9.prototype), "g", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); + var _this1 = this, _superprop_get_g = function() { + return _get(_getPrototypeOf(C9.prototype), "g", _this); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - _super_g(); + _superprop_get_g().call(_this1); case 1: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.2.minified.js index 25672986778..fc08169cb19 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es2018_es5.2.minified.js @@ -1,9 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - (null == len || len > arr.length) && (len = arr.length); - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} function AsyncGenerator(gen) { var front, back; function resume(key, arg) { @@ -310,17 +305,18 @@ var C1 = function() { { key: "f", value: function() { + var _this = this; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - this.g(); + _this.g(); case 1: case "end": return _ctx.stop(); } - }, _callee, this); - }).bind(this))(); + }, _callee); + }))(); } } ]), C8; @@ -377,30 +373,12 @@ var C1 = function() { { key: "f", value: function() { - var _instance, _this = this, _super_g = function() { - for(var arr, _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(C9.prototype), "g", _this)).call.apply(_instance, [ - _this - ].concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); - }(arr = _args) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); - }(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } - }(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - }())); - }; + var _this = this, _this1 = this; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - _super_g(); + _get(_getPrototypeOf(C9.prototype), "g", _this).call(_this1); case 1: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es2015.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es2015.1.normal.js index fe0c09c08a9..1035a790a55 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es2015.1.normal.js @@ -154,9 +154,10 @@ class C7 { class C8 { g() {} f() { - return _wrapAsyncGenerator((function*() { - this.g(); - }).bind(this))(); + var _this = this; + return _wrapAsyncGenerator(function*() { + _this.g(); + })(); } } // @filename: C9.ts @@ -165,10 +166,10 @@ class B9 { } class C9 extends B9 { f() { - var _super_g = (..._args)=>super.g(..._args) + var _this = this, _superprop_get_g = ()=>super.g ; return _wrapAsyncGenerator(function*() { - _super_g(); + _superprop_get_g().call(_this); })(); } } diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.1.normal.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.1.normal.js index 433b95281c8..0d68bbbf3f5 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.1.normal.js @@ -1,12 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - if (len == null || len > arr.length) len = arr.length; - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); -} function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); @@ -154,12 +146,6 @@ function _inherits(subClass, superClass) { }); if (superClass) _setPrototypeOf(subClass, superClass); } -function _iterableToArray(iter) { - if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); -} -function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); -} function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; @@ -180,21 +166,10 @@ function _superPropBase(object, property) { } return object; } -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); -} var _typeof = function(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }; -function _unsupportedIterableToArray(o, minLen) { - if (!o) return; - if (typeof o === "string") return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if (n === "Object" && o.constructor) n = o.constructor.name; - if (n === "Map" || n === "Set") return Array.from(n); - if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); -} function _wrapAsyncGenerator(fn) { return function() { return new AsyncGenerator(fn.apply(this, arguments)); @@ -451,17 +426,18 @@ var C8 = // @filename: C8.ts { key: "f", value: function f() { + var _this = this; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - this.g(); + _this.g(); case 1: case "end": return _ctx.stop(); } - }, _callee, this); - }).bind(this))(); + }, _callee); + }))(); } } ]); @@ -494,20 +470,14 @@ var C9 = /*#__PURE__*/ function(B9) { key: "f", value: function f() { var _this = this; - var _instance; - var _super_g = function() { - for(var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++){ - _args[_key] = arguments[_key]; - } - return (_instance = _get(_getPrototypeOf(C9.prototype), "g", _this)).call.apply(_instance, [ - _this - ].concat(_toConsumableArray(_args))); + var _this1 = this, _superprop_get_g = function() { + return _get(_getPrototypeOf(C9.prototype), "g", _this); }; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function _callee$(_ctx) { while(1)switch(_ctx.prev = _ctx.next){ case 0: - _super_g(); + _superprop_get_g().call(_this1); case 1: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.2.minified.js b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.2.minified.js index 25672986778..fc08169cb19 100644 --- a/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/emitter.asyncGenerators.classMethods.es5_es5.2.minified.js @@ -1,9 +1,4 @@ import regeneratorRuntime from "regenerator-runtime"; -function _arrayLikeToArray(arr, len) { - (null == len || len > arr.length) && (len = arr.length); - for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i]; - return arr2; -} function AsyncGenerator(gen) { var front, back; function resume(key, arg) { @@ -310,17 +305,18 @@ var C1 = function() { { key: "f", value: function() { + var _this = this; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - this.g(); + _this.g(); case 1: case "end": return _ctx.stop(); } - }, _callee, this); - }).bind(this))(); + }, _callee); + }))(); } } ]), C8; @@ -377,30 +373,12 @@ var C1 = function() { { key: "f", value: function() { - var _instance, _this = this, _super_g = function() { - for(var arr, _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++)_args[_key] = arguments[_key]; - return (_instance = _get(_getPrototypeOf(C9.prototype), "g", _this)).call.apply(_instance, [ - _this - ].concat(function(arr) { - if (Array.isArray(arr)) return _arrayLikeToArray(arr); - }(arr = _args) || function(iter) { - if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter); - }(arr) || function(o, minLen) { - if (o) { - if ("string" == typeof o) return _arrayLikeToArray(o, minLen); - var n = Object.prototype.toString.call(o).slice(8, -1); - if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n); - if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); - } - }(arr) || function() { - throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); - }())); - }; + var _this = this, _this1 = this; return _wrapAsyncGenerator(regeneratorRuntime.mark(function _callee() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - _super_g(); + _get(_getPrototypeOf(C9.prototype), "g", _this).call(_this1); case 1: case "end": return _ctx.stop(); diff --git a/crates/swc/tests/tsc-references/superMethodCall_es2015.1.normal.js b/crates/swc/tests/tsc-references/superMethodCall_es2015.1.normal.js index 75c7f7edd16..ffcd49eb216 100644 --- a/crates/swc/tests/tsc-references/superMethodCall_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/superMethodCall_es2015.1.normal.js @@ -38,11 +38,11 @@ class Derived extends Base { return (ref = super.method) === null || ref === void 0 ? void 0 : ref.call(this); } asyncMethod() { - var _super_method = ()=>super.method + var _this = this, _superprop_get_method = ()=>super.method ; - return _asyncToGenerator((function*() { + return _asyncToGenerator(function*() { var ref; - return (ref = _super_method()) === null || ref === void 0 ? void 0 : ref.call(this); - }).bind(this))(); + return (ref = _superprop_get_method()) === null || ref === void 0 ? void 0 : ref.call(_this); + })(); } } diff --git a/crates/swc/tests/tsc-references/superMethodCall_es5.1.normal.js b/crates/swc/tests/tsc-references/superMethodCall_es5.1.normal.js index 0d7dff550fe..5e87d725add 100644 --- a/crates/swc/tests/tsc-references/superMethodCall_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/superMethodCall_es5.1.normal.js @@ -171,7 +171,7 @@ var Derived = /*#__PURE__*/ function(Base) { key: "asyncMethod", value: function asyncMethod() { var _this = this; - var _super_method = function() { + var _this1 = this, _superprop_get_method = function() { return _get(_getPrototypeOf(Derived.prototype), "method", _this); }; return _asyncToGenerator(regeneratorRuntime.mark(function _callee() { @@ -180,13 +180,13 @@ var Derived = /*#__PURE__*/ function(Base) { while(1)switch(_ctx.prev = _ctx.next){ case 0: ; - return _ctx.abrupt("return", (ref = _super_method()) === null || ref === void 0 ? void 0 : ref.call(this)); + return _ctx.abrupt("return", (ref = _superprop_get_method()) === null || ref === void 0 ? void 0 : ref.call(_this1)); case 2: case "end": return _ctx.stop(); } - }, _callee, this); - }).bind(this))(); + }, _callee); + }))(); } } ]); diff --git a/crates/swc/tests/tsc-references/superMethodCall_es5.2.minified.js b/crates/swc/tests/tsc-references/superMethodCall_es5.2.minified.js index 470f34d10a1..555ad721f37 100644 --- a/crates/swc/tests/tsc-references/superMethodCall_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/superMethodCall_es5.2.minified.js @@ -103,7 +103,7 @@ var Base = function() { { key: "asyncMethod", value: function() { - var _this = this; + var _this = this, _this1 = this; return (function(fn) { return function() { var self = this, args = arguments; @@ -123,13 +123,13 @@ var Base = function() { return regeneratorRuntime.wrap(function(_ctx) { for(;;)switch(_ctx.prev = _ctx.next){ case 0: - return _ctx.abrupt("return", null === (ref = _get(_getPrototypeOf(Derived1.prototype), "method", _this)) || void 0 === ref ? void 0 : ref.call(this)); + return _ctx.abrupt("return", null === (ref = _get(_getPrototypeOf(Derived1.prototype), "method", _this)) || void 0 === ref ? void 0 : ref.call(_this1)); case 2: case "end": return _ctx.stop(); } - }, _callee, this); - }).bind(this))(); + }, _callee); + }))(); } } ]), Derived1; diff --git a/crates/swc_ecma_ast/src/operators.rs b/crates/swc_ecma_ast/src/operators.rs index 031dce17118..8cdfaa5706f 100644 --- a/crates/swc_ecma_ast/src/operators.rs +++ b/crates/swc_ecma_ast/src/operators.rs @@ -151,6 +151,30 @@ pub enum AssignOp { NullishAssign, } +impl AssignOp { + pub fn to_update(self) -> Option { + match self { + op!("=") => None, + + op!("+=") => Some(op!(bin, "+")), + op!("-=") => Some(op!(bin, "-")), + op!("*=") => Some(op!("*")), + op!("/=") => Some(op!("/")), + op!("%=") => Some(op!("%")), + op!("<<=") => Some(op!("<<")), + op!(">>=") => Some(op!(">>")), + op!(">>>=") => Some(op!(">>>")), + op!("|=") => Some(op!("|")), + op!("&=") => Some(op!("&")), + op!("^=") => Some(op!("^")), + op!("**=") => Some(op!("**")), + op!("&&=") => Some(op!("&&")), + op!("||=") => Some(op!("||")), + op!("??=") => Some(op!("??")), + } + } +} + #[derive(StringEnum, Clone, Copy, Eq, PartialEq, PartialOrd, Ord, Hash, EqIgnoreSpan)] #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[cfg_attr( diff --git a/crates/swc_ecma_transforms_classes/src/super_field.rs b/crates/swc_ecma_transforms_classes/src/super_field.rs index 288b28ff90f..f18bfd4edc7 100644 --- a/crates/swc_ecma_transforms_classes/src/super_field.rs +++ b/crates/swc_ecma_transforms_classes/src/super_field.rs @@ -424,25 +424,7 @@ impl<'a> SuperFieldAccessFolder<'a> { BinExpr { span: DUMMY_SP, left, - op: match op { - op!("=") => unreachable!(), - - op!("+=") => op!(bin, "+"), - op!("-=") => op!(bin, "-"), - op!("*=") => op!("*"), - op!("/=") => op!("/"), - op!("%=") => op!("%"), - op!("<<=") => op!("<<"), - op!(">>=") => op!(">>"), - op!(">>>=") => op!(">>>"), - op!("|=") => op!("|"), - op!("&=") => op!("&"), - op!("^=") => op!("^"), - op!("**=") => op!("**"), - op!("&&=") => op!("&&"), - op!("||=") => op!("||"), - op!("??=") => op!("??"), - }, + op: op.to_update().unwrap(), right: rhs, } .as_arg() diff --git a/crates/swc_ecma_transforms_compat/src/es2015/arrow.rs b/crates/swc_ecma_transforms_compat/src/es2015/arrow.rs index 72ce2c72737..e969e3be438 100644 --- a/crates/swc_ecma_transforms_compat/src/es2015/arrow.rs +++ b/crates/swc_ecma_transforms_compat/src/es2015/arrow.rs @@ -3,7 +3,7 @@ use std::mem; use swc_common::{util::take::Take, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_utils::{ - function::{init_this, FnEnvHoister, FnEnvState}, + function::{init_this, FnEnvHoister}, prepend, }; use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, InjectVars, VisitMut, VisitMutWith}; @@ -63,7 +63,7 @@ pub fn arrow() -> impl Fold + VisitMut + InjectVars { #[derive(Default)] struct Arrow { in_subclass: bool, - state: FnEnvState, + hoister: FnEnvHoister, } impl VisitMut for Arrow { @@ -73,12 +73,13 @@ impl VisitMut for Arrow { c.params.visit_mut_children_with(self); if let Some(BlockStmt { span: _, stmts }) = &mut c.body { - let old_rep = self.state.take(); + let old_rep = self.hoister.take(); stmts.visit_mut_children_with(self); if self.in_subclass { - let (decl, this_id) = mem::replace(&mut self.state, old_rep).to_stmt_in_subclass(); + let (decl, this_id) = + mem::replace(&mut self.hoister, old_rep).to_stmt_in_subclass(); if let Some(stmt) = decl { if let Some(this_id) = this_id { @@ -87,7 +88,7 @@ impl VisitMut for Arrow { prepend(stmts, stmt); } } else { - let decl = mem::replace(&mut self.state, old_rep).to_stmt(); + let decl = mem::replace(&mut self.hoister, old_rep).to_stmt(); if let Some(stmt) = decl { prepend(stmts, stmt); @@ -115,7 +116,7 @@ impl VisitMut for Arrow { .. }) => { params.visit_mut_with(self); - params.visit_mut_with(&mut FnEnvHoister::new(&mut self.state)); + params.visit_mut_with(&mut self.hoister); let params: Vec = params .take() @@ -129,7 +130,7 @@ impl VisitMut for Arrow { body.visit_mut_with(self); - body.visit_mut_with(&mut FnEnvHoister::new(&mut self.state)); + body.visit_mut_with(&mut self.hoister); let fn_expr = Expr::Fn(FnExpr { ident: None, @@ -155,7 +156,6 @@ impl VisitMut for Arrow { }); *expr = fn_expr; - return; } _ => { expr.visit_mut_children_with(self); @@ -170,7 +170,7 @@ impl VisitMut for Arrow { fn visit_mut_module_items(&mut self, stmts: &mut Vec) { stmts.visit_mut_children_with(self); - let decl = self.state.take().to_stmt(); + let decl = self.hoister.take().to_stmt(); if let Some(stmt) = decl { prepend(stmts, ModuleItem::Stmt(stmt)); @@ -178,11 +178,11 @@ impl VisitMut for Arrow { } fn visit_mut_stmts(&mut self, stmts: &mut Vec) { - let old_rep = self.state.take(); + let old_rep = self.hoister.take(); stmts.visit_mut_children_with(self); - let decl = mem::replace(&mut self.state, old_rep).to_stmt(); + let decl = mem::replace(&mut self.hoister, old_rep).to_stmt(); if let Some(stmt) = decl { prepend(stmts, stmt); @@ -192,6 +192,6 @@ impl VisitMut for Arrow { impl InjectVars for Arrow { fn take_vars(&mut self) -> Vec { - self.state.take().to_decl() + self.hoister.take().to_decl() } } diff --git a/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs b/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs index 9085532ea7e..911cfb4fd8b 100644 --- a/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs +++ b/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs @@ -353,25 +353,7 @@ impl SuperReplacer { BinExpr { span: DUMMY_SP, left, - op: match op { - op!("=") => unreachable!(), - - op!("+=") => op!(bin, "+"), - op!("-=") => op!(bin, "-"), - op!("*=") => op!("*"), - op!("/=") => op!("/"), - op!("%=") => op!("%"), - op!("<<=") => op!("<<"), - op!(">>=") => op!(">>"), - op!(">>>=") => op!(">>>"), - op!("|=") => op!("|"), - op!("&=") => op!("&"), - op!("^=") => op!("^"), - op!("**=") => op!("**"), - op!("&&=") => op!("&&"), - op!("||=") => op!("||"), - op!("??=") => op!("??"), - }, + op: op.to_update().unwrap(), right: rhs, } } diff --git a/crates/swc_ecma_transforms_compat/src/es2015/parameters.rs b/crates/swc_ecma_transforms_compat/src/es2015/parameters.rs index 9242a263801..8a4cc611bc6 100644 --- a/crates/swc_ecma_transforms_compat/src/es2015/parameters.rs +++ b/crates/swc_ecma_transforms_compat/src/es2015/parameters.rs @@ -8,7 +8,7 @@ use swc_ecma_ast::*; // use swc_ecma_transforms_base::perf::Parallel; // use swc_ecma_transforms_macros::parallel; use swc_ecma_utils::{ - function::{init_this, FnEnvHoister, FnEnvState}, + function::{init_this, FnEnvHoister}, member_expr, prepend, prepend_stmts, private_ident, quote_ident, undefined, ExprFactory, }; use swc_ecma_visit::{as_folder, noop_visit_mut_type, Fold, VisitMut, VisitMutWith}; @@ -21,11 +21,11 @@ pub fn parameters(c: Config) -> impl 'static + Fold { }) } -#[derive(Clone, Default)] +#[derive(Default)] struct Params { /// Used to store `this, in case if `arguments` is used and we should /// transform an arrow expression to a function expression. - state: FnEnvState, + hoister: FnEnvHoister, in_subclass: bool, c: Config, } @@ -398,11 +398,11 @@ impl VisitMut for Params { noop_visit_mut_type!(); fn visit_mut_block_stmt_or_expr(&mut self, body: &mut BlockStmtOrExpr) { - let old_rep = self.state.take(); + let old_rep = self.hoister.take(); body.visit_mut_children_with(self); - let decls = mem::replace(&mut self.state, old_rep).to_stmt(); + let decls = mem::replace(&mut self.hoister, old_rep).to_stmt(); if let Some(decls) = decls { if let BlockStmtOrExpr::Expr(v) = body { @@ -453,12 +453,13 @@ impl VisitMut for Params { f.params.visit_mut_with(self); if let Some(BlockStmt { span: _, stmts }) = &mut f.body { - let old_rep = self.state.take(); + let old_rep = self.hoister.take(); stmts.visit_mut_children_with(self); if self.in_subclass { - let (decl, this_id) = mem::replace(&mut self.state, old_rep).to_stmt_in_subclass(); + let (decl, this_id) = + mem::replace(&mut self.hoister, old_rep).to_stmt_in_subclass(); if let Some(stmt) = decl { if let Some(this_id) = this_id { @@ -467,7 +468,7 @@ impl VisitMut for Params { prepend(stmts, stmt); } } else { - let decl = mem::replace(&mut self.state, old_rep).to_stmt(); + let decl = mem::replace(&mut self.hoister, old_rep).to_stmt(); if let Some(stmt) = decl { prepend(stmts, stmt); @@ -486,10 +487,7 @@ impl VisitMut for Params { Expr::Arrow(f) => { f.visit_mut_children_with(self); - let was_expr = match f.body { - BlockStmtOrExpr::Expr(..) => true, - _ => false, - }; + let was_expr = f.body.is_expr(); let need_arrow_to_function = f.params.iter().any(|p| match p { Pat::Rest(..) => true, @@ -499,7 +497,7 @@ impl VisitMut for Params { // this needs to happen before rest parameter transform if need_arrow_to_function { - f.visit_mut_children_with(&mut FnEnvHoister::new(&mut self.state)); + f.visit_mut_children_with(&mut self.hoister); } let body_span = f.body.span(); @@ -635,7 +633,7 @@ impl VisitMut for Params { fn visit_mut_module_items(&mut self, stmts: &mut Vec) { stmts.visit_mut_children_with(self); - let decl = self.state.take().to_stmt(); + let decl = self.hoister.take().to_stmt(); if let Some(stmt) = decl { prepend(stmts, ModuleItem::Stmt(stmt)); @@ -643,11 +641,11 @@ impl VisitMut for Params { } fn visit_mut_stmts(&mut self, stmts: &mut Vec) { - let old_rep = self.state.take(); + let old_rep = self.hoister.take(); stmts.visit_mut_children_with(self); - let decl = mem::replace(&mut self.state, old_rep).to_stmt(); + let decl = mem::replace(&mut self.hoister, old_rep).to_stmt(); if let Some(stmt) = decl { prepend(stmts, stmt); diff --git a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs index e7333e4ab11..87bdccf7b04 100644 --- a/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/src/es2017/async_to_generator.rs @@ -1,11 +1,11 @@ -use std::{iter, mem::replace}; -use swc_common::{util::take::Take, Mark, Span, Spanned, DUMMY_SP}; +use std::iter; +use swc_common::{util::take::Take, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_transforms_base::{helper, perf::Check}; use swc_ecma_transforms_macros::fast_path; use swc_ecma_utils::{ contains_this_expr, - function::{FnEnvHoister, FnEnvState, FnWrapperResult, FunctionWrapper}, + function::{FnEnvHoister, FnWrapperResult, FunctionWrapper}, private_ident, quote_ident, ExprFactory, StmtLike, }; use swc_ecma_visit::{ @@ -86,28 +86,6 @@ impl AsyncToGenerator { impl VisitMut for Actual { noop_visit_mut_type!(); - /// Removes nested binds like `(function(){}).bind(this).bind(this)` - fn visit_mut_call_expr(&mut self, n: &mut CallExpr) { - n.visit_mut_children_with(self); - - if let Some(callee) = extract_callee_of_bind_this(n) { - if let Expr::Call(callee_of_callee) = callee { - if let Some(..) = extract_callee_of_bind_this(callee_of_callee) { - // We found bind(this).bind(this) - *n = replace( - callee_of_callee, - CallExpr { - span: DUMMY_SP, - callee: Callee::Super(Super { span: DUMMY_SP }), - args: Default::default(), - type_args: Default::default(), - }, - ); - } - } - } - } - fn visit_mut_class_method(&mut self, m: &mut ClassMethod) { if m.function.body.is_none() { return; @@ -117,33 +95,15 @@ impl VisitMut for Actual { } let params = m.function.params.clone(); - let mut folder = MethodFolder { - vars: vec![], - scope_ident: FnEnvState::default(), - }; + let mut visitor = FnEnvHoister::default(); m.function.params.clear(); - m.function.visit_mut_children_with(&mut folder); + m.function.body.visit_mut_with(&mut visitor); - let expr = make_fn_ref( - FnExpr { - ident: None, - function: m.function.take(), - }, - None, - false, - ); - - let hoisted_super = if folder.vars.is_empty() { - None - } else { - Some(Stmt::Decl(Decl::Var(VarDecl { - span: DUMMY_SP, - kind: VarDeclKind::Var, - decls: folder.vars, - declare: false, - }))) - }; + let expr = make_fn_ref(FnExpr { + ident: None, + function: m.function.take(), + }); m.function = Function { span: m.span, @@ -152,9 +112,9 @@ impl VisitMut for Actual { params, body: Some(BlockStmt { span: DUMMY_SP, - stmts: hoisted_super + stmts: visitor + .to_stmt() .into_iter() - .chain(folder.scope_ident.to_stmt()) .chain(iter::once(Stmt::Return(ReturnStmt { span: DUMMY_SP, arg: Some(Box::new(Expr::Call(CallExpr { @@ -186,7 +146,7 @@ impl VisitMut for Actual { let fn_expr = wrapper.function.fn_expr().unwrap(); - wrapper.function = make_fn_ref(fn_expr, None, true); + wrapper.function = make_fn_ref(fn_expr); let FnWrapperResult { name_fn, ref_fn } = wrapper.into(); *f = name_fn; @@ -203,7 +163,7 @@ impl VisitMut for Actual { let fn_expr = wrapper.function.fn_expr().unwrap(); - wrapper.function = make_fn_ref(fn_expr, None, true); + wrapper.function = make_fn_ref(fn_expr); let FnWrapperResult { name_fn, ref_fn } = wrapper.into(); @@ -243,17 +203,13 @@ impl VisitMut for Actual { }; prop.function.span = prop_method_body_span; - let fn_ref = make_fn_ref( - FnExpr { - ident: None, - function: Function { - params: vec![], - ..prop.function.take() - }, + let fn_ref = make_fn_ref(FnExpr { + ident: None, + function: Function { + params: vec![], + ..prop.function.take() }, - None, - true, - ); + }); let fn_ref = if is_this_used { fn_ref.apply( @@ -319,260 +275,15 @@ impl VisitMut for Actual { } } -/// Hoists super access -/// -/// ## In -/// -/// ```js -/// class Foo { -/// async foo () { -/// super.getter -/// super.setter = 1 -/// super.method() -/// } -/// } -/// ``` -/// -/// ## OUt -/// -/// ```js -/// class Foo { -/// var _super_getter = () => super.getter; -/// var _super_setter = (v) => super.setter = v; -/// var _super_method = (...args) => super.method(args); -/// foo () { -/// super.getter -/// super.setter = 1 -/// super.method() -/// } -/// } -/// ``` -struct MethodFolder { - vars: Vec, - scope_ident: FnEnvState, -} - -impl MethodFolder { - fn handle_assign_to_super_prop( - &mut self, - span: Span, - left: SuperPropExpr, - op: AssignOp, - right: Box, - ) -> Expr { - let SuperPropExpr { - span: m_span, - obj, - prop, - } = left; - - let (mark, ident) = self.ident_for_super(&prop); - let args_ident = quote_ident!(DUMMY_SP.apply_mark(mark), "_args"); - - self.vars.push(VarDeclarator { - span: DUMMY_SP, - name: ident.clone().into(), - init: Some(Box::new(Expr::Arrow(ArrowExpr { - span: DUMMY_SP, - is_async: false, - is_generator: false, - params: vec![args_ident.clone().into()], - body: BlockStmtOrExpr::Expr(Box::new(Expr::Assign(AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Expr(Box::new( - SuperPropExpr { - span: m_span, - obj, - prop, - } - .into(), - )), - op, - right: Box::new(args_ident.into()), - }))), - type_params: Default::default(), - return_type: Default::default(), - }))), - definite: false, - }); - - Expr::Call(CallExpr { - span, - callee: ident.as_callee(), - args: vec![right.as_arg()], - type_args: Default::default(), - }) - } - fn ident_for_super(&mut self, prop: &SuperProp) -> (Mark, Ident) { - let mark = Mark::fresh(Mark::root()); - let prop_span = prop.span(); - let mut ident = match *prop { - SuperProp::Ident(ref ident) => quote_ident!(prop_span, format!("_super_{}", ident.sym)), - _ => quote_ident!(prop_span, "_super_method"), - }; - ident.span = ident.span.apply_mark(mark); - (mark, ident) - } -} - -impl VisitMut for MethodFolder { - noop_visit_mut_type!(); - - fn visit_mut_expr(&mut self, expr: &mut Expr) { - match expr { - // TODO: handle arrow with this in constructor once we remove all this bind - Expr::Arrow(ArrowExpr { body, .. }) => { - body.visit_mut_with(&mut FnEnvHoister::new(&mut self.scope_ident)); - } - Expr::Fn(FnExpr { - function: Function { - body: Some(body), .. - }, - .. - }) => { - body.visit_mut_with(&mut FnEnvHoister::new(&mut self.scope_ident)); - } - _ => {} - }; - - // TODO(kdy): Cache (Reuse declaration for same property) - - match expr { - // super.setter = 1 - Expr::Assign(AssignExpr { - span, - left: PatOrExpr::Expr(left), - op, - right, - }) if left.is_super_prop() => { - *expr = self.handle_assign_to_super_prop( - *span, - left.take().expect_super_prop(), - *op, - right.take(), - ); - } - - // super.setter = 1 - Expr::Assign(AssignExpr { - span, - left: PatOrExpr::Pat(left), - op, - right, - }) if match &**left { - Pat::Expr(left) => left.is_super_prop(), - _ => false, - } => - { - *expr = self.handle_assign_to_super_prop( - *span, - left.take().expect_expr().expect_super_prop(), - *op, - right.take(), - ); - return; - } - - // super.method() - Expr::Call(CallExpr { - span, - callee: Callee::Expr(callee), - args, - type_args, - }) if callee.is_super_prop() => { - let SuperPropExpr { obj, prop, .. } = callee.take().expect_super_prop(); - - let (mark, ident) = self.ident_for_super(&prop); - let args_ident = quote_ident!(DUMMY_SP.apply_mark(mark), "_args"); - - self.vars.push(VarDeclarator { - span: DUMMY_SP, - name: ident.clone().into(), - init: Some(Box::new(Expr::Arrow(ArrowExpr { - span: DUMMY_SP, - is_async: false, - is_generator: false, - params: vec![Pat::Rest(RestPat { - span: DUMMY_SP, - dot3_token: DUMMY_SP, - arg: args_ident.clone().into(), - type_ann: Default::default(), - })], - body: BlockStmtOrExpr::Expr(Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: SuperPropExpr { - span: DUMMY_SP, - obj, - prop, - } - .as_callee(), - args: vec![ExprOrSpread { - spread: Some(DUMMY_SP), - expr: Box::new(args_ident.into()), - }], - type_args: Default::default(), - }))), - type_params: Default::default(), - return_type: Default::default(), - }))), - definite: false, - }); - - *expr = Expr::Call(CallExpr { - span: *span, - callee: ident.as_callee(), - args: args.take(), - type_args: type_args.take(), - }); - } - // super.getter - Expr::SuperProp(SuperPropExpr { span, obj, prop }) => { - let (_, ident) = self.ident_for_super(&prop); - self.vars.push(VarDeclarator { - span: DUMMY_SP, - name: ident.clone().into(), - init: Some(Box::new(Expr::Arrow(ArrowExpr { - span: DUMMY_SP, - is_async: false, - is_generator: false, - params: vec![], - body: BlockStmtOrExpr::Expr(Box::new( - SuperPropExpr { - span: DUMMY_SP, - obj: obj.take(), - prop: prop.take(), - } - .into(), - )), - type_params: Default::default(), - return_type: Default::default(), - }))), - definite: false, - }); - - *expr = Expr::Call(CallExpr { - span: *span, - callee: ident.as_callee(), - args: vec![], - type_args: Default::default(), - }) - } - _ => expr.visit_mut_children_with(self), - } - } -} - impl Actual { fn visit_mut_expr_with_binding(&mut self, expr: &mut Expr, binding_ident: Option) { expr.visit_mut_children_with(self); match expr { Expr::Arrow(arrow_expr @ ArrowExpr { is_async: true, .. }) => { - let mut state = FnEnvState::default(); + let mut state = FnEnvHoister::default(); - arrow_expr - .body - .visit_mut_with(&mut FnEnvHoister::new(&mut state)); + arrow_expr.body.visit_mut_with(&mut state); self.hoist_stmts.extend(state.to_stmt()); @@ -581,8 +292,7 @@ impl Actual { let fn_expr = wrapper.function.expect_fn_expr(); - // We should not bind `this` in FunctionWrapper - wrapper.function = make_fn_ref(fn_expr, None, true); + wrapper.function = make_fn_ref(fn_expr); *expr = wrapper.into(); } @@ -597,7 +307,7 @@ impl Actual { let fn_expr = wrapper.function.expect_fn_expr(); - wrapper.function = make_fn_ref(fn_expr, None, true); + wrapper.function = make_fn_ref(fn_expr); *expr = wrapper.into(); } @@ -610,11 +320,7 @@ impl Actual { /// Creates /// /// `_asyncToGenerator(function*() {})` from `async function() {}`; -fn make_fn_ref( - mut expr: FnExpr, - this_expr: Option, - should_not_bind_this: bool, -) -> Expr { +fn make_fn_ref(mut expr: FnExpr) -> Expr { expr.function.body.visit_mut_with(&mut AsyncFnBodyHandler { is_async_generator: expr.function.is_generator, }); @@ -632,17 +338,7 @@ fn make_fn_ref( let span = expr.span(); - let should_bind_this = !should_not_bind_this && contains_this_expr(&expr.function.body); - let expr = if should_bind_this { - Expr::Call(CallExpr { - span: DUMMY_SP, - callee: expr.make_member(quote_ident!("bind")).as_callee(), - args: vec![this_expr.unwrap_or(ThisExpr { span: DUMMY_SP }.as_arg())], - type_args: Default::default(), - }) - } else { - Expr::Fn(expr) - }; + let expr = Expr::Fn(expr); Expr::Call(CallExpr { span, @@ -739,28 +435,6 @@ impl Check for ShouldWork { } } -fn extract_callee_of_bind_this(n: &mut CallExpr) -> Option<&mut Expr> { - if n.args.len() != 1 { - return None; - } - - match &*n.args[0].expr { - Expr::This(..) => {} - _ => return None, - } - - match &mut n.callee { - Callee::Super(_) | Callee::Import(_) => None, - Callee::Expr(callee) => match &mut **callee { - Expr::Member(MemberExpr { - prop: MemberProp::Ident(Ident { sym, .. }), - .. - }) if *sym == *"bind" => Some(&mut **callee), - _ => None, - }, - } -} - fn handle_await_for(stmt: &mut Stmt, is_async_generator: bool) { let s = match stmt { Stmt::ForOf( diff --git a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/private_field.rs b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/private_field.rs index 0d9c8a45c50..4b1948c9714 100644 --- a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/private_field.rs +++ b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/private_field.rs @@ -336,25 +336,7 @@ impl<'a> VisitMut for FieldAccessFolder<'a> { BinExpr { span: DUMMY_SP, left, - op: match op { - op!("=") => unreachable!(), - - op!("+=") => op!(bin, "+"), - op!("-=") => op!(bin, "-"), - op!("*=") => op!("*"), - op!("/=") => op!("/"), - op!("%=") => op!("%"), - op!("<<=") => op!("<<"), - op!(">>=") => op!(">>"), - op!(">>>=") => op!(">>>"), - op!("|=") => op!("|"), - op!("&=") => op!("&"), - op!("^=") => op!("^"), - op!("**=") => op!("**"), - op!("&&=") => op!("&&"), - op!("||=") => op!("||"), - op!("??=") => op!("??"), - }, + op: op.to_update().unwrap(), right: right.take(), } .as_arg() diff --git a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs index 8b70045c2a4..d3b85f2eed6 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2017_async_to_generator.rs @@ -366,17 +366,18 @@ class Class { r#" class Class { method() { - return _asyncToGenerator((function*() { - var _this2 = this; - this; + var _this2 = this; + return _asyncToGenerator(function*() { + var _this1 = _this2; + _this2; (function() { - return _this2; + return _this1; }); (function() { - var _this1 = _this2; - _this2; + var _this3 = _this1; + _this1; (function() { - return _this1; + return _this3; }); function x() { var _this = this; @@ -399,7 +400,7 @@ class Class { _this; }); } - }).bind(this))(); + })(); } } "# @@ -420,11 +421,12 @@ test!( class Foo extends class{ }{ method() { - var _super_method = (..._args)=>super.method(..._args), _super_method1 = (..._args)=>super.method(..._args); + var _this = this, _superprop_get_method = ()=>super.method; return _asyncToGenerator(function*() { - _super_method(); + var _this1 = _this, _superprop_get_method1 = ()=>_superprop_get_method(); + _superprop_get_method().call(_this); var arrow = function arrow() { - return _super_method1(); + return _superprop_get_method1().call(_this1); }; })(); } @@ -966,25 +968,25 @@ class Class { } } } - "#, r#" class Class { method() { - var _this = this; - return _asyncToGenerator((function*() { - this; - ()=>_this + var _this1 = this; + return _asyncToGenerator(function*() { + _this1; + ()=>_this1 ; ()=>{ - _this; - ()=>_this + _this1; + ()=>_this1 ; function x() { this; ()=>{ - _this; + this; }; + var _this = this; _asyncToGenerator(function*() { _this; }); @@ -993,13 +995,14 @@ class Class { function x() { this; ()=>{ - _this; + this; }; + var _this = this; _asyncToGenerator(function*() { _this; }); } - }).bind(this))(); + })(); } } "# @@ -1560,7 +1563,6 @@ function _six() { // async_to_generator_object_method_with_super test!( - // TODO: Implement caching ignore, syntax(), |_| async_to_generator(), @@ -3402,6 +3404,131 @@ _asyncToGenerator(function*(a = 10, ...rest) {})(); " ); +test!( + Syntax::default(), + |_| async_to_generator(), + issue_2895, + " +export class Quirk { + async doStuff() { + const args = arguments; + console.log(args); + return { foo: null, ...args[0] }; + } +} +", + " +export class Quirk { + doStuff() { + var _arguments = arguments; + return _asyncToGenerator(function*() { + const args = _arguments; + console.log(args); + return { + foo: null, + ...args[0] + }; + })(); + } +} +" +); + +test!( + Syntax::default(), + |_| async_to_generator(), + super_field_update, + " +class Foo { + async doStuff() { + super.foo += 123; + super['abc'] *= 456; + } +} +", + " +class Foo { + doStuff() { + var _superprop_get_foo = ()=>super.foo + , _superprop_get = (_prop)=>super[_prop] + , _superprop_set_foo = (_value)=>super.foo = _value + , _superprop_set = (_prop, _value)=>super[_prop] = _value + ; + return _asyncToGenerator(function*() { + var tmp; + _superprop_set_foo(_superprop_get_foo() + 123); + _superprop_set(tmp = 'abc', _superprop_get(tmp) * 456); + })() + } +} +" +); + +test!( + Syntax::default(), + |_| async_to_generator(), + microbundle_835, + " +class A extends B { + a() { + (async () => { + super.b(); + })(); + } +} +", + " +class A extends B { + a() { + var _this = this, _superprop_get_b = ()=>super.b; + _asyncToGenerator(function*() { + _superprop_get_b().call(_this); + })(); + } +} +" +); + +test!( + Syntax::default(), + |_| async_to_generator(), + super_update, + " +class A extends B { + async foo() { + super.foo ++; + -- super.bar; + super['foo'] ++; + -- super['bar']; + } +} +", + " +class A extends B { + foo() { + var _superprop_get_foo = () => super.foo, + _superprop_get_bar = () => super.bar, + _superprop_get = (_prop) => super[_prop], + _superprop_set_foo = (_value) => super.foo = _value, + _superprop_set_bar = (_value) => super.bar = _value, + _superprop_set = (_prop, _value) => super[_prop] = _value; + + return _asyncToGenerator(function* () { + var tmp, tmp1, tmp2, prop, tmp3, prop1; + + tmp = _superprop_get_foo(), _superprop_set_foo(tmp + 1), tmp; + tmp1 = _superprop_get_bar(), _superprop_set_bar(tmp1 - 1); + tmp2 = _superprop_get(prop = 'foo'), + _superprop_set(prop, tmp2 + 1), + tmp2; + tmp3 = _superprop_get(prop1 = 'bar'), + _superprop_set(prop1, tmp3 - 1); + })(); + } +} +" +); + test!( Syntax::default(), |_| async_to_generator(), diff --git a/crates/swc_ecma_utils/Cargo.toml b/crates/swc_ecma_utils/Cargo.toml index 17fa9740810..7b9319c9e3d 100644 --- a/crates/swc_ecma_utils/Cargo.toml +++ b/crates/swc_ecma_utils/Cargo.toml @@ -20,6 +20,7 @@ concurrent = [ ] [dependencies] +indexmap = "1" once_cell = "1" rayon = {version = "1.5.1", optional = true} swc_atoms = {version = "0.2.0", path = "../swc_atoms"} diff --git a/crates/swc_ecma_utils/src/factory.rs b/crates/swc_ecma_utils/src/factory.rs index 015d85e4081..f4363227e84 100644 --- a/crates/swc_ecma_utils/src/factory.rs +++ b/crates/swc_ecma_utils/src/factory.rs @@ -60,6 +60,28 @@ pub trait ExprFactory: Into { }) } + #[inline] + fn call_fn(self, span: Span, args: Vec) -> Expr { + Expr::Call(CallExpr { + span, + args, + callee: Callee::Expr(Box::new( + self.make_member(Ident::new(js_word!("call"), span)), + )), + type_args: None, + }) + } + + #[inline] + fn as_call(self, span: Span, args: Vec) -> Expr { + Expr::Call(CallExpr { + span, + args, + callee: Callee::Expr(Box::new(self.into())), + type_args: None, + }) + } + #[inline] fn wrap_with_paren(self) -> Expr { let expr = Box::new(self.into()); diff --git a/crates/swc_ecma_utils/src/function/fn_env_hoister.rs b/crates/swc_ecma_utils/src/function/fn_env_hoister.rs index 9b1977050bc..2b732701d2a 100644 --- a/crates/swc_ecma_utils/src/function/fn_env_hoister.rs +++ b/crates/swc_ecma_utils/src/function/fn_env_hoister.rs @@ -1,35 +1,48 @@ -use swc_atoms::js_word; -use swc_common::{util::take::Take, DUMMY_SP}; +use indexmap::IndexMap; +use swc_atoms::{js_word, JsWord}; +use swc_common::{util::take::Take, Span, Spanned, DUMMY_SP}; use swc_ecma_ast::*; use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith}; -#[derive(Clone, Default)] -pub struct FnEnvState { +use crate::ExprFactory; + +#[derive(Default)] +struct SuperField { + computed: Option, + ident: IndexMap, +} + +/// Don't use it aginst function, it will stop if come across any function +/// use it against function body + +#[derive(Default)] +pub struct FnEnvHoister { this: Option, args: Option, new_target: Option, + super_get: SuperField, + super_set: SuperField, + + // extra ident for super["xx"] += 123 + extra_ident: Vec, } -impl FnEnvState { - pub fn new(this: Option, args: Option, new_target: Option) -> Self { - Self { - this, - args, - new_target, - } - } +impl FnEnvHoister { pub fn to_decl(self) -> Vec { let Self { this, args, new_target, + super_get, + super_set, + .. } = self; let mut decls = Vec::with_capacity(3); if let Some(this_id) = this { decls.push(VarDeclarator { span: DUMMY_SP, - name: Pat::Ident(this_id.into()), + name: this_id.into(), init: Some(Box::new(Expr::This(ThisExpr { span: DUMMY_SP }))), definite: false, }); @@ -37,7 +50,7 @@ impl FnEnvState { if let Some(id) = args { decls.push(VarDeclarator { span: DUMMY_SP, - name: Pat::Ident(id.into()), + name: id.into(), init: Some(Box::new(Expr::Ident(Ident::new( js_word!("arguments"), DUMMY_SP, @@ -48,7 +61,7 @@ impl FnEnvState { if let Some(id) = new_target { decls.push(VarDeclarator { span: DUMMY_SP, - name: Pat::Ident(id.into()), + name: id.into(), init: Some(Box::new(Expr::MetaProp(MetaPropExpr { span: DUMMY_SP, kind: MetaPropKind::NewTarget, @@ -56,6 +69,7 @@ impl FnEnvState { definite: false, }); } + extend_super(&mut decls, super_get, super_set); decls } pub fn to_stmt(self) -> Option { @@ -78,13 +92,16 @@ impl FnEnvState { this, args, new_target, + super_get, + super_set, + .. } = self; let mut decls = Vec::with_capacity(3); if let Some(this_id) = &this { decls.push(VarDeclarator { span: DUMMY_SP, - name: Pat::Ident(this_id.clone().into()), + name: this_id.clone().into(), init: None, definite: false, }); @@ -92,7 +109,7 @@ impl FnEnvState { if let Some(id) = args { decls.push(VarDeclarator { span: DUMMY_SP, - name: Pat::Ident(id.into()), + name: id.into(), init: Some(Box::new(Expr::Ident(Ident::new( js_word!("arguments"), DUMMY_SP, @@ -103,7 +120,7 @@ impl FnEnvState { if let Some(id) = new_target { decls.push(VarDeclarator { span: DUMMY_SP, - name: Pat::Ident(id.into()), + name: id.into(), init: Some(Box::new(Expr::MetaProp(MetaPropExpr { span: DUMMY_SP, kind: MetaPropKind::NewTarget, @@ -112,6 +129,8 @@ impl FnEnvState { }); } + extend_super(&mut decls, super_get, super_set); + if decls.is_empty() { (None, None) } else { @@ -126,57 +145,369 @@ impl FnEnvState { ) } } + + fn get_this(&mut self) -> Ident { + self.this + .get_or_insert_with(|| private_ident!("_this")) + .clone() + } + + fn super_get(&mut self, id: &mut Ident, span: Span) -> Ident { + if let Some(callee) = self.super_get.ident.get(&id.sym) { + callee.clone() + } else { + let ident = private_ident!(span, format!("_superprop_get_{}", id.sym)); + self.super_get.ident.insert(id.take().sym, ident.clone()); + ident + } + } + + fn super_get_computed(&mut self, span: Span) -> Ident { + self.super_get + .computed + .get_or_insert_with(|| private_ident!(span, "_superprop_get")) + .clone() + } + + fn super_set(&mut self, id: &mut Ident, span: Span) -> Ident { + if let Some(callee) = self.super_set.ident.get(&id.sym) { + callee.clone() + } else { + let ident = private_ident!(span, format!("_superprop_set_{}", id.sym)); + self.super_set.ident.insert(id.take().sym, ident.clone()); + ident + } + } + + fn super_set_computed(&mut self, span: Span) -> Ident { + self.super_set + .computed + .get_or_insert_with(|| private_ident!(span, "_superprop_set")) + .clone() + } } -impl Take for FnEnvState { +impl Take for FnEnvHoister { fn dummy() -> Self { Self::default() } } -pub struct FnEnvHoister<'a> { - state: &'a mut FnEnvState, -} - -impl<'a> FnEnvHoister<'a> { - pub fn new(state: &'a mut FnEnvState) -> Self { - FnEnvHoister { state } - } -} - -impl<'a> VisitMut for FnEnvHoister<'a> { +impl VisitMut for FnEnvHoister { noop_visit_mut_type!(); fn visit_mut_expr(&mut self, e: &mut Expr) { match e { Expr::Ident(id) if id.sym == js_word!("arguments") => { let arguments = self - .state .args .get_or_insert_with(|| private_ident!("_arguments")); *e = Expr::Ident(arguments.clone()); } Expr::This(..) => { - let this = self - .state - .this - .get_or_insert_with(|| private_ident!("_this")); - *e = Expr::Ident(this.clone()); + let this = self.get_this(); + *e = Expr::Ident(this); } Expr::MetaProp(MetaPropExpr { kind: MetaPropKind::NewTarget, .. }) => { let target = self - .state .new_target .get_or_insert_with(|| private_ident!("_newtarget")); *e = Expr::Ident(target.clone()); } + // super.foo = 123 => super_get_foo = (value) => super.foo = value + Expr::Assign(AssignExpr { + left, + right, + span, + op, + }) => { + let expr = match left { + PatOrExpr::Expr(e) => e, + PatOrExpr::Pat(p) => { + if let Pat::Expr(e) = &mut **p { + e + } else { + e.visit_mut_children_with(self); + return; + } + } + }; + if let Expr::SuperProp(super_prop) = &mut **expr { + let left_span = super_prop.span; + match &mut super_prop.prop { + SuperProp::Computed(c) => { + let callee = self.super_set_computed(left_span); + + let op = op.to_update(); + + let args = if let Some(op) = op { + let tmp = private_ident!("tmp"); + self.extra_ident.push(tmp.clone()); + vec![ + Expr::Assign(AssignExpr { + span: DUMMY_SP, + left: PatOrExpr::Pat(tmp.clone().into()), + op: op!("="), + right: c.expr.take(), + }) + .as_arg(), + Expr::Bin(BinExpr { + span: DUMMY_SP, + left: Box::new(Expr::Call(CallExpr { + span: DUMMY_SP, + callee: self.super_get_computed(DUMMY_SP).as_callee(), + args: vec![tmp.as_arg()], + type_args: None, + })), + op, + right: right.take(), + }) + .as_arg(), + ] + } else { + vec![c.expr.take().as_arg(), right.take().as_arg()] + }; + *e = Expr::Call(CallExpr { + span: *span, + args, + callee: callee.as_callee(), + type_args: None, + }); + } + SuperProp::Ident(id) => { + let callee = self.super_set(&mut id.clone(), left_span); + *e = Expr::Call(CallExpr { + span: *span, + args: vec![(if let Some(op) = op.to_update() { + Box::new(Expr::Bin(BinExpr { + span: DUMMY_SP, + left: Box::new( + self.super_get(id, id.span) + .as_call(id.span, Vec::new()), + ), + op, + right: right.take(), + })) + } else { + right.take() + }) + .as_arg()], + callee: callee.as_callee(), + type_args: None, + }); + } + } + } + e.visit_mut_children_with(self) + } + // super.foo() => super_get_foo = () => super.foo + Expr::Call(CallExpr { + span, + callee: Callee::Expr(expr), + args, + .. + }) => { + if let Expr::SuperProp(super_prop) = &mut **expr { + match &mut super_prop.prop { + SuperProp::Computed(c) => { + let callee = self.super_get_computed(super_prop.span); + let call = Expr::Call(CallExpr { + span: *span, + args: vec![c.expr.take().as_arg()], + callee: callee.as_callee(), + type_args: None, + }); + let mut new_args = args.take(); + + new_args.insert(0, self.get_this().as_arg()); + + *e = call.call_fn(*span, new_args); + } + SuperProp::Ident(id) => { + let callee = self.super_get(id, super_prop.span); + let call = Expr::Call(CallExpr { + span: *span, + args: Vec::new(), + callee: callee.as_callee(), + type_args: None, + }); + let mut new_args = args.take(); + + new_args.insert(0, self.get_this().as_arg()); + + *e = call.call_fn(*span, new_args); + } + } + }; + e.visit_mut_children_with(self) + } + // super.foo ++ + Expr::Update(UpdateExpr { + span, + op, + prefix, + arg, + }) => { + if let Expr::SuperProp(SuperPropExpr { + span: arg_span, + prop, + .. + }) = &mut **arg + { + let tmp = private_ident!("tmp"); + self.extra_ident.push(tmp.clone()); + + let op = match op { + op!("++") => op!(bin, "+"), + op!("--") => op!(bin, "-"), + }; + + let update_expr = Expr::Bin(BinExpr { + span: DUMMY_SP, + left: Box::new(Expr::Ident(tmp.clone())), + right: 1_f64.into(), + op, + }) + .as_arg(); + + let mut exprs = match prop { + SuperProp::Ident(id) => vec![ + Box::new(Expr::Assign(AssignExpr { + left: PatOrExpr::Pat(tmp.clone().into()), + op: op!("="), + right: Box::new( + self.super_get(&mut id.clone(), *arg_span) + .as_call(*arg_span, Vec::new()), + ), + span: *arg_span, + })), + Box::new( + self.super_set(&mut id.clone(), *arg_span) + .as_call(*arg_span, vec![update_expr]), + ), + ], + SuperProp::Computed(c) => { + let prop = private_ident!("prop"); + self.extra_ident.push(prop.clone()); + vec![ + Box::new(Expr::Assign(AssignExpr { + span: *arg_span, + left: PatOrExpr::Pat(tmp.clone().into()), + op: op!("="), + right: Box::new(self.super_get_computed(*arg_span).as_call( + *arg_span, + vec![Expr::Assign(AssignExpr { + span: c.span, + left: PatOrExpr::Pat(prop.clone().into()), + right: c.expr.take(), + op: op!("="), + }) + .as_arg()], + )), + })), + Box::new( + self.super_set_computed(*arg_span) + .as_call(*arg_span, vec![prop.as_arg(), update_expr]), + ), + ] + } + }; + if !*prefix { + exprs.push(Box::new(Expr::Ident(tmp))) + } + *e = Expr::Seq(SeqExpr { span: *span, exprs }) + } else { + e.visit_mut_children_with(self) + } + } + Expr::SuperProp(SuperPropExpr { prop, span, .. }) => match prop { + SuperProp::Computed(c) => { + c.expr.visit_mut_children_with(self); + *e = Expr::Call(CallExpr { + span: *span, + args: vec![c.expr.take().as_arg()], + callee: self.super_get_computed(*span).as_callee(), + type_args: None, + }) + } + SuperProp::Ident(id) => { + *e = Expr::Call(CallExpr { + span: *span, + args: Vec::new(), + callee: self.super_get(id, *span).as_callee(), + type_args: None, + }) + } + }, _ => e.visit_mut_children_with(self), } } + fn visit_mut_block_stmt(&mut self, b: &mut BlockStmt) { + b.visit_mut_children_with(self); + + // we will not vist into fn/class so it's fine + if !self.extra_ident.is_empty() { + b.stmts.insert( + 0, + Stmt::Decl(Decl::Var(VarDecl { + kind: VarDeclKind::Var, + span: DUMMY_SP, + decls: self + .extra_ident + .take() + .into_iter() + .map(|ident| VarDeclarator { + span: DUMMY_SP, + name: ident.into(), + init: None, + definite: false, + }) + .collect(), + declare: false, + })), + ) + } + } + + fn visit_mut_block_stmt_or_expr(&mut self, b: &mut BlockStmtOrExpr) { + b.visit_mut_children_with(self); + + // we will not vist into fn/class so it's fine + if !self.extra_ident.is_empty() { + if let BlockStmtOrExpr::Expr(e) = b { + *b = BlockStmtOrExpr::BlockStmt(BlockStmt { + span: DUMMY_SP, + stmts: vec![ + Stmt::Decl(Decl::Var(VarDecl { + kind: VarDeclKind::Var, + span: DUMMY_SP, + decls: self + .extra_ident + .take() + .into_iter() + .map(|ident| VarDeclarator { + span: DUMMY_SP, + name: ident.into(), + init: None, + definite: false, + }) + .collect(), + declare: false, + })), + Stmt::Return(ReturnStmt { + span: e.span(), + arg: Some(e.take()), + }), + ], + }) + } + } + } + /// Don't recurse into prop of member expression unless computed fn visit_mut_member_expr(&mut self, m: &mut MemberExpr) { if let MemberProp::Computed(computed) = &mut m.prop { @@ -259,7 +590,7 @@ impl<'a> VisitMut for InitThis<'a> { })), Box::new(Expr::Assign(AssignExpr { span: DUMMY_SP, - left: PatOrExpr::Pat(Box::new(self.this_id.clone().into())), + left: PatOrExpr::Pat(self.this_id.clone().into()), op: AssignOp::Assign, right: Box::new(Expr::This(ThisExpr { span: DUMMY_SP })), })), @@ -269,3 +600,104 @@ impl<'a> VisitMut for InitThis<'a> { } } } + +fn extend_super(decls: &mut Vec, get: SuperField, set: SuperField) { + decls.extend(get.ident.into_iter().map(|(key, ident)| VarDeclarator { + span: DUMMY_SP, + name: ident.into(), + init: Some(Box::new(Expr::Arrow(ArrowExpr { + span: DUMMY_SP, + params: Vec::new(), + body: BlockStmtOrExpr::Expr(Box::new(Expr::SuperProp(SuperPropExpr { + obj: Super { span: DUMMY_SP }, + prop: SuperProp::Ident(quote_ident!(key)), + span: DUMMY_SP, + }))), + is_async: false, + is_generator: false, + return_type: None, + type_params: None, + }))), + definite: false, + })); + if let Some(id) = get.computed { + let param = private_ident!("_prop"); + decls.push(VarDeclarator { + span: DUMMY_SP, + name: id.into(), + init: Some(Box::new(Expr::Arrow(ArrowExpr { + span: DUMMY_SP, + params: vec![param.clone().into()], + body: BlockStmtOrExpr::Expr(Box::new(Expr::SuperProp(SuperPropExpr { + obj: Super { span: DUMMY_SP }, + prop: SuperProp::Computed(ComputedPropName { + span: DUMMY_SP, + expr: Box::new(Expr::Ident(param)), + }), + span: DUMMY_SP, + }))), + is_async: false, + is_generator: false, + return_type: None, + type_params: None, + }))), + definite: false, + }); + } + decls.extend(set.ident.into_iter().map(|(key, ident)| { + let value = private_ident!("_value"); + VarDeclarator { + span: DUMMY_SP, + name: ident.into(), + init: Some(Box::new(Expr::Arrow(ArrowExpr { + span: DUMMY_SP, + params: vec![value.clone().into()], + body: BlockStmtOrExpr::Expr(Box::new(Expr::Assign(AssignExpr { + span: DUMMY_SP, + left: PatOrExpr::Expr(Box::new(Expr::SuperProp(SuperPropExpr { + obj: Super { span: DUMMY_SP }, + prop: SuperProp::Ident(quote_ident!(key)), + span: DUMMY_SP, + }))), + op: op!("="), + right: Box::new(Expr::Ident(value)), + }))), + is_async: false, + is_generator: false, + return_type: None, + type_params: None, + }))), + definite: false, + } + })); + if let Some(id) = set.computed { + let prop = private_ident!("_prop"); + let value = private_ident!("_value"); + decls.push(VarDeclarator { + span: DUMMY_SP, + name: id.into(), + init: Some(Box::new(Expr::Arrow(ArrowExpr { + span: DUMMY_SP, + params: vec![prop.clone().into(), value.clone().into()], + body: BlockStmtOrExpr::Expr(Box::new(Expr::Assign(AssignExpr { + span: DUMMY_SP, + left: PatOrExpr::Expr(Box::new(Expr::SuperProp(SuperPropExpr { + obj: Super { span: DUMMY_SP }, + prop: SuperProp::Computed(ComputedPropName { + span: DUMMY_SP, + expr: Box::new(Expr::Ident(prop)), + }), + span: DUMMY_SP, + }))), + op: op!("="), + right: Box::new(Expr::Ident(value)), + }))), + is_async: false, + is_generator: false, + return_type: None, + type_params: None, + }))), + definite: false, + }); + } +}