Merge pull request #3096 from loganfsmyth/double-class-traverse
Avoid duplicating traversal of class declarations - fixes T2694
This commit is contained in:
commit
ba0388eba5
@ -8,5 +8,5 @@ var MyClass2 = function MyClass2() {
|
||||
babelHelpers.classCallCheck(this, MyClass2);
|
||||
};
|
||||
|
||||
export default MyClass2;
|
||||
MyClass2.property = value;
|
||||
export default MyClass2;
|
||||
|
||||
@ -8,16 +8,23 @@ export default function ({ types: t }) {
|
||||
|
||||
return {
|
||||
visitor: {
|
||||
ExportDefaultDeclaration(path){
|
||||
if (!path.get("declaration").isClassDeclaration()) return;
|
||||
|
||||
let { node } = path;
|
||||
let ref = node.declaration.id || path.scope.generateUidIdentifier("class");
|
||||
node.declaration.id = ref;
|
||||
|
||||
// Split the class declaration and the export into two separate statements.
|
||||
path.replaceWith(node.declaration);
|
||||
path.insertAfter(t.exportDefaultDeclaration(ref));
|
||||
},
|
||||
|
||||
ClassDeclaration(path) {
|
||||
let { node } = path;
|
||||
|
||||
let ref = node.id || path.scope.generateUidIdentifier("class");
|
||||
|
||||
if (path.parentPath.isExportDefaultDeclaration()) {
|
||||
path = path.parentPath;
|
||||
path.insertAfter(t.exportDefaultDeclaration(ref));
|
||||
}
|
||||
|
||||
path.replaceWith(t.variableDeclaration("let", [
|
||||
t.variableDeclarator(ref, t.toExpression(node))
|
||||
]));
|
||||
|
||||
16
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/3028/actual.js
vendored
Normal file
16
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/3028/actual.js
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
class b {
|
||||
}
|
||||
|
||||
class a1 extends b {
|
||||
constructor() {
|
||||
super();
|
||||
this.x = () => this;
|
||||
}
|
||||
}
|
||||
|
||||
export default class a2 extends b {
|
||||
constructor() {
|
||||
super();
|
||||
this.x = () => this;
|
||||
}
|
||||
}
|
||||
45
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/3028/expected.js
vendored
Normal file
45
packages/babel-plugin-transform-es2015-classes/test/fixtures/regression/3028/expected.js
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var b = function b() {
|
||||
babelHelpers.classCallCheck(this, b);
|
||||
};
|
||||
|
||||
var a1 = (function (_b) {
|
||||
babelHelpers.inherits(a1, _b);
|
||||
|
||||
function a1() {
|
||||
babelHelpers.classCallCheck(this, a1);
|
||||
|
||||
var _this = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(a1).call(this));
|
||||
|
||||
_this.x = function () {
|
||||
return _this;
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
|
||||
return a1;
|
||||
})(b);
|
||||
|
||||
var a2 = (function (_b2) {
|
||||
babelHelpers.inherits(a2, _b2);
|
||||
|
||||
function a2() {
|
||||
babelHelpers.classCallCheck(this, a2);
|
||||
|
||||
var _this2 = babelHelpers.possibleConstructorReturn(this, Object.getPrototypeOf(a2).call(this));
|
||||
|
||||
_this2.x = function () {
|
||||
return _this2;
|
||||
};
|
||||
return _this2;
|
||||
}
|
||||
|
||||
return a2;
|
||||
})(b);
|
||||
|
||||
exports.default = a2;
|
||||
Loading…
x
Reference in New Issue
Block a user