How to use the abstract-syntax-tree.parse function in abstract-syntax-tree

To help you get started, we’ve selected a few abstract-syntax-tree 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 buxlabs / amd-to-es6 / test / helper / spec.js View on Github external
harvest: function harvest (dir) {
    const file1 = path.join(__dirname, '../fixture/', dir, '/input.js')
    const file2 = path.join(__dirname, '../fixture/', dir, '/harvest.json')
    const input = fs.readFileSync(file1, 'utf8')
    const expected = JSON.parse(fs.readFileSync(file2, 'utf8'))
    const ast = AbstractSyntaxTree.parse(input, { sourceType: 'module' })
    const analyzer = new Analyzer(ast)
    const harvester = new Importer(ast, { analyzer })
    const result = harvester.harvest()
    const isValid = JSON.stringify(expected) === JSON.stringify(result)
    if (!isValid) {
      console.log('-- EXPECTED --')
      console.log(JSON.stringify(expected, null, 2))
      console.log('-- RESULT --')
      console.log(JSON.stringify(result, null, 2))
    }
    return isValid
  }
}
github buxlabs / amd-to-es6 / src / class / Module.js View on Github external
static parse (source, options) {
    options.next = true
    return AbstractSyntaxTree.parse(source, options)
  }

abstract-syntax-tree

abstract syntax tree

MIT
Latest version published 9 months ago

Package Health Score

70 / 100
Full package analysis

Popular abstract-syntax-tree functions