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

fix: max stack call error is caught on locate #4160

Merged
merged 1 commit into from Jul 1, 2021
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
37 changes: 20 additions & 17 deletions src/Module.ts
Expand Up @@ -947,24 +947,27 @@ export default class Module {
props.id = this.id;
props.pos = pos;
let code = this.info.code;
let { column, line } = locate(code!, pos, { offsetLine: 1 });
try {
({ column, line } = getOriginalLocation(this.sourcemapChain, { column, line }));
code = this.originalCode;
} catch (e) {
this.options.onwarn({
code: 'SOURCEMAP_ERROR',
id: this.id,
loc: {
column,
file: this.id,
line
},
message: `Error when using sourcemap for reporting an error: ${e.message}`,
pos
});
const location = locate(code!, pos, { offsetLine: 1 });
if (location) {
let { column, line } = location;
try {
({ column, line } = getOriginalLocation(this.sourcemapChain, { column, line }));
code = this.originalCode;
} catch (e) {
this.options.onwarn({
code: 'SOURCEMAP_ERROR',
id: this.id,
loc: {
column,
file: this.id,
line
},
message: `Error when using sourcemap for reporting an error: ${e.message}`,
pos
});
}
augmentCodeLocation(props, { column, line }, code!, this.id);
}
augmentCodeLocation(props, { column, line }, code!, this.id);
}

private addModulesToImportDescriptions(importDescription: {
Expand Down
26 changes: 26 additions & 0 deletions test/misc/misc.js
Expand Up @@ -242,4 +242,30 @@ console.log(x);
assert.strictEqual(subfeature.fileName, 'base/main/feature/sub');
assert.ok(subfeature.code.startsWith("import { fn } from '../../main'"));
});

it('throws the proper error on max call stack exception', async () => {
const count = 10000;
let source = '';
for (let i = 0; i < count; i++) {
source += `if (foo) {`;
}
for (let i = 0; i < count; i++) {
source += '}';
}
try {
await rollup.rollup({
input: {
input: 'input'
},
plugins: [
loader({
input: source
})
]
});
} catch (err) {
assert.notDeepStrictEqual(err.message, 'Maximum call stack size exceeded');
assert.strictEqual(err.name, 'Error');
}
});
});