mirror of
https://github.com/nodejs/node.git
synced 2025-08-16 14:18:44 +02:00

Update ESLint to 2.1.0. ESLint has a number of potentially-useful new features but this change attempts to be minimal in its changes. However, some things could not be avoided reasonably. ESLint 2.1.0 found a few lint issues that ESLing 1.x missed with template strings that did not take advantage of any features of template strings, and `let` declarations where `const` sufficed. Additionally, ESLint 2.1.0 removes some granularity around enabling ES6 features. Some features (e.g., spread operator) that had been turned off in our configuration for ESLint 1.x are now permitted. PR-URL: https://github.com/nodejs/node/pull/5214 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: jbergstroem - Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Myles Borins <myles.borins@gmail.com>
118 lines
3 KiB
JavaScript
118 lines
3 KiB
JavaScript
/**
|
|
* @fileoverview A class of the code path.
|
|
* @author Toru Nagashima
|
|
* @copyright 2015 Toru Nagashima. All rights reserved.
|
|
* See LICENSE file in root directory for full license.
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Requirements
|
|
//------------------------------------------------------------------------------
|
|
|
|
var CodePathState = require("./code-path-state");
|
|
var IdGenerator = require("./id-generator");
|
|
|
|
//------------------------------------------------------------------------------
|
|
// Public Interface
|
|
//------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* A code path.
|
|
*
|
|
* @constructor
|
|
* @param {string} id - An identifier.
|
|
* @param {CodePath|null} upper - The code path of the upper function scope.
|
|
* @param {function} onLooped - A callback function to notify looping.
|
|
*/
|
|
function CodePath(id, upper, onLooped) {
|
|
/**
|
|
* The identifier of this code path.
|
|
* Rules use it to store additional information of each rule.
|
|
* @type {string}
|
|
*/
|
|
this.id = id;
|
|
|
|
/**
|
|
* The code path of the upper function scope.
|
|
* @type {CodePath|null}
|
|
*/
|
|
this.upper = upper;
|
|
|
|
/**
|
|
* The code paths of nested function scopes.
|
|
* @type {CodePath[]}
|
|
*/
|
|
this.childCodePaths = [];
|
|
|
|
// Initializes internal state.
|
|
Object.defineProperty(
|
|
this,
|
|
"internal",
|
|
{value: new CodePathState(new IdGenerator(id + "_"), onLooped)});
|
|
|
|
// Adds this into `childCodePaths` of `upper`.
|
|
if (upper) {
|
|
upper.childCodePaths.push(this);
|
|
}
|
|
}
|
|
|
|
CodePath.prototype = {
|
|
constructor: CodePath,
|
|
|
|
/**
|
|
* The initial code path segment.
|
|
* @type {CodePathSegment}
|
|
*/
|
|
get initialSegment() {
|
|
return this.internal.initialSegment;
|
|
},
|
|
|
|
/**
|
|
* Final code path segments.
|
|
* This array is a mix of `returnedSegments` and `thrownSegments`.
|
|
* @type {CodePathSegment[]}
|
|
*/
|
|
get finalSegments() {
|
|
return this.internal.finalSegments;
|
|
},
|
|
|
|
/**
|
|
* Final code path segments which is with `return` statements.
|
|
* This array contains the last path segment if it's reachable.
|
|
* Since the reachable last path returns `undefined`.
|
|
* @type {CodePathSegment[]}
|
|
*/
|
|
get returnedSegments() {
|
|
return this.internal.returnedForkContext;
|
|
},
|
|
|
|
/**
|
|
* Final code path segments which is with `throw` statements.
|
|
* @type {CodePathSegment[]}
|
|
*/
|
|
get thrownSegments() {
|
|
return this.internal.thrownForkContext;
|
|
},
|
|
|
|
/**
|
|
* Current code path segments.
|
|
* @type {CodePathSegment[]}
|
|
*/
|
|
get currentSegments() {
|
|
return this.internal.currentSegments;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Gets the state of a given code path.
|
|
*
|
|
* @param {CodePath} codePath - A code path to get.
|
|
* @returns {CodePathState} The state of the code path.
|
|
*/
|
|
CodePath.getState = function getState(codePath) {
|
|
return codePath.internal;
|
|
};
|
|
|
|
module.exports = CodePath;
|