Skip to content

Commit

Permalink
fix: Maximum call stack size exceeded (sveltejs#4694)
Browse files Browse the repository at this point in the history
  • Loading branch information
milahu committed Sep 10, 2021
1 parent 4f9a260 commit 7597e20
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 5 deletions.
16 changes: 15 additions & 1 deletion src/compiler/compile/css/Stylesheet.ts
@@ -1,3 +1,17 @@
// TODO move pushArray to npm module
function pushArray(thisArray: any[], ...otherList: any[]) {
let count = 0;
for (let a = 0; a < otherList.length; a++) {
const other = otherList[a];
for (let i = 0; i < other.length; i++) {
thisArray.push(other[i]);
}
count += other.length;
}
return count;
}


import MagicString from 'magic-string';
import { walk } from 'estree-walker';
import Selector from './Selector';
Expand Down Expand Up @@ -351,7 +365,7 @@ export default class Stylesheet {
const at_rule_declarations = node.block.children
.filter(node => node.type === 'Declaration')
.map(node => new Declaration(node));
atrule.declarations.push(...at_rule_declarations);
pushArray(atrule.declarations,at_rule_declarations);
}

current_atrule = atrule;
Expand Down
16 changes: 15 additions & 1 deletion src/compiler/compile/render_dom/wrappers/Element/index.ts
@@ -1,3 +1,17 @@
// TODO move pushArray to npm module
function pushArray(thisArray: any[], ...otherList: any[]) {
let count = 0;
for (let a = 0; a < otherList.length; a++) {
const other = otherList[a];
for (let i = 0; i < other.length; i++) {
thisArray.push(other[i]);
}
count += other.length;
}
return count;
}


import Renderer from '../../Renderer';
import Element from '../../../nodes/Element';
import Wrapper from '../shared/Wrapper';
Expand Down Expand Up @@ -596,7 +610,7 @@ export default class ElementWrapper extends Wrapper {
this.attributes.forEach((attribute) => {
if (attribute.node.name === 'class') {
const dependencies = attribute.node.get_dependencies();
this.class_dependencies.push(...dependencies);
pushArray(this.class_dependencies,dependencies);
}
});

Expand Down
16 changes: 15 additions & 1 deletion src/compiler/compile/render_dom/wrappers/IfBlock.ts
@@ -1,3 +1,17 @@
// TODO move pushArray to npm module
function pushArray(thisArray: any[], ...otherList: any[]) {
let count = 0;
for (let a = 0; a < otherList.length; a++) {
const other = otherList[a];
for (let i = 0; i < other.length; i++) {
thisArray.push(other[i]);
}
count += other.length;
}
return count;
}


import Wrapper from './shared/Wrapper';
import Renderer from '../Renderer';
import Block from '../Block';
Expand Down Expand Up @@ -166,7 +180,7 @@ export default class IfBlockWrapper extends Wrapper {
block.has_outro_method = has_outros;
});

renderer.blocks.push(...blocks);
pushArray(renderer.blocks,blocks);
}

render(
Expand Down
18 changes: 16 additions & 2 deletions src/compiler/preprocess/index.ts
@@ -1,3 +1,17 @@
// TODO move pushArray to npm module
function pushArray(thisArray: any[], ...otherList: any[]) {
let count = 0;
for (let a = 0; a < otherList.length; a++) {
const other = otherList[a];
for (let i = 0; i < other.length; i++) {
thisArray.push(other[i]);
}
count += other.length;
}
return count;
}


import { RawSourceMap, DecodedSourceMap } from '@ampproject/remapping/dist/types/types';
import { getLocator } from 'locate-character';
import { MappedCode, SourceLocation, parse_attached_sourcemap, sourcemap_add_offset, combine_sourcemaps } from '../utils/mapped_code';
Expand Down Expand Up @@ -48,7 +62,7 @@ class PreprocessResult implements Source {
}

if (dependencies) {
this.dependencies.push(...dependencies);
pushArray(this.dependencies,dependencies);
}
}

Expand Down Expand Up @@ -165,7 +179,7 @@ async function process_tag(
});

if (!processed) return no_change();
if (processed.dependencies) dependencies.push(...processed.dependencies);
if (processed.dependencies) pushArray(dependencies,processed.dependencies);
if (!processed.map && processed.code === content) return no_change();

return processed_tag_to_code(processed, tag_name, attributes, slice_source(content, tag_offset, source));
Expand Down

0 comments on commit 7597e20

Please sign in to comment.