Skip to content

Commit

Permalink
DevTools: fix CSS sourcemap to be populated for multilpe sourcemaps s…
Browse files Browse the repository at this point in the history
…cenario

This patch fixes multiple issues:
- there is a bug in SASSSourceMapping which adds sources only for the
  one sourcemap in frame
- there was another bug in SourceMapManager which handled enabling/disabling
  wrong.

BUG=none
R=dgozman

Review-Url: https://codereview.chromium.org/2787963002
Cr-Commit-Position: refs/heads/master@{#460947}
  • Loading branch information
aslushnikov authored and Commit bot committed Mar 31, 2017
1 parent 46c3768 commit 629abaa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
25 changes: 18 additions & 7 deletions front_end/bindings/SASSSourceMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Bindings.SASSSourceMapping = class {
];

/** @type {!Multimap<string, !SDK.CSSStyleSheetHeader>} */
this._frameIdToHeaders = new Multimap();
this._sourceMapIdToHeaders = new Multimap();
}

/**
Expand All @@ -60,18 +60,28 @@ Bindings.SASSSourceMapping = class {
_sourceMapAttachedForTest(sourceMap) {
}

/**
* @param {string} frameId
* @param {string} sourceMapURL
* @return {string}
*/
static _sourceMapId(frameId, sourceMapURL) {
return frameId + ':' + sourceMapURL;
}

/**
* @param {!Common.Event} event
*/
_sourceMapAttached(event) {
var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client);
var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
if (this._frameIdToHeaders.has(header.frameId)) {
this._frameIdToHeaders.set(header.frameId, header);
var sourceMapId = Bindings.SASSSourceMapping._sourceMapId(header.frameId, sourceMap.url());
if (this._sourceMapIdToHeaders.has(sourceMapId)) {
this._sourceMapIdToHeaders.set(sourceMapId, header);
this._sourceMapAttachedForTest(sourceMap);
return;
}
this._frameIdToHeaders.set(header.frameId, header);
this._sourceMapIdToHeaders.set(sourceMapId, header);

for (var sassURL of sourceMap.sourceURLs()) {
var contentProvider = sourceMap.sourceContentProvider(sassURL, Common.resourceTypes.SourceMapStyleSheet);
Expand All @@ -88,10 +98,11 @@ Bindings.SASSSourceMapping = class {
*/
_sourceMapDetached(event) {
var header = /** @type {!SDK.CSSStyleSheetHeader} */ (event.data.client);
this._frameIdToHeaders.remove(header.frameId, header);
if (this._frameIdToHeaders.has(header.frameId))
return;
var sourceMap = /** @type {!SDK.SourceMap} */ (event.data.sourceMap);
var sourceMapId = Bindings.SASSSourceMapping._sourceMapId(header.frameId, sourceMap.url());
this._sourceMapIdToHeaders.remove(sourceMapId, header);
if (this._sourceMapIdToHeaders.has(sourceMapId))
return;
for (var sassURL of sourceMap.sourceURLs())
this._networkProject.removeSourceMapFile(sassURL, header.frameId, false);
Bindings.cssWorkspaceBinding.updateLocations(header);
Expand Down
3 changes: 1 addition & 2 deletions front_end/sdk/SourceMapManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ SDK.SourceMapManager = class extends SDK.SDKObject {
var relativeSourceURL = this._relativeSourceURL.get(client);
var relativeSourceMapURL = this._relativeSourceMapURL.get(client);
this.detachSourceMap(client);
if (isEnabled)
this.attachSourceMap(client, relativeSourceURL, relativeSourceMapURL);
this.attachSourceMap(client, relativeSourceURL, relativeSourceMapURL);
}
}

Expand Down

0 comments on commit 629abaa

Please sign in to comment.