Skip to content

Commit 7597e20

Browse files
committed
fix: Maximum call stack size exceeded (#4694)
1 parent 4f9a260 commit 7597e20

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

src/compiler/compile/css/Stylesheet.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// TODO move pushArray to npm module
2+
function pushArray(thisArray: any[], ...otherList: any[]) {
3+
let count = 0;
4+
for (let a = 0; a < otherList.length; a++) {
5+
const other = otherList[a];
6+
for (let i = 0; i < other.length; i++) {
7+
thisArray.push(other[i]);
8+
}
9+
count += other.length;
10+
}
11+
return count;
12+
}
13+
14+
115
import MagicString from 'magic-string';
216
import { walk } from 'estree-walker';
317
import Selector from './Selector';
@@ -351,7 +365,7 @@ export default class Stylesheet {
351365
const at_rule_declarations = node.block.children
352366
.filter(node => node.type === 'Declaration')
353367
.map(node => new Declaration(node));
354-
atrule.declarations.push(...at_rule_declarations);
368+
pushArray(atrule.declarations,at_rule_declarations);
355369
}
356370

357371
current_atrule = atrule;

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// TODO move pushArray to npm module
2+
function pushArray(thisArray: any[], ...otherList: any[]) {
3+
let count = 0;
4+
for (let a = 0; a < otherList.length; a++) {
5+
const other = otherList[a];
6+
for (let i = 0; i < other.length; i++) {
7+
thisArray.push(other[i]);
8+
}
9+
count += other.length;
10+
}
11+
return count;
12+
}
13+
14+
115
import Renderer from '../../Renderer';
216
import Element from '../../../nodes/Element';
317
import Wrapper from '../shared/Wrapper';
@@ -596,7 +610,7 @@ export default class ElementWrapper extends Wrapper {
596610
this.attributes.forEach((attribute) => {
597611
if (attribute.node.name === 'class') {
598612
const dependencies = attribute.node.get_dependencies();
599-
this.class_dependencies.push(...dependencies);
613+
pushArray(this.class_dependencies,dependencies);
600614
}
601615
});
602616

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// TODO move pushArray to npm module
2+
function pushArray(thisArray: any[], ...otherList: any[]) {
3+
let count = 0;
4+
for (let a = 0; a < otherList.length; a++) {
5+
const other = otherList[a];
6+
for (let i = 0; i < other.length; i++) {
7+
thisArray.push(other[i]);
8+
}
9+
count += other.length;
10+
}
11+
return count;
12+
}
13+
14+
115
import Wrapper from './shared/Wrapper';
216
import Renderer from '../Renderer';
317
import Block from '../Block';
@@ -166,7 +180,7 @@ export default class IfBlockWrapper extends Wrapper {
166180
block.has_outro_method = has_outros;
167181
});
168182

169-
renderer.blocks.push(...blocks);
183+
pushArray(renderer.blocks,blocks);
170184
}
171185

172186
render(

src/compiler/preprocess/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// TODO move pushArray to npm module
2+
function pushArray(thisArray: any[], ...otherList: any[]) {
3+
let count = 0;
4+
for (let a = 0; a < otherList.length; a++) {
5+
const other = otherList[a];
6+
for (let i = 0; i < other.length; i++) {
7+
thisArray.push(other[i]);
8+
}
9+
count += other.length;
10+
}
11+
return count;
12+
}
13+
14+
115
import { RawSourceMap, DecodedSourceMap } from '@ampproject/remapping/dist/types/types';
216
import { getLocator } from 'locate-character';
317
import { MappedCode, SourceLocation, parse_attached_sourcemap, sourcemap_add_offset, combine_sourcemaps } from '../utils/mapped_code';
@@ -48,7 +62,7 @@ class PreprocessResult implements Source {
4862
}
4963

5064
if (dependencies) {
51-
this.dependencies.push(...dependencies);
65+
pushArray(this.dependencies,dependencies);
5266
}
5367
}
5468

@@ -165,7 +179,7 @@ async function process_tag(
165179
});
166180

167181
if (!processed) return no_change();
168-
if (processed.dependencies) dependencies.push(...processed.dependencies);
182+
if (processed.dependencies) pushArray(dependencies,processed.dependencies);
169183
if (!processed.map && processed.code === content) return no_change();
170184

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

0 commit comments

Comments
 (0)