Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function normalize(ast) {
// Strip non-semantic information from an esprima AST
return estraverse.replace(
espurify.customize({extra: ['defaults', 'directive', 'expression']})(ast), {
enter: function (node, parent) {
if (parent
&& (parent.type === 'MethodDefinition' || parent.type === 'Property' && !parent.shorthand)
&& !parent.computed
&& parent.key === node) {
if (node.type === 'Identifier') {
// Treat ({ a(){} }) and ({ 'a'(){} }) the same
return {
type: 'Literal',
value: node.name
};
} else if (node.type === 'Literal' && typeof node.value === 'number') {
// Treat ({ 0(){} }) and ({ '0'(){} }) the same
return {
type: 'Literal',
value: '' + node.value
'use strict';
const pkg = require('../package.json');
const { ArgumentModification, NoModification } = require('./argument-modification');
const { createNewAssertionMessage, NodeCreator, getOrCreateNode, findBlockedScope, findEspathOfAncestorNode, insertAfterUseStrictDirective } = require('./create-node');
const estraverse = require('estraverse');
const escodegen = require('escodegen');
const espurify = require('espurify');
const espurifyWithRaw = espurify.customize({ extra: 'raw' });
const syntax = estraverse.Syntax;
const EspowerLocationDetector = require('espower-location-detector');
const toBeSkipped = require('./rules/to-be-skipped');
const toBeCaptured = require('./rules/to-be-captured');
const { getParentNode, getCurrentKey } = require('./controller-utils');
const recorderClassAst = require('./templates/argument-recorder.json');
const assertionMessageClassAst = require('./templates/assertion-message');
const canonicalCodeOptions = {
format: {
indent: {
style: ''
},
newline: ''
},
verbatim: 'x-verbatim-espower'
};