How to use espurify - 5 common examples

To help you get started, we’ve selected a few espurify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shapesecurity / shift-spidermonkey-converter-js / test / simple.js View on Github external
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
github teppeis / closure-ts / src / generator.ts View on Github external
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!);
github azu / ast-source / src / ASTDataContainer.js View on Github external
cloneValue() {
        return espurify(this.value);
    }
github power-assert-js / espower / lib / assertion-visitor.js View on Github external
'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'
};
github power-assert-js / babel-plugin-espower / lib / babel-assertion-visitor.js View on Github external
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);
}

espurify

Clone AST without extra properties

MIT
Latest version published 2 years ago

Package Health Score

50 / 100
Full package analysis