diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-12-10 21:51:33 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-12-10 21:51:33 +0100 |
commit | 0469abd4a9c9270a1fdc962969e36e63699af8b4 (patch) | |
tree | f9864d4a4148621378958794cbbfdc2393733283 /node_modules/source-map/lib | |
parent | 6947e79bbc258f7bc96af424ddb71a511f0c15a3 (diff) |
upgrade dependencies
Diffstat (limited to 'node_modules/source-map/lib')
-rw-r--r-- | node_modules/source-map/lib/array-set.js | 37 | ||||
-rw-r--r-- | node_modules/source-map/lib/source-map-generator.js | 12 | ||||
-rw-r--r-- | node_modules/source-map/lib/source-node.js | 24 |
3 files changed, 54 insertions, 19 deletions
diff --git a/node_modules/source-map/lib/array-set.js b/node_modules/source-map/lib/array-set.js index 51dffeb59..fbd5c81ca 100644 --- a/node_modules/source-map/lib/array-set.js +++ b/node_modules/source-map/lib/array-set.js @@ -7,6 +7,7 @@ var util = require('./util'); var has = Object.prototype.hasOwnProperty; +var hasNativeMap = typeof Map !== "undefined"; /** * A data structure which is a combination of an array and a set. Adding a new @@ -16,7 +17,7 @@ var has = Object.prototype.hasOwnProperty; */ function ArraySet() { this._array = []; - this._set = Object.create(null); + this._set = hasNativeMap ? new Map() : Object.create(null); } /** @@ -37,7 +38,7 @@ ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { * @returns Number */ ArraySet.prototype.size = function ArraySet_size() { - return Object.getOwnPropertyNames(this._set).length; + return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length; }; /** @@ -46,14 +47,18 @@ ArraySet.prototype.size = function ArraySet_size() { * @param String aStr */ ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { - var sStr = util.toSetString(aStr); - var isDuplicate = has.call(this._set, sStr); + var sStr = hasNativeMap ? aStr : util.toSetString(aStr); + var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr); var idx = this._array.length; if (!isDuplicate || aAllowDuplicates) { this._array.push(aStr); } if (!isDuplicate) { - this._set[sStr] = idx; + if (hasNativeMap) { + this._set.set(aStr, idx); + } else { + this._set[sStr] = idx; + } } }; @@ -63,8 +68,12 @@ ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { * @param String aStr */ ArraySet.prototype.has = function ArraySet_has(aStr) { - var sStr = util.toSetString(aStr); - return has.call(this._set, sStr); + if (hasNativeMap) { + return this._set.has(aStr); + } else { + var sStr = util.toSetString(aStr); + return has.call(this._set, sStr); + } }; /** @@ -73,10 +82,18 @@ ArraySet.prototype.has = function ArraySet_has(aStr) { * @param String aStr */ ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { - var sStr = util.toSetString(aStr); - if (has.call(this._set, sStr)) { - return this._set[sStr]; + if (hasNativeMap) { + var idx = this._set.get(aStr); + if (idx >= 0) { + return idx; + } + } else { + var sStr = util.toSetString(aStr); + if (has.call(this._set, sStr)) { + return this._set[sStr]; + } } + throw new Error('"' + aStr + '" is not in the set.'); }; diff --git a/node_modules/source-map/lib/source-map-generator.js b/node_modules/source-map/lib/source-map-generator.js index 8fbb8e8b7..aff1e7fb2 100644 --- a/node_modules/source-map/lib/source-map-generator.js +++ b/node_modules/source-map/lib/source-map-generator.js @@ -259,6 +259,18 @@ SourceMapGenerator.prototype.applySourceMap = SourceMapGenerator.prototype._validateMapping = function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, aName) { + // When aOriginal is truthy but has empty values for .line and .column, + // it is most likely a programmer error. In this case we throw a very + // specific error message to try to guide them the right way. + // For example: https://github.com/Polymer/polymer-bundler/pull/519 + if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') { + throw new Error( + 'original.line and original.column are not numbers -- you probably meant to omit ' + + 'the original mapping entirely and only map the generated position. If so, pass ' + + 'null for the original mapping instead of an object with empty or null values.' + ); + } + if (aGenerated && 'line' in aGenerated && 'column' in aGenerated && aGenerated.line > 0 && aGenerated.column >= 0 && !aOriginal && !aSource && !aName) { diff --git a/node_modules/source-map/lib/source-node.js b/node_modules/source-map/lib/source-node.js index e927f6663..d196a53f8 100644 --- a/node_modules/source-map/lib/source-node.js +++ b/node_modules/source-map/lib/source-node.js @@ -60,13 +60,19 @@ SourceNode.fromStringWithSourceMap = // All even indices of this array are one line of the generated code, // while all odd indices are the newlines between two adjacent lines // (since `REGEX_NEWLINE` captures its match). - // Processed fragments are removed from this array, by calling `shiftNextLine`. + // Processed fragments are accessed by calling `shiftNextLine`. var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); + var remainingLinesIndex = 0; var shiftNextLine = function() { - var lineContents = remainingLines.shift(); + var lineContents = getNextLine(); // The last line of a file might not have a newline. - var newLine = remainingLines.shift() || ""; + var newLine = getNextLine() || ""; return lineContents + newLine; + + function getNextLine() { + return remainingLinesIndex < remainingLines.length ? + remainingLines[remainingLinesIndex++] : undefined; + } }; // We need to remember the position of "remainingLines" @@ -91,10 +97,10 @@ SourceNode.fromStringWithSourceMap = // There is no new line in between. // Associate the code between "lastGeneratedColumn" and // "mapping.generatedColumn" with "lastMapping" - var nextLine = remainingLines[0]; + var nextLine = remainingLines[remainingLinesIndex]; var code = nextLine.substr(0, mapping.generatedColumn - lastGeneratedColumn); - remainingLines[0] = nextLine.substr(mapping.generatedColumn - + remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn - lastGeneratedColumn); lastGeneratedColumn = mapping.generatedColumn; addMappingWithCode(lastMapping, code); @@ -111,21 +117,21 @@ SourceNode.fromStringWithSourceMap = lastGeneratedLine++; } if (lastGeneratedColumn < mapping.generatedColumn) { - var nextLine = remainingLines[0]; + var nextLine = remainingLines[remainingLinesIndex]; node.add(nextLine.substr(0, mapping.generatedColumn)); - remainingLines[0] = nextLine.substr(mapping.generatedColumn); + remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn); lastGeneratedColumn = mapping.generatedColumn; } lastMapping = mapping; }, this); // We have processed all mappings. - if (remainingLines.length > 0) { + if (remainingLinesIndex < remainingLines.length) { if (lastMapping) { // Associate the remaining code in the current line with "lastMapping" addMappingWithCode(lastMapping, shiftNextLine()); } // and add the remaining lines without any mapping - node.add(remainingLines.join("")); + node.add(remainingLines.splice(remainingLinesIndex).join("")); } // Copy sourcesContent into SourceNode |