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
function extractProvide(
statement: estree.Statement | estree.ModuleDeclaration,
provides: string[]
): boolean {
if (
statement.type === Syntax.ExpressionStatement &&
statement.expression.type === Syntax.CallExpression
) {
const callExp = statement.expression;
const firstArg = callExp.arguments[0];
if (
firstArg &&
firstArg.type === Syntax.Literal &&
deepEqual(espurify(callExp.callee), {
type: 'MemberExpression',
computed: false,
object: {
type: 'Identifier',
name: 'goog',
},
property: {
type: 'Identifier',
name: 'provide',
},
})
) {
if (typeof firstArg.value !== 'string') {
throw new Error('Unexpected value: ' + firstArg.value);
}
provides.push(firstArg.value!);
cloneValue() {
return espurify(this.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'
};
function BabelAssertionVisitor (babel, matcher, options) {
this.babel = babel;
this.matcher = matcher;
this.options = options;
this.currentArgumentNodePath = null;
this.argumentModified = false;
this.valueRecorder = null;
this.locationDetector = new EspowerLocationDetector(this.options);
var babelTemplate = babel.template;
this.helperTemplate = babelTemplate(helperCode);
var whiteListWithRange = Object.keys(options.astWhiteList).reduce(function (acc, key) {
acc[key] = options.astWhiteList[key].concat(['range']);
return acc;
}, {});
this.purifyAst = cloneWithWhitelist(whiteListWithRange);
}