From 80e0c7e73912f680c35692798c51ce24c3a228ed Mon Sep 17 00:00:00 2001 From: Chris Wendt Date: Fri, 24 Aug 2018 01:44:26 -0700 Subject: [PATCH] Do not mutate the given path --- src/impl/edit.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/impl/edit.ts b/src/impl/edit.ts index d524896..0f8c14b 100644 --- a/src/impl/edit.ts +++ b/src/impl/edit.ts @@ -12,7 +12,8 @@ export function removeProperty(text: string, path: JSONPath, formattingOptions: return setProperty(text, path, void 0, formattingOptions); } -export function setProperty(text: string, path: JSONPath, value: any, formattingOptions: FormattingOptions, getInsertionIndex?: (properties: string[]) => number): Edit[] { +export function setProperty(text: string, originalPath: JSONPath, value: any, formattingOptions: FormattingOptions, getInsertionIndex?: (properties: string[]) => number): Edit[] { + let path = originalPath.slice() let errors: ParseError[] = []; let root = parseTree(text, errors); let parent: Node | undefined = void 0; @@ -160,4 +161,4 @@ export function applyEdit(text: string, edit: Edit): string { export function isWS(text: string, offset: number) { return '\r\n \t'.indexOf(text.charAt(offset)) !== -1; -} \ No newline at end of file +}