less 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +4 -0
- data/Gemfile +1 -1
- data/less.gemspec +1 -1
- data/lib/less/defaults.rb +3 -3
- data/lib/less/java_script/v8_context.rb +1 -1
- data/lib/less/js/.gitattributes +3 -2
- data/lib/less/js/.gitignore +18 -2
- data/lib/less/js/.jshintrc +11 -0
- data/lib/less/js/CHANGELOG.md +87 -2
- data/lib/less/js/CONTRIBUTING.md +4 -3
- data/lib/less/js/Gruntfile.js +290 -0
- data/lib/less/js/README.md +342 -12
- data/lib/less/js/benchmark/benchmark.less +194 -194
- data/lib/less/js/benchmark/less-benchmark.js +9 -10
- data/lib/less/js/bin/lessc +154 -12
- data/lib/less/js/bower.json +18 -0
- data/lib/less/js/build.gradle +347 -0
- data/lib/less/js/build/README.md +350 -0
- data/lib/less/js/build/browser-header.js +4 -0
- data/lib/less/js/build/build.yml +160 -0
- data/lib/less/js/build/require-rhino.js +7 -2
- data/lib/less/js/build/rhino-header.js +4 -0
- data/lib/less/js/build/rhino-modules.js +131 -0
- data/lib/less/js/build/tasks/.gitkeep +1 -0
- data/lib/less/js/dist/less-1.5.0.js +6914 -0
- data/lib/less/js/dist/less-1.5.0.min.js +13 -0
- data/lib/less/js/dist/less-1.5.1.js +6941 -0
- data/lib/less/js/dist/less-1.5.1.min.js +13 -0
- data/lib/less/js/dist/less-1.6.0.js +7485 -0
- data/lib/less/js/dist/less-1.6.0.min.js +16 -0
- data/lib/less/js/dist/less-1.6.1.js +7513 -0
- data/lib/less/js/dist/less-1.6.1.min.js +16 -0
- data/lib/less/js/dist/less-1.6.2.js +7624 -0
- data/lib/less/js/dist/less-1.6.2.min.js +16 -0
- data/lib/less/js/dist/less-rhino-1.5.1.js +6831 -0
- data/lib/less/js/dist/less-rhino-1.6.2.js +9017 -0
- data/lib/less/js/dist/lessc-rhino-1.6.2.js +449 -0
- data/lib/less/js/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/lib/less/js/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/lib/less/js/gradlew +164 -0
- data/lib/less/js/gradlew.bat +90 -0
- data/lib/less/js/lib/less/browser.js +482 -367
- data/lib/less/js/lib/less/colors.js +0 -1
- data/lib/less/js/lib/less/encoder.js +4 -0
- data/lib/less/js/lib/less/env.js +50 -19
- data/lib/less/js/lib/less/extend-visitor.js +66 -41
- data/lib/less/js/lib/less/functions.js +309 -104
- data/lib/less/js/lib/less/import-visitor.js +21 -10
- data/lib/less/js/lib/less/index.js +90 -68
- data/lib/less/js/lib/less/join-selector-visitor.js +11 -4
- data/lib/less/js/lib/less/lessc_helper.js +56 -45
- data/lib/less/js/lib/less/parser.js +830 -460
- data/lib/less/js/lib/less/rhino.js +380 -58
- data/lib/less/js/lib/less/source-map-output.js +141 -0
- data/lib/less/js/lib/less/to-css-visitor.js +215 -0
- data/lib/less/js/lib/less/tree.js +57 -5
- data/lib/less/js/lib/less/tree/alpha.js +13 -5
- data/lib/less/js/lib/less/tree/anonymous.js +11 -5
- data/lib/less/js/lib/less/tree/assignment.js +11 -5
- data/lib/less/js/lib/less/tree/call.js +19 -8
- data/lib/less/js/lib/less/tree/color.js +59 -36
- data/lib/less/js/lib/less/tree/comment.js +17 -4
- data/lib/less/js/lib/less/tree/condition.js +3 -3
- data/lib/less/js/lib/less/tree/dimension.js +161 -153
- data/lib/less/js/lib/less/tree/directive.js +39 -18
- data/lib/less/js/lib/less/tree/element.js +41 -18
- data/lib/less/js/lib/less/tree/expression.js +11 -5
- data/lib/less/js/lib/less/tree/extend.js +11 -1
- data/lib/less/js/lib/less/tree/import.js +34 -20
- data/lib/less/js/lib/less/tree/javascript.js +16 -10
- data/lib/less/js/lib/less/tree/keyword.js +5 -2
- data/lib/less/js/lib/less/tree/media.js +39 -22
- data/lib/less/js/lib/less/tree/mixin.js +135 -56
- data/lib/less/js/lib/less/tree/negative.js +4 -2
- data/lib/less/js/lib/less/tree/operation.js +17 -12
- data/lib/less/js/lib/less/tree/paren.js +5 -2
- data/lib/less/js/lib/less/tree/quoted.js +9 -6
- data/lib/less/js/lib/less/tree/rule.js +39 -21
- data/lib/less/js/lib/less/tree/ruleset.js +229 -145
- data/lib/less/js/lib/less/tree/selector.js +101 -34
- data/lib/less/js/lib/less/tree/unicode-descriptor.js +4 -3
- data/lib/less/js/lib/less/tree/url.js +33 -11
- data/lib/less/js/lib/less/tree/value.js +13 -6
- data/lib/less/js/lib/less/tree/variable.js +13 -8
- data/lib/less/js/lib/less/visitor.js +117 -25
- data/lib/less/js/lib/source-map/source-map-0.1.31.js +1933 -0
- data/lib/less/js/lib/source-map/source-map-footer.js +4 -0
- data/lib/less/js/lib/source-map/source-map-header.js +3 -0
- data/lib/less/js/package.json +30 -15
- data/lib/less/js/test/browser/common.js +131 -56
- data/lib/less/js/test/browser/css/global-vars/simple.css +3 -0
- data/lib/less/js/test/browser/css/modify-vars/simple.css +8 -0
- data/lib/less/js/test/browser/css/relative-urls/urls.css +8 -9
- data/lib/less/js/test/browser/css/rootpath-relative/urls.css +0 -1
- data/lib/less/js/test/browser/css/rootpath/urls.css +0 -1
- data/lib/less/js/test/browser/css/urls.css +18 -14
- data/lib/less/js/test/browser/es5.js +27 -0
- data/lib/less/js/test/{less/errors/color-operation-error.less → browser/less/console-errors/test-error.less} +0 -0
- data/lib/less/js/test/browser/less/console-errors/test-error.txt +2 -0
- data/lib/less/js/test/browser/less/global-vars/simple.less +3 -0
- data/lib/less/js/test/browser/less/modify-vars/imports/simple2.less +4 -0
- data/lib/less/js/test/browser/less/modify-vars/simple.less +8 -0
- data/lib/less/js/test/browser/less/relative-urls/urls.less +1 -1
- data/lib/less/js/test/browser/less/rootpath-relative/urls.less +1 -1
- data/lib/less/js/test/browser/less/rootpath/urls.less +1 -1
- data/lib/less/js/test/browser/less/urls.less +9 -1
- data/lib/less/js/test/browser/phantom-runner.js +112 -103
- data/lib/less/js/test/browser/runner-browser-options.js +42 -0
- data/lib/less/js/test/browser/{runner-browser.js → runner-browser-spec.js} +7 -2
- data/lib/less/js/test/browser/runner-console-errors.js +5 -0
- data/lib/less/js/test/browser/runner-errors-options.js +5 -0
- data/lib/less/js/test/browser/runner-errors-spec.js +4 -0
- data/lib/less/js/test/browser/runner-global-vars-options.js +4 -0
- data/lib/less/js/test/browser/runner-global-vars-spec.js +3 -0
- data/lib/less/js/test/browser/runner-legacy-options.js +4 -0
- data/lib/less/js/test/browser/{runner-legacy.js → runner-legacy-spec.js} +1 -4
- data/lib/less/js/test/browser/runner-main-options.js +15 -0
- data/lib/less/js/test/browser/runner-main-spec.js +3 -0
- data/lib/less/js/test/browser/runner-modify-vars-options.js +2 -0
- data/lib/less/js/test/browser/runner-modify-vars-spec.js +43 -0
- data/lib/less/js/test/browser/runner-no-js-errors-options.js +4 -0
- data/lib/less/js/test/browser/runner-no-js-errors-spec.js +4 -0
- data/lib/less/js/test/browser/runner-production-options.js +3 -0
- data/lib/less/js/test/browser/{runner-production.js → runner-production-spec.js} +1 -3
- data/lib/less/js/test/browser/runner-relative-urls-options.js +3 -0
- data/lib/less/js/test/browser/{runner-relative-urls.js → runner-relative-urls-spec.js} +1 -2
- data/lib/less/js/test/browser/runner-rootpath-options.js +3 -0
- data/lib/less/js/test/browser/runner-rootpath-relative-options.js +4 -0
- data/lib/less/js/test/browser/{runner-rootpath-relative.js → runner-rootpath-relative-spec.js} +1 -3
- data/lib/less/js/test/browser/{runner-rootpath.js → runner-rootpath-spec.js} +1 -2
- data/lib/less/js/test/browser/test-runner-template.tmpl +47 -0
- data/lib/less/js/test/css/colors.css +7 -0
- data/lib/less/js/test/css/comments.css +9 -4
- data/lib/less/js/test/css/compression/compression.css +3 -2
- data/lib/less/js/test/css/css-3.css +17 -5
- data/lib/less/js/test/css/css-guards.css +37 -0
- data/lib/less/js/test/css/debug/linenumbers-all.css +6 -0
- data/lib/less/js/test/css/debug/linenumbers-comments.css +5 -0
- data/lib/less/js/test/css/debug/linenumbers-mediaquery.css +5 -0
- data/lib/less/js/test/css/empty.css +0 -0
- data/lib/less/js/test/css/extend-chaining.css +9 -0
- data/lib/less/js/test/css/extend-selector.css +10 -2
- data/lib/less/js/test/css/extract-and-length.css +133 -0
- data/lib/less/js/test/css/functions.css +23 -10
- data/lib/less/js/test/css/globalVars/extended.css +12 -0
- data/lib/less/js/test/css/globalVars/simple.css +6 -0
- data/lib/less/js/test/css/import-inline.css +5 -0
- data/lib/less/js/test/css/import-once.css +12 -0
- data/lib/less/js/test/css/import-reference.css +49 -0
- data/lib/less/js/test/css/import.css +0 -2
- data/lib/less/js/test/css/media.css +21 -5
- data/lib/less/js/test/css/merge.css +26 -0
- data/lib/less/js/test/css/mixins-guards-default-func.css +129 -0
- data/lib/less/js/test/css/mixins-guards.css +6 -0
- data/lib/less/js/test/css/mixins-important.css +7 -0
- data/lib/less/js/test/css/mixins-interpolated.css +39 -0
- data/lib/less/js/test/css/mixins.css +20 -0
- data/lib/less/js/test/css/modifyVars/extended.css +9 -0
- data/lib/less/js/test/css/no-output.css +0 -0
- data/lib/less/js/test/css/parens.css +3 -0
- data/lib/less/js/test/css/property-name-interp.css +20 -0
- data/lib/less/js/test/css/selectors.css +12 -0
- data/lib/less/js/test/css/static-urls/urls.css +7 -4
- data/lib/less/js/test/css/strings.css +3 -0
- data/lib/less/js/test/css/url-args/urls.css +56 -0
- data/lib/less/js/test/css/urls.css +21 -9
- data/lib/less/js/test/index.js +45 -0
- data/lib/less/js/test/less-test.js +234 -191
- data/lib/less/js/test/less/colors.less +6 -0
- data/lib/less/js/test/less/comments.less +7 -1
- data/lib/less/js/test/less/compression/compression.less +21 -1
- data/lib/less/js/test/less/css-3.less +12 -0
- data/lib/less/js/test/less/css-guards.less +99 -0
- data/lib/less/js/test/less/debug/linenumbers.less +11 -1
- data/lib/less/js/test/less/empty.less +0 -0
- data/lib/less/js/test/less/errors/add-mixed-units.txt +4 -2
- data/lib/less/js/test/less/errors/add-mixed-units2.txt +4 -2
- data/lib/less/js/test/less/errors/color-func-invalid-color.less +3 -0
- data/lib/less/js/test/less/errors/color-func-invalid-color.txt +4 -0
- data/lib/less/js/test/less/errors/css-guard-default-func.less +4 -0
- data/lib/less/js/test/less/errors/css-guard-default-func.txt +4 -0
- data/lib/less/js/test/less/errors/import-subfolder2.txt +4 -2
- data/lib/less/js/test/less/errors/javascript-undefined-var.less +3 -0
- data/lib/less/js/test/less/errors/javascript-undefined-var.txt +4 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-1.less +9 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-1.txt +4 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-2.less +9 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-2.txt +4 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-3.less +9 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-3.txt +4 -0
- data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors.less +4 -0
- data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors.txt +4 -0
- data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors2.less +4 -0
- data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors2.txt +4 -0
- data/lib/less/js/test/less/errors/parse-error-curly-bracket.less +4 -1
- data/lib/less/js/test/less/errors/parse-error-curly-bracket.txt +4 -2
- data/lib/less/js/test/less/errors/parse-error-extra-parens.less +5 -0
- data/lib/less/js/test/less/errors/parse-error-extra-parens.txt +3 -0
- data/lib/less/js/test/less/errors/parse-error-missing-bracket.txt +2 -2
- data/lib/less/js/test/less/errors/parse-error-missing-parens.less +5 -0
- data/lib/less/js/test/less/errors/parse-error-missing-parens.txt +3 -0
- data/lib/less/js/test/less/errors/property-asterisk-only-name.less +3 -0
- data/lib/less/js/test/less/errors/property-asterisk-only-name.txt +4 -0
- data/lib/less/js/test/less/errors/property-interp-not-defined.less +1 -0
- data/lib/less/js/test/less/errors/property-interp-not-defined.txt +2 -0
- data/lib/less/js/test/less/errors/svg-gradient1.less +3 -0
- data/lib/less/js/test/less/errors/svg-gradient1.txt +4 -0
- data/lib/less/js/test/less/errors/svg-gradient2.less +3 -0
- data/lib/less/js/test/less/errors/svg-gradient2.txt +4 -0
- data/lib/less/js/test/less/errors/svg-gradient3.less +3 -0
- data/lib/less/js/test/less/errors/svg-gradient3.txt +4 -0
- data/lib/less/js/test/less/errors/unit-function.less +3 -0
- data/lib/less/js/test/less/errors/unit-function.txt +4 -0
- data/lib/less/js/test/less/extend-chaining.less +12 -0
- data/lib/less/js/test/less/extend-selector.less +15 -0
- data/lib/less/js/test/less/extract-and-length.less +133 -0
- data/lib/less/js/test/less/functions.less +15 -2
- data/lib/less/js/test/less/globalVars/extended.json +5 -0
- data/lib/less/js/test/less/globalVars/extended.less +10 -0
- data/lib/less/js/test/less/globalVars/simple.json +3 -0
- data/lib/less/js/test/less/globalVars/simple.less +3 -0
- data/lib/less/js/test/less/import-inline.less +2 -0
- data/lib/less/js/test/less/import-once.less +2 -0
- data/lib/less/js/test/less/import-reference.less +18 -0
- data/lib/less/js/test/less/import/import-and-relative-paths-test.less +11 -0
- data/lib/less/js/test/less/import/import-reference.less +43 -0
- data/lib/less/js/test/less/import/import-test-f.less +5 -0
- data/lib/less/js/test/less/import/invalid-css.less +1 -0
- data/lib/less/js/test/less/media.less +25 -1
- data/lib/less/js/test/less/merge.less +59 -0
- data/lib/less/js/test/less/mixins-args.less +10 -0
- data/lib/less/js/test/less/mixins-guards-default-func.less +195 -0
- data/lib/less/js/test/less/mixins-guards.less +16 -0
- data/lib/less/js/test/less/mixins-important.less +4 -1
- data/lib/less/js/test/less/mixins-interpolated.less +69 -0
- data/lib/less/js/test/less/mixins.less +27 -0
- data/lib/less/js/test/less/modifyVars/extended.json +5 -0
- data/lib/less/js/test/less/modifyVars/extended.less +11 -0
- data/lib/less/js/test/less/no-js-errors/no-js-errors.less +3 -0
- data/lib/less/js/test/less/no-js-errors/no-js-errors.txt +4 -0
- data/lib/less/js/test/less/no-output.less +2 -0
- data/lib/less/js/test/less/parens.less +4 -0
- data/lib/less/js/test/less/property-name-interp.less +53 -0
- data/lib/less/js/test/less/selectors.less +13 -0
- data/lib/less/js/test/less/sourcemaps/basic.json +3 -0
- data/lib/less/js/test/less/sourcemaps/basic.less +27 -0
- data/lib/less/js/test/less/sourcemaps/imported.css +7 -0
- data/lib/less/js/test/less/strings.less +6 -0
- data/lib/less/js/test/less/url-args/urls.less +63 -0
- data/lib/less/js/test/less/urls.less +15 -0
- data/lib/less/js/test/rhino/test-header.js +15 -0
- data/lib/less/js/test/sourcemaps/basic.json +1 -0
- data/lib/less/js/test/sourcemaps/index.html +17 -0
- data/lib/less/loader.rb +48 -40
- data/lib/less/version.rb +1 -1
- data/spec/less/parser_spec.rb +15 -15
- metadata +146 -40
- data/lib/less/js/Makefile +0 -102
- data/lib/less/js/build/header.js +0 -9
- data/lib/less/js/test/browser-test-prepare.js +0 -46
- data/lib/less/js/test/browser/runner-errors.js +0 -5
- data/lib/less/js/test/browser/runner-main.js +0 -15
- data/lib/less/js/test/browser/template.htm +0 -10
- data/lib/less/js/test/less/errors/color-operation-error.txt +0 -2
@@ -0,0 +1,1933 @@
|
|
1
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
4
|
+
* Licensed under the New BSD license. See LICENSE or:
|
5
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
6
|
+
*/
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Define a module along with a payload.
|
10
|
+
* @param {string} moduleName Name for the payload
|
11
|
+
* @param {ignored} deps Ignored. For compatibility with CommonJS AMD Spec
|
12
|
+
* @param {function} payload Function with (require, exports, module) params
|
13
|
+
*/
|
14
|
+
function define(moduleName, deps, payload) {
|
15
|
+
if (typeof moduleName != "string") {
|
16
|
+
throw new TypeError('Expected string, got: ' + moduleName);
|
17
|
+
}
|
18
|
+
|
19
|
+
if (arguments.length == 2) {
|
20
|
+
payload = deps;
|
21
|
+
}
|
22
|
+
|
23
|
+
if (moduleName in define.modules) {
|
24
|
+
throw new Error("Module already defined: " + moduleName);
|
25
|
+
}
|
26
|
+
define.modules[moduleName] = payload;
|
27
|
+
};
|
28
|
+
|
29
|
+
/**
|
30
|
+
* The global store of un-instantiated modules
|
31
|
+
*/
|
32
|
+
define.modules = {};
|
33
|
+
|
34
|
+
|
35
|
+
/**
|
36
|
+
* We invoke require() in the context of a Domain so we can have multiple
|
37
|
+
* sets of modules running separate from each other.
|
38
|
+
* This contrasts with JSMs which are singletons, Domains allows us to
|
39
|
+
* optionally load a CommonJS module twice with separate data each time.
|
40
|
+
* Perhaps you want 2 command lines with a different set of commands in each,
|
41
|
+
* for example.
|
42
|
+
*/
|
43
|
+
function Domain() {
|
44
|
+
this.modules = {};
|
45
|
+
this._currentModule = null;
|
46
|
+
}
|
47
|
+
|
48
|
+
(function () {
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Lookup module names and resolve them by calling the definition function if
|
52
|
+
* needed.
|
53
|
+
* There are 2 ways to call this, either with an array of dependencies and a
|
54
|
+
* callback to call when the dependencies are found (which can happen
|
55
|
+
* asynchronously in an in-page context) or with a single string an no callback
|
56
|
+
* where the dependency is resolved synchronously and returned.
|
57
|
+
* The API is designed to be compatible with the CommonJS AMD spec and
|
58
|
+
* RequireJS.
|
59
|
+
* @param {string[]|string} deps A name, or names for the payload
|
60
|
+
* @param {function|undefined} callback Function to call when the dependencies
|
61
|
+
* are resolved
|
62
|
+
* @return {undefined|object} The module required or undefined for
|
63
|
+
* array/callback method
|
64
|
+
*/
|
65
|
+
Domain.prototype.require = function(deps, callback) {
|
66
|
+
if (Array.isArray(deps)) {
|
67
|
+
var params = deps.map(function(dep) {
|
68
|
+
return this.lookup(dep);
|
69
|
+
}, this);
|
70
|
+
if (callback) {
|
71
|
+
callback.apply(null, params);
|
72
|
+
}
|
73
|
+
return undefined;
|
74
|
+
}
|
75
|
+
else {
|
76
|
+
return this.lookup(deps);
|
77
|
+
}
|
78
|
+
};
|
79
|
+
|
80
|
+
function normalize(path) {
|
81
|
+
var bits = path.split('/');
|
82
|
+
var i = 1;
|
83
|
+
while (i < bits.length) {
|
84
|
+
if (bits[i] === '..') {
|
85
|
+
bits.splice(i-1, 1);
|
86
|
+
} else if (bits[i] === '.') {
|
87
|
+
bits.splice(i, 1);
|
88
|
+
} else {
|
89
|
+
i++;
|
90
|
+
}
|
91
|
+
}
|
92
|
+
return bits.join('/');
|
93
|
+
}
|
94
|
+
|
95
|
+
function join(a, b) {
|
96
|
+
a = a.trim();
|
97
|
+
b = b.trim();
|
98
|
+
if (/^\//.test(b)) {
|
99
|
+
return b;
|
100
|
+
} else {
|
101
|
+
return a.replace(/\/*$/, '/') + b;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
function dirname(path) {
|
106
|
+
var bits = path.split('/');
|
107
|
+
bits.pop();
|
108
|
+
return bits.join('/');
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Lookup module names and resolve them by calling the definition function if
|
113
|
+
* needed.
|
114
|
+
* @param {string} moduleName A name for the payload to lookup
|
115
|
+
* @return {object} The module specified by aModuleName or null if not found.
|
116
|
+
*/
|
117
|
+
Domain.prototype.lookup = function(moduleName) {
|
118
|
+
if (/^\./.test(moduleName)) {
|
119
|
+
moduleName = normalize(join(dirname(this._currentModule), moduleName));
|
120
|
+
}
|
121
|
+
|
122
|
+
if (moduleName in this.modules) {
|
123
|
+
var module = this.modules[moduleName];
|
124
|
+
return module;
|
125
|
+
}
|
126
|
+
|
127
|
+
if (!(moduleName in define.modules)) {
|
128
|
+
throw new Error("Module not defined: " + moduleName);
|
129
|
+
}
|
130
|
+
|
131
|
+
var module = define.modules[moduleName];
|
132
|
+
|
133
|
+
if (typeof module == "function") {
|
134
|
+
var exports = {};
|
135
|
+
var previousModule = this._currentModule;
|
136
|
+
this._currentModule = moduleName;
|
137
|
+
module(this.require.bind(this), exports, { id: moduleName, uri: "" });
|
138
|
+
this._currentModule = previousModule;
|
139
|
+
module = exports;
|
140
|
+
}
|
141
|
+
|
142
|
+
// cache the resulting module object for next time
|
143
|
+
this.modules[moduleName] = module;
|
144
|
+
|
145
|
+
return module;
|
146
|
+
};
|
147
|
+
|
148
|
+
}());
|
149
|
+
|
150
|
+
define.Domain = Domain;
|
151
|
+
define.globalDomain = new Domain();
|
152
|
+
var require = define.globalDomain.require.bind(define.globalDomain);
|
153
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
154
|
+
/*
|
155
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
156
|
+
* Licensed under the New BSD license. See LICENSE or:
|
157
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
158
|
+
*/
|
159
|
+
define('source-map/source-map-generator', ['require', 'exports', 'module' , 'source-map/base64-vlq', 'source-map/util', 'source-map/array-set'], function(require, exports, module) {
|
160
|
+
|
161
|
+
var base64VLQ = require('./base64-vlq');
|
162
|
+
var util = require('./util');
|
163
|
+
var ArraySet = require('./array-set').ArraySet;
|
164
|
+
|
165
|
+
/**
|
166
|
+
* An instance of the SourceMapGenerator represents a source map which is
|
167
|
+
* being built incrementally. To create a new one, you must pass an object
|
168
|
+
* with the following properties:
|
169
|
+
*
|
170
|
+
* - file: The filename of the generated source.
|
171
|
+
* - sourceRoot: An optional root for all URLs in this source map.
|
172
|
+
*/
|
173
|
+
function SourceMapGenerator(aArgs) {
|
174
|
+
this._file = util.getArg(aArgs, 'file');
|
175
|
+
this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
|
176
|
+
this._sources = new ArraySet();
|
177
|
+
this._names = new ArraySet();
|
178
|
+
this._mappings = [];
|
179
|
+
this._sourcesContents = null;
|
180
|
+
}
|
181
|
+
|
182
|
+
SourceMapGenerator.prototype._version = 3;
|
183
|
+
|
184
|
+
/**
|
185
|
+
* Creates a new SourceMapGenerator based on a SourceMapConsumer
|
186
|
+
*
|
187
|
+
* @param aSourceMapConsumer The SourceMap.
|
188
|
+
*/
|
189
|
+
SourceMapGenerator.fromSourceMap =
|
190
|
+
function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
|
191
|
+
var sourceRoot = aSourceMapConsumer.sourceRoot;
|
192
|
+
var generator = new SourceMapGenerator({
|
193
|
+
file: aSourceMapConsumer.file,
|
194
|
+
sourceRoot: sourceRoot
|
195
|
+
});
|
196
|
+
aSourceMapConsumer.eachMapping(function (mapping) {
|
197
|
+
var newMapping = {
|
198
|
+
generated: {
|
199
|
+
line: mapping.generatedLine,
|
200
|
+
column: mapping.generatedColumn
|
201
|
+
}
|
202
|
+
};
|
203
|
+
|
204
|
+
if (mapping.source) {
|
205
|
+
newMapping.source = mapping.source;
|
206
|
+
if (sourceRoot) {
|
207
|
+
newMapping.source = util.relative(sourceRoot, newMapping.source);
|
208
|
+
}
|
209
|
+
|
210
|
+
newMapping.original = {
|
211
|
+
line: mapping.originalLine,
|
212
|
+
column: mapping.originalColumn
|
213
|
+
};
|
214
|
+
|
215
|
+
if (mapping.name) {
|
216
|
+
newMapping.name = mapping.name;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
generator.addMapping(newMapping);
|
221
|
+
});
|
222
|
+
aSourceMapConsumer.sources.forEach(function (sourceFile) {
|
223
|
+
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
|
224
|
+
if (content) {
|
225
|
+
generator.setSourceContent(sourceFile, content);
|
226
|
+
}
|
227
|
+
});
|
228
|
+
return generator;
|
229
|
+
};
|
230
|
+
|
231
|
+
/**
|
232
|
+
* Add a single mapping from original source line and column to the generated
|
233
|
+
* source's line and column for this source map being created. The mapping
|
234
|
+
* object should have the following properties:
|
235
|
+
*
|
236
|
+
* - generated: An object with the generated line and column positions.
|
237
|
+
* - original: An object with the original line and column positions.
|
238
|
+
* - source: The original source file (relative to the sourceRoot).
|
239
|
+
* - name: An optional original token name for this mapping.
|
240
|
+
*/
|
241
|
+
SourceMapGenerator.prototype.addMapping =
|
242
|
+
function SourceMapGenerator_addMapping(aArgs) {
|
243
|
+
var generated = util.getArg(aArgs, 'generated');
|
244
|
+
var original = util.getArg(aArgs, 'original', null);
|
245
|
+
var source = util.getArg(aArgs, 'source', null);
|
246
|
+
var name = util.getArg(aArgs, 'name', null);
|
247
|
+
|
248
|
+
this._validateMapping(generated, original, source, name);
|
249
|
+
|
250
|
+
if (source && !this._sources.has(source)) {
|
251
|
+
this._sources.add(source);
|
252
|
+
}
|
253
|
+
|
254
|
+
if (name && !this._names.has(name)) {
|
255
|
+
this._names.add(name);
|
256
|
+
}
|
257
|
+
|
258
|
+
this._mappings.push({
|
259
|
+
generatedLine: generated.line,
|
260
|
+
generatedColumn: generated.column,
|
261
|
+
originalLine: original != null && original.line,
|
262
|
+
originalColumn: original != null && original.column,
|
263
|
+
source: source,
|
264
|
+
name: name
|
265
|
+
});
|
266
|
+
};
|
267
|
+
|
268
|
+
/**
|
269
|
+
* Set the source content for a source file.
|
270
|
+
*/
|
271
|
+
SourceMapGenerator.prototype.setSourceContent =
|
272
|
+
function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
|
273
|
+
var source = aSourceFile;
|
274
|
+
if (this._sourceRoot) {
|
275
|
+
source = util.relative(this._sourceRoot, source);
|
276
|
+
}
|
277
|
+
|
278
|
+
if (aSourceContent !== null) {
|
279
|
+
// Add the source content to the _sourcesContents map.
|
280
|
+
// Create a new _sourcesContents map if the property is null.
|
281
|
+
if (!this._sourcesContents) {
|
282
|
+
this._sourcesContents = {};
|
283
|
+
}
|
284
|
+
this._sourcesContents[util.toSetString(source)] = aSourceContent;
|
285
|
+
} else {
|
286
|
+
// Remove the source file from the _sourcesContents map.
|
287
|
+
// If the _sourcesContents map is empty, set the property to null.
|
288
|
+
delete this._sourcesContents[util.toSetString(source)];
|
289
|
+
if (Object.keys(this._sourcesContents).length === 0) {
|
290
|
+
this._sourcesContents = null;
|
291
|
+
}
|
292
|
+
}
|
293
|
+
};
|
294
|
+
|
295
|
+
/**
|
296
|
+
* Applies the mappings of a sub-source-map for a specific source file to the
|
297
|
+
* source map being generated. Each mapping to the supplied source file is
|
298
|
+
* rewritten using the supplied source map. Note: The resolution for the
|
299
|
+
* resulting mappings is the minimium of this map and the supplied map.
|
300
|
+
*
|
301
|
+
* @param aSourceMapConsumer The source map to be applied.
|
302
|
+
* @param aSourceFile Optional. The filename of the source file.
|
303
|
+
* If omitted, SourceMapConsumer's file property will be used.
|
304
|
+
*/
|
305
|
+
SourceMapGenerator.prototype.applySourceMap =
|
306
|
+
function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile) {
|
307
|
+
// If aSourceFile is omitted, we will use the file property of the SourceMap
|
308
|
+
if (!aSourceFile) {
|
309
|
+
aSourceFile = aSourceMapConsumer.file;
|
310
|
+
}
|
311
|
+
var sourceRoot = this._sourceRoot;
|
312
|
+
// Make "aSourceFile" relative if an absolute Url is passed.
|
313
|
+
if (sourceRoot) {
|
314
|
+
aSourceFile = util.relative(sourceRoot, aSourceFile);
|
315
|
+
}
|
316
|
+
// Applying the SourceMap can add and remove items from the sources and
|
317
|
+
// the names array.
|
318
|
+
var newSources = new ArraySet();
|
319
|
+
var newNames = new ArraySet();
|
320
|
+
|
321
|
+
// Find mappings for the "aSourceFile"
|
322
|
+
this._mappings.forEach(function (mapping) {
|
323
|
+
if (mapping.source === aSourceFile && mapping.originalLine) {
|
324
|
+
// Check if it can be mapped by the source map, then update the mapping.
|
325
|
+
var original = aSourceMapConsumer.originalPositionFor({
|
326
|
+
line: mapping.originalLine,
|
327
|
+
column: mapping.originalColumn
|
328
|
+
});
|
329
|
+
if (original.source !== null) {
|
330
|
+
// Copy mapping
|
331
|
+
if (sourceRoot) {
|
332
|
+
mapping.source = util.relative(sourceRoot, original.source);
|
333
|
+
} else {
|
334
|
+
mapping.source = original.source;
|
335
|
+
}
|
336
|
+
mapping.originalLine = original.line;
|
337
|
+
mapping.originalColumn = original.column;
|
338
|
+
if (original.name !== null && mapping.name !== null) {
|
339
|
+
// Only use the identifier name if it's an identifier
|
340
|
+
// in both SourceMaps
|
341
|
+
mapping.name = original.name;
|
342
|
+
}
|
343
|
+
}
|
344
|
+
}
|
345
|
+
|
346
|
+
var source = mapping.source;
|
347
|
+
if (source && !newSources.has(source)) {
|
348
|
+
newSources.add(source);
|
349
|
+
}
|
350
|
+
|
351
|
+
var name = mapping.name;
|
352
|
+
if (name && !newNames.has(name)) {
|
353
|
+
newNames.add(name);
|
354
|
+
}
|
355
|
+
|
356
|
+
}, this);
|
357
|
+
this._sources = newSources;
|
358
|
+
this._names = newNames;
|
359
|
+
|
360
|
+
// Copy sourcesContents of applied map.
|
361
|
+
aSourceMapConsumer.sources.forEach(function (sourceFile) {
|
362
|
+
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
|
363
|
+
if (content) {
|
364
|
+
if (sourceRoot) {
|
365
|
+
sourceFile = util.relative(sourceRoot, sourceFile);
|
366
|
+
}
|
367
|
+
this.setSourceContent(sourceFile, content);
|
368
|
+
}
|
369
|
+
}, this);
|
370
|
+
};
|
371
|
+
|
372
|
+
/**
|
373
|
+
* A mapping can have one of the three levels of data:
|
374
|
+
*
|
375
|
+
* 1. Just the generated position.
|
376
|
+
* 2. The Generated position, original position, and original source.
|
377
|
+
* 3. Generated and original position, original source, as well as a name
|
378
|
+
* token.
|
379
|
+
*
|
380
|
+
* To maintain consistency, we validate that any new mapping being added falls
|
381
|
+
* in to one of these categories.
|
382
|
+
*/
|
383
|
+
SourceMapGenerator.prototype._validateMapping =
|
384
|
+
function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
|
385
|
+
aName) {
|
386
|
+
if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
|
387
|
+
&& aGenerated.line > 0 && aGenerated.column >= 0
|
388
|
+
&& !aOriginal && !aSource && !aName) {
|
389
|
+
// Case 1.
|
390
|
+
return;
|
391
|
+
}
|
392
|
+
else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
|
393
|
+
&& aOriginal && 'line' in aOriginal && 'column' in aOriginal
|
394
|
+
&& aGenerated.line > 0 && aGenerated.column >= 0
|
395
|
+
&& aOriginal.line > 0 && aOriginal.column >= 0
|
396
|
+
&& aSource) {
|
397
|
+
// Cases 2 and 3.
|
398
|
+
return;
|
399
|
+
}
|
400
|
+
else {
|
401
|
+
throw new Error('Invalid mapping: ' + JSON.stringify({
|
402
|
+
generated: aGenerated,
|
403
|
+
source: aSource,
|
404
|
+
original: aOriginal,
|
405
|
+
name: aName
|
406
|
+
}));
|
407
|
+
}
|
408
|
+
};
|
409
|
+
|
410
|
+
/**
|
411
|
+
* Serialize the accumulated mappings in to the stream of base 64 VLQs
|
412
|
+
* specified by the source map format.
|
413
|
+
*/
|
414
|
+
SourceMapGenerator.prototype._serializeMappings =
|
415
|
+
function SourceMapGenerator_serializeMappings() {
|
416
|
+
var previousGeneratedColumn = 0;
|
417
|
+
var previousGeneratedLine = 1;
|
418
|
+
var previousOriginalColumn = 0;
|
419
|
+
var previousOriginalLine = 0;
|
420
|
+
var previousName = 0;
|
421
|
+
var previousSource = 0;
|
422
|
+
var result = '';
|
423
|
+
var mapping;
|
424
|
+
|
425
|
+
// The mappings must be guaranteed to be in sorted order before we start
|
426
|
+
// serializing them or else the generated line numbers (which are defined
|
427
|
+
// via the ';' separators) will be all messed up. Note: it might be more
|
428
|
+
// performant to maintain the sorting as we insert them, rather than as we
|
429
|
+
// serialize them, but the big O is the same either way.
|
430
|
+
this._mappings.sort(util.compareByGeneratedPositions);
|
431
|
+
|
432
|
+
for (var i = 0, len = this._mappings.length; i < len; i++) {
|
433
|
+
mapping = this._mappings[i];
|
434
|
+
|
435
|
+
if (mapping.generatedLine !== previousGeneratedLine) {
|
436
|
+
previousGeneratedColumn = 0;
|
437
|
+
while (mapping.generatedLine !== previousGeneratedLine) {
|
438
|
+
result += ';';
|
439
|
+
previousGeneratedLine++;
|
440
|
+
}
|
441
|
+
}
|
442
|
+
else {
|
443
|
+
if (i > 0) {
|
444
|
+
if (!util.compareByGeneratedPositions(mapping, this._mappings[i - 1])) {
|
445
|
+
continue;
|
446
|
+
}
|
447
|
+
result += ',';
|
448
|
+
}
|
449
|
+
}
|
450
|
+
|
451
|
+
result += base64VLQ.encode(mapping.generatedColumn
|
452
|
+
- previousGeneratedColumn);
|
453
|
+
previousGeneratedColumn = mapping.generatedColumn;
|
454
|
+
|
455
|
+
if (mapping.source) {
|
456
|
+
result += base64VLQ.encode(this._sources.indexOf(mapping.source)
|
457
|
+
- previousSource);
|
458
|
+
previousSource = this._sources.indexOf(mapping.source);
|
459
|
+
|
460
|
+
// lines are stored 0-based in SourceMap spec version 3
|
461
|
+
result += base64VLQ.encode(mapping.originalLine - 1
|
462
|
+
- previousOriginalLine);
|
463
|
+
previousOriginalLine = mapping.originalLine - 1;
|
464
|
+
|
465
|
+
result += base64VLQ.encode(mapping.originalColumn
|
466
|
+
- previousOriginalColumn);
|
467
|
+
previousOriginalColumn = mapping.originalColumn;
|
468
|
+
|
469
|
+
if (mapping.name) {
|
470
|
+
result += base64VLQ.encode(this._names.indexOf(mapping.name)
|
471
|
+
- previousName);
|
472
|
+
previousName = this._names.indexOf(mapping.name);
|
473
|
+
}
|
474
|
+
}
|
475
|
+
}
|
476
|
+
|
477
|
+
return result;
|
478
|
+
};
|
479
|
+
|
480
|
+
SourceMapGenerator.prototype._generateSourcesContent =
|
481
|
+
function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
|
482
|
+
return aSources.map(function (source) {
|
483
|
+
if (!this._sourcesContents) {
|
484
|
+
return null;
|
485
|
+
}
|
486
|
+
if (aSourceRoot) {
|
487
|
+
source = util.relative(aSourceRoot, source);
|
488
|
+
}
|
489
|
+
var key = util.toSetString(source);
|
490
|
+
return Object.prototype.hasOwnProperty.call(this._sourcesContents,
|
491
|
+
key)
|
492
|
+
? this._sourcesContents[key]
|
493
|
+
: null;
|
494
|
+
}, this);
|
495
|
+
};
|
496
|
+
|
497
|
+
/**
|
498
|
+
* Externalize the source map.
|
499
|
+
*/
|
500
|
+
SourceMapGenerator.prototype.toJSON =
|
501
|
+
function SourceMapGenerator_toJSON() {
|
502
|
+
var map = {
|
503
|
+
version: this._version,
|
504
|
+
file: this._file,
|
505
|
+
sources: this._sources.toArray(),
|
506
|
+
names: this._names.toArray(),
|
507
|
+
mappings: this._serializeMappings()
|
508
|
+
};
|
509
|
+
if (this._sourceRoot) {
|
510
|
+
map.sourceRoot = this._sourceRoot;
|
511
|
+
}
|
512
|
+
if (this._sourcesContents) {
|
513
|
+
map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
|
514
|
+
}
|
515
|
+
|
516
|
+
return map;
|
517
|
+
};
|
518
|
+
|
519
|
+
/**
|
520
|
+
* Render the source map being generated to a string.
|
521
|
+
*/
|
522
|
+
SourceMapGenerator.prototype.toString =
|
523
|
+
function SourceMapGenerator_toString() {
|
524
|
+
return JSON.stringify(this);
|
525
|
+
};
|
526
|
+
|
527
|
+
exports.SourceMapGenerator = SourceMapGenerator;
|
528
|
+
|
529
|
+
});
|
530
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
531
|
+
/*
|
532
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
533
|
+
* Licensed under the New BSD license. See LICENSE or:
|
534
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
535
|
+
*
|
536
|
+
* Based on the Base 64 VLQ implementation in Closure Compiler:
|
537
|
+
* https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
|
538
|
+
*
|
539
|
+
* Copyright 2011 The Closure Compiler Authors. All rights reserved.
|
540
|
+
* Redistribution and use in source and binary forms, with or without
|
541
|
+
* modification, are permitted provided that the following conditions are
|
542
|
+
* met:
|
543
|
+
*
|
544
|
+
* * Redistributions of source code must retain the above copyright
|
545
|
+
* notice, this list of conditions and the following disclaimer.
|
546
|
+
* * Redistributions in binary form must reproduce the above
|
547
|
+
* copyright notice, this list of conditions and the following
|
548
|
+
* disclaimer in the documentation and/or other materials provided
|
549
|
+
* with the distribution.
|
550
|
+
* * Neither the name of Google Inc. nor the names of its
|
551
|
+
* contributors may be used to endorse or promote products derived
|
552
|
+
* from this software without specific prior written permission.
|
553
|
+
*
|
554
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
555
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
556
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
557
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
558
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
559
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
560
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
561
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
562
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
563
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
564
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
565
|
+
*/
|
566
|
+
define('source-map/base64-vlq', ['require', 'exports', 'module' , 'source-map/base64'], function(require, exports, module) {
|
567
|
+
|
568
|
+
var base64 = require('./base64');
|
569
|
+
|
570
|
+
// A single base 64 digit can contain 6 bits of data. For the base 64 variable
|
571
|
+
// length quantities we use in the source map spec, the first bit is the sign,
|
572
|
+
// the next four bits are the actual value, and the 6th bit is the
|
573
|
+
// continuation bit. The continuation bit tells us whether there are more
|
574
|
+
// digits in this value following this digit.
|
575
|
+
//
|
576
|
+
// Continuation
|
577
|
+
// | Sign
|
578
|
+
// | |
|
579
|
+
// V V
|
580
|
+
// 101011
|
581
|
+
|
582
|
+
var VLQ_BASE_SHIFT = 5;
|
583
|
+
|
584
|
+
// binary: 100000
|
585
|
+
var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
|
586
|
+
|
587
|
+
// binary: 011111
|
588
|
+
var VLQ_BASE_MASK = VLQ_BASE - 1;
|
589
|
+
|
590
|
+
// binary: 100000
|
591
|
+
var VLQ_CONTINUATION_BIT = VLQ_BASE;
|
592
|
+
|
593
|
+
/**
|
594
|
+
* Converts from a two-complement value to a value where the sign bit is
|
595
|
+
* is placed in the least significant bit. For example, as decimals:
|
596
|
+
* 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
|
597
|
+
* 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
|
598
|
+
*/
|
599
|
+
function toVLQSigned(aValue) {
|
600
|
+
return aValue < 0
|
601
|
+
? ((-aValue) << 1) + 1
|
602
|
+
: (aValue << 1) + 0;
|
603
|
+
}
|
604
|
+
|
605
|
+
/**
|
606
|
+
* Converts to a two-complement value from a value where the sign bit is
|
607
|
+
* is placed in the least significant bit. For example, as decimals:
|
608
|
+
* 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
|
609
|
+
* 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
|
610
|
+
*/
|
611
|
+
function fromVLQSigned(aValue) {
|
612
|
+
var isNegative = (aValue & 1) === 1;
|
613
|
+
var shifted = aValue >> 1;
|
614
|
+
return isNegative
|
615
|
+
? -shifted
|
616
|
+
: shifted;
|
617
|
+
}
|
618
|
+
|
619
|
+
/**
|
620
|
+
* Returns the base 64 VLQ encoded value.
|
621
|
+
*/
|
622
|
+
exports.encode = function base64VLQ_encode(aValue) {
|
623
|
+
var encoded = "";
|
624
|
+
var digit;
|
625
|
+
|
626
|
+
var vlq = toVLQSigned(aValue);
|
627
|
+
|
628
|
+
do {
|
629
|
+
digit = vlq & VLQ_BASE_MASK;
|
630
|
+
vlq >>>= VLQ_BASE_SHIFT;
|
631
|
+
if (vlq > 0) {
|
632
|
+
// There are still more digits in this value, so we must make sure the
|
633
|
+
// continuation bit is marked.
|
634
|
+
digit |= VLQ_CONTINUATION_BIT;
|
635
|
+
}
|
636
|
+
encoded += base64.encode(digit);
|
637
|
+
} while (vlq > 0);
|
638
|
+
|
639
|
+
return encoded;
|
640
|
+
};
|
641
|
+
|
642
|
+
/**
|
643
|
+
* Decodes the next base 64 VLQ value from the given string and returns the
|
644
|
+
* value and the rest of the string.
|
645
|
+
*/
|
646
|
+
exports.decode = function base64VLQ_decode(aStr) {
|
647
|
+
var i = 0;
|
648
|
+
var strLen = aStr.length;
|
649
|
+
var result = 0;
|
650
|
+
var shift = 0;
|
651
|
+
var continuation, digit;
|
652
|
+
|
653
|
+
do {
|
654
|
+
if (i >= strLen) {
|
655
|
+
throw new Error("Expected more digits in base 64 VLQ value.");
|
656
|
+
}
|
657
|
+
digit = base64.decode(aStr.charAt(i++));
|
658
|
+
continuation = !!(digit & VLQ_CONTINUATION_BIT);
|
659
|
+
digit &= VLQ_BASE_MASK;
|
660
|
+
result = result + (digit << shift);
|
661
|
+
shift += VLQ_BASE_SHIFT;
|
662
|
+
} while (continuation);
|
663
|
+
|
664
|
+
return {
|
665
|
+
value: fromVLQSigned(result),
|
666
|
+
rest: aStr.slice(i)
|
667
|
+
};
|
668
|
+
};
|
669
|
+
|
670
|
+
});
|
671
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
672
|
+
/*
|
673
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
674
|
+
* Licensed under the New BSD license. See LICENSE or:
|
675
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
676
|
+
*/
|
677
|
+
define('source-map/base64', ['require', 'exports', 'module' , ], function(require, exports, module) {
|
678
|
+
|
679
|
+
var charToIntMap = {};
|
680
|
+
var intToCharMap = {};
|
681
|
+
|
682
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
683
|
+
.split('')
|
684
|
+
.forEach(function (ch, index) {
|
685
|
+
charToIntMap[ch] = index;
|
686
|
+
intToCharMap[index] = ch;
|
687
|
+
});
|
688
|
+
|
689
|
+
/**
|
690
|
+
* Encode an integer in the range of 0 to 63 to a single base 64 digit.
|
691
|
+
*/
|
692
|
+
exports.encode = function base64_encode(aNumber) {
|
693
|
+
if (aNumber in intToCharMap) {
|
694
|
+
return intToCharMap[aNumber];
|
695
|
+
}
|
696
|
+
throw new TypeError("Must be between 0 and 63: " + aNumber);
|
697
|
+
};
|
698
|
+
|
699
|
+
/**
|
700
|
+
* Decode a single base 64 digit to an integer.
|
701
|
+
*/
|
702
|
+
exports.decode = function base64_decode(aChar) {
|
703
|
+
if (aChar in charToIntMap) {
|
704
|
+
return charToIntMap[aChar];
|
705
|
+
}
|
706
|
+
throw new TypeError("Not a valid base 64 digit: " + aChar);
|
707
|
+
};
|
708
|
+
|
709
|
+
});
|
710
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
711
|
+
/*
|
712
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
713
|
+
* Licensed under the New BSD license. See LICENSE or:
|
714
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
715
|
+
*/
|
716
|
+
define('source-map/util', ['require', 'exports', 'module' , ], function(require, exports, module) {
|
717
|
+
|
718
|
+
/**
|
719
|
+
* This is a helper function for getting values from parameter/options
|
720
|
+
* objects.
|
721
|
+
*
|
722
|
+
* @param args The object we are extracting values from
|
723
|
+
* @param name The name of the property we are getting.
|
724
|
+
* @param defaultValue An optional value to return if the property is missing
|
725
|
+
* from the object. If this is not specified and the property is missing, an
|
726
|
+
* error will be thrown.
|
727
|
+
*/
|
728
|
+
function getArg(aArgs, aName, aDefaultValue) {
|
729
|
+
if (aName in aArgs) {
|
730
|
+
return aArgs[aName];
|
731
|
+
} else if (arguments.length === 3) {
|
732
|
+
return aDefaultValue;
|
733
|
+
} else {
|
734
|
+
throw new Error('"' + aName + '" is a required argument.');
|
735
|
+
}
|
736
|
+
}
|
737
|
+
exports.getArg = getArg;
|
738
|
+
|
739
|
+
var urlRegexp = /([\w+\-.]+):\/\/((\w+:\w+)@)?([\w.]+)?(:(\d+))?(\S+)?/;
|
740
|
+
var dataUrlRegexp = /^data:.+\,.+/;
|
741
|
+
|
742
|
+
function urlParse(aUrl) {
|
743
|
+
var match = aUrl.match(urlRegexp);
|
744
|
+
if (!match) {
|
745
|
+
return null;
|
746
|
+
}
|
747
|
+
return {
|
748
|
+
scheme: match[1],
|
749
|
+
auth: match[3],
|
750
|
+
host: match[4],
|
751
|
+
port: match[6],
|
752
|
+
path: match[7]
|
753
|
+
};
|
754
|
+
}
|
755
|
+
exports.urlParse = urlParse;
|
756
|
+
|
757
|
+
function urlGenerate(aParsedUrl) {
|
758
|
+
var url = aParsedUrl.scheme + "://";
|
759
|
+
if (aParsedUrl.auth) {
|
760
|
+
url += aParsedUrl.auth + "@"
|
761
|
+
}
|
762
|
+
if (aParsedUrl.host) {
|
763
|
+
url += aParsedUrl.host;
|
764
|
+
}
|
765
|
+
if (aParsedUrl.port) {
|
766
|
+
url += ":" + aParsedUrl.port
|
767
|
+
}
|
768
|
+
if (aParsedUrl.path) {
|
769
|
+
url += aParsedUrl.path;
|
770
|
+
}
|
771
|
+
return url;
|
772
|
+
}
|
773
|
+
exports.urlGenerate = urlGenerate;
|
774
|
+
|
775
|
+
function join(aRoot, aPath) {
|
776
|
+
var url;
|
777
|
+
|
778
|
+
if (aPath.match(urlRegexp) || aPath.match(dataUrlRegexp)) {
|
779
|
+
return aPath;
|
780
|
+
}
|
781
|
+
|
782
|
+
if (aPath.charAt(0) === '/' && (url = urlParse(aRoot))) {
|
783
|
+
url.path = aPath;
|
784
|
+
return urlGenerate(url);
|
785
|
+
}
|
786
|
+
|
787
|
+
return aRoot.replace(/\/$/, '') + '/' + aPath;
|
788
|
+
}
|
789
|
+
exports.join = join;
|
790
|
+
|
791
|
+
/**
|
792
|
+
* Because behavior goes wacky when you set `__proto__` on objects, we
|
793
|
+
* have to prefix all the strings in our set with an arbitrary character.
|
794
|
+
*
|
795
|
+
* See https://github.com/mozilla/source-map/pull/31 and
|
796
|
+
* https://github.com/mozilla/source-map/issues/30
|
797
|
+
*
|
798
|
+
* @param String aStr
|
799
|
+
*/
|
800
|
+
function toSetString(aStr) {
|
801
|
+
return '$' + aStr;
|
802
|
+
}
|
803
|
+
exports.toSetString = toSetString;
|
804
|
+
|
805
|
+
function fromSetString(aStr) {
|
806
|
+
return aStr.substr(1);
|
807
|
+
}
|
808
|
+
exports.fromSetString = fromSetString;
|
809
|
+
|
810
|
+
function relative(aRoot, aPath) {
|
811
|
+
aRoot = aRoot.replace(/\/$/, '');
|
812
|
+
|
813
|
+
var url = urlParse(aRoot);
|
814
|
+
if (aPath.charAt(0) == "/" && url && url.path == "/") {
|
815
|
+
return aPath.slice(1);
|
816
|
+
}
|
817
|
+
|
818
|
+
return aPath.indexOf(aRoot + '/') === 0
|
819
|
+
? aPath.substr(aRoot.length + 1)
|
820
|
+
: aPath;
|
821
|
+
}
|
822
|
+
exports.relative = relative;
|
823
|
+
|
824
|
+
function strcmp(aStr1, aStr2) {
|
825
|
+
var s1 = aStr1 || "";
|
826
|
+
var s2 = aStr2 || "";
|
827
|
+
return (s1 > s2) - (s1 < s2);
|
828
|
+
}
|
829
|
+
|
830
|
+
/**
|
831
|
+
* Comparator between two mappings where the original positions are compared.
|
832
|
+
*
|
833
|
+
* Optionally pass in `true` as `onlyCompareGenerated` to consider two
|
834
|
+
* mappings with the same original source/line/column, but different generated
|
835
|
+
* line and column the same. Useful when searching for a mapping with a
|
836
|
+
* stubbed out mapping.
|
837
|
+
*/
|
838
|
+
function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
|
839
|
+
var cmp;
|
840
|
+
|
841
|
+
cmp = strcmp(mappingA.source, mappingB.source);
|
842
|
+
if (cmp) {
|
843
|
+
return cmp;
|
844
|
+
}
|
845
|
+
|
846
|
+
cmp = mappingA.originalLine - mappingB.originalLine;
|
847
|
+
if (cmp) {
|
848
|
+
return cmp;
|
849
|
+
}
|
850
|
+
|
851
|
+
cmp = mappingA.originalColumn - mappingB.originalColumn;
|
852
|
+
if (cmp || onlyCompareOriginal) {
|
853
|
+
return cmp;
|
854
|
+
}
|
855
|
+
|
856
|
+
cmp = strcmp(mappingA.name, mappingB.name);
|
857
|
+
if (cmp) {
|
858
|
+
return cmp;
|
859
|
+
}
|
860
|
+
|
861
|
+
cmp = mappingA.generatedLine - mappingB.generatedLine;
|
862
|
+
if (cmp) {
|
863
|
+
return cmp;
|
864
|
+
}
|
865
|
+
|
866
|
+
return mappingA.generatedColumn - mappingB.generatedColumn;
|
867
|
+
};
|
868
|
+
exports.compareByOriginalPositions = compareByOriginalPositions;
|
869
|
+
|
870
|
+
/**
|
871
|
+
* Comparator between two mappings where the generated positions are
|
872
|
+
* compared.
|
873
|
+
*
|
874
|
+
* Optionally pass in `true` as `onlyCompareGenerated` to consider two
|
875
|
+
* mappings with the same generated line and column, but different
|
876
|
+
* source/name/original line and column the same. Useful when searching for a
|
877
|
+
* mapping with a stubbed out mapping.
|
878
|
+
*/
|
879
|
+
function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
|
880
|
+
var cmp;
|
881
|
+
|
882
|
+
cmp = mappingA.generatedLine - mappingB.generatedLine;
|
883
|
+
if (cmp) {
|
884
|
+
return cmp;
|
885
|
+
}
|
886
|
+
|
887
|
+
cmp = mappingA.generatedColumn - mappingB.generatedColumn;
|
888
|
+
if (cmp || onlyCompareGenerated) {
|
889
|
+
return cmp;
|
890
|
+
}
|
891
|
+
|
892
|
+
cmp = strcmp(mappingA.source, mappingB.source);
|
893
|
+
if (cmp) {
|
894
|
+
return cmp;
|
895
|
+
}
|
896
|
+
|
897
|
+
cmp = mappingA.originalLine - mappingB.originalLine;
|
898
|
+
if (cmp) {
|
899
|
+
return cmp;
|
900
|
+
}
|
901
|
+
|
902
|
+
cmp = mappingA.originalColumn - mappingB.originalColumn;
|
903
|
+
if (cmp) {
|
904
|
+
return cmp;
|
905
|
+
}
|
906
|
+
|
907
|
+
return strcmp(mappingA.name, mappingB.name);
|
908
|
+
};
|
909
|
+
exports.compareByGeneratedPositions = compareByGeneratedPositions;
|
910
|
+
|
911
|
+
});
|
912
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
913
|
+
/*
|
914
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
915
|
+
* Licensed under the New BSD license. See LICENSE or:
|
916
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
917
|
+
*/
|
918
|
+
define('source-map/array-set', ['require', 'exports', 'module' , 'source-map/util'], function(require, exports, module) {
|
919
|
+
|
920
|
+
var util = require('./util');
|
921
|
+
|
922
|
+
/**
|
923
|
+
* A data structure which is a combination of an array and a set. Adding a new
|
924
|
+
* member is O(1), testing for membership is O(1), and finding the index of an
|
925
|
+
* element is O(1). Removing elements from the set is not supported. Only
|
926
|
+
* strings are supported for membership.
|
927
|
+
*/
|
928
|
+
function ArraySet() {
|
929
|
+
this._array = [];
|
930
|
+
this._set = {};
|
931
|
+
}
|
932
|
+
|
933
|
+
/**
|
934
|
+
* Static method for creating ArraySet instances from an existing array.
|
935
|
+
*/
|
936
|
+
ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
|
937
|
+
var set = new ArraySet();
|
938
|
+
for (var i = 0, len = aArray.length; i < len; i++) {
|
939
|
+
set.add(aArray[i], aAllowDuplicates);
|
940
|
+
}
|
941
|
+
return set;
|
942
|
+
};
|
943
|
+
|
944
|
+
/**
|
945
|
+
* Add the given string to this set.
|
946
|
+
*
|
947
|
+
* @param String aStr
|
948
|
+
*/
|
949
|
+
ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
|
950
|
+
var isDuplicate = this.has(aStr);
|
951
|
+
var idx = this._array.length;
|
952
|
+
if (!isDuplicate || aAllowDuplicates) {
|
953
|
+
this._array.push(aStr);
|
954
|
+
}
|
955
|
+
if (!isDuplicate) {
|
956
|
+
this._set[util.toSetString(aStr)] = idx;
|
957
|
+
}
|
958
|
+
};
|
959
|
+
|
960
|
+
/**
|
961
|
+
* Is the given string a member of this set?
|
962
|
+
*
|
963
|
+
* @param String aStr
|
964
|
+
*/
|
965
|
+
ArraySet.prototype.has = function ArraySet_has(aStr) {
|
966
|
+
return Object.prototype.hasOwnProperty.call(this._set,
|
967
|
+
util.toSetString(aStr));
|
968
|
+
};
|
969
|
+
|
970
|
+
/**
|
971
|
+
* What is the index of the given string in the array?
|
972
|
+
*
|
973
|
+
* @param String aStr
|
974
|
+
*/
|
975
|
+
ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
|
976
|
+
if (this.has(aStr)) {
|
977
|
+
return this._set[util.toSetString(aStr)];
|
978
|
+
}
|
979
|
+
throw new Error('"' + aStr + '" is not in the set.');
|
980
|
+
};
|
981
|
+
|
982
|
+
/**
|
983
|
+
* What is the element at the given index?
|
984
|
+
*
|
985
|
+
* @param Number aIdx
|
986
|
+
*/
|
987
|
+
ArraySet.prototype.at = function ArraySet_at(aIdx) {
|
988
|
+
if (aIdx >= 0 && aIdx < this._array.length) {
|
989
|
+
return this._array[aIdx];
|
990
|
+
}
|
991
|
+
throw new Error('No element indexed by ' + aIdx);
|
992
|
+
};
|
993
|
+
|
994
|
+
/**
|
995
|
+
* Returns the array representation of this set (which has the proper indices
|
996
|
+
* indicated by indexOf). Note that this is a copy of the internal array used
|
997
|
+
* for storing the members so that no one can mess with internal state.
|
998
|
+
*/
|
999
|
+
ArraySet.prototype.toArray = function ArraySet_toArray() {
|
1000
|
+
return this._array.slice();
|
1001
|
+
};
|
1002
|
+
|
1003
|
+
exports.ArraySet = ArraySet;
|
1004
|
+
|
1005
|
+
});
|
1006
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
1007
|
+
/*
|
1008
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
1009
|
+
* Licensed under the New BSD license. See LICENSE or:
|
1010
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
1011
|
+
*/
|
1012
|
+
define('source-map/source-map-consumer', ['require', 'exports', 'module' , 'source-map/util', 'source-map/binary-search', 'source-map/array-set', 'source-map/base64-vlq'], function(require, exports, module) {
|
1013
|
+
|
1014
|
+
var util = require('./util');
|
1015
|
+
var binarySearch = require('./binary-search');
|
1016
|
+
var ArraySet = require('./array-set').ArraySet;
|
1017
|
+
var base64VLQ = require('./base64-vlq');
|
1018
|
+
|
1019
|
+
/**
|
1020
|
+
* A SourceMapConsumer instance represents a parsed source map which we can
|
1021
|
+
* query for information about the original file positions by giving it a file
|
1022
|
+
* position in the generated source.
|
1023
|
+
*
|
1024
|
+
* The only parameter is the raw source map (either as a JSON string, or
|
1025
|
+
* already parsed to an object). According to the spec, source maps have the
|
1026
|
+
* following attributes:
|
1027
|
+
*
|
1028
|
+
* - version: Which version of the source map spec this map is following.
|
1029
|
+
* - sources: An array of URLs to the original source files.
|
1030
|
+
* - names: An array of identifiers which can be referrenced by individual mappings.
|
1031
|
+
* - sourceRoot: Optional. The URL root from which all sources are relative.
|
1032
|
+
* - sourcesContent: Optional. An array of contents of the original source files.
|
1033
|
+
* - mappings: A string of base64 VLQs which contain the actual mappings.
|
1034
|
+
* - file: The generated file this source map is associated with.
|
1035
|
+
*
|
1036
|
+
* Here is an example source map, taken from the source map spec[0]:
|
1037
|
+
*
|
1038
|
+
* {
|
1039
|
+
* version : 3,
|
1040
|
+
* file: "out.js",
|
1041
|
+
* sourceRoot : "",
|
1042
|
+
* sources: ["foo.js", "bar.js"],
|
1043
|
+
* names: ["src", "maps", "are", "fun"],
|
1044
|
+
* mappings: "AA,AB;;ABCDE;"
|
1045
|
+
* }
|
1046
|
+
*
|
1047
|
+
* [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
|
1048
|
+
*/
|
1049
|
+
function SourceMapConsumer(aSourceMap) {
|
1050
|
+
var sourceMap = aSourceMap;
|
1051
|
+
if (typeof aSourceMap === 'string') {
|
1052
|
+
sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
|
1053
|
+
}
|
1054
|
+
|
1055
|
+
var version = util.getArg(sourceMap, 'version');
|
1056
|
+
var sources = util.getArg(sourceMap, 'sources');
|
1057
|
+
// Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
|
1058
|
+
// requires the array) to play nice here.
|
1059
|
+
var names = util.getArg(sourceMap, 'names', []);
|
1060
|
+
var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
|
1061
|
+
var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
|
1062
|
+
var mappings = util.getArg(sourceMap, 'mappings');
|
1063
|
+
var file = util.getArg(sourceMap, 'file', null);
|
1064
|
+
|
1065
|
+
// Once again, Sass deviates from the spec and supplies the version as a
|
1066
|
+
// string rather than a number, so we use loose equality checking here.
|
1067
|
+
if (version != this._version) {
|
1068
|
+
throw new Error('Unsupported version: ' + version);
|
1069
|
+
}
|
1070
|
+
|
1071
|
+
// Pass `true` below to allow duplicate names and sources. While source maps
|
1072
|
+
// are intended to be compressed and deduplicated, the TypeScript compiler
|
1073
|
+
// sometimes generates source maps with duplicates in them. See Github issue
|
1074
|
+
// #72 and bugzil.la/889492.
|
1075
|
+
this._names = ArraySet.fromArray(names, true);
|
1076
|
+
this._sources = ArraySet.fromArray(sources, true);
|
1077
|
+
|
1078
|
+
this.sourceRoot = sourceRoot;
|
1079
|
+
this.sourcesContent = sourcesContent;
|
1080
|
+
this._mappings = mappings;
|
1081
|
+
this.file = file;
|
1082
|
+
}
|
1083
|
+
|
1084
|
+
/**
|
1085
|
+
* Create a SourceMapConsumer from a SourceMapGenerator.
|
1086
|
+
*
|
1087
|
+
* @param SourceMapGenerator aSourceMap
|
1088
|
+
* The source map that will be consumed.
|
1089
|
+
* @returns SourceMapConsumer
|
1090
|
+
*/
|
1091
|
+
SourceMapConsumer.fromSourceMap =
|
1092
|
+
function SourceMapConsumer_fromSourceMap(aSourceMap) {
|
1093
|
+
var smc = Object.create(SourceMapConsumer.prototype);
|
1094
|
+
|
1095
|
+
smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
|
1096
|
+
smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
|
1097
|
+
smc.sourceRoot = aSourceMap._sourceRoot;
|
1098
|
+
smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
|
1099
|
+
smc.sourceRoot);
|
1100
|
+
smc.file = aSourceMap._file;
|
1101
|
+
|
1102
|
+
smc.__generatedMappings = aSourceMap._mappings.slice()
|
1103
|
+
.sort(util.compareByGeneratedPositions);
|
1104
|
+
smc.__originalMappings = aSourceMap._mappings.slice()
|
1105
|
+
.sort(util.compareByOriginalPositions);
|
1106
|
+
|
1107
|
+
return smc;
|
1108
|
+
};
|
1109
|
+
|
1110
|
+
/**
|
1111
|
+
* The version of the source mapping spec that we are consuming.
|
1112
|
+
*/
|
1113
|
+
SourceMapConsumer.prototype._version = 3;
|
1114
|
+
|
1115
|
+
/**
|
1116
|
+
* The list of original sources.
|
1117
|
+
*/
|
1118
|
+
Object.defineProperty(SourceMapConsumer.prototype, 'sources', {
|
1119
|
+
get: function () {
|
1120
|
+
return this._sources.toArray().map(function (s) {
|
1121
|
+
return this.sourceRoot ? util.join(this.sourceRoot, s) : s;
|
1122
|
+
}, this);
|
1123
|
+
}
|
1124
|
+
});
|
1125
|
+
|
1126
|
+
// `__generatedMappings` and `__originalMappings` are arrays that hold the
|
1127
|
+
// parsed mapping coordinates from the source map's "mappings" attribute. They
|
1128
|
+
// are lazily instantiated, accessed via the `_generatedMappings` and
|
1129
|
+
// `_originalMappings` getters respectively, and we only parse the mappings
|
1130
|
+
// and create these arrays once queried for a source location. We jump through
|
1131
|
+
// these hoops because there can be many thousands of mappings, and parsing
|
1132
|
+
// them is expensive, so we only want to do it if we must.
|
1133
|
+
//
|
1134
|
+
// Each object in the arrays is of the form:
|
1135
|
+
//
|
1136
|
+
// {
|
1137
|
+
// generatedLine: The line number in the generated code,
|
1138
|
+
// generatedColumn: The column number in the generated code,
|
1139
|
+
// source: The path to the original source file that generated this
|
1140
|
+
// chunk of code,
|
1141
|
+
// originalLine: The line number in the original source that
|
1142
|
+
// corresponds to this chunk of generated code,
|
1143
|
+
// originalColumn: The column number in the original source that
|
1144
|
+
// corresponds to this chunk of generated code,
|
1145
|
+
// name: The name of the original symbol which generated this chunk of
|
1146
|
+
// code.
|
1147
|
+
// }
|
1148
|
+
//
|
1149
|
+
// All properties except for `generatedLine` and `generatedColumn` can be
|
1150
|
+
// `null`.
|
1151
|
+
//
|
1152
|
+
// `_generatedMappings` is ordered by the generated positions.
|
1153
|
+
//
|
1154
|
+
// `_originalMappings` is ordered by the original positions.
|
1155
|
+
|
1156
|
+
SourceMapConsumer.prototype.__generatedMappings = null;
|
1157
|
+
Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
|
1158
|
+
get: function () {
|
1159
|
+
if (!this.__generatedMappings) {
|
1160
|
+
this.__generatedMappings = [];
|
1161
|
+
this.__originalMappings = [];
|
1162
|
+
this._parseMappings(this._mappings, this.sourceRoot);
|
1163
|
+
}
|
1164
|
+
|
1165
|
+
return this.__generatedMappings;
|
1166
|
+
}
|
1167
|
+
});
|
1168
|
+
|
1169
|
+
SourceMapConsumer.prototype.__originalMappings = null;
|
1170
|
+
Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
|
1171
|
+
get: function () {
|
1172
|
+
if (!this.__originalMappings) {
|
1173
|
+
this.__generatedMappings = [];
|
1174
|
+
this.__originalMappings = [];
|
1175
|
+
this._parseMappings(this._mappings, this.sourceRoot);
|
1176
|
+
}
|
1177
|
+
|
1178
|
+
return this.__originalMappings;
|
1179
|
+
}
|
1180
|
+
});
|
1181
|
+
|
1182
|
+
/**
|
1183
|
+
* Parse the mappings in a string in to a data structure which we can easily
|
1184
|
+
* query (the ordered arrays in the `this.__generatedMappings` and
|
1185
|
+
* `this.__originalMappings` properties).
|
1186
|
+
*/
|
1187
|
+
SourceMapConsumer.prototype._parseMappings =
|
1188
|
+
function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
|
1189
|
+
var generatedLine = 1;
|
1190
|
+
var previousGeneratedColumn = 0;
|
1191
|
+
var previousOriginalLine = 0;
|
1192
|
+
var previousOriginalColumn = 0;
|
1193
|
+
var previousSource = 0;
|
1194
|
+
var previousName = 0;
|
1195
|
+
var mappingSeparator = /^[,;]/;
|
1196
|
+
var str = aStr;
|
1197
|
+
var mapping;
|
1198
|
+
var temp;
|
1199
|
+
|
1200
|
+
while (str.length > 0) {
|
1201
|
+
if (str.charAt(0) === ';') {
|
1202
|
+
generatedLine++;
|
1203
|
+
str = str.slice(1);
|
1204
|
+
previousGeneratedColumn = 0;
|
1205
|
+
}
|
1206
|
+
else if (str.charAt(0) === ',') {
|
1207
|
+
str = str.slice(1);
|
1208
|
+
}
|
1209
|
+
else {
|
1210
|
+
mapping = {};
|
1211
|
+
mapping.generatedLine = generatedLine;
|
1212
|
+
|
1213
|
+
// Generated column.
|
1214
|
+
temp = base64VLQ.decode(str);
|
1215
|
+
mapping.generatedColumn = previousGeneratedColumn + temp.value;
|
1216
|
+
previousGeneratedColumn = mapping.generatedColumn;
|
1217
|
+
str = temp.rest;
|
1218
|
+
|
1219
|
+
if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
|
1220
|
+
// Original source.
|
1221
|
+
temp = base64VLQ.decode(str);
|
1222
|
+
mapping.source = this._sources.at(previousSource + temp.value);
|
1223
|
+
previousSource += temp.value;
|
1224
|
+
str = temp.rest;
|
1225
|
+
if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
|
1226
|
+
throw new Error('Found a source, but no line and column');
|
1227
|
+
}
|
1228
|
+
|
1229
|
+
// Original line.
|
1230
|
+
temp = base64VLQ.decode(str);
|
1231
|
+
mapping.originalLine = previousOriginalLine + temp.value;
|
1232
|
+
previousOriginalLine = mapping.originalLine;
|
1233
|
+
// Lines are stored 0-based
|
1234
|
+
mapping.originalLine += 1;
|
1235
|
+
str = temp.rest;
|
1236
|
+
if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
|
1237
|
+
throw new Error('Found a source and line, but no column');
|
1238
|
+
}
|
1239
|
+
|
1240
|
+
// Original column.
|
1241
|
+
temp = base64VLQ.decode(str);
|
1242
|
+
mapping.originalColumn = previousOriginalColumn + temp.value;
|
1243
|
+
previousOriginalColumn = mapping.originalColumn;
|
1244
|
+
str = temp.rest;
|
1245
|
+
|
1246
|
+
if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
|
1247
|
+
// Original name.
|
1248
|
+
temp = base64VLQ.decode(str);
|
1249
|
+
mapping.name = this._names.at(previousName + temp.value);
|
1250
|
+
previousName += temp.value;
|
1251
|
+
str = temp.rest;
|
1252
|
+
}
|
1253
|
+
}
|
1254
|
+
|
1255
|
+
this.__generatedMappings.push(mapping);
|
1256
|
+
if (typeof mapping.originalLine === 'number') {
|
1257
|
+
this.__originalMappings.push(mapping);
|
1258
|
+
}
|
1259
|
+
}
|
1260
|
+
}
|
1261
|
+
|
1262
|
+
this.__originalMappings.sort(util.compareByOriginalPositions);
|
1263
|
+
};
|
1264
|
+
|
1265
|
+
/**
|
1266
|
+
* Find the mapping that best matches the hypothetical "needle" mapping that
|
1267
|
+
* we are searching for in the given "haystack" of mappings.
|
1268
|
+
*/
|
1269
|
+
SourceMapConsumer.prototype._findMapping =
|
1270
|
+
function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
|
1271
|
+
aColumnName, aComparator) {
|
1272
|
+
// To return the position we are searching for, we must first find the
|
1273
|
+
// mapping for the given position and then return the opposite position it
|
1274
|
+
// points to. Because the mappings are sorted, we can use binary search to
|
1275
|
+
// find the best mapping.
|
1276
|
+
|
1277
|
+
if (aNeedle[aLineName] <= 0) {
|
1278
|
+
throw new TypeError('Line must be greater than or equal to 1, got '
|
1279
|
+
+ aNeedle[aLineName]);
|
1280
|
+
}
|
1281
|
+
if (aNeedle[aColumnName] < 0) {
|
1282
|
+
throw new TypeError('Column must be greater than or equal to 0, got '
|
1283
|
+
+ aNeedle[aColumnName]);
|
1284
|
+
}
|
1285
|
+
|
1286
|
+
return binarySearch.search(aNeedle, aMappings, aComparator);
|
1287
|
+
};
|
1288
|
+
|
1289
|
+
/**
|
1290
|
+
* Returns the original source, line, and column information for the generated
|
1291
|
+
* source's line and column positions provided. The only argument is an object
|
1292
|
+
* with the following properties:
|
1293
|
+
*
|
1294
|
+
* - line: The line number in the generated source.
|
1295
|
+
* - column: The column number in the generated source.
|
1296
|
+
*
|
1297
|
+
* and an object is returned with the following properties:
|
1298
|
+
*
|
1299
|
+
* - source: The original source file, or null.
|
1300
|
+
* - line: The line number in the original source, or null.
|
1301
|
+
* - column: The column number in the original source, or null.
|
1302
|
+
* - name: The original identifier, or null.
|
1303
|
+
*/
|
1304
|
+
SourceMapConsumer.prototype.originalPositionFor =
|
1305
|
+
function SourceMapConsumer_originalPositionFor(aArgs) {
|
1306
|
+
var needle = {
|
1307
|
+
generatedLine: util.getArg(aArgs, 'line'),
|
1308
|
+
generatedColumn: util.getArg(aArgs, 'column')
|
1309
|
+
};
|
1310
|
+
|
1311
|
+
var mapping = this._findMapping(needle,
|
1312
|
+
this._generatedMappings,
|
1313
|
+
"generatedLine",
|
1314
|
+
"generatedColumn",
|
1315
|
+
util.compareByGeneratedPositions);
|
1316
|
+
|
1317
|
+
if (mapping) {
|
1318
|
+
var source = util.getArg(mapping, 'source', null);
|
1319
|
+
if (source && this.sourceRoot) {
|
1320
|
+
source = util.join(this.sourceRoot, source);
|
1321
|
+
}
|
1322
|
+
return {
|
1323
|
+
source: source,
|
1324
|
+
line: util.getArg(mapping, 'originalLine', null),
|
1325
|
+
column: util.getArg(mapping, 'originalColumn', null),
|
1326
|
+
name: util.getArg(mapping, 'name', null)
|
1327
|
+
};
|
1328
|
+
}
|
1329
|
+
|
1330
|
+
return {
|
1331
|
+
source: null,
|
1332
|
+
line: null,
|
1333
|
+
column: null,
|
1334
|
+
name: null
|
1335
|
+
};
|
1336
|
+
};
|
1337
|
+
|
1338
|
+
/**
|
1339
|
+
* Returns the original source content. The only argument is the url of the
|
1340
|
+
* original source file. Returns null if no original source content is
|
1341
|
+
* availible.
|
1342
|
+
*/
|
1343
|
+
SourceMapConsumer.prototype.sourceContentFor =
|
1344
|
+
function SourceMapConsumer_sourceContentFor(aSource) {
|
1345
|
+
if (!this.sourcesContent) {
|
1346
|
+
return null;
|
1347
|
+
}
|
1348
|
+
|
1349
|
+
if (this.sourceRoot) {
|
1350
|
+
aSource = util.relative(this.sourceRoot, aSource);
|
1351
|
+
}
|
1352
|
+
|
1353
|
+
if (this._sources.has(aSource)) {
|
1354
|
+
return this.sourcesContent[this._sources.indexOf(aSource)];
|
1355
|
+
}
|
1356
|
+
|
1357
|
+
var url;
|
1358
|
+
if (this.sourceRoot
|
1359
|
+
&& (url = util.urlParse(this.sourceRoot))) {
|
1360
|
+
// XXX: file:// URIs and absolute paths lead to unexpected behavior for
|
1361
|
+
// many users. We can help them out when they expect file:// URIs to
|
1362
|
+
// behave like it would if they were running a local HTTP server. See
|
1363
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
|
1364
|
+
var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
|
1365
|
+
if (url.scheme == "file"
|
1366
|
+
&& this._sources.has(fileUriAbsPath)) {
|
1367
|
+
return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
|
1368
|
+
}
|
1369
|
+
|
1370
|
+
if ((!url.path || url.path == "/")
|
1371
|
+
&& this._sources.has("/" + aSource)) {
|
1372
|
+
return this.sourcesContent[this._sources.indexOf("/" + aSource)];
|
1373
|
+
}
|
1374
|
+
}
|
1375
|
+
|
1376
|
+
throw new Error('"' + aSource + '" is not in the SourceMap.');
|
1377
|
+
};
|
1378
|
+
|
1379
|
+
/**
|
1380
|
+
* Returns the generated line and column information for the original source,
|
1381
|
+
* line, and column positions provided. The only argument is an object with
|
1382
|
+
* the following properties:
|
1383
|
+
*
|
1384
|
+
* - source: The filename of the original source.
|
1385
|
+
* - line: The line number in the original source.
|
1386
|
+
* - column: The column number in the original source.
|
1387
|
+
*
|
1388
|
+
* and an object is returned with the following properties:
|
1389
|
+
*
|
1390
|
+
* - line: The line number in the generated source, or null.
|
1391
|
+
* - column: The column number in the generated source, or null.
|
1392
|
+
*/
|
1393
|
+
SourceMapConsumer.prototype.generatedPositionFor =
|
1394
|
+
function SourceMapConsumer_generatedPositionFor(aArgs) {
|
1395
|
+
var needle = {
|
1396
|
+
source: util.getArg(aArgs, 'source'),
|
1397
|
+
originalLine: util.getArg(aArgs, 'line'),
|
1398
|
+
originalColumn: util.getArg(aArgs, 'column')
|
1399
|
+
};
|
1400
|
+
|
1401
|
+
if (this.sourceRoot) {
|
1402
|
+
needle.source = util.relative(this.sourceRoot, needle.source);
|
1403
|
+
}
|
1404
|
+
|
1405
|
+
var mapping = this._findMapping(needle,
|
1406
|
+
this._originalMappings,
|
1407
|
+
"originalLine",
|
1408
|
+
"originalColumn",
|
1409
|
+
util.compareByOriginalPositions);
|
1410
|
+
|
1411
|
+
if (mapping) {
|
1412
|
+
return {
|
1413
|
+
line: util.getArg(mapping, 'generatedLine', null),
|
1414
|
+
column: util.getArg(mapping, 'generatedColumn', null)
|
1415
|
+
};
|
1416
|
+
}
|
1417
|
+
|
1418
|
+
return {
|
1419
|
+
line: null,
|
1420
|
+
column: null
|
1421
|
+
};
|
1422
|
+
};
|
1423
|
+
|
1424
|
+
SourceMapConsumer.GENERATED_ORDER = 1;
|
1425
|
+
SourceMapConsumer.ORIGINAL_ORDER = 2;
|
1426
|
+
|
1427
|
+
/**
|
1428
|
+
* Iterate over each mapping between an original source/line/column and a
|
1429
|
+
* generated line/column in this source map.
|
1430
|
+
*
|
1431
|
+
* @param Function aCallback
|
1432
|
+
* The function that is called with each mapping.
|
1433
|
+
* @param Object aContext
|
1434
|
+
* Optional. If specified, this object will be the value of `this` every
|
1435
|
+
* time that `aCallback` is called.
|
1436
|
+
* @param aOrder
|
1437
|
+
* Either `SourceMapConsumer.GENERATED_ORDER` or
|
1438
|
+
* `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
|
1439
|
+
* iterate over the mappings sorted by the generated file's line/column
|
1440
|
+
* order or the original's source/line/column order, respectively. Defaults to
|
1441
|
+
* `SourceMapConsumer.GENERATED_ORDER`.
|
1442
|
+
*/
|
1443
|
+
SourceMapConsumer.prototype.eachMapping =
|
1444
|
+
function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
|
1445
|
+
var context = aContext || null;
|
1446
|
+
var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
|
1447
|
+
|
1448
|
+
var mappings;
|
1449
|
+
switch (order) {
|
1450
|
+
case SourceMapConsumer.GENERATED_ORDER:
|
1451
|
+
mappings = this._generatedMappings;
|
1452
|
+
break;
|
1453
|
+
case SourceMapConsumer.ORIGINAL_ORDER:
|
1454
|
+
mappings = this._originalMappings;
|
1455
|
+
break;
|
1456
|
+
default:
|
1457
|
+
throw new Error("Unknown order of iteration.");
|
1458
|
+
}
|
1459
|
+
|
1460
|
+
var sourceRoot = this.sourceRoot;
|
1461
|
+
mappings.map(function (mapping) {
|
1462
|
+
var source = mapping.source;
|
1463
|
+
if (source && sourceRoot) {
|
1464
|
+
source = util.join(sourceRoot, source);
|
1465
|
+
}
|
1466
|
+
return {
|
1467
|
+
source: source,
|
1468
|
+
generatedLine: mapping.generatedLine,
|
1469
|
+
generatedColumn: mapping.generatedColumn,
|
1470
|
+
originalLine: mapping.originalLine,
|
1471
|
+
originalColumn: mapping.originalColumn,
|
1472
|
+
name: mapping.name
|
1473
|
+
};
|
1474
|
+
}).forEach(aCallback, context);
|
1475
|
+
};
|
1476
|
+
|
1477
|
+
exports.SourceMapConsumer = SourceMapConsumer;
|
1478
|
+
|
1479
|
+
});
|
1480
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
1481
|
+
/*
|
1482
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
1483
|
+
* Licensed under the New BSD license. See LICENSE or:
|
1484
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
1485
|
+
*/
|
1486
|
+
define('source-map/binary-search', ['require', 'exports', 'module' , ], function(require, exports, module) {
|
1487
|
+
|
1488
|
+
/**
|
1489
|
+
* Recursive implementation of binary search.
|
1490
|
+
*
|
1491
|
+
* @param aLow Indices here and lower do not contain the needle.
|
1492
|
+
* @param aHigh Indices here and higher do not contain the needle.
|
1493
|
+
* @param aNeedle The element being searched for.
|
1494
|
+
* @param aHaystack The non-empty array being searched.
|
1495
|
+
* @param aCompare Function which takes two elements and returns -1, 0, or 1.
|
1496
|
+
*/
|
1497
|
+
function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
|
1498
|
+
// This function terminates when one of the following is true:
|
1499
|
+
//
|
1500
|
+
// 1. We find the exact element we are looking for.
|
1501
|
+
//
|
1502
|
+
// 2. We did not find the exact element, but we can return the next
|
1503
|
+
// closest element that is less than that element.
|
1504
|
+
//
|
1505
|
+
// 3. We did not find the exact element, and there is no next-closest
|
1506
|
+
// element which is less than the one we are searching for, so we
|
1507
|
+
// return null.
|
1508
|
+
var mid = Math.floor((aHigh - aLow) / 2) + aLow;
|
1509
|
+
var cmp = aCompare(aNeedle, aHaystack[mid], true);
|
1510
|
+
if (cmp === 0) {
|
1511
|
+
// Found the element we are looking for.
|
1512
|
+
return aHaystack[mid];
|
1513
|
+
}
|
1514
|
+
else if (cmp > 0) {
|
1515
|
+
// aHaystack[mid] is greater than our needle.
|
1516
|
+
if (aHigh - mid > 1) {
|
1517
|
+
// The element is in the upper half.
|
1518
|
+
return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
|
1519
|
+
}
|
1520
|
+
// We did not find an exact match, return the next closest one
|
1521
|
+
// (termination case 2).
|
1522
|
+
return aHaystack[mid];
|
1523
|
+
}
|
1524
|
+
else {
|
1525
|
+
// aHaystack[mid] is less than our needle.
|
1526
|
+
if (mid - aLow > 1) {
|
1527
|
+
// The element is in the lower half.
|
1528
|
+
return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
|
1529
|
+
}
|
1530
|
+
// The exact needle element was not found in this haystack. Determine if
|
1531
|
+
// we are in termination case (2) or (3) and return the appropriate thing.
|
1532
|
+
return aLow < 0
|
1533
|
+
? null
|
1534
|
+
: aHaystack[aLow];
|
1535
|
+
}
|
1536
|
+
}
|
1537
|
+
|
1538
|
+
/**
|
1539
|
+
* This is an implementation of binary search which will always try and return
|
1540
|
+
* the next lowest value checked if there is no exact hit. This is because
|
1541
|
+
* mappings between original and generated line/col pairs are single points,
|
1542
|
+
* and there is an implicit region between each of them, so a miss just means
|
1543
|
+
* that you aren't on the very start of a region.
|
1544
|
+
*
|
1545
|
+
* @param aNeedle The element you are looking for.
|
1546
|
+
* @param aHaystack The array that is being searched.
|
1547
|
+
* @param aCompare A function which takes the needle and an element in the
|
1548
|
+
* array and returns -1, 0, or 1 depending on whether the needle is less
|
1549
|
+
* than, equal to, or greater than the element, respectively.
|
1550
|
+
*/
|
1551
|
+
exports.search = function search(aNeedle, aHaystack, aCompare) {
|
1552
|
+
return aHaystack.length > 0
|
1553
|
+
? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare)
|
1554
|
+
: null;
|
1555
|
+
};
|
1556
|
+
|
1557
|
+
});
|
1558
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
1559
|
+
/*
|
1560
|
+
* Copyright 2011 Mozilla Foundation and contributors
|
1561
|
+
* Licensed under the New BSD license. See LICENSE or:
|
1562
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
1563
|
+
*/
|
1564
|
+
define('source-map/source-node', ['require', 'exports', 'module' , 'source-map/source-map-generator', 'source-map/util'], function(require, exports, module) {
|
1565
|
+
|
1566
|
+
var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
|
1567
|
+
var util = require('./util');
|
1568
|
+
|
1569
|
+
/**
|
1570
|
+
* SourceNodes provide a way to abstract over interpolating/concatenating
|
1571
|
+
* snippets of generated JavaScript source code while maintaining the line and
|
1572
|
+
* column information associated with the original source code.
|
1573
|
+
*
|
1574
|
+
* @param aLine The original line number.
|
1575
|
+
* @param aColumn The original column number.
|
1576
|
+
* @param aSource The original source's filename.
|
1577
|
+
* @param aChunks Optional. An array of strings which are snippets of
|
1578
|
+
* generated JS, or other SourceNodes.
|
1579
|
+
* @param aName The original identifier.
|
1580
|
+
*/
|
1581
|
+
function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
|
1582
|
+
this.children = [];
|
1583
|
+
this.sourceContents = {};
|
1584
|
+
this.line = aLine === undefined ? null : aLine;
|
1585
|
+
this.column = aColumn === undefined ? null : aColumn;
|
1586
|
+
this.source = aSource === undefined ? null : aSource;
|
1587
|
+
this.name = aName === undefined ? null : aName;
|
1588
|
+
if (aChunks != null) this.add(aChunks);
|
1589
|
+
}
|
1590
|
+
|
1591
|
+
/**
|
1592
|
+
* Creates a SourceNode from generated code and a SourceMapConsumer.
|
1593
|
+
*
|
1594
|
+
* @param aGeneratedCode The generated code
|
1595
|
+
* @param aSourceMapConsumer The SourceMap for the generated code
|
1596
|
+
*/
|
1597
|
+
SourceNode.fromStringWithSourceMap =
|
1598
|
+
function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer) {
|
1599
|
+
// The SourceNode we want to fill with the generated code
|
1600
|
+
// and the SourceMap
|
1601
|
+
var node = new SourceNode();
|
1602
|
+
|
1603
|
+
// The generated code
|
1604
|
+
// Processed fragments are removed from this array.
|
1605
|
+
var remainingLines = aGeneratedCode.split('\n');
|
1606
|
+
|
1607
|
+
// We need to remember the position of "remainingLines"
|
1608
|
+
var lastGeneratedLine = 1, lastGeneratedColumn = 0;
|
1609
|
+
|
1610
|
+
// The generate SourceNodes we need a code range.
|
1611
|
+
// To extract it current and last mapping is used.
|
1612
|
+
// Here we store the last mapping.
|
1613
|
+
var lastMapping = null;
|
1614
|
+
|
1615
|
+
aSourceMapConsumer.eachMapping(function (mapping) {
|
1616
|
+
if (lastMapping === null) {
|
1617
|
+
// We add the generated code until the first mapping
|
1618
|
+
// to the SourceNode without any mapping.
|
1619
|
+
// Each line is added as separate string.
|
1620
|
+
while (lastGeneratedLine < mapping.generatedLine) {
|
1621
|
+
node.add(remainingLines.shift() + "\n");
|
1622
|
+
lastGeneratedLine++;
|
1623
|
+
}
|
1624
|
+
if (lastGeneratedColumn < mapping.generatedColumn) {
|
1625
|
+
var nextLine = remainingLines[0];
|
1626
|
+
node.add(nextLine.substr(0, mapping.generatedColumn));
|
1627
|
+
remainingLines[0] = nextLine.substr(mapping.generatedColumn);
|
1628
|
+
lastGeneratedColumn = mapping.generatedColumn;
|
1629
|
+
}
|
1630
|
+
} else {
|
1631
|
+
// We add the code from "lastMapping" to "mapping":
|
1632
|
+
// First check if there is a new line in between.
|
1633
|
+
if (lastGeneratedLine < mapping.generatedLine) {
|
1634
|
+
var code = "";
|
1635
|
+
// Associate full lines with "lastMapping"
|
1636
|
+
do {
|
1637
|
+
code += remainingLines.shift() + "\n";
|
1638
|
+
lastGeneratedLine++;
|
1639
|
+
lastGeneratedColumn = 0;
|
1640
|
+
} while (lastGeneratedLine < mapping.generatedLine);
|
1641
|
+
// When we reached the correct line, we add code until we
|
1642
|
+
// reach the correct column too.
|
1643
|
+
if (lastGeneratedColumn < mapping.generatedColumn) {
|
1644
|
+
var nextLine = remainingLines[0];
|
1645
|
+
code += nextLine.substr(0, mapping.generatedColumn);
|
1646
|
+
remainingLines[0] = nextLine.substr(mapping.generatedColumn);
|
1647
|
+
lastGeneratedColumn = mapping.generatedColumn;
|
1648
|
+
}
|
1649
|
+
// Create the SourceNode.
|
1650
|
+
addMappingWithCode(lastMapping, code);
|
1651
|
+
} else {
|
1652
|
+
// There is no new line in between.
|
1653
|
+
// Associate the code between "lastGeneratedColumn" and
|
1654
|
+
// "mapping.generatedColumn" with "lastMapping"
|
1655
|
+
var nextLine = remainingLines[0];
|
1656
|
+
var code = nextLine.substr(0, mapping.generatedColumn -
|
1657
|
+
lastGeneratedColumn);
|
1658
|
+
remainingLines[0] = nextLine.substr(mapping.generatedColumn -
|
1659
|
+
lastGeneratedColumn);
|
1660
|
+
lastGeneratedColumn = mapping.generatedColumn;
|
1661
|
+
addMappingWithCode(lastMapping, code);
|
1662
|
+
}
|
1663
|
+
}
|
1664
|
+
lastMapping = mapping;
|
1665
|
+
}, this);
|
1666
|
+
// We have processed all mappings.
|
1667
|
+
// Associate the remaining code in the current line with "lastMapping"
|
1668
|
+
// and add the remaining lines without any mapping
|
1669
|
+
addMappingWithCode(lastMapping, remainingLines.join("\n"));
|
1670
|
+
|
1671
|
+
// Copy sourcesContent into SourceNode
|
1672
|
+
aSourceMapConsumer.sources.forEach(function (sourceFile) {
|
1673
|
+
var content = aSourceMapConsumer.sourceContentFor(sourceFile);
|
1674
|
+
if (content) {
|
1675
|
+
node.setSourceContent(sourceFile, content);
|
1676
|
+
}
|
1677
|
+
});
|
1678
|
+
|
1679
|
+
return node;
|
1680
|
+
|
1681
|
+
function addMappingWithCode(mapping, code) {
|
1682
|
+
if (mapping === null || mapping.source === undefined) {
|
1683
|
+
node.add(code);
|
1684
|
+
} else {
|
1685
|
+
node.add(new SourceNode(mapping.originalLine,
|
1686
|
+
mapping.originalColumn,
|
1687
|
+
mapping.source,
|
1688
|
+
code,
|
1689
|
+
mapping.name));
|
1690
|
+
}
|
1691
|
+
}
|
1692
|
+
};
|
1693
|
+
|
1694
|
+
/**
|
1695
|
+
* Add a chunk of generated JS to this source node.
|
1696
|
+
*
|
1697
|
+
* @param aChunk A string snippet of generated JS code, another instance of
|
1698
|
+
* SourceNode, or an array where each member is one of those things.
|
1699
|
+
*/
|
1700
|
+
SourceNode.prototype.add = function SourceNode_add(aChunk) {
|
1701
|
+
if (Array.isArray(aChunk)) {
|
1702
|
+
aChunk.forEach(function (chunk) {
|
1703
|
+
this.add(chunk);
|
1704
|
+
}, this);
|
1705
|
+
}
|
1706
|
+
else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
|
1707
|
+
if (aChunk) {
|
1708
|
+
this.children.push(aChunk);
|
1709
|
+
}
|
1710
|
+
}
|
1711
|
+
else {
|
1712
|
+
throw new TypeError(
|
1713
|
+
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
1714
|
+
);
|
1715
|
+
}
|
1716
|
+
return this;
|
1717
|
+
};
|
1718
|
+
|
1719
|
+
/**
|
1720
|
+
* Add a chunk of generated JS to the beginning of this source node.
|
1721
|
+
*
|
1722
|
+
* @param aChunk A string snippet of generated JS code, another instance of
|
1723
|
+
* SourceNode, or an array where each member is one of those things.
|
1724
|
+
*/
|
1725
|
+
SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
|
1726
|
+
if (Array.isArray(aChunk)) {
|
1727
|
+
for (var i = aChunk.length-1; i >= 0; i--) {
|
1728
|
+
this.prepend(aChunk[i]);
|
1729
|
+
}
|
1730
|
+
}
|
1731
|
+
else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
|
1732
|
+
this.children.unshift(aChunk);
|
1733
|
+
}
|
1734
|
+
else {
|
1735
|
+
throw new TypeError(
|
1736
|
+
"Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
|
1737
|
+
);
|
1738
|
+
}
|
1739
|
+
return this;
|
1740
|
+
};
|
1741
|
+
|
1742
|
+
/**
|
1743
|
+
* Walk over the tree of JS snippets in this node and its children. The
|
1744
|
+
* walking function is called once for each snippet of JS and is passed that
|
1745
|
+
* snippet and the its original associated source's line/column location.
|
1746
|
+
*
|
1747
|
+
* @param aFn The traversal function.
|
1748
|
+
*/
|
1749
|
+
SourceNode.prototype.walk = function SourceNode_walk(aFn) {
|
1750
|
+
var chunk;
|
1751
|
+
for (var i = 0, len = this.children.length; i < len; i++) {
|
1752
|
+
chunk = this.children[i];
|
1753
|
+
if (chunk instanceof SourceNode) {
|
1754
|
+
chunk.walk(aFn);
|
1755
|
+
}
|
1756
|
+
else {
|
1757
|
+
if (chunk !== '') {
|
1758
|
+
aFn(chunk, { source: this.source,
|
1759
|
+
line: this.line,
|
1760
|
+
column: this.column,
|
1761
|
+
name: this.name });
|
1762
|
+
}
|
1763
|
+
}
|
1764
|
+
}
|
1765
|
+
};
|
1766
|
+
|
1767
|
+
/**
|
1768
|
+
* Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
|
1769
|
+
* each of `this.children`.
|
1770
|
+
*
|
1771
|
+
* @param aSep The separator.
|
1772
|
+
*/
|
1773
|
+
SourceNode.prototype.join = function SourceNode_join(aSep) {
|
1774
|
+
var newChildren;
|
1775
|
+
var i;
|
1776
|
+
var len = this.children.length;
|
1777
|
+
if (len > 0) {
|
1778
|
+
newChildren = [];
|
1779
|
+
for (i = 0; i < len-1; i++) {
|
1780
|
+
newChildren.push(this.children[i]);
|
1781
|
+
newChildren.push(aSep);
|
1782
|
+
}
|
1783
|
+
newChildren.push(this.children[i]);
|
1784
|
+
this.children = newChildren;
|
1785
|
+
}
|
1786
|
+
return this;
|
1787
|
+
};
|
1788
|
+
|
1789
|
+
/**
|
1790
|
+
* Call String.prototype.replace on the very right-most source snippet. Useful
|
1791
|
+
* for trimming whitespace from the end of a source node, etc.
|
1792
|
+
*
|
1793
|
+
* @param aPattern The pattern to replace.
|
1794
|
+
* @param aReplacement The thing to replace the pattern with.
|
1795
|
+
*/
|
1796
|
+
SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
|
1797
|
+
var lastChild = this.children[this.children.length - 1];
|
1798
|
+
if (lastChild instanceof SourceNode) {
|
1799
|
+
lastChild.replaceRight(aPattern, aReplacement);
|
1800
|
+
}
|
1801
|
+
else if (typeof lastChild === 'string') {
|
1802
|
+
this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
|
1803
|
+
}
|
1804
|
+
else {
|
1805
|
+
this.children.push(''.replace(aPattern, aReplacement));
|
1806
|
+
}
|
1807
|
+
return this;
|
1808
|
+
};
|
1809
|
+
|
1810
|
+
/**
|
1811
|
+
* Set the source content for a source file. This will be added to the SourceMapGenerator
|
1812
|
+
* in the sourcesContent field.
|
1813
|
+
*
|
1814
|
+
* @param aSourceFile The filename of the source file
|
1815
|
+
* @param aSourceContent The content of the source file
|
1816
|
+
*/
|
1817
|
+
SourceNode.prototype.setSourceContent =
|
1818
|
+
function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
|
1819
|
+
this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
|
1820
|
+
};
|
1821
|
+
|
1822
|
+
/**
|
1823
|
+
* Walk over the tree of SourceNodes. The walking function is called for each
|
1824
|
+
* source file content and is passed the filename and source content.
|
1825
|
+
*
|
1826
|
+
* @param aFn The traversal function.
|
1827
|
+
*/
|
1828
|
+
SourceNode.prototype.walkSourceContents =
|
1829
|
+
function SourceNode_walkSourceContents(aFn) {
|
1830
|
+
for (var i = 0, len = this.children.length; i < len; i++) {
|
1831
|
+
if (this.children[i] instanceof SourceNode) {
|
1832
|
+
this.children[i].walkSourceContents(aFn);
|
1833
|
+
}
|
1834
|
+
}
|
1835
|
+
|
1836
|
+
var sources = Object.keys(this.sourceContents);
|
1837
|
+
for (var i = 0, len = sources.length; i < len; i++) {
|
1838
|
+
aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
|
1839
|
+
}
|
1840
|
+
};
|
1841
|
+
|
1842
|
+
/**
|
1843
|
+
* Return the string representation of this source node. Walks over the tree
|
1844
|
+
* and concatenates all the various snippets together to one string.
|
1845
|
+
*/
|
1846
|
+
SourceNode.prototype.toString = function SourceNode_toString() {
|
1847
|
+
var str = "";
|
1848
|
+
this.walk(function (chunk) {
|
1849
|
+
str += chunk;
|
1850
|
+
});
|
1851
|
+
return str;
|
1852
|
+
};
|
1853
|
+
|
1854
|
+
/**
|
1855
|
+
* Returns the string representation of this source node along with a source
|
1856
|
+
* map.
|
1857
|
+
*/
|
1858
|
+
SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
|
1859
|
+
var generated = {
|
1860
|
+
code: "",
|
1861
|
+
line: 1,
|
1862
|
+
column: 0
|
1863
|
+
};
|
1864
|
+
var map = new SourceMapGenerator(aArgs);
|
1865
|
+
var sourceMappingActive = false;
|
1866
|
+
var lastOriginalSource = null;
|
1867
|
+
var lastOriginalLine = null;
|
1868
|
+
var lastOriginalColumn = null;
|
1869
|
+
var lastOriginalName = null;
|
1870
|
+
this.walk(function (chunk, original) {
|
1871
|
+
generated.code += chunk;
|
1872
|
+
if (original.source !== null
|
1873
|
+
&& original.line !== null
|
1874
|
+
&& original.column !== null) {
|
1875
|
+
if(lastOriginalSource !== original.source
|
1876
|
+
|| lastOriginalLine !== original.line
|
1877
|
+
|| lastOriginalColumn !== original.column
|
1878
|
+
|| lastOriginalName !== original.name) {
|
1879
|
+
map.addMapping({
|
1880
|
+
source: original.source,
|
1881
|
+
original: {
|
1882
|
+
line: original.line,
|
1883
|
+
column: original.column
|
1884
|
+
},
|
1885
|
+
generated: {
|
1886
|
+
line: generated.line,
|
1887
|
+
column: generated.column
|
1888
|
+
},
|
1889
|
+
name: original.name
|
1890
|
+
});
|
1891
|
+
}
|
1892
|
+
lastOriginalSource = original.source;
|
1893
|
+
lastOriginalLine = original.line;
|
1894
|
+
lastOriginalColumn = original.column;
|
1895
|
+
lastOriginalName = original.name;
|
1896
|
+
sourceMappingActive = true;
|
1897
|
+
} else if (sourceMappingActive) {
|
1898
|
+
map.addMapping({
|
1899
|
+
generated: {
|
1900
|
+
line: generated.line,
|
1901
|
+
column: generated.column
|
1902
|
+
}
|
1903
|
+
});
|
1904
|
+
lastOriginalSource = null;
|
1905
|
+
sourceMappingActive = false;
|
1906
|
+
}
|
1907
|
+
chunk.split('').forEach(function (ch) {
|
1908
|
+
if (ch === '\n') {
|
1909
|
+
generated.line++;
|
1910
|
+
generated.column = 0;
|
1911
|
+
} else {
|
1912
|
+
generated.column++;
|
1913
|
+
}
|
1914
|
+
});
|
1915
|
+
});
|
1916
|
+
this.walkSourceContents(function (sourceFile, sourceContent) {
|
1917
|
+
map.setSourceContent(sourceFile, sourceContent);
|
1918
|
+
});
|
1919
|
+
|
1920
|
+
return { code: generated.code, map: map };
|
1921
|
+
};
|
1922
|
+
|
1923
|
+
exports.SourceNode = SourceNode;
|
1924
|
+
|
1925
|
+
});
|
1926
|
+
/* -*- Mode: js; js-indent-level: 2; -*- */
|
1927
|
+
///////////////////////////////////////////////////////////////////////////////
|
1928
|
+
|
1929
|
+
this.sourceMap = {
|
1930
|
+
SourceMapConsumer: require('source-map/source-map-consumer').SourceMapConsumer,
|
1931
|
+
SourceMapGenerator: require('source-map/source-map-generator').SourceMapGenerator,
|
1932
|
+
SourceNode: require('source-map/source-node').SourceNode
|
1933
|
+
};
|