opal 1.3.2 → 1.4.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -0
  3. data/.github/workflows/build.yml +0 -3
  4. data/.rubocop.yml +5 -1
  5. data/UNRELEASED.md +66 -2
  6. data/benchmark-ips/bm_truthy.rb +30 -0
  7. data/bin/opal-mspec +1 -3
  8. data/bin/opal-repl +1 -2
  9. data/bin/remove-filters +1 -4
  10. data/docs/compiled_ruby.md +10 -6
  11. data/exe/opal-repl +1 -3
  12. data/lib/opal/ast/builder.rb +1 -1
  13. data/lib/opal/cli.rb +2 -2
  14. data/lib/opal/cli_runners/nodejs.rb +9 -2
  15. data/lib/opal/cli_runners/source-map-support-browser.js +80 -216
  16. data/lib/opal/cli_runners/source-map-support-node.js +80 -216
  17. data/lib/opal/cli_runners/source-map-support.js +5 -1
  18. data/lib/opal/cli_runners/system_runner.rb +10 -4
  19. data/lib/opal/compiler.rb +3 -5
  20. data/lib/opal/fragment.rb +5 -1
  21. data/lib/opal/nodes/args/extract_block_arg.rb +1 -8
  22. data/lib/opal/nodes/args/extract_kwoptarg.rb +1 -3
  23. data/lib/opal/nodes/args/extract_optarg.rb +1 -3
  24. data/lib/opal/nodes/args/extract_post_arg.rb +2 -5
  25. data/lib/opal/nodes/args/extract_post_optarg.rb +2 -7
  26. data/lib/opal/nodes/args/initialize_iterarg.rb +1 -3
  27. data/lib/opal/nodes/args/prepare_post_args.rb +5 -1
  28. data/lib/opal/nodes/base.rb +3 -2
  29. data/lib/opal/nodes/call.rb +20 -9
  30. data/lib/opal/nodes/call_special.rb +50 -0
  31. data/lib/opal/nodes/class.rb +24 -15
  32. data/lib/opal/nodes/constants.rb +23 -5
  33. data/lib/opal/nodes/def.rb +20 -23
  34. data/lib/opal/nodes/defined.rb +5 -5
  35. data/lib/opal/nodes/definitions.rb +2 -2
  36. data/lib/opal/nodes/defs.rb +2 -5
  37. data/lib/opal/nodes/helpers.rb +48 -18
  38. data/lib/opal/nodes/if.rb +109 -8
  39. data/lib/opal/nodes/iter.rb +23 -16
  40. data/lib/opal/nodes/literal.rb +18 -4
  41. data/lib/opal/nodes/logic.rb +2 -1
  42. data/lib/opal/nodes/masgn.rb +4 -9
  43. data/lib/opal/nodes/module.rb +29 -19
  44. data/lib/opal/nodes/node_with_args.rb +1 -7
  45. data/lib/opal/nodes/scope.rb +54 -15
  46. data/lib/opal/nodes/singleton_class.rb +5 -3
  47. data/lib/opal/nodes/super.rb +3 -3
  48. data/lib/opal/nodes/top.rb +34 -31
  49. data/lib/opal/nodes/variables.rb +2 -2
  50. data/lib/opal/nodes/x_string.rb +3 -0
  51. data/lib/opal/nodes.rb +0 -1
  52. data/lib/opal/parser/patch.rb +75 -0
  53. data/lib/opal/parser/with_ruby_lexer.rb +1 -1
  54. data/lib/opal/regexp_anchors.rb +7 -7
  55. data/lib/opal/requires.rb +19 -0
  56. data/lib/opal/rewriters/pattern_matching.rb +1 -1
  57. data/lib/opal/rewriters/returnable_logic.rb +102 -4
  58. data/lib/opal/util.rb +2 -2
  59. data/lib/opal/version.rb +1 -1
  60. data/lib/opal.rb +1 -17
  61. data/opal/corelib/array/pack.rb +11 -11
  62. data/opal/corelib/array.rb +193 -152
  63. data/opal/corelib/basic_object.rb +14 -14
  64. data/opal/corelib/binding.rb +7 -7
  65. data/opal/corelib/boolean.rb +12 -15
  66. data/opal/corelib/class.rb +23 -1
  67. data/opal/corelib/comparable.rb +8 -8
  68. data/opal/corelib/complex/base.rb +2 -2
  69. data/opal/corelib/complex.rb +79 -88
  70. data/opal/corelib/constants.rb +9 -9
  71. data/opal/corelib/dir.rb +4 -3
  72. data/opal/corelib/enumerable.rb +140 -127
  73. data/opal/corelib/enumerator/arithmetic_sequence.rb +177 -0
  74. data/opal/corelib/enumerator/chain.rb +42 -0
  75. data/opal/corelib/enumerator/generator.rb +35 -0
  76. data/opal/corelib/enumerator/lazy.rb +243 -0
  77. data/opal/corelib/enumerator/yielder.rb +36 -0
  78. data/opal/corelib/enumerator.rb +45 -300
  79. data/opal/corelib/error/errno.rb +47 -0
  80. data/opal/corelib/error.rb +62 -60
  81. data/opal/corelib/file.rb +26 -12
  82. data/opal/corelib/hash.rb +98 -107
  83. data/opal/corelib/helpers.rb +62 -13
  84. data/opal/corelib/io.rb +47 -34
  85. data/opal/corelib/kernel/format.rb +29 -29
  86. data/opal/corelib/kernel.rb +86 -83
  87. data/opal/corelib/main.rb +14 -12
  88. data/opal/corelib/marshal/read_buffer.rb +15 -15
  89. data/opal/corelib/marshal/write_buffer.rb +45 -44
  90. data/opal/corelib/marshal.rb +3 -3
  91. data/opal/corelib/math.rb +50 -50
  92. data/opal/corelib/method.rb +12 -8
  93. data/opal/corelib/module.rb +96 -79
  94. data/opal/corelib/nil.rb +9 -11
  95. data/opal/corelib/number.rb +113 -118
  96. data/opal/corelib/numeric.rb +37 -33
  97. data/opal/corelib/object_space.rb +11 -10
  98. data/opal/corelib/pack_unpack/format_string_parser.rb +3 -3
  99. data/opal/corelib/pattern_matching/base.rb +7 -7
  100. data/opal/corelib/pattern_matching.rb +1 -1
  101. data/opal/corelib/proc.rb +15 -16
  102. data/opal/corelib/process/base.rb +2 -2
  103. data/opal/corelib/process/status.rb +21 -0
  104. data/opal/corelib/process.rb +5 -5
  105. data/opal/corelib/random/formatter.rb +11 -11
  106. data/opal/corelib/random/math_random.js.rb +1 -1
  107. data/opal/corelib/random/mersenne_twister.rb +3 -3
  108. data/opal/corelib/random/seedrandom.js.rb +3 -3
  109. data/opal/corelib/random.rb +17 -17
  110. data/opal/corelib/range.rb +51 -35
  111. data/opal/corelib/rational/base.rb +4 -4
  112. data/opal/corelib/rational.rb +61 -62
  113. data/opal/corelib/regexp.rb +47 -38
  114. data/opal/corelib/runtime.js +245 -139
  115. data/opal/corelib/string/encoding.rb +21 -21
  116. data/opal/corelib/string/unpack.rb +19 -14
  117. data/opal/corelib/string.rb +135 -128
  118. data/opal/corelib/struct.rb +59 -46
  119. data/opal/corelib/time.rb +47 -57
  120. data/opal/corelib/trace_point.rb +2 -2
  121. data/opal/corelib/unsupported.rb +31 -120
  122. data/opal/corelib/variables.rb +3 -3
  123. data/opal/opal/base.rb +9 -8
  124. data/opal/opal/full.rb +8 -8
  125. data/opal/opal/mini.rb +17 -17
  126. data/opal/opal.rb +17 -18
  127. data/opal.gemspec +1 -1
  128. data/spec/filters/bugs/array.rb +4 -24
  129. data/spec/filters/bugs/bigdecimal.rb +0 -23
  130. data/spec/filters/bugs/binding.rb +0 -1
  131. data/spec/filters/bugs/boolean.rb +3 -0
  132. data/spec/filters/bugs/class.rb +2 -0
  133. data/spec/filters/bugs/date.rb +0 -5
  134. data/spec/filters/bugs/encoding.rb +8 -50
  135. data/spec/filters/bugs/enumerable.rb +4 -1
  136. data/spec/filters/bugs/enumerator.rb +3 -36
  137. data/spec/filters/bugs/exception.rb +0 -2
  138. data/spec/filters/bugs/file.rb +0 -2
  139. data/spec/filters/bugs/float.rb +0 -3
  140. data/spec/filters/bugs/hash.rb +5 -3
  141. data/spec/filters/bugs/integer.rb +2 -3
  142. data/spec/filters/bugs/kernel.rb +2 -31
  143. data/spec/filters/bugs/language.rb +29 -49
  144. data/spec/filters/bugs/main.rb +0 -2
  145. data/spec/filters/bugs/marshal.rb +2 -3
  146. data/spec/filters/bugs/matrix.rb +0 -36
  147. data/spec/filters/bugs/module.rb +7 -61
  148. data/spec/filters/bugs/numeric.rb +0 -7
  149. data/spec/filters/bugs/objectspace.rb +1 -1
  150. data/spec/filters/bugs/pack_unpack.rb +0 -4
  151. data/spec/filters/bugs/proc.rb +0 -9
  152. data/spec/filters/bugs/random.rb +0 -5
  153. data/spec/filters/bugs/range.rb +1 -6
  154. data/spec/filters/bugs/regexp.rb +0 -3
  155. data/spec/filters/bugs/set.rb +8 -1
  156. data/spec/filters/bugs/string.rb +9 -34
  157. data/spec/filters/bugs/stringscanner.rb +8 -7
  158. data/spec/filters/bugs/struct.rb +2 -3
  159. data/spec/filters/bugs/symbol.rb +0 -1
  160. data/spec/filters/bugs/time.rb +0 -8
  161. data/spec/filters/bugs/unboundmethod.rb +0 -8
  162. data/spec/filters/bugs/warnings.rb +1 -7
  163. data/spec/filters/unsupported/freeze.rb +24 -0
  164. data/spec/filters/unsupported/integer.rb +1 -0
  165. data/spec/filters/unsupported/kernel.rb +12 -0
  166. data/spec/filters/unsupported/privacy.rb +3 -0
  167. data/spec/filters/unsupported/string.rb +2 -0
  168. data/spec/lib/builder_spec.rb +2 -2
  169. data/spec/lib/cli_spec.rb +1 -1
  170. data/spec/lib/compiler_spec.rb +37 -37
  171. data/spec/lib/simple_server_spec.rb +2 -2
  172. data/spec/lib/source_map/file_spec.rb +1 -1
  173. data/spec/opal/compiler/irb_spec.rb +2 -2
  174. data/spec/opal/core/kernel/puts_spec.rb +90 -0
  175. data/spec/opal/core/language/super_spec.rb +24 -0
  176. data/spec/ruby_specs +4 -2
  177. data/spec/support/rewriters_helper.rb +1 -1
  178. data/stdlib/bigdecimal.rb +7 -11
  179. data/stdlib/buffer/view.rb +2 -2
  180. data/stdlib/buffer.rb +2 -2
  181. data/stdlib/date.rb +5 -6
  182. data/stdlib/erb.rb +1 -0
  183. data/stdlib/js.rb +2 -1
  184. data/stdlib/native.rb +7 -8
  185. data/stdlib/nodejs/argf.rb +4 -4
  186. data/stdlib/nodejs/base.rb +29 -0
  187. data/stdlib/nodejs/dir.rb +1 -1
  188. data/stdlib/nodejs/env.rb +6 -9
  189. data/stdlib/nodejs/file.rb +23 -17
  190. data/stdlib/nodejs/fileutils.rb +3 -3
  191. data/stdlib/nodejs/io.rb +2 -20
  192. data/stdlib/nodejs/irb.rb +0 -0
  193. data/stdlib/nodejs/kernel.rb +2 -37
  194. data/stdlib/nodejs.rb +1 -3
  195. data/stdlib/opal/miniracer.rb +2 -0
  196. data/stdlib/opal/platform.rb +6 -13
  197. data/stdlib/opal/replutils.rb +16 -5
  198. data/stdlib/opal-parser.rb +2 -2
  199. data/stdlib/optparse/ac.rb +54 -0
  200. data/stdlib/optparse/date.rb +14 -0
  201. data/stdlib/optparse/kwargs.rb +22 -0
  202. data/stdlib/optparse/shellwords.rb +7 -0
  203. data/stdlib/optparse/time.rb +15 -0
  204. data/stdlib/optparse/uri.rb +7 -0
  205. data/stdlib/optparse/version.rb +69 -0
  206. data/stdlib/optparse.rb +2279 -0
  207. data/stdlib/pathname.rb +5 -6
  208. data/stdlib/pp.rb +18 -2
  209. data/stdlib/promise/v2.rb +18 -22
  210. data/stdlib/promise.rb +15 -21
  211. data/stdlib/set.rb +32 -32
  212. data/stdlib/shellwords.rb +240 -0
  213. data/stdlib/stringio.rb +3 -6
  214. data/stdlib/strscan.rb +5 -8
  215. data/stdlib/template.rb +2 -2
  216. data/stdlib/thread.rb +7 -9
  217. data/tasks/performance.rake +5 -2
  218. data/tasks/testing/mspec_special_calls.rb +0 -12
  219. data/tasks/testing.rake +55 -37
  220. data/test/nodejs/test_file.rb +11 -0
  221. metadata +55 -10
  222. data/lib/opal/nodes/case.rb +0 -114
@@ -1,7 +1,10 @@
1
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
+ /* eslint-disable node/no-deprecated-api */
3
+
2
4
  var toString = Object.prototype.toString
3
5
 
4
6
  var isModern = (
7
+ typeof Buffer !== 'undefined' &&
5
8
  typeof Buffer.alloc === 'function' &&
6
9
  typeof Buffer.allocUnsafe === 'function' &&
7
10
  typeof Buffer.from === 'function'
@@ -727,19 +730,19 @@ var ArraySet = require('./array-set').ArraySet;
727
730
  var base64VLQ = require('./base64-vlq');
728
731
  var quickSort = require('./quick-sort').quickSort;
729
732
 
730
- function SourceMapConsumer(aSourceMap, aSourceMapURL) {
733
+ function SourceMapConsumer(aSourceMap) {
731
734
  var sourceMap = aSourceMap;
732
735
  if (typeof aSourceMap === 'string') {
733
- sourceMap = util.parseSourceMapInput(aSourceMap);
736
+ sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
734
737
  }
735
738
 
736
739
  return sourceMap.sections != null
737
- ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
738
- : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
740
+ ? new IndexedSourceMapConsumer(sourceMap)
741
+ : new BasicSourceMapConsumer(sourceMap);
739
742
  }
740
743
 
741
- SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
742
- return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
744
+ SourceMapConsumer.fromSourceMap = function(aSourceMap) {
745
+ return BasicSourceMapConsumer.fromSourceMap(aSourceMap);
743
746
  }
744
747
 
745
748
  /**
@@ -779,8 +782,6 @@ SourceMapConsumer.prototype._version = 3;
779
782
 
780
783
  SourceMapConsumer.prototype.__generatedMappings = null;
781
784
  Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
782
- configurable: true,
783
- enumerable: true,
784
785
  get: function () {
785
786
  if (!this.__generatedMappings) {
786
787
  this._parseMappings(this._mappings, this.sourceRoot);
@@ -792,8 +793,6 @@ Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
792
793
 
793
794
  SourceMapConsumer.prototype.__originalMappings = null;
794
795
  Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
795
- configurable: true,
796
- enumerable: true,
797
796
  get: function () {
798
797
  if (!this.__originalMappings) {
799
798
  this._parseMappings(this._mappings, this.sourceRoot);
@@ -861,7 +860,9 @@ SourceMapConsumer.prototype.eachMapping =
861
860
  var sourceRoot = this.sourceRoot;
862
861
  mappings.map(function (mapping) {
863
862
  var source = mapping.source === null ? null : this._sources.at(mapping.source);
864
- source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
863
+ if (source != null && sourceRoot != null) {
864
+ source = util.join(sourceRoot, source);
865
+ }
865
866
  return {
866
867
  source: source,
867
868
  generatedLine: mapping.generatedLine,
@@ -884,16 +885,13 @@ SourceMapConsumer.prototype.eachMapping =
884
885
  * The only argument is an object with the following properties:
885
886
  *
886
887
  * - source: The filename of the original source.
887
- * - line: The line number in the original source. The line number is 1-based.
888
+ * - line: The line number in the original source.
888
889
  * - column: Optional. the column number in the original source.
889
- * The column number is 0-based.
890
890
  *
891
891
  * and an array of objects is returned, each with the following properties:
892
892
  *
893
- * - line: The line number in the generated source, or null. The
894
- * line number is 1-based.
893
+ * - line: The line number in the generated source, or null.
895
894
  * - column: The column number in the generated source, or null.
896
- * The column number is 0-based.
897
895
  */
898
896
  SourceMapConsumer.prototype.allGeneratedPositionsFor =
899
897
  function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
@@ -909,10 +907,13 @@ SourceMapConsumer.prototype.allGeneratedPositionsFor =
909
907
  originalColumn: util.getArg(aArgs, 'column', 0)
910
908
  };
911
909
 
912
- needle.source = this._findSourceIndex(needle.source);
913
- if (needle.source < 0) {
910
+ if (this.sourceRoot != null) {
911
+ needle.source = util.relative(this.sourceRoot, needle.source);
912
+ }
913
+ if (!this._sources.has(needle.source)) {
914
914
  return [];
915
915
  }
916
+ needle.source = this._sources.indexOf(needle.source);
916
917
 
917
918
  var mappings = [];
918
919
 
@@ -972,7 +973,7 @@ exports.SourceMapConsumer = SourceMapConsumer;
972
973
  * query for information about the original file positions by giving it a file
973
974
  * position in the generated source.
974
975
  *
975
- * The first parameter is the raw source map (either as a JSON string, or
976
+ * The only parameter is the raw source map (either as a JSON string, or
976
977
  * already parsed to an object). According to the spec, source maps have the
977
978
  * following attributes:
978
979
  *
@@ -995,16 +996,12 @@ exports.SourceMapConsumer = SourceMapConsumer;
995
996
  * mappings: "AA,AB;;ABCDE;"
996
997
  * }
997
998
  *
998
- * The second parameter, if given, is a string whose value is the URL
999
- * at which the source map was found. This URL is used to compute the
1000
- * sources array.
1001
- *
1002
999
  * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
1003
1000
  */
1004
- function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
1001
+ function BasicSourceMapConsumer(aSourceMap) {
1005
1002
  var sourceMap = aSourceMap;
1006
1003
  if (typeof aSourceMap === 'string') {
1007
- sourceMap = util.parseSourceMapInput(aSourceMap);
1004
+ sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
1008
1005
  }
1009
1006
 
1010
1007
  var version = util.getArg(sourceMap, 'version');
@@ -1023,10 +1020,6 @@ function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
1023
1020
  throw new Error('Unsupported version: ' + version);
1024
1021
  }
1025
1022
 
1026
- if (sourceRoot) {
1027
- sourceRoot = util.normalize(sourceRoot);
1028
- }
1029
-
1030
1023
  sources = sources
1031
1024
  .map(String)
1032
1025
  // Some source maps produce relative source paths like "./foo.js" instead of
@@ -1050,57 +1043,24 @@ function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
1050
1043
  this._names = ArraySet.fromArray(names.map(String), true);
1051
1044
  this._sources = ArraySet.fromArray(sources, true);
1052
1045
 
1053
- this._absoluteSources = this._sources.toArray().map(function (s) {
1054
- return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
1055
- });
1056
-
1057
1046
  this.sourceRoot = sourceRoot;
1058
1047
  this.sourcesContent = sourcesContent;
1059
1048
  this._mappings = mappings;
1060
- this._sourceMapURL = aSourceMapURL;
1061
1049
  this.file = file;
1062
1050
  }
1063
1051
 
1064
1052
  BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
1065
1053
  BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
1066
1054
 
1067
- /**
1068
- * Utility function to find the index of a source. Returns -1 if not
1069
- * found.
1070
- */
1071
- BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
1072
- var relativeSource = aSource;
1073
- if (this.sourceRoot != null) {
1074
- relativeSource = util.relative(this.sourceRoot, relativeSource);
1075
- }
1076
-
1077
- if (this._sources.has(relativeSource)) {
1078
- return this._sources.indexOf(relativeSource);
1079
- }
1080
-
1081
- // Maybe aSource is an absolute URL as returned by |sources|. In
1082
- // this case we can't simply undo the transform.
1083
- var i;
1084
- for (i = 0; i < this._absoluteSources.length; ++i) {
1085
- if (this._absoluteSources[i] == aSource) {
1086
- return i;
1087
- }
1088
- }
1089
-
1090
- return -1;
1091
- };
1092
-
1093
1055
  /**
1094
1056
  * Create a BasicSourceMapConsumer from a SourceMapGenerator.
1095
1057
  *
1096
1058
  * @param SourceMapGenerator aSourceMap
1097
1059
  * The source map that will be consumed.
1098
- * @param String aSourceMapURL
1099
- * The URL at which the source map can be found (optional)
1100
1060
  * @returns BasicSourceMapConsumer
1101
1061
  */
1102
1062
  BasicSourceMapConsumer.fromSourceMap =
1103
- function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
1063
+ function SourceMapConsumer_fromSourceMap(aSourceMap) {
1104
1064
  var smc = Object.create(BasicSourceMapConsumer.prototype);
1105
1065
 
1106
1066
  var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
@@ -1109,10 +1069,6 @@ BasicSourceMapConsumer.fromSourceMap =
1109
1069
  smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
1110
1070
  smc.sourceRoot);
1111
1071
  smc.file = aSourceMap._file;
1112
- smc._sourceMapURL = aSourceMapURL;
1113
- smc._absoluteSources = smc._sources.toArray().map(function (s) {
1114
- return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
1115
- });
1116
1072
 
1117
1073
  // Because we are modifying the entries (by converting string sources and
1118
1074
  // names to indices into the sources and names ArraySets), we have to make
@@ -1159,7 +1115,9 @@ BasicSourceMapConsumer.prototype._version = 3;
1159
1115
  */
1160
1116
  Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
1161
1117
  get: function () {
1162
- return this._absoluteSources.slice();
1118
+ return this._sources.toArray().map(function (s) {
1119
+ return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s;
1120
+ }, this);
1163
1121
  }
1164
1122
  });
1165
1123
 
@@ -1340,10 +1298,8 @@ BasicSourceMapConsumer.prototype.computeColumnSpans =
1340
1298
  * source's line and column positions provided. The only argument is an object
1341
1299
  * with the following properties:
1342
1300
  *
1343
- * - line: The line number in the generated source. The line number
1344
- * is 1-based.
1345
- * - column: The column number in the generated source. The column
1346
- * number is 0-based.
1301
+ * - line: The line number in the generated source.
1302
+ * - column: The column number in the generated source.
1347
1303
  * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
1348
1304
  * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
1349
1305
  * closest element that is smaller than or greater than the one we are
@@ -1353,10 +1309,8 @@ BasicSourceMapConsumer.prototype.computeColumnSpans =
1353
1309
  * and an object is returned with the following properties:
1354
1310
  *
1355
1311
  * - source: The original source file, or null.
1356
- * - line: The line number in the original source, or null. The
1357
- * line number is 1-based.
1358
- * - column: The column number in the original source, or null. The
1359
- * column number is 0-based.
1312
+ * - line: The line number in the original source, or null.
1313
+ * - column: The column number in the original source, or null.
1360
1314
  * - name: The original identifier, or null.
1361
1315
  */
1362
1316
  BasicSourceMapConsumer.prototype.originalPositionFor =
@@ -1382,7 +1336,9 @@ BasicSourceMapConsumer.prototype.originalPositionFor =
1382
1336
  var source = util.getArg(mapping, 'source', null);
1383
1337
  if (source !== null) {
1384
1338
  source = this._sources.at(source);
1385
- source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
1339
+ if (this.sourceRoot != null) {
1340
+ source = util.join(this.sourceRoot, source);
1341
+ }
1386
1342
  }
1387
1343
  var name = util.getArg(mapping, 'name', null);
1388
1344
  if (name !== null) {
@@ -1429,14 +1385,12 @@ BasicSourceMapConsumer.prototype.sourceContentFor =
1429
1385
  return null;
1430
1386
  }
1431
1387
 
1432
- var index = this._findSourceIndex(aSource);
1433
- if (index >= 0) {
1434
- return this.sourcesContent[index];
1388
+ if (this.sourceRoot != null) {
1389
+ aSource = util.relative(this.sourceRoot, aSource);
1435
1390
  }
1436
1391
 
1437
- var relativeSource = aSource;
1438
- if (this.sourceRoot != null) {
1439
- relativeSource = util.relative(this.sourceRoot, relativeSource);
1392
+ if (this._sources.has(aSource)) {
1393
+ return this.sourcesContent[this._sources.indexOf(aSource)];
1440
1394
  }
1441
1395
 
1442
1396
  var url;
@@ -1446,15 +1400,15 @@ BasicSourceMapConsumer.prototype.sourceContentFor =
1446
1400
  // many users. We can help them out when they expect file:// URIs to
1447
1401
  // behave like it would if they were running a local HTTP server. See
1448
1402
  // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
1449
- var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
1403
+ var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
1450
1404
  if (url.scheme == "file"
1451
1405
  && this._sources.has(fileUriAbsPath)) {
1452
1406
  return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
1453
1407
  }
1454
1408
 
1455
1409
  if ((!url.path || url.path == "/")
1456
- && this._sources.has("/" + relativeSource)) {
1457
- return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
1410
+ && this._sources.has("/" + aSource)) {
1411
+ return this.sourcesContent[this._sources.indexOf("/" + aSource)];
1458
1412
  }
1459
1413
  }
1460
1414
 
@@ -1466,7 +1420,7 @@ BasicSourceMapConsumer.prototype.sourceContentFor =
1466
1420
  return null;
1467
1421
  }
1468
1422
  else {
1469
- throw new Error('"' + relativeSource + '" is not in the SourceMap.');
1423
+ throw new Error('"' + aSource + '" is not in the SourceMap.');
1470
1424
  }
1471
1425
  };
1472
1426
 
@@ -1476,10 +1430,8 @@ BasicSourceMapConsumer.prototype.sourceContentFor =
1476
1430
  * the following properties:
1477
1431
  *
1478
1432
  * - source: The filename of the original source.
1479
- * - line: The line number in the original source. The line number
1480
- * is 1-based.
1481
- * - column: The column number in the original source. The column
1482
- * number is 0-based.
1433
+ * - line: The line number in the original source.
1434
+ * - column: The column number in the original source.
1483
1435
  * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
1484
1436
  * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
1485
1437
  * closest element that is smaller than or greater than the one we are
@@ -1488,22 +1440,23 @@ BasicSourceMapConsumer.prototype.sourceContentFor =
1488
1440
  *
1489
1441
  * and an object is returned with the following properties:
1490
1442
  *
1491
- * - line: The line number in the generated source, or null. The
1492
- * line number is 1-based.
1443
+ * - line: The line number in the generated source, or null.
1493
1444
  * - column: The column number in the generated source, or null.
1494
- * The column number is 0-based.
1495
1445
  */
1496
1446
  BasicSourceMapConsumer.prototype.generatedPositionFor =
1497
1447
  function SourceMapConsumer_generatedPositionFor(aArgs) {
1498
1448
  var source = util.getArg(aArgs, 'source');
1499
- source = this._findSourceIndex(source);
1500
- if (source < 0) {
1449
+ if (this.sourceRoot != null) {
1450
+ source = util.relative(this.sourceRoot, source);
1451
+ }
1452
+ if (!this._sources.has(source)) {
1501
1453
  return {
1502
1454
  line: null,
1503
1455
  column: null,
1504
1456
  lastColumn: null
1505
1457
  };
1506
1458
  }
1459
+ source = this._sources.indexOf(source);
1507
1460
 
1508
1461
  var needle = {
1509
1462
  source: source,
@@ -1547,7 +1500,7 @@ exports.BasicSourceMapConsumer = BasicSourceMapConsumer;
1547
1500
  * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
1548
1501
  * input.
1549
1502
  *
1550
- * The first parameter is a raw source map (either as a JSON string, or already
1503
+ * The only parameter is a raw source map (either as a JSON string, or already
1551
1504
  * parsed to an object). According to the spec for indexed source maps, they
1552
1505
  * have the following attributes:
1553
1506
  *
@@ -1584,16 +1537,12 @@ exports.BasicSourceMapConsumer = BasicSourceMapConsumer;
1584
1537
  * }],
1585
1538
  * }
1586
1539
  *
1587
- * The second parameter, if given, is a string whose value is the URL
1588
- * at which the source map was found. This URL is used to compute the
1589
- * sources array.
1590
- *
1591
1540
  * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
1592
1541
  */
1593
- function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
1542
+ function IndexedSourceMapConsumer(aSourceMap) {
1594
1543
  var sourceMap = aSourceMap;
1595
1544
  if (typeof aSourceMap === 'string') {
1596
- sourceMap = util.parseSourceMapInput(aSourceMap);
1545
+ sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
1597
1546
  }
1598
1547
 
1599
1548
  var version = util.getArg(sourceMap, 'version');
@@ -1633,7 +1582,7 @@ function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
1633
1582
  generatedLine: offsetLine + 1,
1634
1583
  generatedColumn: offsetColumn + 1
1635
1584
  },
1636
- consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
1585
+ consumer: new SourceMapConsumer(util.getArg(s, 'map'))
1637
1586
  }
1638
1587
  });
1639
1588
  }
@@ -1666,18 +1615,14 @@ Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
1666
1615
  * source's line and column positions provided. The only argument is an object
1667
1616
  * with the following properties:
1668
1617
  *
1669
- * - line: The line number in the generated source. The line number
1670
- * is 1-based.
1671
- * - column: The column number in the generated source. The column
1672
- * number is 0-based.
1618
+ * - line: The line number in the generated source.
1619
+ * - column: The column number in the generated source.
1673
1620
  *
1674
1621
  * and an object is returned with the following properties:
1675
1622
  *
1676
1623
  * - source: The original source file, or null.
1677
- * - line: The line number in the original source, or null. The
1678
- * line number is 1-based.
1679
- * - column: The column number in the original source, or null. The
1680
- * column number is 0-based.
1624
+ * - line: The line number in the original source, or null.
1625
+ * - column: The column number in the original source, or null.
1681
1626
  * - name: The original identifier, or null.
1682
1627
  */
1683
1628
  IndexedSourceMapConsumer.prototype.originalPositionFor =
@@ -1761,17 +1706,13 @@ IndexedSourceMapConsumer.prototype.sourceContentFor =
1761
1706
  * the following properties:
1762
1707
  *
1763
1708
  * - source: The filename of the original source.
1764
- * - line: The line number in the original source. The line number
1765
- * is 1-based.
1766
- * - column: The column number in the original source. The column
1767
- * number is 0-based.
1709
+ * - line: The line number in the original source.
1710
+ * - column: The column number in the original source.
1768
1711
  *
1769
1712
  * and an object is returned with the following properties:
1770
1713
  *
1771
- * - line: The line number in the generated source, or null. The
1772
- * line number is 1-based.
1714
+ * - line: The line number in the generated source, or null.
1773
1715
  * - column: The column number in the generated source, or null.
1774
- * The column number is 0-based.
1775
1716
  */
1776
1717
  IndexedSourceMapConsumer.prototype.generatedPositionFor =
1777
1718
  function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
@@ -1780,7 +1721,7 @@ IndexedSourceMapConsumer.prototype.generatedPositionFor =
1780
1721
 
1781
1722
  // Only consider this section if the requested source is in the list of
1782
1723
  // sources of the consumer.
1783
- if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
1724
+ if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) {
1784
1725
  continue;
1785
1726
  }
1786
1727
  var generatedPosition = section.consumer.generatedPositionFor(aArgs);
@@ -1819,16 +1760,15 @@ IndexedSourceMapConsumer.prototype._parseMappings =
1819
1760
  var mapping = sectionMappings[j];
1820
1761
 
1821
1762
  var source = section.consumer._sources.at(mapping.source);
1822
- source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
1763
+ if (section.consumer.sourceRoot !== null) {
1764
+ source = util.join(section.consumer.sourceRoot, source);
1765
+ }
1823
1766
  this._sources.add(source);
1824
1767
  source = this._sources.indexOf(source);
1825
1768
 
1826
- var name = null;
1827
- if (mapping.name) {
1828
- name = section.consumer._names.at(mapping.name);
1829
- this._names.add(name);
1830
- name = this._names.indexOf(name);
1831
- }
1769
+ var name = section.consumer._names.at(mapping.name);
1770
+ this._names.add(name);
1771
+ name = this._names.indexOf(name);
1832
1772
 
1833
1773
  // The mappings coming from the consumer for the section have
1834
1774
  // generated positions relative to the start of the section, so we
@@ -1935,15 +1875,6 @@ SourceMapGenerator.fromSourceMap =
1935
1875
  generator.addMapping(newMapping);
1936
1876
  });
1937
1877
  aSourceMapConsumer.sources.forEach(function (sourceFile) {
1938
- var sourceRelative = sourceFile;
1939
- if (sourceRoot !== null) {
1940
- sourceRelative = util.relative(sourceRoot, sourceFile);
1941
- }
1942
-
1943
- if (!generator._sources.has(sourceRelative)) {
1944
- generator._sources.add(sourceRelative);
1945
- }
1946
-
1947
1878
  var content = aSourceMapConsumer.sourceContentFor(sourceFile);
1948
1879
  if (content != null) {
1949
1880
  generator.setSourceContent(sourceFile, content);
@@ -2387,7 +2318,7 @@ SourceNode.fromStringWithSourceMap =
2387
2318
  // There is no new line in between.
2388
2319
  // Associate the code between "lastGeneratedColumn" and
2389
2320
  // "mapping.generatedColumn" with "lastMapping"
2390
- var nextLine = remainingLines[remainingLinesIndex] || '';
2321
+ var nextLine = remainingLines[remainingLinesIndex];
2391
2322
  var code = nextLine.substr(0, mapping.generatedColumn -
2392
2323
  lastGeneratedColumn);
2393
2324
  remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
@@ -2407,7 +2338,7 @@ SourceNode.fromStringWithSourceMap =
2407
2338
  lastGeneratedLine++;
2408
2339
  }
2409
2340
  if (lastGeneratedColumn < mapping.generatedColumn) {
2410
- var nextLine = remainingLines[remainingLinesIndex] || '';
2341
+ var nextLine = remainingLines[remainingLinesIndex];
2411
2342
  node.add(nextLine.substr(0, mapping.generatedColumn));
2412
2343
  remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
2413
2344
  lastGeneratedColumn = mapping.generatedColumn;
@@ -2731,7 +2662,7 @@ function getArg(aArgs, aName, aDefaultValue) {
2731
2662
  }
2732
2663
  exports.getArg = getArg;
2733
2664
 
2734
- var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
2665
+ var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/;
2735
2666
  var dataUrlRegexp = /^data:.+\,.+$/;
2736
2667
 
2737
2668
  function urlParse(aUrl) {
@@ -2887,7 +2818,7 @@ function join(aRoot, aPath) {
2887
2818
  exports.join = join;
2888
2819
 
2889
2820
  exports.isAbsolute = function (aPath) {
2890
- return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
2821
+ return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp);
2891
2822
  };
2892
2823
 
2893
2824
  /**
@@ -3007,7 +2938,7 @@ function isProtoString(s) {
3007
2938
  * stubbed out mapping.
3008
2939
  */
3009
2940
  function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
3010
- var cmp = strcmp(mappingA.source, mappingB.source);
2941
+ var cmp = mappingA.source - mappingB.source;
3011
2942
  if (cmp !== 0) {
3012
2943
  return cmp;
3013
2944
  }
@@ -3032,7 +2963,7 @@ function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
3032
2963
  return cmp;
3033
2964
  }
3034
2965
 
3035
- return strcmp(mappingA.name, mappingB.name);
2966
+ return mappingA.name - mappingB.name;
3036
2967
  }
3037
2968
  exports.compareByOriginalPositions = compareByOriginalPositions;
3038
2969
 
@@ -3056,7 +2987,7 @@ function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGene
3056
2987
  return cmp;
3057
2988
  }
3058
2989
 
3059
- cmp = strcmp(mappingA.source, mappingB.source);
2990
+ cmp = mappingA.source - mappingB.source;
3060
2991
  if (cmp !== 0) {
3061
2992
  return cmp;
3062
2993
  }
@@ -3071,7 +3002,7 @@ function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGene
3071
3002
  return cmp;
3072
3003
  }
3073
3004
 
3074
- return strcmp(mappingA.name, mappingB.name);
3005
+ return mappingA.name - mappingB.name;
3075
3006
  }
3076
3007
  exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
3077
3008
 
@@ -3080,14 +3011,6 @@ function strcmp(aStr1, aStr2) {
3080
3011
  return 0;
3081
3012
  }
3082
3013
 
3083
- if (aStr1 === null) {
3084
- return 1; // aStr2 !== null
3085
- }
3086
-
3087
- if (aStr2 === null) {
3088
- return -1; // aStr1 !== null
3089
- }
3090
-
3091
3014
  if (aStr1 > aStr2) {
3092
3015
  return 1;
3093
3016
  }
@@ -3129,69 +3052,6 @@ function compareByGeneratedPositionsInflated(mappingA, mappingB) {
3129
3052
  }
3130
3053
  exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
3131
3054
 
3132
- /**
3133
- * Strip any JSON XSSI avoidance prefix from the string (as documented
3134
- * in the source maps specification), and then parse the string as
3135
- * JSON.
3136
- */
3137
- function parseSourceMapInput(str) {
3138
- return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
3139
- }
3140
- exports.parseSourceMapInput = parseSourceMapInput;
3141
-
3142
- /**
3143
- * Compute the URL of a source given the the source root, the source's
3144
- * URL, and the source map's URL.
3145
- */
3146
- function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
3147
- sourceURL = sourceURL || '';
3148
-
3149
- if (sourceRoot) {
3150
- // This follows what Chrome does.
3151
- if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
3152
- sourceRoot += '/';
3153
- }
3154
- // The spec says:
3155
- // Line 4: An optional source root, useful for relocating source
3156
- // files on a server or removing repeated values in the
3157
- // “sources” entry. This value is prepended to the individual
3158
- // entries in the “source” field.
3159
- sourceURL = sourceRoot + sourceURL;
3160
- }
3161
-
3162
- // Historically, SourceMapConsumer did not take the sourceMapURL as
3163
- // a parameter. This mode is still somewhat supported, which is why
3164
- // this code block is conditional. However, it's preferable to pass
3165
- // the source map URL to SourceMapConsumer, so that this function
3166
- // can implement the source URL resolution algorithm as outlined in
3167
- // the spec. This block is basically the equivalent of:
3168
- // new URL(sourceURL, sourceMapURL).toString()
3169
- // ... except it avoids using URL, which wasn't available in the
3170
- // older releases of node still supported by this library.
3171
- //
3172
- // The spec says:
3173
- // If the sources are not absolute URLs after prepending of the
3174
- // “sourceRoot”, the sources are resolved relative to the
3175
- // SourceMap (like resolving script src in a html document).
3176
- if (sourceMapURL) {
3177
- var parsed = urlParse(sourceMapURL);
3178
- if (!parsed) {
3179
- throw new Error("sourceMapURL could not be parsed");
3180
- }
3181
- if (parsed.path) {
3182
- // Strip the last path component, but keep the "/".
3183
- var index = parsed.path.lastIndexOf('/');
3184
- if (index >= 0) {
3185
- parsed.path = parsed.path.substring(0, index + 1);
3186
- }
3187
- }
3188
- sourceURL = join(urlGenerate(parsed), sourceURL);
3189
- }
3190
-
3191
- return normalize(sourceURL);
3192
- }
3193
- exports.computeSourceURL = computeSourceURL;
3194
-
3195
3055
  },{}],12:[function(require,module,exports){
3196
3056
  /*
3197
3057
  * Copyright 2009-2011 Mozilla Foundation and contributors
@@ -3721,7 +3581,11 @@ function printErrorAndExit (error) {
3721
3581
  }
3722
3582
 
3723
3583
  if (typeof error.$full_message === 'function') {
3724
- console.error(error.$full_message().$chomp());
3584
+ var full_message = error.$full_message();
3585
+ while (full_message[full_message.length - 1] == "\n") {
3586
+ full_message = full_message.slice(0, full_message.length - 1);
3587
+ }
3588
+ console.error(full_message);
3725
3589
  }
3726
3590
  else {
3727
3591
  if (source) {
@@ -516,7 +516,11 @@ function printErrorAndExit (error) {
516
516
  }
517
517
 
518
518
  if (typeof error.$full_message === 'function') {
519
- console.error(error.$full_message().$chomp());
519
+ var full_message = error.$full_message();
520
+ while (full_message[full_message.length - 1] == "\n") {
521
+ full_message = full_message.slice(0, full_message.length - 1);
522
+ }
523
+ console.error(full_message);
520
524
  }
521
525
  else {
522
526
  if (source) {
@@ -17,9 +17,11 @@ SystemRunner = ->(data, &block) {
17
17
  output = data.fetch(:output)
18
18
 
19
19
  env = options.fetch(:env, {})
20
- debug = options.fetch(:debug, false)
20
+ debug = options.fetch(:debug, false) || RUBY_ENGINE == 'opal'
21
21
 
22
- code = builder.to_s + "\n" + builder.source_map.to_data_uri_comment
22
+ code = builder.to_s
23
+ # Temporary issue with UTF-8, Base64 and source maps
24
+ code += "\n" + builder.source_map.to_data_uri_comment unless RUBY_ENGINE == 'opal'
23
25
 
24
26
  tempfile =
25
27
  if debug
@@ -32,11 +34,15 @@ SystemRunner = ->(data, &block) {
32
34
  cmd = block.call tempfile
33
35
  tempfile.close
34
36
 
35
- # JRuby (v9.2) doesn't support using `out:` to redirect output.
36
- if IO.try_convert(output) && RUBY_PLATFORM != 'java'
37
+ if RUBY_PLATFORM == 'opal'
38
+ # Opal doesn't support neither `out:` nor `IO.try_convert` nor `open3`
39
+ system(env, *cmd)
40
+ $?.exitstatus
41
+ elsif IO.try_convert(output) && RUBY_PLATFORM != 'java'
37
42
  system(env, *cmd, out: output)
38
43
  $?.exitstatus
39
44
  else
45
+ # JRuby (v9.2) doesn't support using `out:` to redirect output.
40
46
  require 'open3'
41
47
  captured_output, status = Open3.capture2(env, *cmd)
42
48
  output.write captured_output