function _isChakraLoad(path) { // 'WScript.LoadScriptFile' used by Chakra. // TODO(ochang): The optional second argument can change semantics ("self", // "samethread", "crossthread" etc). // Investigate whether if it still makes sense to include them. return (babelTypes.isMemberExpression(path.node.callee) && babelTypes.isIdentifier(path.node.callee.property) && path.node.callee.property.name == 'LoadScriptFile' && path.node.arguments.length >= 1 && babelTypes.isStringLiteral(path.node.arguments[0])); }
/** * Turn the key of an object property into a string literal. */ function keyToString(key) { if (babelTypes.isNumericLiteral(key)) { return babelTypes.stringLiteral(key.value.toString()); } if (babelTypes.isIdentifier(key)) { return babelTypes.stringLiteral(key.name); } // Already a string literal. return key; }
/** * Filter out disallowed V8 runtime functions. */ function neuterDisallowedV8Natives(ast) { babelTraverse(ast, { CallExpression(path) { if (!babelTypes.isIdentifier(path.node.callee) || !path.node.callee.name.startsWith(V8_BUILTIN_PREFIX)) { return; } const functionName = path.node.callee.name.substr( V8_BUILTIN_PREFIX.length); if (!exceptions.isAllowedRuntimeFunction(functionName)) { path.replaceWith(babelTypes.callExpression( babelTypes.identifier('nop'), [])); } } }); }
/** * Helper for printing the contents of several variables. */ printVariables(path, nodes) { const statements = []; for (const node of nodes) { if (!babelTypes.isIdentifier(node) || !common.isVariableIdentifier(node.name)) continue; statements.push(prettyPrintExtraStatement(node)); } if (statements.length) { this.annotate(statements[0], 'Extra variable printing'); this.insertAfterSkip(path, statements); } }
// Wrap particular member expressions after `new` that are known to appear // in initializer lists of `let` and `const`. function replaceNewExpression(path) { const callee = path.node.callee; if (!babelTypes.isMemberExpression(callee) || !babelTypes.isIdentifier(callee.object) || !babelTypes.isIdentifier(callee.property)) { return; } if (WRAPPED_MEMBER_EXPRESSIONS.some( ([object, property]) => callee.object.name === object && callee.property.name === property)) { path.replaceWith(wrapTryCatchInFunction(path.node)); path.skip(); } }
const generateSafeParamIds = (path) => { const params = _.get(path, 'node.params', []); const paramIds = params.map((param) => { if (t.isIdentifier(param)) { return param.name; } if (t.isObjectPattern(param)) { return path.scope.generateUidIdentifier('obj').name; } if (t.isAssignmentPattern(param)) { return _.get(param, 'left.name', 'unhandled_assignment_pattern_default'); } return _.snakeCase(`unhandled.${param.type}`); }); return paramIds; }
MemberExpression(path, scope) { const { node } = path; if ( (t.isIdentifier(node.property) && (t.isThisExpression(node.object) && (node.property.name === "props" || node.property.name === "state"))) || (t.isIdentifier(node.object) && scope.hasOwnBinding(node.object.name)) ) { throw path.buildCodeFrameError( `Expected a constant ` + `as part of the template literal expression ` + `(eg: <style jsx>{\`p { color: $\{myColor}\`}</style>), ` + `but got a MemberExpression: this.${node.property.name}` ); } }
function _isV8OrSpiderMonkeyLoad(path) { // 'load' and 'loadRelativeToScript' used by V8 and SpiderMonkey. return (babelTypes.isIdentifier(path.node.callee) && (path.node.callee.name == 'load' || path.node.callee.name == 'loadRelativeToScript') && path.node.arguments.length == 1 && babelTypes.isStringLiteral(path.node.arguments[0])); }
_.set(this.importedModules, [importId, 'functions', functionId], functions); } else if (t.isIdentifier(callee)) {
if (path.isIdentifier() || path.isMemberExpression() || path.isConditionalExpression() || path.isBinaryExpression() || path.isDoExpression() || if (babelTypes.isIdentifier(path.node.left.object)) { if (babelTypes.isNumericLiteral(path.node.left.property)) { babelTypes.isIdentifier(path.node.callee) && !globalIdentifiers.has(path.node.callee.name)) {
const right = _.get(path, 'node.right'); if (!right) return; if (t.isIdentifier(right)) {
if (babelTypes.isIdentifier(path.node.callee) && path.node.callee.name == 'print') { path.node.callee = babelTypes.identifier('__prettyPrintExtra'); if (probability < settings.DIFF_FUZZ_EXTRA_PRINT && path.node.param && babelTypes.isIdentifier(path.node.param)) { const statement = prettyPrintExtraStatement(path.node.param); path.node.body.body.unshift(statement);
if (!babelTypes.isIdentifier(path.node.callee)) { return;
function capturePathsOfRequiredModules(path) { if (_.get(path, 'node.callee.name') === 'require') { const idNode = _.get(path, 'parent.id'); if (t.isIdentifier(idNode)) {