1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 * An object of this type represents an original source for the style
9 * editor. An "original" source is one that is mentioned in a source
13 * The URL of the original source.
14 * @param {String} sourceID
15 * The source ID of the original source, as used by the source
17 * @param {SourceMapLoader} sourceMapLoader
18 * The source map loader; @see Toolbox.sourceMapLoader
20 function OriginalSource(url
, sourceId
, sourceMapLoader
) {
21 this.isOriginalSource
= true;
24 this._sourceId
= sourceId
;
25 this._sourceMapLoader
= sourceMapLoader
;
28 OriginalSource
.prototype = {
30 return this._sourceId
;
33 /** Get the original source's URL. */
38 /** Get the original source's URL. */
44 * Return a promise that will resolve to the original source's full
45 * text. The return result is actually an object with a single
46 * `string` method; this method will return the source text as a
47 * string. This is done because the style editor elsewhere expects
48 * a long string actor.
51 if (!this._sourcePromise
) {
52 this._sourcePromise
= this._sourceMapLoader
53 .getOriginalSourceText(this._sourceId
)
55 // Make it look like a long string actor.
57 string
: () => contents
.text
,
61 return this._sourcePromise
;
65 * Given a source-mapped, generated style sheet, a line, and a
66 * column, return the corresponding original location in this style
69 * @param {StyleSheetResource} relatedSheet
70 * The generated style sheet's resource
71 * @param {Number} line
73 * @param {Number} column
76 * The original location, an object with at least
77 * `sourceUrl`, `source`, `styleSheet`, `line`, and `column`
80 getOriginalLocation(relatedSheet
, line
, column
) {
81 const { href
, nodeHref
, resourceId
: sourceId
} = relatedSheet
;
82 const sourceUrl
= href
|| nodeHref
;
83 return this._sourceMapLoader
84 .getOriginalLocation({
91 // Add some properties for the style editor.
92 location
.source
= location
.sourceUrl
;
93 location
.styleSheet
= relatedSheet
;
98 // Dummy implementations, as we never emit an event.
103 exports
.OriginalSource
= OriginalSource
;