Skip to content

Commit

Permalink
fix: max stack call error is caught on locate (#4160)
Browse files Browse the repository at this point in the history
  • Loading branch information
semoal committed Jul 1, 2021
1 parent c3ad218 commit a632d50
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 17 deletions.
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');
}
});
});

0 comments on commit a632d50

Please sign in to comment.