Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"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
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: