forked from mozilla/source-map
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* -*- Mode: js; js-indent-level: 2; -*- */ | ||
/* | ||
* Copyright 2011 Mozilla Foundation and contributors | ||
* Licensed under the New BSD license. See LICENSE or: | ||
* http://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
if (typeof define !== 'function') { | ||
var define = require('amdefine')(module); | ||
} | ||
define(function (require, exports, module) { | ||
|
||
var SourceMapGenerator = require('../../lib/source-map/source-map-generator').SourceMapGenerator; | ||
var SourceMapConsumer = require('../../lib/source-map/source-map-consumer').SourceMapConsumer; | ||
var SourceNode = require('../../lib/source-map/source-node').SourceNode; | ||
|
||
exports['test minimizing coffee-script'] = function (assert, util) { | ||
// Coffeescript input file: | ||
/* | ||
# Assignment: | ||
number = 42 | ||
opposite = true | ||
# Conditions: | ||
number = -42 if opposite | ||
# Functions: | ||
square = (x) -> x * x | ||
# Arrays: | ||
list = [1, 2, 3, 4, 5] | ||
# Objects: | ||
math = | ||
root: Math.sqrt | ||
square: square | ||
cube: (x) -> x * square x | ||
# Splats: | ||
race = (winner, runners...) -> | ||
print winner, runners | ||
# Existence: | ||
alert "I knew it!" if elvis? | ||
# Array comprehensions: | ||
cubes = (math.cube num for num in list) | ||
*/ | ||
|
||
// Compiled with "coffee -c -m script.coffee" | ||
var coffeeToJsMap = { | ||
"version": 3, | ||
"file": "script.js", | ||
"sources": [ | ||
"script.coffee" | ||
], | ||
"names": [], | ||
"mappings": ";AACA;CAAA,KAAA,gDAAA;KAAA,aAAA;;CAAA,CAAA,CAAW,GAAX;;CAAA,CACA,CAAW,CADX,IACA;;CAGA,CAAA,EAAgB,IAAhB;AAAU,CAAV,CAAA,CAAS,CAAT,EAAA;IAJA;;CAAA,CAOA,CAAS,GAAT,GAAU;CAAM,EAAI,QAAJ;CAPhB,EAOS;;CAPT,CAUA,CAAO,CAAP;;CAVA,CAaA,CACE,CADF;CACE,CAAQ,EAAR;CAAA,CACQ,EAAR,EAAA;CADA,CAEQ,CAAA,CAAR,KAAS;CAAM,EAAI,GAAA,OAAJ;CAFf,IAEQ;CAhBV,GAAA;;CAAA,CAmBA,CAAO,CAAP,KAAO;CACL,OAAA,OAAA;;CAAA,CADc,EAAR,mDACN;CAAM,CAAQ,GAAd,CAAA,CAAA,IAAA;CApBF,EAmBO;;CAIP,CAAA,EAAsB,0CAAtB;CAAA,GAAA,CAAA,OAAA;IAvBA;;CAAA,CA0BA,GAAA;;;AAAS,CAAA;UAAA,iCAAA;sBAAA;CAAA,EAAA,CAAI;CAAJ;;CA1BT;CAAA" | ||
}; | ||
|
||
// Minimized with "uglifyjs -m -b --source-map script.min.map script.js > script.min.js" | ||
var jsToMinMap = { | ||
"version":3, | ||
"file":"script.min.js", | ||
"sources":["script.js"], | ||
"names":[ | ||
"cubes","list","math","num","number", | ||
"opposite","race","square","__slice", | ||
"slice","x","root","Math","sqrt","cube", | ||
"runners","winner","arguments","length", | ||
"call","print","elvis","alert","_i", | ||
"_len","_results","push","this" | ||
], | ||
"mappings":"CACA;IACE,IAAIA,GAAOC,GAAMC,GAAMC,GAAKC,GAAQC,GAAUC,GAAMC,GAClDC,OAAaC;IAEfL,IAAS;IAETC,IAAW;IAEX,IAAIA,GAAU;QACZD,KAAU;;IAGZG,IAAS,SAASG;QAChB,OAAOA,IAAIA;;IAGbT,MAAQ,GAAG,GAAG,GAAG,GAAG;IAEpBC;QACES,MAAMC,KAAKC;QACXN,QAAQA;QACRO,MAAM,SAASJ;YACb,OAAOA,IAAIH,EAAOG;;;IAItBJ,IAAO;QACL,IAAIS,GAASC;QAEbA,IAASC,UAAU,IAAIF,IAAU,KAAKE,UAAUC,SAASV,EAAQW,KAAKF,WAAW;QACjF,OAAOG,MAAMJ,GAAQD;;IAGvB,WAAWM,UAAU,eAAeA,UAAU,MAAM;QAClDC,MAAM;;IAGRtB,IAAQ;QACN,IAAIuB,GAAIC,GAAMC;QAEdA;QACA,KAAKF,IAAK,GAAGC,IAAOvB,EAAKiB,QAAQK,IAAKC,GAAMD,KAAM;YAChDpB,IAAMF,EAAKsB;YACXE,EAASC,KAAKxB,EAAKY,KAAKX;;QAE1B,OAAOsB;;GAGRN,KAAKQ" | ||
}; | ||
|
||
var expectedMap = { | ||
"version": 3, | ||
"file": "script.min.js", | ||
"sources": [ | ||
"script.coffee" | ||
], | ||
"names": [ | ||
"cubes","list","math","num","number", | ||
"opposite","race","square","__slice", | ||
"slice","x","root","Math","sqrt","cube", | ||
"runners","winner","arguments","length", | ||
"call","print","elvis","alert","_i", | ||
"_len","_results","push","this" | ||
], | ||
"mappings": "CACA;IAAA,IAAAA,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,OAAAC;IAAAL,IAAA;IACAC,IAAA;IAGA,IAAgBA,GAAhB;QAAAD,KAAA;;IAGAG,IAAU,SAAAG;QAAU,OAAJA,IAAAA;;IAGhBT,MAAA,GAAA,GAAA,GAAA,GAAA;IAGAC;QACES,MAAAC,KAAAC;QACAN,QAAAA;QACAO,MAAS,SAAAJ;YAAU,OAAJA,IAAAH,EAAAG;;;IAGjBJ,IAAO;QACL,IAAAS,GAAAC;QADMA,IAAAC,UAAA,IAAAF,IAAA,KAAAE,UAAAC,SACNV,EAAAW,KAAAF,WAAA;QAAc,OAAdG,MAAAJ,GAAAD;;IAGF,WAAsBM,UAAA,eAAAA,UAAtB,MAAA;QAAAC,MAAA;;IAGAtB,IAAA;QAAA,IAAAuB,GAAAC,GAAAC;QAASA;QAAA,KAAAF,IAAA,GAAAC,IAAAvB,EAAAiB,QAAAK,IAAAC,GAAAD,KAAA;YAAApB,IAAAF,EAAAsB;YAAIE,EAAAC,KAAAxB,EAAAY,KAAAX;;QAAJ,OAAAsB;;GA1BTN,KAAAQ" | ||
}; | ||
|
||
// Combining with "applySourceMap": | ||
var gen = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(jsToMinMap)); | ||
gen.applySourceMap(new SourceMapConsumer(coffeeToJsMap)); | ||
var map = gen.toJSON(); | ||
|
||
assert.equal(map.version, expectedMap.version); | ||
assert.deepEqual(map.sources, expectedMap.sources); | ||
assert.deepEqual(map.names, expectedMap.names); | ||
assert.equal(map.mappings, expectedMap.mappings); | ||
}; | ||
}); |