Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function processMethod(node, scope) {
if (classState.isLoose && !node.decorators) {
// use assignments instead of define properties for loose classes
let { classRef } = classState;
if (!node.static) {
insertProtoAliasOnce();
classRef = classState.protoAlias;
}
const methodName = t.memberExpression(
t.cloneNode(classRef),
node.key,
node.computed || t.isLiteral(node.key),
);
let func = t.functionExpression(
null,
node.params,
node.body,
node.generator,
node.async,
);
t.inherits(func, node);
const key = t.toComputedKey(node, node.key);
if (t.isStringLiteral(key)) {
func = nameFunction({
_processMethod(node, scope) {
if (!node.decorators) {
// use assignments instead of define properties for loose classes
let classRef = this.classRef;
if (!node.static) {
this._insertProtoAliasOnce();
classRef = this._protoAlias;
}
const methodName = t.memberExpression(
t.cloneNode(classRef),
node.key,
node.computed || t.isLiteral(node.key),
);
let func = t.functionExpression(
null,
node.params,
node.body,
node.generator,
node.async,
);
func.returnType = node.returnType;
const key = t.toComputedKey(node, node.key);
if (t.isStringLiteral(key)) {
func = nameFunction({
node: func,
const restElement = t.cloneNode(last.node);
last.remove();
const impureComputedPropertyDeclarators = replaceImpureComputedKeys(
path.get("properties"),
path.scope,
);
const { keys, allLiteral } = extractNormalizedKeys(path);
if (keys.length === 0) {
return [
impureComputedPropertyDeclarators,
restElement.argument,
t.callExpression(getExtendsHelper(file), [
t.objectExpression([]),
t.cloneNode(objRef),
]),
];
}
let keyExpression;
if (!allLiteral) {
// map to toPropertyKey to handle the possible non-string values
keyExpression = t.callExpression(
t.memberExpression(t.arrayExpression(keys), t.identifier("map")),
[file.addHelper("toPropertyKey")],
);
} else {
keyExpression = t.arrayExpression(keys);
}
return [
) {
// const { a, ...b } = foo();
// to avoid calling foo() twice, as a first step convert it to:
// const _foo = foo(),
// { a, ...b } = _foo;
const initRef = path.scope.generateUidIdentifierBasedOnNode(
originalPath.node.init,
"ref",
);
// insert _foo = foo()
originalPath.insertBefore(
t.variableDeclarator(initRef, originalPath.node.init),
);
// replace foo() with _foo
originalPath.replaceWith(
t.variableDeclarator(originalPath.node.id, t.cloneNode(initRef)),
);
return;
}
let ref = originalPath.node.init;
const refPropertyPath = [];
let kind;
path.findParent(path => {
if (path.isObjectProperty()) {
refPropertyPath.unshift(path);
} else if (path.isVariableDeclarator()) {
kind = path.parentPath.node.kind;
return true;
}
]);
} else {
acc = acc.concat(
t.callExpression(state.addHelper("applyDecoratedDescriptor"), [
t.cloneNode(target),
t.cloneNode(property),
t.arrayExpression(decorators.map(dec => t.cloneNode(dec.expression))),
t.isObjectProperty(node) || t.isClassProperty(node, { static: true })
? buildGetObjectInitializer({
TEMP: path.scope.generateDeclaredUidIdentifier("init"),
TARGET: t.cloneNode(target),
PROPERTY: t.cloneNode(property),
}).expression
: buildGetDescriptor({
TARGET: t.cloneNode(target),
PROPERTY: t.cloneNode(property),
}).expression,
t.cloneNode(target),
]),
);
}
return acc;
}, []);
if (!isStringsRawEqual) {
callExpressionInput.push(t.arrayExpression(raws));
}
const lazyLoad = template.ast`
function ${templateObject}() {
const data = ${t.callExpression(helperId, callExpressionInput)};
${templateObject} = function() { return data };
return data;
}
`;
scope.path.unshiftContainer("body", lazyLoad);
path.replaceWith(
t.callExpression(node.tag, [
t.callExpression(t.cloneNode(templateObject), []),
...quasi.expressions,
]),
);
},
);
break;
case isStatic && isPrivate && isField && !loose:
needsClassRef = true;
staticNodes.push(
buildPrivateStaticFieldInitSpec(prop, privateNamesMap),
);
break;
case isStatic && isPublic && isField && loose:
needsClassRef = true;
staticNodes.push(buildPublicFieldInitLoose(t.cloneNode(ref), prop));
break;
case isStatic && isPublic && isField && !loose:
needsClassRef = true;
staticNodes.push(
buildPublicFieldInitSpec(t.cloneNode(ref), prop, state),
);
break;
case isInstance && isPrivate && isField && loose:
instanceNodes.push(
buildPrivateFieldInitLoose(t.thisExpression(), prop, privateNamesMap),
);
break;
case isInstance && isPrivate && isField && !loose:
instanceNodes.push(
buildPrivateInstanceFieldInitSpec(
t.thisExpression(),
prop,
privateNamesMap,
),
);
break;
receiver(member) {
const { object } = member.node;
if (this.memoiser.has(object)) {
return t.cloneNode(this.memoiser.get(object));
}
return t.cloneNode(object);
},
: buildGetDescriptor({
TARGET: t.cloneNode(target),
PROPERTY: t.cloneNode(property),
}).expression,
t.cloneNode(target),
]),
);
}
return acc;
}, []);
return t.sequenceExpression([
t.assignmentExpression("=", t.cloneNode(name), path.node),
t.sequenceExpression(exprs),
t.cloneNode(name),
]);
}
if (prop.kind === "get" || prop.kind === "set") {
pushMutatorDefine(info, prop);
} else if (t.isStringLiteral(key, { value: "__proto__" })) {
pushAssign(objId, prop, body);
} else {
if (computedProps.length === 1) {
return t.callExpression(state.addHelper("defineProperty"), [
info.initPropExpression,
key,
getValue(prop),
]);
} else {
body.push(
t.expressionStatement(
t.callExpression(state.addHelper("defineProperty"), [
t.cloneNode(objId),
key,
getValue(prop),
]),
),
);
}
}
}
}