Skip to content

Commit 7a479ec

Browse files
committed
handle empty source maps
1 parent be2d4d0 commit 7a479ec

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

code.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,6 @@
480480
const originalName = index => sm.names[index];
481481
originalTextArea = null;
482482
if (sm.sources.length > 0) {
483-
fileList.selectedIndex = 0;
484483
const updateOriginalSource = () => {
485484
const source = sm.sources[fileList.selectedIndex];
486485
originalTextArea = createTextArea({
@@ -503,7 +502,13 @@
503502
};
504503
fileList.onchange = updateOriginalSource;
505504
updateOriginalSource();
505+
} else {
506+
const option = document.createElement('option');
507+
option.textContent = `(no original code)`;
508+
option.disabled = true;
509+
fileList.appendChild(option);
506510
}
511+
fileList.selectedIndex = 0;
507512

508513
generatedTextArea = createTextArea({
509514
sourceIndex: null,
@@ -1377,18 +1382,18 @@
13771382
isInvalid = false;
13781383

13791384
c.clearRect(0, 0, innerWidth, innerHeight);
1380-
if (!originalTextArea || !generatedTextArea) return;
1385+
if (!generatedTextArea) return;
13811386

13821387
const bodyStyle = getComputedStyle(document.body);
1383-
originalTextArea.draw(bodyStyle);
1388+
if (originalTextArea) originalTextArea.draw(bodyStyle);
13841389
generatedTextArea.draw(bodyStyle);
13851390

13861391
// Draw the splitter
13871392
c.fillStyle = 'rgba(127, 127, 127, 0.2)';
13881393
c.fillRect((innerWidth >>> 1) - (splitterWidth >> 1), toolbarHeight, splitterWidth, innerHeight - toolbarHeight - statusBarHeight);
13891394

13901395
// Draw the arrow between the two hover areas
1391-
if (hover && hover.mapping && originalTextArea.sourceIndex === hover.mapping.originalSource) {
1396+
if (hover && hover.mapping && originalTextArea && originalTextArea.sourceIndex === hover.mapping.originalSource) {
13921397
const originalHoverRect = originalTextArea.getHoverRect();
13931398
const generatedHoverRect = generatedTextArea.getHoverRect();
13941399
if (originalHoverRect && generatedHoverRect) {

0 commit comments

Comments
 (0)