Tabnine Logo For Javascript
babel-types
Code IndexAdd Tabnine to your IDE (free)

How to use babel-types

Best JavaScript code snippets using babel-types(Showing top 15 results out of 315)

origin: TheSoftwareDesignLab/mutode

SwitchCase (node) {
   const line = node.loc.start.line
   const caseContent = node.test ? node.test.extra ? node.test.extra.raw : `${node.test.value}` : 'default'

   const mutantId = ++mutodeInstance.mutants
   const log = `MUTANT ${mutantId}:\tRSCM Lines ${node.loc.start.line}-${node.loc.end.line}: Commented case ${caseContent}`
   debug(log)
   mutodeInstance.mutantLog(log)
   const linesCopy = lines.slice()
   for (let i = line - 1; i < node.loc.end.line; i++) {
    linesCopy[i] = `// ${linesCopy[i]}`
   }
   const contentToWrite = linesCopy.join('\n')
   queue.push(mutantRunner({ mutodeInstance, filePath, contentToWrite, log }))
  }
origin: TheSoftwareDesignLab/mutode

UnaryExpression (node) {
   if (node.operator !== '-') {
    return
   }
   const line = node.loc.start.line
   const lineContent = lines[line - 1]

   const mutantLineContent = lineContent.substr(0, node.loc.start.column) +
    lineContent.substr(node.loc.start.column + 1)

   const mutantId = ++mutodeInstance.mutants
   const diff = lineDiff(lineContent, mutantLineContent)
   const log = `MUTANT ${mutantId}:\tINM Line ${line}:\t${diff}...`
   debug(log)
   mutodeInstance.mutantLog(`MUTANT ${mutantId}:\tINM ${filePath} Line ${line}:\t\`${lineContent.trim()}\` > \`${mutantLineContent.trim()}'\``)
   const linesCopy = lines.slice()
   linesCopy[line - 1] = mutantLineContent
   const contentToWrite = linesCopy.join('\n')
   queue.push(mutantRunner({ mutodeInstance, filePath, contentToWrite, log }))
  }
origin: TheSoftwareDesignLab/mutode

BinaryExpression (node) {
   for (const pair of operators) {
    if (node.operator !== pair[0] || node.left.loc.end - node.right.loc.start > 5) {
     continue
    }
    const line = node.loc.start.line
    const lineContent = lines[line - 1]

    const mutantLineContent = lineContent.substr(0, node.left.loc.end.column) +
     lineContent.substr(node.left.loc.end.column, node.right.loc.start.column - node.left.loc.end.column).replace(pair[0], pair[1]) +
     lineContent.substr(node.right.loc.start.column)

    const mutantId = ++mutodeInstance.mutants
    const diff = lineDiff(lineContent, mutantLineContent)
    const log = `MUTANT ${mutantId}:\tMM Line ${line}:\t${diff}`
    debug(log)
    mutodeInstance.mutantLog(`MUTANT ${mutantId}:\tMM ${filePath} Line ${line}:\t\`${lineContent.trim()}\` > \`${mutantLineContent.trim()}'\``)
    const linesCopy = lines.slice()
    linesCopy[line - 1] = mutantLineContent
    const contentToWrite = linesCopy.join('\n')
    queue.push(mutantRunner({ mutodeInstance, filePath, contentToWrite, log }))
   }
  }
origin: jonschlinkert/babel-extract-comments

/**
 * Extract code comments from the given `string`.
 *
 * ```js
 * var extract = require('babel-extract-comments');
 * console.log(extract('// this is a code comment'));
 * // [{ type: 'CommentBlock',
 * //  value: '!\n * babel-extract-comments <https://github.com/jonschlinkert/babel-extract-comments>\n *\n *
 * // Copyright (c) 2014-2018, Jon Schlinkert.\n * Released under the MIT License.\n ',
 * //   start: 0,
 * //   end: 173,
 * //   loc: SourceLocation { start: [Position], end: [Position] } }]
 * ```
 * @param  {String} `string` String of javascript
 * @return {Array} Array of code comment objects.
 * @api public
 */

function extract(str, options) {
 const res = babylon.parse(str, options);
 return res.comments;
}
origin: TheSoftwareDesignLab/mutode

NumericLiteral (node) {
   const line = node.loc.start.line
   const lineContent = lines[line - 1]

   const newValues = []

   if (node.value !== 0) newValues.push(0)
   if (node.value !== 1) newValues.push(node.value - 1)
   newValues.push(node.value + 1)
   newValues.push(Math.floor(Math.random() * 1000000))

   for (const newValue of newValues) {
    const mutantLineContent = lineContent.substr(0, node.loc.start.column) +
     newValue +
     lineContent.substr(node.loc.end.column)

    const mutantId = ++mutodeInstance.mutants
    const diff = lineDiff(lineContent, mutantLineContent)
    const log = `MUTANT ${mutantId}:\tNLM Line ${line}:\t${diff}...`
    debug(log)
    mutodeInstance.mutantLog(`MUTANT ${mutantId}:\tNLM ${filePath} Line ${line}:\t\`${lineContent.trim()}\` > \`${mutantLineContent.trim()}'\``)
    const linesCopy = lines.slice()
    linesCopy[line - 1] = mutantLineContent
    const contentToWrite = linesCopy.join('\n')
    queue.push(mutantRunner({ mutodeInstance, filePath, contentToWrite, log }))
   }
  }
origin: TheSoftwareDesignLab/mutode

UpdateExpression (node) {
   for (const pair of operators) {
    if (node.operator !== pair[0]) {
     continue
    }
    const line = node.loc.start.line
    const lineContent = lines[line - 1]

    const mutantLineContent = lineContent.substr(0, node.loc.start.column) +
     lineContent.substr(node.loc.start.column, node.loc.end.column - node.loc.start.column).replace(pair[0], pair[1]) +
     lineContent.substr(node.loc.end.column)

    const mutantId = ++mutodeInstance.mutants
    const diff = lineDiff(lineContent, mutantLineContent)
    const log = `MUTANT ${mutantId}:\tIM Line ${line}:\t${diff}...`
    debug(log)
    mutodeInstance.mutantLog(`MUTANT ${mutantId}:\tIM ${filePath} Line ${line}:\t\`${lineContent.trim()}\` > \`${mutantLineContent.trim()}'\``)
    const linesCopy = lines.slice()
    linesCopy[line - 1] = mutantLineContent
    const contentToWrite = linesCopy.join('\n')
    queue.push(mutantRunner({ mutodeInstance, filePath, contentToWrite, log }))
   }
  }
origin: TheSoftwareDesignLab/mutode

CallExpression (functionNode, state, ancestors) {
   if (ancestors.length >= 2) {
    const ancestor = ancestors[ancestors.length - 2]
    if (ancestor.type && ancestor.type === 'CallExpression' && ancestor.callee) {
     if (ancestor.callee.type === 'MemberExpression' && ancestor.callee.object.name === 'console') return
     if (ancestor.callee.name) {
      switch (ancestor.callee.name) {
       case 'require':
       case 'debug':
   for (const node of functionNode.arguments) {
    const line = node.loc.start.line
    const lineContent = lines[line - 1]
origin: TheSoftwareDesignLab/mutode

ArrayExpression (arrayNode) {
   for (const node of arrayNode.elements) {
    let contentToWrite = ''
    let log = ''
     log = `MUTANT ${mutantId}:\tRAEM Lines ${node.loc.start.line}-${node.loc.end.line}: Commented element #${arrayNode.elements.indexOf(node) + 1}`
     debug(log)
     mutodeInstance.mutantLog(log)
origin: TheSoftwareDesignLab/mutode

StringLiteral (node, state, ancestors) {
   const line = node.loc.start.line
   const lineContent = lines[line - 1]
    if (ancestor.type && ancestor.type === 'CallExpression' && ancestor.callee) {
     if (ancestor.callee.type === 'MemberExpression' && ancestor.callee.object.name === 'console') return
     if (ancestor.callee.name) {
      switch (ancestor.callee.name) {
       case 'require':
       case 'debug':
   if (node.value.length !== 0) {
    const mutantLineContent = lineContent.substr(0, node.loc.start.column) +
     node.extra.raw.replace(node.value, '') +
     lineContent.substr(node.loc.end.column)
   const newValue = `'${randomString(node.value.length || 10)}'`
   const mutantLineContent = lineContent.substr(0, node.loc.start.column) +
    newValue +
    lineContent.substr(node.loc.end.column)
origin: TheSoftwareDesignLab/mutode

ObjectProperty (node) {
   const propertyName = node.key.name
   if (node.loc.start.line !== node.loc.end.line) {
    const line = node.loc.start.line
    log = `MUTANT ${mutantId}:\tROPM Lines ${node.loc.start.line}-${node.loc.end.line}: Commented property ${propertyName}`
    debug(log)
    mutodeInstance.mutantLog(log)
    const linesCopy = lines.slice()
    for (let i = line - 1; i < node.loc.end.line; i++) {
     linesCopy[i] = `// ${linesCopy[i]}`
    const line = node.loc.start.line
    const lineContent = lines[line - 1]
    let start = lineContent.substr(0, node.loc.start.column)
    if (start.trim().endsWith(',')) {
     start = start.substr(0, start.lastIndexOf(','))
     trimmed = true
    let end = lineContent.substr(node.loc.end.column)
    if (!trimmed && end.startsWith(',')) end = end.substr(1).trim()
    const mutantLineContent = start + end
origin: TheSoftwareDesignLab/mutode

FunctionDeclaration (functionNode) {
   for (const node of functionNode.params) {
    const line = node.loc.start.line
    const lineContent = lines[line - 1]

    let trimmed = false
    let start = lineContent.substr(0, node.loc.start.column)
    if (start.trim().endsWith(',')) {
     start = start.substr(0, start.lastIndexOf(','))
     trimmed = true
    }
    let end = lineContent.substr(node.loc.end.column)
    if (!trimmed && end.startsWith(',')) end = end.substr(1).trim()
    const mutantLineContent = start + end

    const mutantId = ++mutodeInstance.mutants
    const diff = lineDiff(lineContent, mutantLineContent)
    const log = `MUTANT ${mutantId}:\tRFDPM Line ${line}:\t${diff}`
    debug(log)
    mutodeInstance.mutantLog(`MUTANT ${mutantId}:\tRFDPM ${filePath} Line ${line}:\t\`${lineContent.trim()}\` > \`${mutantLineContent.trim()}'\``)
    const linesCopy = lines.slice()
    linesCopy[line - 1] = mutantLineContent
    const contentToWrite = linesCopy.join('\n')
    queue.push(mutantRunner({ mutodeInstance, filePath, contentToWrite, log }))
   }
  }
origin: TheSoftwareDesignLab/mutode

BooleanLiteral (node) {
   const line = node.loc.start.line
   const lineContent = lines[line - 1]

   const mutantLineContent = lineContent.substr(0, node.loc.start.column) +
    !node.value +
    lineContent.substr(node.loc.end.column)

   const mutantId = ++mutodeInstance.mutants
   const diff = lineDiff(lineContent, mutantLineContent)
   const log = `MUTANT ${mutantId}:\tBLM Line ${line}:\t${diff}...`
   debug(log)
   mutodeInstance.mutantLog(`MUTANT ${mutantId}:\tBLM ${filePath} Line ${line}:\t\`${lineContent.trim()}\` > \`${mutantLineContent.trim()}'\``)
   const linesCopy = lines.slice()
   linesCopy[line - 1] = mutantLineContent
   const contentToWrite = linesCopy.join('\n')
   queue.push(mutantRunner({ mutodeInstance, filePath, contentToWrite, log }))
  }
origin: TheSoftwareDesignLab/mutode

BinaryExpression (node) {
   for (const operator of operators) {
    if (node.operator !== operator) {
     continue
    }
    const line = node.loc.start.line
    const lineContent = lines[line - 1]

    for (const replacement of ['true', 'false']) {
     const mutantLineContent = lineContent.substr(0, node.loc.start.column) +
      replacement +
      lineContent.substr(node.loc.end.column)

     const mutantId = ++mutodeInstance.mutants
     const diff = lineDiff(lineContent, mutantLineContent)
     const log = `MUTANT ${mutantId}:\tRCM Line ${line}:\t${diff}`
     debug(log)
     mutodeInstance.mutantLog(`MUTANT ${mutantId}:\tRCM ${filePath} Line ${line}:\t\`${lineContent.trim()}\` > \`${mutantLineContent.trim()}'\``)
     const linesCopy = lines.slice()
     linesCopy[line - 1] = mutantLineContent
     const contentToWrite = linesCopy.join('\n')
     queue.push(mutantRunner({ mutodeInstance, filePath, contentToWrite, log }))
    }
   }
  }
origin: TheSoftwareDesignLab/mutode

BinaryExpression (node) {
   for (const pair of operators) {
    if (node.operator !== pair[0]) {
     continue
    }
    const line = node.loc.start.line
    const lineContent = lines[line - 1]

    const mutantLineContent = lineContent.substr(0, node.loc.start.column) +
     lineContent.substr(node.loc.start.column, node.loc.end.column - node.loc.start.column).replace(pair[0], pair[1]) +
     lineContent.substr(node.loc.end.column)

    const mutantId = ++mutodeInstance.mutants
    const diff = lineDiff(lineContent, mutantLineContent)
    const log = `MUTANT ${mutantId}:\tCBM Line ${line}:\t${diff}`
    debug(log)
    mutodeInstance.mutantLog(`MUTANT ${mutantId}:\tCBM ${filePath} Line ${line}:\t\`${lineContent.trim()}\` > \`${mutantLineContent.trim()}'\``)
    const linesCopy = lines.slice()
    linesCopy[line - 1] = mutantLineContent
    const contentToWrite = linesCopy.join('\n')
    queue.push(mutantRunner({ mutodeInstance, filePath, contentToWrite, log }))
   }
  }
origin: TheSoftwareDesignLab/mutode

BinaryExpression (node) {
   for (const pair of operators) {
    if (node.operator !== pair[0]) {
     continue
    }
    const line = node.loc.start.line
    const lineContent = lines[line - 1]

    const mutantLineContent = lineContent.substr(0, node.loc.start.column) +
     lineContent.substr(node.loc.start.column, node.loc.end.column - node.loc.start.column).replace(pair[0], pair[1]) +
     lineContent.substr(node.loc.end.column)

    const mutantId = ++mutodeInstance.mutants
    const diff = lineDiff(lineContent, mutantLineContent)
    const log = `MUTANT ${mutantId}:\tNCM Line ${line}:\t${diff}`
    debug(log)
    mutodeInstance.mutantLog(`MUTANT ${mutantId}:\tNCM ${filePath} Line ${line}:\t\`${lineContent.trim()}\` > \`${mutantLineContent.trim()}'\``)
    const linesCopy = lines.slice()
    linesCopy[line - 1] = mutantLineContent
    const contentToWrite = linesCopy.join('\n')
    queue.push(mutantRunner({ mutodeInstance, filePath, contentToWrite, log }))
   }
  }
babel-types(npm)

JSDoc

Babel Types is a Lodash-esque utility library for AST nodes

Most used babel-types functions

  • ArrayExpression.arguments
  • ArrayExpression.elements
  • ArrayExpression.extra
  • ArrayExpression.key
  • ArrayExpression.left
  • ArrayExpression.operator,
  • ArrayExpression.params,
  • ArrayExpression.right,
  • ArrayExpression.test,
  • ArrayExpression.value,
  • File.comments,
  • Node.callee,
  • Node.type,
  • SourceLocation.end,
  • SourceLocation.start,
  • column,
  • line

Popular in JavaScript

  • qs
    A querystring parser that supports nesting and arrays, with a depth limit
  • cheerio
    Tiny, fast, and elegant implementation of core jQuery designed specifically for the server
  • ws
    Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js
  • minimist
    parse argument options
  • superagent
    elegant & feature rich browser / node HTTP with a fluent API
  • semver
    The semantic version parser used by npm.
  • path
  • commander
    the complete solution for node.js command-line programs
  • winston
    A logger for just about everything.
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJavascript Code Index
Get Tabnine for your IDE now