aboutsummaryrefslogtreecommitdiff
path: root/node_modules/istanbul-lib-source-maps/lib
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/istanbul-lib-source-maps/lib')
-rw-r--r--node_modules/istanbul-lib-source-maps/lib/map-store.js160
-rw-r--r--node_modules/istanbul-lib-source-maps/lib/mapped.js120
-rw-r--r--node_modules/istanbul-lib-source-maps/lib/pathutils.js17
-rw-r--r--node_modules/istanbul-lib-source-maps/lib/source-store.js80
-rw-r--r--node_modules/istanbul-lib-source-maps/lib/transformer.js181
5 files changed, 0 insertions, 558 deletions
diff --git a/node_modules/istanbul-lib-source-maps/lib/map-store.js b/node_modules/istanbul-lib-source-maps/lib/map-store.js
deleted file mode 100644
index 8b31d4229..000000000
--- a/node_modules/istanbul-lib-source-maps/lib/map-store.js
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- Copyright 2015, Yahoo Inc.
- Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
- */
-"use strict";
-
-var debug = require('debug')('istanbuljs'),
- path = require('path'),
- fs = require('fs'),
- pathutils = require('./pathutils'),
- sourceStore = require('./source-store'),
- transformer = require('./transformer'),
- SMC = require('source-map').SourceMapConsumer;
-
-/**
- * tracks source maps for registered files
- * @param {Object} opts [opts=undefined] options.
- * @param {Boolean} opts.verbose [opts.verbose=false] verbose mode
- * @param {String} opts.baseDir [opts.baseDir=null] alternate base directory
- * to resolve sourcemap files
- * @param {String} opts.sourceStore [opts.sourceStore='memory'] - store that tracks
- * embedded sources found in source maps, one of 'memory' or 'file'
- * @param {String} opts.tmpdir [opts.tmpdir=undefined] - temporary directory
- * to use for storing files.
- * @constructor
- */
-function MapStore(opts) {
- opts = opts || {};
- this.baseDir = opts.baseDir || null;
- this.verbose = opts.verbose || false;
- this.sourceStore = sourceStore.create(opts.sourceStore, { tmpdir: opts.tmpdir});
- this.data = {};
-}
-/**
- * registers a source map URL with this store. It makes some input sanity checks
- * and silently fails on malformed input.
- * @param transformedFilePath - the file path for which the source map is valid.
- * This must *exactly* match the path stashed for the coverage object to be
- * useful.
- * @param sourceMapUrl - the source map URL, **not** a comment
- */
-MapStore.prototype.registerURL = function (transformedFilePath, sourceMapUrl) {
- var d = 'data:',
- b64 = 'base64,',
- pos;
-
- if (sourceMapUrl.length > d.length && sourceMapUrl.substring(0, d.length) === d) {
- pos = sourceMapUrl.indexOf(b64);
- if (pos > 0) {
- this.data[transformedFilePath] = {
- type: 'encoded',
- data: sourceMapUrl.substring(pos + b64.length)
- };
- } else {
- debug('Unable to interpret source map URL: ' + sourceMapUrl);
- }
- return;
- }
- var dir = path.dirname(path.resolve(transformedFilePath)),
- file = path.resolve(dir, sourceMapUrl);
- this.data[transformedFilePath] = { type: 'file', data: file };
-};
-/**
- * registers a source map object with this store. Makes some basic sanity checks
- * and silently fails on malformed input.
- * @param transformedFilePath - the file path for which the source map is valid
- * @param sourceMap - the source map object
- */
-MapStore.prototype.registerMap = function (transformedFilePath, sourceMap) {
- if (sourceMap && sourceMap.version) {
- this.data[transformedFilePath] = { type: 'object', data: sourceMap };
- } else {
- debug('Invalid source map object:' + JSON.stringify(sourceMap, null, 2));
- }
-};
-/**
- * transforms the coverage map provided into one that refers to original
- * sources when valid mappings have been registered with this store.
- * @param {CoverageMap} coverageMap - the coverage map to transform
- * @returns {Object} an object with 2 properties. `map` for the transformed
- * coverage map and `sourceFinder` which is a function to return the source
- * text for a file.
- */
-MapStore.prototype.transformCoverage = function (coverageMap) {
- var that = this,
- mappedCoverage,
- sourceFinder;
-
- sourceFinder = function (filePath) {
- var content = that.sourceStore.getSource(filePath);
- if (content !== null) {
- return content;
- }
- if (pathutils.isAbsolute(filePath)) {
- return fs.readFileSync(filePath, 'utf8');
- }
- return fs.readFileSync(pathutils.asAbsolute(filePath, that.baseDir));
- };
-
- coverageMap.files().forEach(function (file) {
- var coverage = coverageMap.fileCoverageFor(file);
- if (coverage.data.inputSourceMap && !that.data[file]) {
- that.registerMap(file, coverage.data.inputSourceMap);
- }
- });
-
- if (Object.keys(this.data).length === 0) {
- return {
- map: coverageMap,
- sourceFinder: sourceFinder
- };
- }
- mappedCoverage = transformer.create(function (filePath) {
- try {
- if (!that.data[filePath]) {
- return null;
- }
- var d = that.data[filePath],
- obj,
- smc;
-
- if (d.type === 'file') {
- obj = JSON.parse(fs.readFileSync(d.data, 'utf8'));
- } else if (d.type === 'encoded') {
- obj = JSON.parse(new Buffer(d.data, 'base64').toString());
- } else {
- obj = d.data;
- }
- smc = new SMC(obj);
- smc.sources.forEach(function (s) {
- var content = smc.sourceContentFor(s),
- sourceFilePath = pathutils.relativeTo(s, filePath);
- if (content) {
- that.sourceStore.registerSource(sourceFilePath, content);
- }
- });
- return smc;
- } catch (ex) {
- debug('Error returning source map for ' + filePath);
- debug(ex.stack);
- return null;
- }
- }).transform(coverageMap);
-
- return {
- map: mappedCoverage,
- sourceFinder: sourceFinder
- };
-};
-
-/**
- * disposes temporary resources allocated by this map store
- */
-MapStore.prototype.dispose = function () {
- this.sourceStore.dispose();
-};
-
-module.exports = {
- MapStore: MapStore
-};
diff --git a/node_modules/istanbul-lib-source-maps/lib/mapped.js b/node_modules/istanbul-lib-source-maps/lib/mapped.js
deleted file mode 100644
index fac8d7d5f..000000000
--- a/node_modules/istanbul-lib-source-maps/lib/mapped.js
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- Copyright 2015, Yahoo Inc.
- Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
- */
-"use strict";
-
-var FileCoverage = require('istanbul-lib-coverage').classes.FileCoverage,
- util = require('util');
-
-function MappedCoverage(pathOrObj) {
- FileCoverage.call(this, pathOrObj);
- this.meta = {
- last: {
- s: 0,
- f: 0,
- b: 0
- },
- seen: {}
- };
-}
-
-util.inherits(MappedCoverage, FileCoverage);
-
-function locString(loc) {
- return [loc.start.line, loc.start.column, loc.end.line, loc.end.column].join(':');
-}
-
-MappedCoverage.prototype.addStatement = function (loc, hits) {
- var key = 's:' + locString(loc),
- meta = this.meta,
- index = meta.seen[key];
-
- if (index === undefined) {
- index = meta.last.s;
- meta.last.s += 1;
- meta.seen[key] = index;
- this.statementMap[index] = this.cloneLocation(loc);
- }
- this.s[index] = this.s[index] || 0;
- this.s[index] += hits;
- return index;
-};
-
-MappedCoverage.prototype.addFunction = function (name, decl, loc, hits) {
- var key = 'f:' + locString(decl),
- meta = this.meta,
- index = meta.seen[key];
-
- if (index === undefined) {
- index = meta.last.f;
- meta.last.f += 1;
- meta.seen[key] = index;
- name = name || '(unknown_' + index + ')';
- this.fnMap[index] = {
- name: name,
- decl: this.cloneLocation(decl),
- loc: this.cloneLocation(loc)
- };
- }
- this.f[index] = this.f[index] || 0;
- this.f[index] += hits;
- return index;
-};
-
-MappedCoverage.prototype.addBranch = function (type, loc, branchLocations, hits) {
- var key = ['b'],
- meta = this.meta,
- that = this,
- index,
- i;
-
- branchLocations.forEach(function (l) {
- key.push(locString(l));
- });
-
- key = key.join(':');
- index = meta.seen[key];
- if (index === undefined) {
- index = meta.last.b;
- meta.last.b += 1;
- meta.seen[key] = index;
- this.branchMap[index] = {
- loc: loc,
- type: type,
- locations: branchLocations.map(function (l) {
- return that.cloneLocation(l);
- })
- };
- }
-
- if (!this.b[index]) {
- this.b[index] = [];
- branchLocations.forEach(function () {
- that.b[index].push(0);
- });
- }
- for (i = 0; i < hits.length; i += 1) {
- that.b[index][i] += hits[i];
- }
- return index;
-};
-
-// returns a clone of the location object with only
-// the attributes of interest
-MappedCoverage.prototype.cloneLocation = function (loc) {
- return {
- start: {
- line: loc.start.line,
- column: loc.start.column
- },
- end: {
- line: loc.end.line,
- column: loc.end.column
- }
- };
-};
-
-module.exports = {
- MappedCoverage: MappedCoverage
-};
diff --git a/node_modules/istanbul-lib-source-maps/lib/pathutils.js b/node_modules/istanbul-lib-source-maps/lib/pathutils.js
deleted file mode 100644
index c72eb6ecf..000000000
--- a/node_modules/istanbul-lib-source-maps/lib/pathutils.js
+++ /dev/null
@@ -1,17 +0,0 @@
-var path = require('path'),
- isAbsolute = function (p) {
- if (path.isAbsolute) {
- return path.isAbsolute(p);
- }
- return path.resolve(p) === path.normalize(p);
- };
-
-exports.isAbsolute = isAbsolute;
-
-exports.asAbsolute = function (file, baseDir) {
- return isAbsolute(file) ? file : path.resolve(baseDir || process.cwd, file);
-};
-
-exports.relativeTo = function (file, origFile) {
- return isAbsolute(file) ? file : path.resolve(path.dirname(origFile), file);
-};
diff --git a/node_modules/istanbul-lib-source-maps/lib/source-store.js b/node_modules/istanbul-lib-source-maps/lib/source-store.js
deleted file mode 100644
index cb84e9ec8..000000000
--- a/node_modules/istanbul-lib-source-maps/lib/source-store.js
+++ /dev/null
@@ -1,80 +0,0 @@
-var util = require('util'),
- os = require('os'),
- path = require('path'),
- mkdirp = require('mkdirp'),
- rimraf = require('rimraf'),
- fs = require('fs');
-
-function SourceStore(/*opts*/) {
-}
-
-SourceStore.prototype.registerSource = function (/* filePath, sourceText */) {
- throw new Error('registerSource must be overridden');
-};
-
-SourceStore.prototype.getSource = function (/* filePath */) {
- throw new Error('getSource must be overridden');
-};
-
-SourceStore.prototype.dispose = function () {
-};
-
-function MemoryStore() {
- this.data = {};
-}
-
-util.inherits(MemoryStore, SourceStore);
-
-MemoryStore.prototype.registerSource = function (filePath, sourceText) {
- this.data[filePath] = sourceText;
-};
-
-MemoryStore.prototype.getSource = function (filePath) {
- return this.data[filePath] || null;
-};
-
-function FileStore(opts) {
- opts = opts || {};
- var tmpDir = opts.tmpdir || os.tmpdir();
- this.counter = 0;
- this.mappings = [];
- this.basePath = path.resolve(tmpDir, '.istanbul', 'cache_');
- mkdirp.sync(path.dirname(this.basePath));
-}
-
-util.inherits(FileStore, SourceStore);
-
-FileStore.prototype.registerSource = function (filePath, sourceText) {
- if (this.mappings[filePath]) {
- return;
- }
- this.counter += 1;
- var mapFile = this.basePath + this.counter;
- this.mappings[filePath] = mapFile;
- fs.writeFileSync(mapFile, sourceText, 'utf8');
-};
-
-FileStore.prototype.getSource = function (filePath) {
- var mapFile = this.mappings[filePath];
- if (!mapFile) {
- return null;
- }
- return fs.readFileSync(mapFile, 'utf8');
-};
-
-FileStore.prototype.dispose = function () {
- this.mappings = [];
- rimraf.sync(path.dirname(this.basePath));
-};
-
-module.exports = {
- create: function (type, opts) {
- opts = opts || {};
- type = (type || 'memory').toLowerCase();
-
- if (type === 'file') {
- return new FileStore(opts);
- }
- return new MemoryStore(opts);
- }
-};
diff --git a/node_modules/istanbul-lib-source-maps/lib/transformer.js b/node_modules/istanbul-lib-source-maps/lib/transformer.js
deleted file mode 100644
index 748805949..000000000
--- a/node_modules/istanbul-lib-source-maps/lib/transformer.js
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- Copyright 2015, Yahoo Inc.
- Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
- */
-"use strict";
-
-var debug = require('debug')('istanbuljs'),
- pathutils = require('./pathutils'),
- libCoverage = require('istanbul-lib-coverage'),
- MappedCoverage = require('./mapped').MappedCoverage;
-
-function isInvalidPosition (pos) {
- return !pos || typeof pos.line !== "number" || typeof pos.column !== "number" || pos.line < 0 || pos.column < 0;
-}
-
-/**
- * determines the original position for a given location
- * @param {SourceMapConsumer} sourceMap the source map
- * @param {Object} location the original location Object
- * @returns {Object} the remapped location Object
- */
-function getMapping(sourceMap, location, origFile) {
-
- if (!location) {
- return null;
- }
-
- if (isInvalidPosition(location.start) || isInvalidPosition(location.end)) {
- return null;
- }
-
- var start = sourceMap.originalPositionFor(location.start),
- end = sourceMap.originalPositionFor(location.end);
-
- /* istanbul ignore if: edge case too hard to test for */
- if (!(start && end)) {
- return null;
- }
- if (!(start.source && end.source)) {
- return null;
- }
- if (start.source !== end.source) {
- return null;
- }
-
- /* istanbul ignore if: edge case too hard to test for */
- if (start.line === null || start.column === null) {
- return null;
- }
- /* istanbul ignore if: edge case too hard to test for */
- if (end.line === null || end.column === null) {
- return null;
- }
-
- if (start.line === end.line && start.column === end.column) {
- end = sourceMap.originalPositionFor({
- line: location.end.line,
- column: location.end.column,
- bias: 2
- });
- end.column = end.column - 1;
- }
-
- return {
- source: pathutils.relativeTo(start.source, origFile),
- loc: {
- start: {
- line: start.line,
- column: start.column
- },
- end: {
- line: end.line,
- column: end.column
- }
- }
- };
-}
-
-function SourceMapTransformer(finder, opts) {
- opts = opts || {};
- this.finder = finder;
- this.baseDir = opts.baseDir || process.cwd();
-}
-
-SourceMapTransformer.prototype.processFile = function (fc, sourceMap, coverageMapper) {
- var changes = 0;
-
- Object.keys(fc.statementMap).forEach(function (s) {
- var loc = fc.statementMap[s],
- hits = fc.s[s],
- mapping = getMapping(sourceMap, loc, fc.path),
- mappedCoverage;
-
- if (mapping) {
- changes += 1;
- mappedCoverage = coverageMapper(mapping.source);
- mappedCoverage.addStatement(mapping.loc, hits);
- }
- });
-
- Object.keys(fc.fnMap).forEach(function (f) {
- var fnMeta = fc.fnMap[f],
- hits = fc.f[f],
- mapping = getMapping(sourceMap, fnMeta.decl, fc.path),
- spanMapping = getMapping(sourceMap, fnMeta.loc, fc.path),
- mappedCoverage;
-
- if (mapping && spanMapping && mapping.source === spanMapping.source) {
- changes += 1;
- mappedCoverage = coverageMapper(mapping.source);
- mappedCoverage.addFunction(fnMeta.name, mapping.loc, spanMapping.loc, hits);
- }
- });
-
- Object.keys(fc.branchMap).forEach(function (b) {
- var branchMeta = fc.branchMap[b],
- source,
- hits = fc.b[b],
- mapping,
- locs = [],
- mappedHits = [],
- mappedCoverage,
- skip,
- i;
- for (i = 0; i < branchMeta.locations.length; i += 1) {
- mapping = getMapping(sourceMap, branchMeta.locations[i], fc.path);
- if (mapping) {
- if (!source) {
- source = mapping.source;
- }
- if (mapping.source !== source) {
- skip = true;
- }
- locs.push(mapping.loc);
- mappedHits.push(hits[i]);
- }
- }
- if (!skip && locs.length > 0) {
- changes += 1;
- mappedCoverage = coverageMapper(source);
- mappedCoverage.addBranch(branchMeta.type, locs[0] /* XXX */, locs, mappedHits);
- }
- });
-
- return changes > 0;
-};
-
-SourceMapTransformer.prototype.transform = function (coverageMap) {
- var that = this,
- finder = this.finder,
- output = {},
- getMappedCoverage = function (file) {
- if (!output[file]) {
- output[file] = new MappedCoverage(file);
- }
- return output[file];
- };
-
- coverageMap.files().forEach(function (file) {
- var fc = coverageMap.fileCoverageFor(file),
- sourceMap = finder(file),
- changed;
-
- if (!sourceMap) {
- output[file] = fc;
- return;
- }
-
- changed = that.processFile(fc, sourceMap, getMappedCoverage);
- if (!changed) {
- debug('File [' + file + '] ignored, nothing could be mapped');
- }
- });
- return libCoverage.createCoverageMap(output);
-};
-
-module.exports = {
- create: function (finder, opts) {
- return new SourceMapTransformer(finder, opts);
- }
-};