Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Skip: postMessage = value || function x (postMessage = value) { ... }
if ((parent.type === Syntax.AssignmentExpression || parent.type === Syntax.AssignmentPattern) &&
parent.left === node)
return false;
// Skip: const postMessage = value;
if (parent.type === Syntax.VariableDeclarator && parent.id === node)
return false;
// Skip: postMessage++ || postMessage-- || ++postMessage || --postMessage
if (parent.type === Syntax.UpdateExpression && (parent.operator === '++' || parent.operator === '--'))
return false;
// Skip already transformed: __get$PostMessage(postMessage) || __call$(obj, postMessage, args...);
if (parent.type === Syntax.CallExpression && parent.callee.type === Syntax.Identifier &&
(parent.callee.name === INSTRUCTION.getPostMessage ||
parent.callee.name === INSTRUCTION.callMethod && parent.arguments[1] === node))
return false;
// Skip: function x (...postMessage) {}
if (parent.type === Syntax.RestElement)
return false;
return true;
},
return false;
// Skip: window.eval.field
if (parent.type === Syntax.MemberExpression && (parent.property === node || parent.object === node))
return false;
// Skip: window.eval()
if (parent.type === Syntax.CallExpression && parent.callee === node)
return false;
// Skip: window.eval = 1, window["eval"] = 1
if (parent.type === Syntax.AssignmentExpression && parent.left === node)
return false;
// Skip already transformed: __get$Eval(window.eval), __get$Eval(window["eval"])
if (parent.type === Syntax.CallExpression && parent.callee.type === Syntax.Identifier &&
parent.callee.name === INSTRUCTION.getEval)
return false;
// window.eval
if (node.property.type === Syntax.Identifier && node.property.name === 'eval')
return true;
// window['eval']
if (node.property.type === Syntax.Literal && node.property.value === 'eval')
return true;
return false;
},
import { Identifier } from 'estree';
import { Transformer } from './index';
/*eslint-enable no-unused-vars*/
import INSTRUCTION from '../instruction';
import { createGetPostMessageMethCall } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';
// Transform:
// const foo = postMessage; foo = postMessage; { _postMessage: postMessage }; return postMessage;
// -->
// const foo = _get$PostMessage(postMessage); foo = _get$PostMessage(postMessage); { _postMessage: _get$PostMessage(postMessage) }; return _get$PostMessage(postMessage);
const transformer: Transformer = {
nodeReplacementRequireTransform: false,
nodeTypes: Syntax.Identifier,
condition: (node, parent) => {
if (node.name !== 'postMessage' || !parent)
return false;
// Skip: window.postMessage, postMessage.call
if (parent.type === Syntax.MemberExpression)
return false;
// Skip: class X { postMessage () {} }
if (parent.type === Syntax.MethodDefinition)
return false;
// Skip: class postMessage { x () {} }
if (parent.type === Syntax.ClassDeclaration)
return false;
import { Identifier } from 'estree';
import { Transformer } from './index';
/*eslint-enable no-unused-vars*/
import INSTRUCTION from '../instruction';
import { createGetEvalMethCall } from '../node-builder';
import { Syntax } from 'esotope-hammerhead';
// Transform:
// const foo = eval; foo = eval; { _eval: eval }; return eval;
// -->
// const foo = _get$Eval(eval); foo = _get$Eval(eval); { _eval: _get$Eval(eval) }; return _get$Eval(eval);
const transformer: Transformer = {
nodeReplacementRequireTransform: false,
nodeTypes: Syntax.Identifier,
condition: (node, parent) => {
if (node.name === 'eval' && parent) {
// Skip: eval()
if (parent.type === Syntax.CallExpression && parent.callee === node)
return false;
// Skip: class X { eval () {} }
if (parent.type === Syntax.MethodDefinition)
return false;
// Skip: class eval { x () {} }
if (parent.type === Syntax.ClassDeclaration)
return false;
// Skip: window.eval, eval.call
condition: node => {
if (!node.arguments.length)
return false;
const callee = node.callee;
// eval()
if (callee.type === Syntax.Identifier && callee.name === 'eval')
return true;
// obj.eval(), obj['eval'](),
return callee.type === Syntax.MemberExpression &&
(callee.property.type === Syntax.Identifier && callee.property.name ||
callee.property.type === Syntax.Literal && callee.property.value) === 'eval';
},
// Skip: window.eval()
if (parent.type === Syntax.CallExpression && parent.callee === node)
return false;
// Skip: window.eval = 1, window["eval"] = 1
if (parent.type === Syntax.AssignmentExpression && parent.left === node)
return false;
// Skip already transformed: __get$Eval(window.eval), __get$Eval(window["eval"])
if (parent.type === Syntax.CallExpression && parent.callee.type === Syntax.Identifier &&
parent.callee.name === INSTRUCTION.getEval)
return false;
// window.eval
if (node.property.type === Syntax.Identifier && node.property.name === 'eval')
return true;
// window['eval']
if (node.property.type === Syntax.Literal && node.property.value === 'eval')
return true;
return false;
},
condition: node => {
// super.prop = value
if (node.left.type === Syntax.MemberExpression && node.left.object.type === Syntax.Super)
return false;
return node.operator === '=' &&
node.left.type === Syntax.MemberExpression && !node.left.computed &&
node.left.property.type === Syntax.Identifier &&
shouldInstrumentProperty(node.left.property.name);
},
/*eslint-disable no-unused-vars*/
import { Identifier } from 'estree';
import { Transformer } from './index';
/*eslint-enable no-unused-vars*/
import { createLocationGetWrapper } from '../node-builder';
import INSTRUCTION from '../instruction';
import { Syntax } from 'esotope-hammerhead';
// Transform:
// location -->
// __get$Loc(location)
const transformer: Transformer = {
nodeReplacementRequireTransform: false,
nodeTypes: Syntax.Identifier,
condition: (node, parent) => {
if (node.name !== 'location' || !parent)
return false;
// Skip: const location = value;
if (parent.type === Syntax.VariableDeclarator && parent.id === node)
return false;
// Skip: location = value || function x (location = value) { ... }
if ((parent.type === Syntax.AssignmentExpression || parent.type === Syntax.AssignmentPattern) &&
parent.left === node)
return false;
// Skip: function location() {}
if ((parent.type === Syntax.FunctionExpression || parent.type === Syntax.FunctionDeclaration) &&
condition: node => node.operator === '=' && node.left.type === Syntax.Identifier && node.left.name === 'location',
export function createTempVarIdentifier (): Identifier {
return {
type: Syntax.Identifier,
name: INTERNAL_LITERAL.tempVar
};
}