Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
extendClass = _getArgumentFromNodeAsString(path, 5, config)
} catch (e) {
config.logger.warn(e.message)
return;
}
var overriddenMethodNames = _getOverriddenMethodsTypescript(path, 3);
var extendPath = _getParent(path, 3, config);
var declaredClassName = "";
var typescriptClassExtendSuperCallLocation = getTypeScriptExtendSuperCallLocation(extendPath, config);
var extendParent = _getParent(path, 1, config);
if (types.isCallExpression(extendParent)) {
declaredClassName = extendParent.node.arguments[0].name;
}
var decorateNodes = traverseForDecorate(path, config, 3);
var isDecoratedWithExtend = false,
customExtendDecoratorName,
customExtendDecoratorValue,
implementedInterfaces = [];
if (!decorateNodes) {
// 7 -> Takes 7 levels up to get to the scope where the class is declared
decorateNodes = traverseForDecorateSpecial(path, config, 7);
}
if (decorateNodes) {
if (duplicateJsImportSpecifier) {
importDeclarationContainerArray.splice(
importDeclarationContainerArray.indexOf(jsImport), 1);
}
}
}
// Dynamic Import
if (jsImport.type === 'Import') {
// Transform:
// import('./some/module.js')
// Into:
// import('./bundle_1.js')
// .then(({ $bundled$some$module }) => $bundled$some$module)
const importCallExpression = babelUtils.getParentNode(astRoot, jsImport);
if (!importCallExpression ||
!babel.isCallExpression(importCallExpression)) {
// TODO(usergenic): This log should be a real error or warning or
// something.
console.log(
'CAN NOT INSERT CODE BECAUSE CAN NOT FIND PARENT OF IMPORT IN DOCUMENT AST');
continue;
}
const importCallArgument = importCallExpression.arguments[0]!;
if (!babel.isStringLiteral(importCallArgument)) {
console.log(
'CAN NOT FIGURE OUT WHERE THE DYNAMIC IMPORT IS PULLING FROM. I ONLY UNDERSTAND STRING LITERALS');
continue;
}
const sourceUrl = importCallArgument.value;
const resolvedSourceUrl =
urlLib.resolve(docBundle.url, sourceUrl) as ResolvedUrl;
const sourceBundle = bundleManifest.getBundleForFile(resolvedSourceUrl);
const isStyled = (tag, state) => {
if (
t.isCallExpression(tag) &&
t.isMemberExpression(tag.callee) &&
tag.callee.property.name !== 'default' /** ignore default for #93 below */
) {
// styled.something()
return isStyled(tag.callee.object, state);
}
return (
(t.isMemberExpression(tag) && tag.object.name === importLocalName('default', state)) ||
(t.isCallExpression(tag) && tag.callee.name === importLocalName('default', state)) ||
(t.isCallExpression(tag) &&
t.isCallExpression(tag.callee.object) &&
tag.callee.object.callee.name === 'require' &&
tag.callee.object.arguments[0].value === 'styled-components')
);
};
ReturnStatement(path) {
// return function () { ...body... }() becomes: ...body...
const call = path.node.argument;
const inlineable = (
isCallExpression(call) &&
!call.arguments.length &&
isFunctionExpression(call.callee) &&
!call.callee.id &&
!call.callee.params.length &&
isBlockStatement(call.callee.body) &&
!Object.keys(path.get('argument.callee').scope.bindings).length
);
if (inlineable) {
path.replaceWithMultiple(call.callee.body.body);
}
},
CallExpression(path) {
exit (path: NodePath) {
const openingElement = path.get('openingElement')
const jsxName = openingElement.get('name')
if (!jsxName.isJSXIdentifier({ name: 'Block' })) {
return
}
const children = path.node.children
if (children.length === 1) {
const caller = children[0]
if (t.isJSXExpressionContainer(caller) && t.isCallExpression(caller.expression) && !path.parentPath.isExpressionStatement()) {
try {
path.replaceWith(caller)
} catch (error) {
//
}
}
}
}
}
enter(path: NodePath): void {
if (h.containsCall(path)) {
if (t.isCallExpression(path.node.callee)) {
const id = fastFreshId.fresh('callee');
path.getStatementParent().insertBefore(h.letExpression(id, path.node.callee));
path.node.callee = id;
}
path.node.arguments.forEach((e: t.Expression, i) => {
const id = fastFreshId.fresh('arg');
path.getStatementParent().insertBefore(h.letExpression(id, e));
path.node.arguments[i] = id;
});
}
},
function traverseToFindDecorate(path, config, extendClass, overriddenMethodNames) {
var iifeRoot = _getParrent(path, 3)
var body = iifeRoot.node.body;
for(var index in body) {
var ci = body[index];
if(t.isExpressionStatement(ci) &&
t.isAssignmentExpression(ci.expression) &&
ci.expression.right.callee &&
ci.expression.right.callee.name === "__decorate" &&
ci.expression.right.arguments &&
t.isArrayExpression(ci.expression.right.arguments[0])) {
for(var i in ci.expression.right.arguments[0].elements) {
var currentDecorator = ci.expression.right.arguments[0].elements[i]
if(t.isCallExpression(currentDecorator)) {
if(currentDecorator.callee.name === config.extendDecoratorName) {
currentDecorator.callee.skipMeOnVisit = true;
var customDecoratorName = config.extendDecoratorName === undefined ? defaultExtendDecoratorName : config.extendDecoratorName;
traverseJavaProxyExtend(currentDecorator.arguments[0].value, config, customDecoratorName, extendClass, overriddenMethodNames);
return true;
}
}
}
}
}
}
function isRequire(node, filename) {
if (
t.isCallExpression(node) &&
t.isIdentifier(node.callee, { name: 'require' }) &&
node.arguments.length === 1 &&
t.isStringLiteral(node.arguments[0])
) {
var relative = node.arguments[0].value;
var fullPath = resolve.sync(relative, { basedir: dirname(filename) });
return { relative: relative, fullPath: fullPath };
} else {
return false;
}
}
enter: function enter(p) {
if (t.isCallExpression(p.node) && t.isMemberExpression(p.node.callee) && p.node.callee.object.name == 'ReactDOM' && p.node.callee.property.name == 'render' && t.isJSXElement(p.node.arguments[0])) {
p.insertBefore(expressionNode0.program.body[0]);
p.insertBefore(expressionNode1.program.body[0]);
var el = p.node.arguments[0].openingElement;
var attrNode = t.jSXSpreadAttribute(t.memberExpression(t.memberExpression(t.identifier('global'), t.identifier('$obj')), t.identifier('props')));
el.attributes = [];
el.name = t.identifier('Wrapped$');
}
}
});
jsx_1.setJSXAttr(block2, adapter_1.Adapter.else);
block2.children = [alternate];
const parentBlock = jsx_1.buildBlockElement();
parentBlock.children = [block, block2];
parentPath.replaceWith(parentBlock);
if (statementParent) {
const name = utils_1.findIdentifierFromStatement(statementParent.node);
utils_1.setTemplate(name, jsxElementPath, this.templates);
}
}
else if (t.isJSXElement(consequent) && t.isCallExpression(alternate) && !utils_1.isArrayMapCallExpression(parentPath.get('alternate'))) {
const id = utils_1.generateAnonymousState(this.renderScope, parentPath.get('alternate'), this.referencedIdentifiers, true);
parentPath.get('alternate').replaceWith(id);
//
}
else if (t.isJSXElement(alternate) && t.isCallExpression(consequent) && !utils_1.isArrayMapCallExpression(parentPath.get('consequent'))) {
const id = utils_1.generateAnonymousState(this.renderScope, parentPath.get('consequent'), this.referencedIdentifiers, true);
parentPath.get('consequent').replaceWith(id);
}
else {
block.children = [t.jSXExpressionContainer(consequent)];
utils_1.newJSXIfAttr(block, test);
const block2 = jsx_1.buildBlockElement();
jsx_1.setJSXAttr(block2, adapter_1.Adapter.else);
block2.children = [t.jSXExpressionContainer(alternate)];
const parentBlock = jsx_1.buildBlockElement();
parentBlock.children = [block, block2];
parentPath.replaceWith(parentBlock);
if (statementParent) {
const name = utils_1.findIdentifierFromStatement(statementParent.node);
utils_1.setTemplate(name, jsxElementPath, this.templates);
}