Fix #5378, stack overflow on large files (#5380)

This commit is contained in:
Geoffrey Booth 2021-10-02 16:24:32 -07:00 committed by GitHub
parent e82de9c0f6
commit d572d744eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 21 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -723,7 +723,7 @@
// better not to generate them in the first place, but for now, clean up
// obvious double-parentheses.
compileNode(o) {
var fragments, parts;
var fragments, functionKeyword;
o.indent = o.bare ? '' : TAB;
o.level = LEVEL_TOP;
o.compiling = true;
@ -732,15 +732,8 @@
if (o.bare) {
return fragments;
}
parts = [];
parts.push(this.makeCode('('));
if (this.isAsync) {
parts.push(this.makeCode('async '));
}
parts.push(this.makeCode('function() {\n'));
parts.push(...fragments);
parts.push(this.makeCode('\n}).call(this);\n'));
return [].concat(...parts);
functionKeyword = `${this.isAsync ? 'async ' : ''}function`;
return [].concat(this.makeCode(`(${functionKeyword}() {\n`), fragments, this.makeCode("\n}).call(this);\n"));
}
initializeScope(o) {

View File

@ -528,13 +528,8 @@ exports.Root = class Root extends Base
@initializeScope o
fragments = @body.compileRoot o
return fragments if o.bare
parts = []
parts.push @makeCode '('
parts.push @makeCode 'async ' if @isAsync
parts.push @makeCode 'function() {\n'
parts.push ...fragments
parts.push @makeCode '\n}).call(this);\n'
[].concat ...parts
functionKeyword = "#{if @isAsync then 'async ' else ''}function"
[].concat @makeCode("(#{functionKeyword}() {\n"), fragments, @makeCode("\n}).call(this);\n")
initializeScope: (o) ->
o.scope = new Scope null, @body, null, o.referencedVars ? []