module.exports = function createGenArgument(type, optional) { const testcheckGen = t.memberExpression( t.identifier('testcheck'), t.identifier('gen') ); const typeIdentifier = t.memberExpression( testcheckGen, t.identifier(type) ); //if (!optional) { //const notEmptyIdentifier = t.memberExpression( //testcheckGen, //t.identifier('notEmpty') //); //return t.callExpression( //notEmptyIdentifier, //[typeIdentifier] //); //} return typeIdentifier; };
export default function bindifyDecorators(decorators: Array<NodePath>): Array<NodePath> { for (let decoratorPath of decorators) { let decorator = decoratorPath.node; let expression = decorator.expression; if (!t.isMemberExpression(expression)) continue; let temp = decoratorPath.scope.maybeGenerateMemoised(expression.object); let ref; let nodes = []; if (temp) { ref = temp; nodes.push(t.assignmentExpression("=", temp, expression.object)); } else { ref = expression.object; } nodes.push(t.callExpression( t.memberExpression( t.memberExpression(ref, expression.property, expression.computed), t.identifier("bind") ), [ref] )); if (nodes.length === 1) { decorator.expression = nodes[0]; } else { decorator.expression = t.sequenceExpression(nodes); } } }
wrapSuperCall(bareSuper, superRef, thisRef, body) { let bareSuperNode = bareSuper.node; if (this.isLoose) { bareSuperNode.arguments.unshift(t.thisExpression()); if (bareSuperNode.arguments.length === 2 && t.isSpreadElement(bareSuperNode.arguments[1]) && t.isIdentifier(bareSuperNode.arguments[1].argument, { name: "arguments" })) { // special case single arguments spread bareSuperNode.arguments[1] = bareSuperNode.arguments[1].argument; bareSuperNode.callee = t.memberExpression(superRef, t.identifier("apply")); } else { bareSuperNode.callee = t.memberExpression(superRef, t.identifier("call")); } } else { bareSuperNode = optimiseCall( t.callExpression( t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")), [this.classRef] ), t.thisExpression(), bareSuperNode.arguments ); } let call = t.callExpression( this.file.addHelper("possibleConstructorReturn"), [t.thisExpression(), bareSuperNode] ); let bareSuperAfter = this.bareSuperAfter.map((fn) => fn(thisRef)); if (bareSuper.parentPath.isExpressionStatement() && bareSuper.parentPath.container === body.node.body && body.node.body.length - 1 === bareSuper.parentPath.key) { // this super call is the last statement in the body so we can just straight up // turn it into a return if (this.superThises.length || bareSuperAfter.length) { bareSuper.scope.push({ id: thisRef }); call = t.assignmentExpression("=", thisRef, call); } if (bareSuperAfter.length) { call = t.toSequenceExpression([call, ...bareSuperAfter, thisRef]); } bareSuper.parentPath.replaceWith(t.returnStatement(call)); } else { bareSuper.replaceWithMultiple([ t.variableDeclaration("var", [ t.variableDeclarator(thisRef, call) ]), ...bareSuperAfter, t.expressionStatement(thisRef) ]); } }
/** * Creates an expression which result is the proto of objectRef. * Uses CLASS.__proto__ first for InternetExplorer <= 10 support * * @example <caption>isStatic === true</caption> * * CLASS.__proto__ || Object.getPrototypeOf(CLASS) * * @example <caption>isStatic === false</caption> * * CLASS.prototype.__proto__ || Object.getPrototypeOf(CLASS.prototype) */ function getPrototypeOfExpression(objectRef, isStatic) { const targetRef = isStatic ? objectRef : t.memberExpression(objectRef, t.identifier("prototype")); return t.logicalExpression( "||", t.memberExpression(targetRef, t.identifier("__proto__")), t.callExpression( t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")), [ targetRef ] ), ); }
getSuperProperty(property: Object, isComputed: boolean): Object { return t.callExpression( this.file.addHelper("get"), [ t.callExpression( t.memberExpression(t.identifier("Object"), t.identifier("getPrototypeOf")), [ this.isStatic ? this.getObjectRef() : t.memberExpression(this.getObjectRef(), t.identifier("prototype")) ] ), isComputed ? property : t.stringLiteral(property.name), t.thisExpression() ] ); }
Ep.contextProperty = function(name, computed) { return t.memberExpression( this.contextId, computed ? t.stringLiteral(name) : t.identifier(name), !!computed ); };