aboutsummaryrefslogtreecommitdiff
path: root/node_modules/typhonjs-istanbul-instrument-jspm/dist
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-10-10 03:43:44 +0200
committerFlorian Dold <florian.dold@gmail.com>2016-10-10 03:43:44 +0200
commitabd94a7f5a50f43c797a11b53549ae48fff667c3 (patch)
treeab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/typhonjs-istanbul-instrument-jspm/dist
parenta0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff)
downloadwallet-core-abd94a7f5a50f43c797a11b53549ae48fff667c3.tar.xz
add node_modules to address #4364
Diffstat (limited to 'node_modules/typhonjs-istanbul-instrument-jspm/dist')
-rw-r--r--node_modules/typhonjs-istanbul-instrument-jspm/dist/instrumentIstanbulSystem.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/node_modules/typhonjs-istanbul-instrument-jspm/dist/instrumentIstanbulSystem.js b/node_modules/typhonjs-istanbul-instrument-jspm/dist/instrumentIstanbulSystem.js
new file mode 100644
index 000000000..593260119
--- /dev/null
+++ b/node_modules/typhonjs-istanbul-instrument-jspm/dist/instrumentIstanbulSystem.js
@@ -0,0 +1,85 @@
+'use strict';
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = instrumentIstanbulSystem;
+
+var _istanbulLibInstrument = require('istanbul-lib-instrument');
+
+var _istanbulLibInstrument2 = _interopRequireDefault(_istanbulLibInstrument);
+
+function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+// Good enough ES6 module detection regex.
+// Format detections not designed to be accurate, but to handle the 99% use case.
+var s_ESM_REGEX = /(^\s*|[}\);\n]\s*)(import\s*(['"]|(\*\s+as\s+)?[^"'\(\)\n;]+\s*from\s*['"]|\{)|export\s+\*\s+from\s+["']|export\s* (\{|default|function|class|var|const|let|async\s+function))/;
+
+/**
+ * Instruments JSPM / SystemJS replacing the `System.translate` hook adding Istanbul instrumentation of loaded source
+ * code before deferring the instrumented source for translation. The instrumentation process occurs on the original
+ * source code and supports ES5 and ES Modules (ES6+).
+ *
+ * @param {object} System - An instance of SystemJS.
+ *
+ * @param {RegExp} sourceFilePathRegex - A regex which defines which source files are instrumented; default excludes
+ * any sources with file paths that includes `jspm_packages`.
+ */
+function instrumentIstanbulSystem(System) {
+ var sourceFilePathRegex = arguments.length <= 1 || arguments[1] === undefined ? /^((?!jspm_packages).)*$/ : arguments[1];
+
+ /* istanbul ignore if */
+ if (typeof System.translate !== 'function') {
+ throw new TypeError("instrumentIstanbulSystem - 'System' is not an instance of the SystemJS API.");
+ }
+
+ /* istanbul ignore if */
+ if (!(sourceFilePathRegex instanceof RegExp)) {
+ throw new TypeError("instrumentIstanbulSystem - 'sourceFilePathRegex' is not an instance of RexExp.");
+ }
+
+ // Coverage variable created by Istanbul and stored in global variables.
+ var coverageVariable = Object.keys(global).filter(function (key) {
+ return key.startsWith('$$cov_');
+ })[0];
+
+ /* istanbul ignore if */
+ if (typeof coverageVariable === 'undefined') {
+ throw new TypeError('instrumentIstanbulSystem - Istanbul coverage variable could not be located in global variables.');
+ }
+
+ // ES5 instrumenter
+ var instrumenter = _istanbulLibInstrument2.default.createInstrumenter({ coverageVariable: coverageVariable });
+
+ // ES6 / ES Modules instrumenter
+ var instrumenterESM = _istanbulLibInstrument2.default.createInstrumenter({ coverageVariable: coverageVariable, esModules: true });
+
+ // Store the original `System.translate` hook.
+ var systemTranslate = System.translate;
+
+ // Override SystemJS translate hook to instrument original sources with Istanbul.
+ System.translate = function (load) {
+ var filePath = load.address.substr(System.baseURL.length);
+
+ // Use `sourceFilePathRegex` to test file path for source instrumentation.
+ if (sourceFilePathRegex.test(filePath)) {
+ /* istanbul ignore next */
+ try {
+ // If a source file passes the ES6 / ES Module regex test then use the ESM instrumenter.
+ if (s_ESM_REGEX.test(load.source) || load.metadata.format === 'esm') {
+ load.source = instrumenterESM.instrumentSync(load.source, filePath);
+ } else {
+ load.source = instrumenter.instrumentSync(load.source, filePath);
+ }
+ } catch (err) {
+ var newErr = new Error('Unable to instrument \'' + load.name + '\' for Istanbul:\n\t' + err.message);
+ newErr.stack = 'Unable to instrument \'' + load.name + '\' for istanbul:\n\t' + err.stack;
+ newErr.originalErr = err.originalErr || err;
+ throw newErr;
+ }
+ }
+
+ // Defer to the original `System.translate` hook.
+ return systemTranslate.call(System, load);
+ };
+} \ No newline at end of file