@babel/types#isFunctionExpression TypeScript Examples
The following examples show how to use
@babel/types#isFunctionExpression.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: webpackParser.ts From react-native-decompiler with GNU Affero General Public License v3.0 | 6 votes |
protected parseAst(ast: File, modules: Module[]): void {
traverse(ast, {
CallExpression: (nodePath) => {
const firstArg = nodePath.get('arguments')[0];
if (isFunctionExpression(nodePath.node.callee) && firstArg?.isArrayExpression()) { // entrypoint
this.parseArray(ast, firstArg, modules);
} else if (isMemberExpression(nodePath.node.callee) && isAssignmentExpression(nodePath.node.callee.object) && firstArg?.isArrayExpression()) { // chunked
const assignment = nodePath.node.callee.object;
if (isMemberExpression(assignment.left)) {
let leftPropName = '';
if (isIdentifier(assignment.left.property)) {
leftPropName = assignment.left.property.name;
} else if (isStringLiteral(assignment.left.property)) {
leftPropName = assignment.left.property.value;
}
if (leftPropName.startsWith('webpackJsonp')) {
const modulesObject = firstArg.get('elements')[1];
if (modulesObject.isArrayExpression()) {
this.parseArray(ast, modulesObject, modules);
} else {
if (!modulesObject || !modulesObject.isObjectExpression()) throw new Error('Failed assertion');
this.parseObject(ast, modulesObject, modules);
}
}
}
}
nodePath.skip();
},
});
}
Example #2
Source File: webpackParser.ts From react-native-decompiler with GNU Affero General Public License v3.0 | 6 votes |
private parseArray(file: File, ast: NodePath<ArrayExpression>, modules: Module[]): void {
ast.get('elements').forEach((element, i) => {
if (!element.isFunctionExpression()) return;
if (element.node.body.body.length === 0) return;
const dependencyValues: number[] = [];
const requireIdentifer = element.node.params[2];
if (isIdentifier(requireIdentifer)) {
element.traverse({
CallExpression: (dependencyPath) => {
if (!isIdentifier(dependencyPath.node.callee) || !isNumericLiteral(dependencyPath.node.arguments[0])) return;
if (dependencyPath.scope.bindingIdentifierEquals(dependencyPath.node.callee.name, requireIdentifer)) {
dependencyValues[dependencyPath.node.arguments[0].value] = dependencyPath.node.arguments[0].value;
}
},
});
}
const newModule = new Module(file, element, i, dependencyValues, this.PARAM_MAPPING);
newModule.calculateFields();
modules[i] = newModule;
});
}
Example #3
Source File: webpackParser.ts From react-native-decompiler with GNU Affero General Public License v3.0 | 6 votes |
private parseObject(file: File, ast: NodePath<ObjectExpression>, modules: Module[]): void {
ast.get('properties').forEach((property) => {
if (!property.isObjectProperty() || !isNumericLiteral(property.node.key)) return;
const element = property.get('value');
const i = property.node.key.value;
if (!element.isFunctionExpression()) return;
if (element.node.body.body.length === 0) return;
const dependencyValues: number[] = [];
const requireIdentifer = element.node.params[2];
if (isIdentifier(requireIdentifer)) {
element.traverse({
CallExpression: (dependencyPath) => {
if (!isIdentifier(dependencyPath.node.callee) || !isNumericLiteral(dependencyPath.node.arguments[0])) return;
if (dependencyPath.scope.bindingIdentifierEquals(dependencyPath.node.callee.name, requireIdentifer)) {
dependencyValues[dependencyPath.node.arguments[0].value] = dependencyPath.node.arguments[0].value;
}
},
});
}
const newModule = new Module(file, element, i, dependencyValues, this.PARAM_MAPPING);
newModule.calculateFields();
modules[i] = newModule;
});
}
Example #4
Source File: webpackParser.ts From react-native-decompiler with GNU Affero General Public License v3.0 | 6 votes |
protected parseAst(ast: File, modules: Module[]): void {
traverse(ast, {
CallExpression: (nodePath) => {
const firstArg = nodePath.get('arguments')[0];
if (isFunctionExpression(nodePath.node.callee) && firstArg?.isArrayExpression()) { // entrypoint
this.parseArray(ast, firstArg, modules);
} else if (isMemberExpression(nodePath.node.callee) && isAssignmentExpression(nodePath.node.callee.object) && firstArg?.isArrayExpression()) { // chunked
const assignment = nodePath.node.callee.object;
if (isMemberExpression(assignment.left)) {
let leftPropName = '';
if (isIdentifier(assignment.left.property)) {
leftPropName = assignment.left.property.name;
} else if (isStringLiteral(assignment.left.property)) {
leftPropName = assignment.left.property.value;
}
if (leftPropName.startsWith('webpackJsonp')) {
const modulesObject = firstArg.get('elements')[1];
if (modulesObject.isArrayExpression()) {
this.parseArray(ast, modulesObject, modules);
} else {
if (!modulesObject || !modulesObject.isObjectExpression()) throw new Error('Failed assertion');
this.parseObject(ast, modulesObject, modules);
}
}
}
}
nodePath.skip();
},
});
}
Example #5
Source File: webpackParser.ts From react-native-decompiler with GNU Affero General Public License v3.0 | 6 votes |
private parseArray(file: File, ast: NodePath<ArrayExpression>, modules: Module[]): void {
ast.get('elements').forEach((element, i) => {
if (!element.isFunctionExpression()) return;
if (element.node.body.body.length === 0) return;
const dependencyValues: number[] = [];
const requireIdentifer = element.node.params[2];
if (isIdentifier(requireIdentifer)) {
element.traverse({
CallExpression: (dependencyPath) => {
if (!isIdentifier(dependencyPath.node.callee) || !isNumericLiteral(dependencyPath.node.arguments[0])) return;
if (dependencyPath.scope.bindingIdentifierEquals(dependencyPath.node.callee.name, requireIdentifer)) {
dependencyValues[dependencyPath.node.arguments[0].value] = dependencyPath.node.arguments[0].value;
}
},
});
}
const newModule = new Module(file, element, i, dependencyValues, this.PARAM_MAPPING);
newModule.calculateFields();
modules[i] = newModule;
});
}
Example #6
Source File: webpackParser.ts From react-native-decompiler with GNU Affero General Public License v3.0 | 6 votes |
private parseObject(file: File, ast: NodePath<ObjectExpression>, modules: Module[]): void {
ast.get('properties').forEach((property) => {
if (!property.isObjectProperty() || !isNumericLiteral(property.node.key)) return;
const element = property.get('value');
const i = property.node.key.value;
if (!element.isFunctionExpression()) return;
if (element.node.body.body.length === 0) return;
const dependencyValues: number[] = [];
const requireIdentifer = element.node.params[2];
if (isIdentifier(requireIdentifer)) {
element.traverse({
CallExpression: (dependencyPath) => {
if (!isIdentifier(dependencyPath.node.callee) || !isNumericLiteral(dependencyPath.node.arguments[0])) return;
if (dependencyPath.scope.bindingIdentifierEquals(dependencyPath.node.callee.name, requireIdentifer)) {
dependencyValues[dependencyPath.node.arguments[0].value] = dependencyPath.node.arguments[0].value;
}
},
});
}
const newModule = new Module(file, element, i, dependencyValues, this.PARAM_MAPPING);
newModule.calculateFields();
modules[i] = newModule;
});
}