Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (propsTypeDecl) {
console.log(decl.id.name, propsTypeDecl.id.name)
const comp: ComponentInfo = {
name: decl.id.name,
propsTypeInfo: typeAliasToTypeInfo(propsTypeDecl),
}
file.components.push(comp)
}
// console.log(decl.id.name, propsTypeName)
}
for (const st of file.parsed.program.body) {
if (isExpressionStatement(st)) {
const exp = st.expression
if (isAssignmentExpression(exp)) {
const left = exp.left
if (isMemberExpression(left)) {
const prop = left.property
const obj = left.object
if (isIdentifier(obj) && isIdentifier(prop) && prop.name == "propTypes") {
const right = exp.right
if (isObjectExpression(right)) {
file.components.push({
name: obj.name,
propsTypeInfo: propTypesToTypeInfo(right),
})
// console.log(file.components[file.components.length - 1].propsTypeInfo.properties)
}
}
}
}
}
}
const callingMethodParamsInNode = (callee, node) => {
let foundParams = [];
if (t.isFunctionDeclaration(node)) {
foundParams = node.params;
}
else if (t.isVariableDeclarator(node)) {
if (t.isFunctionExpression(node.init) || t.isArrowFunctionExpression(node.init)) {
foundParams = node.init.params;
}
else if (t.isObjectExpression(node.init)) {
let calleName = null;
if (t.isMemberExpression(callee) && t.isIdentifier(callee.property)) {
//call-6
calleName = callee.property.name;
}
else if (t.isIdentifier(callee)) {
// attribute-call-1
calleName = callee.name;
}
// else throw 'ERROR: not implemented in callingMethodParams -> ' + callee.type;
calleName &&
node.init.properties.every((prop) => {
if (t.isObjectProperty(prop) &&
t.isIdentifier(prop.key) &&
prop.key.name === calleName &&
t.isFunctionExpression(prop.value)) {
foundParams = prop.value.params;
return false;
// Page((_defineProperty(_Page = {
// data: {
// edit_state: 0,
// select_all_state: !1
// },
// },_defineProperty(_Page, "onShow", function() {
// var t = this;
// http.post("apicloud/like_list", {}).then(function(e) {
// t.setData({
// list: e.result.data
// });
// });
// }),_Page));
if (t.isObjectProperty(path.node)) {
const value = path.node.value;
if (value.object && t.isMemberExpression(value.object) && value.object.object.name != "e") {
vistors.data.handle(path.node);
}
} else {
vistors.data.handle(path.node);
}
}
}
break;
}
}
}
if ((t.isMemberExpression(path.parent) &&
path.parent.property.name === "$val") == false &&
check_1.check.isTrackedVariable(path.scope, path.node) &&
t.isIdentifier(path.node.object) &&
!check_1.check.isTrackedVariable(path.parentPath.scope, path.parentPath.node) &&
!check_1.check.isFidanCall(path.parentPath.node) &&
!t.isAssignmentExpression(path.parentPath.node) // object-property-3
) {
path.node.object = t.memberExpression(path.node.object, t.identifier(path.node.property.name));
modify_1.modify.renameToVal(path.node, "property");
}
else if (check_1.check.specialMemberAccessKeywords.indexOf(path.node.property.name) === -1 &&
check_1.check.isTrackedVariable(path.scope, path.node.object)) {
path.node.object = modify_1.modify.memberVal(path.node.object);
}
else if (t.isMemberExpression(path.node.property) &&
t.isCallExpression(path.parentPath.node) === false &&
t.isVariableDeclarator(path.parentPath.node) === false &&
check_1.check.isTrackedVariable(path.scope, path.node.property) &&
(t.isMemberExpression(path.parentPath.node) &&
path.parentPath.node.property.name === "$val") == false) {
//object-indexed-property-1
path.node.property = modify_1.modify.memberVal(path.node.property);
}
}
}
catch (e) {
errorReport(e, path, file);
}
},
VariableDeclarator(path, file) {
});
} catch (e) {
return {
name: node.name,
type: 'error',
};
}
case types.isCallExpression(node):
return getObjectDescriptor({
node: await reduceToObject({ node: node, ast, cwd }),
ast,
cwd,
});
case types.isMemberExpression(node):
const propertyDescriptor = await createDescriptor({
node: await getMemberProperty({ node: node, ast, cwd }),
ast,
cwd,
});
return propertyDescriptor.props;
default:
throw Error(`Unsupported spread for type ${node.type}`);
}
};
if (t.isStringLiteral(arguments[0])) {
let filePath = arguments[0].value;
filePath = pathUtil.relativePath(filePath, global.miniprogramRoot, fileDir);
path2.node.arguments[0] = t.stringLiteral(filePath);
}
}
} else if (t.isIdentifier(callee.node, { name: "getApp" })) {
/**
* getApp().xxx;
* 替换为:
* getApp().globalData.xxx;
*
* 虽然var app = getApp()已替换,还是会有漏网之鱼,如var t = getApp();
*/
const parent2 = path2.parentPath;
if (t.isMemberExpression(parent2.node) && parent2.node.property && parent2.node.property.name !== "globalData") {
const me = t.memberExpression(t.callExpression(t.identifier("getApp"), []), t.identifier("globalData"));
path2.replaceWith(me);
path2.skip();
}
}
},
VariableDeclarator(path2) {
if (t.isStringLiteral(arguments[0])) {
let filePath = arguments[0].value;
filePath = pathUtil.relativePath(filePath, global.miniprogramRoot, fileDir);
path2.node.arguments[0] = t.stringLiteral(filePath);
}
}
} else if (t.isIdentifier(callee.node, { name: "getApp" })) {
/**
* getApp().xxx;
* 替换为:
* getApp().globalData.xxx;
*
* 虽然var app = getApp()已替换,还是会有漏网之鱼,如var t = getApp();
*/
const parent2 = path2.parentPath;
if (t.isMemberExpression(parent2.node) && parent2.node.property && parent2.node.property.name !== "globalData") {
const me = t.memberExpression(t.callExpression(t.identifier("getApp"), []), t.identifier("globalData"));
path2.replaceWith(me);
path2.skip();
}
}
},
VariableDeclarator(path2) {
function extractSequentialDestructurableElements(module: Module, elements: Array, start=0): Array {
let result = [];
let objectSource = null;
for (let i = start; i < elements.length; i++) {
let element = elements[i];
let { left, right } = leftRightOfAssignment(element) || {};
if (!t.isIdentifier(left)) {
break;
}
if (!t.isMemberExpression(right)) {
break;
}
if (right.computed) {
break;
}
if (left.name !== right.property.name) {
break;
}
let thisObjectSource = module.sourceOf(right.object);
if (!objectSource) {
objectSource = thisObjectSource;
} else if (objectSource !== thisObjectSource) {
function getMemberSnippet(node: Node, expression: string = "") {
if (t.isMemberExpression(node)) {
const name = node.property.name;
const snippet = getMemberSnippet(
node.object,
extendSnippet(name, expression, { node })
);
return snippet;
}
if (t.isCallExpression(node)) {
return "";
}
if (t.isThisExpression(node)) {
return `this.${expression}`;
}
const memberExpressionCheck = (expression, checkFn) => {
var member = expression;
while (true) {
if (t.isIdentifier(member.object) || t.isStringLiteral(member.object)) {
if (checkFn(member)) {
return member;
}
else {
return null;
}
}
else if (t.isMemberExpression(member.object))
member = member.object;
else if (t.isCallExpression(member.object))
return callMemberExpressionCheck(member.object, checkFn);
else if (t.isMemberExpression(member))
return member.property;
}
};
const parentPathFound = (path, check) => {