Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

espree

Package Overview
Dependencies
Maintainers
3
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

espree - npm Package Compare versions

Comparing version 5.0.1 to 6.0.0-alpha.0

4

CHANGELOG.md

@@ -0,1 +1,5 @@

v6.0.0-alpha.0 - April 12, 2019
* [`493d464`](https://github.com/eslint/espree/commit/493d464e1564aea0ea33000389771d42ddece2cb) Breaking: validate parser options (fixes #384) (#412) (薛定谔的猫)
v5.0.1 - February 15, 2019

@@ -2,0 +6,0 @@

61

lib/espree.js

@@ -13,8 +13,10 @@ "use strict";

/**
* 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) {
function normalizeEcmaVersion(ecmaVersion = DEFAULT_ECMA_VERSION) {
if (typeof ecmaVersion === "number") {

@@ -39,11 +41,41 @@ let version = ecmaVersion;

default:
throw new Error("Invalid ecmaVersion.");
// no default
}
} else {
return DEFAULT_ECMA_VERSION;
}
throw new Error("Invalid ecmaVersion.");
}
/**
* Normalize sourceType from the initial config
* @param {string} sourceType to normalize
* @throws {Error} throw an error if sourceType is invalid
* @returns {string} normalized sourceType
*/
function normalizeSourceType(sourceType = "script") {
if (sourceType === "script" || sourceType === "module") {
return sourceType;
}
throw new Error("Invalid sourceType.");
}
/**
* Normalize parserOptions
* @param {Object} options the parser options to normalize
* @throws {Error} throw an error if found invalid option.
* @returns {Object} normalized options
*/
function normalizeOptions(options) {
const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);
const sourceType = normalizeSourceType(options.sourceType);
const ranges = options.range === true;
const locations = options.loc === true;
if (sourceType === "module" && ecmaVersion < 6) {
throw new Error("sourceType 'module' is not supported when ecmaVersion < 2015. Consider adding `{ ecmaVersion: 2015 }` to the parser options.");
}
return Object.assign({}, options, { ecmaVersion, sourceType, ranges, locations });
}
/**
* Converts an Acorn comment to a Esprima comment.

@@ -82,5 +114,5 @@ * @param {boolean} block True if it's a block comment, false if not.

module.exports = () => Parser => class Espree extends Parser {
constructor(options, code) {
if (typeof options !== "object" || options === null) {
options = {};
constructor(opts, code) {
if (typeof opts !== "object" || opts === null) {
opts = {};
}

@@ -91,5 +123,4 @@ if (typeof code !== "string" && !(code instanceof String)) {

const options = normalizeOptions(opts);
const ecmaFeatures = options.ecmaFeatures || {};
const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);
const isModule = options.sourceType === "module";
const tokenTranslator =

@@ -102,7 +133,9 @@ options.tokens === true

super({
ecmaVersion: isModule ? Math.max(6, ecmaVersion) : ecmaVersion,
sourceType: isModule ? "module" : "script",
ranges: options.range === true,
locations: options.loc === true,
// TODO: use {...options} when spread is supported(Node.js >= 8.3.0).
ecmaVersion: options.ecmaVersion,
sourceType: options.sourceType,
ranges: options.ranges,
locations: options.locations,
// Truthy value is true for backward compatibility.

@@ -109,0 +142,0 @@ allowReturnOutsideFunction: Boolean(ecmaFeatures.globalReturn),

@@ -7,3 +7,3 @@ {

"main": "espree.js",
"version": "5.0.1",
"version": "6.0.0-alpha.0",
"files": [

@@ -10,0 +10,0 @@ "lib",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc