diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/non-block-arrow-func/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/non-block-arrow-func/output.mjs index 4bacda92aa9c..a661c981308e 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/non-block-arrow-func/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/non-block-arrow-func/output.mjs @@ -1,7 +1,7 @@ export default (param => { - var _class, _temp; + var _class; - return _temp = _class = class App { + return _class = class App { getParam() { return param; } @@ -9,5 +9,5 @@ export default (param => { }, _class.props = { prop1: 'prop1', prop2: 'prop2' - }, _temp; + }, _class; }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/regression-T2983/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/regression-T2983/output.mjs index b962b2bfb723..272e6fdde122 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/regression-T2983/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/regression-T2983/output.mjs @@ -1,6 +1,6 @@ -var _class, _temp; +var _class; -call((_temp = _class = class {}, _class.test = true, _temp)); +call((_class = class {}, _class.test = true, _class)); export default class _class2 {} _class2.test = true; ; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/regression-T6719/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/regression-T6719/output.js index 7e9c64e86abe..2f73fb04825d 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/regression-T6719/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/regression-T6719/output.js @@ -1,11 +1,11 @@ function withContext(ComposedComponent) { - var _class, _temp; + var _class; - return _temp = _class = class WithContext extends Component {}, _class.propTypes = { + return _class = class WithContext extends Component {}, _class.propTypes = { context: PropTypes.shape({ addCss: PropTypes.func, setTitle: PropTypes.func, setMeta: PropTypes.func }) - }, _temp; + }, _class; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/static-infer-name/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/static-infer-name/output.js index 812b9613442d..6e8dd1370b38 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/static-infer-name/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/static-infer-name/output.js @@ -1,3 +1,3 @@ -var _class, _temp; +var _class; -var Foo = (_temp = _class = class Foo {}, _class.num = 0, _temp); +var Foo = (_class = class Foo {}, _class.num = 0, _class); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/super-expression/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/super-expression/output.js index 6896211d2e9d..9948db3f5497 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/super-expression/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/assumption-setPublicClassFields/super-expression/output.js @@ -1,8 +1,6 @@ class Foo extends Bar { constructor() { - var _temp; - - foo((_temp = super(), this.bar = "foo", _temp)); + foo((super(), this.bar = "foo", this)); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/nested-class-computed-redeclared/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/nested-class-computed-redeclared/output.js index d4b862f38e4f..f3dbcb3ae308 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/nested-class-computed-redeclared/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/nested-class-computed-redeclared/output.js @@ -20,7 +20,7 @@ var Foo = /*#__PURE__*/function () { _babelHelpers$classPr = babelHelpers.classPrivateFieldLooseBase(this, _foo2)[_foo2]; - var Nested = /*#__PURE__*/function (_babelHelpers$classPr2) { + var Nested = /*#__PURE__*/function () { function Nested() { babelHelpers.classCallCheck(this, Nested); Object.defineProperty(this, _foo2, { @@ -30,11 +30,11 @@ var Foo = /*#__PURE__*/function () { } babelHelpers.createClass(Nested, [{ - key: _babelHelpers$classPr2, + key: _babelHelpers$classPr, value: function () {} }]); return Nested; - }(_babelHelpers$classPr); + }(); babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo]; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/non-block-arrow-func/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/non-block-arrow-func/output.mjs index ff7278934487..f2f8dd1eadcd 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/non-block-arrow-func/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/non-block-arrow-func/output.mjs @@ -1,16 +1,16 @@ export default (param => { - var _class, _props, _temp; + var _class, _props; - return _temp = (_props = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("props"), _class = class App { + return _props = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("props"), (_class = class App { getParam() { return param; } - }), Object.defineProperty(_class, _props, { + }, Object.defineProperty(_class, _props, { writable: true, value: { prop1: 'prop1', prop2: 'prop2' } - }), _temp; + }), _class); }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/reevaluated/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/reevaluated/output.js index bdfa8dc95398..fbf3bede6bfa 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/reevaluated/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/reevaluated/output.js @@ -1,7 +1,7 @@ function classFactory() { - var _class, _foo, _bar, _temp; + var _class, _foo, _bar; - return _temp = (_foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"), _bar = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("bar"), _class = class Foo { + return _foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"), _bar = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("bar"), (_class = class Foo { constructor() { Object.defineProperty(this, _foo, { writable: true, @@ -25,10 +25,10 @@ function classFactory() { return babelHelpers.classPrivateFieldLooseBase(Foo, _bar)[_bar]; } - }), Object.defineProperty(_class, _bar, { + }, Object.defineProperty(_class, _bar, { writable: true, value: "bar" - }), _temp; + }), _class); } var Foo1 = classFactory(); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-infer-name/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-infer-name/output.js index 9f9239b68084..de65ca431f66 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-infer-name/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-infer-name/output.js @@ -1,6 +1,6 @@ -var _class, _num, _temp; +var _class, _num; -var Foo = (_temp = (_num = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("num"), _class = class Foo {}), Object.defineProperty(_class, _num, { +var Foo = (_num = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("num"), (_class = class Foo {}, Object.defineProperty(_class, _num, { writable: true, value: 0 -}), _temp); +}), _class)); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/super-expression/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/super-expression/output.js index dbef325dbbeb..7120acbd6a5d 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/super-expression/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/super-expression/output.js @@ -8,13 +8,13 @@ var Foo = /*#__PURE__*/function (_Bar) { var _super = babelHelpers.createSuper(Foo); function Foo() { - var _temp, _this; + var _this; babelHelpers.classCallCheck(this, Foo); - foo((_temp = _this = _super.call(this), Object.defineProperty(babelHelpers.assertThisInitialized(_this), _bar, { + foo((_this = _super.call(this), Object.defineProperty(babelHelpers.assertThisInitialized(_this), _bar, { writable: true, value: "foo" - }), _temp)); + }), babelHelpers.assertThisInitialized(_this))); return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js index 1f1a88576bf3..d5a2d7886687 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js @@ -20,7 +20,7 @@ var Foo = /*#__PURE__*/function () { _babelHelpers$classPr = babelHelpers.classPrivateFieldGet(this, _foo2); - var Nested = /*#__PURE__*/function (_babelHelpers$classPr2) { + var Nested = /*#__PURE__*/function () { function Nested() { babelHelpers.classCallCheck(this, Nested); babelHelpers.classPrivateFieldInitSpec(this, _foo2, { @@ -30,11 +30,11 @@ var Foo = /*#__PURE__*/function () { } babelHelpers.createClass(Nested, [{ - key: _babelHelpers$classPr2, + key: _babelHelpers$classPr, value: function () {} }]); return Nested; - }(_babelHelpers$classPr); + }(); babelHelpers.classPrivateFieldGet(this, _foo); } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/non-block-arrow-func/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/non-block-arrow-func/output.mjs index bc605408a7d3..3a3ac8ea4563 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/non-block-arrow-func/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/non-block-arrow-func/output.mjs @@ -1,7 +1,7 @@ export default (param => { - var _class, _temp, _props; + var _class, _props; - return _temp = _class = class App { + return _class = class App { getParam() { return param; } @@ -12,5 +12,5 @@ export default (param => { prop1: 'prop1', prop2: 'prop2' } - }, _temp; + }, _class; }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js index 6c22c5c9bf08..d6138f4a37fb 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js @@ -1,7 +1,7 @@ function classFactory() { - var _class, _foo, _temp, _bar; + var _class, _foo, _bar; - return _temp = (_foo = /*#__PURE__*/new WeakMap(), _class = class Foo { + return _foo = /*#__PURE__*/new WeakMap(), (_class = class Foo { constructor() { babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, @@ -25,8 +25,8 @@ function classFactory() { return babelHelpers.classStaticPrivateFieldSpecGet(Foo, _class, _bar); } - }), _bar = { + }, _bar = { writable: true, value: "bar" - }, _temp; + }, _class); } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T2983/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T2983/output.mjs index e3f239e10280..6a04f9c3a95e 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T2983/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T2983/output.mjs @@ -1,9 +1,9 @@ -var _class, _temp, _test; +var _class, _test; -call((_temp = _class = class {}, _test = { +call((_class = class {}, _test = { writable: true, value: true -}, _temp)); +}, _class)); export default class _class2 {} var _test2 = { writable: true, diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T6719/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T6719/output.js index 18507b822ba3..deae4722e5d0 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T6719/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T6719/output.js @@ -1,7 +1,7 @@ function withContext(ComposedComponent) { - var _class, _temp, _propTypes; + var _class, _propTypes; - return _temp = _class = class WithContext extends Component {}, _propTypes = { + return _class = class WithContext extends Component {}, _propTypes = { writable: true, value: { context: PropTypes.shape({ @@ -10,5 +10,5 @@ function withContext(ComposedComponent) { setMeta: PropTypes.func }) } - }, _temp; + }, _class; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-infer-name/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-infer-name/output.js index 9d864999469b..10152a56c3c8 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-infer-name/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-infer-name/output.js @@ -1,6 +1,6 @@ -var _class, _temp, _num; +var _class, _num; -var Foo = (_temp = _class = class Foo {}, _num = { +var Foo = (_class = class Foo {}, _num = { writable: true, value: 0 -}, _temp); +}, _class); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-self-field/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-self-field/output.js index e24d4e7024e4..eca63984a6e1 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-self-field/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-self-field/output.js @@ -1,6 +1,6 @@ -var _class, _temp, _x; +var _class, _x; -var f = (_temp = _class = class Foo {}, _x = { +var f = (_class = class Foo {}, _x = { writable: true, value: _class -}, babelHelpers.defineProperty(_class, "y", _class), _temp); +}, babelHelpers.defineProperty(_class, "y", _class), _class); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js index 95768a684b62..cc3455fd34b9 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js @@ -8,13 +8,13 @@ var Foo = /*#__PURE__*/function (_Bar) { var _super = babelHelpers.createSuper(Foo); function Foo() { - var _temp, _this; + var _this; babelHelpers.classCallCheck(this, Foo); - foo((_temp = _this = _super.call(this), babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _bar, { + foo((_this = _super.call(this), babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _bar, { writable: true, value: "foo" - }), _temp)); + }), babelHelpers.assertThisInitialized(_this))); return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/computed/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/computed/output.js index 0c430c431ec4..568c7b0116b1 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/computed/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/computed/output.js @@ -15,7 +15,7 @@ _ref3 = /regex/; _baz = baz; _ref4 = `template${expression}`; -var MyClass = /*#__PURE__*/function (_computed3, _computed4, _ref5) { +var MyClass = /*#__PURE__*/function () { "use strict"; function MyClass() { @@ -36,20 +36,20 @@ var MyClass = /*#__PURE__*/function (_computed3, _computed4, _ref5) { get: function () {}, set: function (value) {} }, { - key: _computed3, + key: _computed, get: function () {} }, { - key: _computed4, + key: _computed2, set: function (value) {} }, { - key: _ref5, + key: _ref2, value: function () {} }], [{ key: "10", value: function _() {} }]); return MyClass; -}(_computed, _computed2, _ref2); +}(); MyClass[_one] = "test"; MyClass[2 * 4 + 7] = "247"; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/non-block-arrow-func/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/non-block-arrow-func/output.mjs index 328111844f48..de66b53521e6 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/non-block-arrow-func/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/non-block-arrow-func/output.mjs @@ -1,7 +1,7 @@ export default (param => { - var _class, _temp; + var _class; - return _temp = _class = /*#__PURE__*/function () { + return _class = /*#__PURE__*/function () { function App() { babelHelpers.classCallCheck(this, App); } @@ -16,5 +16,5 @@ export default (param => { }(), _class.props = { prop1: 'prop1', prop2: 'prop2' - }, _temp; + }, _class; }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/regression-T2983/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/regression-T2983/output.mjs index 56bfab2d0842..7bffb9480ae7 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/regression-T2983/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/regression-T2983/output.mjs @@ -1,8 +1,8 @@ -var _class, _temp; +var _class; -call((_temp = _class = /*#__PURE__*/babelHelpers.createClass(function _class() { +call((_class = /*#__PURE__*/babelHelpers.createClass(function _class() { babelHelpers.classCallCheck(this, _class); -}), _class.test = true, _temp)); +}), _class.test = true, _class)); var _default = /*#__PURE__*/babelHelpers.createClass(function _default() { babelHelpers.classCallCheck(this, _default); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/regression-T6719/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/regression-T6719/output.js index 2ba02473913b..07587f0a37fc 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/regression-T6719/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/regression-T6719/output.js @@ -1,7 +1,7 @@ function withContext(ComposedComponent) { - var _class, _temp; + var _class; - return _temp = _class = /*#__PURE__*/function (_Component) { + return _class = /*#__PURE__*/function (_Component) { "use strict"; babelHelpers.inherits(WithContext, _Component); @@ -20,5 +20,5 @@ function withContext(ComposedComponent) { setTitle: PropTypes.func, setMeta: PropTypes.func }) - }, _temp; + }, _class; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/static-infer-name/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/static-infer-name/output.js index 79567b729cad..989a6a951cbf 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/static-infer-name/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/static-infer-name/output.js @@ -1,7 +1,7 @@ -var _class, _temp; +var _class; -var Foo = (_temp = _class = /*#__PURE__*/babelHelpers.createClass(function Foo() { +var Foo = (_class = /*#__PURE__*/babelHelpers.createClass(function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); -}), _class.num = 0, _temp); +}), _class.num = 0, _class); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/super-expression/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/super-expression/output.js index e81c08978b2f..7c9f86e1ca4a 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/super-expression/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public-loose/super-expression/output.js @@ -6,10 +6,10 @@ var Foo = /*#__PURE__*/function (_Bar) { var _super = babelHelpers.createSuper(Foo); function Foo() { - var _temp, _this; + var _this; babelHelpers.classCallCheck(this, Foo); - foo((_temp = _this = _super.call(this), _this.bar = "foo", _temp)); + foo((_this = _super.call(this), _this.bar = "foo", babelHelpers.assertThisInitialized(_this))); return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/computed/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/computed/output.js index 8c78f5dc5401..aeca991c9373 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/computed/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/computed/output.js @@ -15,7 +15,7 @@ _ref3 = /regex/; _baz = baz; _ref4 = `template${expression}`; -var MyClass = /*#__PURE__*/function (_computed3, _computed4, _ref5) { +var MyClass = /*#__PURE__*/function () { "use strict"; function MyClass() { @@ -36,20 +36,20 @@ var MyClass = /*#__PURE__*/function (_computed3, _computed4, _ref5) { get: function () {}, set: function (value) {} }, { - key: _computed3, + key: _computed, get: function () {} }, { - key: _computed4, + key: _computed2, set: function (value) {} }, { - key: _ref5, + key: _ref2, value: function () {} }], [{ key: "10", value: function _() {} }]); return MyClass; -}(_computed, _computed2, _ref2); +}(); babelHelpers.defineProperty(MyClass, _one, "test"); babelHelpers.defineProperty(MyClass, 2 * 4 + 7, "247"); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params-complex/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params-complex/output.js index 1d4f378afdd5..1b75a9bdb01d 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params-complex/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params-complex/output.js @@ -1,8 +1,4 @@ class Foo extends Bar { - constructor(x = test ? (() => { - var _temp; - - return _temp = super(), babelHelpers.defineProperty(this, "bar", "foo"), _temp; - })() : 0) {} + constructor(x = test ? (() => (super(), babelHelpers.defineProperty(this, "bar", "foo"), this))() : 0) {} } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params-in-arrow/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params-in-arrow/output.js index db628b9500cc..dc05adb96f90 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params-in-arrow/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params-in-arrow/output.js @@ -1,8 +1,6 @@ class Foo extends Bar { constructor(x = () => { - var _temp; - - check((_temp = super(), babelHelpers.defineProperty(this, "bar", "foo"), _temp)); + check((super(), babelHelpers.defineProperty(this, "bar", "foo"), this)); }) {} } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params/output.js index bcc2f94334ef..179fda049b4d 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/derived-super-in-default-params/output.js @@ -1,8 +1,4 @@ class Foo extends Bar { - constructor(x = (() => { - var _temp; - - return _temp = super(), babelHelpers.defineProperty(this, "bar", "foo"), _temp; - })()) {} + constructor(x = (() => (super(), babelHelpers.defineProperty(this, "bar", "foo"), this))()) {} } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/non-block-arrow-func/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/non-block-arrow-func/output.mjs index 996c6cc9912e..d10338290b88 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/non-block-arrow-func/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/non-block-arrow-func/output.mjs @@ -1,7 +1,7 @@ export default (param => { - var _class, _temp; + var _class; - return _temp = _class = /*#__PURE__*/function () { + return _class = /*#__PURE__*/function () { function App() { babelHelpers.classCallCheck(this, App); } @@ -16,5 +16,5 @@ export default (param => { }(), babelHelpers.defineProperty(_class, "props", { prop1: 'prop1', prop2: 'prop2' - }), _temp; + }), _class; }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T2983/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T2983/output.mjs index 01b0b8d3c279..4b87f74c7f86 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T2983/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T2983/output.mjs @@ -1,8 +1,8 @@ -var _class, _temp; +var _class; -call((_temp = _class = /*#__PURE__*/babelHelpers.createClass(function _class() { +call((_class = /*#__PURE__*/babelHelpers.createClass(function _class() { babelHelpers.classCallCheck(this, _class); -}), babelHelpers.defineProperty(_class, "test", true), _temp)); +}), babelHelpers.defineProperty(_class, "test", true), _class)); var _default = /*#__PURE__*/babelHelpers.createClass(function _default() { babelHelpers.classCallCheck(this, _default); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T6719/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T6719/output.js index e00219afdfce..3f3778bcec25 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T6719/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/regression-T6719/output.js @@ -1,7 +1,7 @@ function withContext(ComposedComponent) { - var _class, _temp; + var _class; - return _temp = _class = /*#__PURE__*/function (_Component) { + return _class = /*#__PURE__*/function (_Component) { "use strict"; babelHelpers.inherits(WithContext, _Component); @@ -20,5 +20,5 @@ function withContext(ComposedComponent) { setTitle: PropTypes.func, setMeta: PropTypes.func }) - }), _temp; + }), _class; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/static-infer-name/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/static-infer-name/output.js index d6b3ecee1eb7..0f3e5e2d1a22 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/static-infer-name/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/static-infer-name/output.js @@ -1,7 +1,7 @@ -var _class, _temp; +var _class; -var Foo = (_temp = _class = /*#__PURE__*/babelHelpers.createClass(function Foo() { +var Foo = (_class = /*#__PURE__*/babelHelpers.createClass(function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); -}), babelHelpers.defineProperty(_class, "num", 0), _temp); +}), babelHelpers.defineProperty(_class, "num", 0), _class); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/super-expression/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/super-expression/output.js index 04fbd2241347..139c44c8c4ce 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/public/super-expression/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/public/super-expression/output.js @@ -6,10 +6,10 @@ var Foo = /*#__PURE__*/function (_Bar) { var _super = babelHelpers.createSuper(Foo); function Foo() { - var _temp, _this; + var _this; babelHelpers.classCallCheck(this, Foo); - foo((_temp = _this = _super.call(this), babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "bar", "foo"), _temp)); + foo((_this = _super.call(this), babelHelpers.defineProperty(babelHelpers.assertThisInitialized(_this), "bar", "foo"), babelHelpers.assertThisInitialized(_this))); return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6153/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6153/output.js index 0fdb59a7573c..3b6253ee5add 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6153/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/6153/output.js @@ -16,9 +16,9 @@ }); (function () { - var _class, _temp; + var _class; - return _temp = _class = class Bar { + return _class = class Bar { constructor() { var _this2 = this; @@ -29,7 +29,7 @@ }, babelHelpers.defineProperty(_class, "fn", function () { return console.log(_class); - }), _temp; + }), _class; }); (function () { diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/7371/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/7371/output.js index 0e8cc4e60e0e..57f812f36073 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/7371/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/7371/output.js @@ -33,9 +33,7 @@ class Obj { class SuperClass extends Obj { constructor() { - var _temp; - - class B extends ((_temp = super(), babelHelpers.defineProperty(this, "field", 1), _temp), Obj) { + class B extends ((super(), babelHelpers.defineProperty(this, "field", 1)), Obj) { constructor() { super(); expect(this.field).toBeUndefined(); @@ -53,15 +51,13 @@ new SuperClass(); // ensure ComputedKey Method is still transformed class ComputedMethod extends Obj { constructor() { - var _temp2; - class B extends Obj { constructor() { super(); expect(this.field).toBeUndefined(); } - [(_temp2 = super(), babelHelpers.defineProperty(this, "field", 1), _temp2)]() {} + [(super(), babelHelpers.defineProperty(this, "field", 1), this)]() {} } @@ -77,9 +73,7 @@ class ComputedField extends Obj { constructor() { let _ref; - var _temp3; - - _ref = (_temp3 = super(), babelHelpers.defineProperty(this, "field", 1), _temp3); + _ref = (super(), babelHelpers.defineProperty(this, "field", 1), this); class B extends Obj { constructor() { diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js index fc17c143e229..c5ebed437028 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js @@ -1,11 +1,11 @@ const classes = []; for (let i = 0; i <= 10; ++i) { - var _class, _bar, _temp; + var _class, _bar; let _i; - classes.push((_temp = (_bar = /*#__PURE__*/new WeakMap(), _i = i, _class = class A { + classes.push((_bar = /*#__PURE__*/new WeakMap(), _i = i, (_class = class A { constructor() { babelHelpers.defineProperty(this, _i, `computed field ${i}`); babelHelpers.classPrivateFieldInitSpec(this, _bar, { @@ -18,5 +18,5 @@ for (let i = 0; i <= 10; ++i) { return babelHelpers.classPrivateFieldGet(this, _bar); } - }), babelHelpers.defineProperty(_class, "foo", `static field ${i}`), _temp)); + }, babelHelpers.defineProperty(_class, "foo", `static field ${i}`), _class))); } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T2983/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T2983/output.mjs index 56bfab2d0842..7bffb9480ae7 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T2983/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T2983/output.mjs @@ -1,8 +1,8 @@ -var _class, _temp; +var _class; -call((_temp = _class = /*#__PURE__*/babelHelpers.createClass(function _class() { +call((_class = /*#__PURE__*/babelHelpers.createClass(function _class() { babelHelpers.classCallCheck(this, _class); -}), _class.test = true, _temp)); +}), _class.test = true, _class)); var _default = /*#__PURE__*/babelHelpers.createClass(function _default() { babelHelpers.classCallCheck(this, _default); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T6719/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T6719/output.js index 2ba02473913b..07587f0a37fc 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T6719/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/T6719/output.js @@ -1,7 +1,7 @@ function withContext(ComposedComponent) { - var _class, _temp; + var _class; - return _temp = _class = /*#__PURE__*/function (_Component) { + return _class = /*#__PURE__*/function (_Component) { "use strict"; babelHelpers.inherits(WithContext, _Component); @@ -20,5 +20,5 @@ function withContext(ComposedComponent) { setTitle: PropTypes.func, setMeta: PropTypes.func }) - }, _temp; + }, _class; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/static-property-tdz/decorator-interop/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/static-property-tdz/decorator-interop/output.js index c424973adebb..63c65192b695 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/static-property-tdz/decorator-interop/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/static-property-tdz/decorator-interop/output.js @@ -4,7 +4,7 @@ var _class, _descriptor; function dec() {} -let A = (_class = (_Symbol$search = Symbol.search, /*#__PURE__*/function (_Symbol$search2) { +let A = (_class = (_Symbol$search = Symbol.search, /*#__PURE__*/function () { "use strict"; function A() { @@ -13,11 +13,11 @@ let A = (_class = (_Symbol$search = Symbol.search, /*#__PURE__*/function (_Symbo } babelHelpers.createClass(A, [{ - key: _Symbol$search2, + key: _Symbol$search, value: function () {} }]); return A; -}(_Symbol$search)), (_descriptor = babelHelpers.applyDecoratedDescriptor(_class.prototype, "a", [dec], { +}()), (_descriptor = babelHelpers.applyDecoratedDescriptor(_class.prototype, "a", [dec], { configurable: true, enumerable: true, writable: true, diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/in-class-heritage/output.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/in-class-heritage/output.js index 2ed3468c3ec4..ef169ff2843c 100644 --- a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/in-class-heritage/output.js +++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/in-class-heritage/output.js @@ -1,10 +1,10 @@ -var _class, _temp, _class2, _temp2; +var _class, _class2; -class Foo extends (_temp = _class = class extends (_temp2 = _class2 = class Base {}, (() => { +class Foo extends (_class = class extends (_class2 = class Base {}, (() => { _class2.qux = 21; -})(), _temp2) {}, (() => { +})(), _class2) {}, (() => { _class.bar = 21; -})(), _temp) {} +})(), _class) {} (() => { Foo.foo = Foo.bar + Foo.qux; diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/super-static-block/output.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/super-static-block/output.js index ec5bf773773c..7d95740c3a0d 100644 --- a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/super-static-block/output.js +++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration-loose/super-static-block/output.js @@ -1,8 +1,8 @@ -var _ref, _class, _temp; +var _ref, _class; -class Foo extends (_ref = (_temp = _class = class _ref {}, (() => { +class Foo extends (_ref = (_class = class _ref {}, (() => { _class.bar = 42; -})(), _temp)) {} +})(), _class)) {} Foo.bar = 21; diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/in-class-heritage/output.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/in-class-heritage/output.js index 2ed3468c3ec4..ef169ff2843c 100644 --- a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/in-class-heritage/output.js +++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/in-class-heritage/output.js @@ -1,10 +1,10 @@ -var _class, _temp, _class2, _temp2; +var _class, _class2; -class Foo extends (_temp = _class = class extends (_temp2 = _class2 = class Base {}, (() => { +class Foo extends (_class = class extends (_class2 = class Base {}, (() => { _class2.qux = 21; -})(), _temp2) {}, (() => { +})(), _class2) {}, (() => { _class.bar = 21; -})(), _temp) {} +})(), _class) {} (() => { Foo.foo = Foo.bar + Foo.qux; diff --git a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/new-target/output.js b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/new-target/output.js index 9d1f4c6b03cd..96943c83a8af 100644 --- a/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/new-target/output.js +++ b/packages/babel-plugin-proposal-class-static-block/test/fixtures/integration/new-target/output.js @@ -1,10 +1,10 @@ class Base { constructor() { - var _class, _temp; + var _class; - this.Foo = (_temp = _class = class {}, (() => { + this.Foo = (_class = class {}, (() => { _class.foo = void 0; - })(), _temp); + })(), _class); } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions/output.js index e5285c7fe78c..db346f6ca9ad 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/expressions/output.js @@ -1,53 +1,53 @@ -var _initClass, _A, _class, _temp, _initClass2, _C, _class2, _temp2, _initClass3, _D, _class3, _temp3, _initClass4, _decorated_class, _class4, _temp4, _initClass5, _G, _class5, _temp5, _initClass6, _decorated_class2, _class6, _temp6, _initClass7, _H, _class7, _temp7, _initClass8, _K, _class8, _temp8; +var _initClass, _A, _class, _initClass2, _C, _class2, _initClass3, _D, _class3, _initClass4, _decorated_class, _class4, _initClass5, _G, _class5, _initClass6, _decorated_class2, _class6, _initClass7, _H, _class7, _initClass8, _K, _class8; const dec = () => {}; -const A = ((_temp = _class = class A {}, (() => { +const A = ((_class = class A {}, (() => { [_A, _initClass] = babelHelpers.applyDecs(_class, [], [dec]); })(), (() => { _initClass(); -})(), _temp), _A); -const B = ((_temp2 = _class2 = class C {}, (() => { +})()), _A); +const B = ((_class2 = class C {}, (() => { [_C, _initClass2] = babelHelpers.applyDecs(_class2, [], [dec]); })(), (() => { _initClass2(); -})(), _temp2), _C); -const D = ((_temp3 = _class3 = class D {}, (() => { +})()), _C); +const D = ((_class3 = class D {}, (() => { [_D, _initClass3] = babelHelpers.applyDecs(_class3, [], [dec]); })(), (() => { _initClass3(); -})(), _temp3), _D); -const E = (((_temp4 = _class4 = class {}, (() => { +})()), _D); +const E = (((_class4 = class {}, (() => { [_decorated_class, _initClass4] = babelHelpers.applyDecs(_class4, [], [dec]); })(), (() => { _initClass4(); -})(), _temp4), _decorated_class), 123); -const F = [((_temp5 = _class5 = class G {}, (() => { +})()), _decorated_class), 123); +const F = [((_class5 = class G {}, (() => { [_G, _initClass5] = babelHelpers.applyDecs(_class5, [], [dec]); })(), (() => { _initClass5(); -})(), _temp5), _G), ((_temp6 = _class6 = class {}, (() => { +})()), _G), ((_class6 = class {}, (() => { [_decorated_class2, _initClass6] = babelHelpers.applyDecs(_class6, [], [dec]); })(), (() => { _initClass6(); -})(), _temp6), _decorated_class2)]; -const H = ((_temp7 = _class7 = class H extends I {}, (() => { +})()), _decorated_class2)]; +const H = ((_class7 = class H extends I {}, (() => { [_H, _initClass7] = babelHelpers.applyDecs(_class7, [], [dec]); })(), (() => { _initClass7(); -})(), _temp7), _H); -const J = ((_temp8 = _class8 = class K extends L {}, (() => { +})()), _H); +const J = ((_class8 = class K extends L {}, (() => { [_K, _initClass8] = babelHelpers.applyDecs(_class8, [], [dec]); })(), (() => { _initClass8(); -})(), _temp8), _K); +})()), _K); function classFactory() { - var _initClass9, _decorated_class3, _class9, _temp9; + var _initClass9, _decorated_class3, _class9; - return (_temp9 = _class9 = class {}, (() => { + return (_class9 = class {}, (() => { [_decorated_class3, _initClass9] = babelHelpers.applyDecs(_class9, [], [dec]); })(), (() => { _initClass9(); - })(), _temp9), _decorated_class3; + })()), _decorated_class3; } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js index e2484dd973ae..3b794609ecbd 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/initializers/output.js @@ -1,14 +1,12 @@ -var _initClass, _temp2, _initClass2, _temp4; +var _initClass, _temp, _initClass2, _temp2; const dec = () => {}; let _Foo; -new (_temp2 = class extends babelHelpers.identity { +new (_temp = class extends babelHelpers.identity { constructor() { - var _temp; - - (_temp = super(_Foo), babelHelpers.defineProperty(this, "field", 123), _temp), _initClass(); + (super(_Foo), babelHelpers.defineProperty(this, "field", 123)), _initClass(); } }, (() => { @@ -17,17 +15,15 @@ new (_temp2 = class extends babelHelpers.identity { (() => { [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); })(); -})(), _temp2)(); +})(), _temp)(); let _Bar; -new (_temp4 = class extends babelHelpers.identity { +new (_temp2 = class extends babelHelpers.identity { constructor() { - var _temp3; - - (_temp3 = super(_Bar), babelHelpers.defineProperty(this, "field", ((() => { + (super(_Bar), babelHelpers.defineProperty(this, "field", ((() => { this.otherField = 456; - })(), 123)), _temp3), _initClass2(); + })(), 123))), _initClass2(); } }, (() => { @@ -36,4 +32,4 @@ new (_temp4 = class extends babelHelpers.identity { (() => { [_Bar, _initClass2] = babelHelpers.applyDecs(Bar, [], [dec]); })(); -})(), _temp4)(); +})(), _temp2)(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js index 8403fb9bb9ba..88ed1dcdf968 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js @@ -1,4 +1,4 @@ -var _initClass, _x, _m, _temp2; +var _initClass, _x, _m, _temp; const dec = () => {}; @@ -6,21 +6,19 @@ let hasX, hasM; let _Foo; -new (_temp2 = (_x = /*#__PURE__*/new WeakMap(), _m = /*#__PURE__*/new WeakSet(), class extends babelHelpers.identity { +new (_x = /*#__PURE__*/new WeakMap(), _m = /*#__PURE__*/new WeakSet(), (_temp = class extends babelHelpers.identity { constructor() { - var _temp; - - (_temp = super(_Foo), babelHelpers.classPrivateMethodInitSpec(this, _m), babelHelpers.classPrivateFieldInitSpec(this, _x, { + (super(_Foo), babelHelpers.classPrivateMethodInitSpec(this, _m), babelHelpers.classPrivateFieldInitSpec(this, _x, { writable: true, value: void 0 - }), babelHelpers.defineProperty(this, "x", void 0), _temp), (() => { + }), babelHelpers.defineProperty(this, "x", void 0)), (() => { hasX = o => _x.has(o); hasM = o => _m.has(o); })(), _initClass(); } -}), (() => { +}, (() => { class Foo { static m() {} @@ -29,6 +27,6 @@ new (_temp2 = (_x = /*#__PURE__*/new WeakMap(), _m = /*#__PURE__*/new WeakSet(), (() => { [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); })(); -})(), _temp2)(); +})(), _temp))(); function _m2() {} diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js index 5ff5ed1f935b..783a8255086d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-this/output.js @@ -1,16 +1,14 @@ -var _initClass, _temp2; +var _initClass, _temp; const dec = () => {}; let _Foo; -new (_temp2 = class extends babelHelpers.identity { +new (_temp = class extends babelHelpers.identity { constructor() { - var _temp; - - (_temp = super(_Foo), babelHelpers.defineProperty(this, "field", ((() => { + (super(_Foo), babelHelpers.defineProperty(this, "field", ((() => { this; - })(), this)), _temp), (() => { + })(), this))), (() => { this; })(), _initClass(); } @@ -21,4 +19,4 @@ new (_temp2 = class extends babelHelpers.identity { (() => { [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); })(); -})(), _temp2)(); +})(), _temp)(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/output.js index 911bb3449af4..92a4d6d65424 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-with-expr/output.js @@ -1,8 +1,8 @@ -var _initClass, _Bar, _class, _temp; +var _initClass, _Bar, _class; const dec = () => {}; -const Foo = ((_temp = _class = class Bar { +const Foo = ((_class = class Bar { constructor() { babelHelpers.defineProperty(this, "bar", new _Bar()); } @@ -11,5 +11,5 @@ const Foo = ((_temp = _class = class Bar { [_Bar, _initClass] = babelHelpers.applyDecs(_class, [], [dec]); })(), (() => { _initClass(); -})(), _temp), _Bar); +})()), _Bar); const foo = new Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js index f2fb1fb216f7..41bf818a89a4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement/output.js @@ -1,14 +1,12 @@ -var _initClass, _temp2; +var _initClass, _temp; const dec = () => {}; let _Foo; -new (_temp2 = class extends babelHelpers.identity { +new (_temp = class extends babelHelpers.identity { constructor() { - var _temp; - - (_temp = super(_Foo), babelHelpers.defineProperty(this, "foo", new _Foo()), _temp), _initClass(); + (super(_Foo), babelHelpers.defineProperty(this, "foo", new _Foo())), _initClass(); } }, (() => { @@ -17,5 +15,5 @@ new (_temp2 = class extends babelHelpers.identity { (() => { [_Foo, _initClass] = babelHelpers.applyDecs(Foo, [], [dec]); })(); -})(), _temp2)(); +})(), _temp)(); const foo = new _Foo(); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js index c6a734ce3d65..22ccb1e38008 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-misc--to-es2015/valid-expression-formats/output.js @@ -28,16 +28,16 @@ class Foo { method() {} makeClass() { - var _dec9, _init_bar, _class, _temp; + var _dec9, _init_bar, _class; - return _dec9 = babelHelpers.classPrivateFieldGet(this, _a), (_temp = _class = class Nested { + return _dec9 = babelHelpers.classPrivateFieldGet(this, _a), (_class = class Nested { constructor() { babelHelpers.defineProperty(this, "bar", _init_bar(this)); } }, (() => { [_init_bar] = babelHelpers.applyDecs(_class, [[_dec9, 0, "bar"]], []); - })(), _temp); + })(), _class); } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/initiailzer-after-super-bug-8808/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/initiailzer-after-super-bug-8808/output.js index b7707bd53987..d08dbee2da12 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/initiailzer-after-super-bug-8808/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/initiailzer-after-super-bug-8808/output.js @@ -3,9 +3,7 @@ let Sub = babelHelpers.decorate([decorator(parameter)], function (_initialize, _ class Sub extends _Super { constructor() { - var _temp; - - (_temp = super(), _initialize(this), _temp).method(); + (super(), _initialize(this), this).method(); } } diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/initialize-after-super-expression/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/initialize-after-super-expression/output.js index 1c46c7388322..72f58603ad4e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/initialize-after-super-expression/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/transformation/initialize-after-super-expression/output.js @@ -3,9 +3,7 @@ let B = babelHelpers.decorate([dec], function (_initialize, _A) { class B extends _A { constructor() { - var _temp; - - 0, (_temp = super(), _initialize(this), _temp); + 0, (super(), _initialize(this), this); } } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-loose/class-expression/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-loose/class-expression/output.js index 171fe93641af..8ac0fc1b5fd2 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-loose/class-expression/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-loose/class-expression/output.js @@ -1,12 +1,12 @@ -var _class, _foo, _temp; +var _class, _foo; -console.log((_temp = (_foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"), _class = class A { +console.log((_foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"), (_class = class A { method() { babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo](); } -}), Object.defineProperty(_class, _foo, { +}, Object.defineProperty(_class, _foo, { value: _foo2 -}), _temp)); +}), _class))); function _foo2() {} diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-privateFieldsAsProperties/class-expression/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-privateFieldsAsProperties/class-expression/output.js index 171fe93641af..8ac0fc1b5fd2 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-privateFieldsAsProperties/class-expression/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-static-method-privateFieldsAsProperties/class-expression/output.js @@ -1,12 +1,12 @@ -var _class, _foo, _temp; +var _class, _foo; -console.log((_temp = (_foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"), _class = class A { +console.log((_foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"), (_class = class A { method() { babelHelpers.classPrivateFieldLooseBase(this, _foo)[_foo](); } -}), Object.defineProperty(_class, _foo, { +}, Object.defineProperty(_class, _foo, { value: _foo2 -}), _temp)); +}), _class))); function _foo2() {} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/field/output.js index c0ea2596a758..a89ac259c60a 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/field/output.js @@ -1,9 +1,7 @@ -var _temp; - var _fooBrandCheck = /*#__PURE__*/new WeakSet(); class Foo { - #foo = (_temp = 1, _fooBrandCheck.add(this), _temp); + #foo = (_fooBrandCheck.add(this), 1); test(other) { return _fooBrandCheck.has(other); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-instance/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-instance/output.js index 6a6068c69d7a..da91696ae063 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-instance/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-instance/output.js @@ -1,4 +1,4 @@ -var _temp, _temp2; +var _temp; var _FBrandCheck = /*#__PURE__*/new WeakSet(); @@ -19,10 +19,10 @@ class F { get #w() {} - #x = (_temp = (_FBrandCheck.add(this), 0), _xBrandCheck.add(this), _temp); - #y = (_temp2 = (() => { + #x = (_FBrandCheck.add(this), (_xBrandCheck.add(this), 0)); + #y = (_temp = (() => { throw 'error'; - })(), _yBrandCheck.add(this), _temp2); + })(), _yBrandCheck.add(this), _temp); #z() {} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-static/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-static/output.js index 5a318b582285..c6b53781a1c4 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-static/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-static/output.js @@ -1,4 +1,4 @@ -var _temp, _temp2; +var _temp; var _xBrandCheck = /*#__PURE__*/new WeakSet(); @@ -13,10 +13,10 @@ class F { F === this; } - static #x = (_temp = 0, _xBrandCheck.add(this), _temp); - static #y = (_temp2 = (() => { + static #x = (_xBrandCheck.add(this), 0); + static #y = (_temp = (() => { throw 'error'; - })(), _yBrandCheck.add(this), _temp2); + })(), _yBrandCheck.add(this), _temp); static #z() {} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-other-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-other-redeclared/output.js index 9048d000144f..1ccdc2a97a37 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-other-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-other-redeclared/output.js @@ -1,20 +1,16 @@ -var _temp, _temp3; - var _fooBrandCheck = /*#__PURE__*/new WeakSet(); var _barBrandCheck2 = /*#__PURE__*/new WeakSet(); class Foo { - #foo = (_temp = 1, _fooBrandCheck.add(this), _temp); - #bar = (_temp3 = 1, _barBrandCheck2.add(this), _temp3); + #foo = (_fooBrandCheck.add(this), 1); + #bar = (_barBrandCheck2.add(this), 1); test() { - var _temp2; - var _barBrandCheck = /*#__PURE__*/new WeakSet(); class Nested { - #bar = (_temp2 = 2, _barBrandCheck.add(this), _temp2); + #bar = (_barBrandCheck.add(this), 2); test() { _fooBrandCheck.has(this); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-redeclared/output.js index 279f759f6f6d..35cd3f938be4 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-redeclared/output.js @@ -1,17 +1,13 @@ -var _temp2; - var _fooBrandCheck2 = /*#__PURE__*/new WeakSet(); class Foo { - #foo = (_temp2 = 1, _fooBrandCheck2.add(this), _temp2); + #foo = (_fooBrandCheck2.add(this), 1); test() { - var _temp; - var _fooBrandCheck = /*#__PURE__*/new WeakSet(); class Nested { - #foo = (_temp = 2, _fooBrandCheck.add(this), _temp); + #foo = (_fooBrandCheck.add(this), 2); test() { _fooBrandCheck.has(this); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class/output.js index ff28dc79027c..46c5a47480d2 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class/output.js @@ -1,9 +1,7 @@ -var _temp; - var _fooBrandCheck = /*#__PURE__*/new WeakSet(); class Foo { - #foo = (_temp = 1, _fooBrandCheck.add(this), _temp); + #foo = (_fooBrandCheck.add(this), 1); test() { class Nested { diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-field/output.js index 588b3ad0b3c9..91193265df12 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-field/output.js @@ -1,9 +1,7 @@ -var _temp; - var _fooBrandCheck = /*#__PURE__*/new WeakSet(); class Foo { - static #foo = (_temp = 1, _fooBrandCheck.add(this), _temp); + static #foo = (_fooBrandCheck.add(this), 1); test(other) { return _fooBrandCheck.has(other); diff --git a/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties-loose/output.js b/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties-loose/output.js index a64af0349e52..19010c573c8f 100644 --- a/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties-loose/output.js +++ b/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties-loose/output.js @@ -1,8 +1,7 @@ class Foo { constructor() { var _newtarget = this.constructor, - _class, - _temp; + _class; this.test = function _target() { this instanceof _target ? this.constructor : void 0; @@ -12,7 +11,7 @@ class Foo { _newtarget; }; - this.Bar = (_temp = _class = class _target2 { + this.Bar = (_class = class _target2 { constructor() { this.q = this.constructor; } // should not replace @@ -29,7 +28,7 @@ class Foo { void 0; }, _class.p4 = function _target5() { this instanceof _target5 ? this.constructor : void 0; - }, _temp); + }, _class); } } diff --git a/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties/output.js b/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties/output.js index 50c1d35350a6..b37a4560aef0 100644 --- a/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties/output.js +++ b/packages/babel-plugin-transform-new-target/test/fixtures/general/class-properties/output.js @@ -1,8 +1,7 @@ class Foo { constructor() { var _newtarget = this.constructor, - _class, - _temp; + _class; babelHelpers.defineProperty(this, "test", function _target() { this instanceof _target ? this.constructor : void 0; @@ -10,7 +9,7 @@ class Foo { babelHelpers.defineProperty(this, "test2", function () { _newtarget; }); - this.Bar = (_temp = _class = class _target2 { + this.Bar = (_class = class _target2 { constructor() { babelHelpers.defineProperty(this, "q", this.constructor); } // should not replace @@ -27,7 +26,7 @@ class Foo { void 0; }), babelHelpers.defineProperty(_class, "p4", function _target5() { this instanceof _target5 ? this.constructor : void 0; - }), _temp); + }), _class); } } diff --git a/packages/babel-plugin-transform-parameters/test/fixtures/parameters/rest-arrow-functions/output.js b/packages/babel-plugin-transform-parameters/test/fixtures/parameters/rest-arrow-functions/output.js index 64af13d76e9b..ad95b7b156bf 100644 --- a/packages/babel-plugin-transform-parameters/test/fixtures/parameters/rest-arrow-functions/output.js +++ b/packages/babel-plugin-transform-parameters/test/fixtures/parameters/rest-arrow-functions/output.js @@ -44,16 +44,16 @@ var x = function () { }; var innerclassproperties = function () { - var _class, _temp; + var _class; for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { args[_key3] = arguments[_key3]; } - return _temp = _class = /*#__PURE__*/babelHelpers.createClass(function _class() { + return _class = /*#__PURE__*/babelHelpers.createClass(function _class() { "use strict"; babelHelpers.classCallCheck(this, _class); this.args = args; - }), _class.args = args, _temp; + }), _class.args = args, _class; }; diff --git a/packages/babel-traverse/src/path/modification.ts b/packages/babel-traverse/src/path/modification.ts index e4bbc8567fb7..01764659bb60 100644 --- a/packages/babel-traverse/src/path/modification.ts +++ b/packages/babel-traverse/src/path/modification.ts @@ -11,7 +11,13 @@ import { callExpression, cloneNode, expressionStatement, + isAssignmentExpression, + isCallExpression, isExpression, + isIdentifier, + isSequenceExpression, + isSuper, + thisExpression, } from "@babel/types"; import type * as t from "@babel/types"; import type Scope from "../scope"; @@ -100,6 +106,36 @@ export function _containerInsertAfter(this: NodePath, nodes) { return this._containerInsert(this.key + 1, nodes); } +const last = arr => arr[arr.length - 1]; + +function isHiddenInSequenceExpression(path: NodePath) { + return ( + isSequenceExpression(path.parent) && + (last(path.parent.expressions) !== path.node || + isHiddenInSequenceExpression(path.parentPath)) + ); +} + +function isAlmostConstantAssignment( + node: t.Node, + scope: Scope, +): node is t.AssignmentExpression & { left: t.Identifier } { + if (!isAssignmentExpression(node) || !isIdentifier(node.left)) { + return false; + } + + // Not every scope can contain variables. For example, we might be in + // a ClassScope either in the ClassHeritage or in a computed key. + const blockScope = scope.getBlockParent(); + + // If the variable is defined in the current scope and only assigned here, + // we can be sure that its value won't change. + return ( + blockScope.hasOwnBinding(node.left.name) && + blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1 + ); +} + /** * Insert the provided nodes after the current one. When inserting nodes after an * expression, ensure that the completion record is correct by pushing the current node. @@ -111,6 +147,10 @@ export function insertAfter( ): NodePath[] { this._assertUnremoved(); + if (this.isSequenceExpression()) { + return last(this.get("expressions")).insertAfter(nodes_); + } + const nodes = this._verifyNodeList(nodes_); const { parentPath } = this; @@ -149,21 +189,37 @@ export function insertAfter( return [this]; } - // Inserting after the computed key of a method should insert the - // temporary binding in the method's parent's scope. - if (parentPath.isMethod({ computed: true, key: node })) { - scope = scope.parent; + if (isHiddenInSequenceExpression(this)) { + nodes.unshift(node); + } + // We need to preserve the value of this expression. + else if (isCallExpression(node) && isSuper(node.callee)) { + nodes.unshift(node); + // `super(...)` always evaluates to `this`. + nodes.push(thisExpression()); + } else if (isAlmostConstantAssignment(node, scope)) { + nodes.unshift(node); + nodes.push(cloneNode(node.left)); + } else if (scope.isPure(node, true)) { + // Insert the nodes before rather than after; it's not observable. + nodes.push(node); + } else { + // Inserting after the computed key of a method should insert the + // temporary binding in the method's parent's scope. + if (parentPath.isMethod({ computed: true, key: node })) { + scope = scope.parent; + } + const temp = scope.generateDeclaredUidIdentifier(); + nodes.unshift( + expressionStatement( + // @ts-expect-error todo(flow->ts): This can be a variable + // declaraion in the "init" of a for statement, but that's + // invalid here. + assignmentExpression("=", cloneNode(temp), node), + ), + ); + nodes.push(expressionStatement(cloneNode(temp))); } - const temp = scope.generateDeclaredUidIdentifier(); - nodes.unshift( - expressionStatement( - // @ts-expect-error todo(flow->ts): This can be a variable - // declaraion in the "init" of a for statement, but that's - // invalid here. - assignmentExpression("=", cloneNode(temp), node), - ), - ); - nodes.push(expressionStatement(cloneNode(temp))); } // @ts-expect-error todo(flow->ts): check that nodes is an array of statements return this.replaceExpressionWithStatements(nodes); diff --git a/packages/babel-traverse/src/scope/index.ts b/packages/babel-traverse/src/scope/index.ts index 068b67b5b2d2..7170b5acacca 100644 --- a/packages/babel-traverse/src/scope/index.ts +++ b/packages/babel-traverse/src/scope/index.ts @@ -1020,8 +1020,8 @@ export default class Scope { } const declarator = variableDeclarator(opts.id, opts.init); - declarPath.node.declarations.push(declarator); - this.registerBinding(kind, declarPath.get("declarations").pop()); + const len = declarPath.node.declarations.push(declarator); + path.scope.registerBinding(kind, declarPath.get("declarations")[len - 1]); } /** diff --git a/packages/babel-traverse/test/modification.js b/packages/babel-traverse/test/modification.js index 5dc38ee31e63..3e86c04952d8 100644 --- a/packages/babel-traverse/test/modification.js +++ b/packages/babel-traverse/test/modification.js @@ -222,13 +222,13 @@ describe("modification", function () { }); it("the exported expression", function () { - const declPath = getPath("export default 2;", { + const declPath = getPath("export default fn();", { sourceType: "module", }); const path = declPath.get("declaration"); path.insertBefore(t.identifier("x")); - expect(generateCode(declPath)).toBe("export default (x, 2);"); + expect(generateCode(declPath)).toBe("export default (x, fn());"); }); }); }); @@ -336,14 +336,14 @@ describe("modification", function () { }); it("the exported expression", function () { - const bodyPath = getPath("export default 2;", { + const bodyPath = getPath("export default fn();", { sourceType: "module", }).parentPath; const path = bodyPath.get("body.0.declaration"); path.insertAfter(t.identifier("x")); expect(generateCode({ parentPath: bodyPath })).toBe( - "var _temp;\n\nexport default (_temp = 2, x, _temp);", + "var _temp;\n\nexport default (_temp = fn(), x, _temp);", ); }); }); diff --git a/packages/babel-traverse/test/scope.js b/packages/babel-traverse/test/scope.js index ea3375d18e0d..e5c2dfaa9611 100644 --- a/packages/babel-traverse/test/scope.js +++ b/packages/babel-traverse/test/scope.js @@ -922,4 +922,18 @@ describe("scope", () => { }); }); }); + + describe(".push", () => { + it("registers the new binding in the correct scope", () => { + const program = getPath("class A {}"); + const classDeclaration = program.get("body.0"); + classDeclaration.scope.push({ id: t.identifier("class") }); + expect(program.toString()).toMatchInlineSnapshot(` + "var class; + + class A {}" + `); + expect(program.scope.hasOwnBinding("class")).toBe(true); + }); + }); });