Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import * as React from 'react';
Expand All @@ -26,10 +27,14 @@ function checkConditions(
try {
const url = new URL(editorURL);

let [, sourceURL, ,] = source;
const [, sourceURL, line] = source;
let filePath;

// Check if sourceURL is a correct URL, which has a protocol specified
if (sourceURL.includes('://')) {
if (sourceURL.startsWith('file:///')) {
filePath = new URL(sourceURL).pathname;
} else if (sourceURL.includes('://')) {
// $FlowFixMe[cannot-resolve-name]
if (!__IS_INTERNAL_VERSION__) {
// In this case, we can't really determine the path to a file, disable a button
return {url: null, shouldDisableButton: true};
Expand All @@ -42,20 +47,22 @@ function checkConditions(
if (endOfSourceMapURLIndex === -1) {
return {url: null, shouldDisableButton: true};
} else {
sourceURL = sourceURL.slice(
filePath = sourceURL.slice(
endOfSourceMapURLIndex + endOfSourceMapURLPattern.length,
sourceURL.length,
);
}
}
} else {
filePath = sourceURL;
}

const lineNumberAsString = String(source.line);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this in the previous PR because this file wasn't flow checked.

const lineNumberAsString = String(line);

url.href = url.href
.replace('{path}', sourceURL)
.replace('{path}', filePath)
.replace('{line}', lineNumberAsString)
.replace('%7Bpath%7D', sourceURL)
.replace('%7Bpath%7D', filePath)
.replace('%7Bline%7D', lineNumberAsString);

return {url, shouldDisableButton: false};
Expand Down
Loading