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 6, 2021
1 parent 4f9a260 commit 2c84484
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 7 deletions.
24 changes: 23 additions & 1 deletion src/compiler/compile/css/Stylesheet.ts
@@ -1,3 +1,25 @@
// push-array.ts start
// TODO move pushArray to npm module
//export{}
//declare global {
// interface Array<T> {
// pushArray(...otherList: any[]): number;
// }
//}
(Array.prototype as any).pushArray = function pushArray(...otherList: any[]) {
let c = 0; // count pushed elements
for (let a = 0; a < otherList.length; a++) {
const other = otherList[a];
for (let i = 0; i < other.length; i++) {
this.push(other[i]);
c++;
}
}
return c;
};
// push-array.ts end


import MagicString from 'magic-string';
import { walk } from 'estree-walker';
import Selector from './Selector';
Expand Down Expand Up @@ -351,7 +373,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);
atrule.declarations.pushArray(at_rule_declarations);
}

current_atrule = atrule;
Expand Down
24 changes: 23 additions & 1 deletion src/compiler/compile/nodes/shared/map_children.ts
@@ -1,3 +1,25 @@
// push-array.ts start
// TODO move pushArray to npm module
//export{}
//declare global {
// interface Array<T> {
// pushArray(...otherList: any[]): number;
// }
//}
(Array.prototype as any).pushArray = function pushArray(...otherList: any[]) {
let c = 0; // count pushed elements
for (let a = 0; a < otherList.length; a++) {
const other = otherList[a];
for (let i = 0; i < other.length; i++) {
this.push(other[i]);
c++;
}
}
return c;
};
// push-array.ts end


import AwaitBlock from '../AwaitBlock';
import Body from '../Body';
import Comment from '../Comment';
Expand Down Expand Up @@ -58,7 +80,7 @@ export default function map_children(component, parent, scope, children: Templat
if (use_ignores) component.pop_ignores(), ignores = [];

if (node.type === 'Comment' && node.ignores.length) {
ignores.push(...node.ignores);
ignores.pushArray(node.ignores);
}

if (last) last.next = node;
Expand Down
24 changes: 23 additions & 1 deletion src/compiler/compile/render_dom/wrappers/Element/index.ts
@@ -1,3 +1,25 @@
// push-array.ts start
// TODO move pushArray to npm module
//export{}
//declare global {
// interface Array<T> {
// pushArray(...otherList: any[]): number;
// }
//}
(Array.prototype as any).pushArray = function pushArray(...otherList: any[]) {
let c = 0; // count pushed elements
for (let a = 0; a < otherList.length; a++) {
const other = otherList[a];
for (let i = 0; i < other.length; i++) {
this.push(other[i]);
c++;
}
}
return c;
};
// push-array.ts end


import Renderer from '../../Renderer';
import Element from '../../../nodes/Element';
import Wrapper from '../shared/Wrapper';
Expand Down Expand Up @@ -596,7 +618,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);
this.class_dependencies.pushArray(dependencies);
}
});

Expand Down
24 changes: 23 additions & 1 deletion src/compiler/compile/render_dom/wrappers/IfBlock.ts
@@ -1,3 +1,25 @@
// push-array.ts start
// TODO move pushArray to npm module
//export{}
//declare global {
// interface Array<T> {
// pushArray(...otherList: any[]): number;
// }
//}
(Array.prototype as any).pushArray = function pushArray(...otherList: any[]) {
let c = 0; // count pushed elements
for (let a = 0; a < otherList.length; a++) {
const other = otherList[a];
for (let i = 0; i < other.length; i++) {
this.push(other[i]);
c++;
}
}
return c;
};
// push-array.ts end


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

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

render(
Expand Down
24 changes: 23 additions & 1 deletion src/compiler/preprocess/decode_sourcemap.ts
@@ -1,3 +1,25 @@
// push-array.ts start
// TODO move pushArray to npm module
//export{}
//declare global {
// interface Array<T> {
// pushArray(...otherList: any[]): number;
// }
//}
(Array.prototype as any).pushArray = function pushArray(...otherList: any[]) {
let c = 0; // count pushed elements
for (let a = 0; a < otherList.length; a++) {
const other = otherList[a];
for (let i = 0; i < other.length; i++) {
this.push(other[i]);
c++;
}
}
return c;
};
// push-array.ts end


import { decode as decode_mappings } from 'sourcemap-codec';
import { Processed } from './types';

Expand Down Expand Up @@ -50,7 +72,7 @@ function decoded_sourcemap_from_generator(generator: any) {
result_segment = result_line[result_line.length - 1];

if (mapping.source != null) {
result_segment.push(...[
result_segment.pushArray([
source_idx[mapping.source],
mapping.originalLine - 1, // line is one-based
mapping.originalColumn
Expand Down
26 changes: 24 additions & 2 deletions src/compiler/preprocess/index.ts
@@ -1,3 +1,25 @@
// push-array.ts start
// TODO move pushArray to npm module
//export{}
//declare global {
// interface Array<T> {
// pushArray(...otherList: any[]): number;
// }
//}
(Array.prototype as any).pushArray = function pushArray(...otherList: any[]) {
let c = 0; // count pushed elements
for (let a = 0; a < otherList.length; a++) {
const other = otherList[a];
for (let i = 0; i < other.length; i++) {
this.push(other[i]);
c++;
}
}
return c;
};
// push-array.ts end


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 +70,7 @@ class PreprocessResult implements Source {
}

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

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

if (!processed) return no_change();
if (processed.dependencies) dependencies.push(...processed.dependencies);
if (processed.dependencies) dependencies.pushArray(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 2c84484

Please sign in to comment.