How to use the acorn-jsx.tokTypes 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 eslint / espree / lib / espree.js View on Github external
"use strict";

/* eslint-disable no-param-reassign*/
const acorn = require("acorn");
const jsx = require("acorn-jsx");
const TokenTranslator = require("./token-translator");

const DEFAULT_ECMA_VERSION = 5;
const STATE = Symbol("espree's internal state");
const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
const tokTypes = Object.assign({}, acorn.tokTypes, jsx.tokTypes);


/**
 * Normalize ECMAScript version from the initial config
 * @param {number} ecmaVersion ECMAScript version from the initial config
 * @throws {Error} throws an error if the ecmaVersion is invalid.
 * @returns {number} normalized ECMAScript version
 */
function normalizeEcmaVersion(ecmaVersion = DEFAULT_ECMA_VERSION) {
    if (typeof ecmaVersion !== "number") {
        throw new Error(`ecmaVersion must be a number. Received value of type ${typeof ecmaVersion} instead.`);
    }

    let version = ecmaVersion;

    // Calculate ECMAScript edition number from official year version starting with
github hitext / hitext / src / temp-generators / lang-js / syntax.js View on Github external
tokens.forEach(({ token, context }) => {
        let type = null;

        switch (context) {
            case acorn.tokContexts.j_oTag:
            case acorn.tokContexts.j_cTag:
                switch (token.type) {
                    case acorn.tokTypes.jsxTagStart:
                    case acorn.tokTypes.jsxTagEnd:
                    case acorn.tokTypes.braceR:
                    case acorn.tokTypes.eq:
                    case acorn.tokTypes.slash:
                        type = 'punctuator';
                        break;
                }
                break;

            default:
                switch (token.type) {
                    case acorn.tokTypes.num:
                        type = 'number';
                        break;

                    case acorn.tokTypes.regexp:

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