opal 1.1.0 → 1.1.1.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebf169fc98d390d965c39386668f569467dc11db3eff5f2571db172f9f632b02
4
- data.tar.gz: 7d4d4e0de908d931ca39ac6d05d5fcbc1f1f1c1585e0cad22549ad31129f4064
3
+ metadata.gz: 1258e4fe63a4d35db8c8472acd68f434d597fff7be3e32c936be00dffbc83407
4
+ data.tar.gz: e7f697b42cd2e1c849f349e107e26740a8922ca409cdbfe94a7bba7bd7a06c6d
5
5
  SHA512:
6
- metadata.gz: 6c80d8bcb148c8c8563b88c0e482f77937e4f4e8cc2144a5f9f83ea1e4b914a3e3bf7888b591d9721a20e050a64e08ddb099af7c5b4cb939d8c2f8472a662c9d
7
- data.tar.gz: e04acce5335dd3ffe2bafdd40425ad788ff50316240d7863c7b8256b97f69a48a7f18cdcb9d9c1ddf0b738e366d5290b510ed6978735661a8f59f3e9003d3148
6
+ metadata.gz: a842bac817402616b1cb4e62e3d33d87c9a76011ac336b88efa3f28359a006a3f16139962cc7f2e4269389ae0a8a09a3902a9d53c36c1e347c28674454758976
7
+ data.tar.gz: e40165a56cb60445deee1525f51b12d629876b486b88a1f6f30e009aa127df769a6425fcbcaa1023654eeebb1b82cf50d2b3eece0476625775c431ed0957d700
data/.codeclimate.yml CHANGED
@@ -50,5 +50,4 @@ exclude_patterns:
50
50
  - "**/node_modules/*"
51
51
  - stdlib/nodejs/js-yaml-3-6-1.js
52
52
  - lib/opal/source_map/vlq.rb
53
- - lib/opal/cli_runners/source-map-support.js
54
- - lib/opal/cli_runners/source-map-support-browser.js
53
+ - lib/opal/cli_runners/source-map-support*.js
data/CHANGELOG.md CHANGED
@@ -15,7 +15,19 @@ Changes are grouped as follows:
15
15
 
16
16
 
17
17
 
18
- ## [Unreleased](https://github.com/opal/opal/compare/v1.0.5...HEAD) - unreleased
18
+ ## [Unreleased](https://github.com/opal/opal/compare/v1.1.0...HEAD) - unreleased
19
+
20
+
21
+ ### Added
22
+ ### Fixed
23
+ ### Changed
24
+ ### Deprecated
25
+ ### Removed
26
+
27
+
28
+
29
+
30
+ ## [1.1.0](https://github.com/opal/opal/compare/v1.0.5...v1.1.0) - 2021-02-19
19
31
 
20
32
 
21
33
  ### Added
@@ -36,6 +48,14 @@ Changes are grouped as follows:
36
48
  - Added a generic implementation of Kernel#caller and #warn(uplevel:) that works with sourcemaps in Node.js and Chrome ([#2065](https://github.com/opal/opal/pull/2065))
37
49
  - Added support for numblocks `-> { _1 + _2 }.call(3, 4) # => 7` ([#2149](https://github.com/opal/opal/pull/2149))
38
50
  - Support `<internal:…>` and `<js:…>` in stacktraces, like MRI we now distinguish internal lines from lib/app lines ([#2154](https://github.com/opal/opal/pull/2154))
51
+ - `Array#difference`, `Array#intersection`, `Array#union` as aliases respectively to `Array#{-,&,|}` ([#2151](https://github.com/opal/opal/pull/2151))
52
+ - Aliases `filter{,!}` to `select{,!}` throughout the corelib classes ([#2151](https://github.com/opal/opal/pull/2151))
53
+ - `Enumerable#filter_map`, `Enumerable#tally` ([#2151](https://github.com/opal/opal/pull/2151))
54
+ - Alias `Kernel#then` for `Kernel#yield_self` ([#2151](https://github.com/opal/opal/pull/2151))
55
+ - Method chaining: `{Proc,Method}#{<<,>>}` ([#2151](https://github.com/opal/opal/pull/2151))
56
+ - Added Integer#to_d ([#2006](https://github.com/opal/opal/pull/2006))
57
+ - Added a compiler option `use_strict` which can also be set by the `use_strict` magic comment ([#1959](https://github.com/opal/opal/pull/1959))
58
+ - Add `--rbrequire (-q)` option to `opal` command line executable ([#2120](https://github.com/opal/opal/pull/2120))
39
59
 
40
60
  ### Fixed
41
61
 
@@ -55,6 +75,7 @@ Changes are grouped as follows:
55
75
  - Set#keep_if ([#1987](https://github.com/opal/opal/pull/1987))
56
76
  - Set#select! ([#1987](https://github.com/opal/opal/pull/1987))
57
77
  - Set#reject! ([#1987](https://github.com/opal/opal/pull/1987))
78
+ - String#unicode_normalize ([#2175](https://github.com/opal/opal/pull/2175))
58
79
  - Module#alias_method ([#1983](https://github.com/opal/opal/pull/1983))
59
80
  - Enumerable#minmax_by ([#1981](https://github.com/opal/opal/pull/1981))
60
81
  - Enumerator#each_with_index ([#1990](https://github.com/opal/opal/pull/1990))
@@ -72,6 +93,21 @@ Changes are grouped as follows:
72
93
  - Set match on StringScanner#skip and StringScanner#scan_until ([#2061](https://github.com/opal/opal/pull/2061))
73
94
  - Fix ruby 2.7 warnings ([#2071](https://github.com/opal/opal/pull/2071))
74
95
  - Improve the --help descriptions ([#2146](https://github.com/opal/opal/pull/2146))
96
+ - Remove BasicObject#class ([#2166](https://github.com/opal/opal/pull/2166))
97
+ - Time#strftime %j leading zeros ([#2161](https://github.com/opal/opal/pull/2161))
98
+ - Fix `call { true or next }` producing invalid code ([#2160](https://github.com/opal/opal/pull/2160))
99
+ - `define_method` can now be called on the main object ([#2029](https://github.com/opal/opal/pull/2029))
100
+ - Fix nested for-loops ([#2033](https://github.com/opal/opal/pull/2033))
101
+ - Fix Number#round for Integers ([#2030](https://github.com/opal/opal/pull/2030))
102
+ - Fix parsing Unicode characters from Opal ([#2073](https://github.com/opal/opal/pull/2073))
103
+ - Integer#===: improve Integer recognition ([#2089](https://github.com/opal/opal/pull/2089))
104
+ - Regexp: ensure ignoreCase is never undefined ([#2098](https://github.com/opal/opal/pull/2098))
105
+ - Hash#delete: ensure String keys are converted to values ([#2106](https://github.com/opal/opal/pull/2106))
106
+ - Array#shift: improve performance on v8 >7.1 ([#2115](https://github.com/opal/opal/pull/2115))
107
+ - Array#pop(1): improve performance ([#2130](https://github.com/opal/opal/pull/2130))
108
+ - Object#pretty_inspect ([#2139](https://github.com/opal/opal/pull/2139))
109
+ - Fix conversion from UTF-8 to bytes ([#2138](https://github.com/opal/opal/pull/2138))
110
+ - Restore compatibility with Chrome 38, used by Cordova and many mobile browsers ([#2109](https://github.com/opal/opal/pull/2109))
75
111
 
76
112
  ### Changed
77
113
 
@@ -86,6 +122,12 @@ Changes are grouped as follows:
86
122
  - Change parser to 3.0 ([#2148](https://github.com/opal/opal/pull/2148))
87
123
  - Fix forwarding a rescued error to a global var: `rescue => $gvar` ([#2154](https://github.com/opal/opal/pull/2154))
88
124
  - Now using Parser v3.0 and targeting Ruby 3.0 ([#2156](https://github.com/opal/opal/pull/2156))
125
+ - `Comparable#clamp` to support a Range argument ([#2151](https://github.com/opal/opal/pull/2151))
126
+ - `#to_h` method to support a block (shortform for `.map(&block).to_h`) ([#2151](https://github.com/opal/opal/pull/2151))
127
+ - BigDecimal is now a subclass of Numeric ([#2006](https://github.com/opal/opal/pull/2006))
128
+ - PP to be rebased on upstream Ruby version ([#2083](https://github.com/opal/opal/pull/2083))
129
+ - String to report UTF-8 encoding by default, as MRI does ([#2117](https://github.com/opal/opal/pull/2117))
130
+ - Don't output "Failed to load WithCLexer, using pure Ruby lexer" warning unless in $DEBUG mode ([#2174](https://github.com/opal/opal/pull/2174))
89
131
 
90
132
  ### Deprecated
91
133
 
@@ -96,6 +138,7 @@ Changes are grouped as follows:
96
138
  ### Removed
97
139
 
98
140
  - Removed special compilation for the `Opal.truthy?` and `Opal.falsy?` helpers ([#2076](https://github.com/opal/opal/pull/2076))
141
+ - Removed the deprecated `tainting` compiler config option ([#2072](https://github.com/opal/opal/pull/2072))
99
142
 
100
143
 
101
144
 
data/UNRELEASED.md CHANGED
@@ -1,109 +1,5 @@
1
1
  ### Added
2
-
3
- - Basic support for `uplevel:` keyword argument in `Kernel#warn` (#2006)
4
- - Added a `#respond_to_missing?` implementation for `BasicObject`, `Delegator`, `OpenStruct`, that's meant for future support in the Opal runtime, which currently ignores it (#2007)
5
- - `Opal::Compiler#magic_comments` that allows to access magic-comments format and converts it to a hash (#2038)
6
- - Use magic-comments to declare helpers required by the file (#2038)
7
- - `Opal.$$` is now a shortcut for `Opal.const_get_relative` (#2038)
8
- - `Opal.$$$` is now a shortcut for `Opal.const_get_qualified` (#2038)
9
- - Added support for `globalThis` as the generic global object accessor (#2047)
10
- - `Opal::Compiler#magic_comments` that allows to access magic-comments format and converts it to a hash
11
- - Use magic-comments to declare helpers required by the file
12
- - `Opal.$$` is now a shortcut for `Opal.const_get_relative`
13
- - `Opal.$$$` is now a shortcut for `Opal.const_get_qualified`
14
- - Source-map support for Node.js in the default runner (#2045)
15
- - SecureRandom#hex(n) (#2050)
16
- - Added a generic implementation of Kernel#caller and #warn(uplevel:) that works with sourcemaps in Node.js and Chrome (#2065)
17
- - Added support for numblocks `-> { _1 + _2 }.call(3, 4) # => 7` (#2149)
18
- - Support `<internal:…>` and `<js:…>` in stacktraces, like MRI we now distinguish internal lines from lib/app lines (#2154)
19
- - `Array#difference`, `Array#intersection`, `Array#union` as aliases respectively to `Array#{-,&,|}` (#2151)
20
- - Aliases `filter{,!}` to `select{,!}` throughout the corelib classes (#2151)
21
- - `Enumerable#filter_map`, `Enumerable#tally` (#2151)
22
- - Alias `Kernel#then` for `Kernel#yield_self` (#2151)
23
- - Method chaining: `{Proc,Method}#{<<,>>}` (#2151)
24
- - Added Integer#to_d (#2006)
25
- - Added a compiler option `use_strict` which can also be set by the `use_strict` magic comment (#1959)
26
- - Add `--rbrequire (-q)` option to `opal` command line executable (#2120)
27
-
28
2
  ### Fixed
29
-
30
- - Array#delete_if (#2069)
31
- - Array#keep_if (#2069)
32
- - Array#reject! (#2069)
33
- - Array#select! (#2069)
34
- - Struct#dup (#1995)
35
- - Integer#gcdlcm (#1972)
36
- - Enumerable#to_h (#1979)
37
- - Enumerator#size (#1980)
38
- - Enumerable#min (#1982)
39
- - Enumerable#min_by (#1985)
40
- - Enumerable#max_by (#1985)
41
- - Set#intersect? (#1988)
42
- - Set#disjoint? (#1988)
43
- - Set#keep_if (#1987)
44
- - Set#select! (#1987)
45
- - Set#reject! (#1987)
46
- - String#unicode_normalize (#2175)
47
- - Module#alias_method (#1983)
48
- - Enumerable#minmax_by (#1981)
49
- - Enumerator#each_with_index (#1990)
50
- - Range#== (#1992)
51
- - Range#each (#1991)
52
- - Enumerable#zip (#1986)
53
- - String#getbyte (#2141)
54
- - Struct#dup not copying `$$data` (#1995)
55
- - Fixed usage of semicolon in single-line backticks (#2004)
56
- - Module#attr with multiple arguments (#2003)
57
- - `PathReader` used to try to read missing files instead of respecting the `missing_require_severity` configuration value (#2044)
58
- - Removed some unused variables from the runtime (#2052)
59
- - Fixed a typo in the runtime (#2054)
60
- - Fix Regexp interpolation, previously interpolating with other regexps was broken (#2062)
61
- - Set match on StringScanner#skip and StringScanner#scan_until (#2061)
62
- - Fix ruby 2.7 warnings (#2071)
63
- - Improve the --help descriptions (#2146)
64
- - Remove BasicObject#class (#2166)
65
- - Time#strftime %j leading zeros (#2161)
66
- - Fix `call { true or next }` producing invalid code (#2160)
67
- - `define_method` can now be called on the main object (#2029)
68
- - Fix nested for-loops (#2033)
69
- - Fix Number#round for Integers (#2030)
70
- - Fix parsing Unicode characters from Opal (#2073)
71
- - Integer#===: improve Integer recognition (#2089)
72
- - Regexp: ensure ignoreCase is never undefined (#2098)
73
- - Hash#delete: ensure String keys are converted to values (#2106)
74
- - Array#shift: improve performance on v8 >7.1 (#2115)
75
- - Array#pop(1): improve performance (#2130)
76
- - Object#pretty_inspect (#2139)
77
- - Fix conversion from UTF-8 to bytes (#2138)
78
- - Restore compatibility with Chrome 38, used by Cordova and many mobile browsers (#2109)
79
-
80
3
  ### Changed
81
-
82
- - Updated outdated parser version (#2013)
83
- - Nashorn has been deprecated but GraalVM still supports it (#1997)
84
- - "opal/mini" now includes "opal/io" (#2002)
85
- - Regexps assigned to constants are now frozen (#2007)
86
- - `Opal.$$` changed from being the constant cache of Object to being a shortcut for `Opal.const_get_relative` (#2038)
87
- - Moved REPL implementation from bin/ to its own lib/ file as `opal/repl.rb` (#2048)
88
- - `Encoding.default_external` is now initialized with `__ENCODING__` (#2072)
89
- - Keep the MersenneTwister implementation private (#2108)
90
- - Change parser to 3.0 (#2148)
91
- - Fix forwarding a rescued error to a global var: `rescue => $gvar` (#2154)
92
- - Now using Parser v3.0 and targeting Ruby 3.0 (#2156)
93
- - `Comparable#clamp` to support a Range argument (#2151)
94
- - `#to_h` method to support a block (shortform for `.map(&block).to_h`) (#2151)
95
- - BigDecimal is now a subclass of Numeric (#2006)
96
- - PP to be rebased on upstream Ruby version (#2083)
97
- - String to report UTF-8 encoding by default, as MRI does (#2117)
98
- - Don't output "Failed to load WithCLexer, using pure Ruby lexer" warning unless in $DEBUG mode (#2174)
99
-
100
4
  ### Deprecated
101
-
102
- - Requiring nodejs/stacktrace has been deprecated, source-maps are already
103
- supported by the default Node.js runner or by requiring https://github.com/evanw/node-source-map-support
104
- before loading code compiled by Opal (#2045)
105
-
106
5
  ### Removed
107
-
108
- - Removed special compilation for the `Opal.truthy?` and `Opal.falsy?` helpers (#2076)
109
- - Removed the deprecated `tainting` compiler config option (#2072)
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
- yarn -s browserify -r ./lib/opal/cli_runners/source-map-support.js -o ./lib/opal/cli_runners/source-map-support-browser.js -s sourceMapSupport ~/C/opal
4
-
5
-
3
+ yarn -s browserify -r ./lib/opal/cli_runners/source-map-support.js -o ./lib/opal/cli_runners/source-map-support-browser.js -s sourceMapSupport
4
+ yarn -s browserify -r ./lib/opal/cli_runners/source-map-support.js -o ./lib/opal/cli_runners/source-map-support-node.js --bare -s sourceMapSupport
@@ -17,7 +17,7 @@ module Opal
17
17
  SystemRunner.call(data) do |tempfile|
18
18
  [
19
19
  'node',
20
- '--require', "#{__dir__}/source-map-support",
20
+ '--require', "#{__dir__}/source-map-support-node",
21
21
  tempfile.path,
22
22
  *argv
23
23
  ]
@@ -5804,7 +5804,11 @@ exports.SourceNode = require('./lib/source-node').SourceNode;
5804
5804
 
5805
5805
  },{"./lib/source-map-consumer":14,"./lib/source-map-generator":15,"./lib/source-node":16}],"/lib/opal/cli_runners/source-map-support.js":[function(require,module,exports){
5806
5806
  (function (process){(function (){
5807
- // Taken and adapted from the work of Evan Wallace
5807
+ // IMPORTANT NOTICE:
5808
+ // Remember to update the browser version whenever this file is changed,
5809
+ // to do so, `run bin/build-browser-source-map-support`
5810
+
5811
+ // The following is taken and adapted from the work of Evan Wallace
5808
5812
  // https://github.com/evanw/node-source-map-support v0.5.12
5809
5813
 
5810
5814
  // The MIT License (MIT)
@@ -0,0 +1,3704 @@
1
+ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.sourceMapSupport = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2
+ var toString = Object.prototype.toString
3
+
4
+ var isModern = (
5
+ typeof Buffer.alloc === 'function' &&
6
+ typeof Buffer.allocUnsafe === 'function' &&
7
+ typeof Buffer.from === 'function'
8
+ )
9
+
10
+ function isArrayBuffer (input) {
11
+ return toString.call(input).slice(8, -1) === 'ArrayBuffer'
12
+ }
13
+
14
+ function fromArrayBuffer (obj, byteOffset, length) {
15
+ byteOffset >>>= 0
16
+
17
+ var maxLength = obj.byteLength - byteOffset
18
+
19
+ if (maxLength < 0) {
20
+ throw new RangeError("'offset' is out of bounds")
21
+ }
22
+
23
+ if (length === undefined) {
24
+ length = maxLength
25
+ } else {
26
+ length >>>= 0
27
+
28
+ if (length > maxLength) {
29
+ throw new RangeError("'length' is out of bounds")
30
+ }
31
+ }
32
+
33
+ return isModern
34
+ ? Buffer.from(obj.slice(byteOffset, byteOffset + length))
35
+ : new Buffer(new Uint8Array(obj.slice(byteOffset, byteOffset + length)))
36
+ }
37
+
38
+ function fromString (string, encoding) {
39
+ if (typeof encoding !== 'string' || encoding === '') {
40
+ encoding = 'utf8'
41
+ }
42
+
43
+ if (!Buffer.isEncoding(encoding)) {
44
+ throw new TypeError('"encoding" must be a valid string encoding')
45
+ }
46
+
47
+ return isModern
48
+ ? Buffer.from(string, encoding)
49
+ : new Buffer(string, encoding)
50
+ }
51
+
52
+ function bufferFrom (value, encodingOrOffset, length) {
53
+ if (typeof value === 'number') {
54
+ throw new TypeError('"value" argument must not be a number')
55
+ }
56
+
57
+ if (isArrayBuffer(value)) {
58
+ return fromArrayBuffer(value, encodingOrOffset, length)
59
+ }
60
+
61
+ if (typeof value === 'string') {
62
+ return fromString(value, encodingOrOffset)
63
+ }
64
+
65
+ return isModern
66
+ ? Buffer.from(value)
67
+ : new Buffer(value)
68
+ }
69
+
70
+ module.exports = bufferFrom
71
+
72
+ },{}],2:[function(require,module,exports){
73
+ /* -*- Mode: js; js-indent-level: 2; -*- */
74
+ /*
75
+ * Copyright 2011 Mozilla Foundation and contributors
76
+ * Licensed under the New BSD license. See LICENSE or:
77
+ * http://opensource.org/licenses/BSD-3-Clause
78
+ */
79
+
80
+ var util = require('./util');
81
+ var has = Object.prototype.hasOwnProperty;
82
+ var hasNativeMap = typeof Map !== "undefined";
83
+
84
+ /**
85
+ * A data structure which is a combination of an array and a set. Adding a new
86
+ * member is O(1), testing for membership is O(1), and finding the index of an
87
+ * element is O(1). Removing elements from the set is not supported. Only
88
+ * strings are supported for membership.
89
+ */
90
+ function ArraySet() {
91
+ this._array = [];
92
+ this._set = hasNativeMap ? new Map() : Object.create(null);
93
+ }
94
+
95
+ /**
96
+ * Static method for creating ArraySet instances from an existing array.
97
+ */
98
+ ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
99
+ var set = new ArraySet();
100
+ for (var i = 0, len = aArray.length; i < len; i++) {
101
+ set.add(aArray[i], aAllowDuplicates);
102
+ }
103
+ return set;
104
+ };
105
+
106
+ /**
107
+ * Return how many unique items are in this ArraySet. If duplicates have been
108
+ * added, than those do not count towards the size.
109
+ *
110
+ * @returns Number
111
+ */
112
+ ArraySet.prototype.size = function ArraySet_size() {
113
+ return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
114
+ };
115
+
116
+ /**
117
+ * Add the given string to this set.
118
+ *
119
+ * @param String aStr
120
+ */
121
+ ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
122
+ var sStr = hasNativeMap ? aStr : util.toSetString(aStr);
123
+ var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
124
+ var idx = this._array.length;
125
+ if (!isDuplicate || aAllowDuplicates) {
126
+ this._array.push(aStr);
127
+ }
128
+ if (!isDuplicate) {
129
+ if (hasNativeMap) {
130
+ this._set.set(aStr, idx);
131
+ } else {
132
+ this._set[sStr] = idx;
133
+ }
134
+ }
135
+ };
136
+
137
+ /**
138
+ * Is the given string a member of this set?
139
+ *
140
+ * @param String aStr
141
+ */
142
+ ArraySet.prototype.has = function ArraySet_has(aStr) {
143
+ if (hasNativeMap) {
144
+ return this._set.has(aStr);
145
+ } else {
146
+ var sStr = util.toSetString(aStr);
147
+ return has.call(this._set, sStr);
148
+ }
149
+ };
150
+
151
+ /**
152
+ * What is the index of the given string in the array?
153
+ *
154
+ * @param String aStr
155
+ */
156
+ ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
157
+ if (hasNativeMap) {
158
+ var idx = this._set.get(aStr);
159
+ if (idx >= 0) {
160
+ return idx;
161
+ }
162
+ } else {
163
+ var sStr = util.toSetString(aStr);
164
+ if (has.call(this._set, sStr)) {
165
+ return this._set[sStr];
166
+ }
167
+ }
168
+
169
+ throw new Error('"' + aStr + '" is not in the set.');
170
+ };
171
+
172
+ /**
173
+ * What is the element at the given index?
174
+ *
175
+ * @param Number aIdx
176
+ */
177
+ ArraySet.prototype.at = function ArraySet_at(aIdx) {
178
+ if (aIdx >= 0 && aIdx < this._array.length) {
179
+ return this._array[aIdx];
180
+ }
181
+ throw new Error('No element indexed by ' + aIdx);
182
+ };
183
+
184
+ /**
185
+ * Returns the array representation of this set (which has the proper indices
186
+ * indicated by indexOf). Note that this is a copy of the internal array used
187
+ * for storing the members so that no one can mess with internal state.
188
+ */
189
+ ArraySet.prototype.toArray = function ArraySet_toArray() {
190
+ return this._array.slice();
191
+ };
192
+
193
+ exports.ArraySet = ArraySet;
194
+
195
+ },{"./util":11}],3:[function(require,module,exports){
196
+ /* -*- Mode: js; js-indent-level: 2; -*- */
197
+ /*
198
+ * Copyright 2011 Mozilla Foundation and contributors
199
+ * Licensed under the New BSD license. See LICENSE or:
200
+ * http://opensource.org/licenses/BSD-3-Clause
201
+ *
202
+ * Based on the Base 64 VLQ implementation in Closure Compiler:
203
+ * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
204
+ *
205
+ * Copyright 2011 The Closure Compiler Authors. All rights reserved.
206
+ * Redistribution and use in source and binary forms, with or without
207
+ * modification, are permitted provided that the following conditions are
208
+ * met:
209
+ *
210
+ * * Redistributions of source code must retain the above copyright
211
+ * notice, this list of conditions and the following disclaimer.
212
+ * * Redistributions in binary form must reproduce the above
213
+ * copyright notice, this list of conditions and the following
214
+ * disclaimer in the documentation and/or other materials provided
215
+ * with the distribution.
216
+ * * Neither the name of Google Inc. nor the names of its
217
+ * contributors may be used to endorse or promote products derived
218
+ * from this software without specific prior written permission.
219
+ *
220
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
221
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
222
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
223
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
224
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
225
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
227
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
228
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
229
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
230
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
231
+ */
232
+
233
+ var base64 = require('./base64');
234
+
235
+ // A single base 64 digit can contain 6 bits of data. For the base 64 variable
236
+ // length quantities we use in the source map spec, the first bit is the sign,
237
+ // the next four bits are the actual value, and the 6th bit is the
238
+ // continuation bit. The continuation bit tells us whether there are more
239
+ // digits in this value following this digit.
240
+ //
241
+ // Continuation
242
+ // | Sign
243
+ // | |
244
+ // V V
245
+ // 101011
246
+
247
+ var VLQ_BASE_SHIFT = 5;
248
+
249
+ // binary: 100000
250
+ var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
251
+
252
+ // binary: 011111
253
+ var VLQ_BASE_MASK = VLQ_BASE - 1;
254
+
255
+ // binary: 100000
256
+ var VLQ_CONTINUATION_BIT = VLQ_BASE;
257
+
258
+ /**
259
+ * Converts from a two-complement value to a value where the sign bit is
260
+ * placed in the least significant bit. For example, as decimals:
261
+ * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
262
+ * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
263
+ */
264
+ function toVLQSigned(aValue) {
265
+ return aValue < 0
266
+ ? ((-aValue) << 1) + 1
267
+ : (aValue << 1) + 0;
268
+ }
269
+
270
+ /**
271
+ * Converts to a two-complement value from a value where the sign bit is
272
+ * placed in the least significant bit. For example, as decimals:
273
+ * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
274
+ * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
275
+ */
276
+ function fromVLQSigned(aValue) {
277
+ var isNegative = (aValue & 1) === 1;
278
+ var shifted = aValue >> 1;
279
+ return isNegative
280
+ ? -shifted
281
+ : shifted;
282
+ }
283
+
284
+ /**
285
+ * Returns the base 64 VLQ encoded value.
286
+ */
287
+ exports.encode = function base64VLQ_encode(aValue) {
288
+ var encoded = "";
289
+ var digit;
290
+
291
+ var vlq = toVLQSigned(aValue);
292
+
293
+ do {
294
+ digit = vlq & VLQ_BASE_MASK;
295
+ vlq >>>= VLQ_BASE_SHIFT;
296
+ if (vlq > 0) {
297
+ // There are still more digits in this value, so we must make sure the
298
+ // continuation bit is marked.
299
+ digit |= VLQ_CONTINUATION_BIT;
300
+ }
301
+ encoded += base64.encode(digit);
302
+ } while (vlq > 0);
303
+
304
+ return encoded;
305
+ };
306
+
307
+ /**
308
+ * Decodes the next base 64 VLQ value from the given string and returns the
309
+ * value and the rest of the string via the out parameter.
310
+ */
311
+ exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
312
+ var strLen = aStr.length;
313
+ var result = 0;
314
+ var shift = 0;
315
+ var continuation, digit;
316
+
317
+ do {
318
+ if (aIndex >= strLen) {
319
+ throw new Error("Expected more digits in base 64 VLQ value.");
320
+ }
321
+
322
+ digit = base64.decode(aStr.charCodeAt(aIndex++));
323
+ if (digit === -1) {
324
+ throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
325
+ }
326
+
327
+ continuation = !!(digit & VLQ_CONTINUATION_BIT);
328
+ digit &= VLQ_BASE_MASK;
329
+ result = result + (digit << shift);
330
+ shift += VLQ_BASE_SHIFT;
331
+ } while (continuation);
332
+
333
+ aOutParam.value = fromVLQSigned(result);
334
+ aOutParam.rest = aIndex;
335
+ };
336
+
337
+ },{"./base64":4}],4:[function(require,module,exports){
338
+ /* -*- Mode: js; js-indent-level: 2; -*- */
339
+ /*
340
+ * Copyright 2011 Mozilla Foundation and contributors
341
+ * Licensed under the New BSD license. See LICENSE or:
342
+ * http://opensource.org/licenses/BSD-3-Clause
343
+ */
344
+
345
+ var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
346
+
347
+ /**
348
+ * Encode an integer in the range of 0 to 63 to a single base 64 digit.
349
+ */
350
+ exports.encode = function (number) {
351
+ if (0 <= number && number < intToCharMap.length) {
352
+ return intToCharMap[number];
353
+ }
354
+ throw new TypeError("Must be between 0 and 63: " + number);
355
+ };
356
+
357
+ /**
358
+ * Decode a single base 64 character code digit to an integer. Returns -1 on
359
+ * failure.
360
+ */
361
+ exports.decode = function (charCode) {
362
+ var bigA = 65; // 'A'
363
+ var bigZ = 90; // 'Z'
364
+
365
+ var littleA = 97; // 'a'
366
+ var littleZ = 122; // 'z'
367
+
368
+ var zero = 48; // '0'
369
+ var nine = 57; // '9'
370
+
371
+ var plus = 43; // '+'
372
+ var slash = 47; // '/'
373
+
374
+ var littleOffset = 26;
375
+ var numberOffset = 52;
376
+
377
+ // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
378
+ if (bigA <= charCode && charCode <= bigZ) {
379
+ return (charCode - bigA);
380
+ }
381
+
382
+ // 26 - 51: abcdefghijklmnopqrstuvwxyz
383
+ if (littleA <= charCode && charCode <= littleZ) {
384
+ return (charCode - littleA + littleOffset);
385
+ }
386
+
387
+ // 52 - 61: 0123456789
388
+ if (zero <= charCode && charCode <= nine) {
389
+ return (charCode - zero + numberOffset);
390
+ }
391
+
392
+ // 62: +
393
+ if (charCode == plus) {
394
+ return 62;
395
+ }
396
+
397
+ // 63: /
398
+ if (charCode == slash) {
399
+ return 63;
400
+ }
401
+
402
+ // Invalid base64 digit.
403
+ return -1;
404
+ };
405
+
406
+ },{}],5:[function(require,module,exports){
407
+ /* -*- Mode: js; js-indent-level: 2; -*- */
408
+ /*
409
+ * Copyright 2011 Mozilla Foundation and contributors
410
+ * Licensed under the New BSD license. See LICENSE or:
411
+ * http://opensource.org/licenses/BSD-3-Clause
412
+ */
413
+
414
+ exports.GREATEST_LOWER_BOUND = 1;
415
+ exports.LEAST_UPPER_BOUND = 2;
416
+
417
+ /**
418
+ * Recursive implementation of binary search.
419
+ *
420
+ * @param aLow Indices here and lower do not contain the needle.
421
+ * @param aHigh Indices here and higher do not contain the needle.
422
+ * @param aNeedle The element being searched for.
423
+ * @param aHaystack The non-empty array being searched.
424
+ * @param aCompare Function which takes two elements and returns -1, 0, or 1.
425
+ * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
426
+ * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
427
+ * closest element that is smaller than or greater than the one we are
428
+ * searching for, respectively, if the exact element cannot be found.
429
+ */
430
+ function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
431
+ // This function terminates when one of the following is true:
432
+ //
433
+ // 1. We find the exact element we are looking for.
434
+ //
435
+ // 2. We did not find the exact element, but we can return the index of
436
+ // the next-closest element.
437
+ //
438
+ // 3. We did not find the exact element, and there is no next-closest
439
+ // element than the one we are searching for, so we return -1.
440
+ var mid = Math.floor((aHigh - aLow) / 2) + aLow;
441
+ var cmp = aCompare(aNeedle, aHaystack[mid], true);
442
+ if (cmp === 0) {
443
+ // Found the element we are looking for.
444
+ return mid;
445
+ }
446
+ else if (cmp > 0) {
447
+ // Our needle is greater than aHaystack[mid].
448
+ if (aHigh - mid > 1) {
449
+ // The element is in the upper half.
450
+ return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
451
+ }
452
+
453
+ // The exact needle element was not found in this haystack. Determine if
454
+ // we are in termination case (3) or (2) and return the appropriate thing.
455
+ if (aBias == exports.LEAST_UPPER_BOUND) {
456
+ return aHigh < aHaystack.length ? aHigh : -1;
457
+ } else {
458
+ return mid;
459
+ }
460
+ }
461
+ else {
462
+ // Our needle is less than aHaystack[mid].
463
+ if (mid - aLow > 1) {
464
+ // The element is in the lower half.
465
+ return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
466
+ }
467
+
468
+ // we are in termination case (3) or (2) and return the appropriate thing.
469
+ if (aBias == exports.LEAST_UPPER_BOUND) {
470
+ return mid;
471
+ } else {
472
+ return aLow < 0 ? -1 : aLow;
473
+ }
474
+ }
475
+ }
476
+
477
+ /**
478
+ * This is an implementation of binary search which will always try and return
479
+ * the index of the closest element if there is no exact hit. This is because
480
+ * mappings between original and generated line/col pairs are single points,
481
+ * and there is an implicit region between each of them, so a miss just means
482
+ * that you aren't on the very start of a region.
483
+ *
484
+ * @param aNeedle The element you are looking for.
485
+ * @param aHaystack The array that is being searched.
486
+ * @param aCompare A function which takes the needle and an element in the
487
+ * array and returns -1, 0, or 1 depending on whether the needle is less
488
+ * than, equal to, or greater than the element, respectively.
489
+ * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
490
+ * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
491
+ * closest element that is smaller than or greater than the one we are
492
+ * searching for, respectively, if the exact element cannot be found.
493
+ * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
494
+ */
495
+ exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
496
+ if (aHaystack.length === 0) {
497
+ return -1;
498
+ }
499
+
500
+ var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
501
+ aCompare, aBias || exports.GREATEST_LOWER_BOUND);
502
+ if (index < 0) {
503
+ return -1;
504
+ }
505
+
506
+ // We have found either the exact element, or the next-closest element than
507
+ // the one we are searching for. However, there may be more than one such
508
+ // element. Make sure we always return the smallest of these.
509
+ while (index - 1 >= 0) {
510
+ if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
511
+ break;
512
+ }
513
+ --index;
514
+ }
515
+
516
+ return index;
517
+ };
518
+
519
+ },{}],6:[function(require,module,exports){
520
+ /* -*- Mode: js; js-indent-level: 2; -*- */
521
+ /*
522
+ * Copyright 2014 Mozilla Foundation and contributors
523
+ * Licensed under the New BSD license. See LICENSE or:
524
+ * http://opensource.org/licenses/BSD-3-Clause
525
+ */
526
+
527
+ var util = require('./util');
528
+
529
+ /**
530
+ * Determine whether mappingB is after mappingA with respect to generated
531
+ * position.
532
+ */
533
+ function generatedPositionAfter(mappingA, mappingB) {
534
+ // Optimized for most common case
535
+ var lineA = mappingA.generatedLine;
536
+ var lineB = mappingB.generatedLine;
537
+ var columnA = mappingA.generatedColumn;
538
+ var columnB = mappingB.generatedColumn;
539
+ return lineB > lineA || lineB == lineA && columnB >= columnA ||
540
+ util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
541
+ }
542
+
543
+ /**
544
+ * A data structure to provide a sorted view of accumulated mappings in a
545
+ * performance conscious manner. It trades a neglibable overhead in general
546
+ * case for a large speedup in case of mappings being added in order.
547
+ */
548
+ function MappingList() {
549
+ this._array = [];
550
+ this._sorted = true;
551
+ // Serves as infimum
552
+ this._last = {generatedLine: -1, generatedColumn: 0};
553
+ }
554
+
555
+ /**
556
+ * Iterate through internal items. This method takes the same arguments that
557
+ * `Array.prototype.forEach` takes.
558
+ *
559
+ * NOTE: The order of the mappings is NOT guaranteed.
560
+ */
561
+ MappingList.prototype.unsortedForEach =
562
+ function MappingList_forEach(aCallback, aThisArg) {
563
+ this._array.forEach(aCallback, aThisArg);
564
+ };
565
+
566
+ /**
567
+ * Add the given source mapping.
568
+ *
569
+ * @param Object aMapping
570
+ */
571
+ MappingList.prototype.add = function MappingList_add(aMapping) {
572
+ if (generatedPositionAfter(this._last, aMapping)) {
573
+ this._last = aMapping;
574
+ this._array.push(aMapping);
575
+ } else {
576
+ this._sorted = false;
577
+ this._array.push(aMapping);
578
+ }
579
+ };
580
+
581
+ /**
582
+ * Returns the flat, sorted array of mappings. The mappings are sorted by
583
+ * generated position.
584
+ *
585
+ * WARNING: This method returns internal data without copying, for
586
+ * performance. The return value must NOT be mutated, and should be treated as
587
+ * an immutable borrow. If you want to take ownership, you must make your own
588
+ * copy.
589
+ */
590
+ MappingList.prototype.toArray = function MappingList_toArray() {
591
+ if (!this._sorted) {
592
+ this._array.sort(util.compareByGeneratedPositionsInflated);
593
+ this._sorted = true;
594
+ }
595
+ return this._array;
596
+ };
597
+
598
+ exports.MappingList = MappingList;
599
+
600
+ },{"./util":11}],7:[function(require,module,exports){
601
+ /* -*- Mode: js; js-indent-level: 2; -*- */
602
+ /*
603
+ * Copyright 2011 Mozilla Foundation and contributors
604
+ * Licensed under the New BSD license. See LICENSE or:
605
+ * http://opensource.org/licenses/BSD-3-Clause
606
+ */
607
+
608
+ // It turns out that some (most?) JavaScript engines don't self-host
609
+ // `Array.prototype.sort`. This makes sense because C++ will likely remain
610
+ // faster than JS when doing raw CPU-intensive sorting. However, when using a
611
+ // custom comparator function, calling back and forth between the VM's C++ and
612
+ // JIT'd JS is rather slow *and* loses JIT type information, resulting in
613
+ // worse generated code for the comparator function than would be optimal. In
614
+ // fact, when sorting with a comparator, these costs outweigh the benefits of
615
+ // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
616
+ // a ~3500ms mean speed-up in `bench/bench.html`.
617
+
618
+ /**
619
+ * Swap the elements indexed by `x` and `y` in the array `ary`.
620
+ *
621
+ * @param {Array} ary
622
+ * The array.
623
+ * @param {Number} x
624
+ * The index of the first item.
625
+ * @param {Number} y
626
+ * The index of the second item.
627
+ */
628
+ function swap(ary, x, y) {
629
+ var temp = ary[x];
630
+ ary[x] = ary[y];
631
+ ary[y] = temp;
632
+ }
633
+
634
+ /**
635
+ * Returns a random integer within the range `low .. high` inclusive.
636
+ *
637
+ * @param {Number} low
638
+ * The lower bound on the range.
639
+ * @param {Number} high
640
+ * The upper bound on the range.
641
+ */
642
+ function randomIntInRange(low, high) {
643
+ return Math.round(low + (Math.random() * (high - low)));
644
+ }
645
+
646
+ /**
647
+ * The Quick Sort algorithm.
648
+ *
649
+ * @param {Array} ary
650
+ * An array to sort.
651
+ * @param {function} comparator
652
+ * Function to use to compare two items.
653
+ * @param {Number} p
654
+ * Start index of the array
655
+ * @param {Number} r
656
+ * End index of the array
657
+ */
658
+ function doQuickSort(ary, comparator, p, r) {
659
+ // If our lower bound is less than our upper bound, we (1) partition the
660
+ // array into two pieces and (2) recurse on each half. If it is not, this is
661
+ // the empty array and our base case.
662
+
663
+ if (p < r) {
664
+ // (1) Partitioning.
665
+ //
666
+ // The partitioning chooses a pivot between `p` and `r` and moves all
667
+ // elements that are less than or equal to the pivot to the before it, and
668
+ // all the elements that are greater than it after it. The effect is that
669
+ // once partition is done, the pivot is in the exact place it will be when
670
+ // the array is put in sorted order, and it will not need to be moved
671
+ // again. This runs in O(n) time.
672
+
673
+ // Always choose a random pivot so that an input array which is reverse
674
+ // sorted does not cause O(n^2) running time.
675
+ var pivotIndex = randomIntInRange(p, r);
676
+ var i = p - 1;
677
+
678
+ swap(ary, pivotIndex, r);
679
+ var pivot = ary[r];
680
+
681
+ // Immediately after `j` is incremented in this loop, the following hold
682
+ // true:
683
+ //
684
+ // * Every element in `ary[p .. i]` is less than or equal to the pivot.
685
+ //
686
+ // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
687
+ for (var j = p; j < r; j++) {
688
+ if (comparator(ary[j], pivot) <= 0) {
689
+ i += 1;
690
+ swap(ary, i, j);
691
+ }
692
+ }
693
+
694
+ swap(ary, i + 1, j);
695
+ var q = i + 1;
696
+
697
+ // (2) Recurse on each half.
698
+
699
+ doQuickSort(ary, comparator, p, q - 1);
700
+ doQuickSort(ary, comparator, q + 1, r);
701
+ }
702
+ }
703
+
704
+ /**
705
+ * Sort the given array in-place with the given comparator function.
706
+ *
707
+ * @param {Array} ary
708
+ * An array to sort.
709
+ * @param {function} comparator
710
+ * Function to use to compare two items.
711
+ */
712
+ exports.quickSort = function (ary, comparator) {
713
+ doQuickSort(ary, comparator, 0, ary.length - 1);
714
+ };
715
+
716
+ },{}],8:[function(require,module,exports){
717
+ /* -*- Mode: js; js-indent-level: 2; -*- */
718
+ /*
719
+ * Copyright 2011 Mozilla Foundation and contributors
720
+ * Licensed under the New BSD license. See LICENSE or:
721
+ * http://opensource.org/licenses/BSD-3-Clause
722
+ */
723
+
724
+ var util = require('./util');
725
+ var binarySearch = require('./binary-search');
726
+ var ArraySet = require('./array-set').ArraySet;
727
+ var base64VLQ = require('./base64-vlq');
728
+ var quickSort = require('./quick-sort').quickSort;
729
+
730
+ function SourceMapConsumer(aSourceMap) {
731
+ var sourceMap = aSourceMap;
732
+ if (typeof aSourceMap === 'string') {
733
+ sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
734
+ }
735
+
736
+ return sourceMap.sections != null
737
+ ? new IndexedSourceMapConsumer(sourceMap)
738
+ : new BasicSourceMapConsumer(sourceMap);
739
+ }
740
+
741
+ SourceMapConsumer.fromSourceMap = function(aSourceMap) {
742
+ return BasicSourceMapConsumer.fromSourceMap(aSourceMap);
743
+ }
744
+
745
+ /**
746
+ * The version of the source mapping spec that we are consuming.
747
+ */
748
+ SourceMapConsumer.prototype._version = 3;
749
+
750
+ // `__generatedMappings` and `__originalMappings` are arrays that hold the
751
+ // parsed mapping coordinates from the source map's "mappings" attribute. They
752
+ // are lazily instantiated, accessed via the `_generatedMappings` and
753
+ // `_originalMappings` getters respectively, and we only parse the mappings
754
+ // and create these arrays once queried for a source location. We jump through
755
+ // these hoops because there can be many thousands of mappings, and parsing
756
+ // them is expensive, so we only want to do it if we must.
757
+ //
758
+ // Each object in the arrays is of the form:
759
+ //
760
+ // {
761
+ // generatedLine: The line number in the generated code,
762
+ // generatedColumn: The column number in the generated code,
763
+ // source: The path to the original source file that generated this
764
+ // chunk of code,
765
+ // originalLine: The line number in the original source that
766
+ // corresponds to this chunk of generated code,
767
+ // originalColumn: The column number in the original source that
768
+ // corresponds to this chunk of generated code,
769
+ // name: The name of the original symbol which generated this chunk of
770
+ // code.
771
+ // }
772
+ //
773
+ // All properties except for `generatedLine` and `generatedColumn` can be
774
+ // `null`.
775
+ //
776
+ // `_generatedMappings` is ordered by the generated positions.
777
+ //
778
+ // `_originalMappings` is ordered by the original positions.
779
+
780
+ SourceMapConsumer.prototype.__generatedMappings = null;
781
+ Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
782
+ get: function () {
783
+ if (!this.__generatedMappings) {
784
+ this._parseMappings(this._mappings, this.sourceRoot);
785
+ }
786
+
787
+ return this.__generatedMappings;
788
+ }
789
+ });
790
+
791
+ SourceMapConsumer.prototype.__originalMappings = null;
792
+ Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
793
+ get: function () {
794
+ if (!this.__originalMappings) {
795
+ this._parseMappings(this._mappings, this.sourceRoot);
796
+ }
797
+
798
+ return this.__originalMappings;
799
+ }
800
+ });
801
+
802
+ SourceMapConsumer.prototype._charIsMappingSeparator =
803
+ function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
804
+ var c = aStr.charAt(index);
805
+ return c === ";" || c === ",";
806
+ };
807
+
808
+ /**
809
+ * Parse the mappings in a string in to a data structure which we can easily
810
+ * query (the ordered arrays in the `this.__generatedMappings` and
811
+ * `this.__originalMappings` properties).
812
+ */
813
+ SourceMapConsumer.prototype._parseMappings =
814
+ function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
815
+ throw new Error("Subclasses must implement _parseMappings");
816
+ };
817
+
818
+ SourceMapConsumer.GENERATED_ORDER = 1;
819
+ SourceMapConsumer.ORIGINAL_ORDER = 2;
820
+
821
+ SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
822
+ SourceMapConsumer.LEAST_UPPER_BOUND = 2;
823
+
824
+ /**
825
+ * Iterate over each mapping between an original source/line/column and a
826
+ * generated line/column in this source map.
827
+ *
828
+ * @param Function aCallback
829
+ * The function that is called with each mapping.
830
+ * @param Object aContext
831
+ * Optional. If specified, this object will be the value of `this` every
832
+ * time that `aCallback` is called.
833
+ * @param aOrder
834
+ * Either `SourceMapConsumer.GENERATED_ORDER` or
835
+ * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
836
+ * iterate over the mappings sorted by the generated file's line/column
837
+ * order or the original's source/line/column order, respectively. Defaults to
838
+ * `SourceMapConsumer.GENERATED_ORDER`.
839
+ */
840
+ SourceMapConsumer.prototype.eachMapping =
841
+ function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
842
+ var context = aContext || null;
843
+ var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
844
+
845
+ var mappings;
846
+ switch (order) {
847
+ case SourceMapConsumer.GENERATED_ORDER:
848
+ mappings = this._generatedMappings;
849
+ break;
850
+ case SourceMapConsumer.ORIGINAL_ORDER:
851
+ mappings = this._originalMappings;
852
+ break;
853
+ default:
854
+ throw new Error("Unknown order of iteration.");
855
+ }
856
+
857
+ var sourceRoot = this.sourceRoot;
858
+ mappings.map(function (mapping) {
859
+ var source = mapping.source === null ? null : this._sources.at(mapping.source);
860
+ if (source != null && sourceRoot != null) {
861
+ source = util.join(sourceRoot, source);
862
+ }
863
+ return {
864
+ source: source,
865
+ generatedLine: mapping.generatedLine,
866
+ generatedColumn: mapping.generatedColumn,
867
+ originalLine: mapping.originalLine,
868
+ originalColumn: mapping.originalColumn,
869
+ name: mapping.name === null ? null : this._names.at(mapping.name)
870
+ };
871
+ }, this).forEach(aCallback, context);
872
+ };
873
+
874
+ /**
875
+ * Returns all generated line and column information for the original source,
876
+ * line, and column provided. If no column is provided, returns all mappings
877
+ * corresponding to a either the line we are searching for or the next
878
+ * closest line that has any mappings. Otherwise, returns all mappings
879
+ * corresponding to the given line and either the column we are searching for
880
+ * or the next closest column that has any offsets.
881
+ *
882
+ * The only argument is an object with the following properties:
883
+ *
884
+ * - source: The filename of the original source.
885
+ * - line: The line number in the original source.
886
+ * - column: Optional. the column number in the original source.
887
+ *
888
+ * and an array of objects is returned, each with the following properties:
889
+ *
890
+ * - line: The line number in the generated source, or null.
891
+ * - column: The column number in the generated source, or null.
892
+ */
893
+ SourceMapConsumer.prototype.allGeneratedPositionsFor =
894
+ function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
895
+ var line = util.getArg(aArgs, 'line');
896
+
897
+ // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
898
+ // returns the index of the closest mapping less than the needle. By
899
+ // setting needle.originalColumn to 0, we thus find the last mapping for
900
+ // the given line, provided such a mapping exists.
901
+ var needle = {
902
+ source: util.getArg(aArgs, 'source'),
903
+ originalLine: line,
904
+ originalColumn: util.getArg(aArgs, 'column', 0)
905
+ };
906
+
907
+ if (this.sourceRoot != null) {
908
+ needle.source = util.relative(this.sourceRoot, needle.source);
909
+ }
910
+ if (!this._sources.has(needle.source)) {
911
+ return [];
912
+ }
913
+ needle.source = this._sources.indexOf(needle.source);
914
+
915
+ var mappings = [];
916
+
917
+ var index = this._findMapping(needle,
918
+ this._originalMappings,
919
+ "originalLine",
920
+ "originalColumn",
921
+ util.compareByOriginalPositions,
922
+ binarySearch.LEAST_UPPER_BOUND);
923
+ if (index >= 0) {
924
+ var mapping = this._originalMappings[index];
925
+
926
+ if (aArgs.column === undefined) {
927
+ var originalLine = mapping.originalLine;
928
+
929
+ // Iterate until either we run out of mappings, or we run into
930
+ // a mapping for a different line than the one we found. Since
931
+ // mappings are sorted, this is guaranteed to find all mappings for
932
+ // the line we found.
933
+ while (mapping && mapping.originalLine === originalLine) {
934
+ mappings.push({
935
+ line: util.getArg(mapping, 'generatedLine', null),
936
+ column: util.getArg(mapping, 'generatedColumn', null),
937
+ lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
938
+ });
939
+
940
+ mapping = this._originalMappings[++index];
941
+ }
942
+ } else {
943
+ var originalColumn = mapping.originalColumn;
944
+
945
+ // Iterate until either we run out of mappings, or we run into
946
+ // a mapping for a different line than the one we were searching for.
947
+ // Since mappings are sorted, this is guaranteed to find all mappings for
948
+ // the line we are searching for.
949
+ while (mapping &&
950
+ mapping.originalLine === line &&
951
+ mapping.originalColumn == originalColumn) {
952
+ mappings.push({
953
+ line: util.getArg(mapping, 'generatedLine', null),
954
+ column: util.getArg(mapping, 'generatedColumn', null),
955
+ lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
956
+ });
957
+
958
+ mapping = this._originalMappings[++index];
959
+ }
960
+ }
961
+ }
962
+
963
+ return mappings;
964
+ };
965
+
966
+ exports.SourceMapConsumer = SourceMapConsumer;
967
+
968
+ /**
969
+ * A BasicSourceMapConsumer instance represents a parsed source map which we can
970
+ * query for information about the original file positions by giving it a file
971
+ * position in the generated source.
972
+ *
973
+ * The only parameter is the raw source map (either as a JSON string, or
974
+ * already parsed to an object). According to the spec, source maps have the
975
+ * following attributes:
976
+ *
977
+ * - version: Which version of the source map spec this map is following.
978
+ * - sources: An array of URLs to the original source files.
979
+ * - names: An array of identifiers which can be referrenced by individual mappings.
980
+ * - sourceRoot: Optional. The URL root from which all sources are relative.
981
+ * - sourcesContent: Optional. An array of contents of the original source files.
982
+ * - mappings: A string of base64 VLQs which contain the actual mappings.
983
+ * - file: Optional. The generated file this source map is associated with.
984
+ *
985
+ * Here is an example source map, taken from the source map spec[0]:
986
+ *
987
+ * {
988
+ * version : 3,
989
+ * file: "out.js",
990
+ * sourceRoot : "",
991
+ * sources: ["foo.js", "bar.js"],
992
+ * names: ["src", "maps", "are", "fun"],
993
+ * mappings: "AA,AB;;ABCDE;"
994
+ * }
995
+ *
996
+ * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
997
+ */
998
+ function BasicSourceMapConsumer(aSourceMap) {
999
+ var sourceMap = aSourceMap;
1000
+ if (typeof aSourceMap === 'string') {
1001
+ sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
1002
+ }
1003
+
1004
+ var version = util.getArg(sourceMap, 'version');
1005
+ var sources = util.getArg(sourceMap, 'sources');
1006
+ // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
1007
+ // requires the array) to play nice here.
1008
+ var names = util.getArg(sourceMap, 'names', []);
1009
+ var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
1010
+ var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
1011
+ var mappings = util.getArg(sourceMap, 'mappings');
1012
+ var file = util.getArg(sourceMap, 'file', null);
1013
+
1014
+ // Once again, Sass deviates from the spec and supplies the version as a
1015
+ // string rather than a number, so we use loose equality checking here.
1016
+ if (version != this._version) {
1017
+ throw new Error('Unsupported version: ' + version);
1018
+ }
1019
+
1020
+ sources = sources
1021
+ .map(String)
1022
+ // Some source maps produce relative source paths like "./foo.js" instead of
1023
+ // "foo.js". Normalize these first so that future comparisons will succeed.
1024
+ // See bugzil.la/1090768.
1025
+ .map(util.normalize)
1026
+ // Always ensure that absolute sources are internally stored relative to
1027
+ // the source root, if the source root is absolute. Not doing this would
1028
+ // be particularly problematic when the source root is a prefix of the
1029
+ // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
1030
+ .map(function (source) {
1031
+ return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
1032
+ ? util.relative(sourceRoot, source)
1033
+ : source;
1034
+ });
1035
+
1036
+ // Pass `true` below to allow duplicate names and sources. While source maps
1037
+ // are intended to be compressed and deduplicated, the TypeScript compiler
1038
+ // sometimes generates source maps with duplicates in them. See Github issue
1039
+ // #72 and bugzil.la/889492.
1040
+ this._names = ArraySet.fromArray(names.map(String), true);
1041
+ this._sources = ArraySet.fromArray(sources, true);
1042
+
1043
+ this.sourceRoot = sourceRoot;
1044
+ this.sourcesContent = sourcesContent;
1045
+ this._mappings = mappings;
1046
+ this.file = file;
1047
+ }
1048
+
1049
+ BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
1050
+ BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
1051
+
1052
+ /**
1053
+ * Create a BasicSourceMapConsumer from a SourceMapGenerator.
1054
+ *
1055
+ * @param SourceMapGenerator aSourceMap
1056
+ * The source map that will be consumed.
1057
+ * @returns BasicSourceMapConsumer
1058
+ */
1059
+ BasicSourceMapConsumer.fromSourceMap =
1060
+ function SourceMapConsumer_fromSourceMap(aSourceMap) {
1061
+ var smc = Object.create(BasicSourceMapConsumer.prototype);
1062
+
1063
+ var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
1064
+ var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
1065
+ smc.sourceRoot = aSourceMap._sourceRoot;
1066
+ smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
1067
+ smc.sourceRoot);
1068
+ smc.file = aSourceMap._file;
1069
+
1070
+ // Because we are modifying the entries (by converting string sources and
1071
+ // names to indices into the sources and names ArraySets), we have to make
1072
+ // a copy of the entry or else bad things happen. Shared mutable state
1073
+ // strikes again! See github issue #191.
1074
+
1075
+ var generatedMappings = aSourceMap._mappings.toArray().slice();
1076
+ var destGeneratedMappings = smc.__generatedMappings = [];
1077
+ var destOriginalMappings = smc.__originalMappings = [];
1078
+
1079
+ for (var i = 0, length = generatedMappings.length; i < length; i++) {
1080
+ var srcMapping = generatedMappings[i];
1081
+ var destMapping = new Mapping;
1082
+ destMapping.generatedLine = srcMapping.generatedLine;
1083
+ destMapping.generatedColumn = srcMapping.generatedColumn;
1084
+
1085
+ if (srcMapping.source) {
1086
+ destMapping.source = sources.indexOf(srcMapping.source);
1087
+ destMapping.originalLine = srcMapping.originalLine;
1088
+ destMapping.originalColumn = srcMapping.originalColumn;
1089
+
1090
+ if (srcMapping.name) {
1091
+ destMapping.name = names.indexOf(srcMapping.name);
1092
+ }
1093
+
1094
+ destOriginalMappings.push(destMapping);
1095
+ }
1096
+
1097
+ destGeneratedMappings.push(destMapping);
1098
+ }
1099
+
1100
+ quickSort(smc.__originalMappings, util.compareByOriginalPositions);
1101
+
1102
+ return smc;
1103
+ };
1104
+
1105
+ /**
1106
+ * The version of the source mapping spec that we are consuming.
1107
+ */
1108
+ BasicSourceMapConsumer.prototype._version = 3;
1109
+
1110
+ /**
1111
+ * The list of original sources.
1112
+ */
1113
+ Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
1114
+ get: function () {
1115
+ return this._sources.toArray().map(function (s) {
1116
+ return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s;
1117
+ }, this);
1118
+ }
1119
+ });
1120
+
1121
+ /**
1122
+ * Provide the JIT with a nice shape / hidden class.
1123
+ */
1124
+ function Mapping() {
1125
+ this.generatedLine = 0;
1126
+ this.generatedColumn = 0;
1127
+ this.source = null;
1128
+ this.originalLine = null;
1129
+ this.originalColumn = null;
1130
+ this.name = null;
1131
+ }
1132
+
1133
+ /**
1134
+ * Parse the mappings in a string in to a data structure which we can easily
1135
+ * query (the ordered arrays in the `this.__generatedMappings` and
1136
+ * `this.__originalMappings` properties).
1137
+ */
1138
+ BasicSourceMapConsumer.prototype._parseMappings =
1139
+ function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
1140
+ var generatedLine = 1;
1141
+ var previousGeneratedColumn = 0;
1142
+ var previousOriginalLine = 0;
1143
+ var previousOriginalColumn = 0;
1144
+ var previousSource = 0;
1145
+ var previousName = 0;
1146
+ var length = aStr.length;
1147
+ var index = 0;
1148
+ var cachedSegments = {};
1149
+ var temp = {};
1150
+ var originalMappings = [];
1151
+ var generatedMappings = [];
1152
+ var mapping, str, segment, end, value;
1153
+
1154
+ while (index < length) {
1155
+ if (aStr.charAt(index) === ';') {
1156
+ generatedLine++;
1157
+ index++;
1158
+ previousGeneratedColumn = 0;
1159
+ }
1160
+ else if (aStr.charAt(index) === ',') {
1161
+ index++;
1162
+ }
1163
+ else {
1164
+ mapping = new Mapping();
1165
+ mapping.generatedLine = generatedLine;
1166
+
1167
+ // Because each offset is encoded relative to the previous one,
1168
+ // many segments often have the same encoding. We can exploit this
1169
+ // fact by caching the parsed variable length fields of each segment,
1170
+ // allowing us to avoid a second parse if we encounter the same
1171
+ // segment again.
1172
+ for (end = index; end < length; end++) {
1173
+ if (this._charIsMappingSeparator(aStr, end)) {
1174
+ break;
1175
+ }
1176
+ }
1177
+ str = aStr.slice(index, end);
1178
+
1179
+ segment = cachedSegments[str];
1180
+ if (segment) {
1181
+ index += str.length;
1182
+ } else {
1183
+ segment = [];
1184
+ while (index < end) {
1185
+ base64VLQ.decode(aStr, index, temp);
1186
+ value = temp.value;
1187
+ index = temp.rest;
1188
+ segment.push(value);
1189
+ }
1190
+
1191
+ if (segment.length === 2) {
1192
+ throw new Error('Found a source, but no line and column');
1193
+ }
1194
+
1195
+ if (segment.length === 3) {
1196
+ throw new Error('Found a source and line, but no column');
1197
+ }
1198
+
1199
+ cachedSegments[str] = segment;
1200
+ }
1201
+
1202
+ // Generated column.
1203
+ mapping.generatedColumn = previousGeneratedColumn + segment[0];
1204
+ previousGeneratedColumn = mapping.generatedColumn;
1205
+
1206
+ if (segment.length > 1) {
1207
+ // Original source.
1208
+ mapping.source = previousSource + segment[1];
1209
+ previousSource += segment[1];
1210
+
1211
+ // Original line.
1212
+ mapping.originalLine = previousOriginalLine + segment[2];
1213
+ previousOriginalLine = mapping.originalLine;
1214
+ // Lines are stored 0-based
1215
+ mapping.originalLine += 1;
1216
+
1217
+ // Original column.
1218
+ mapping.originalColumn = previousOriginalColumn + segment[3];
1219
+ previousOriginalColumn = mapping.originalColumn;
1220
+
1221
+ if (segment.length > 4) {
1222
+ // Original name.
1223
+ mapping.name = previousName + segment[4];
1224
+ previousName += segment[4];
1225
+ }
1226
+ }
1227
+
1228
+ generatedMappings.push(mapping);
1229
+ if (typeof mapping.originalLine === 'number') {
1230
+ originalMappings.push(mapping);
1231
+ }
1232
+ }
1233
+ }
1234
+
1235
+ quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated);
1236
+ this.__generatedMappings = generatedMappings;
1237
+
1238
+ quickSort(originalMappings, util.compareByOriginalPositions);
1239
+ this.__originalMappings = originalMappings;
1240
+ };
1241
+
1242
+ /**
1243
+ * Find the mapping that best matches the hypothetical "needle" mapping that
1244
+ * we are searching for in the given "haystack" of mappings.
1245
+ */
1246
+ BasicSourceMapConsumer.prototype._findMapping =
1247
+ function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
1248
+ aColumnName, aComparator, aBias) {
1249
+ // To return the position we are searching for, we must first find the
1250
+ // mapping for the given position and then return the opposite position it
1251
+ // points to. Because the mappings are sorted, we can use binary search to
1252
+ // find the best mapping.
1253
+
1254
+ if (aNeedle[aLineName] <= 0) {
1255
+ throw new TypeError('Line must be greater than or equal to 1, got '
1256
+ + aNeedle[aLineName]);
1257
+ }
1258
+ if (aNeedle[aColumnName] < 0) {
1259
+ throw new TypeError('Column must be greater than or equal to 0, got '
1260
+ + aNeedle[aColumnName]);
1261
+ }
1262
+
1263
+ return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
1264
+ };
1265
+
1266
+ /**
1267
+ * Compute the last column for each generated mapping. The last column is
1268
+ * inclusive.
1269
+ */
1270
+ BasicSourceMapConsumer.prototype.computeColumnSpans =
1271
+ function SourceMapConsumer_computeColumnSpans() {
1272
+ for (var index = 0; index < this._generatedMappings.length; ++index) {
1273
+ var mapping = this._generatedMappings[index];
1274
+
1275
+ // Mappings do not contain a field for the last generated columnt. We
1276
+ // can come up with an optimistic estimate, however, by assuming that
1277
+ // mappings are contiguous (i.e. given two consecutive mappings, the
1278
+ // first mapping ends where the second one starts).
1279
+ if (index + 1 < this._generatedMappings.length) {
1280
+ var nextMapping = this._generatedMappings[index + 1];
1281
+
1282
+ if (mapping.generatedLine === nextMapping.generatedLine) {
1283
+ mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
1284
+ continue;
1285
+ }
1286
+ }
1287
+
1288
+ // The last mapping for each line spans the entire line.
1289
+ mapping.lastGeneratedColumn = Infinity;
1290
+ }
1291
+ };
1292
+
1293
+ /**
1294
+ * Returns the original source, line, and column information for the generated
1295
+ * source's line and column positions provided. The only argument is an object
1296
+ * with the following properties:
1297
+ *
1298
+ * - line: The line number in the generated source.
1299
+ * - column: The column number in the generated source.
1300
+ * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
1301
+ * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
1302
+ * closest element that is smaller than or greater than the one we are
1303
+ * searching for, respectively, if the exact element cannot be found.
1304
+ * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
1305
+ *
1306
+ * and an object is returned with the following properties:
1307
+ *
1308
+ * - source: The original source file, or null.
1309
+ * - line: The line number in the original source, or null.
1310
+ * - column: The column number in the original source, or null.
1311
+ * - name: The original identifier, or null.
1312
+ */
1313
+ BasicSourceMapConsumer.prototype.originalPositionFor =
1314
+ function SourceMapConsumer_originalPositionFor(aArgs) {
1315
+ var needle = {
1316
+ generatedLine: util.getArg(aArgs, 'line'),
1317
+ generatedColumn: util.getArg(aArgs, 'column')
1318
+ };
1319
+
1320
+ var index = this._findMapping(
1321
+ needle,
1322
+ this._generatedMappings,
1323
+ "generatedLine",
1324
+ "generatedColumn",
1325
+ util.compareByGeneratedPositionsDeflated,
1326
+ util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
1327
+ );
1328
+
1329
+ if (index >= 0) {
1330
+ var mapping = this._generatedMappings[index];
1331
+
1332
+ if (mapping.generatedLine === needle.generatedLine) {
1333
+ var source = util.getArg(mapping, 'source', null);
1334
+ if (source !== null) {
1335
+ source = this._sources.at(source);
1336
+ if (this.sourceRoot != null) {
1337
+ source = util.join(this.sourceRoot, source);
1338
+ }
1339
+ }
1340
+ var name = util.getArg(mapping, 'name', null);
1341
+ if (name !== null) {
1342
+ name = this._names.at(name);
1343
+ }
1344
+ return {
1345
+ source: source,
1346
+ line: util.getArg(mapping, 'originalLine', null),
1347
+ column: util.getArg(mapping, 'originalColumn', null),
1348
+ name: name
1349
+ };
1350
+ }
1351
+ }
1352
+
1353
+ return {
1354
+ source: null,
1355
+ line: null,
1356
+ column: null,
1357
+ name: null
1358
+ };
1359
+ };
1360
+
1361
+ /**
1362
+ * Return true if we have the source content for every source in the source
1363
+ * map, false otherwise.
1364
+ */
1365
+ BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
1366
+ function BasicSourceMapConsumer_hasContentsOfAllSources() {
1367
+ if (!this.sourcesContent) {
1368
+ return false;
1369
+ }
1370
+ return this.sourcesContent.length >= this._sources.size() &&
1371
+ !this.sourcesContent.some(function (sc) { return sc == null; });
1372
+ };
1373
+
1374
+ /**
1375
+ * Returns the original source content. The only argument is the url of the
1376
+ * original source file. Returns null if no original source content is
1377
+ * available.
1378
+ */
1379
+ BasicSourceMapConsumer.prototype.sourceContentFor =
1380
+ function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
1381
+ if (!this.sourcesContent) {
1382
+ return null;
1383
+ }
1384
+
1385
+ if (this.sourceRoot != null) {
1386
+ aSource = util.relative(this.sourceRoot, aSource);
1387
+ }
1388
+
1389
+ if (this._sources.has(aSource)) {
1390
+ return this.sourcesContent[this._sources.indexOf(aSource)];
1391
+ }
1392
+
1393
+ var url;
1394
+ if (this.sourceRoot != null
1395
+ && (url = util.urlParse(this.sourceRoot))) {
1396
+ // XXX: file:// URIs and absolute paths lead to unexpected behavior for
1397
+ // many users. We can help them out when they expect file:// URIs to
1398
+ // behave like it would if they were running a local HTTP server. See
1399
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
1400
+ var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
1401
+ if (url.scheme == "file"
1402
+ && this._sources.has(fileUriAbsPath)) {
1403
+ return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
1404
+ }
1405
+
1406
+ if ((!url.path || url.path == "/")
1407
+ && this._sources.has("/" + aSource)) {
1408
+ return this.sourcesContent[this._sources.indexOf("/" + aSource)];
1409
+ }
1410
+ }
1411
+
1412
+ // This function is used recursively from
1413
+ // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
1414
+ // don't want to throw if we can't find the source - we just want to
1415
+ // return null, so we provide a flag to exit gracefully.
1416
+ if (nullOnMissing) {
1417
+ return null;
1418
+ }
1419
+ else {
1420
+ throw new Error('"' + aSource + '" is not in the SourceMap.');
1421
+ }
1422
+ };
1423
+
1424
+ /**
1425
+ * Returns the generated line and column information for the original source,
1426
+ * line, and column positions provided. The only argument is an object with
1427
+ * the following properties:
1428
+ *
1429
+ * - source: The filename of the original source.
1430
+ * - line: The line number in the original source.
1431
+ * - column: The column number in the original source.
1432
+ * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
1433
+ * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
1434
+ * closest element that is smaller than or greater than the one we are
1435
+ * searching for, respectively, if the exact element cannot be found.
1436
+ * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
1437
+ *
1438
+ * and an object is returned with the following properties:
1439
+ *
1440
+ * - line: The line number in the generated source, or null.
1441
+ * - column: The column number in the generated source, or null.
1442
+ */
1443
+ BasicSourceMapConsumer.prototype.generatedPositionFor =
1444
+ function SourceMapConsumer_generatedPositionFor(aArgs) {
1445
+ var source = util.getArg(aArgs, 'source');
1446
+ if (this.sourceRoot != null) {
1447
+ source = util.relative(this.sourceRoot, source);
1448
+ }
1449
+ if (!this._sources.has(source)) {
1450
+ return {
1451
+ line: null,
1452
+ column: null,
1453
+ lastColumn: null
1454
+ };
1455
+ }
1456
+ source = this._sources.indexOf(source);
1457
+
1458
+ var needle = {
1459
+ source: source,
1460
+ originalLine: util.getArg(aArgs, 'line'),
1461
+ originalColumn: util.getArg(aArgs, 'column')
1462
+ };
1463
+
1464
+ var index = this._findMapping(
1465
+ needle,
1466
+ this._originalMappings,
1467
+ "originalLine",
1468
+ "originalColumn",
1469
+ util.compareByOriginalPositions,
1470
+ util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
1471
+ );
1472
+
1473
+ if (index >= 0) {
1474
+ var mapping = this._originalMappings[index];
1475
+
1476
+ if (mapping.source === needle.source) {
1477
+ return {
1478
+ line: util.getArg(mapping, 'generatedLine', null),
1479
+ column: util.getArg(mapping, 'generatedColumn', null),
1480
+ lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
1481
+ };
1482
+ }
1483
+ }
1484
+
1485
+ return {
1486
+ line: null,
1487
+ column: null,
1488
+ lastColumn: null
1489
+ };
1490
+ };
1491
+
1492
+ exports.BasicSourceMapConsumer = BasicSourceMapConsumer;
1493
+
1494
+ /**
1495
+ * An IndexedSourceMapConsumer instance represents a parsed source map which
1496
+ * we can query for information. It differs from BasicSourceMapConsumer in
1497
+ * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
1498
+ * input.
1499
+ *
1500
+ * The only parameter is a raw source map (either as a JSON string, or already
1501
+ * parsed to an object). According to the spec for indexed source maps, they
1502
+ * have the following attributes:
1503
+ *
1504
+ * - version: Which version of the source map spec this map is following.
1505
+ * - file: Optional. The generated file this source map is associated with.
1506
+ * - sections: A list of section definitions.
1507
+ *
1508
+ * Each value under the "sections" field has two fields:
1509
+ * - offset: The offset into the original specified at which this section
1510
+ * begins to apply, defined as an object with a "line" and "column"
1511
+ * field.
1512
+ * - map: A source map definition. This source map could also be indexed,
1513
+ * but doesn't have to be.
1514
+ *
1515
+ * Instead of the "map" field, it's also possible to have a "url" field
1516
+ * specifying a URL to retrieve a source map from, but that's currently
1517
+ * unsupported.
1518
+ *
1519
+ * Here's an example source map, taken from the source map spec[0], but
1520
+ * modified to omit a section which uses the "url" field.
1521
+ *
1522
+ * {
1523
+ * version : 3,
1524
+ * file: "app.js",
1525
+ * sections: [{
1526
+ * offset: {line:100, column:10},
1527
+ * map: {
1528
+ * version : 3,
1529
+ * file: "section.js",
1530
+ * sources: ["foo.js", "bar.js"],
1531
+ * names: ["src", "maps", "are", "fun"],
1532
+ * mappings: "AAAA,E;;ABCDE;"
1533
+ * }
1534
+ * }],
1535
+ * }
1536
+ *
1537
+ * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
1538
+ */
1539
+ function IndexedSourceMapConsumer(aSourceMap) {
1540
+ var sourceMap = aSourceMap;
1541
+ if (typeof aSourceMap === 'string') {
1542
+ sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
1543
+ }
1544
+
1545
+ var version = util.getArg(sourceMap, 'version');
1546
+ var sections = util.getArg(sourceMap, 'sections');
1547
+
1548
+ if (version != this._version) {
1549
+ throw new Error('Unsupported version: ' + version);
1550
+ }
1551
+
1552
+ this._sources = new ArraySet();
1553
+ this._names = new ArraySet();
1554
+
1555
+ var lastOffset = {
1556
+ line: -1,
1557
+ column: 0
1558
+ };
1559
+ this._sections = sections.map(function (s) {
1560
+ if (s.url) {
1561
+ // The url field will require support for asynchronicity.
1562
+ // See https://github.com/mozilla/source-map/issues/16
1563
+ throw new Error('Support for url field in sections not implemented.');
1564
+ }
1565
+ var offset = util.getArg(s, 'offset');
1566
+ var offsetLine = util.getArg(offset, 'line');
1567
+ var offsetColumn = util.getArg(offset, 'column');
1568
+
1569
+ if (offsetLine < lastOffset.line ||
1570
+ (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
1571
+ throw new Error('Section offsets must be ordered and non-overlapping.');
1572
+ }
1573
+ lastOffset = offset;
1574
+
1575
+ return {
1576
+ generatedOffset: {
1577
+ // The offset fields are 0-based, but we use 1-based indices when
1578
+ // encoding/decoding from VLQ.
1579
+ generatedLine: offsetLine + 1,
1580
+ generatedColumn: offsetColumn + 1
1581
+ },
1582
+ consumer: new SourceMapConsumer(util.getArg(s, 'map'))
1583
+ }
1584
+ });
1585
+ }
1586
+
1587
+ IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
1588
+ IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
1589
+
1590
+ /**
1591
+ * The version of the source mapping spec that we are consuming.
1592
+ */
1593
+ IndexedSourceMapConsumer.prototype._version = 3;
1594
+
1595
+ /**
1596
+ * The list of original sources.
1597
+ */
1598
+ Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
1599
+ get: function () {
1600
+ var sources = [];
1601
+ for (var i = 0; i < this._sections.length; i++) {
1602
+ for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
1603
+ sources.push(this._sections[i].consumer.sources[j]);
1604
+ }
1605
+ }
1606
+ return sources;
1607
+ }
1608
+ });
1609
+
1610
+ /**
1611
+ * Returns the original source, line, and column information for the generated
1612
+ * source's line and column positions provided. The only argument is an object
1613
+ * with the following properties:
1614
+ *
1615
+ * - line: The line number in the generated source.
1616
+ * - column: The column number in the generated source.
1617
+ *
1618
+ * and an object is returned with the following properties:
1619
+ *
1620
+ * - source: The original source file, or null.
1621
+ * - line: The line number in the original source, or null.
1622
+ * - column: The column number in the original source, or null.
1623
+ * - name: The original identifier, or null.
1624
+ */
1625
+ IndexedSourceMapConsumer.prototype.originalPositionFor =
1626
+ function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
1627
+ var needle = {
1628
+ generatedLine: util.getArg(aArgs, 'line'),
1629
+ generatedColumn: util.getArg(aArgs, 'column')
1630
+ };
1631
+
1632
+ // Find the section containing the generated position we're trying to map
1633
+ // to an original position.
1634
+ var sectionIndex = binarySearch.search(needle, this._sections,
1635
+ function(needle, section) {
1636
+ var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
1637
+ if (cmp) {
1638
+ return cmp;
1639
+ }
1640
+
1641
+ return (needle.generatedColumn -
1642
+ section.generatedOffset.generatedColumn);
1643
+ });
1644
+ var section = this._sections[sectionIndex];
1645
+
1646
+ if (!section) {
1647
+ return {
1648
+ source: null,
1649
+ line: null,
1650
+ column: null,
1651
+ name: null
1652
+ };
1653
+ }
1654
+
1655
+ return section.consumer.originalPositionFor({
1656
+ line: needle.generatedLine -
1657
+ (section.generatedOffset.generatedLine - 1),
1658
+ column: needle.generatedColumn -
1659
+ (section.generatedOffset.generatedLine === needle.generatedLine
1660
+ ? section.generatedOffset.generatedColumn - 1
1661
+ : 0),
1662
+ bias: aArgs.bias
1663
+ });
1664
+ };
1665
+
1666
+ /**
1667
+ * Return true if we have the source content for every source in the source
1668
+ * map, false otherwise.
1669
+ */
1670
+ IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
1671
+ function IndexedSourceMapConsumer_hasContentsOfAllSources() {
1672
+ return this._sections.every(function (s) {
1673
+ return s.consumer.hasContentsOfAllSources();
1674
+ });
1675
+ };
1676
+
1677
+ /**
1678
+ * Returns the original source content. The only argument is the url of the
1679
+ * original source file. Returns null if no original source content is
1680
+ * available.
1681
+ */
1682
+ IndexedSourceMapConsumer.prototype.sourceContentFor =
1683
+ function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
1684
+ for (var i = 0; i < this._sections.length; i++) {
1685
+ var section = this._sections[i];
1686
+
1687
+ var content = section.consumer.sourceContentFor(aSource, true);
1688
+ if (content) {
1689
+ return content;
1690
+ }
1691
+ }
1692
+ if (nullOnMissing) {
1693
+ return null;
1694
+ }
1695
+ else {
1696
+ throw new Error('"' + aSource + '" is not in the SourceMap.');
1697
+ }
1698
+ };
1699
+
1700
+ /**
1701
+ * Returns the generated line and column information for the original source,
1702
+ * line, and column positions provided. The only argument is an object with
1703
+ * the following properties:
1704
+ *
1705
+ * - source: The filename of the original source.
1706
+ * - line: The line number in the original source.
1707
+ * - column: The column number in the original source.
1708
+ *
1709
+ * and an object is returned with the following properties:
1710
+ *
1711
+ * - line: The line number in the generated source, or null.
1712
+ * - column: The column number in the generated source, or null.
1713
+ */
1714
+ IndexedSourceMapConsumer.prototype.generatedPositionFor =
1715
+ function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
1716
+ for (var i = 0; i < this._sections.length; i++) {
1717
+ var section = this._sections[i];
1718
+
1719
+ // Only consider this section if the requested source is in the list of
1720
+ // sources of the consumer.
1721
+ if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) {
1722
+ continue;
1723
+ }
1724
+ var generatedPosition = section.consumer.generatedPositionFor(aArgs);
1725
+ if (generatedPosition) {
1726
+ var ret = {
1727
+ line: generatedPosition.line +
1728
+ (section.generatedOffset.generatedLine - 1),
1729
+ column: generatedPosition.column +
1730
+ (section.generatedOffset.generatedLine === generatedPosition.line
1731
+ ? section.generatedOffset.generatedColumn - 1
1732
+ : 0)
1733
+ };
1734
+ return ret;
1735
+ }
1736
+ }
1737
+
1738
+ return {
1739
+ line: null,
1740
+ column: null
1741
+ };
1742
+ };
1743
+
1744
+ /**
1745
+ * Parse the mappings in a string in to a data structure which we can easily
1746
+ * query (the ordered arrays in the `this.__generatedMappings` and
1747
+ * `this.__originalMappings` properties).
1748
+ */
1749
+ IndexedSourceMapConsumer.prototype._parseMappings =
1750
+ function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
1751
+ this.__generatedMappings = [];
1752
+ this.__originalMappings = [];
1753
+ for (var i = 0; i < this._sections.length; i++) {
1754
+ var section = this._sections[i];
1755
+ var sectionMappings = section.consumer._generatedMappings;
1756
+ for (var j = 0; j < sectionMappings.length; j++) {
1757
+ var mapping = sectionMappings[j];
1758
+
1759
+ var source = section.consumer._sources.at(mapping.source);
1760
+ if (section.consumer.sourceRoot !== null) {
1761
+ source = util.join(section.consumer.sourceRoot, source);
1762
+ }
1763
+ this._sources.add(source);
1764
+ source = this._sources.indexOf(source);
1765
+
1766
+ var name = section.consumer._names.at(mapping.name);
1767
+ this._names.add(name);
1768
+ name = this._names.indexOf(name);
1769
+
1770
+ // The mappings coming from the consumer for the section have
1771
+ // generated positions relative to the start of the section, so we
1772
+ // need to offset them to be relative to the start of the concatenated
1773
+ // generated file.
1774
+ var adjustedMapping = {
1775
+ source: source,
1776
+ generatedLine: mapping.generatedLine +
1777
+ (section.generatedOffset.generatedLine - 1),
1778
+ generatedColumn: mapping.generatedColumn +
1779
+ (section.generatedOffset.generatedLine === mapping.generatedLine
1780
+ ? section.generatedOffset.generatedColumn - 1
1781
+ : 0),
1782
+ originalLine: mapping.originalLine,
1783
+ originalColumn: mapping.originalColumn,
1784
+ name: name
1785
+ };
1786
+
1787
+ this.__generatedMappings.push(adjustedMapping);
1788
+ if (typeof adjustedMapping.originalLine === 'number') {
1789
+ this.__originalMappings.push(adjustedMapping);
1790
+ }
1791
+ }
1792
+ }
1793
+
1794
+ quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
1795
+ quickSort(this.__originalMappings, util.compareByOriginalPositions);
1796
+ };
1797
+
1798
+ exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
1799
+
1800
+ },{"./array-set":2,"./base64-vlq":3,"./binary-search":5,"./quick-sort":7,"./util":11}],9:[function(require,module,exports){
1801
+ /* -*- Mode: js; js-indent-level: 2; -*- */
1802
+ /*
1803
+ * Copyright 2011 Mozilla Foundation and contributors
1804
+ * Licensed under the New BSD license. See LICENSE or:
1805
+ * http://opensource.org/licenses/BSD-3-Clause
1806
+ */
1807
+
1808
+ var base64VLQ = require('./base64-vlq');
1809
+ var util = require('./util');
1810
+ var ArraySet = require('./array-set').ArraySet;
1811
+ var MappingList = require('./mapping-list').MappingList;
1812
+
1813
+ /**
1814
+ * An instance of the SourceMapGenerator represents a source map which is
1815
+ * being built incrementally. You may pass an object with the following
1816
+ * properties:
1817
+ *
1818
+ * - file: The filename of the generated source.
1819
+ * - sourceRoot: A root for all relative URLs in this source map.
1820
+ */
1821
+ function SourceMapGenerator(aArgs) {
1822
+ if (!aArgs) {
1823
+ aArgs = {};
1824
+ }
1825
+ this._file = util.getArg(aArgs, 'file', null);
1826
+ this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
1827
+ this._skipValidation = util.getArg(aArgs, 'skipValidation', false);
1828
+ this._sources = new ArraySet();
1829
+ this._names = new ArraySet();
1830
+ this._mappings = new MappingList();
1831
+ this._sourcesContents = null;
1832
+ }
1833
+
1834
+ SourceMapGenerator.prototype._version = 3;
1835
+
1836
+ /**
1837
+ * Creates a new SourceMapGenerator based on a SourceMapConsumer
1838
+ *
1839
+ * @param aSourceMapConsumer The SourceMap.
1840
+ */
1841
+ SourceMapGenerator.fromSourceMap =
1842
+ function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
1843
+ var sourceRoot = aSourceMapConsumer.sourceRoot;
1844
+ var generator = new SourceMapGenerator({
1845
+ file: aSourceMapConsumer.file,
1846
+ sourceRoot: sourceRoot
1847
+ });
1848
+ aSourceMapConsumer.eachMapping(function (mapping) {
1849
+ var newMapping = {
1850
+ generated: {
1851
+ line: mapping.generatedLine,
1852
+ column: mapping.generatedColumn
1853
+ }
1854
+ };
1855
+
1856
+ if (mapping.source != null) {
1857
+ newMapping.source = mapping.source;
1858
+ if (sourceRoot != null) {
1859
+ newMapping.source = util.relative(sourceRoot, newMapping.source);
1860
+ }
1861
+
1862
+ newMapping.original = {
1863
+ line: mapping.originalLine,
1864
+ column: mapping.originalColumn
1865
+ };
1866
+
1867
+ if (mapping.name != null) {
1868
+ newMapping.name = mapping.name;
1869
+ }
1870
+ }
1871
+
1872
+ generator.addMapping(newMapping);
1873
+ });
1874
+ aSourceMapConsumer.sources.forEach(function (sourceFile) {
1875
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile);
1876
+ if (content != null) {
1877
+ generator.setSourceContent(sourceFile, content);
1878
+ }
1879
+ });
1880
+ return generator;
1881
+ };
1882
+
1883
+ /**
1884
+ * Add a single mapping from original source line and column to the generated
1885
+ * source's line and column for this source map being created. The mapping
1886
+ * object should have the following properties:
1887
+ *
1888
+ * - generated: An object with the generated line and column positions.
1889
+ * - original: An object with the original line and column positions.
1890
+ * - source: The original source file (relative to the sourceRoot).
1891
+ * - name: An optional original token name for this mapping.
1892
+ */
1893
+ SourceMapGenerator.prototype.addMapping =
1894
+ function SourceMapGenerator_addMapping(aArgs) {
1895
+ var generated = util.getArg(aArgs, 'generated');
1896
+ var original = util.getArg(aArgs, 'original', null);
1897
+ var source = util.getArg(aArgs, 'source', null);
1898
+ var name = util.getArg(aArgs, 'name', null);
1899
+
1900
+ if (!this._skipValidation) {
1901
+ this._validateMapping(generated, original, source, name);
1902
+ }
1903
+
1904
+ if (source != null) {
1905
+ source = String(source);
1906
+ if (!this._sources.has(source)) {
1907
+ this._sources.add(source);
1908
+ }
1909
+ }
1910
+
1911
+ if (name != null) {
1912
+ name = String(name);
1913
+ if (!this._names.has(name)) {
1914
+ this._names.add(name);
1915
+ }
1916
+ }
1917
+
1918
+ this._mappings.add({
1919
+ generatedLine: generated.line,
1920
+ generatedColumn: generated.column,
1921
+ originalLine: original != null && original.line,
1922
+ originalColumn: original != null && original.column,
1923
+ source: source,
1924
+ name: name
1925
+ });
1926
+ };
1927
+
1928
+ /**
1929
+ * Set the source content for a source file.
1930
+ */
1931
+ SourceMapGenerator.prototype.setSourceContent =
1932
+ function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
1933
+ var source = aSourceFile;
1934
+ if (this._sourceRoot != null) {
1935
+ source = util.relative(this._sourceRoot, source);
1936
+ }
1937
+
1938
+ if (aSourceContent != null) {
1939
+ // Add the source content to the _sourcesContents map.
1940
+ // Create a new _sourcesContents map if the property is null.
1941
+ if (!this._sourcesContents) {
1942
+ this._sourcesContents = Object.create(null);
1943
+ }
1944
+ this._sourcesContents[util.toSetString(source)] = aSourceContent;
1945
+ } else if (this._sourcesContents) {
1946
+ // Remove the source file from the _sourcesContents map.
1947
+ // If the _sourcesContents map is empty, set the property to null.
1948
+ delete this._sourcesContents[util.toSetString(source)];
1949
+ if (Object.keys(this._sourcesContents).length === 0) {
1950
+ this._sourcesContents = null;
1951
+ }
1952
+ }
1953
+ };
1954
+
1955
+ /**
1956
+ * Applies the mappings of a sub-source-map for a specific source file to the
1957
+ * source map being generated. Each mapping to the supplied source file is
1958
+ * rewritten using the supplied source map. Note: The resolution for the
1959
+ * resulting mappings is the minimium of this map and the supplied map.
1960
+ *
1961
+ * @param aSourceMapConsumer The source map to be applied.
1962
+ * @param aSourceFile Optional. The filename of the source file.
1963
+ * If omitted, SourceMapConsumer's file property will be used.
1964
+ * @param aSourceMapPath Optional. The dirname of the path to the source map
1965
+ * to be applied. If relative, it is relative to the SourceMapConsumer.
1966
+ * This parameter is needed when the two source maps aren't in the same
1967
+ * directory, and the source map to be applied contains relative source
1968
+ * paths. If so, those relative source paths need to be rewritten
1969
+ * relative to the SourceMapGenerator.
1970
+ */
1971
+ SourceMapGenerator.prototype.applySourceMap =
1972
+ function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
1973
+ var sourceFile = aSourceFile;
1974
+ // If aSourceFile is omitted, we will use the file property of the SourceMap
1975
+ if (aSourceFile == null) {
1976
+ if (aSourceMapConsumer.file == null) {
1977
+ throw new Error(
1978
+ 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
1979
+ 'or the source map\'s "file" property. Both were omitted.'
1980
+ );
1981
+ }
1982
+ sourceFile = aSourceMapConsumer.file;
1983
+ }
1984
+ var sourceRoot = this._sourceRoot;
1985
+ // Make "sourceFile" relative if an absolute Url is passed.
1986
+ if (sourceRoot != null) {
1987
+ sourceFile = util.relative(sourceRoot, sourceFile);
1988
+ }
1989
+ // Applying the SourceMap can add and remove items from the sources and
1990
+ // the names array.
1991
+ var newSources = new ArraySet();
1992
+ var newNames = new ArraySet();
1993
+
1994
+ // Find mappings for the "sourceFile"
1995
+ this._mappings.unsortedForEach(function (mapping) {
1996
+ if (mapping.source === sourceFile && mapping.originalLine != null) {
1997
+ // Check if it can be mapped by the source map, then update the mapping.
1998
+ var original = aSourceMapConsumer.originalPositionFor({
1999
+ line: mapping.originalLine,
2000
+ column: mapping.originalColumn
2001
+ });
2002
+ if (original.source != null) {
2003
+ // Copy mapping
2004
+ mapping.source = original.source;
2005
+ if (aSourceMapPath != null) {
2006
+ mapping.source = util.join(aSourceMapPath, mapping.source)
2007
+ }
2008
+ if (sourceRoot != null) {
2009
+ mapping.source = util.relative(sourceRoot, mapping.source);
2010
+ }
2011
+ mapping.originalLine = original.line;
2012
+ mapping.originalColumn = original.column;
2013
+ if (original.name != null) {
2014
+ mapping.name = original.name;
2015
+ }
2016
+ }
2017
+ }
2018
+
2019
+ var source = mapping.source;
2020
+ if (source != null && !newSources.has(source)) {
2021
+ newSources.add(source);
2022
+ }
2023
+
2024
+ var name = mapping.name;
2025
+ if (name != null && !newNames.has(name)) {
2026
+ newNames.add(name);
2027
+ }
2028
+
2029
+ }, this);
2030
+ this._sources = newSources;
2031
+ this._names = newNames;
2032
+
2033
+ // Copy sourcesContents of applied map.
2034
+ aSourceMapConsumer.sources.forEach(function (sourceFile) {
2035
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile);
2036
+ if (content != null) {
2037
+ if (aSourceMapPath != null) {
2038
+ sourceFile = util.join(aSourceMapPath, sourceFile);
2039
+ }
2040
+ if (sourceRoot != null) {
2041
+ sourceFile = util.relative(sourceRoot, sourceFile);
2042
+ }
2043
+ this.setSourceContent(sourceFile, content);
2044
+ }
2045
+ }, this);
2046
+ };
2047
+
2048
+ /**
2049
+ * A mapping can have one of the three levels of data:
2050
+ *
2051
+ * 1. Just the generated position.
2052
+ * 2. The Generated position, original position, and original source.
2053
+ * 3. Generated and original position, original source, as well as a name
2054
+ * token.
2055
+ *
2056
+ * To maintain consistency, we validate that any new mapping being added falls
2057
+ * in to one of these categories.
2058
+ */
2059
+ SourceMapGenerator.prototype._validateMapping =
2060
+ function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
2061
+ aName) {
2062
+ // When aOriginal is truthy but has empty values for .line and .column,
2063
+ // it is most likely a programmer error. In this case we throw a very
2064
+ // specific error message to try to guide them the right way.
2065
+ // For example: https://github.com/Polymer/polymer-bundler/pull/519
2066
+ if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
2067
+ throw new Error(
2068
+ 'original.line and original.column are not numbers -- you probably meant to omit ' +
2069
+ 'the original mapping entirely and only map the generated position. If so, pass ' +
2070
+ 'null for the original mapping instead of an object with empty or null values.'
2071
+ );
2072
+ }
2073
+
2074
+ if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
2075
+ && aGenerated.line > 0 && aGenerated.column >= 0
2076
+ && !aOriginal && !aSource && !aName) {
2077
+ // Case 1.
2078
+ return;
2079
+ }
2080
+ else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
2081
+ && aOriginal && 'line' in aOriginal && 'column' in aOriginal
2082
+ && aGenerated.line > 0 && aGenerated.column >= 0
2083
+ && aOriginal.line > 0 && aOriginal.column >= 0
2084
+ && aSource) {
2085
+ // Cases 2 and 3.
2086
+ return;
2087
+ }
2088
+ else {
2089
+ throw new Error('Invalid mapping: ' + JSON.stringify({
2090
+ generated: aGenerated,
2091
+ source: aSource,
2092
+ original: aOriginal,
2093
+ name: aName
2094
+ }));
2095
+ }
2096
+ };
2097
+
2098
+ /**
2099
+ * Serialize the accumulated mappings in to the stream of base 64 VLQs
2100
+ * specified by the source map format.
2101
+ */
2102
+ SourceMapGenerator.prototype._serializeMappings =
2103
+ function SourceMapGenerator_serializeMappings() {
2104
+ var previousGeneratedColumn = 0;
2105
+ var previousGeneratedLine = 1;
2106
+ var previousOriginalColumn = 0;
2107
+ var previousOriginalLine = 0;
2108
+ var previousName = 0;
2109
+ var previousSource = 0;
2110
+ var result = '';
2111
+ var next;
2112
+ var mapping;
2113
+ var nameIdx;
2114
+ var sourceIdx;
2115
+
2116
+ var mappings = this._mappings.toArray();
2117
+ for (var i = 0, len = mappings.length; i < len; i++) {
2118
+ mapping = mappings[i];
2119
+ next = ''
2120
+
2121
+ if (mapping.generatedLine !== previousGeneratedLine) {
2122
+ previousGeneratedColumn = 0;
2123
+ while (mapping.generatedLine !== previousGeneratedLine) {
2124
+ next += ';';
2125
+ previousGeneratedLine++;
2126
+ }
2127
+ }
2128
+ else {
2129
+ if (i > 0) {
2130
+ if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
2131
+ continue;
2132
+ }
2133
+ next += ',';
2134
+ }
2135
+ }
2136
+
2137
+ next += base64VLQ.encode(mapping.generatedColumn
2138
+ - previousGeneratedColumn);
2139
+ previousGeneratedColumn = mapping.generatedColumn;
2140
+
2141
+ if (mapping.source != null) {
2142
+ sourceIdx = this._sources.indexOf(mapping.source);
2143
+ next += base64VLQ.encode(sourceIdx - previousSource);
2144
+ previousSource = sourceIdx;
2145
+
2146
+ // lines are stored 0-based in SourceMap spec version 3
2147
+ next += base64VLQ.encode(mapping.originalLine - 1
2148
+ - previousOriginalLine);
2149
+ previousOriginalLine = mapping.originalLine - 1;
2150
+
2151
+ next += base64VLQ.encode(mapping.originalColumn
2152
+ - previousOriginalColumn);
2153
+ previousOriginalColumn = mapping.originalColumn;
2154
+
2155
+ if (mapping.name != null) {
2156
+ nameIdx = this._names.indexOf(mapping.name);
2157
+ next += base64VLQ.encode(nameIdx - previousName);
2158
+ previousName = nameIdx;
2159
+ }
2160
+ }
2161
+
2162
+ result += next;
2163
+ }
2164
+
2165
+ return result;
2166
+ };
2167
+
2168
+ SourceMapGenerator.prototype._generateSourcesContent =
2169
+ function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
2170
+ return aSources.map(function (source) {
2171
+ if (!this._sourcesContents) {
2172
+ return null;
2173
+ }
2174
+ if (aSourceRoot != null) {
2175
+ source = util.relative(aSourceRoot, source);
2176
+ }
2177
+ var key = util.toSetString(source);
2178
+ return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
2179
+ ? this._sourcesContents[key]
2180
+ : null;
2181
+ }, this);
2182
+ };
2183
+
2184
+ /**
2185
+ * Externalize the source map.
2186
+ */
2187
+ SourceMapGenerator.prototype.toJSON =
2188
+ function SourceMapGenerator_toJSON() {
2189
+ var map = {
2190
+ version: this._version,
2191
+ sources: this._sources.toArray(),
2192
+ names: this._names.toArray(),
2193
+ mappings: this._serializeMappings()
2194
+ };
2195
+ if (this._file != null) {
2196
+ map.file = this._file;
2197
+ }
2198
+ if (this._sourceRoot != null) {
2199
+ map.sourceRoot = this._sourceRoot;
2200
+ }
2201
+ if (this._sourcesContents) {
2202
+ map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
2203
+ }
2204
+
2205
+ return map;
2206
+ };
2207
+
2208
+ /**
2209
+ * Render the source map being generated to a string.
2210
+ */
2211
+ SourceMapGenerator.prototype.toString =
2212
+ function SourceMapGenerator_toString() {
2213
+ return JSON.stringify(this.toJSON());
2214
+ };
2215
+
2216
+ exports.SourceMapGenerator = SourceMapGenerator;
2217
+
2218
+ },{"./array-set":2,"./base64-vlq":3,"./mapping-list":6,"./util":11}],10:[function(require,module,exports){
2219
+ /* -*- Mode: js; js-indent-level: 2; -*- */
2220
+ /*
2221
+ * Copyright 2011 Mozilla Foundation and contributors
2222
+ * Licensed under the New BSD license. See LICENSE or:
2223
+ * http://opensource.org/licenses/BSD-3-Clause
2224
+ */
2225
+
2226
+ var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
2227
+ var util = require('./util');
2228
+
2229
+ // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
2230
+ // operating systems these days (capturing the result).
2231
+ var REGEX_NEWLINE = /(\r?\n)/;
2232
+
2233
+ // Newline character code for charCodeAt() comparisons
2234
+ var NEWLINE_CODE = 10;
2235
+
2236
+ // Private symbol for identifying `SourceNode`s when multiple versions of
2237
+ // the source-map library are loaded. This MUST NOT CHANGE across
2238
+ // versions!
2239
+ var isSourceNode = "$$$isSourceNode$$$";
2240
+
2241
+ /**
2242
+ * SourceNodes provide a way to abstract over interpolating/concatenating
2243
+ * snippets of generated JavaScript source code while maintaining the line and
2244
+ * column information associated with the original source code.
2245
+ *
2246
+ * @param aLine The original line number.
2247
+ * @param aColumn The original column number.
2248
+ * @param aSource The original source's filename.
2249
+ * @param aChunks Optional. An array of strings which are snippets of
2250
+ * generated JS, or other SourceNodes.
2251
+ * @param aName The original identifier.
2252
+ */
2253
+ function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
2254
+ this.children = [];
2255
+ this.sourceContents = {};
2256
+ this.line = aLine == null ? null : aLine;
2257
+ this.column = aColumn == null ? null : aColumn;
2258
+ this.source = aSource == null ? null : aSource;
2259
+ this.name = aName == null ? null : aName;
2260
+ this[isSourceNode] = true;
2261
+ if (aChunks != null) this.add(aChunks);
2262
+ }
2263
+
2264
+ /**
2265
+ * Creates a SourceNode from generated code and a SourceMapConsumer.
2266
+ *
2267
+ * @param aGeneratedCode The generated code
2268
+ * @param aSourceMapConsumer The SourceMap for the generated code
2269
+ * @param aRelativePath Optional. The path that relative sources in the
2270
+ * SourceMapConsumer should be relative to.
2271
+ */
2272
+ SourceNode.fromStringWithSourceMap =
2273
+ function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
2274
+ // The SourceNode we want to fill with the generated code
2275
+ // and the SourceMap
2276
+ var node = new SourceNode();
2277
+
2278
+ // All even indices of this array are one line of the generated code,
2279
+ // while all odd indices are the newlines between two adjacent lines
2280
+ // (since `REGEX_NEWLINE` captures its match).
2281
+ // Processed fragments are accessed by calling `shiftNextLine`.
2282
+ var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
2283
+ var remainingLinesIndex = 0;
2284
+ var shiftNextLine = function() {
2285
+ var lineContents = getNextLine();
2286
+ // The last line of a file might not have a newline.
2287
+ var newLine = getNextLine() || "";
2288
+ return lineContents + newLine;
2289
+
2290
+ function getNextLine() {
2291
+ return remainingLinesIndex < remainingLines.length ?
2292
+ remainingLines[remainingLinesIndex++] : undefined;
2293
+ }
2294
+ };
2295
+
2296
+ // We need to remember the position of "remainingLines"
2297
+ var lastGeneratedLine = 1, lastGeneratedColumn = 0;
2298
+
2299
+ // The generate SourceNodes we need a code range.
2300
+ // To extract it current and last mapping is used.
2301
+ // Here we store the last mapping.
2302
+ var lastMapping = null;
2303
+
2304
+ aSourceMapConsumer.eachMapping(function (mapping) {
2305
+ if (lastMapping !== null) {
2306
+ // We add the code from "lastMapping" to "mapping":
2307
+ // First check if there is a new line in between.
2308
+ if (lastGeneratedLine < mapping.generatedLine) {
2309
+ // Associate first line with "lastMapping"
2310
+ addMappingWithCode(lastMapping, shiftNextLine());
2311
+ lastGeneratedLine++;
2312
+ lastGeneratedColumn = 0;
2313
+ // The remaining code is added without mapping
2314
+ } else {
2315
+ // There is no new line in between.
2316
+ // Associate the code between "lastGeneratedColumn" and
2317
+ // "mapping.generatedColumn" with "lastMapping"
2318
+ var nextLine = remainingLines[remainingLinesIndex];
2319
+ var code = nextLine.substr(0, mapping.generatedColumn -
2320
+ lastGeneratedColumn);
2321
+ remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
2322
+ lastGeneratedColumn);
2323
+ lastGeneratedColumn = mapping.generatedColumn;
2324
+ addMappingWithCode(lastMapping, code);
2325
+ // No more remaining code, continue
2326
+ lastMapping = mapping;
2327
+ return;
2328
+ }
2329
+ }
2330
+ // We add the generated code until the first mapping
2331
+ // to the SourceNode without any mapping.
2332
+ // Each line is added as separate string.
2333
+ while (lastGeneratedLine < mapping.generatedLine) {
2334
+ node.add(shiftNextLine());
2335
+ lastGeneratedLine++;
2336
+ }
2337
+ if (lastGeneratedColumn < mapping.generatedColumn) {
2338
+ var nextLine = remainingLines[remainingLinesIndex];
2339
+ node.add(nextLine.substr(0, mapping.generatedColumn));
2340
+ remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
2341
+ lastGeneratedColumn = mapping.generatedColumn;
2342
+ }
2343
+ lastMapping = mapping;
2344
+ }, this);
2345
+ // We have processed all mappings.
2346
+ if (remainingLinesIndex < remainingLines.length) {
2347
+ if (lastMapping) {
2348
+ // Associate the remaining code in the current line with "lastMapping"
2349
+ addMappingWithCode(lastMapping, shiftNextLine());
2350
+ }
2351
+ // and add the remaining lines without any mapping
2352
+ node.add(remainingLines.splice(remainingLinesIndex).join(""));
2353
+ }
2354
+
2355
+ // Copy sourcesContent into SourceNode
2356
+ aSourceMapConsumer.sources.forEach(function (sourceFile) {
2357
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile);
2358
+ if (content != null) {
2359
+ if (aRelativePath != null) {
2360
+ sourceFile = util.join(aRelativePath, sourceFile);
2361
+ }
2362
+ node.setSourceContent(sourceFile, content);
2363
+ }
2364
+ });
2365
+
2366
+ return node;
2367
+
2368
+ function addMappingWithCode(mapping, code) {
2369
+ if (mapping === null || mapping.source === undefined) {
2370
+ node.add(code);
2371
+ } else {
2372
+ var source = aRelativePath
2373
+ ? util.join(aRelativePath, mapping.source)
2374
+ : mapping.source;
2375
+ node.add(new SourceNode(mapping.originalLine,
2376
+ mapping.originalColumn,
2377
+ source,
2378
+ code,
2379
+ mapping.name));
2380
+ }
2381
+ }
2382
+ };
2383
+
2384
+ /**
2385
+ * Add a chunk of generated JS to this source node.
2386
+ *
2387
+ * @param aChunk A string snippet of generated JS code, another instance of
2388
+ * SourceNode, or an array where each member is one of those things.
2389
+ */
2390
+ SourceNode.prototype.add = function SourceNode_add(aChunk) {
2391
+ if (Array.isArray(aChunk)) {
2392
+ aChunk.forEach(function (chunk) {
2393
+ this.add(chunk);
2394
+ }, this);
2395
+ }
2396
+ else if (aChunk[isSourceNode] || typeof aChunk === "string") {
2397
+ if (aChunk) {
2398
+ this.children.push(aChunk);
2399
+ }
2400
+ }
2401
+ else {
2402
+ throw new TypeError(
2403
+ "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
2404
+ );
2405
+ }
2406
+ return this;
2407
+ };
2408
+
2409
+ /**
2410
+ * Add a chunk of generated JS to the beginning of this source node.
2411
+ *
2412
+ * @param aChunk A string snippet of generated JS code, another instance of
2413
+ * SourceNode, or an array where each member is one of those things.
2414
+ */
2415
+ SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
2416
+ if (Array.isArray(aChunk)) {
2417
+ for (var i = aChunk.length-1; i >= 0; i--) {
2418
+ this.prepend(aChunk[i]);
2419
+ }
2420
+ }
2421
+ else if (aChunk[isSourceNode] || typeof aChunk === "string") {
2422
+ this.children.unshift(aChunk);
2423
+ }
2424
+ else {
2425
+ throw new TypeError(
2426
+ "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
2427
+ );
2428
+ }
2429
+ return this;
2430
+ };
2431
+
2432
+ /**
2433
+ * Walk over the tree of JS snippets in this node and its children. The
2434
+ * walking function is called once for each snippet of JS and is passed that
2435
+ * snippet and the its original associated source's line/column location.
2436
+ *
2437
+ * @param aFn The traversal function.
2438
+ */
2439
+ SourceNode.prototype.walk = function SourceNode_walk(aFn) {
2440
+ var chunk;
2441
+ for (var i = 0, len = this.children.length; i < len; i++) {
2442
+ chunk = this.children[i];
2443
+ if (chunk[isSourceNode]) {
2444
+ chunk.walk(aFn);
2445
+ }
2446
+ else {
2447
+ if (chunk !== '') {
2448
+ aFn(chunk, { source: this.source,
2449
+ line: this.line,
2450
+ column: this.column,
2451
+ name: this.name });
2452
+ }
2453
+ }
2454
+ }
2455
+ };
2456
+
2457
+ /**
2458
+ * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
2459
+ * each of `this.children`.
2460
+ *
2461
+ * @param aSep The separator.
2462
+ */
2463
+ SourceNode.prototype.join = function SourceNode_join(aSep) {
2464
+ var newChildren;
2465
+ var i;
2466
+ var len = this.children.length;
2467
+ if (len > 0) {
2468
+ newChildren = [];
2469
+ for (i = 0; i < len-1; i++) {
2470
+ newChildren.push(this.children[i]);
2471
+ newChildren.push(aSep);
2472
+ }
2473
+ newChildren.push(this.children[i]);
2474
+ this.children = newChildren;
2475
+ }
2476
+ return this;
2477
+ };
2478
+
2479
+ /**
2480
+ * Call String.prototype.replace on the very right-most source snippet. Useful
2481
+ * for trimming whitespace from the end of a source node, etc.
2482
+ *
2483
+ * @param aPattern The pattern to replace.
2484
+ * @param aReplacement The thing to replace the pattern with.
2485
+ */
2486
+ SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
2487
+ var lastChild = this.children[this.children.length - 1];
2488
+ if (lastChild[isSourceNode]) {
2489
+ lastChild.replaceRight(aPattern, aReplacement);
2490
+ }
2491
+ else if (typeof lastChild === 'string') {
2492
+ this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
2493
+ }
2494
+ else {
2495
+ this.children.push(''.replace(aPattern, aReplacement));
2496
+ }
2497
+ return this;
2498
+ };
2499
+
2500
+ /**
2501
+ * Set the source content for a source file. This will be added to the SourceMapGenerator
2502
+ * in the sourcesContent field.
2503
+ *
2504
+ * @param aSourceFile The filename of the source file
2505
+ * @param aSourceContent The content of the source file
2506
+ */
2507
+ SourceNode.prototype.setSourceContent =
2508
+ function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
2509
+ this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
2510
+ };
2511
+
2512
+ /**
2513
+ * Walk over the tree of SourceNodes. The walking function is called for each
2514
+ * source file content and is passed the filename and source content.
2515
+ *
2516
+ * @param aFn The traversal function.
2517
+ */
2518
+ SourceNode.prototype.walkSourceContents =
2519
+ function SourceNode_walkSourceContents(aFn) {
2520
+ for (var i = 0, len = this.children.length; i < len; i++) {
2521
+ if (this.children[i][isSourceNode]) {
2522
+ this.children[i].walkSourceContents(aFn);
2523
+ }
2524
+ }
2525
+
2526
+ var sources = Object.keys(this.sourceContents);
2527
+ for (var i = 0, len = sources.length; i < len; i++) {
2528
+ aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
2529
+ }
2530
+ };
2531
+
2532
+ /**
2533
+ * Return the string representation of this source node. Walks over the tree
2534
+ * and concatenates all the various snippets together to one string.
2535
+ */
2536
+ SourceNode.prototype.toString = function SourceNode_toString() {
2537
+ var str = "";
2538
+ this.walk(function (chunk) {
2539
+ str += chunk;
2540
+ });
2541
+ return str;
2542
+ };
2543
+
2544
+ /**
2545
+ * Returns the string representation of this source node along with a source
2546
+ * map.
2547
+ */
2548
+ SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
2549
+ var generated = {
2550
+ code: "",
2551
+ line: 1,
2552
+ column: 0
2553
+ };
2554
+ var map = new SourceMapGenerator(aArgs);
2555
+ var sourceMappingActive = false;
2556
+ var lastOriginalSource = null;
2557
+ var lastOriginalLine = null;
2558
+ var lastOriginalColumn = null;
2559
+ var lastOriginalName = null;
2560
+ this.walk(function (chunk, original) {
2561
+ generated.code += chunk;
2562
+ if (original.source !== null
2563
+ && original.line !== null
2564
+ && original.column !== null) {
2565
+ if(lastOriginalSource !== original.source
2566
+ || lastOriginalLine !== original.line
2567
+ || lastOriginalColumn !== original.column
2568
+ || lastOriginalName !== original.name) {
2569
+ map.addMapping({
2570
+ source: original.source,
2571
+ original: {
2572
+ line: original.line,
2573
+ column: original.column
2574
+ },
2575
+ generated: {
2576
+ line: generated.line,
2577
+ column: generated.column
2578
+ },
2579
+ name: original.name
2580
+ });
2581
+ }
2582
+ lastOriginalSource = original.source;
2583
+ lastOriginalLine = original.line;
2584
+ lastOriginalColumn = original.column;
2585
+ lastOriginalName = original.name;
2586
+ sourceMappingActive = true;
2587
+ } else if (sourceMappingActive) {
2588
+ map.addMapping({
2589
+ generated: {
2590
+ line: generated.line,
2591
+ column: generated.column
2592
+ }
2593
+ });
2594
+ lastOriginalSource = null;
2595
+ sourceMappingActive = false;
2596
+ }
2597
+ for (var idx = 0, length = chunk.length; idx < length; idx++) {
2598
+ if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
2599
+ generated.line++;
2600
+ generated.column = 0;
2601
+ // Mappings end at eol
2602
+ if (idx + 1 === length) {
2603
+ lastOriginalSource = null;
2604
+ sourceMappingActive = false;
2605
+ } else if (sourceMappingActive) {
2606
+ map.addMapping({
2607
+ source: original.source,
2608
+ original: {
2609
+ line: original.line,
2610
+ column: original.column
2611
+ },
2612
+ generated: {
2613
+ line: generated.line,
2614
+ column: generated.column
2615
+ },
2616
+ name: original.name
2617
+ });
2618
+ }
2619
+ } else {
2620
+ generated.column++;
2621
+ }
2622
+ }
2623
+ });
2624
+ this.walkSourceContents(function (sourceFile, sourceContent) {
2625
+ map.setSourceContent(sourceFile, sourceContent);
2626
+ });
2627
+
2628
+ return { code: generated.code, map: map };
2629
+ };
2630
+
2631
+ exports.SourceNode = SourceNode;
2632
+
2633
+ },{"./source-map-generator":9,"./util":11}],11:[function(require,module,exports){
2634
+ /* -*- Mode: js; js-indent-level: 2; -*- */
2635
+ /*
2636
+ * Copyright 2011 Mozilla Foundation and contributors
2637
+ * Licensed under the New BSD license. See LICENSE or:
2638
+ * http://opensource.org/licenses/BSD-3-Clause
2639
+ */
2640
+
2641
+ /**
2642
+ * This is a helper function for getting values from parameter/options
2643
+ * objects.
2644
+ *
2645
+ * @param args The object we are extracting values from
2646
+ * @param name The name of the property we are getting.
2647
+ * @param defaultValue An optional value to return if the property is missing
2648
+ * from the object. If this is not specified and the property is missing, an
2649
+ * error will be thrown.
2650
+ */
2651
+ function getArg(aArgs, aName, aDefaultValue) {
2652
+ if (aName in aArgs) {
2653
+ return aArgs[aName];
2654
+ } else if (arguments.length === 3) {
2655
+ return aDefaultValue;
2656
+ } else {
2657
+ throw new Error('"' + aName + '" is a required argument.');
2658
+ }
2659
+ }
2660
+ exports.getArg = getArg;
2661
+
2662
+ var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/;
2663
+ var dataUrlRegexp = /^data:.+\,.+$/;
2664
+
2665
+ function urlParse(aUrl) {
2666
+ var match = aUrl.match(urlRegexp);
2667
+ if (!match) {
2668
+ return null;
2669
+ }
2670
+ return {
2671
+ scheme: match[1],
2672
+ auth: match[2],
2673
+ host: match[3],
2674
+ port: match[4],
2675
+ path: match[5]
2676
+ };
2677
+ }
2678
+ exports.urlParse = urlParse;
2679
+
2680
+ function urlGenerate(aParsedUrl) {
2681
+ var url = '';
2682
+ if (aParsedUrl.scheme) {
2683
+ url += aParsedUrl.scheme + ':';
2684
+ }
2685
+ url += '//';
2686
+ if (aParsedUrl.auth) {
2687
+ url += aParsedUrl.auth + '@';
2688
+ }
2689
+ if (aParsedUrl.host) {
2690
+ url += aParsedUrl.host;
2691
+ }
2692
+ if (aParsedUrl.port) {
2693
+ url += ":" + aParsedUrl.port
2694
+ }
2695
+ if (aParsedUrl.path) {
2696
+ url += aParsedUrl.path;
2697
+ }
2698
+ return url;
2699
+ }
2700
+ exports.urlGenerate = urlGenerate;
2701
+
2702
+ /**
2703
+ * Normalizes a path, or the path portion of a URL:
2704
+ *
2705
+ * - Replaces consecutive slashes with one slash.
2706
+ * - Removes unnecessary '.' parts.
2707
+ * - Removes unnecessary '<dir>/..' parts.
2708
+ *
2709
+ * Based on code in the Node.js 'path' core module.
2710
+ *
2711
+ * @param aPath The path or url to normalize.
2712
+ */
2713
+ function normalize(aPath) {
2714
+ var path = aPath;
2715
+ var url = urlParse(aPath);
2716
+ if (url) {
2717
+ if (!url.path) {
2718
+ return aPath;
2719
+ }
2720
+ path = url.path;
2721
+ }
2722
+ var isAbsolute = exports.isAbsolute(path);
2723
+
2724
+ var parts = path.split(/\/+/);
2725
+ for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
2726
+ part = parts[i];
2727
+ if (part === '.') {
2728
+ parts.splice(i, 1);
2729
+ } else if (part === '..') {
2730
+ up++;
2731
+ } else if (up > 0) {
2732
+ if (part === '') {
2733
+ // The first part is blank if the path is absolute. Trying to go
2734
+ // above the root is a no-op. Therefore we can remove all '..' parts
2735
+ // directly after the root.
2736
+ parts.splice(i + 1, up);
2737
+ up = 0;
2738
+ } else {
2739
+ parts.splice(i, 2);
2740
+ up--;
2741
+ }
2742
+ }
2743
+ }
2744
+ path = parts.join('/');
2745
+
2746
+ if (path === '') {
2747
+ path = isAbsolute ? '/' : '.';
2748
+ }
2749
+
2750
+ if (url) {
2751
+ url.path = path;
2752
+ return urlGenerate(url);
2753
+ }
2754
+ return path;
2755
+ }
2756
+ exports.normalize = normalize;
2757
+
2758
+ /**
2759
+ * Joins two paths/URLs.
2760
+ *
2761
+ * @param aRoot The root path or URL.
2762
+ * @param aPath The path or URL to be joined with the root.
2763
+ *
2764
+ * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
2765
+ * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
2766
+ * first.
2767
+ * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
2768
+ * is updated with the result and aRoot is returned. Otherwise the result
2769
+ * is returned.
2770
+ * - If aPath is absolute, the result is aPath.
2771
+ * - Otherwise the two paths are joined with a slash.
2772
+ * - Joining for example 'http://' and 'www.example.com' is also supported.
2773
+ */
2774
+ function join(aRoot, aPath) {
2775
+ if (aRoot === "") {
2776
+ aRoot = ".";
2777
+ }
2778
+ if (aPath === "") {
2779
+ aPath = ".";
2780
+ }
2781
+ var aPathUrl = urlParse(aPath);
2782
+ var aRootUrl = urlParse(aRoot);
2783
+ if (aRootUrl) {
2784
+ aRoot = aRootUrl.path || '/';
2785
+ }
2786
+
2787
+ // `join(foo, '//www.example.org')`
2788
+ if (aPathUrl && !aPathUrl.scheme) {
2789
+ if (aRootUrl) {
2790
+ aPathUrl.scheme = aRootUrl.scheme;
2791
+ }
2792
+ return urlGenerate(aPathUrl);
2793
+ }
2794
+
2795
+ if (aPathUrl || aPath.match(dataUrlRegexp)) {
2796
+ return aPath;
2797
+ }
2798
+
2799
+ // `join('http://', 'www.example.com')`
2800
+ if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
2801
+ aRootUrl.host = aPath;
2802
+ return urlGenerate(aRootUrl);
2803
+ }
2804
+
2805
+ var joined = aPath.charAt(0) === '/'
2806
+ ? aPath
2807
+ : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
2808
+
2809
+ if (aRootUrl) {
2810
+ aRootUrl.path = joined;
2811
+ return urlGenerate(aRootUrl);
2812
+ }
2813
+ return joined;
2814
+ }
2815
+ exports.join = join;
2816
+
2817
+ exports.isAbsolute = function (aPath) {
2818
+ return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp);
2819
+ };
2820
+
2821
+ /**
2822
+ * Make a path relative to a URL or another path.
2823
+ *
2824
+ * @param aRoot The root path or URL.
2825
+ * @param aPath The path or URL to be made relative to aRoot.
2826
+ */
2827
+ function relative(aRoot, aPath) {
2828
+ if (aRoot === "") {
2829
+ aRoot = ".";
2830
+ }
2831
+
2832
+ aRoot = aRoot.replace(/\/$/, '');
2833
+
2834
+ // It is possible for the path to be above the root. In this case, simply
2835
+ // checking whether the root is a prefix of the path won't work. Instead, we
2836
+ // need to remove components from the root one by one, until either we find
2837
+ // a prefix that fits, or we run out of components to remove.
2838
+ var level = 0;
2839
+ while (aPath.indexOf(aRoot + '/') !== 0) {
2840
+ var index = aRoot.lastIndexOf("/");
2841
+ if (index < 0) {
2842
+ return aPath;
2843
+ }
2844
+
2845
+ // If the only part of the root that is left is the scheme (i.e. http://,
2846
+ // file:///, etc.), one or more slashes (/), or simply nothing at all, we
2847
+ // have exhausted all components, so the path is not relative to the root.
2848
+ aRoot = aRoot.slice(0, index);
2849
+ if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
2850
+ return aPath;
2851
+ }
2852
+
2853
+ ++level;
2854
+ }
2855
+
2856
+ // Make sure we add a "../" for each component we removed from the root.
2857
+ return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
2858
+ }
2859
+ exports.relative = relative;
2860
+
2861
+ var supportsNullProto = (function () {
2862
+ var obj = Object.create(null);
2863
+ return !('__proto__' in obj);
2864
+ }());
2865
+
2866
+ function identity (s) {
2867
+ return s;
2868
+ }
2869
+
2870
+ /**
2871
+ * Because behavior goes wacky when you set `__proto__` on objects, we
2872
+ * have to prefix all the strings in our set with an arbitrary character.
2873
+ *
2874
+ * See https://github.com/mozilla/source-map/pull/31 and
2875
+ * https://github.com/mozilla/source-map/issues/30
2876
+ *
2877
+ * @param String aStr
2878
+ */
2879
+ function toSetString(aStr) {
2880
+ if (isProtoString(aStr)) {
2881
+ return '$' + aStr;
2882
+ }
2883
+
2884
+ return aStr;
2885
+ }
2886
+ exports.toSetString = supportsNullProto ? identity : toSetString;
2887
+
2888
+ function fromSetString(aStr) {
2889
+ if (isProtoString(aStr)) {
2890
+ return aStr.slice(1);
2891
+ }
2892
+
2893
+ return aStr;
2894
+ }
2895
+ exports.fromSetString = supportsNullProto ? identity : fromSetString;
2896
+
2897
+ function isProtoString(s) {
2898
+ if (!s) {
2899
+ return false;
2900
+ }
2901
+
2902
+ var length = s.length;
2903
+
2904
+ if (length < 9 /* "__proto__".length */) {
2905
+ return false;
2906
+ }
2907
+
2908
+ if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
2909
+ s.charCodeAt(length - 2) !== 95 /* '_' */ ||
2910
+ s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
2911
+ s.charCodeAt(length - 4) !== 116 /* 't' */ ||
2912
+ s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
2913
+ s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
2914
+ s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
2915
+ s.charCodeAt(length - 8) !== 95 /* '_' */ ||
2916
+ s.charCodeAt(length - 9) !== 95 /* '_' */) {
2917
+ return false;
2918
+ }
2919
+
2920
+ for (var i = length - 10; i >= 0; i--) {
2921
+ if (s.charCodeAt(i) !== 36 /* '$' */) {
2922
+ return false;
2923
+ }
2924
+ }
2925
+
2926
+ return true;
2927
+ }
2928
+
2929
+ /**
2930
+ * Comparator between two mappings where the original positions are compared.
2931
+ *
2932
+ * Optionally pass in `true` as `onlyCompareGenerated` to consider two
2933
+ * mappings with the same original source/line/column, but different generated
2934
+ * line and column the same. Useful when searching for a mapping with a
2935
+ * stubbed out mapping.
2936
+ */
2937
+ function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
2938
+ var cmp = mappingA.source - mappingB.source;
2939
+ if (cmp !== 0) {
2940
+ return cmp;
2941
+ }
2942
+
2943
+ cmp = mappingA.originalLine - mappingB.originalLine;
2944
+ if (cmp !== 0) {
2945
+ return cmp;
2946
+ }
2947
+
2948
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
2949
+ if (cmp !== 0 || onlyCompareOriginal) {
2950
+ return cmp;
2951
+ }
2952
+
2953
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
2954
+ if (cmp !== 0) {
2955
+ return cmp;
2956
+ }
2957
+
2958
+ cmp = mappingA.generatedLine - mappingB.generatedLine;
2959
+ if (cmp !== 0) {
2960
+ return cmp;
2961
+ }
2962
+
2963
+ return mappingA.name - mappingB.name;
2964
+ }
2965
+ exports.compareByOriginalPositions = compareByOriginalPositions;
2966
+
2967
+ /**
2968
+ * Comparator between two mappings with deflated source and name indices where
2969
+ * the generated positions are compared.
2970
+ *
2971
+ * Optionally pass in `true` as `onlyCompareGenerated` to consider two
2972
+ * mappings with the same generated line and column, but different
2973
+ * source/name/original line and column the same. Useful when searching for a
2974
+ * mapping with a stubbed out mapping.
2975
+ */
2976
+ function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
2977
+ var cmp = mappingA.generatedLine - mappingB.generatedLine;
2978
+ if (cmp !== 0) {
2979
+ return cmp;
2980
+ }
2981
+
2982
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
2983
+ if (cmp !== 0 || onlyCompareGenerated) {
2984
+ return cmp;
2985
+ }
2986
+
2987
+ cmp = mappingA.source - mappingB.source;
2988
+ if (cmp !== 0) {
2989
+ return cmp;
2990
+ }
2991
+
2992
+ cmp = mappingA.originalLine - mappingB.originalLine;
2993
+ if (cmp !== 0) {
2994
+ return cmp;
2995
+ }
2996
+
2997
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
2998
+ if (cmp !== 0) {
2999
+ return cmp;
3000
+ }
3001
+
3002
+ return mappingA.name - mappingB.name;
3003
+ }
3004
+ exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
3005
+
3006
+ function strcmp(aStr1, aStr2) {
3007
+ if (aStr1 === aStr2) {
3008
+ return 0;
3009
+ }
3010
+
3011
+ if (aStr1 > aStr2) {
3012
+ return 1;
3013
+ }
3014
+
3015
+ return -1;
3016
+ }
3017
+
3018
+ /**
3019
+ * Comparator between two mappings with inflated source and name strings where
3020
+ * the generated positions are compared.
3021
+ */
3022
+ function compareByGeneratedPositionsInflated(mappingA, mappingB) {
3023
+ var cmp = mappingA.generatedLine - mappingB.generatedLine;
3024
+ if (cmp !== 0) {
3025
+ return cmp;
3026
+ }
3027
+
3028
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
3029
+ if (cmp !== 0) {
3030
+ return cmp;
3031
+ }
3032
+
3033
+ cmp = strcmp(mappingA.source, mappingB.source);
3034
+ if (cmp !== 0) {
3035
+ return cmp;
3036
+ }
3037
+
3038
+ cmp = mappingA.originalLine - mappingB.originalLine;
3039
+ if (cmp !== 0) {
3040
+ return cmp;
3041
+ }
3042
+
3043
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
3044
+ if (cmp !== 0) {
3045
+ return cmp;
3046
+ }
3047
+
3048
+ return strcmp(mappingA.name, mappingB.name);
3049
+ }
3050
+ exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
3051
+
3052
+ },{}],12:[function(require,module,exports){
3053
+ /*
3054
+ * Copyright 2009-2011 Mozilla Foundation and contributors
3055
+ * Licensed under the New BSD license. See LICENSE.txt or:
3056
+ * http://opensource.org/licenses/BSD-3-Clause
3057
+ */
3058
+ exports.SourceMapGenerator = require('./lib/source-map-generator').SourceMapGenerator;
3059
+ exports.SourceMapConsumer = require('./lib/source-map-consumer').SourceMapConsumer;
3060
+ exports.SourceNode = require('./lib/source-node').SourceNode;
3061
+
3062
+ },{"./lib/source-map-consumer":8,"./lib/source-map-generator":9,"./lib/source-node":10}],"/lib/opal/cli_runners/source-map-support.js":[function(require,module,exports){
3063
+ // IMPORTANT NOTICE:
3064
+ // Remember to update the browser version whenever this file is changed,
3065
+ // to do so, `run bin/build-browser-source-map-support`
3066
+
3067
+ // The following is taken and adapted from the work of Evan Wallace
3068
+ // https://github.com/evanw/node-source-map-support v0.5.12
3069
+
3070
+ // The MIT License (MIT)
3071
+ //
3072
+ // Copyright (c) 2014 Evan Wallace
3073
+ //
3074
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
3075
+ // of this software and associated documentation files (the "Software"), to deal
3076
+ // in the Software without restriction, including without limitation the rights
3077
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3078
+ // copies of the Software, and to permit persons to whom the Software is
3079
+ // furnished to do so, subject to the following conditions:
3080
+ //
3081
+ // The above copyright notice and this permission notice shall be included in all
3082
+ // copies or substantial portions of the Software.
3083
+ //
3084
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3085
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3086
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3087
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3088
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3089
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3090
+ // SOFTWARE.
3091
+
3092
+ var SourceMapConsumer = require('source-map').SourceMapConsumer;
3093
+ var path = require('path');
3094
+
3095
+ var fs;
3096
+ try {
3097
+ fs = require('fs');
3098
+ if (!fs.existsSync || !fs.readFileSync) {
3099
+ // fs doesn't have all methods we need
3100
+ fs = null;
3101
+ }
3102
+ } catch (err) {
3103
+ /* nop */
3104
+ }
3105
+
3106
+ var bufferFrom = require('buffer-from');
3107
+
3108
+ // Only install once if called multiple times
3109
+ var errorFormatterInstalled = false;
3110
+ var uncaughtShimInstalled = false;
3111
+
3112
+ // If true, the caches are reset before a stack trace formatting operation
3113
+ var emptyCacheBetweenOperations = false;
3114
+
3115
+ // Supports {browser, node, auto}
3116
+ var environment = "auto";
3117
+
3118
+ // Maps a file path to a string containing the file contents
3119
+ var fileContentsCache = {};
3120
+
3121
+ // Maps a file path to a source map for that file
3122
+ var sourceMapCache = {};
3123
+
3124
+ // Regex for detecting source maps
3125
+ var reSourceMap = /^data:application\/json[^,]+base64,/;
3126
+
3127
+ // Priority list of retrieve handlers
3128
+ var retrieveFileHandlers = [];
3129
+ var retrieveMapHandlers = [];
3130
+
3131
+ function isInBrowser() {
3132
+ if (environment === "browser")
3133
+ return true;
3134
+ if (environment === "node")
3135
+ return false;
3136
+ return ((typeof window !== 'undefined') && (typeof XMLHttpRequest === 'function') && !(window.require && window.module && window.process && window.process.type === "renderer"));
3137
+ }
3138
+
3139
+ function hasGlobalProcessEventEmitter() {
3140
+ return ((typeof process === 'object') && (process !== null) && (typeof process.on === 'function'));
3141
+ }
3142
+
3143
+ function handlerExec(list) {
3144
+ return function(arg) {
3145
+ for (var i = 0; i < list.length; i++) {
3146
+ var ret = list[i](arg);
3147
+ if (ret) {
3148
+ return ret;
3149
+ }
3150
+ }
3151
+ return null;
3152
+ };
3153
+ }
3154
+
3155
+ var retrieveFile = handlerExec(retrieveFileHandlers);
3156
+
3157
+ retrieveFileHandlers.push(function(path) {
3158
+ // Trim the path to make sure there is no extra whitespace.
3159
+ path = path.trim();
3160
+ if (/^file:/.test(path)) {
3161
+ // existsSync/readFileSync can't handle file protocol, but once stripped, it works
3162
+ path = path.replace(/file:\/\/\/(\w:)?/, function(protocol, drive) {
3163
+ return drive ?
3164
+ '' : // file:///C:/dir/file -> C:/dir/file
3165
+ '/'; // file:///root-dir/file -> /root-dir/file
3166
+ });
3167
+ }
3168
+ if (path in fileContentsCache) {
3169
+ return fileContentsCache[path];
3170
+ }
3171
+
3172
+ var contents = '';
3173
+ try {
3174
+ if (!fs) {
3175
+ // Use SJAX if we are in the browser
3176
+ var xhr = new XMLHttpRequest();
3177
+ xhr.open('GET', path, /** async */ false);
3178
+ xhr.send(null);
3179
+ if (xhr.readyState === 4 && xhr.status === 200) {
3180
+ contents = xhr.responseText;
3181
+ }
3182
+ } else if (fs.existsSync(path)) {
3183
+ // Otherwise, use the filesystem
3184
+ contents = fs.readFileSync(path, 'utf8');
3185
+ }
3186
+ } catch (er) {
3187
+ /* ignore any errors */
3188
+ }
3189
+
3190
+ return fileContentsCache[path] = contents;
3191
+ });
3192
+
3193
+ // Support URLs relative to a directory, but be careful about a protocol prefix
3194
+ // in case we are in the browser (i.e. directories may start with "http://" or "file:///")
3195
+ function supportRelativeURL(file, url) {
3196
+ // Force file to null otherwise it will relativize locations to the current file
3197
+ file = null
3198
+
3199
+ if (!file) return url;
3200
+ var dir = path.dirname(file);
3201
+ var match = /^\w+:\/\/[^\/]*/.exec(dir);
3202
+ var protocol = match ? match[0] : '';
3203
+ var startPath = dir.slice(protocol.length);
3204
+ if (protocol && /^\/\w\:/.test(startPath)) {
3205
+ // handle file:///C:/ paths
3206
+ protocol += '/';
3207
+ return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, '/');
3208
+ }
3209
+ return protocol + path.resolve(dir.slice(protocol.length), url);
3210
+ }
3211
+
3212
+ function retrieveSourceMapURL(source) {
3213
+ var fileData;
3214
+
3215
+ if (isInBrowser()) {
3216
+ try {
3217
+ var xhr = new XMLHttpRequest();
3218
+ xhr.open('GET', source, false);
3219
+ xhr.send(null);
3220
+ fileData = xhr.readyState === 4 ? xhr.responseText : null;
3221
+
3222
+ // Support providing a sourceMappingURL via the SourceMap header
3223
+ var sourceMapHeader = xhr.getResponseHeader("SourceMap") ||
3224
+ xhr.getResponseHeader("X-SourceMap");
3225
+ if (sourceMapHeader) {
3226
+ return sourceMapHeader;
3227
+ }
3228
+ } catch (e) {
3229
+ }
3230
+ }
3231
+
3232
+ // Get the URL of the source map
3233
+ fileData = retrieveFile(source);
3234
+ var re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;
3235
+ // Keep executing the search to find the *last* sourceMappingURL to avoid
3236
+ // picking up sourceMappingURLs from comments, strings, etc.
3237
+ var lastMatch, match;
3238
+ while (match = re.exec(fileData)) lastMatch = match;
3239
+ if (!lastMatch) return null;
3240
+ return lastMatch[1];
3241
+ };
3242
+
3243
+ // Can be overridden by the retrieveSourceMap option to install. Takes a
3244
+ // generated source filename; returns a {map, optional url} object, or null if
3245
+ // there is no source map. The map field may be either a string or the parsed
3246
+ // JSON object (ie, it must be a valid argument to the SourceMapConsumer
3247
+ // constructor).
3248
+ var retrieveSourceMap = handlerExec(retrieveMapHandlers);
3249
+ retrieveMapHandlers.push(function(source) {
3250
+ var sourceMappingURL = retrieveSourceMapURL(source);
3251
+ if (!sourceMappingURL) return null;
3252
+
3253
+ // Read the contents of the source map
3254
+ var sourceMapData;
3255
+ if (reSourceMap.test(sourceMappingURL)) {
3256
+ // Support source map URL as a data url
3257
+ var rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(',') + 1);
3258
+ sourceMapData = bufferFrom(rawData, "base64").toString();
3259
+ sourceMappingURL = source;
3260
+ } else {
3261
+ // Support source map URLs relative to the source URL
3262
+ sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
3263
+ sourceMapData = retrieveFile(sourceMappingURL);
3264
+ }
3265
+
3266
+ if (!sourceMapData) {
3267
+ return null;
3268
+ }
3269
+
3270
+ return {
3271
+ url: sourceMappingURL,
3272
+ map: sourceMapData
3273
+ };
3274
+ });
3275
+
3276
+ function mapSourcePosition(position) {
3277
+ var sourceMap = sourceMapCache[position.source];
3278
+ if (!sourceMap) {
3279
+ // Call the (overrideable) retrieveSourceMap function to get the source map.
3280
+ var urlAndMap = retrieveSourceMap(position.source);
3281
+ if (urlAndMap) {
3282
+ sourceMap = sourceMapCache[position.source] = {
3283
+ url: urlAndMap.url,
3284
+ map: new SourceMapConsumer(urlAndMap.map)
3285
+ };
3286
+
3287
+ // Load all sources stored inline with the source map into the file cache
3288
+ // to pretend like they are already loaded. They may not exist on disk.
3289
+ if (sourceMap.map.sourcesContent) {
3290
+ sourceMap.map.sources.forEach(function(source, i) {
3291
+ var contents = sourceMap.map.sourcesContent[i];
3292
+ if (contents) {
3293
+ var url = supportRelativeURL(sourceMap.url, source);
3294
+ fileContentsCache[url] = contents;
3295
+ }
3296
+ });
3297
+ }
3298
+ } else {
3299
+ sourceMap = sourceMapCache[position.source] = {
3300
+ url: null,
3301
+ map: null
3302
+ };
3303
+ }
3304
+ }
3305
+
3306
+ // Resolve the source URL relative to the URL of the source map
3307
+ if (sourceMap && sourceMap.map && typeof sourceMap.map.originalPositionFor === 'function') {
3308
+ var originalPosition = sourceMap.map.originalPositionFor(position);
3309
+
3310
+ // Only return the original position if a matching line was found. If no
3311
+ // matching line is found then we return position instead, which will cause
3312
+ // the stack trace to print the path and line for the compiled file. It is
3313
+ // better to give a precise location in the compiled file than a vague
3314
+ // location in the original file.
3315
+ if (originalPosition.source !== null) {
3316
+ originalPosition.source = supportRelativeURL(
3317
+ sourceMap.url, originalPosition.source);
3318
+ return originalPosition;
3319
+ }
3320
+ }
3321
+
3322
+ return position;
3323
+ }
3324
+
3325
+ // Parses code generated by FormatEvalOrigin(), a function inside V8:
3326
+ // https://code.google.com/p/v8/source/browse/trunk/src/messages.js
3327
+ function mapEvalOrigin(origin) {
3328
+ // Most eval() calls are in this format
3329
+ var match = /^eval from ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
3330
+ if (match) {
3331
+ var position = mapSourcePosition({
3332
+ source: match[2],
3333
+ line: +match[3],
3334
+ column: match[4] - 1
3335
+ });
3336
+ return 'eval from ' + match[1] + ' (' + position.source + ':' +
3337
+ position.line + ':' + (position.column + 1) + ')';
3338
+ }
3339
+
3340
+ // Parse nested eval() calls using recursion
3341
+ match = /^eval from ([^(]+) \((.+)\)$/.exec(origin);
3342
+ if (match) {
3343
+ return 'eval from ' + match[1] + ' (' + mapEvalOrigin(match[2]) + ')';
3344
+ }
3345
+
3346
+ // Make sure we still return useful information if we didn't find anything
3347
+ return origin;
3348
+ }
3349
+
3350
+ // This is copied almost verbatim from the V8 source code at
3351
+ // https://code.google.com/p/v8/source/browse/trunk/src/messages.js. The
3352
+ // implementation of wrapCallSite() used to just forward to the actual source
3353
+ // code of CallSite.prototype.toString but unfortunately a new release of V8
3354
+ // did something to the prototype chain and broke the shim. The only fix I
3355
+ // could find was copy/paste.
3356
+ function CallSiteToString() {
3357
+ var fileName;
3358
+ var fileLocation = "";
3359
+ if (this.isNative()) {
3360
+ fileLocation = "native";
3361
+ } else {
3362
+ fileName = this.getScriptNameOrSourceURL();
3363
+ if (!fileName && this.isEval()) {
3364
+ fileLocation = this.getEvalOrigin();
3365
+ fileLocation += ", "; // Expecting source position to follow.
3366
+ }
3367
+
3368
+ if (fileName) {
3369
+ fileLocation += fileName;
3370
+ } else {
3371
+ // Source code does not originate from a file and is not native, but we
3372
+ // can still get the source position inside the source string, e.g. in
3373
+ // an eval string.
3374
+ fileLocation += "<anonymous>";
3375
+ }
3376
+
3377
+ if (fileLocation.startsWith("corelib/")) {
3378
+ fileLocation = "<internal:" + fileLocation + ">";
3379
+ } else if (fileLocation.endsWith(".js")) {
3380
+ fileLocation = "<js:" + fileLocation + ">";
3381
+ }
3382
+
3383
+ var lineNumber = this.getLineNumber();
3384
+ if (lineNumber != null) {
3385
+ fileLocation += ":" + lineNumber;
3386
+ var columnNumber = this.getColumnNumber();
3387
+ if (columnNumber) {
3388
+ fileLocation += ":" + columnNumber;
3389
+ }
3390
+ }
3391
+ }
3392
+
3393
+ var line = "";
3394
+ var functionName = this.getFunctionName();
3395
+ var addSuffix = true;
3396
+ var isConstructor = this.isConstructor();
3397
+ var isMethodCall = !(this.isToplevel() || isConstructor);
3398
+ if (isMethodCall) {
3399
+ var typeName = this.getTypeName();
3400
+ // Fixes shim to be backward compatable with Node v0 to v4
3401
+ if (typeName === "[object Object]") {
3402
+ typeName = "null";
3403
+ }
3404
+ var methodName = this.getMethodName();
3405
+ if (functionName) {
3406
+ if (functionName.startsWith("$")) {
3407
+ functionName = functionName.slice(1);
3408
+ }
3409
+ if (typeName && functionName.indexOf(typeName) != 0) {
3410
+ line += typeName + ".";
3411
+ }
3412
+ line += functionName;
3413
+ if (methodName && functionName.indexOf("." + methodName) != functionName.length - methodName.length - 1) {
3414
+ line += " [as " + methodName + "]";
3415
+ }
3416
+ } else {
3417
+ line += typeName + "." + (methodName || "<anonymous>");
3418
+ }
3419
+ } else if (isConstructor) {
3420
+ line += "new " + (functionName || "<anonymous>");
3421
+ } else if (functionName) {
3422
+ line += functionName;
3423
+ } else {
3424
+ line += fileLocation;
3425
+ addSuffix = false;
3426
+ }
3427
+ if (addSuffix) {
3428
+ line += " (" + fileLocation + ")";
3429
+ }
3430
+ line = fileLocation + ":in `" + (functionName || methodName) + "'"
3431
+ return line;
3432
+ }
3433
+
3434
+ function cloneCallSite(frame) {
3435
+ var object = {};
3436
+ Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach(function(name) {
3437
+ object[name] = /^(?:is|get)/.test(name) ? function() { return frame[name].call(frame); } : frame[name];
3438
+ });
3439
+ object.toString = CallSiteToString;
3440
+ return object;
3441
+ }
3442
+
3443
+ function wrapCallSite(frame) {
3444
+ if(frame.isNative()) {
3445
+ return frame;
3446
+ }
3447
+
3448
+ // Most call sites will return the source file from getFileName(), but code
3449
+ // passed to eval() ending in "//# sourceURL=..." will return the source file
3450
+ // from getScriptNameOrSourceURL() instead
3451
+ var source = frame.getFileName() || frame.getScriptNameOrSourceURL();
3452
+ if (source) {
3453
+ var line = frame.getLineNumber();
3454
+ var column = frame.getColumnNumber() - 1;
3455
+
3456
+ // Fix position in Node where some (internal) code is prepended.
3457
+ // See https://github.com/evanw/node-source-map-support/issues/36
3458
+ var headerLength = 62;
3459
+ if (line === 1 && column > headerLength && !isInBrowser() && !frame.isEval()) {
3460
+ column -= headerLength;
3461
+ }
3462
+
3463
+ var position = mapSourcePosition({
3464
+ source: source,
3465
+ line: line,
3466
+ column: column
3467
+ });
3468
+ frame = cloneCallSite(frame);
3469
+ var originalFunctionName = frame.getFunctionName;
3470
+ frame.getFunctionName = function() { return position.name || originalFunctionName(); };
3471
+ frame.getFileName = function() { return position.source; };
3472
+ frame.getLineNumber = function() { return position.line; };
3473
+ frame.getColumnNumber = function() { return position.column + 1; };
3474
+ frame.getScriptNameOrSourceURL = function() { return position.source; };
3475
+ return frame;
3476
+ }
3477
+
3478
+ // Code called using eval() needs special handling
3479
+ var origin = frame.isEval() && frame.getEvalOrigin();
3480
+ if (origin) {
3481
+ origin = mapEvalOrigin(origin);
3482
+ frame = cloneCallSite(frame);
3483
+ frame.getEvalOrigin = function() { return origin; };
3484
+ return frame;
3485
+ }
3486
+
3487
+ // If we get here then we were unable to change the source position
3488
+ return frame;
3489
+ }
3490
+
3491
+ // This function is part of the V8 stack trace API, for more info see:
3492
+ // https://v8.dev/docs/stack-trace-api
3493
+ function prepareStackTrace(error, stack) {
3494
+ if (emptyCacheBetweenOperations) {
3495
+ fileContentsCache = {};
3496
+ sourceMapCache = {};
3497
+ }
3498
+
3499
+ var name = error.name || 'Error';
3500
+ var message = error.message || '';
3501
+ var errorString = name + ": " + message;
3502
+
3503
+ return errorString + stack.map(function(frame) {
3504
+ return '\n from ' + wrapCallSite(frame);
3505
+ }).join('');
3506
+ }
3507
+
3508
+ // Generate position and snippet of original source with pointer
3509
+ function getErrorSource(error) {
3510
+ var match = /\n from [^(]+ \((.*):(\d+):(\d+)\)/.exec(error.stack);
3511
+ if (match) {
3512
+ var source = match[1];
3513
+ var line = +match[2];
3514
+ var column = +match[3];
3515
+
3516
+ // Support the inline sourceContents inside the source map
3517
+ var contents = fileContentsCache[source];
3518
+
3519
+ // Support files on disk
3520
+ if (!contents && fs && fs.existsSync(source)) {
3521
+ try {
3522
+ contents = fs.readFileSync(source, 'utf8');
3523
+ } catch (er) {
3524
+ contents = '';
3525
+ }
3526
+ }
3527
+
3528
+ // Format the line from the original source code like node does
3529
+ if (contents) {
3530
+ var code = contents.split(/(?:\r\n|\r|\n)/)[line - 1];
3531
+ if (code) {
3532
+ return source + ':' + line + '\n' + code + '\n' +
3533
+ new Array(column).join(' ') + '^';
3534
+ }
3535
+ }
3536
+ }
3537
+ return null;
3538
+ }
3539
+
3540
+ function printErrorAndExit (error) {
3541
+ var source = getErrorSource(error);
3542
+
3543
+ // Ensure error is printed synchronously and not truncated
3544
+ if (process.stderr._handle && process.stderr._handle.setBlocking) {
3545
+ process.stderr._handle.setBlocking(true);
3546
+ }
3547
+
3548
+ if (source) {
3549
+ console.error();
3550
+ console.error(source);
3551
+ }
3552
+
3553
+ console.error(error.stack);
3554
+ process.exit(1);
3555
+ }
3556
+
3557
+ function shimEmitUncaughtException () {
3558
+ var origEmit = process.emit;
3559
+
3560
+ process.emit = function (type) {
3561
+ if (type === 'uncaughtException') {
3562
+ var hasStack = (arguments[1] && arguments[1].stack);
3563
+ var hasListeners = (this.listeners(type).length > 0);
3564
+
3565
+ if (hasStack && !hasListeners) {
3566
+ return printErrorAndExit(arguments[1]);
3567
+ }
3568
+ }
3569
+
3570
+ return origEmit.apply(this, arguments);
3571
+ };
3572
+ }
3573
+
3574
+ var originalRetrieveFileHandlers = retrieveFileHandlers.slice(0);
3575
+ var originalRetrieveMapHandlers = retrieveMapHandlers.slice(0);
3576
+
3577
+ exports.wrapCallSite = wrapCallSite;
3578
+ exports.getErrorSource = getErrorSource;
3579
+ exports.mapSourcePosition = mapSourcePosition;
3580
+ exports.retrieveSourceMap = retrieveSourceMap;
3581
+
3582
+ exports.install = function(options) {
3583
+ options = options || {};
3584
+
3585
+ if (options.environment) {
3586
+ environment = options.environment;
3587
+ if (["node", "browser", "auto"].indexOf(environment) === -1) {
3588
+ throw new Error("environment " + environment + " was unknown. Available options are {auto, browser, node}")
3589
+ }
3590
+ }
3591
+
3592
+ // Allow sources to be found by methods other than reading the files
3593
+ // directly from disk.
3594
+ if (options.retrieveFile) {
3595
+ if (options.overrideRetrieveFile) {
3596
+ retrieveFileHandlers.length = 0;
3597
+ }
3598
+
3599
+ retrieveFileHandlers.unshift(options.retrieveFile);
3600
+ }
3601
+
3602
+ // Allow source maps to be found by methods other than reading the files
3603
+ // directly from disk.
3604
+ if (options.retrieveSourceMap) {
3605
+ if (options.overrideRetrieveSourceMap) {
3606
+ retrieveMapHandlers.length = 0;
3607
+ }
3608
+
3609
+ retrieveMapHandlers.unshift(options.retrieveSourceMap);
3610
+ }
3611
+
3612
+ // Support runtime transpilers that include inline source maps
3613
+ if (options.hookRequire && !isInBrowser()) {
3614
+ var Module;
3615
+ try {
3616
+ Module = require('module');
3617
+ } catch (err) {
3618
+ // NOP: Loading in catch block to convert webpack error to warning.
3619
+ }
3620
+ var $compile = Module.prototype._compile;
3621
+
3622
+ if (!$compile.__sourceMapSupport) {
3623
+ Module.prototype._compile = function(content, filename) {
3624
+ fileContentsCache[filename] = content;
3625
+ sourceMapCache[filename] = undefined;
3626
+ return $compile.call(this, content, filename);
3627
+ };
3628
+
3629
+ Module.prototype._compile.__sourceMapSupport = true;
3630
+ }
3631
+ }
3632
+
3633
+ // Configure options
3634
+ if (!emptyCacheBetweenOperations) {
3635
+ emptyCacheBetweenOperations = 'emptyCacheBetweenOperations' in options ?
3636
+ options.emptyCacheBetweenOperations : false;
3637
+ }
3638
+
3639
+ // Install the error reformatter
3640
+ if (!errorFormatterInstalled) {
3641
+ errorFormatterInstalled = true;
3642
+ Error.prepareStackTrace = prepareStackTrace;
3643
+ }
3644
+
3645
+ if (!uncaughtShimInstalled) {
3646
+ var installHandler = 'handleUncaughtExceptions' in options ?
3647
+ options.handleUncaughtExceptions : true;
3648
+
3649
+ // Provide the option to not install the uncaught exception handler. This is
3650
+ // to support other uncaught exception handlers (in test frameworks, for
3651
+ // example). If this handler is not installed and there are no other uncaught
3652
+ // exception handlers, uncaught exceptions will be caught by node's built-in
3653
+ // exception handler and the process will still be terminated. However, the
3654
+ // generated JavaScript code will be shown above the stack trace instead of
3655
+ // the original source code.
3656
+ if (installHandler && hasGlobalProcessEventEmitter()) {
3657
+ uncaughtShimInstalled = true;
3658
+ shimEmitUncaughtException();
3659
+ }
3660
+ }
3661
+ };
3662
+
3663
+ exports.resetRetrieveHandlers = function() {
3664
+ retrieveFileHandlers.length = 0;
3665
+ retrieveMapHandlers.length = 0;
3666
+
3667
+ retrieveFileHandlers = originalRetrieveFileHandlers.slice(0);
3668
+ retrieveMapHandlers = originalRetrieveMapHandlers.slice(0);
3669
+
3670
+ retrieveSourceMap = handlerExec(retrieveMapHandlers);
3671
+ retrieveFile = handlerExec(retrieveFileHandlers);
3672
+ }
3673
+
3674
+ // Autoinstall.
3675
+ exports.install();
3676
+
3677
+ // Regenerate the browser version with:
3678
+ // browserify lib/opal/cli_runners/source-map-support.js -s sourceMapSupport | uglifyjs -c > lib/opal/cli_runners/source-map-support-browser.js
3679
+
3680
+ // = Stacktrace Examples:
3681
+ //
3682
+ // == Traditional Ruby stacktrace:
3683
+ //
3684
+ // /Users/elia/Code/opal/lib/opal/cli_runners/system_runner.rb:43:in `call': unhandled exception
3685
+ // from /Users/elia/Code/opal/lib/opal/cli_runners/nodejs.rb:14:in `call'
3686
+ // from /Users/elia/Code/opal/lib/opal/cli_runners.rb:50:in `block in register_runner'
3687
+ // from /Users/elia/Code/opal/lib/opal/cli.rb:62:in `run'
3688
+ // from /Users/elia/Code/opal/exe/opal:24:in `<top (required)>'
3689
+ // from bin/opal:4:in `load'
3690
+ // from bin/opal:4:in `<main>'
3691
+ //
3692
+ // == Traceback style:
3693
+ //
3694
+ // Traceback (most recent call last):
3695
+ // 6: from bin/opal:4:in `<main>'
3696
+ // 5: from bin/opal:4:in `load'
3697
+ // 4: from /Users/elia/Code/opal/exe/opal:24:in `<top (required)>'
3698
+ // 3: from /Users/elia/Code/opal/lib/opal/cli.rb:62:in `run'
3699
+ // 2: from /Users/elia/Code/opal/lib/opal/cli_runners.rb:50:in `block in register_runner'
3700
+ // 1: from /Users/elia/Code/opal/lib/opal/cli_runners/nodejs.rb:14:in `call'
3701
+ // /Users/elia/Code/opal/lib/opal/cli_runners/system_runner.rb:43:in `call': unhandled exception
3702
+
3703
+ },{"buffer-from":1,"fs":undefined,"module":undefined,"path":undefined,"source-map":12}]},{},[])("/lib/opal/cli_runners/source-map-support.js")
3704
+ });