How to use the acorn-jsx/inject function in acorn-jsx

To help you get started, we’ve selected a few acorn-jsx 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 hoschi / yode / src / js / ast / parser-acorn-jsx.js View on Github external
import * as acornBase from 'acorn'
import inject from 'acorn-jsx/inject'
import estraverse from '../../../lib/estraverse'
import escodegen from 'escodegen'

let acorn = inject(acornBase)

let parser = {
    estraverse,
    parse(text) {
        return acorn.parse(text, {
            plugins: {
                jsx: true
            },
            ecmaVersion: 6,
            sourceType: 'module',
            locations: true
        });
    },
    print(ast) {
        // TODO not working, escodegen can't generate JSX tags
        return escodegen.generate(ast);
github babel / babel / src / acorn / index.js View on Github external
export * from "./src/index";
import "./plugins/flow";

import inject from "acorn-jsx/inject";
import * as acorn from "./src/index";
inject(acorn);
github hoschi / yode / src / js / ast / parser-recast.js View on Github external
import recast from 'recast';
import inject from 'acorn-jsx/inject'
import * as acornBase from 'acorn'
import estraverse from '../../../lib/estraverse'

let acorn = inject(acornBase)

let parser = {
    estraverse,
    parse(text) {
        let result = recast.parse(text, {
            parser: acorn
        });
        if (result) {
            return result.program;
        }
        return result;
    },
    print(ast) {
        return recast.print(ast).code;
    }
}
github fkling / astexplorer / registry / tools / acorn / v4.js View on Github external
load() {
    return Promise.resolve({
      loose: parse_dammit,
      parse: jsxInject(acorn).parse,
    });
  },
};
github hoschi / yode / src / js / ast / parser-recast-jsx.js View on Github external
import recast from 'recast';
import * as acornBase from 'acorn'
import inject from 'acorn-jsx/inject'
import jsxKeys from 'estraverse-fb/keys';
import estraverseOrig from '../../../lib/estraverse'

let acorn = inject(acornBase)

let acornParser = {
    parse(text, options) {
        let baseOptions = {
            plugins: {
                jsx: true
            }
        };
        let mergedOptions = Object.assign({}, options, baseOptions);
        return acorn.parse(text, mergedOptions);
    }
}

let parser = {
    estraverse: {
        ...estraverseOrig,
github fkling / astexplorer / registry / tools / acorn / v2.js View on Github external
load() {
    return Promise.resolve({
      loose: parse_dammit,
      parse: jsxInject(acorn).parse,
    });
  },
};
github fkling / astexplorer / registry / tools / acorn / v3.js View on Github external
load() {
    return Promise.resolve({
      loose: parse_dammit,
      parse: jsxInject(acorn).parse,
    });
  },
};

acorn-jsx

Modern, fast React.js JSX parser

MIT
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis

Similar packages