* Fix #4840: Alias class prototype for methods in loose mode * Cleanup
This commit is contained in:
committed by
Justin Ridgewell
parent
d8b4073536
commit
960151c876
@@ -5,16 +5,33 @@ import * as t from "babel-types";
|
||||
export default class LooseClassTransformer extends VanillaTransformer {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this._protoAlias = null;
|
||||
this.isLoose = true;
|
||||
}
|
||||
|
||||
_insertProtoAliasOnce() {
|
||||
if (!this._protoAlias) {
|
||||
this._protoAlias = this.scope.generateUidIdentifier("proto");
|
||||
const classProto = t.memberExpression(
|
||||
this.classRef,
|
||||
t.identifier("prototype"),
|
||||
);
|
||||
const protoDeclaration = t.variableDeclaration("var", [
|
||||
t.variableDeclarator(this._protoAlias, classProto),
|
||||
]);
|
||||
|
||||
this.body.push(protoDeclaration);
|
||||
}
|
||||
}
|
||||
|
||||
_processMethod(node, scope) {
|
||||
if (!node.decorators) {
|
||||
// use assignments instead of define properties for loose classes
|
||||
|
||||
let classRef = this.classRef;
|
||||
if (!node.static) {
|
||||
classRef = t.memberExpression(classRef, t.identifier("prototype"));
|
||||
this._insertProtoAliasOnce();
|
||||
classRef = this._protoAlias;
|
||||
}
|
||||
const methodName = t.memberExpression(
|
||||
classRef,
|
||||
|
||||
Reference in New Issue
Block a user