update
This commit is contained in:
+25
-15
@@ -7,30 +7,34 @@ exports.default = void 0;
|
||||
|
||||
var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
||||
|
||||
var _helperAnnotateAsPure = _interopRequireDefault(require("@babel/helper-annotate-as-pure"));
|
||||
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
|
||||
|
||||
var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name"));
|
||||
var _helperFunctionName = require("@babel/helper-function-name");
|
||||
|
||||
var _helperSplitExportDeclaration = _interopRequireDefault(require("@babel/helper-split-export-declaration"));
|
||||
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
|
||||
|
||||
var _core = require("@babel/core");
|
||||
|
||||
var _globals = _interopRequireDefault(require("globals"));
|
||||
var _globals = require("globals");
|
||||
|
||||
var _transformClass = _interopRequireDefault(require("./transformClass"));
|
||||
var _transformClass = require("./transformClass");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const getBuiltinClasses = category => Object.keys(_globals.default[category]).filter(name => /^[A-Z]/.test(name));
|
||||
const getBuiltinClasses = category => Object.keys(_globals[category]).filter(name => /^[A-Z]/.test(name));
|
||||
|
||||
const builtinClasses = new Set([...getBuiltinClasses("builtin"), ...getBuiltinClasses("browser")]);
|
||||
|
||||
var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
var _api$assumption, _api$assumption2, _api$assumption3, _api$assumption4;
|
||||
|
||||
api.assertVersion(7);
|
||||
const {
|
||||
loose
|
||||
loose = false
|
||||
} = options;
|
||||
const VISITED = Symbol();
|
||||
const setClassMethods = (_api$assumption = api.assumption("setClassMethods")) != null ? _api$assumption : loose;
|
||||
const constantSuper = (_api$assumption2 = api.assumption("constantSuper")) != null ? _api$assumption2 : loose;
|
||||
const superIsCallableConstructor = (_api$assumption3 = api.assumption("superIsCallableConstructor")) != null ? _api$assumption3 : loose;
|
||||
const noClassCalls = (_api$assumption4 = api.assumption("noClassCalls")) != null ? _api$assumption4 : loose;
|
||||
const VISITED = new WeakSet();
|
||||
return {
|
||||
name: "transform-classes",
|
||||
visitor: {
|
||||
@@ -51,7 +55,7 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
const {
|
||||
node
|
||||
} = path;
|
||||
if (node[VISITED]) return;
|
||||
if (VISITED.has(node)) return;
|
||||
const inferred = (0, _helperFunctionName.default)(path);
|
||||
|
||||
if (inferred && inferred !== node) {
|
||||
@@ -59,14 +63,20 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
return;
|
||||
}
|
||||
|
||||
node[VISITED] = true;
|
||||
path.replaceWith((0, _transformClass.default)(path, state.file, builtinClasses, loose));
|
||||
VISITED.add(node);
|
||||
path.replaceWith((0, _transformClass.default)(path, state.file, builtinClasses, loose, {
|
||||
setClassMethods,
|
||||
constantSuper,
|
||||
superIsCallableConstructor,
|
||||
noClassCalls
|
||||
}));
|
||||
|
||||
if (path.isCallExpression()) {
|
||||
(0, _helperAnnotateAsPure.default)(path);
|
||||
const callee = path.get("callee");
|
||||
|
||||
if (path.get("callee").isArrowFunctionExpression()) {
|
||||
path.get("callee").arrowFunctionToExpression();
|
||||
if (callee.isArrowFunctionExpression()) {
|
||||
callee.arrowFunctionToExpression();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+148
-101
@@ -5,25 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = transformClass;
|
||||
|
||||
var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name"));
|
||||
var _helperFunctionName = require("@babel/helper-function-name");
|
||||
|
||||
var _helperReplaceSupers = _interopRequireWildcard(require("@babel/helper-replace-supers"));
|
||||
var _helperReplaceSupers = require("@babel/helper-replace-supers");
|
||||
|
||||
var _helperOptimiseCallExpression = _interopRequireDefault(require("@babel/helper-optimise-call-expression"));
|
||||
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
|
||||
|
||||
var defineMap = _interopRequireWildcard(require("@babel/helper-define-map"));
|
||||
var _helperOptimiseCallExpression = require("@babel/helper-optimise-call-expression");
|
||||
|
||||
var _core = require("@babel/core");
|
||||
|
||||
var _helperAnnotateAsPure = _interopRequireDefault(require("@babel/helper-annotate-as-pure"));
|
||||
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
|
||||
|
||||
var _inlineCreateSuperHelpers = _interopRequireDefault(require("./inline-createSuper-helpers"));
|
||||
|
||||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
var _inlineCreateSuperHelpers = require("./inline-createSuper-helpers");
|
||||
|
||||
function buildConstructor(classRef, constructorBody, node) {
|
||||
const func = _core.types.functionDeclaration(_core.types.cloneNode(classRef), [], constructorBody);
|
||||
@@ -33,7 +27,7 @@ function buildConstructor(classRef, constructorBody, node) {
|
||||
return func;
|
||||
}
|
||||
|
||||
function transformClass(path, file, builtinClasses, isLoose) {
|
||||
function transformClass(path, file, builtinClasses, isLoose, assumptions) {
|
||||
const classState = {
|
||||
parent: undefined,
|
||||
scope: undefined,
|
||||
@@ -43,7 +37,7 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
classId: undefined,
|
||||
classRef: undefined,
|
||||
superFnId: undefined,
|
||||
superName: undefined,
|
||||
superName: null,
|
||||
superReturns: [],
|
||||
isDerived: false,
|
||||
extendsNative: false,
|
||||
@@ -52,54 +46,41 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
userConstructor: undefined,
|
||||
userConstructorPath: undefined,
|
||||
hasConstructor: false,
|
||||
instancePropBody: [],
|
||||
instancePropRefs: {},
|
||||
staticPropBody: [],
|
||||
body: [],
|
||||
superThises: [],
|
||||
pushedConstructor: false,
|
||||
pushedInherits: false,
|
||||
pushedCreateClass: false,
|
||||
protoAlias: null,
|
||||
isLoose: false,
|
||||
hasInstanceDescriptors: false,
|
||||
hasStaticDescriptors: false,
|
||||
instanceMutatorMap: {},
|
||||
staticMutatorMap: {}
|
||||
dynamicKeys: new Map(),
|
||||
methods: {
|
||||
instance: {
|
||||
hasComputed: false,
|
||||
list: [],
|
||||
map: new Map()
|
||||
},
|
||||
static: {
|
||||
hasComputed: false,
|
||||
list: [],
|
||||
map: new Map()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const setState = newState => {
|
||||
Object.assign(classState, newState);
|
||||
};
|
||||
|
||||
const findThisesVisitor = _core.traverse.visitors.merge([_helperReplaceSupers.environmentVisitor, {
|
||||
const findThisesVisitor = _core.traverse.visitors.merge([_helperEnvironmentVisitor.default, {
|
||||
ThisExpression(path) {
|
||||
classState.superThises.push(path);
|
||||
}
|
||||
|
||||
}]);
|
||||
|
||||
function pushToMap(node, enumerable, kind = "value", scope) {
|
||||
let mutatorMap;
|
||||
|
||||
if (node.static) {
|
||||
setState({
|
||||
hasStaticDescriptors: true
|
||||
});
|
||||
mutatorMap = classState.staticMutatorMap;
|
||||
} else {
|
||||
setState({
|
||||
hasInstanceDescriptors: true
|
||||
});
|
||||
mutatorMap = classState.instanceMutatorMap;
|
||||
}
|
||||
|
||||
const map = defineMap.push(mutatorMap, node, kind, classState.file, scope);
|
||||
|
||||
if (enumerable) {
|
||||
map.enumerable = _core.types.booleanLiteral(true);
|
||||
}
|
||||
|
||||
return map;
|
||||
function createClassHelper(args) {
|
||||
return _core.types.callExpression(classState.file.addHelper("createClass"), args);
|
||||
}
|
||||
|
||||
function maybeCreateConstructor() {
|
||||
@@ -141,7 +122,7 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
userConstructor,
|
||||
construct
|
||||
} = classState;
|
||||
constructorBody.body = constructorBody.body.concat(userConstructor.body.body);
|
||||
constructorBody.body.push(...userConstructor.body.body);
|
||||
|
||||
_core.types.inherits(construct, userConstructor);
|
||||
|
||||
@@ -171,12 +152,13 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
methodPath: path,
|
||||
objectRef: classState.classRef,
|
||||
superRef: classState.superName,
|
||||
isLoose: classState.isLoose,
|
||||
file: classState.file
|
||||
constantSuper: assumptions.constantSuper,
|
||||
file: classState.file,
|
||||
refToPreserve: classState.classRef
|
||||
});
|
||||
replaceSupers.replace();
|
||||
const superReturns = [];
|
||||
path.traverse(_core.traverse.visitors.merge([_helperReplaceSupers.environmentVisitor, {
|
||||
path.traverse(_core.traverse.visitors.merge([_helperEnvironmentVisitor.default, {
|
||||
ReturnStatement(path) {
|
||||
if (!path.getFunctionParent().isArrowFunctionExpression()) {
|
||||
superReturns.push(path);
|
||||
@@ -194,43 +176,34 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
}
|
||||
}
|
||||
|
||||
function clearDescriptors() {
|
||||
setState({
|
||||
hasInstanceDescriptors: false,
|
||||
hasStaticDescriptors: false,
|
||||
instanceMutatorMap: {},
|
||||
staticMutatorMap: {}
|
||||
});
|
||||
}
|
||||
|
||||
function pushDescriptors() {
|
||||
pushInheritsToBody();
|
||||
const {
|
||||
body
|
||||
} = classState;
|
||||
let instanceProps;
|
||||
let staticProps;
|
||||
const props = {
|
||||
instance: null,
|
||||
static: null
|
||||
};
|
||||
|
||||
if (classState.hasInstanceDescriptors) {
|
||||
instanceProps = defineMap.toClassObject(classState.instanceMutatorMap);
|
||||
for (const placement of ["static", "instance"]) {
|
||||
if (classState.methods[placement].list.length) {
|
||||
props[placement] = classState.methods[placement].list.map(desc => {
|
||||
const obj = _core.types.objectExpression([_core.types.objectProperty(_core.types.identifier("key"), desc.key)]);
|
||||
|
||||
for (const kind of ["get", "set", "value"]) {
|
||||
if (desc[kind] != null) {
|
||||
obj.properties.push(_core.types.objectProperty(_core.types.identifier(kind), desc[kind]));
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (classState.hasStaticDescriptors) {
|
||||
staticProps = defineMap.toClassObject(classState.staticMutatorMap);
|
||||
}
|
||||
|
||||
if (instanceProps || staticProps) {
|
||||
if (instanceProps) {
|
||||
instanceProps = defineMap.toComputedObjectFromClass(instanceProps);
|
||||
}
|
||||
|
||||
if (staticProps) {
|
||||
staticProps = defineMap.toComputedObjectFromClass(staticProps);
|
||||
}
|
||||
|
||||
let args = [_core.types.cloneNode(classState.classRef), _core.types.nullLiteral(), _core.types.nullLiteral()];
|
||||
if (instanceProps) args[1] = instanceProps;
|
||||
if (staticProps) args[2] = staticProps;
|
||||
if (props.instance || props.static) {
|
||||
let args = [_core.types.cloneNode(classState.classRef), props.instance ? _core.types.arrayExpression(props.instance) : _core.types.nullLiteral(), props.static ? _core.types.arrayExpression(props.static) : _core.types.nullLiteral()];
|
||||
let lastNonNullIndex = 0;
|
||||
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
@@ -238,17 +211,16 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
}
|
||||
|
||||
args = args.slice(0, lastNonNullIndex + 1);
|
||||
body.push(_core.types.expressionStatement(_core.types.callExpression(classState.file.addHelper("createClass"), args)));
|
||||
body.push(_core.types.expressionStatement(createClassHelper(args)));
|
||||
classState.pushedCreateClass = true;
|
||||
}
|
||||
|
||||
clearDescriptors();
|
||||
}
|
||||
|
||||
function wrapSuperCall(bareSuper, superRef, thisRef, body) {
|
||||
const bareSuperNode = bareSuper.node;
|
||||
let call;
|
||||
|
||||
if (classState.isLoose) {
|
||||
if (assumptions.superIsCallableConstructor) {
|
||||
bareSuperNode.arguments.unshift(_core.types.thisExpression());
|
||||
|
||||
if (bareSuperNode.arguments.length === 2 && _core.types.isSpreadElement(bareSuperNode.arguments[1]) && _core.types.isIdentifier(bareSuperNode.arguments[1].argument, {
|
||||
@@ -262,7 +234,7 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
|
||||
call = _core.types.logicalExpression("||", bareSuperNode, _core.types.thisExpression());
|
||||
} else {
|
||||
call = (0, _helperOptimiseCallExpression.default)(_core.types.cloneNode(classState.superFnId), _core.types.thisExpression(), bareSuperNode.arguments);
|
||||
call = (0, _helperOptimiseCallExpression.default)(_core.types.cloneNode(classState.superFnId), _core.types.thisExpression(), bareSuperNode.arguments, false);
|
||||
}
|
||||
|
||||
if (bareSuper.parentPath.isExpressionStatement() && bareSuper.parentPath.container === body.node.body && body.node.body.length - 1 === bareSuper.parentPath.key) {
|
||||
@@ -306,8 +278,8 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
thisPath.replaceWith(_core.types.callExpression(classState.file.addHelper("assertThisInitialized"), [thisRef()]));
|
||||
}
|
||||
|
||||
const bareSupers = new Set();
|
||||
path.traverse(_core.traverse.visitors.merge([_helperReplaceSupers.environmentVisitor, {
|
||||
const bareSupers = [];
|
||||
path.traverse(_core.traverse.visitors.merge([_helperEnvironmentVisitor.default, {
|
||||
Super(path) {
|
||||
const {
|
||||
node,
|
||||
@@ -317,12 +289,12 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
if (parentPath.isCallExpression({
|
||||
callee: node
|
||||
})) {
|
||||
bareSupers.add(parentPath);
|
||||
bareSupers.unshift(parentPath);
|
||||
}
|
||||
}
|
||||
|
||||
}]));
|
||||
let guaranteedSuperBeforeFinish = !!bareSupers.size;
|
||||
let guaranteedSuperBeforeFinish = !!bareSupers.length;
|
||||
|
||||
for (const bareSuper of bareSupers) {
|
||||
wrapSuperCall(bareSuper, classState.superName, thisRef, body);
|
||||
@@ -350,7 +322,15 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
return returnArg ? _core.types.logicalExpression("||", returnArg, thisExpr) : thisExpr;
|
||||
};
|
||||
} else {
|
||||
wrapReturn = returnArg => _core.types.callExpression(classState.file.addHelper("possibleConstructorReturn"), [thisRef()].concat(returnArg || []));
|
||||
wrapReturn = returnArg => {
|
||||
const returnParams = [thisRef()];
|
||||
|
||||
if (returnArg != null) {
|
||||
returnParams.push(returnArg);
|
||||
}
|
||||
|
||||
return _core.types.callExpression(classState.file.addHelper("possibleConstructorReturn"), returnParams);
|
||||
};
|
||||
}
|
||||
|
||||
const bodyPaths = body.get("body");
|
||||
@@ -371,11 +351,52 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
if (processMethod(node, scope)) return;
|
||||
}
|
||||
|
||||
pushToMap(node, false, null, scope);
|
||||
const placement = node.static ? "static" : "instance";
|
||||
const methods = classState.methods[placement];
|
||||
const descKey = node.kind === "method" ? "value" : node.kind;
|
||||
const key = _core.types.isNumericLiteral(node.key) || _core.types.isBigIntLiteral(node.key) ? _core.types.stringLiteral(String(node.key.value)) : _core.types.toComputedKey(node);
|
||||
|
||||
let fn = _core.types.toExpression(node);
|
||||
|
||||
if (_core.types.isStringLiteral(key)) {
|
||||
if (node.kind === "method") {
|
||||
fn = (0, _helperFunctionName.default)({
|
||||
id: key,
|
||||
node: node,
|
||||
scope
|
||||
});
|
||||
}
|
||||
} else {
|
||||
methods.hasComputed = true;
|
||||
}
|
||||
|
||||
let descriptor;
|
||||
|
||||
if (!methods.hasComputed && methods.map.has(key.value)) {
|
||||
descriptor = methods.map.get(key.value);
|
||||
descriptor[descKey] = fn;
|
||||
|
||||
if (descKey === "value") {
|
||||
descriptor.get = null;
|
||||
descriptor.set = null;
|
||||
} else {
|
||||
descriptor.value = null;
|
||||
}
|
||||
} else {
|
||||
descriptor = {
|
||||
key: key,
|
||||
[descKey]: fn
|
||||
};
|
||||
methods.list.push(descriptor);
|
||||
|
||||
if (!methods.hasComputed) {
|
||||
methods.map.set(key.value, descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function processMethod(node, scope) {
|
||||
if (classState.isLoose && !node.decorators) {
|
||||
if (assumptions.setClassMethods && !node.decorators) {
|
||||
let {
|
||||
classRef
|
||||
} = classState;
|
||||
@@ -427,10 +448,6 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
}
|
||||
|
||||
function pushConstructor(superReturns, method, path) {
|
||||
if (path.scope.hasOwnBinding(classState.classRef.name)) {
|
||||
path.scope.rename(classState.classRef.name);
|
||||
}
|
||||
|
||||
setState({
|
||||
userConstructorPath: path,
|
||||
userConstructor: method,
|
||||
@@ -471,16 +488,33 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
superFnId
|
||||
});
|
||||
|
||||
if (!classState.isLoose) {
|
||||
if (!assumptions.superIsCallableConstructor) {
|
||||
classState.body.unshift(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(superFnId, _core.types.callExpression((0, _inlineCreateSuperHelpers.default)(classState.file), [_core.types.cloneNode(classState.classRef)]))]));
|
||||
}
|
||||
|
||||
classState.body.unshift(_core.types.expressionStatement(_core.types.callExpression(classState.file.addHelper(classState.isLoose ? "inheritsLoose" : "inherits"), [_core.types.cloneNode(classState.classRef), _core.types.cloneNode(classState.superName)])));
|
||||
}
|
||||
|
||||
function extractDynamicKeys() {
|
||||
const {
|
||||
dynamicKeys,
|
||||
node,
|
||||
scope
|
||||
} = classState;
|
||||
|
||||
for (const elem of node.body.body) {
|
||||
if (!_core.types.isClassMethod(elem) || !elem.computed) continue;
|
||||
if (scope.isPure(elem.key, true)) continue;
|
||||
const id = scope.generateUidIdentifierBasedOnNode(elem.key);
|
||||
dynamicKeys.set(id.name, elem.key);
|
||||
elem.key = id;
|
||||
}
|
||||
}
|
||||
|
||||
function setupClosureParamsArgs() {
|
||||
const {
|
||||
superName
|
||||
superName,
|
||||
dynamicKeys
|
||||
} = classState;
|
||||
const closureParams = [];
|
||||
const closureArgs = [];
|
||||
@@ -501,6 +535,11 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
});
|
||||
}
|
||||
|
||||
for (const [name, value] of dynamicKeys) {
|
||||
closureParams.push(_core.types.identifier(name));
|
||||
closureArgs.push(value);
|
||||
}
|
||||
|
||||
return {
|
||||
closureParams,
|
||||
closureArgs
|
||||
@@ -524,7 +563,7 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
constructorBody: _core.types.blockStatement([])
|
||||
});
|
||||
setState({
|
||||
extendsNative: classState.isDerived && builtinClasses.has(classState.superName.name) && !classState.scope.hasBinding(classState.superName.name, true)
|
||||
extendsNative: _core.types.isIdentifier(classState.superName) && builtinClasses.has(classState.superName.name) && !classState.scope.hasBinding(classState.superName.name, true)
|
||||
});
|
||||
const {
|
||||
classRef,
|
||||
@@ -534,7 +573,8 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
setState({
|
||||
construct: buildConstructor(classRef, constructorBody, node)
|
||||
});
|
||||
let {
|
||||
extractDynamicKeys();
|
||||
const {
|
||||
body
|
||||
} = classState;
|
||||
const {
|
||||
@@ -543,11 +583,10 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
} = setupClosureParamsArgs();
|
||||
buildBody();
|
||||
|
||||
if (!classState.isLoose) {
|
||||
if (!assumptions.noClassCalls) {
|
||||
constructorBody.body.unshift(_core.types.expressionStatement(_core.types.callExpression(classState.file.addHelper("classCallCheck"), [_core.types.thisExpression(), _core.types.cloneNode(classState.classRef)])));
|
||||
}
|
||||
|
||||
body = body.concat(classState.staticPropBody.map(fn => fn(_core.types.cloneNode(classState.classRef))));
|
||||
const isStrict = path.isInStrictMode();
|
||||
let constructorOnly = classState.classId && body.length === 1;
|
||||
|
||||
@@ -567,10 +606,18 @@ function transformClass(path, file, builtinClasses, isLoose) {
|
||||
}
|
||||
|
||||
if (constructorOnly) {
|
||||
return _core.types.toExpression(body[0]);
|
||||
const expr = _core.types.toExpression(body[0]);
|
||||
|
||||
return classState.isLoose ? expr : createClassHelper([expr]);
|
||||
}
|
||||
|
||||
body.push(_core.types.returnStatement(_core.types.cloneNode(classState.classRef)));
|
||||
let returnArg = _core.types.cloneNode(classState.classRef);
|
||||
|
||||
if (!classState.pushedCreateClass && !classState.isLoose) {
|
||||
returnArg = createClassHelper([returnArg]);
|
||||
}
|
||||
|
||||
body.push(_core.types.returnStatement(returnArg));
|
||||
|
||||
const container = _core.types.arrowFunctionExpression(closureParams, _core.types.blockStatement(body, directives));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user