Skip to content

Commit b79a62d

Browse files
committed
[fix] Maximum call stack size exceeded (#4694)
1 parent c040f13 commit b79a62d

File tree

7 files changed

+24
-7
lines changed

7 files changed

+24
-7
lines changed

src/compiler/compile/css/Stylesheet.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { push_array } from '../../utils/push_array';
12
import MagicString from 'magic-string';
23
import { walk } from 'estree-walker';
34
import Selector from './Selector';
@@ -351,7 +352,7 @@ export default class Stylesheet {
351352
const at_rule_declarations = node.block.children
352353
.filter(node => node.type === 'Declaration')
353354
.map(node => new Declaration(node));
354-
atrule.declarations.push(...at_rule_declarations);
355+
push_array(atrule.declarations,at_rule_declarations);
355356
}
356357

357358
current_atrule = atrule;

src/compiler/compile/nodes/shared/map_children.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { push_array } from '../../../utils/push_array';
12
import AwaitBlock from '../AwaitBlock';
23
import Body from '../Body';
34
import Comment from '../Comment';
@@ -58,7 +59,7 @@ export default function map_children(component, parent, scope, children: Templat
5859
if (use_ignores) component.pop_ignores(), ignores = [];
5960

6061
if (node.type === 'Comment' && node.ignores.length) {
61-
ignores.push(...node.ignores);
62+
push_array(ignores,node.ignores);
6263
}
6364

6465
if (last) last.next = node;

src/compiler/compile/render_dom/wrappers/Element/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { push_array } from '../../../../utils/push_array';
12
import Renderer from '../../Renderer';
23
import Element from '../../../nodes/Element';
34
import Wrapper from '../shared/Wrapper';
@@ -596,7 +597,7 @@ export default class ElementWrapper extends Wrapper {
596597
this.attributes.forEach((attribute) => {
597598
if (attribute.node.name === 'class') {
598599
const dependencies = attribute.node.get_dependencies();
599-
this.class_dependencies.push(...dependencies);
600+
push_array(this.class_dependencies,dependencies);
600601
}
601602
});
602603

src/compiler/compile/render_dom/wrappers/IfBlock.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { push_array } from '../../../utils/push_array';
12
import Wrapper from './shared/Wrapper';
23
import Renderer from '../Renderer';
34
import Block from '../Block';
@@ -166,7 +167,7 @@ export default class IfBlockWrapper extends Wrapper {
166167
block.has_outro_method = has_outros;
167168
});
168169

169-
renderer.blocks.push(...blocks);
170+
push_array(renderer.blocks,blocks);
170171
}
171172

172173
render(

src/compiler/preprocess/decode_sourcemap.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { push_array } from '../utils/push_array';
12
import { decode as decode_mappings } from 'sourcemap-codec';
23
import { Processed } from './types';
34

@@ -50,7 +51,7 @@ function decoded_sourcemap_from_generator(generator: any) {
5051
result_segment = result_line[result_line.length - 1];
5152

5253
if (mapping.source != null) {
53-
result_segment.push(...[
54+
push_array(result_segment,[
5455
source_idx[mapping.source],
5556
mapping.originalLine - 1, // line is one-based
5657
mapping.originalColumn

src/compiler/preprocess/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { push_array } from '../utils/push_array';
12
import { RawSourceMap, DecodedSourceMap } from '@ampproject/remapping/dist/types/types';
23
import { getLocator } from 'locate-character';
34
import { MappedCode, SourceLocation, parse_attached_sourcemap, sourcemap_add_offset, combine_sourcemaps } from '../utils/mapped_code';
@@ -48,7 +49,7 @@ class PreprocessResult implements Source {
4849
}
4950

5051
if (dependencies) {
51-
this.dependencies.push(...dependencies);
52+
push_array(this.dependencies,dependencies);
5253
}
5354
}
5455

@@ -165,7 +166,7 @@ async function process_tag(
165166
});
166167

167168
if (!processed) return no_change();
168-
if (processed.dependencies) dependencies.push(...processed.dependencies);
169+
if (processed.dependencies) push_array(dependencies,processed.dependencies);
169170
if (!processed.map && processed.code === content) return no_change();
170171

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

src/compiler/utils/push_array.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function push_array(thisArray: any[], ...otherList: any[]) {
2+
let count = 0;
3+
for (let a = 0; a < otherList.length; a++) {
4+
const other = otherList[a];
5+
for (let i = 0; i < other.length; i++) {
6+
thisArray.push(other[i]);
7+
}
8+
count += other.length;
9+
}
10+
return count;
11+
}

0 commit comments

Comments
 (0)