jsreport-studio
Version:
jsreport templates editor and designer
1,479 lines (1,220 loc) • 4.09 MB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["eslint-browser"] = factory();
else
root["eslint-browser"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _assign = __webpack_require__(1);
var _assign2 = _interopRequireDefault(_assign);
var _linter = __webpack_require__(39);
var _linter2 = _interopRequireDefault(_linter);
var _eslintRecommended = __webpack_require__(637);
var _eslintRecommended2 = _interopRequireDefault(_eslintRecommended);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
_linter2.default.DEFAULT_RECOMMENDED_RULES = (0, _assign2.default)({}, _eslintRecommended2.default);
exports.default = _linter2.default;
module.exports = exports.default;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = { "default": __webpack_require__(2), __esModule: true };
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(3);
module.exports = __webpack_require__(6).Object.assign;
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
// 19.1.3.1 Object.assign(target, source)
var $export = __webpack_require__(4);
$export($export.S + $export.F, 'Object', { assign: __webpack_require__(20) });
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
var global = __webpack_require__(5);
var core = __webpack_require__(6);
var ctx = __webpack_require__(7);
var hide = __webpack_require__(9);
var has = __webpack_require__(19);
var PROTOTYPE = 'prototype';
var $export = function (type, name, source) {
var IS_FORCED = type & $export.F;
var IS_GLOBAL = type & $export.G;
var IS_STATIC = type & $export.S;
var IS_PROTO = type & $export.P;
var IS_BIND = type & $export.B;
var IS_WRAP = type & $export.W;
var exports = IS_GLOBAL ? core : core[name] || (core[name] = {});
var expProto = exports[PROTOTYPE];
var target = IS_GLOBAL ? global : IS_STATIC ? global[name] : (global[name] || {})[PROTOTYPE];
var key, own, out;
if (IS_GLOBAL) source = name;
for (key in source) {
// contains in native
own = !IS_FORCED && target && target[key] !== undefined;
if (own && has(exports, key)) continue;
// export native or passed
out = own ? target[key] : source[key];
// prevent global pollution for namespaces
exports[key] = IS_GLOBAL && typeof target[key] != 'function' ? source[key]
// bind timers to global for call from export context
: IS_BIND && own ? ctx(out, global)
// wrap global constructors for prevent change them in library
: IS_WRAP && target[key] == out ? (function (C) {
var F = function (a, b, c) {
if (this instanceof C) {
switch (arguments.length) {
case 0: return new C();
case 1: return new C(a);
case 2: return new C(a, b);
} return new C(a, b, c);
} return C.apply(this, arguments);
};
F[PROTOTYPE] = C[PROTOTYPE];
return F;
// make static versions for prototype methods
})(out) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
// export proto methods to core.%CONSTRUCTOR%.methods.%NAME%
if (IS_PROTO) {
(exports.virtual || (exports.virtual = {}))[key] = out;
// export proto methods to core.%CONSTRUCTOR%.prototype.%NAME%
if (type & $export.R && expProto && !expProto[key]) hide(expProto, key, out);
}
}
};
// type bitmap
$export.F = 1; // forced
$export.G = 2; // global
$export.S = 4; // static
$export.P = 8; // proto
$export.B = 16; // bind
$export.W = 32; // wrap
$export.U = 64; // safe
$export.R = 128; // real proto method for `library`
module.exports = $export;
/***/ }),
/* 5 */
/***/ (function(module, exports) {
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
var global = module.exports = typeof window != 'undefined' && window.Math == Math
? window : typeof self != 'undefined' && self.Math == Math ? self
// eslint-disable-next-line no-new-func
: Function('return this')();
if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef
/***/ }),
/* 6 */
/***/ (function(module, exports) {
var core = module.exports = { version: '2.6.11' };
if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
// optional / simple context binding
var aFunction = __webpack_require__(8);
module.exports = function (fn, that, length) {
aFunction(fn);
if (that === undefined) return fn;
switch (length) {
case 1: return function (a) {
return fn.call(that, a);
};
case 2: return function (a, b) {
return fn.call(that, a, b);
};
case 3: return function (a, b, c) {
return fn.call(that, a, b, c);
};
}
return function (/* ...args */) {
return fn.apply(that, arguments);
};
};
/***/ }),
/* 8 */
/***/ (function(module, exports) {
module.exports = function (it) {
if (typeof it != 'function') throw TypeError(it + ' is not a function!');
return it;
};
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
var dP = __webpack_require__(10);
var createDesc = __webpack_require__(18);
module.exports = __webpack_require__(14) ? function (object, key, value) {
return dP.f(object, key, createDesc(1, value));
} : function (object, key, value) {
object[key] = value;
return object;
};
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
var anObject = __webpack_require__(11);
var IE8_DOM_DEFINE = __webpack_require__(13);
var toPrimitive = __webpack_require__(17);
var dP = Object.defineProperty;
exports.f = __webpack_require__(14) ? Object.defineProperty : function defineProperty(O, P, Attributes) {
anObject(O);
P = toPrimitive(P, true);
anObject(Attributes);
if (IE8_DOM_DEFINE) try {
return dP(O, P, Attributes);
} catch (e) { /* empty */ }
if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!');
if ('value' in Attributes) O[P] = Attributes.value;
return O;
};
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
var isObject = __webpack_require__(12);
module.exports = function (it) {
if (!isObject(it)) throw TypeError(it + ' is not an object!');
return it;
};
/***/ }),
/* 12 */
/***/ (function(module, exports) {
module.exports = function (it) {
return typeof it === 'object' ? it !== null : typeof it === 'function';
};
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
module.exports = !__webpack_require__(14) && !__webpack_require__(15)(function () {
return Object.defineProperty(__webpack_require__(16)('div'), 'a', { get: function () { return 7; } }).a != 7;
});
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
// Thank's IE8 for his funny defineProperty
module.exports = !__webpack_require__(15)(function () {
return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7;
});
/***/ }),
/* 15 */
/***/ (function(module, exports) {
module.exports = function (exec) {
try {
return !!exec();
} catch (e) {
return true;
}
};
/***/ }),
/* 16 */
/***/ (function(module, exports, __webpack_require__) {
var isObject = __webpack_require__(12);
var document = __webpack_require__(5).document;
// typeof document.createElement is 'object' in old IE
var is = isObject(document) && isObject(document.createElement);
module.exports = function (it) {
return is ? document.createElement(it) : {};
};
/***/ }),
/* 17 */
/***/ (function(module, exports, __webpack_require__) {
// 7.1.1 ToPrimitive(input [, PreferredType])
var isObject = __webpack_require__(12);
// instead of the ES6 spec version, we didn't implement @@toPrimitive case
// and the second argument - flag - preferred type is a string
module.exports = function (it, S) {
if (!isObject(it)) return it;
var fn, val;
if (S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it))) return val;
if (typeof (fn = it.valueOf) == 'function' && !isObject(val = fn.call(it))) return val;
if (!S && typeof (fn = it.toString) == 'function' && !isObject(val = fn.call(it))) return val;
throw TypeError("Can't convert object to primitive value");
};
/***/ }),
/* 18 */
/***/ (function(module, exports) {
module.exports = function (bitmap, value) {
return {
enumerable: !(bitmap & 1),
configurable: !(bitmap & 2),
writable: !(bitmap & 4),
value: value
};
};
/***/ }),
/* 19 */
/***/ (function(module, exports) {
var hasOwnProperty = {}.hasOwnProperty;
module.exports = function (it, key) {
return hasOwnProperty.call(it, key);
};
/***/ }),
/* 20 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// 19.1.2.1 Object.assign(target, source, ...)
var DESCRIPTORS = __webpack_require__(14);
var getKeys = __webpack_require__(21);
var gOPS = __webpack_require__(36);
var pIE = __webpack_require__(37);
var toObject = __webpack_require__(38);
var IObject = __webpack_require__(24);
var $assign = Object.assign;
// should work with symbols and should have deterministic property order (V8 bug)
module.exports = !$assign || __webpack_require__(15)(function () {
var A = {};
var B = {};
// eslint-disable-next-line no-undef
var S = Symbol();
var K = 'abcdefghijklmnopqrst';
A[S] = 7;
K.split('').forEach(function (k) { B[k] = k; });
return $assign({}, A)[S] != 7 || Object.keys($assign({}, B)).join('') != K;
}) ? function assign(target, source) { // eslint-disable-line no-unused-vars
var T = toObject(target);
var aLen = arguments.length;
var index = 1;
var getSymbols = gOPS.f;
var isEnum = pIE.f;
while (aLen > index) {
var S = IObject(arguments[index++]);
var keys = getSymbols ? getKeys(S).concat(getSymbols(S)) : getKeys(S);
var length = keys.length;
var j = 0;
var key;
while (length > j) {
key = keys[j++];
if (!DESCRIPTORS || isEnum.call(S, key)) T[key] = S[key];
}
} return T;
} : $assign;
/***/ }),
/* 21 */
/***/ (function(module, exports, __webpack_require__) {
// 19.1.2.14 / 15.2.3.14 Object.keys(O)
var $keys = __webpack_require__(22);
var enumBugKeys = __webpack_require__(35);
module.exports = Object.keys || function keys(O) {
return $keys(O, enumBugKeys);
};
/***/ }),
/* 22 */
/***/ (function(module, exports, __webpack_require__) {
var has = __webpack_require__(19);
var toIObject = __webpack_require__(23);
var arrayIndexOf = __webpack_require__(27)(false);
var IE_PROTO = __webpack_require__(31)('IE_PROTO');
module.exports = function (object, names) {
var O = toIObject(object);
var i = 0;
var result = [];
var key;
for (key in O) if (key != IE_PROTO) has(O, key) && result.push(key);
// Don't enum bug & hidden keys
while (names.length > i) if (has(O, key = names[i++])) {
~arrayIndexOf(result, key) || result.push(key);
}
return result;
};
/***/ }),
/* 23 */
/***/ (function(module, exports, __webpack_require__) {
// to indexed object, toObject with fallback for non-array-like ES3 strings
var IObject = __webpack_require__(24);
var defined = __webpack_require__(26);
module.exports = function (it) {
return IObject(defined(it));
};
/***/ }),
/* 24 */
/***/ (function(module, exports, __webpack_require__) {
// fallback for non-array-like ES3 and non-enumerable old V8 strings
var cof = __webpack_require__(25);
// eslint-disable-next-line no-prototype-builtins
module.exports = Object('z').propertyIsEnumerable(0) ? Object : function (it) {
return cof(it) == 'String' ? it.split('') : Object(it);
};
/***/ }),
/* 25 */
/***/ (function(module, exports) {
var toString = {}.toString;
module.exports = function (it) {
return toString.call(it).slice(8, -1);
};
/***/ }),
/* 26 */
/***/ (function(module, exports) {
// 7.2.1 RequireObjectCoercible(argument)
module.exports = function (it) {
if (it == undefined) throw TypeError("Can't call method on " + it);
return it;
};
/***/ }),
/* 27 */
/***/ (function(module, exports, __webpack_require__) {
// false -> Array#indexOf
// true -> Array#includes
var toIObject = __webpack_require__(23);
var toLength = __webpack_require__(28);
var toAbsoluteIndex = __webpack_require__(30);
module.exports = function (IS_INCLUDES) {
return function ($this, el, fromIndex) {
var O = toIObject($this);
var length = toLength(O.length);
var index = toAbsoluteIndex(fromIndex, length);
var value;
// Array#includes uses SameValueZero equality algorithm
// eslint-disable-next-line no-self-compare
if (IS_INCLUDES && el != el) while (length > index) {
value = O[index++];
// eslint-disable-next-line no-self-compare
if (value != value) return true;
// Array#indexOf ignores holes, Array#includes - not
} else for (;length > index; index++) if (IS_INCLUDES || index in O) {
if (O[index] === el) return IS_INCLUDES || index || 0;
} return !IS_INCLUDES && -1;
};
};
/***/ }),
/* 28 */
/***/ (function(module, exports, __webpack_require__) {
// 7.1.15 ToLength
var toInteger = __webpack_require__(29);
var min = Math.min;
module.exports = function (it) {
return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
};
/***/ }),
/* 29 */
/***/ (function(module, exports) {
// 7.1.4 ToInteger
var ceil = Math.ceil;
var floor = Math.floor;
module.exports = function (it) {
return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
};
/***/ }),
/* 30 */
/***/ (function(module, exports, __webpack_require__) {
var toInteger = __webpack_require__(29);
var max = Math.max;
var min = Math.min;
module.exports = function (index, length) {
index = toInteger(index);
return index < 0 ? max(index + length, 0) : min(index, length);
};
/***/ }),
/* 31 */
/***/ (function(module, exports, __webpack_require__) {
var shared = __webpack_require__(32)('keys');
var uid = __webpack_require__(34);
module.exports = function (key) {
return shared[key] || (shared[key] = uid(key));
};
/***/ }),
/* 32 */
/***/ (function(module, exports, __webpack_require__) {
var core = __webpack_require__(6);
var global = __webpack_require__(5);
var SHARED = '__core-js_shared__';
var store = global[SHARED] || (global[SHARED] = {});
(module.exports = function (key, value) {
return store[key] || (store[key] = value !== undefined ? value : {});
})('versions', []).push({
version: core.version,
mode: __webpack_require__(33) ? 'pure' : 'global',
copyright: '© 2019 Denis Pushkarev (zloirock.ru)'
});
/***/ }),
/* 33 */
/***/ (function(module, exports) {
module.exports = true;
/***/ }),
/* 34 */
/***/ (function(module, exports) {
var id = 0;
var px = Math.random();
module.exports = function (key) {
return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
};
/***/ }),
/* 35 */
/***/ (function(module, exports) {
// IE 8- don't enum bug keys
module.exports = (
'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'
).split(',');
/***/ }),
/* 36 */
/***/ (function(module, exports) {
exports.f = Object.getOwnPropertySymbols;
/***/ }),
/* 37 */
/***/ (function(module, exports) {
exports.f = {}.propertyIsEnumerable;
/***/ }),
/* 38 */
/***/ (function(module, exports, __webpack_require__) {
// 7.1.13 ToObject(argument)
var defined = __webpack_require__(26);
module.exports = function (it) {
return Object(defined(it));
};
/***/ }),
/* 39 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* @fileoverview Main Linter Class
* @author Gyandeep Singh
*/
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var _getOwnPropertyNames = __webpack_require__(40);
var _getOwnPropertyNames2 = _interopRequireDefault(_getOwnPropertyNames);
var _map = __webpack_require__(46);
var _map2 = _interopRequireDefault(_map);
var _classCallCheck2 = __webpack_require__(89);
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = __webpack_require__(90);
var _createClass3 = _interopRequireDefault(_createClass2);
var _weakMap = __webpack_require__(94);
var _weakMap2 = _interopRequireDefault(_weakMap);
var _create = __webpack_require__(100);
var _create2 = _interopRequireDefault(_create);
var _defineProperty2 = __webpack_require__(103);
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _freeze = __webpack_require__(104);
var _freeze2 = _interopRequireDefault(_freeze);
var _typeof2 = __webpack_require__(107);
var _typeof3 = _interopRequireDefault(_typeof2);
var _toConsumableArray2 = __webpack_require__(119);
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _keys = __webpack_require__(125);
var _keys2 = _interopRequireDefault(_keys);
var _assign = __webpack_require__(1);
var _assign2 = _interopRequireDefault(_assign);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var eslintScope = __webpack_require__(128),
evk = __webpack_require__(185),
espree = __webpack_require__(196),
lodash = __webpack_require__(204),
CodePathAnalyzer = __webpack_require__(207),
ConfigOps = __webpack_require__(222),
validator = __webpack_require__(228),
Environments = __webpack_require__(284),
applyDisableDirectives = __webpack_require__(288),
createEmitter = __webpack_require__(289),
NodeEventGenerator = __webpack_require__(290),
SourceCode = __webpack_require__(292),
Traverser = __webpack_require__(309),
createReportTranslator = __webpack_require__(310),
Rules = __webpack_require__(316),
timing = __webpack_require__(621),
ConfigCommentParser = __webpack_require__(622),
astUtils = __webpack_require__(217),
pkg = __webpack_require__(635),
SourceCodeFixer = __webpack_require__(636);
var debug = __webpack_require__(212)("eslint:linter");
var MAX_AUTOFIX_PASSES = 10;
var DEFAULT_PARSER_NAME = "espree";
var commentParser = new ConfigCommentParser();
//------------------------------------------------------------------------------
// Typedefs
//------------------------------------------------------------------------------
/**
* The result of a parsing operation from parseForESLint()
* @typedef {Object} CustomParseResult
* @property {ASTNode} ast The ESTree AST Program node.
* @property {Object} services An object containing additional services related
* to the parser.
* @property {ScopeManager|null} scopeManager The scope manager object of this AST.
* @property {Object|null} visitorKeys The visitor keys to traverse this AST.
*/
/**
* @typedef {Object} DisableDirective
* @property {("disable"|"enable"|"disable-line"|"disable-next-line")} type
* @property {number} line
* @property {number} column
* @property {(string|null)} ruleId
*/
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
* Ensures that variables representing built-in properties of the Global Object,
* and any globals declared by special block comments, are present in the global
* scope.
* @param {Scope} globalScope The global scope.
* @param {Object} configGlobals The globals declared in configuration
* @param {{exportedVariables: Object, enabledGlobals: Object}} commentDirectives Directives from comment configuration
* @returns {void}
*/
function addDeclaredGlobals(globalScope, configGlobals, commentDirectives) {
var mergedGlobalsInfo = (0, _assign2.default)({}, lodash.mapValues(configGlobals, function (value) {
return { sourceComment: null, value: ConfigOps.normalizeConfigGlobal(value) };
}), lodash.mapValues(commentDirectives.enabledGlobals, function (_ref) {
var comment = _ref.comment,
value = _ref.value;
return { sourceComment: comment, value: ConfigOps.normalizeConfigGlobal(value) };
}));
(0, _keys2.default)(mergedGlobalsInfo).filter(function (name) {
return mergedGlobalsInfo[name].value !== "off";
}).forEach(function (name) {
var variable = globalScope.set.get(name);
if (!variable) {
variable = new eslintScope.Variable(name, globalScope);
if (mergedGlobalsInfo[name].sourceComment === null) {
variable.eslintExplicitGlobal = false;
} else {
variable.eslintExplicitGlobal = true;
variable.eslintExplicitGlobalComment = mergedGlobalsInfo[name].sourceComment;
}
globalScope.variables.push(variable);
globalScope.set.set(name, variable);
}
variable.writeable = mergedGlobalsInfo[name].value === "writeable";
});
// mark all exported variables as such
(0, _keys2.default)(commentDirectives.exportedVariables).forEach(function (name) {
var variable = globalScope.set.get(name);
if (variable) {
variable.eslintUsed = true;
}
});
/*
* "through" contains all references which definitions cannot be found.
* Since we augment the global scope using configuration, we need to update
* references and remove the ones that were added by configuration.
*/
globalScope.through = globalScope.through.filter(function (reference) {
var name = reference.identifier.name;
var variable = globalScope.set.get(name);
if (variable) {
/*
* Links the variable and the reference.
* And this reference is removed from `Scope#through`.
*/
reference.resolved = variable;
variable.references.push(reference);
return false;
}
return true;
});
}
/**
* Creates a collection of disable directives from a comment
* @param {("disable"|"enable"|"disable-line"|"disable-next-line")} type The type of directive comment
* @param {{line: number, column: number}} loc The 0-based location of the comment token
* @param {string} value The value after the directive in the comment
* comment specified no specific rules, so it applies to all rules (e.g. `eslint-disable`)
* @returns {DisableDirective[]} Directives from the comment
*/
function createDisableDirectives(type, loc, value) {
var ruleIds = (0, _keys2.default)(commentParser.parseListConfig(value));
var directiveRules = ruleIds.length ? ruleIds : [null];
return directiveRules.map(function (ruleId) {
return { type: type, line: loc.line, column: loc.column + 1, ruleId: ruleId };
});
}
/**
* Parses comments in file to extract file-specific config of rules, globals
* and environments and merges them with global config; also code blocks
* where reporting is disabled or enabled and merges them with reporting config.
* @param {string} filename The file being checked.
* @param {ASTNode} ast The top node of the AST.
* @param {function(string): {create: Function}} ruleMapper A map from rule IDs to defined rules
* @returns {{configuredRules: Object, enabledGlobals: Object, exportedVariables: Object, problems: Problem[], disableDirectives: DisableDirective[]}}
* A collection of the directive comments that were found, along with any problems that occurred when parsing
*/
function getDirectiveComments(filename, ast, ruleMapper) {
var configuredRules = {};
var enabledGlobals = {};
var exportedVariables = {};
var problems = [];
var disableDirectives = [];
ast.comments.filter(function (token) {
return token.type !== "Shebang";
}).forEach(function (comment) {
var trimmedCommentText = comment.value.trim();
var match = /^(eslint(\x2D[0-9A-Z_a-z]+){0,3}|exported|globals?)([\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]|$)/.exec(trimmedCommentText);
if (!match) {
return;
}
var directiveValue = trimmedCommentText.slice(match.index + match[1].length);
if (/^eslint\x2Ddisable\x2D(next\x2D)?line$/.test(match[1])) {
if (comment.loc.start.line === comment.loc.end.line) {
var directiveType = match[1].slice("eslint-".length);
disableDirectives.push.apply(disableDirectives, (0, _toConsumableArray3.default)(createDisableDirectives(directiveType, comment.loc.start, directiveValue)));
} else {
problems.push({
ruleId: null,
severity: 2,
message: match[1] + " comment should not span multiple lines.",
line: comment.loc.start.line,
column: comment.loc.start.column + 1,
endLine: comment.loc.end.line,
endColumn: comment.loc.end.column + 1,
nodeType: null
});
}
} else if (comment.type === "Block") {
switch (match[1]) {
case "exported":
(0, _assign2.default)(exportedVariables, commentParser.parseStringConfig(directiveValue, comment));
break;
case "globals":
case "global":
(0, _assign2.default)(enabledGlobals, commentParser.parseStringConfig(directiveValue, comment));
break;
case "eslint-disable":
disableDirectives.push.apply(disableDirectives, (0, _toConsumableArray3.default)(createDisableDirectives("disable", comment.loc.start, directiveValue)));
break;
case "eslint-enable":
disableDirectives.push.apply(disableDirectives, (0, _toConsumableArray3.default)(createDisableDirectives("enable", comment.loc.start, directiveValue)));
break;
case "eslint":
{
var parseResult = commentParser.parseJsonConfig(directiveValue, comment.loc);
if (parseResult.success) {
(0, _keys2.default)(parseResult.config).forEach(function (name) {
var ruleValue = parseResult.config[name];
try {
validator.validateRuleOptions(ruleMapper(name), name, ruleValue);
} catch (err) {
problems.push({
ruleId: name,
severity: 2,
message: err.message,
line: comment.loc.start.line,
column: comment.loc.start.column + 1,
endLine: comment.loc.end.line,
endColumn: comment.loc.end.column + 1,
nodeType: null
});
}
configuredRules[name] = ruleValue;
});
} else {
problems.push(parseResult.error);
}
break;
}
// no default
}
}
});
return {
configuredRules: configuredRules,
enabledGlobals: enabledGlobals,
exportedVariables: exportedVariables,
problems: problems,
disableDirectives: disableDirectives
};
}
/**
* Normalize ECMAScript version from the initial config
* @param {number} ecmaVersion ECMAScript version from the initial config
* @param {boolean} isModule Whether the source type is module or not
* @returns {number} normalized ECMAScript version
*/
function normalizeEcmaVersion(ecmaVersion, isModule) {
// Need at least ES6 for modules
if (isModule && (!ecmaVersion || ecmaVersion < 6)) {
return 6;
}
/*
* Calculate ECMAScript edition number from official year version starting with
* ES2015, which corresponds with ES6 (or a difference of 2009).
*/
if (ecmaVersion >= 2015) {
return ecmaVersion - 2009;
}
return ecmaVersion;
}
var eslintEnvPattern = /\/\*[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*eslint\x2Denv[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]((?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+?)\*\//g;
/**
* Checks whether or not there is a comment which has "eslint-env *" in a given text.
* @param {string} text - A source code text to check.
* @returns {Object|null} A result of parseListConfig() with "eslint-env *" comment.
*/
function findEslintEnv(text) {
var match = void 0,
retv = void 0;
eslintEnvPattern.lastIndex = 0;
while (match = eslintEnvPattern.exec(text)) {
retv = (0, _assign2.default)(retv || {}, commentParser.parseListConfig(match[1]));
}
return retv;
}
/**
* Normalizes the possible options for `linter.verify` and `linter.verifyAndFix` to a
* consistent shape.
* @param {(string|{reportUnusedDisableDirectives: boolean, filename: string, allowInlineConfig: boolean})} providedOptions Options
* @returns {{reportUnusedDisableDirectives: boolean, filename: string, allowInlineConfig: boolean}} Normalized options
*/
function normalizeVerifyOptions(providedOptions) {
var isObjectOptions = (typeof providedOptions === "undefined" ? "undefined" : (0, _typeof3.default)(providedOptions)) === "object";
var providedFilename = isObjectOptions ? providedOptions.filename : providedOptions;
return {
filename: typeof providedFilename === "string" ? providedFilename : "<input>",
allowInlineConfig: !isObjectOptions || providedOptions.allowInlineConfig !== false,
reportUnusedDisableDirectives: isObjectOptions && !!providedOptions.reportUnusedDisableDirectives
};
}
/**
* Combines the provided parserOptions with the options from environments
* @param {string} parserName The parser name which uses this options.
* @param {Object} providedOptions The provided 'parserOptions' key in a config
* @param {Environment[]} enabledEnvironments The environments enabled in configuration and with inline comments
* @returns {Object} Resulting parser options after merge
*/
function resolveParserOptions(parserName, providedOptions, enabledEnvironments) {
var parserOptionsFromEnv = enabledEnvironments.filter(function (env) {
return env.parserOptions;
}).reduce(function (parserOptions, env) {
return ConfigOps.merge(parserOptions, env.parserOptions);
}, {});
var mergedParserOptions = ConfigOps.merge(parserOptionsFromEnv, providedOptions || {});
var isModule = mergedParserOptions.sourceType === "module";
if (isModule) {
// can't have global return inside of modules
mergedParserOptions.ecmaFeatures = (0, _assign2.default)({}, mergedParserOptions.ecmaFeatures, { globalReturn: false });
}
mergedParserOptions.ecmaVersion = normalizeEcmaVersion(mergedParserOptions.ecmaVersion, isModule);
// TODO: For backward compatibility. Will remove on v6.0.0.
if (parserName === DEFAULT_PARSER_NAME && mergedParserOptions.ecmaFeatures && mergedParserOptions.ecmaFeatures.experimentalObjectRestSpread && (!mergedParserOptions.ecmaVersion || mergedParserOptions.ecmaVersion < 9)) {
mergedParserOptions.ecmaVersion = 9;
}
return mergedParserOptions;
}
/**
* Combines the provided globals object with the globals from environments
* @param {Object} providedGlobals The 'globals' key in a config
* @param {Environments[]} enabledEnvironments The environments enabled in configuration and with inline comments
* @returns {Object} The resolved globals object
*/
function resolveGlobals(providedGlobals, enabledEnvironments) {
return _assign2.default.apply(Object, [{}].concat((0, _toConsumableArray3.default)(enabledEnvironments.filter(function (env) {
return env.globals;
}).map(function (env) {
return env.globals;
})), [providedGlobals]));
}
/**
* Strips Unicode BOM from a given text.
*
* @param {string} text - A text to strip.
* @returns {string} The stripped text.
*/
function stripUnicodeBOM(text) {
/*
* Check Unicode BOM.
* In JavaScript, string data is stored as UTF-16, so BOM is 0xFEFF.
* http://www.ecma-international.org/ecma-262/6.0/#sec-unicode-format-control-characters
*/
if (text.charCodeAt(0) === 0xFEFF) {
return text.slice(1);
}
return text;
}
/**
* Get the options for a rule (not including severity), if any
* @param {Array|number} ruleConfig rule configuration
* @returns {Array} of rule options, empty Array if none
*/
function getRuleOptions(ruleConfig) {
if (Array.isArray(ruleConfig)) {
return ruleConfig.slice(1);
}
return [];
}
/**
* Analyze scope of the given AST.
* @param {ASTNode} ast The `Program` node to analyze.
* @param {Object} parserOptions The parser options.
* @param {Object} visitorKeys The visitor keys.
* @returns {ScopeManager} The analysis result.
*/
function analyzeScope(ast, parserOptions, visitorKeys) {
var ecmaFeatures = parserOptions.ecmaFeatures || {};
var ecmaVersion = parserOptions.ecmaVersion || 5;
return eslintScope.analyze(ast, {
ignoreEval: true,
nodejsScope: ecmaFeatures.globalReturn,
impliedStrict: ecmaFeatures.impliedStrict,
ecmaVersion: ecmaVersion,
sourceType: parserOptions.sourceType || "script",
childVisitorKeys: visitorKeys || evk.KEYS,
fallback: Traverser.getKeys
});
}
/**
* Parses text into an AST. Moved out here because the try-catch prevents
* optimization of functions, so it's best to keep the try-catch as isolated
* as possible
* @param {string} text The text to parse.
* @param {Object} providedParserOptions Options to pass to the parser
* @param {string} parserName The name of the parser
* @param {Map<string, Object>} parserMap A map from names to loaded parsers
* @param {string} filePath The path to the file being parsed.
* @returns {{success: false, error: Problem}|{success: true, sourceCode: SourceCode}}
* An object containing the AST and parser services if parsing was successful, or the error if parsing failed
* @private
*/
function parse(text, providedParserOptions, parserName, parserMap, filePath) {
var textToParse = stripUnicodeBOM(text).replace(astUtils.SHEBANG_MATCHER, function (match, captured) {
return "//" + captured;
});
var parserOptions = (0, _assign2.default)({}, providedParserOptions, {
loc: true,
range: true,
raw: true,
tokens: true,
comment: true,
eslintVisitorKeys: true,
eslintScopeManager: true,
filePath: filePath
});
var parser = void 0;
try {
parser = parserMap.get(parserName) ;
} catch (ex) {
return {
success: false,
error: {
ruleId: null,
fatal: true,
severity: 2,
message: ex.message,
line: 0,
column: 0
}
};
}
/*
* Check for parsing errors first. If there's a parsing error, nothing
* else can happen. However, a parsing error does not throw an error
* from this method - it's just considered a fatal error message, a
* problem that ESLint identified just like any other.
*/
try {
var parseResult = typeof parser.parseForESLint === "function" ? parser.parseForESLint(textToParse, parserOptions) : { ast: parser.parse(textToParse, parserOptions) };
var ast = parseResult.ast;
var parserServices = parseResult.services || {};
var visitorKeys = parseResult.visitorKeys || evk.KEYS;
var scopeManager = parseResult.scopeManager || analyzeScope(ast, parserOptions, visitorKeys);
return {
success: true,
/*
* Save all values that `parseForESLint()` returned.
* If a `SourceCode` object is given as the first parameter instead of source code text,
* linter skips the parsing process and reuses the source code object.
* In that case, linter needs all the values that `parseForESLint()` returned.
*/
sourceCode: new SourceCode({
text: text,
ast: ast,
parserServices: parserServices,
scopeManager: scopeManager,
visitorKeys: visitorKeys
})
};
} catch (ex) {
// If the message includes a leading line number, strip it:
var message = "Parsing error: " + ex.message.replace(/^line [0-9]+:/i, "").trim();
return {
success: false,
error: {
ruleId: null,
fatal: true,
severity: 2,
message: message,
line: ex.lineNumber,
column: ex.column
}
};
}
}
/**
* Gets the scope for the current node
* @param {ScopeManager} scopeManager The scope manager for this AST
* @param {ASTNode} currentNode The node to get the scope of
* @returns {eslint-scope.Scope} The scope information for this node
*/
function _getScope(scopeManager, currentNode) {
// On Program node, get the outermost scope to avoid return Node.js special function scope or ES modules scope.
var inner = currentNode.type !== "Program";
for (var node = currentNode; node; node = node.parent) {
var scope = scopeManager.acquire(node, inner);
if (scope) {
if (scope.type === "function-expression-name") {
return scope.childScopes[0];
}
return scope;
}
}
return scopeManager.scopes[0];
}
/**
* Marks a variable as used in the current scope
* @param {ScopeManager} scopeManager The scope manager for this AST. The scope may be mutated by this function.
* @param {ASTNode} currentNode The node currently being traversed
* @param {Object} parserOptions The options used to parse this text
* @param {string} name The name of the variable that should be marked as used.
* @returns {boolean} True if the variable was found and marked as used, false if not.
*/
function _markVariableAsUsed(scopeManager, currentNode, parserOptions, name) {
var hasGlobalReturn = parserOptions.ecmaFeatures && parserOptions.ecmaFeatures.globalReturn;
var specialScope = hasGlobalReturn || parserOptions.sourceType === "module";
var currentScope = _getScope(scopeManager, currentNode);
// Special Node.js scope means we need to start one level deeper
var initialScope = currentScope.type === "global" && specialScope ? currentScope.childScopes[0] : currentScope;
for (var scope = initialScope; scope; scope = scope.upper) {
var variable = scope.variables.find(function (scopeVar) {
return scopeVar.name === name;
});
if (variable) {
variable.eslintUsed = true;
return true;
}
}
return false;
}
/**
* Runs a rule, and gets its listeners
* @param {Rule} rule A normalized rule with a `create` method
* @param {Context} ruleContext The context that should be passed to the rule
* @returns {Object} A map of selector listeners provided by the rule
*/
function createRuleListeners(rule, ruleContext) {
try {
return rule.create(ruleContext);
} catch (ex) {
ex.message = "Error while loading rule '" + ruleContext.id + "': " + ex.message;
throw ex;
}
}
/**
* Gets all the ancestors of a given node
* @param {ASTNode} node The node
* @returns {ASTNode[]} All the ancestor nodes in the AST, not including the provided node, starting
* from the root node and going inwards to the parent node.
*/
function _getAncestors(node) {
var ancestorsStartingAtParent = [];
for (var ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
ancestorsStartingAtParent.push(ancestor);
}
return ancestorsStartingAtParent.reverse();
}
// methods that exist on SourceCode object
var DEPRECATED_SOURCECODE_PASSTHROUGHS = {
getSource: "getText",
getSourceLines: "getLines",
getAllComments: "getAllComments",
getNodeByRangeIndex: "getNodeByRangeIndex",
getComments: "getComments",
getCommentsBefore: "getCommentsBefore",
getCommentsAfter: "getCommentsAfter",
getCommentsInside: "getCommentsInside",
getJSDocComment: "getJSDocComment",
getFirstToken: "getFirstToken",
getFirstTokens: "getFirstTokens",
getLastToken: "getLastToken",
getLastTokens: "getLastTokens",
getTokenAfter: "getTokenAfter",
getTokenBefore: "getTokenBefore",
getTokenByRangeStart: "getTokenByRangeStart",
getTokens: "getTokens",
getTokensAfter: "getTokensAfter",
getTokensBefore: "getTokensBefore",
getTokensBetween: "getTokensBetween"
};
var BASE_TRAVERSAL_CONTEXT = (0, _freeze2.default)((0, _keys2.default)(DEPRECATED_SOURCECODE_PASSTHROUGHS).reduce(function (contextInfo, methodName) {
return (0, _assign2.default)(contextInfo, (0, _defineProperty3.default)({}, methodName, function () {
var _getSourceCode;
return (_getSourceCode = this.getSourceCode())[DEPRECATED_SOURCECODE_PASSTHROUGHS[methodName]].apply(_getSourceCode, arguments);
}));
}, {}));
/**
* Runs the given rules on the given SourceCode object
* @param {SourceCode} sourceCode A SourceCode object for the given text
* @param {Object} configuredRules The rules configuration
* @param {function(string): Rule} ruleMapper A mapper function from rule names to rules
* @param {Object} parserOptions The options that were passed to the parser
* @param {string} parserName The name of the parser in the config
* @param {Object} settings The settings that were enabled in the config
* @param {string} filename The reported filename of the code
* @returns {Problem[]} An array of reported problems
*/
function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parserName, settings, filename) {
var emitter = createEmitter();
var nodeQueue = [];
var currentNode = sourceCode.ast;
Traverser.traverse(sourceCode.ast, {
enter: function enter(node, parent) {
node.parent = parent;
nodeQueue.push({ isEntering: true, node: node });
},
leave: function leave(node) {
nodeQueue.push({ isEntering: false, node: node });
},
visitorKeys: sourceCode.visitorKeys
});
/*
* Create a frozen object with the ruleContext properties and methods that are shared by all rules.
* All rule contexts will inherit from this object. This avoids the performance penalty of copying all the
* properties once for each rule.
*/
var sharedTraversalContext = (0, _freeze2.default)((0, _assign2.default)((0, _create2.default)(BASE_TRAVERSAL_CONTEXT), {
getAncestors: function getAncestors() {
return _getAncestors(currentNode);
},
getDeclaredVariables: sourceCode.scopeManager.getDeclaredVariables.bind(sourceCode.scopeManager),
getFilename: function getFilename() {
return filename;
},
getScope: function getScope() {
return _getScope(sourceCode.scopeManager, currentNode);
},
getSourceCode: function getSourceCode() {
return sourceCode;
},
markVariableAsUsed: function markVariableAsUsed(name) {
return _markVariableAsUsed(sourceCode.scopeManager, currentNode, parserOptions, name);
},
parserOptions: parserOptions,
parserPath: parserName,
parserServices: sourceCode.parserServices,
settings: settings
}));
var lintingProblems = [];
(0, _keys2.default)(configuredRules).forEach(function (ruleId) {
var severity = ConfigOps.getRuleSeverity(configuredRules[ruleId]);
if (severity === 0) {
return;
}
var rule = ruleMapper(ruleId);
var messageIds = rule.meta && rule.meta.messages;
var reportTranslator = null;
var ruleContext = (0, _freeze2.default)((0, _assign2.default)((0, _create2.default)(sharedTraversalContext), {
id: ruleId,
options: getRuleOptions(configuredRules[ruleId]),
report: function report() {
/*
* Create a report translator lazily.
* In a vast majority of cases, any given rule reports zero errors on a given
* piece of code. Creating a translator lazily avoids the performance cost of
* creating a new translator function for each rule that usually doesn't get
* called.
*
* Using lazy report translators improves end-to-end performance by about 3%
* with Node 8.4.0.
*/
if (reportTranslator === null) {
reportTranslator = createReportTranslator({ ruleId: ruleId, severity: severity, sourceCode: sourceCode, messageIds: messageIds });
}
var problem = reportTranslator.apply(undefined, arguments);
if (problem.fix && rule.meta && !rule.meta.fixable) {
throw new Error("Fixable rules should export a `meta.fixable` property.");
}
lintingProblems.push(problem);
}
}));