How to use the espurify.customize function in espurify

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 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'
};

espurify

Clone AST without extra properties

MIT
Latest version published 6 months ago

Package Health Score

74 / 100
Full package analysis