acorn-jsx-walk

    2.0.0 • Public • Published

    acorn-jsx-walk

    JSX support for Acorn Walk.

    Install

    npm install acorn-jsx-walk

    Example

    // Extend Acorn parser with JSX
    const acorn = require('acorn')
    const jsx = require('acorn-jsx')
    const parser = acorn.Parser.extend(jsx())
     
    // Extend Acorn walk with JSX
    const walk = require('acorn-walk')
    const { extend } = require('acorn-jsx-walk')
     
    extend(walk.base)
     
    // Create AST from source containing JSX
    const source = `
      const a = 2
      const fn = () => {
        const el = <div>Hello world!</div>
        return el
      }
    `
    const ast = parser.parse(source)
     
    // Finally...
    walk.simple(ast, {
      JSXElement(node) {
        console.log(`Found a ${node.type}!`)
      },
    })

    Copyright 2019 Contributors
    Open source under the MIT License.
    Special thanks to @sderosiaux and @adrianheine.

    Install

    npm i acorn-jsx-walk

    DownloadsWeekly Downloads

    84,466

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    11.3 kB

    Total Files

    5

    Last publish

    Collaborators

    • chtefi