Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}