Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/react-dev-utils/webpackHotDevClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,31 @@ function ensureOverlayDivExists(onOverlayDivReady) {
document.body.appendChild(overlayIframe);
}

/**
* Optionnaly decorate the html output with links to
* @param {Element} node an div that contains error trace
*/
function decorateErrorsWithEditorLink(node) {

var editorLinkPattern = "subl://open?url=%%f&line=%%l&column=%%c";
var url, m;
var createLink = function (url, line, column) {
line = line || 1;
column = column || 1;
return editorLinkPattern.replace('%%f', 'file://'+url).replace('%%l', line).replace('%%c', column);
};

[].forEach.call(node.childNodes, function (element) {
if (element.tagName === "U") {
url = element.innerHTML;
element.innerHTML = '<a style="color:white" href="' + createLink(url) + '">' + url + '</a>';
} else if (element.tagName === "SPAN" && element.innerHTML.match(/\d+:\d+/)) {
m = element.innerHTML.match(/(\d+):(\d+)/);
element.innerHTML = '<a style="color:white" href="' + createLink(url, m[1], m[2]) + '">' + element.innerHTML + '</a>';
}
});
}

function showErrorOverlay(message) {
ensureOverlayDivExists(function onOverlayDivReady(overlayDiv) {
// Make it look similar to our terminal.
Expand All @@ -120,9 +145,11 @@ function showErrorOverlay(message) {
colors.red +
'">Failed to compile.</span><br><br>' +
ansiHTML(entities.encode(message));
decorateErrorsWithEditorLink(overlayDiv);
});
}


function destroyErrorOverlay() {
if (!overlayDiv) {
// It is not there in the first place.
Expand Down