[Pkg-javascript-commits] [node-source-map] 03/08: New upstream version 0.5.7+dfsg

Julien Puydt julien.puydt at laposte.net
Wed Aug 23 11:01:04 UTC 2017


This is an automated email from the git hooks/post-receive script.

jpuydt-guest pushed a commit to branch master
in repository node-source-map.

commit d41f8c86122534002d18fade0a86e8d339b3d707
Author: Julien Puydt <julien.puydt at laposte.net>
Date:   Wed Aug 23 11:17:46 2017 +0200

    New upstream version 0.5.7+dfsg
---
 .travis.yml                 | 15 ++++++-
 README.md                   |  4 +-
 lib/array-set.js            | 37 ++++++++++++-----
 lib/source-map-generator.js | 12 ++++++
 lib/source-node.js          | 24 ++++++-----
 package.json                |  5 ++-
 source-map.d.ts             | 98 +++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 171 insertions(+), 24 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 7eac34b..37036e7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,18 @@
 language: node_js
+
 sudo: false
+
 node_js:
   - "0.10"
-  - 0.12
+  - "0.12"
+  - "4"
+  - "5"
+  - "6"
+
+cache:
+  directories:
+    - node_modules
+
+os:
+  - linux
+  - osx
diff --git a/README.md b/README.md
index 99d3861..3281339 100644
--- a/README.md
+++ b/README.md
@@ -266,7 +266,7 @@ and an object is returned with the following properties:
 * `line`: The line number in the original source, or null if this information is
   not available.
 
-* `column`: The column number in the original source, or null or null if this
+* `column`: The column number in the original source, or null if this
   information is not available.
 
 * `name`: The original identifier, or null if this information is not available.
@@ -566,7 +566,7 @@ Creates a SourceNode from generated code and a SourceMapConsumer.
   should be relative to.
 
 ```js
-var consumer = new SourceMapConsumer(fs.readFileSync("path/to/my-file.js.map"));
+var consumer = new SourceMapConsumer(fs.readFileSync("path/to/my-file.js.map", "utf8"));
 var node = SourceNode.fromStringWithSourceMap(fs.readFileSync("path/to/my-file.js"),
                                               consumer);
 ```
diff --git a/lib/array-set.js b/lib/array-set.js
index 51dffeb..fbd5c81 100644
--- a/lib/array-set.js
+++ b/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/lib/source-map-generator.js b/lib/source-map-generator.js
index 8fbb8e8..aff1e7f 100644
--- a/lib/source-map-generator.js
+++ b/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/lib/source-node.js b/lib/source-node.js
index e927f66..d196a53 100644
--- a/lib/source-node.js
+++ b/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
diff --git a/package.json b/package.json
index 5f793ff..048e3ae 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
   "name": "source-map",
   "description": "Generates and consumes source maps",
-  "version": "0.5.6",
+  "version": "0.5.7",
   "homepage": "https://github.com/mozilla/source-map",
   "author": "Nick Fitzgerald <nfitzgerald at mozilla.com>",
   "contributors": [
@@ -67,5 +67,6 @@
   "devDependencies": {
     "doctoc": "^0.15.0",
     "webpack": "^1.12.0"
-  }
+  },
+  "typings": "source-map"
 }
diff --git a/source-map.d.ts b/source-map.d.ts
new file mode 100644
index 0000000..8f972b0
--- /dev/null
+++ b/source-map.d.ts
@@ -0,0 +1,98 @@
+export interface StartOfSourceMap {
+    file?: string;
+    sourceRoot?: string;
+}
+
+export interface RawSourceMap extends StartOfSourceMap {
+    version: string;
+    sources: string[];
+    names: string[];
+    sourcesContent?: string[];
+    mappings: string;
+}
+
+export interface Position {
+    line: number;
+    column: number;
+}
+
+export interface LineRange extends Position {
+    lastColumn: number;
+}
+
+export interface FindPosition extends Position {
+    // SourceMapConsumer.GREATEST_LOWER_BOUND or SourceMapConsumer.LEAST_UPPER_BOUND
+    bias?: number;
+}
+
+export interface SourceFindPosition extends FindPosition {
+    source: string;
+}
+
+export interface MappedPosition extends Position {
+    source: string;
+    name?: string;
+}
+
+export interface MappingItem {
+    source: string;
+    generatedLine: number;
+    generatedColumn: number;
+    originalLine: number;
+    originalColumn: number;
+    name: string;
+}
+
+export class SourceMapConsumer {
+    static GENERATED_ORDER: number;
+    static ORIGINAL_ORDER: number;
+
+    static GREATEST_LOWER_BOUND: number;
+    static LEAST_UPPER_BOUND: number;
+
+    constructor(rawSourceMap: RawSourceMap);
+    computeColumnSpans(): void;
+    originalPositionFor(generatedPosition: FindPosition): MappedPosition;
+    generatedPositionFor(originalPosition: SourceFindPosition): LineRange;
+    allGeneratedPositionsFor(originalPosition: MappedPosition): Position[];
+    hasContentsOfAllSources(): boolean;
+    sourceContentFor(source: string, returnNullOnMissing?: boolean): string;
+    eachMapping(callback: (mapping: MappingItem) => void, context?: any, order?: number): void;
+}
+
+export interface Mapping {
+    generated: Position;
+    original: Position;
+    source: string;
+    name?: string;
+}
+
+export class SourceMapGenerator {
+    constructor(startOfSourceMap?: StartOfSourceMap);
+    static fromSourceMap(sourceMapConsumer: SourceMapConsumer): SourceMapGenerator;
+    addMapping(mapping: Mapping): void;
+    setSourceContent(sourceFile: string, sourceContent: string): void;
+    applySourceMap(sourceMapConsumer: SourceMapConsumer, sourceFile?: string, sourceMapPath?: string): void;
+    toString(): string;
+}
+
+export interface CodeWithSourceMap {
+    code: string;
+    map: SourceMapGenerator;
+}
+
+export class SourceNode {
+    constructor();
+    constructor(line: number, column: number, source: string);
+    constructor(line: number, column: number, source: string, chunk?: string, name?: string);
+    static fromStringWithSourceMap(code: string, sourceMapConsumer: SourceMapConsumer, relativePath?: string): SourceNode;
+    add(chunk: string): void;
+    prepend(chunk: string): void;
+    setSourceContent(sourceFile: string, sourceContent: string): void;
+    walk(fn: (chunk: string, mapping: MappedPosition) => void): void;
+    walkSourceContents(fn: (file: string, content: string) => void): void;
+    join(sep: string): SourceNode;
+    replaceRight(pattern: string, replacement: string): SourceNode;
+    toString(): string;
+    toStringWithSourceMap(startOfSourceMap?: StartOfSourceMap): CodeWithSourceMap;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-source-map.git



More information about the Pkg-javascript-commits mailing list