opal 1.1.0.rc1 → 1.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +4 -4
- data/.github/ISSUE_TEMPLATE/bug-report.md +47 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/workflows/build.yml +11 -5
- data/.gitignore +1 -0
- data/.jshintrc +1 -1
- data/CHANGELOG.md +42 -1
- data/Gemfile +0 -4
- data/HACKING.md +1 -1
- data/LICENSE +1 -1
- data/README.md +20 -16
- data/UNRELEASED.md +32 -95
- data/benchmark-ips/bm_array_unshift.rb +7 -0
- data/benchmark-ips/bm_js_symbols_vs_strings.rb +7 -2
- data/bin/build-browser-source-map-support +2 -3
- data/bin/opal-mspec +2 -0
- data/docs/compiler.md +1 -1
- data/examples/rack/Gemfile +0 -1
- data/examples/rack/Gemfile.lock +0 -4
- data/lib/opal/cli.rb +1 -0
- data/lib/opal/cli_options.rb +4 -0
- data/lib/opal/cli_runners/nodejs.rb +5 -1
- data/lib/opal/cli_runners/source-map-support-browser.js +8 -2
- data/lib/opal/cli_runners/source-map-support-node.js +3706 -0
- data/lib/opal/cli_runners/source-map-support.js +3 -1
- data/lib/opal/compiler.rb +2 -2
- data/lib/opal/nodes/args/arity_check.rb +1 -0
- data/lib/opal/nodes/args/parameters.rb +6 -0
- data/lib/opal/nodes/class.rb +1 -13
- data/lib/opal/nodes/literal.rb +14 -7
- data/lib/opal/nodes/module.rb +13 -9
- data/lib/opal/nodes/variables.rb +13 -4
- data/lib/opal/nodes/while.rb +54 -17
- data/lib/opal/parser.rb +1 -5
- data/lib/opal/parser/patch.rb +34 -0
- data/lib/opal/repl.rb +7 -0
- data/lib/opal/rewriter.rb +2 -0
- data/lib/opal/rewriters/arguments.rb +4 -1
- data/lib/opal/rewriters/forward_args.rb +54 -0
- data/lib/opal/rewriters/logical_operator_assignment.rb +5 -2
- data/lib/opal/rewriters/opal_engine_check.rb +5 -7
- data/lib/opal/version.rb +1 -1
- data/opal.gemspec +1 -1
- data/opal/corelib/array.rb +42 -20
- data/opal/corelib/array/pack.rb +6 -1
- data/opal/corelib/complex.rb +2 -0
- data/opal/corelib/constants.rb +3 -3
- data/opal/corelib/hash.rb +36 -38
- data/opal/corelib/module.rb +2 -7
- data/opal/corelib/number.rb +2 -180
- data/opal/corelib/numeric.rb +156 -0
- data/opal/corelib/object_space.rb +102 -0
- data/opal/corelib/random.rb +31 -66
- data/opal/corelib/random/formatter.rb +122 -0
- data/opal/corelib/range.rb +50 -19
- data/opal/corelib/runtime.js +82 -21
- data/opal/corelib/string.rb +86 -52
- data/opal/corelib/string/encoding.rb +140 -25
- data/opal/corelib/string/unpack.rb +26 -40
- data/opal/opal.rb +1 -0
- data/opal/opal/full.rb +1 -0
- data/package.json +1 -1
- data/spec/filters/bugs/array.rb +0 -22
- data/spec/filters/bugs/basicobject.rb +3 -0
- data/spec/filters/bugs/encoding.rb +0 -2
- data/spec/filters/bugs/exception.rb +1 -0
- data/spec/filters/bugs/float.rb +0 -2
- data/spec/filters/bugs/hash.rb +2 -7
- data/spec/filters/bugs/integer.rb +0 -2
- data/spec/filters/bugs/kernel.rb +16 -3
- data/spec/filters/bugs/language.rb +6 -14
- data/spec/filters/bugs/marshal.rb +1 -3
- data/spec/filters/bugs/module.rb +16 -1
- data/spec/filters/bugs/numeric.rb +4 -12
- data/spec/filters/bugs/objectspace.rb +67 -0
- data/spec/filters/bugs/pack_unpack.rb +0 -9
- data/spec/filters/bugs/pathname.rb +1 -0
- data/spec/filters/bugs/proc.rb +8 -0
- data/spec/filters/bugs/random.rb +3 -6
- data/spec/filters/bugs/range.rb +83 -113
- data/spec/filters/bugs/set.rb +2 -0
- data/spec/filters/bugs/string.rb +31 -70
- data/spec/filters/bugs/struct.rb +2 -0
- data/spec/filters/bugs/time.rb +8 -2
- data/spec/filters/unsupported/float.rb +3 -0
- data/spec/filters/unsupported/freeze.rb +1 -0
- data/spec/filters/unsupported/integer.rb +3 -0
- data/spec/filters/unsupported/refinements.rb +5 -0
- data/spec/filters/unsupported/string.rb +100 -95
- data/spec/filters/unsupported/time.rb +4 -0
- data/spec/lib/compiler_spec.rb +16 -0
- data/spec/lib/rewriters/forward_args_spec.rb +61 -0
- data/spec/lib/rewriters/logical_operator_assignment_spec.rb +1 -1
- data/spec/lib/rewriters/numblocks_spec.rb +44 -0
- data/spec/lib/rewriters/opal_engine_check_spec.rb +49 -4
- data/spec/opal/core/language/forward_args_spec.rb +53 -0
- data/spec/opal/core/language/infinite_range_spec.rb +13 -0
- data/spec/opal/core/language/memoization_spec.rb +16 -0
- data/spec/opal/core/module_spec.rb +38 -2
- data/spec/opal/core/number/to_i_spec.rb +28 -0
- data/spec/opal/core/runtime/bridged_classes_spec.rb +16 -0
- data/spec/opal/core/runtime/constants_spec.rb +20 -1
- data/spec/opal/core/string/subclassing_spec.rb +16 -0
- data/spec/opal/core/string/unpack_spec.rb +22 -0
- data/spec/opal/core/string_spec.rb +4 -4
- data/spec/ruby_specs +4 -1
- data/stdlib/json.rb +3 -1
- data/stdlib/securerandom.rb +55 -35
- data/tasks/testing.rake +6 -3
- data/test/nodejs/test_string.rb +25 -0
- data/vendored-minitest/minitest/assertions.rb +2 -0
- metadata +35 -12
- data/lib/opal/parser/with_c_lexer.rb +0 -15
@@ -0,0 +1,7 @@
|
|
1
|
+
Benchmark.ips do |x|
|
2
|
+
x.report("unshift") do
|
3
|
+
a = ['4768', '4964', '4266', '4872', '4231', '4017', '4565', '4793', '4298', '4135', '4639', '4780', '4237', '4548', '4655', '4153', '4654', '4922', '4563', '4042', '4329', '4699', '4352', '4127', '4544', '4906', '4814', '4948', '4977', '4830', '4405', '4642', '4666', '4402', '4679', '4465', '4401', '4155', '4767', '4510', '4747', '4993', '4508', '4697', '4758', '4133', '4348', '4200', '4442', '4970', '4452', '4041', '4103', '4567', '4937', '4047', '4933', '4121', '4860', '4659', '4221', '4312', '4583', '4473', '4973', '4262', '4630', '4123', '4139', '4289', '4147', '4222', '4050', '4019', '4454', '4253', '4552', '4947', '4725', '4457', '4929', '4021', '4502', '4307', '4576', '4124', '4586', '4610', '4027', '4572', '4926', '4753', '4185', '4382', '4394', '4923', '4186', '4254', '4012', '4417', '4556', '4349', '4550', '4330', '4938', '4985', '4778', '4716', '4924', '4045', '4358', '4189', '4591', '4213', '4851', '4825', '4260', '4198', '4342', '4824', '4333', '4244', '4752', '4994', '4488', '4532', '4082', '4595', '4098', '4436', '4540', '4267', '4407', '4998', '4751', '4535', '4861', '4819', '4419', '4031', '4029', '4453', '4698', '4965', '4450', '4668', '4036', '4300', '4519', '4281', '4981', '4818', '4939', '4378', '4140', '4841', '4249', '4290', '4388', '4878', '4884', '4235', '4515', '4638', '4410', '4054', '4383', '4238', '4870', '4295', '4804', '4308', '4614', '4105', '4053', '4446', '4757', '4971', '4637', '4831', '4193', '4912', '4000', '4187', '4606', '4566', '4169', '4641', '4749', '4729', '4928', '4601', '4949', '4210', '4313', '4647', '4495', '4460', '4621', '4605', '4694', '4317', '4226', '4263', '4016', '4997', '4940', '4715', '4907', '4620', '4934', '4996', '4955', '4688', '4304', '4220', '4882', '4772', '4536', '4815', '4693', '4469', '4276', '4409', '4071', '4224', '4020', '4629', '4865', '4813', '4366', '4622', '4129', '4533', '4634', '4564', '4087', '4386', '4161', '4265', '4711', '4009', '4376', '4781', '4837', '4112', '4915', '4592', '4658', '4025', '4987', '4291', '4477', '4503', '4437', '4111', '4707', '4879', '4611', '4549', '4078', '4044', '4853', '4835', '4463', '4577', '4008', '4233', '4741', '4384', '4225', '4024', '4726', '4743', '4160', '4180', '4722', '4609', '4114', '4834', '4742', '4662', '4984', '4299', '4060', '4498', '4755', '4320', '4874', '4528', '4216', '4852', '4951', '4958', '4283', '4239', '4476', '4644', '4143', '4104', '4455', '4126', '4950', '4663', '4013', '4931', '4850', '4242', '4130', '4623', '4871', '4014', '4854', '4293', '4512', '4166', '4740', '4735', '4150', '4651', '4172', '4836', '4530', '4664', '4429', '4511', '4558', '4676', '4085', '4074', '4580', '4794', '4379', '4310', '4817', '4966', '4848', '4202', '4336', '4608', '4351', '4396', '4652', '4033', '4188', '4431', '4916', '4259', '4607', '4816', '4810', '4627', '4527', '4560', '4728', '4589', '4274', '4809', '4790', '4398', '4414', '4516', '4581', '4919', '4665', '4331', '4978', '4543', '4877', '4974', '4284', '4004', '4177', '4466', '4116', '4217', '4901', '4372', '4137', '4806', '4264', '4497', '4294', '4787', '4212', '4215', '4115', '4782', '4739', '4821', '4125', '4505', '4230', '4399', '4395', '4079', '4867', '4381', '4706', '4695', '4404', '4691', '4075', '4353', '4301', '4876', '4731', '4523', '4246', '4529', '4412', '4784', '4449', '4229', '4616', '4158', '4002', '4318', '4377', '4205', '4911', '4777', '4792', '4271', '4763', '4141', '4287', '4890', '4279', '4829', '4646', '4840', '4089', '4880', '4067', '4918', '4059', '4109', '4164', '4863', '4883', '4909', '4361', '4174', '4960', '4302', '4003', '4236', '4846', '4034', '4324', '4513', '4765', '4596', '4900', '4007', '4603', '4474', '4439', '4805', '4015', '4496', '4953', '4363', '4551', '4459', '4063', '4983', '4881', '4365', '4604', '4587', '4798', '4005', '4163', '4421', '4471', '4826', '4144', '4635', '4600', '4913', '4640', '4247', '4766', '4779', '4280', '4391', '4891', '4636', '4546', '4683', '4181', '4081', '4862', '4458', '4037', '4321', '4786', '4717', '4628', '4154', '4326', '4032', '4873', '4151', '4905', '4270', '4156', '4733', '4980', '4866', '4325', '4055', '4467', '4480', '4286', '4191', '4762', '4322', '4574', '4022', '4056', '4770', '4451', '4448', '4845', '4341', '4433', '4245', '4684', '4671', '4093', '4920', '4272', '4745', '4799', '4761', '4250', '4578', '4347', '4499', '4526', '4369', '4162', '4537', '4434', '4893', '4120', '4962', '4667', '4525', '4091', '4462', '4182', '4738', '4935', '4173', '4490', '4571', '4424', '4894', '4051', '4214', '4823', '4096', '4206', '4598', '4943', '4701', '4649', '4807', '4107', '4435', '4456', '4083', '4612', '4721', '4472', '4146', '4925', '4340', '4789', '4277', '4375', '4211', '4427', '4547', '4690', '4613', '4727', '4006', '4203', '4430', '4223', '4039', '4932', '4296', '4108', '4278', '4832', '4422', '4917', '4470', '4183', '4887', '4076', '4485', '4597', '4443', '4257', '4991', '4944', '4196', '4672', '4397', '4097', '4119', '4077', '4773', '4602', '4538', '4479', '4968', '4159', '4539', '4956', '4710', '4812', '4902', '4569', '4954', '4385', '4128', '4936', '4416', '4148', '4632', '4759', '4117', '4896', '4392', '4864', '4316', '4132', '4319', '4969', '4175', '4484', '4903', '4910', '4350', '4332', '4952', '4176', '4594', '4709', '4509', '4178', '4167', '4545', '4857', '4617', '4501', '4859', '4207', '4275', '4687', '4049', '4579', '4046', '4921', '4113', '4898', '4681', '4052', '4415', '4064', '4184', '4895', '4744', '4685', '4084', '4305', '4899', '4559', '4208', '4057', '4507', '4258', '4355', '4086', '4373', '4323', '4541', '4297', '4483', '4889', '4531', '4327', '4441', '4914', '4303', '4677', '4445', '4802', '4343', '4585', '4338', '4524', '4590', '4624', '4288', '4704', '4134', '4043', '4720', '4058', '4328', '4095', '4026', '4423', '4657', '4118', '4633', '4487', '4822', '4904', '4255', '4001', '4387', '4500', '4190', '4686', '4995', '4661', '4783', '4992', '4165', '4065', '4927', '4306', '4856', '4292', '4420', '4963', '4468', '4240', '4724', '4432', '4447', '4518', '4028', '4670', '4339', '4771', '4018', '4489', '4110', '4708', '4945', '4136', '4492', '4930', '4090', '4734', '4886', '4542', '4227', '4486', '4491', '4713', '4986', '4068', '4048', '4975', '4570', '4842', '4475', '4131', '4555', '4428', '4776', '4101', '4273', '4811', '4345', '5000', '4653', '4256', '4209', '4769', '4946', '4561', '4080', '4461', '4820', '4311', '4959', '4750', '4795', '4748', '4368', '4506', '4335', '4346', '4568', '4675', '4692', '4774', '4413', '4370', '4723', '4521', '4885', '4678', '4897', '4066', '4674', '4106', '4626', '4389', '4204', '4839', '4023', '4712', '4145', '4035', '4357', '4756', '4648', '4972', '4157', '4406', '4615', '4061', '4219', '4791', '4660', '4073', '4356', '4072', '4599', '4359', '4094', '4673', '4696', '4796', '4282', '4714', '4522', '4736', '4775', '4760', '4400', '4847', '4228', '4803', '4908', '4732', '4645', '4122', '4218', '4478', '4941', '4892', '4364', '4403', '4152', '4444', '4360', '4354', '4241', '4494', '4367', '4808', '4261', '4088', '4573', '4554', '4248', '4371', '4393', '4268', '4201', '4038', '4788', '4593', '4040', '4801', '4582', '4309', '4976', '4374', '4869', '4380', '4514', '4243', '4362', '4849', '4680', '4888', '4764', '4618', '4838', '4828', '4643', '4010', '4827', '4957', '4099', '4875', '4843', '4737', '4102', '4979', '4011', '4504', '4440', '4746', '4557', '4426', '4553', '4656', '4868', '4689', '4988', '4703', '4967', '4069', '4619', '4334', '4669', '4785', '4464', '4562', '4961', '4625', '4754', '4797', '4481', '4705', '4199', '4337', '4062', '4138', '4702', '4534', '4168', '4418', '4092', '4682', '4520', '4030', '4171', '4650', '4858', '4411', '4999', '4252', '4197', '4170', '4942', '4631', '4990', '4179', '4285', '4700', '4482', '4575', '4800', '4070', '4251', '4344', '4982', '4719', '4390', '4149', '4100', '4194', '4269', '4855', '4314', '4718', '4232', '4730', '4438', '4588', '4195', '4192', '4493', '4517', '4833', '4234', '4989', '4315', '4844', '4142', '4408', '4584', '4425']
|
4
|
+
a.unshift('aaa', 'bbb', 'ccc')
|
5
|
+
end
|
6
|
+
x.compare!
|
7
|
+
end
|
@@ -4,15 +4,20 @@ Benchmark.ips do |x|
|
|
4
4
|
o[Symbol.for('foo')] = 123
|
5
5
|
o.foo = 123
|
6
6
|
var foo = Symbol('foo')
|
7
|
+
var gfoo = Symbol.for('foo')
|
7
8
|
o[foo] = 123
|
8
9
|
var a = 0, b = 0, c = 0
|
9
10
|
}
|
10
11
|
|
11
|
-
x.report('global symbol') do
|
12
|
+
x.report('live global symbol') do
|
12
13
|
`a += o[Symbol.for('foo')]`
|
13
14
|
end
|
14
15
|
|
15
|
-
x.report('symbol') do
|
16
|
+
x.report('stored global symbol') do
|
17
|
+
`a += o[gfoo]`
|
18
|
+
end
|
19
|
+
|
20
|
+
x.report('stored symbol') do
|
16
21
|
`a += o[foo]`
|
17
22
|
end
|
18
23
|
|
@@ -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
|
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
|
data/bin/opal-mspec
CHANGED
data/docs/compiler.md
CHANGED
@@ -21,7 +21,7 @@ The [opal parser][parser] relies on the `parser` gem, see debug/development docu
|
|
21
21
|
The [opal compiler][compiler] takes these sexps from the parser
|
22
22
|
and generates ruby code from them. Each type of sexp has [its own node type][base-node]
|
23
23
|
used to generate javascript. Each node creates an array of one or more
|
24
|
-
[fragments][fragments] which are the
|
24
|
+
[fragments][fragments] which are the concatenated together to
|
25
25
|
form the final javascript. Fragments are used as they contain the generated
|
26
26
|
code as well as a reference back to the original sexp which is useful for
|
27
27
|
generating source maps afterwards.
|
data/examples/rack/Gemfile
CHANGED
data/examples/rack/Gemfile.lock
CHANGED
@@ -9,9 +9,6 @@ GEM
|
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
11
|
ast (2.4.0)
|
12
|
-
c_lexer (2.6.4.1.1)
|
13
|
-
ast (~> 2.4.0)
|
14
|
-
parser (= 2.6.4.1)
|
15
12
|
parser (2.6.4.1)
|
16
13
|
ast (~> 2.4.0)
|
17
14
|
rack (2.0.7)
|
@@ -20,7 +17,6 @@ PLATFORMS
|
|
20
17
|
ruby
|
21
18
|
|
22
19
|
DEPENDENCIES
|
23
|
-
c_lexer
|
24
20
|
opal!
|
25
21
|
rack
|
26
22
|
|
data/lib/opal/cli.rb
CHANGED
data/lib/opal/cli_options.rb
CHANGED
@@ -168,6 +168,10 @@ module Opal
|
|
168
168
|
options[:enable_source_location] = true
|
169
169
|
end
|
170
170
|
|
171
|
+
on('--use-strict', 'Enables JavaScript\'s strict mode (i.e., adds \'use strict\'; statement)') do
|
172
|
+
options[:use_strict] = true
|
173
|
+
end
|
174
|
+
|
171
175
|
on('--parse-comments', 'Compiles comments for each method definition.') do
|
172
176
|
options[:parse_comments] = true
|
173
177
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'shellwords'
|
3
4
|
require 'opal/paths'
|
4
5
|
require 'opal/cli_runners/system_runner'
|
5
6
|
|
@@ -14,10 +15,13 @@ module Opal
|
|
14
15
|
argv = data[:argv].dup.to_a
|
15
16
|
argv.unshift('--') if argv.any?
|
16
17
|
|
18
|
+
opts = Shellwords.shellwords(ENV['NODE_OPTS'] || '')
|
19
|
+
|
17
20
|
SystemRunner.call(data) do |tempfile|
|
18
21
|
[
|
19
22
|
'node',
|
20
|
-
'--require', "#{__dir__}/source-map-support",
|
23
|
+
'--require', "#{__dir__}/source-map-support-node",
|
24
|
+
*opts,
|
21
25
|
tempfile.path,
|
22
26
|
*argv
|
23
27
|
]
|
@@ -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
|
-
//
|
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)
|
@@ -6143,7 +6147,9 @@ function CallSiteToString() {
|
|
6143
6147
|
}
|
6144
6148
|
var methodName = this.getMethodName();
|
6145
6149
|
if (functionName) {
|
6146
|
-
if (functionName.startsWith("
|
6150
|
+
if (functionName.startsWith("$$")) {
|
6151
|
+
functionName = functionName.slice(2);
|
6152
|
+
} else if (functionName.startsWith("$")) {
|
6147
6153
|
functionName = functionName.slice(1);
|
6148
6154
|
}
|
6149
6155
|
if (typeName && functionName.indexOf(typeName) != 0) {
|
@@ -0,0 +1,3706 @@
|
|
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(2);
|
3408
|
+
} else if (functionName.startsWith("$")) {
|
3409
|
+
functionName = functionName.slice(1);
|
3410
|
+
}
|
3411
|
+
if (typeName && functionName.indexOf(typeName) != 0) {
|
3412
|
+
line += typeName + ".";
|
3413
|
+
}
|
3414
|
+
line += functionName;
|
3415
|
+
if (methodName && functionName.indexOf("." + methodName) != functionName.length - methodName.length - 1) {
|
3416
|
+
line += " [as " + methodName + "]";
|
3417
|
+
}
|
3418
|
+
} else {
|
3419
|
+
line += typeName + "." + (methodName || "<anonymous>");
|
3420
|
+
}
|
3421
|
+
} else if (isConstructor) {
|
3422
|
+
line += "new " + (functionName || "<anonymous>");
|
3423
|
+
} else if (functionName) {
|
3424
|
+
line += functionName;
|
3425
|
+
} else {
|
3426
|
+
line += fileLocation;
|
3427
|
+
addSuffix = false;
|
3428
|
+
}
|
3429
|
+
if (addSuffix) {
|
3430
|
+
line += " (" + fileLocation + ")";
|
3431
|
+
}
|
3432
|
+
line = fileLocation + ":in `" + (functionName || methodName) + "'"
|
3433
|
+
return line;
|
3434
|
+
}
|
3435
|
+
|
3436
|
+
function cloneCallSite(frame) {
|
3437
|
+
var object = {};
|
3438
|
+
Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach(function(name) {
|
3439
|
+
object[name] = /^(?:is|get)/.test(name) ? function() { return frame[name].call(frame); } : frame[name];
|
3440
|
+
});
|
3441
|
+
object.toString = CallSiteToString;
|
3442
|
+
return object;
|
3443
|
+
}
|
3444
|
+
|
3445
|
+
function wrapCallSite(frame) {
|
3446
|
+
if(frame.isNative()) {
|
3447
|
+
return frame;
|
3448
|
+
}
|
3449
|
+
|
3450
|
+
// Most call sites will return the source file from getFileName(), but code
|
3451
|
+
// passed to eval() ending in "//# sourceURL=..." will return the source file
|
3452
|
+
// from getScriptNameOrSourceURL() instead
|
3453
|
+
var source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
3454
|
+
if (source) {
|
3455
|
+
var line = frame.getLineNumber();
|
3456
|
+
var column = frame.getColumnNumber() - 1;
|
3457
|
+
|
3458
|
+
// Fix position in Node where some (internal) code is prepended.
|
3459
|
+
// See https://github.com/evanw/node-source-map-support/issues/36
|
3460
|
+
var headerLength = 62;
|
3461
|
+
if (line === 1 && column > headerLength && !isInBrowser() && !frame.isEval()) {
|
3462
|
+
column -= headerLength;
|
3463
|
+
}
|
3464
|
+
|
3465
|
+
var position = mapSourcePosition({
|
3466
|
+
source: source,
|
3467
|
+
line: line,
|
3468
|
+
column: column
|
3469
|
+
});
|
3470
|
+
frame = cloneCallSite(frame);
|
3471
|
+
var originalFunctionName = frame.getFunctionName;
|
3472
|
+
frame.getFunctionName = function() { return position.name || originalFunctionName(); };
|
3473
|
+
frame.getFileName = function() { return position.source; };
|
3474
|
+
frame.getLineNumber = function() { return position.line; };
|
3475
|
+
frame.getColumnNumber = function() { return position.column + 1; };
|
3476
|
+
frame.getScriptNameOrSourceURL = function() { return position.source; };
|
3477
|
+
return frame;
|
3478
|
+
}
|
3479
|
+
|
3480
|
+
// Code called using eval() needs special handling
|
3481
|
+
var origin = frame.isEval() && frame.getEvalOrigin();
|
3482
|
+
if (origin) {
|
3483
|
+
origin = mapEvalOrigin(origin);
|
3484
|
+
frame = cloneCallSite(frame);
|
3485
|
+
frame.getEvalOrigin = function() { return origin; };
|
3486
|
+
return frame;
|
3487
|
+
}
|
3488
|
+
|
3489
|
+
// If we get here then we were unable to change the source position
|
3490
|
+
return frame;
|
3491
|
+
}
|
3492
|
+
|
3493
|
+
// This function is part of the V8 stack trace API, for more info see:
|
3494
|
+
// https://v8.dev/docs/stack-trace-api
|
3495
|
+
function prepareStackTrace(error, stack) {
|
3496
|
+
if (emptyCacheBetweenOperations) {
|
3497
|
+
fileContentsCache = {};
|
3498
|
+
sourceMapCache = {};
|
3499
|
+
}
|
3500
|
+
|
3501
|
+
var name = error.name || 'Error';
|
3502
|
+
var message = error.message || '';
|
3503
|
+
var errorString = name + ": " + message;
|
3504
|
+
|
3505
|
+
return errorString + stack.map(function(frame) {
|
3506
|
+
return '\n from ' + wrapCallSite(frame);
|
3507
|
+
}).join('');
|
3508
|
+
}
|
3509
|
+
|
3510
|
+
// Generate position and snippet of original source with pointer
|
3511
|
+
function getErrorSource(error) {
|
3512
|
+
var match = /\n from [^(]+ \((.*):(\d+):(\d+)\)/.exec(error.stack);
|
3513
|
+
if (match) {
|
3514
|
+
var source = match[1];
|
3515
|
+
var line = +match[2];
|
3516
|
+
var column = +match[3];
|
3517
|
+
|
3518
|
+
// Support the inline sourceContents inside the source map
|
3519
|
+
var contents = fileContentsCache[source];
|
3520
|
+
|
3521
|
+
// Support files on disk
|
3522
|
+
if (!contents && fs && fs.existsSync(source)) {
|
3523
|
+
try {
|
3524
|
+
contents = fs.readFileSync(source, 'utf8');
|
3525
|
+
} catch (er) {
|
3526
|
+
contents = '';
|
3527
|
+
}
|
3528
|
+
}
|
3529
|
+
|
3530
|
+
// Format the line from the original source code like node does
|
3531
|
+
if (contents) {
|
3532
|
+
var code = contents.split(/(?:\r\n|\r|\n)/)[line - 1];
|
3533
|
+
if (code) {
|
3534
|
+
return source + ':' + line + '\n' + code + '\n' +
|
3535
|
+
new Array(column).join(' ') + '^';
|
3536
|
+
}
|
3537
|
+
}
|
3538
|
+
}
|
3539
|
+
return null;
|
3540
|
+
}
|
3541
|
+
|
3542
|
+
function printErrorAndExit (error) {
|
3543
|
+
var source = getErrorSource(error);
|
3544
|
+
|
3545
|
+
// Ensure error is printed synchronously and not truncated
|
3546
|
+
if (process.stderr._handle && process.stderr._handle.setBlocking) {
|
3547
|
+
process.stderr._handle.setBlocking(true);
|
3548
|
+
}
|
3549
|
+
|
3550
|
+
if (source) {
|
3551
|
+
console.error();
|
3552
|
+
console.error(source);
|
3553
|
+
}
|
3554
|
+
|
3555
|
+
console.error(error.stack);
|
3556
|
+
process.exit(1);
|
3557
|
+
}
|
3558
|
+
|
3559
|
+
function shimEmitUncaughtException () {
|
3560
|
+
var origEmit = process.emit;
|
3561
|
+
|
3562
|
+
process.emit = function (type) {
|
3563
|
+
if (type === 'uncaughtException') {
|
3564
|
+
var hasStack = (arguments[1] && arguments[1].stack);
|
3565
|
+
var hasListeners = (this.listeners(type).length > 0);
|
3566
|
+
|
3567
|
+
if (hasStack && !hasListeners) {
|
3568
|
+
return printErrorAndExit(arguments[1]);
|
3569
|
+
}
|
3570
|
+
}
|
3571
|
+
|
3572
|
+
return origEmit.apply(this, arguments);
|
3573
|
+
};
|
3574
|
+
}
|
3575
|
+
|
3576
|
+
var originalRetrieveFileHandlers = retrieveFileHandlers.slice(0);
|
3577
|
+
var originalRetrieveMapHandlers = retrieveMapHandlers.slice(0);
|
3578
|
+
|
3579
|
+
exports.wrapCallSite = wrapCallSite;
|
3580
|
+
exports.getErrorSource = getErrorSource;
|
3581
|
+
exports.mapSourcePosition = mapSourcePosition;
|
3582
|
+
exports.retrieveSourceMap = retrieveSourceMap;
|
3583
|
+
|
3584
|
+
exports.install = function(options) {
|
3585
|
+
options = options || {};
|
3586
|
+
|
3587
|
+
if (options.environment) {
|
3588
|
+
environment = options.environment;
|
3589
|
+
if (["node", "browser", "auto"].indexOf(environment) === -1) {
|
3590
|
+
throw new Error("environment " + environment + " was unknown. Available options are {auto, browser, node}")
|
3591
|
+
}
|
3592
|
+
}
|
3593
|
+
|
3594
|
+
// Allow sources to be found by methods other than reading the files
|
3595
|
+
// directly from disk.
|
3596
|
+
if (options.retrieveFile) {
|
3597
|
+
if (options.overrideRetrieveFile) {
|
3598
|
+
retrieveFileHandlers.length = 0;
|
3599
|
+
}
|
3600
|
+
|
3601
|
+
retrieveFileHandlers.unshift(options.retrieveFile);
|
3602
|
+
}
|
3603
|
+
|
3604
|
+
// Allow source maps to be found by methods other than reading the files
|
3605
|
+
// directly from disk.
|
3606
|
+
if (options.retrieveSourceMap) {
|
3607
|
+
if (options.overrideRetrieveSourceMap) {
|
3608
|
+
retrieveMapHandlers.length = 0;
|
3609
|
+
}
|
3610
|
+
|
3611
|
+
retrieveMapHandlers.unshift(options.retrieveSourceMap);
|
3612
|
+
}
|
3613
|
+
|
3614
|
+
// Support runtime transpilers that include inline source maps
|
3615
|
+
if (options.hookRequire && !isInBrowser()) {
|
3616
|
+
var Module;
|
3617
|
+
try {
|
3618
|
+
Module = require('module');
|
3619
|
+
} catch (err) {
|
3620
|
+
// NOP: Loading in catch block to convert webpack error to warning.
|
3621
|
+
}
|
3622
|
+
var $compile = Module.prototype._compile;
|
3623
|
+
|
3624
|
+
if (!$compile.__sourceMapSupport) {
|
3625
|
+
Module.prototype._compile = function(content, filename) {
|
3626
|
+
fileContentsCache[filename] = content;
|
3627
|
+
sourceMapCache[filename] = undefined;
|
3628
|
+
return $compile.call(this, content, filename);
|
3629
|
+
};
|
3630
|
+
|
3631
|
+
Module.prototype._compile.__sourceMapSupport = true;
|
3632
|
+
}
|
3633
|
+
}
|
3634
|
+
|
3635
|
+
// Configure options
|
3636
|
+
if (!emptyCacheBetweenOperations) {
|
3637
|
+
emptyCacheBetweenOperations = 'emptyCacheBetweenOperations' in options ?
|
3638
|
+
options.emptyCacheBetweenOperations : false;
|
3639
|
+
}
|
3640
|
+
|
3641
|
+
// Install the error reformatter
|
3642
|
+
if (!errorFormatterInstalled) {
|
3643
|
+
errorFormatterInstalled = true;
|
3644
|
+
Error.prepareStackTrace = prepareStackTrace;
|
3645
|
+
}
|
3646
|
+
|
3647
|
+
if (!uncaughtShimInstalled) {
|
3648
|
+
var installHandler = 'handleUncaughtExceptions' in options ?
|
3649
|
+
options.handleUncaughtExceptions : true;
|
3650
|
+
|
3651
|
+
// Provide the option to not install the uncaught exception handler. This is
|
3652
|
+
// to support other uncaught exception handlers (in test frameworks, for
|
3653
|
+
// example). If this handler is not installed and there are no other uncaught
|
3654
|
+
// exception handlers, uncaught exceptions will be caught by node's built-in
|
3655
|
+
// exception handler and the process will still be terminated. However, the
|
3656
|
+
// generated JavaScript code will be shown above the stack trace instead of
|
3657
|
+
// the original source code.
|
3658
|
+
if (installHandler && hasGlobalProcessEventEmitter()) {
|
3659
|
+
uncaughtShimInstalled = true;
|
3660
|
+
shimEmitUncaughtException();
|
3661
|
+
}
|
3662
|
+
}
|
3663
|
+
};
|
3664
|
+
|
3665
|
+
exports.resetRetrieveHandlers = function() {
|
3666
|
+
retrieveFileHandlers.length = 0;
|
3667
|
+
retrieveMapHandlers.length = 0;
|
3668
|
+
|
3669
|
+
retrieveFileHandlers = originalRetrieveFileHandlers.slice(0);
|
3670
|
+
retrieveMapHandlers = originalRetrieveMapHandlers.slice(0);
|
3671
|
+
|
3672
|
+
retrieveSourceMap = handlerExec(retrieveMapHandlers);
|
3673
|
+
retrieveFile = handlerExec(retrieveFileHandlers);
|
3674
|
+
}
|
3675
|
+
|
3676
|
+
// Autoinstall.
|
3677
|
+
exports.install();
|
3678
|
+
|
3679
|
+
// Regenerate the browser version with:
|
3680
|
+
// browserify lib/opal/cli_runners/source-map-support.js -s sourceMapSupport | uglifyjs -c > lib/opal/cli_runners/source-map-support-browser.js
|
3681
|
+
|
3682
|
+
// = Stacktrace Examples:
|
3683
|
+
//
|
3684
|
+
// == Traditional Ruby stacktrace:
|
3685
|
+
//
|
3686
|
+
// /Users/elia/Code/opal/lib/opal/cli_runners/system_runner.rb:43:in `call': unhandled exception
|
3687
|
+
// from /Users/elia/Code/opal/lib/opal/cli_runners/nodejs.rb:14:in `call'
|
3688
|
+
// from /Users/elia/Code/opal/lib/opal/cli_runners.rb:50:in `block in register_runner'
|
3689
|
+
// from /Users/elia/Code/opal/lib/opal/cli.rb:62:in `run'
|
3690
|
+
// from /Users/elia/Code/opal/exe/opal:24:in `<top (required)>'
|
3691
|
+
// from bin/opal:4:in `load'
|
3692
|
+
// from bin/opal:4:in `<main>'
|
3693
|
+
//
|
3694
|
+
// == Traceback style:
|
3695
|
+
//
|
3696
|
+
// Traceback (most recent call last):
|
3697
|
+
// 6: from bin/opal:4:in `<main>'
|
3698
|
+
// 5: from bin/opal:4:in `load'
|
3699
|
+
// 4: from /Users/elia/Code/opal/exe/opal:24:in `<top (required)>'
|
3700
|
+
// 3: from /Users/elia/Code/opal/lib/opal/cli.rb:62:in `run'
|
3701
|
+
// 2: from /Users/elia/Code/opal/lib/opal/cli_runners.rb:50:in `block in register_runner'
|
3702
|
+
// 1: from /Users/elia/Code/opal/lib/opal/cli_runners/nodejs.rb:14:in `call'
|
3703
|
+
// /Users/elia/Code/opal/lib/opal/cli_runners/system_runner.rb:43:in `call': unhandled exception
|
3704
|
+
|
3705
|
+
},{"buffer-from":1,"fs":undefined,"module":undefined,"path":undefined,"source-map":12}]},{},[])("/lib/opal/cli_runners/source-map-support.js")
|
3706
|
+
});
|