source-map
Advanced tools
Comparing version 0.1.32 to 0.1.33
# Change Log | ||
## 0.1.33 | ||
* Fix some edge cases surrounding path joining and URL resolution. | ||
* Add a third parameter for relative path to | ||
`SourceMapGenerator.prototype.applySourceMap`. | ||
* Fix issues with mappings and EOLs. | ||
## 0.1.32 | ||
@@ -4,0 +13,0 @@ |
@@ -32,3 +32,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
* - mappings: A string of base64 VLQs which contain the actual mappings. | ||
* - file: The generated file this source map is associated with. | ||
* - file: Optional. The generated file this source map is associated with. | ||
* | ||
@@ -317,3 +317,3 @@ * Here is an example source map, taken from the source map spec[0]: | ||
if (mapping) { | ||
if (mapping && mapping.generatedLine === needle.generatedLine) { | ||
var source = util.getArg(mapping, 'source', null); | ||
@@ -320,0 +320,0 @@ if (source && this.sourceRoot) { |
@@ -18,10 +18,13 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
* An instance of the SourceMapGenerator represents a source map which is | ||
* being built incrementally. To create a new one, you must pass an object | ||
* with the following properties: | ||
* being built incrementally. You may pass an object with the following | ||
* properties: | ||
* | ||
* - file: The filename of the generated source. | ||
* - sourceRoot: An optional root for all URLs in this source map. | ||
* - sourceRoot: A root for all relative URLs in this source map. | ||
*/ | ||
function SourceMapGenerator(aArgs) { | ||
this._file = util.getArg(aArgs, 'file'); | ||
if (!aArgs) { | ||
aArgs = {}; | ||
} | ||
this._file = util.getArg(aArgs, 'file', null); | ||
this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); | ||
@@ -156,7 +159,19 @@ this._sources = new ArraySet(); | ||
* If omitted, SourceMapConsumer's file property will be used. | ||
* @param aSourceMapPath Optional. The dirname of the path to the source map | ||
* to be applied. If relative, it is relative to the SourceMapConsumer. | ||
* This parameter is needed when the two source maps aren't in the same | ||
* directory, and the source map to be applied contains relative source | ||
* paths. If so, those relative source paths need to be rewritten | ||
* relative to the SourceMapGenerator. | ||
*/ | ||
SourceMapGenerator.prototype.applySourceMap = | ||
function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile) { | ||
function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { | ||
// If aSourceFile is omitted, we will use the file property of the SourceMap | ||
if (!aSourceFile) { | ||
if (!aSourceMapConsumer.file) { | ||
throw new Error( | ||
'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + | ||
'or the source map\'s "file" property. Both were omitted.' | ||
); | ||
} | ||
aSourceFile = aSourceMapConsumer.file; | ||
@@ -184,6 +199,8 @@ } | ||
// Copy mapping | ||
mapping.source = original.source; | ||
if (aSourceMapPath) { | ||
mapping.source = util.join(aSourceMapPath, mapping.source) | ||
} | ||
if (sourceRoot) { | ||
mapping.source = util.relative(sourceRoot, original.source); | ||
} else { | ||
mapping.source = original.source; | ||
mapping.source = util.relative(sourceRoot, mapping.source); | ||
} | ||
@@ -190,0 +207,0 @@ mapping.originalLine = original.line; |
@@ -62,17 +62,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
aSourceMapConsumer.eachMapping(function (mapping) { | ||
if (lastMapping === null) { | ||
// We add the generated code until the first mapping | ||
// to the SourceNode without any mapping. | ||
// Each line is added as separate string. | ||
while (lastGeneratedLine < mapping.generatedLine) { | ||
node.add(remainingLines.shift() + "\n"); | ||
lastGeneratedLine++; | ||
} | ||
if (lastGeneratedColumn < mapping.generatedColumn) { | ||
var nextLine = remainingLines[0]; | ||
node.add(nextLine.substr(0, mapping.generatedColumn)); | ||
remainingLines[0] = nextLine.substr(mapping.generatedColumn); | ||
lastGeneratedColumn = mapping.generatedColumn; | ||
} | ||
} else { | ||
if (lastMapping !== null) { | ||
// We add the code from "lastMapping" to "mapping": | ||
@@ -82,18 +68,7 @@ // First check if there is a new line in between. | ||
var code = ""; | ||
// Associate full lines with "lastMapping" | ||
do { | ||
code += remainingLines.shift() + "\n"; | ||
lastGeneratedLine++; | ||
lastGeneratedColumn = 0; | ||
} while (lastGeneratedLine < mapping.generatedLine); | ||
// When we reached the correct line, we add code until we | ||
// reach the correct column too. | ||
if (lastGeneratedColumn < mapping.generatedColumn) { | ||
var nextLine = remainingLines[0]; | ||
code += nextLine.substr(0, mapping.generatedColumn); | ||
remainingLines[0] = nextLine.substr(mapping.generatedColumn); | ||
lastGeneratedColumn = mapping.generatedColumn; | ||
} | ||
// Create the SourceNode. | ||
addMappingWithCode(lastMapping, code); | ||
// Associate first line with "lastMapping" | ||
addMappingWithCode(lastMapping, remainingLines.shift() + "\n"); | ||
lastGeneratedLine++; | ||
lastGeneratedColumn = 0; | ||
// The remaining code is added without mapping | ||
} else { | ||
@@ -110,10 +85,33 @@ // There is no new line in between. | ||
addMappingWithCode(lastMapping, code); | ||
// No more remaining code, continue | ||
lastMapping = mapping; | ||
return; | ||
} | ||
} | ||
// We add the generated code until the first mapping | ||
// to the SourceNode without any mapping. | ||
// Each line is added as separate string. | ||
while (lastGeneratedLine < mapping.generatedLine) { | ||
node.add(remainingLines.shift() + "\n"); | ||
lastGeneratedLine++; | ||
} | ||
if (lastGeneratedColumn < mapping.generatedColumn) { | ||
var nextLine = remainingLines[0]; | ||
node.add(nextLine.substr(0, mapping.generatedColumn)); | ||
remainingLines[0] = nextLine.substr(mapping.generatedColumn); | ||
lastGeneratedColumn = mapping.generatedColumn; | ||
} | ||
lastMapping = mapping; | ||
}, this); | ||
// We have processed all mappings. | ||
// Associate the remaining code in the current line with "lastMapping" | ||
// and add the remaining lines without any mapping | ||
addMappingWithCode(lastMapping, remainingLines.join("\n")); | ||
if (remainingLines.length > 0) { | ||
if (lastMapping) { | ||
// Associate the remaining code in the current line with "lastMapping" | ||
var lastLine = remainingLines.shift(); | ||
if (remainingLines.length > 0) lastLine += "\n"; | ||
addMappingWithCode(lastMapping, lastLine); | ||
} | ||
// and add the remaining lines without any mapping | ||
node.add(remainingLines.join("\n")); | ||
} | ||
@@ -356,6 +354,24 @@ // Copy sourcesContent into SourceNode | ||
} | ||
chunk.split('').forEach(function (ch) { | ||
chunk.split('').forEach(function (ch, idx, array) { | ||
if (ch === '\n') { | ||
generated.line++; | ||
generated.column = 0; | ||
// Mappings end at eol | ||
if (idx + 1 === array.length) { | ||
lastOriginalSource = null; | ||
sourceMappingActive = false; | ||
} else if (sourceMappingActive) { | ||
map.addMapping({ | ||
source: original.source, | ||
original: { | ||
line: original.line, | ||
column: original.column | ||
}, | ||
generated: { | ||
line: generated.line, | ||
column: generated.column | ||
}, | ||
name: original.name | ||
}); | ||
} | ||
} else { | ||
@@ -362,0 +378,0 @@ generated.column++; |
@@ -33,4 +33,4 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
var urlRegexp = /([\w+\-.]+):\/\/((\w+:\w+)@)?([\w.]+)?(:(\d+))?(\S+)?/; | ||
var dataUrlRegexp = /^data:.+\,.+/; | ||
var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/; | ||
var dataUrlRegexp = /^data:.+\,.+$/; | ||
@@ -44,6 +44,6 @@ function urlParse(aUrl) { | ||
scheme: match[1], | ||
auth: match[3], | ||
host: match[4], | ||
port: match[6], | ||
path: match[7] | ||
auth: match[2], | ||
host: match[3], | ||
port: match[4], | ||
path: match[5] | ||
}; | ||
@@ -54,5 +54,9 @@ } | ||
function urlGenerate(aParsedUrl) { | ||
var url = aParsedUrl.scheme + "://"; | ||
var url = ''; | ||
if (aParsedUrl.scheme) { | ||
url += aParsedUrl.scheme + ':'; | ||
} | ||
url += '//'; | ||
if (aParsedUrl.auth) { | ||
url += aParsedUrl.auth + "@" | ||
url += aParsedUrl.auth + '@'; | ||
} | ||
@@ -72,15 +76,108 @@ if (aParsedUrl.host) { | ||
/** | ||
* Normalizes a path, or the path portion of a URL: | ||
* | ||
* - Replaces consequtive slashes with one slash. | ||
* - Removes unnecessary '.' parts. | ||
* - Removes unnecessary '<dir>/..' parts. | ||
* | ||
* Based on code in the Node.js 'path' core module. | ||
* | ||
* @param aPath The path or url to normalize. | ||
*/ | ||
function normalize(aPath) { | ||
var path = aPath; | ||
var url = urlParse(aPath); | ||
if (url) { | ||
if (!url.path) { | ||
return aPath; | ||
} | ||
path = url.path; | ||
} | ||
var isAbsolute = (path.charAt(0) === '/'); | ||
var parts = path.split(/\/+/); | ||
for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { | ||
part = parts[i]; | ||
if (part === '.') { | ||
parts.splice(i, 1); | ||
} else if (part === '..') { | ||
up++; | ||
} else if (up > 0) { | ||
if (part === '') { | ||
// The first part is blank if the path is absolute. Trying to go | ||
// above the root is a no-op. Therefore we can remove all '..' parts | ||
// directly after the root. | ||
parts.splice(i + 1, up); | ||
up = 0; | ||
} else { | ||
parts.splice(i, 2); | ||
up--; | ||
} | ||
} | ||
} | ||
path = parts.join('/'); | ||
if (path === '') { | ||
path = isAbsolute ? '/' : '.'; | ||
} | ||
if (url) { | ||
url.path = path; | ||
return urlGenerate(url); | ||
} | ||
return path; | ||
} | ||
exports.normalize = normalize; | ||
/** | ||
* Joins two paths/URLs. | ||
* | ||
* @param aRoot The root path or URL. | ||
* @param aPath The path or URL to be joined with the root. | ||
* | ||
* - If aPath is a URL or a data URI, aPath is returned, unless aPath is a | ||
* scheme-relative URL: Then the scheme of aRoot, if any, is prepended | ||
* first. | ||
* - Otherwise aPath is a path. If aRoot is a URL, then its path portion | ||
* is updated with the result and aRoot is returned. Otherwise the result | ||
* is returned. | ||
* - If aPath is absolute, the result is aPath. | ||
* - Otherwise the two paths are joined with a slash. | ||
* - Joining for example 'http://' and 'www.example.com' is also supported. | ||
*/ | ||
function join(aRoot, aPath) { | ||
var url; | ||
var aPathUrl = urlParse(aPath); | ||
var aRootUrl = urlParse(aRoot); | ||
if (aRootUrl) { | ||
aRoot = aRootUrl.path || '/'; | ||
} | ||
if (aPath.match(urlRegexp) || aPath.match(dataUrlRegexp)) { | ||
// `join(foo, '//www.example.org')` | ||
if (aPathUrl && !aPathUrl.scheme) { | ||
if (aRootUrl) { | ||
aPathUrl.scheme = aRootUrl.scheme; | ||
} | ||
return urlGenerate(aPathUrl); | ||
} | ||
if (aPathUrl || aPath.match(dataUrlRegexp)) { | ||
return aPath; | ||
} | ||
if (aPath.charAt(0) === '/' && (url = urlParse(aRoot))) { | ||
url.path = aPath; | ||
return urlGenerate(url); | ||
// `join('http://', 'www.example.com')` | ||
if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { | ||
aRootUrl.host = aPath; | ||
return urlGenerate(aRootUrl); | ||
} | ||
return aRoot.replace(/\/$/, '') + '/' + aPath; | ||
var joined = aPath.charAt(0) === '/' | ||
? aPath | ||
: normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); | ||
if (aRootUrl) { | ||
aRootUrl.path = joined; | ||
return urlGenerate(aRootUrl); | ||
} | ||
return joined; | ||
} | ||
@@ -87,0 +184,0 @@ exports.join = join; |
{ | ||
"name": "source-map", | ||
"description": "Generates and consumes source maps", | ||
"version": "0.1.32", | ||
"version": "0.1.33", | ||
"homepage": "https://github.com/mozilla/source-map", | ||
@@ -25,3 +25,5 @@ "author": "Nick Fitzgerald <nfitzgerald@mozilla.com>", | ||
"Hugh Kennedy <hughskennedy@gmail.com>", | ||
"David Glasser <glasser@davidglasser.net>" | ||
"David Glasser <glasser@davidglasser.net>", | ||
"Simon Lydell <simon.lydell@gmail.com>", | ||
"Jmeas Smith <jellyes2@gmail.com>" | ||
], | ||
@@ -28,0 +30,0 @@ "repository": { |
@@ -176,3 +176,3 @@ # Source Map | ||
* `file`: The generated filename this source map is associated with. | ||
* `file`: Optional. The generated filename this source map is associated with. | ||
@@ -248,5 +248,5 @@ #### SourceMapConsumer.prototype.originalPositionFor(generatedPosition) | ||
#### new SourceMapGenerator(startOfSourceMap) | ||
#### new SourceMapGenerator([startOfSourceMap]) | ||
To create a new one, you must pass an object with the following properties: | ||
You may pass an object with the following properties: | ||
@@ -256,3 +256,3 @@ * `file`: The filename of the generated source that this source map is | ||
* `sourceRoot`: An optional root for all relative URLs in this source map. | ||
* `sourceRoot`: A root for all relative URLs in this source map. | ||
@@ -287,3 +287,3 @@ #### SourceMapGenerator.fromSourceMap(sourceMapConsumer) | ||
#### SourceMapGenerator.prototype.applySourceMap(sourceMapConsumer[, sourceFile]) | ||
#### SourceMapGenerator.prototype.applySourceMap(sourceMapConsumer[, sourceFile[, sourceMapPath]]) | ||
@@ -298,4 +298,16 @@ Applies a SourceMap for a source file to the SourceMap. | ||
* `sourceFile`: Optional. The filename of the source file. | ||
If omitted, sourceMapConsumer.file will be used. | ||
If omitted, sourceMapConsumer.file will be used, if it exists. | ||
Otherwise an error will be thrown. | ||
* `sourceMapPath`: Optional. The dirname of the path to the SourceMap | ||
to be applied. If relative, it is relative to the SourceMap. | ||
This parameter is needed when the two SourceMaps aren't in the same | ||
directory, and the SourceMap to be applied contains relative source | ||
paths. If so, those relative source paths need to be rewritten | ||
relative to the SourceMap. | ||
If omitted, it is assumed that both SourceMaps are in the same directory, | ||
thus not needing any rewriting. (Supplying `'.'` has the same effect.) | ||
#### SourceMapGenerator.prototype.toString() | ||
@@ -313,3 +325,3 @@ | ||
#### new SourceNode(line, column, source[, chunk[, name]]) | ||
#### new SourceNode([line, column, source[, chunk[, name]]]) | ||
@@ -322,3 +334,3 @@ * `line`: The original line number associated with this source node, or null if | ||
* `source`: The original source's filename. | ||
* `source`: The original source's filename; null if no filename is provided. | ||
@@ -397,3 +409,3 @@ * `chunk`: Optional. Is immediately passed to `SourceNode.prototype.add`, see | ||
### SourceNode.prototype.toStringWithSourceMap(startOfSourceMap) | ||
### SourceNode.prototype.toStringWithSourceMap([startOfSourceMap]) | ||
@@ -400,0 +412,0 @@ Returns the string representation of this tree of source nodes, plus a |
@@ -45,2 +45,8 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
smg.addMapping({ | ||
source: 'gza.coffee', | ||
original: { line: 5, column: 10 }, | ||
generated: { line: 6, column: 12 } | ||
}); | ||
var smc = new SourceMapConsumer(smg.toString()); | ||
@@ -53,16 +59,20 @@ | ||
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 0, null, smc, assert); | ||
util.assertMapping(6, 12, '/wu/tang/gza.coffee', 5, 10, null, smc, assert); | ||
// Fuzzy | ||
// Original to generated | ||
// Generated to original | ||
util.assertMapping(2, 0, null, null, null, null, smc, assert, true); | ||
util.assertMapping(2, 9, '/wu/tang/gza.coffee', 1, 0, null, smc, assert, true); | ||
util.assertMapping(3, 0, '/wu/tang/gza.coffee', 1, 0, null, smc, assert, true); | ||
util.assertMapping(3, 0, null, null, null, null, smc, assert, true); | ||
util.assertMapping(3, 9, '/wu/tang/gza.coffee', 2, 0, null, smc, assert, true); | ||
util.assertMapping(4, 0, '/wu/tang/gza.coffee', 2, 0, null, smc, assert, true); | ||
util.assertMapping(4, 0, null, null, null, null, smc, assert, true); | ||
util.assertMapping(4, 9, '/wu/tang/gza.coffee', 3, 0, null, smc, assert, true); | ||
util.assertMapping(5, 0, '/wu/tang/gza.coffee', 3, 0, null, smc, assert, true); | ||
util.assertMapping(5, 0, null, null, null, null, smc, assert, true); | ||
util.assertMapping(5, 9, '/wu/tang/gza.coffee', 4, 0, null, smc, assert, true); | ||
util.assertMapping(6, 0, null, null, null, null, smc, assert, true); | ||
util.assertMapping(6, 9, null, null, null, null, smc, assert, true); | ||
util.assertMapping(6, 13, '/wu/tang/gza.coffee', 5, 10, null, smc, assert, true); | ||
// Generated to original | ||
// Original to generated | ||
util.assertMapping(2, 2, '/wu/tang/gza.coffee', 1, 1, null, smc, assert, null, true); | ||
@@ -72,4 +82,6 @@ util.assertMapping(3, 2, '/wu/tang/gza.coffee', 2, 3, null, smc, assert, null, true); | ||
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 4, 9, null, smc, assert, null, true); | ||
util.assertMapping(5, 2, '/wu/tang/gza.coffee', 5, 9, null, smc, assert, null, true); | ||
util.assertMapping(6, 12, '/wu/tang/gza.coffee', 6, 19, null, smc, assert, null, true); | ||
}; | ||
}); |
@@ -15,3 +15,3 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
exports['test that we can instantiate with a string or an objects'] = function (assert, util) { | ||
exports['test that we can instantiate with a string or an object'] = function (assert, util) { | ||
assert.doesNotThrow(function () { | ||
@@ -84,2 +84,26 @@ var map = new SourceMapConsumer(util.testMap); | ||
exports['test mappings and end of lines'] = function (assert, util) { | ||
var smg = new SourceMapGenerator({ | ||
file: 'foo.js' | ||
}); | ||
smg.addMapping({ | ||
original: { line: 1, column: 1 }, | ||
generated: { line: 1, column: 1 }, | ||
source: 'bar.js' | ||
}); | ||
smg.addMapping({ | ||
original: { line: 2, column: 2 }, | ||
generated: { line: 2, column: 2 }, | ||
source: 'bar.js' | ||
}); | ||
var map = SourceMapConsumer.fromSourceMap(smg); | ||
// When finding original positions, mappings end at the end of the line. | ||
util.assertMapping(2, 1, null, null, null, null, map, assert, true) | ||
// When finding generated positions, mappings do not end at the end of the line. | ||
util.assertMapping(1, 1, 'bar.js', 2, 1, null, map, assert, null, true); | ||
}; | ||
exports['test creating source map consumers with )]}\' prefix'] = function (assert, util) { | ||
@@ -86,0 +110,0 @@ assert.doesNotThrow(function () { |
@@ -23,2 +23,5 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
assert.ok(true); | ||
var map = new SourceMapGenerator(); | ||
assert.ok(true); | ||
}; | ||
@@ -273,2 +276,122 @@ | ||
exports['test applySourceMap throws when file is missing'] = function (assert, util) { | ||
var map = new SourceMapGenerator({ | ||
file: 'test.js' | ||
}); | ||
var map2 = new SourceMapGenerator(); | ||
assert.throws(function() { | ||
map.applySourceMap(new SourceMapConsumer(map2.toJSON())); | ||
}); | ||
}; | ||
exports['test the two additional parameters of applySourceMap'] = function (assert, util) { | ||
// Assume the following directory structure: | ||
// | ||
// http://foo.org/ | ||
// bar.coffee | ||
// app/ | ||
// coffee/ | ||
// foo.coffee | ||
// temp/ | ||
// bundle.js | ||
// temp_maps/ | ||
// bundle.js.map | ||
// public/ | ||
// bundle.min.js | ||
// bundle.min.js.map | ||
// | ||
// http://www.example.com/ | ||
// baz.coffee | ||
var bundleMap = new SourceMapGenerator({ | ||
file: 'bundle.js' | ||
}); | ||
bundleMap.addMapping({ | ||
generated: { line: 3, column: 3 }, | ||
original: { line: 2, column: 2 }, | ||
source: '../coffee/foo.coffee' | ||
}); | ||
bundleMap.addMapping({ | ||
generated: { line: 13, column: 13 }, | ||
original: { line: 12, column: 12 }, | ||
source: '/bar.coffee' | ||
}); | ||
bundleMap.addMapping({ | ||
generated: { line: 23, column: 23 }, | ||
original: { line: 22, column: 22 }, | ||
source: 'http://www.example.com/baz.coffee' | ||
}); | ||
bundleMap = new SourceMapConsumer(bundleMap.toJSON()); | ||
var minifiedMap = new SourceMapGenerator({ | ||
file: 'bundle.min.js', | ||
sourceRoot: '..' | ||
}); | ||
minifiedMap.addMapping({ | ||
generated: { line: 1, column: 1 }, | ||
original: { line: 3, column: 3 }, | ||
source: 'temp/bundle.js' | ||
}); | ||
minifiedMap.addMapping({ | ||
generated: { line: 11, column: 11 }, | ||
original: { line: 13, column: 13 }, | ||
source: 'temp/bundle.js' | ||
}); | ||
minifiedMap.addMapping({ | ||
generated: { line: 21, column: 21 }, | ||
original: { line: 23, column: 23 }, | ||
source: 'temp/bundle.js' | ||
}); | ||
minifiedMap = new SourceMapConsumer(minifiedMap.toJSON()); | ||
var expectedMap = function (sources) { | ||
var map = new SourceMapGenerator({ | ||
file: 'bundle.min.js', | ||
sourceRoot: '..' | ||
}); | ||
map.addMapping({ | ||
generated: { line: 1, column: 1 }, | ||
original: { line: 2, column: 2 }, | ||
source: sources[0] | ||
}); | ||
map.addMapping({ | ||
generated: { line: 11, column: 11 }, | ||
original: { line: 12, column: 12 }, | ||
source: sources[1] | ||
}); | ||
map.addMapping({ | ||
generated: { line: 21, column: 21 }, | ||
original: { line: 22, column: 22 }, | ||
source: sources[2] | ||
}); | ||
return map.toJSON(); | ||
} | ||
var actualMap = function (aSourceMapPath) { | ||
var map = SourceMapGenerator.fromSourceMap(minifiedMap); | ||
// Note that relying on `bundleMap.file` (which is simply 'bundle.js') | ||
// instead of supplying the second parameter wouldn't work here. | ||
map.applySourceMap(bundleMap, '../temp/bundle.js', aSourceMapPath); | ||
return map.toJSON(); | ||
} | ||
util.assertEqualMaps(assert, actualMap('../temp_maps'), expectedMap([ | ||
'coffee/foo.coffee', | ||
'/bar.coffee', | ||
'http://www.example.com/baz.coffee' | ||
])); | ||
util.assertEqualMaps(assert, actualMap('/app/temp_maps'), expectedMap([ | ||
'/app/coffee/foo.coffee', | ||
'/bar.coffee', | ||
'http://www.example.com/baz.coffee' | ||
])); | ||
util.assertEqualMaps(assert, actualMap('http://foo.org/app/temp_maps'), expectedMap([ | ||
'http://foo.org/app/coffee/foo.coffee', | ||
'http://foo.org/bar.coffee', | ||
'http://www.example.com/baz.coffee' | ||
])); | ||
}; | ||
exports['test sorting with duplicate generated mappings'] = function (assert, util) { | ||
@@ -275,0 +398,0 @@ var map = new SourceMapGenerator({ |
@@ -143,4 +143,9 @@ /* -*- Mode: js; js-indent-level: 2; -*- */ | ||
}).map; | ||
var mapWithoutOptions = node.toStringWithSourceMap().map; | ||
assert.ok(map instanceof SourceMapGenerator, 'map instanceof SourceMapGenerator'); | ||
assert.ok(mapWithoutOptions instanceof SourceMapGenerator, 'mapWithoutOptions instanceof SourceMapGenerator'); | ||
mapWithoutOptions._file = 'foo.js'; | ||
util.assertEqualMaps(assert, map.toJSON(), mapWithoutOptions.toJSON()); | ||
map = new SourceMapConsumer(map.toString()); | ||
@@ -259,3 +264,3 @@ | ||
exports['test .fromStringWithSourceMap() merging duplicate mappings'] = function (assert, util) { | ||
exports['test .toStringWithSourceMap() merging duplicate mappings'] = function (assert, util) { | ||
var input = new SourceNode(null, null, null, [ | ||
@@ -269,3 +274,5 @@ new SourceNode(1, 0, "a.js", "(function"), | ||
new SourceNode(2, 0, "b.js", ".A", "A"), | ||
new SourceNode(2, 20, "b.js", " = { value: 1234 };\n", "A"), | ||
new SourceNode(2, 20, "b.js", " = { value: ", "A"), | ||
"1234", | ||
new SourceNode(2, 40, "b.js", " };\n", "A"), | ||
"}());\n", | ||
@@ -286,6 +293,5 @@ "/* Generated Source */" | ||
}); | ||
// Here is no need for a empty mapping, | ||
// because mappings ends at eol | ||
correctMap.addMapping({ | ||
generated: { line: 2, column: 0 } | ||
}); | ||
correctMap.addMapping({ | ||
generated: { line: 2, column: 2 }, | ||
@@ -317,11 +323,79 @@ source: 'a.js', | ||
}); | ||
// This empty mapping is required, | ||
// because there is a hole in the middle of the line | ||
correctMap.addMapping({ | ||
generated: { line: 4, column: 0 } | ||
generated: { line: 3, column: 18 } | ||
}); | ||
correctMap.addMapping({ | ||
generated: { line: 3, column: 22 }, | ||
source: 'b.js', | ||
name: 'A', | ||
original: { line: 2, column: 40 } | ||
}); | ||
// Here is no need for a empty mapping, | ||
// because mappings ends at eol | ||
var inputMap = input.map.toJSON(); | ||
correctMap = correctMap.toJSON(); | ||
util.assertEqualMaps(assert, correctMap, inputMap); | ||
util.assertEqualMaps(assert, inputMap, correctMap); | ||
}; | ||
exports['test .toStringWithSourceMap() multi-line SourceNodes'] = function (assert, util) { | ||
var input = new SourceNode(null, null, null, [ | ||
new SourceNode(1, 0, "a.js", "(function() {\nvar nextLine = 1;\nanotherLine();\n"), | ||
new SourceNode(2, 2, "b.js", "Test.call(this, 123);\n"), | ||
new SourceNode(2, 2, "b.js", "this['stuff'] = 'v';\n"), | ||
new SourceNode(2, 2, "b.js", "anotherLine();\n"), | ||
"/*\nGenerated\nSource\n*/\n", | ||
new SourceNode(3, 4, "c.js", "anotherLine();\n"), | ||
"/*\nGenerated\nSource\n*/" | ||
]); | ||
input = input.toStringWithSourceMap({ | ||
file: 'foo.js' | ||
}); | ||
var correctMap = new SourceMapGenerator({ | ||
file: 'foo.js' | ||
}); | ||
correctMap.addMapping({ | ||
generated: { line: 1, column: 0 }, | ||
source: 'a.js', | ||
original: { line: 1, column: 0 } | ||
}); | ||
correctMap.addMapping({ | ||
generated: { line: 2, column: 0 }, | ||
source: 'a.js', | ||
original: { line: 1, column: 0 } | ||
}); | ||
correctMap.addMapping({ | ||
generated: { line: 3, column: 0 }, | ||
source: 'a.js', | ||
original: { line: 1, column: 0 } | ||
}); | ||
correctMap.addMapping({ | ||
generated: { line: 4, column: 0 }, | ||
source: 'b.js', | ||
original: { line: 2, column: 2 } | ||
}); | ||
correctMap.addMapping({ | ||
generated: { line: 5, column: 0 }, | ||
source: 'b.js', | ||
original: { line: 2, column: 2 } | ||
}); | ||
correctMap.addMapping({ | ||
generated: { line: 6, column: 0 }, | ||
source: 'b.js', | ||
original: { line: 2, column: 2 } | ||
}); | ||
correctMap.addMapping({ | ||
generated: { line: 11, column: 0 }, | ||
source: 'c.js', | ||
original: { line: 3, column: 4 } | ||
}); | ||
var inputMap = input.map.toJSON(); | ||
correctMap = correctMap.toJSON(); | ||
util.assertEqualMaps(assert, inputMap, correctMap); | ||
}; | ||
exports['test setSourceContent with toStringWithSourceMap'] = function (assert, util) { | ||
@@ -328,0 +402,0 @@ var aNode = new SourceNode(1, 1, 'a.js', 'a'); |
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
167938
37
3961
447