Merge pull request #17792 from atom/mb-tree-sitter-stack-overflow

Avoid stack overflows due to spread args in Array.splice call
This commit is contained in:
Max Brunsfeld
2018-08-06 16:45:32 -07:00
committed by GitHub

View File

@@ -1,5 +1,5 @@
const Parser = require('tree-sitter')
const {Point, Range} = require('text-buffer')
const {Point, Range, spliceArray} = require('text-buffer')
const {Patch} = require('superstring')
const {Emitter, Disposable} = require('event-kit')
const ScopeDescriptor = require('./scope-descriptor')
@@ -52,10 +52,11 @@ class TreeSitterLanguageMode {
this.subscription = this.buffer.onDidChangeText(({changes}) => {
for (let i = 0, {length} = changes; i < length; i++) {
const {oldRange, newRange} = changes[i]
this.isFoldableCache.splice(
spliceArray(
this.isFoldableCache,
newRange.start.row,
oldRange.end.row - oldRange.start.row,
...new Array(newRange.end.row - newRange.start.row)
{length: newRange.end.row - newRange.start.row}
)
}