Skip to content

Commit

Permalink
Do not fail if the location of a warning is outside the original sour…
Browse files Browse the repository at this point in the history
…ce (#4922)

* Do not fail if the location of a warning is outside the original source

* Fix comparison
  • Loading branch information
lukastaegert committed Mar 24, 2023
1 parent b6c4fd8 commit 1517d03
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/utils/getCodeFrame.ts
Expand Up @@ -14,6 +14,8 @@ const ELLIPSIS = '...';

export default function getCodeFrame(source: string, line: number, column: number): string {
let lines = source.split('\n');
// Needed if a plugin did not generate correct sourcemaps
if (line > lines.length) return '';
const maxLineLength = Math.max(
tabsToSpaces(lines[line - 1].slice(0, column)).length +
MIN_CHARACTERS_SHOWN_AFTER_LOCATION +
Expand Down
@@ -0,0 +1,34 @@
const { join } = require('node:path');
const ID_MAIN = join(__dirname, 'main.js');
const ID_CONSTANTS = join(__dirname, 'constants.js');

module.exports = {
description: 'does not fail if a warning has an incorrect location due to missing sourcemaps',
options: {
plugins: [
{
name: 'test',
transform(code) {
return '/* injected */;\n\n\n\n\n\n\n\n' + code;
}
}
]
},
warnings: [
{
binding: 'NON_EXISTENT',
code: 'MISSING_EXPORT',
exporter: ID_CONSTANTS,
frame: '',
id: ID_MAIN,
loc: {
column: 15,
file: ID_MAIN,
line: 12
},
message: '"NON_EXISTENT" is not exported by "constants.js", imported by "main.js".',
pos: 111,
url: 'https://rollupjs.org/troubleshooting/#error-name-is-not-exported-by-module'
}
]
};
@@ -0,0 +1 @@
export const q = 'Queue';
@@ -0,0 +1,5 @@
import * as CONSTANTS from './constants';

export default class Sample {
x = CONSTANTS.NON_EXISTENT;
}

0 comments on commit 1517d03

Please sign in to comment.