sourcemap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b4a81026175f484ceb522205f323e81f4a70557
4
+ data.tar.gz: ab163856d4087ae34952f1bc5a6d543789acdfa2
5
+ SHA512:
6
+ metadata.gz: 79a8c966756ef258e67acebd246ce3f10f340428785b502387161599406dc7cacb183fec9e546b59ad34b30248fa6a01371e42f1750b24500c1673ae3fad022a
7
+ data.tar.gz: 370b5fb6762a23d60419a38651cf6f9166a51d08b43091e57a61020821b1d52680a896a7e1e1ef4cc24f6cb15c67d7fe66a34de13c6bb4813be40a859bbc3399
@@ -0,0 +1 @@
1
+ Gemfile.lock
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+
5
+ notifications:
6
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alex MacCaw, Joshua Peek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,173 @@
1
+ # Ruby Source Maps
2
+
3
+ A Ruby library to read, create and manipulate Source Maps.
4
+
5
+ [Source Maps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) allow easy debugging and development of CoffeeScript and minifed JavaScript.
6
+
7
+ # Installation
8
+
9
+ gem install sourcemap
10
+ # or Bundler:
11
+ gem 'sourcemap'
12
+
13
+ # Usage
14
+
15
+ ## Concatenation
16
+
17
+ Join multiple source maps together.
18
+
19
+ ``` ruby
20
+ foo = File.read("examples/foo.js")
21
+ bar = File.read("examples/bar.js")
22
+ foobar = foo + bar
23
+
24
+ foo_map = SourceMap::Map.from_json File.read("examples/foo.map")
25
+ bar_map = SourceMap::Map.from_json File.read("examples/bar.map")
26
+ foobar_map = foo_map + bar_map
27
+ foobar_map.to_json
28
+ ```
29
+
30
+ ## Piping
31
+
32
+ Base one source map of another.
33
+
34
+ ``` ruby
35
+ cs_map = SourceMap::Map.from_json File.read("examples/index.map")
36
+ min_map = SourceMap::Map.from_json File.read("examples/index.min.map")
37
+ combined_map = cs_map + min_map
38
+ combined_map.to_json
39
+ ```
40
+
41
+ ## Map
42
+
43
+ ### Map.from_json(json)
44
+
45
+ Create a new `Map` instance from a JSON map string.
46
+
47
+ SourceMap::Map.from_json(%{
48
+ {
49
+ "version": 3,
50
+ "file": "index.js",
51
+ "sourceRoot": "",
52
+ "sources": [
53
+ "index.coffee"
54
+ ],
55
+ "names": [],
56
+ "mappings": ";AAAA;AAAA,MAAA,IAAA;;AAAA"
57
+ }
58
+ })
59
+
60
+ ### Map.from_hash(hash)
61
+
62
+ Create a new `Map` instance from a hash.
63
+
64
+ hash = {
65
+ 'version' => 3,
66
+ 'file' => "script.min.js",
67
+ 'lineCount' => 1,
68
+ 'mappings' => "AAEAA,QAASA,MAAK,EAAG,CACfC,OAAAC,IAAA,CAAY,eAAZ,CADe",
69
+ 'sources' => ["script.js"],
70
+ 'names' => ["hello", "console", "log"]
71
+ }
72
+ map = SourceMap::Map.from_hash(hash)
73
+
74
+ ### Map.new(mappings = [], filename = nil)
75
+
76
+ Instantiate a `Map` instance, passing in an optional array of `Mapping`s and file name.
77
+
78
+ @mappings = SourceMap::Map.new([
79
+ SourceMap::Mapping.new('a.js', SourceMap::Offset.new(0, 0), SourceMap::Offset.new(0, 0)),
80
+ SourceMap::Mapping.new('b.js', SourceMap::Offset.new(1, 0), SourceMap::Offset.new(20, 0)),
81
+ SourceMap::Mapping.new('c.js', SourceMap::Offset.new(2, 0), SourceMap::Offset.new(30, 0))
82
+ ])
83
+
84
+ ### Map#line_count
85
+
86
+ Returns the line number of the last mapping.
87
+
88
+ ### Map#size
89
+
90
+ Returns the amount of mappings
91
+
92
+ ### Map#[]
93
+
94
+ Lookup a mapping by integer
95
+
96
+ map = SourceMap::Map.from_json(json)
97
+ map[5] #=> <Mapping>
98
+
99
+ ### Map#each
100
+
101
+ Iterate over each mapping.
102
+
103
+ ### Map#to_s
104
+
105
+ Returns a VLQ representation of the source map.
106
+
107
+ mapping = SourceMap::Map.from_hash(hash)
108
+ mappings.to_s #=> "ACmBA;ACUA"
109
+
110
+ ### Map#sources
111
+
112
+ Returns an array of the original file names referenced in each mapping.
113
+
114
+ ### Map#names
115
+
116
+ Returns an array of 'names', which are referenced in the mappings (in case the original source file is not available).
117
+
118
+ ### Map#+
119
+
120
+ Concatenates Maps together, so you can serve mappings from multiple sources as one combined map.
121
+
122
+ foo_map = SourceMap::Map.from_json File.read("examples/foo.map")
123
+ bar_map = SourceMap::Map.from_json File.read("examples/bar.map")
124
+ foobar_map = foo_map + bar_map
125
+ foobar_map.to_json
126
+
127
+ ### Map#|
128
+
129
+ Pipes map files together, so for example you could pipe a CoffeeScript map of `index.coffee` and an uglifier map of `index.js` together. In other words, one mapping will be based of the other.
130
+
131
+ coffeescript_map = SourceMap::Map.from_json(cs_map_json)
132
+ uglifier_map = SourceMap::Map.from_json(min_map_json)
133
+
134
+ combined_map = coffeescript_map | uglifier_map
135
+
136
+ ### Map#bsearch(offset)
137
+
138
+ Find the closest generated mapping to any given offset using a binary tree search.
139
+
140
+ foo_map = SourceMap::Map.from_json File.read("examples/foo.map")
141
+ foo_map.bsearch(SourceMap::Offset.new(1,1)) #=> <Mapping>
142
+
143
+ The method will return `nil` if an offset can't be found.
144
+
145
+ ### Map#as_json
146
+
147
+ Convert a `Map` instance back to JSON.
148
+
149
+ map = Map.new([
150
+ Mapping.new('a.js', Offset.new(0, 0), Offset.new(0, 0)),
151
+ Mapping.new('b.js', Offset.new(1, 0), Offset.new(20, 0)),
152
+ Mapping.new('c.js', Offset.new(2, 0), Offset.new(30, 0))
153
+ ])
154
+
155
+ map.to_json #=> "{...}"
156
+
157
+ ## Offset
158
+
159
+ ### Offset.new(line, column)
160
+
161
+ Instantiate an `Offset`, passing in a line and column integer.
162
+
163
+ ### Offset#+
164
+
165
+ Add two offsets together.
166
+
167
+ ### Offset#<=>
168
+
169
+ Compare the position of two offsets, first the line than the column.
170
+
171
+ ## Offset#to_s
172
+
173
+ Get a pretty representation of an offset.
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.warning = true
9
+ end
@@ -0,0 +1,10 @@
1
+ # Eat lunch.
2
+ eat food for food in ['toast', 'cheese', 'wine']
3
+
4
+ # Fine five course dining.
5
+ courses = ['greens', 'caviar', 'truffles', 'roast', 'cake']
6
+ menu i + 1, dish for dish, i in courses
7
+
8
+ # Health conscious meal.
9
+ foods = ['broccoli', 'spinach', 'chocolate']
10
+ eat food for food in foods when food isnt 'chocolate'
@@ -0,0 +1,27 @@
1
+ // Generated by CoffeeScript 1.6.3
2
+ (function() {
3
+ var courses, dish, food, foods, i, _i, _j, _k, _len, _len1, _len2, _ref;
4
+
5
+ _ref = ['toast', 'cheese', 'wine'];
6
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
7
+ food = _ref[_i];
8
+ eat(food);
9
+ }
10
+
11
+ courses = ['greens', 'caviar', 'truffles', 'roast', 'cake'];
12
+
13
+ for (i = _j = 0, _len1 = courses.length; _j < _len1; i = ++_j) {
14
+ dish = courses[i];
15
+ menu(i + 1, dish);
16
+ }
17
+
18
+ foods = ['broccoli', 'spinach', 'chocolate'];
19
+
20
+ for (_k = 0, _len2 = foods.length; _k < _len2; _k++) {
21
+ food = foods[_k];
22
+ if (food !== 'chocolate') {
23
+ eat(food);
24
+ }
25
+ }
26
+
27
+ }).call(this);
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "bar.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "bar.coffee"
7
+ ],
8
+ "names": [],
9
+ "mappings": ";AACA;CAAA,KAAA,6DAAA;;CAAA;CAAA,MAAA,oCAAA;qBAAA;CAAA,EAAA,CAAA;CAAA,EAAA;;CAAA,CAGA,CAAU,GAAA,CAAV,CAAU,EAAA;;AACV,CAAA,MAAA,iDAAA;uBAAA;CAAA,CAAY,CAAH,CAAT;CAAA,EAJA;;CAAA,CAOA,CAAQ,EAAR,IAAQ,CAAA,CAAA;;AACR,CAAA,MAAA,uCAAA;sBAAA;IAAgC,CAAU;CAA1C,EAAA,CAAA,EAAA;MAAA;CAAA,EARA;CAAA"
10
+ }
@@ -0,0 +1,28 @@
1
+ # Assignment:
2
+ number = 42
3
+ opposite = true
4
+
5
+ # Conditions:
6
+ number = -42 if opposite
7
+
8
+ # Functions:
9
+ square = (x) -> x * x
10
+
11
+ # Arrays:
12
+ list = [1, 2, 3, 4, 5]
13
+
14
+ # Objects:
15
+ math =
16
+ root: Math.sqrt
17
+ square: square
18
+ cube: (x) -> x * square x
19
+
20
+ # Splats:
21
+ race = (winner, runners...) ->
22
+ print winner, runners
23
+
24
+ # Existence:
25
+ alert "I knew it!" if elvis?
26
+
27
+ # Array comprehensions:
28
+ cubes = (math.cube num for num in list)
@@ -0,0 +1,48 @@
1
+ // Generated by CoffeeScript 1.6.3
2
+ (function() {
3
+ var cubes, list, math, num, number, opposite, race, square,
4
+ __slice = [].slice;
5
+
6
+ number = 42;
7
+
8
+ opposite = true;
9
+
10
+ if (opposite) {
11
+ number = -42;
12
+ }
13
+
14
+ square = function(x) {
15
+ return x * x;
16
+ };
17
+
18
+ list = [1, 2, 3, 4, 5];
19
+
20
+ math = {
21
+ root: Math.sqrt,
22
+ square: square,
23
+ cube: function(x) {
24
+ return x * square(x);
25
+ }
26
+ };
27
+
28
+ race = function() {
29
+ var runners, winner;
30
+ winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
31
+ return print(winner, runners);
32
+ };
33
+
34
+ if (typeof elvis !== "undefined" && elvis !== null) {
35
+ alert("I knew it!");
36
+ }
37
+
38
+ cubes = (function() {
39
+ var _i, _len, _results;
40
+ _results = [];
41
+ for (_i = 0, _len = list.length; _i < _len; _i++) {
42
+ num = list[_i];
43
+ _results.push(math.cube(num));
44
+ }
45
+ return _results;
46
+ })();
47
+
48
+ }).call(this);
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "file": "foo.js",
4
+ "sourceRoot": "",
5
+ "sources": [
6
+ "foo.coffee"
7
+ ],
8
+ "names": [],
9
+ "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"
10
+ }
@@ -0,0 +1,2 @@
1
+ !function(){var cubes,list,math,num,number,opposite,race,square,__slice=[].slice;number=42;opposite=true;if(opposite){number=-42}square=function(x){return x*x};list=[1,2,3,4,5];math={root:Math.sqrt,square:square,cube:function(x){return x*square(x)}};race=function(){var runners,winner;winner=arguments[0],runners=2<=arguments.length?__slice.call(arguments,1):[];return print(winner,runners)};if(typeof elvis!=="undefined"&&elvis!==null){alert("I knew it!")}cubes=function(){var _i,_len,_results;_results=[];for(_i=0,_len=list.length;_i<_len;_i++){num=list[_i];_results.push(math.cube(num))}return _results}()}.call(this);
2
+ //@ sourceMappingURL=foo.min.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["foo.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,WACE,GAAIA,OAAOC,KAAMC,KAAMC,IAAKC,OAAQC,SAAUC,KAAMC,OAClDC,WAAaC,KAEfL,QAAS,EAETC,UAAW,IAEX,IAAIA,SAAU,CACZD,QAAU,GAGZG,OAAS,SAASG,GAChB,MAAOA,GAAIA,EAGbT,OAAQ,EAAG,EAAG,EAAG,EAAG,EAEpBC,OACES,KAAMC,KAAKC,KACXN,OAAQA,OACRO,KAAM,SAASJ,GACb,MAAOA,GAAIH,OAAOG,IAItBJ,MAAO,WACL,GAAIS,SAASC,MACbA,QAASC,UAAU,GAAIF,QAAU,GAAKE,UAAUC,OAASV,QAAQW,KAAKF,UAAW,KACjF,OAAOG,OAAMJ,OAAQD,SAGvB,UAAWM,SAAU,aAAeA,QAAU,KAAM,CAClDC,MAAM,cAGRtB,MAAQ,WACN,GAAIuB,IAAIC,KAAMC,QACdA,YACA,KAAKF,GAAK,EAAGC,KAAOvB,KAAKiB,OAAQK,GAAKC,KAAMD,KAAM,CAChDpB,IAAMF,KAAKsB,GACXE,UAASC,KAAKxB,KAAKY,KAAKX,MAE1B,MAAOsB,cAGRN,KAAKQ"}
@@ -0,0 +1,6 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <script type="text/javascript" src="foobar.js"></script>
5
+ </head>
6
+ </html>
@@ -0,0 +1,77 @@
1
+ // Generated by CoffeeScript 1.6.3
2
+ (function() {
3
+ var cubes, list, math, num, number, opposite, race, square,
4
+ __slice = [].slice;
5
+
6
+ number = 42;
7
+
8
+ opposite = true;
9
+
10
+ if (opposite) {
11
+ number = -42;
12
+ }
13
+
14
+ square = function(x) {
15
+ return x * x;
16
+ };
17
+
18
+ list = [1, 2, 3, 4, 5];
19
+
20
+ math = {
21
+ root: Math.sqrt,
22
+ square: square,
23
+ cube: function(x) {
24
+ return x * square(x);
25
+ }
26
+ };
27
+
28
+ race = function() {
29
+ var runners, winner;
30
+ winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
31
+ return print(winner, runners);
32
+ };
33
+
34
+ if (typeof elvis !== "undefined" && elvis !== null) {
35
+ alert("I knew it!");
36
+ }
37
+
38
+ cubes = (function() {
39
+ var _i, _len, _results;
40
+ _results = [];
41
+ for (_i = 0, _len = list.length; _i < _len; _i++) {
42
+ num = list[_i];
43
+ _results.push(math.cube(num));
44
+ }
45
+ return _results;
46
+ })();
47
+
48
+ }).call(this);
49
+ // Generated by CoffeeScript 1.6.3
50
+ (function() {
51
+ var courses, dish, food, foods, i, _i, _j, _k, _len, _len1, _len2, _ref;
52
+
53
+ _ref = ['toast', 'cheese', 'wine'];
54
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
55
+ food = _ref[_i];
56
+ eat(food);
57
+ }
58
+
59
+ courses = ['greens', 'caviar', 'truffles', 'roast', 'cake'];
60
+
61
+ for (i = _j = 0, _len1 = courses.length; _j < _len1; i = ++_j) {
62
+ dish = courses[i];
63
+ menu(i + 1, dish);
64
+ }
65
+
66
+ foods = ['broccoli', 'spinach', 'chocolate'];
67
+
68
+ for (_k = 0, _len2 = foods.length; _k < _len2; _k++) {
69
+ food = foods[_k];
70
+ if (food !== 'chocolate') {
71
+ eat(food);
72
+ }
73
+ }
74
+
75
+ }).call(this);
76
+
77
+ //@ sourceMappingURL=foobar.map