source-map
Advanced tools
Comparing version 0.1.39 to 0.1.40
# Change Log | ||
## 0.1.40 | ||
* Performance improvements for parsing source maps in SourceMapConsumer. | ||
## 0.1.39 | ||
@@ -32,4 +36,4 @@ | ||
* Fixed a bug where consecutive newlines were ignored in `SourceNode`s. Issue | ||
#116. | ||
* Fixed a bug where consecutive newlines were ignored in `SourceNode`s. | ||
Issue #116. | ||
@@ -36,0 +40,0 @@ ## 0.1.34 |
@@ -118,5 +118,5 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
* Decodes the next base 64 VLQ value from the given string and returns the | ||
* value and the rest of the string. | ||
* value and the rest of the string via the out parameter. | ||
*/ | ||
exports.decode = function base64VLQ_decode(aStr) { | ||
exports.decode = function base64VLQ_decode(aStr, aOutParam) { | ||
var i = 0; | ||
@@ -139,8 +139,6 @@ var strLen = aStr.length; | ||
return { | ||
value: fromVLQSigned(result), | ||
rest: aStr.slice(i) | ||
}; | ||
aOutParam.value = fromVLQSigned(result); | ||
aOutParam.rest = aStr.slice(i); | ||
}; | ||
}); |
@@ -180,2 +180,8 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
SourceMapConsumer.prototype._nextCharIsMappingSeparator = | ||
function SourceMapConsumer_nextCharIsMappingSeparator(aStr) { | ||
var c = aStr.charAt(0); | ||
return c === ";" || c === ","; | ||
}; | ||
/** | ||
@@ -194,6 +200,5 @@ * Parse the mappings in a string in to a data structure which we can easily | ||
var previousName = 0; | ||
var mappingSeparator = /^[,;]/; | ||
var str = aStr; | ||
var temp = {}; | ||
var mapping; | ||
var temp; | ||
@@ -214,3 +219,3 @@ while (str.length > 0) { | ||
// Generated column. | ||
temp = base64VLQ.decode(str); | ||
base64VLQ.decode(str, temp); | ||
mapping.generatedColumn = previousGeneratedColumn + temp.value; | ||
@@ -220,9 +225,9 @@ previousGeneratedColumn = mapping.generatedColumn; | ||
if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) { | ||
if (str.length > 0 && !this._nextCharIsMappingSeparator(str)) { | ||
// Original source. | ||
temp = base64VLQ.decode(str); | ||
base64VLQ.decode(str, temp); | ||
mapping.source = this._sources.at(previousSource + temp.value); | ||
previousSource += temp.value; | ||
str = temp.rest; | ||
if (str.length === 0 || mappingSeparator.test(str.charAt(0))) { | ||
if (str.length === 0 || this._nextCharIsMappingSeparator(str)) { | ||
throw new Error('Found a source, but no line and column'); | ||
@@ -232,3 +237,3 @@ } | ||
// Original line. | ||
temp = base64VLQ.decode(str); | ||
base64VLQ.decode(str, temp); | ||
mapping.originalLine = previousOriginalLine + temp.value; | ||
@@ -239,3 +244,3 @@ previousOriginalLine = mapping.originalLine; | ||
str = temp.rest; | ||
if (str.length === 0 || mappingSeparator.test(str.charAt(0))) { | ||
if (str.length === 0 || this._nextCharIsMappingSeparator(str)) { | ||
throw new Error('Found a source and line, but no column'); | ||
@@ -245,3 +250,3 @@ } | ||
// Original column. | ||
temp = base64VLQ.decode(str); | ||
base64VLQ.decode(str, temp); | ||
mapping.originalColumn = previousOriginalColumn + temp.value; | ||
@@ -251,5 +256,5 @@ previousOriginalColumn = mapping.originalColumn; | ||
if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) { | ||
if (str.length > 0 && !this._nextCharIsMappingSeparator(str)) { | ||
// Original name. | ||
temp = base64VLQ.decode(str); | ||
base64VLQ.decode(str, temp); | ||
mapping.name = this._names.at(previousName + temp.value); | ||
@@ -256,0 +261,0 @@ previousName += temp.value; |
@@ -207,5 +207,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
mapping.originalColumn = original.column; | ||
if (original.name != null && mapping.name != null) { | ||
// Only use the identifier name if it's an identifier | ||
// in both SourceMaps | ||
if (original.name != null) { | ||
mapping.name = original.name; | ||
@@ -212,0 +210,0 @@ } |
{ | ||
"name": "source-map", | ||
"description": "Generates and consumes source maps", | ||
"version": "0.1.39", | ||
"version": "0.1.40", | ||
"homepage": "https://github.com/mozilla/source-map", | ||
@@ -6,0 +6,0 @@ "author": "Nick Fitzgerald <nfitzgerald@mozilla.com>", |
@@ -15,6 +15,5 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
exports['test normal encoding and decoding'] = function (assert, util) { | ||
var result; | ||
var result = {}; | ||
for (var i = -255; i < 256; i++) { | ||
result = base64VLQ.decode(base64VLQ.encode(i)); | ||
assert.ok(result); | ||
base64VLQ.decode(base64VLQ.encode(i), result); | ||
assert.equal(result.value, i); | ||
@@ -21,0 +20,0 @@ assert.equal(result.rest, ""); |
@@ -450,2 +450,58 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
exports['test applySourceMap name handling'] = function (assert, util) { | ||
// Imagine some CoffeeScript code being compiled into JavaScript and then | ||
// minified. | ||
var assertName = function(coffeeName, jsName, expectedName) { | ||
var minifiedMap = new SourceMapGenerator({ | ||
file: 'test.js.min' | ||
}); | ||
minifiedMap.addMapping({ | ||
generated: { line: 1, column: 4 }, | ||
original: { line: 1, column: 4 }, | ||
source: 'test.js', | ||
name: jsName | ||
}); | ||
var coffeeMap = new SourceMapGenerator({ | ||
file: 'test.js' | ||
}); | ||
coffeeMap.addMapping({ | ||
generated: { line: 1, column: 4 }, | ||
original: { line: 1, column: 0 }, | ||
source: 'test.coffee', | ||
name: coffeeName | ||
}); | ||
minifiedMap.applySourceMap(new SourceMapConsumer(coffeeMap.toJSON())); | ||
new SourceMapConsumer(minifiedMap.toJSON()).eachMapping(function(mapping) { | ||
assert.equal(mapping.name, expectedName); | ||
}); | ||
}; | ||
// `foo = 1` -> `var foo = 1;` -> `var a=1` | ||
// CoffeeScript doesn’t rename variables, so there’s no need for it to | ||
// provide names in its source maps. Minifiers do rename variables and | ||
// therefore do provide names in their source maps. So that name should be | ||
// retained if the original map lacks names. | ||
assertName(null, 'foo', 'foo'); | ||
// `foo = 1` -> `var coffee$foo = 1;` -> `var a=1` | ||
// Imagine that CoffeeScript prefixed all variables with `coffee$`. Even | ||
// though the minifier then also provides a name, the original name is | ||
// what corresponds to the source. | ||
assertName('foo', 'coffee$foo', 'foo'); | ||
// `foo = 1` -> `var coffee$foo = 1;` -> `var coffee$foo=1` | ||
// Minifiers can turn off variable mangling. Then there’s no need to | ||
// provide names in the source map, but the names from the original map are | ||
// still needed. | ||
assertName('foo', null, 'foo'); | ||
// `foo = 1` -> `var foo = 1;` -> `var foo=1` | ||
// No renaming at all. | ||
assertName(null, null, null); | ||
}; | ||
exports['test sorting with duplicate generated mappings'] = function (assert, util) { | ||
@@ -452,0 +508,0 @@ var map = new SourceMapGenerator({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
186655
4385
37