summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn J. Camilleri <john@digitalgrammars.com>2019-06-10 09:45:04 +0200
committerJohn J. Camilleri <john@digitalgrammars.com>2019-06-10 09:45:04 +0200
commit4793d376d97b6b6157c88e2586fdbf8d8decbf77 (patch)
treeb9714676e41699a767cfdffbc5d0926e90818904 /src
parent63606fd2d0eaeb374d22116a5a6159a9ae7c12f5 (diff)
Create copies when tagging
Not sure if this behaviour is identical to previous version, or in truth how important it really is anyway
Diffstat (limited to 'src')
-rw-r--r--src/runtime/typescript/gflib.ts19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/runtime/typescript/gflib.ts b/src/runtime/typescript/gflib.ts
index 641e54880..87c17a839 100644
--- a/src/runtime/typescript/gflib.ts
+++ b/src/runtime/typescript/gflib.ts
@@ -662,8 +662,10 @@ interface String {
tagWith: (tag: string) => string;
}
String.prototype.tagWith = function (tag: string): string {
- this.tag = tag
- return this
+ // returns a copy
+ let s2 = this
+ s2.tag = tag
+ return s2
}
/**
@@ -833,10 +835,11 @@ class SymKS implements Taggable {
return terminalStr.join('')
}
- // TODO magic numbering fails here
public tagWith(tag: string): SymKS {
- this.tag = tag
- return this
+ let s = new SymKS()
+ s.tokens = [...this.tokens] // copy array
+ s.tag = tag
+ return s
}
}
@@ -861,10 +864,10 @@ class SymKP implements Taggable {
return terminalStr.join('')
}
- // TODO magic numbering fails here
public tagWith(tag: string): SymKP {
- this.tag = tag
- return this
+ let s = new SymKP([...this.tokens], [...this.alts]) // copy arguments
+ s.tag = tag
+ return s
}
}