@muze-nl/simplystore 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/fastParse.mjs +38 -51
package/package.json
CHANGED
package/src/fastParse.mjs
CHANGED
|
@@ -567,9 +567,9 @@ export default function parse(input, meta, immutable=true)
|
|
|
567
567
|
error("Input stopped early")
|
|
568
568
|
}
|
|
569
569
|
|
|
570
|
-
let object = function()
|
|
570
|
+
let object = function(object={})
|
|
571
571
|
{
|
|
572
|
-
let key, val
|
|
572
|
+
let key, val
|
|
573
573
|
if (ch !== '{') {
|
|
574
574
|
error("Syntax Error")
|
|
575
575
|
}
|
|
@@ -638,10 +638,10 @@ export default function parse(input, meta, immutable=true)
|
|
|
638
638
|
return parseInt(numString)
|
|
639
639
|
}
|
|
640
640
|
|
|
641
|
-
let parseValue = function(position) {
|
|
641
|
+
let parseValue = function(position, ob={}) {
|
|
642
642
|
at = position.start
|
|
643
643
|
next()
|
|
644
|
-
return value()
|
|
644
|
+
return value(ob)
|
|
645
645
|
}
|
|
646
646
|
|
|
647
647
|
const makeChildProxies = function(parent) {
|
|
@@ -704,7 +704,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
704
704
|
if (i != index) {
|
|
705
705
|
return encoder.encode('~'+index)
|
|
706
706
|
}
|
|
707
|
-
// return newly stringified contents of
|
|
707
|
+
// return newly stringified contents of target
|
|
708
708
|
return encoder.encode(fastStringify(target, meta, true, i))
|
|
709
709
|
}
|
|
710
710
|
break
|
|
@@ -726,7 +726,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
726
726
|
if (JSONTag.getType(value)==='object' && !value[isProxy]) {
|
|
727
727
|
value = getNewValueProxy(value)
|
|
728
728
|
}
|
|
729
|
-
|
|
729
|
+
target[prop] = val
|
|
730
730
|
return true
|
|
731
731
|
}
|
|
732
732
|
}
|
|
@@ -749,6 +749,12 @@ export default function parse(input, meta, immutable=true)
|
|
|
749
749
|
let parsed = false
|
|
750
750
|
at += length
|
|
751
751
|
next()
|
|
752
|
+
let firstParse = function() {
|
|
753
|
+
if (!parsed) {
|
|
754
|
+
parseValue(position, cache)
|
|
755
|
+
parsed = true
|
|
756
|
+
}
|
|
757
|
+
}
|
|
752
758
|
// newValueHandler makes sure that value[getBuffer] runs stringify
|
|
753
759
|
// arrayHandler makes sure that changes in the array set targetIsChanged to true
|
|
754
760
|
let arrayHandler = {
|
|
@@ -794,13 +800,10 @@ export default function parse(input, meta, immutable=true)
|
|
|
794
800
|
}
|
|
795
801
|
let handler = {
|
|
796
802
|
get(target, prop, receiver) {
|
|
797
|
-
|
|
798
|
-
cache = parseValue(position)
|
|
799
|
-
parsed = true
|
|
800
|
-
}
|
|
803
|
+
firstParse()
|
|
801
804
|
switch(prop) {
|
|
802
805
|
case source:
|
|
803
|
-
return
|
|
806
|
+
return target
|
|
804
807
|
break
|
|
805
808
|
case isProxy:
|
|
806
809
|
return true
|
|
@@ -812,8 +815,8 @@ export default function parse(input, meta, immutable=true)
|
|
|
812
815
|
}
|
|
813
816
|
if (targetIsChanged) {
|
|
814
817
|
// return newly stringified contents of cache
|
|
815
|
-
let temp = fastStringify(
|
|
816
|
-
return encoder.encode(fastStringify(
|
|
818
|
+
let temp = fastStringify(target, null, true)
|
|
819
|
+
return encoder.encode(fastStringify(target, null, true))
|
|
817
820
|
}
|
|
818
821
|
return input.slice(position.start,position.end)
|
|
819
822
|
}
|
|
@@ -825,57 +828,41 @@ export default function parse(input, meta, immutable=true)
|
|
|
825
828
|
return targetIsChanged
|
|
826
829
|
break
|
|
827
830
|
default:
|
|
828
|
-
if (!immutable && Array.isArray(
|
|
829
|
-
return new Proxy(
|
|
831
|
+
if (!immutable && Array.isArray(target[prop])) {
|
|
832
|
+
return new Proxy(target[prop], arrayHandler)
|
|
830
833
|
}
|
|
831
|
-
return
|
|
834
|
+
return target[prop] // FIXME: make arrays immutable as well
|
|
832
835
|
break
|
|
833
836
|
}
|
|
834
837
|
},
|
|
835
|
-
|
|
836
|
-
if (!
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
return typeof cache[prop] !== 'undefined'
|
|
841
|
-
},
|
|
842
|
-
ownKeys() {
|
|
843
|
-
if (!parsed) {
|
|
844
|
-
cache = parseValue(position)
|
|
845
|
-
parsed = true
|
|
846
|
-
}
|
|
847
|
-
return Reflect.ownKeys(cache)
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
if (!immutable) {
|
|
851
|
-
Object.assign(handler, {
|
|
852
|
-
set: (target, prop, val) => {
|
|
853
|
-
if (!parsed) {
|
|
854
|
-
cache = parseValue(position)
|
|
855
|
-
parsed = true
|
|
856
|
-
}
|
|
857
|
-
if (JSONTag.getType(val)==='object' && !val[isProxy]) {
|
|
858
|
-
val = getNewValueProxy(val)
|
|
838
|
+
set(target, prop, value) {
|
|
839
|
+
if (!immutable) {
|
|
840
|
+
firstParse()
|
|
841
|
+
if (JSONTag.getType(value)==='object' && !value[isProxy]) {
|
|
842
|
+
value = getNewValueProxy(value)
|
|
859
843
|
}
|
|
860
|
-
|
|
844
|
+
target[prop] = value
|
|
861
845
|
targetIsChanged = true
|
|
862
846
|
return true
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
delete cache[prop]
|
|
847
|
+
}
|
|
848
|
+
},
|
|
849
|
+
deleteProperty: (target, prop) => {
|
|
850
|
+
if (!immutable) {
|
|
851
|
+
firstParse()
|
|
852
|
+
delete target[prop]
|
|
870
853
|
targetIsChanged = true
|
|
871
854
|
return true
|
|
872
855
|
}
|
|
873
|
-
}
|
|
856
|
+
},
|
|
857
|
+
'ownKeys': (target) => {
|
|
858
|
+
firstParse()
|
|
859
|
+
return Reflect.ownKeys(target)
|
|
860
|
+
}
|
|
874
861
|
}
|
|
875
862
|
return new Proxy(cache, handler)
|
|
876
863
|
}
|
|
877
864
|
|
|
878
|
-
value = function()
|
|
865
|
+
value = function(ob={})
|
|
879
866
|
{
|
|
880
867
|
let tagOb, result, tagName;
|
|
881
868
|
whitespace()
|
|
@@ -893,7 +880,7 @@ export default function parse(input, meta, immutable=true)
|
|
|
893
880
|
if (tagName && tagName!=='object') {
|
|
894
881
|
isTypeError(tagName, ch)
|
|
895
882
|
}
|
|
896
|
-
result = object()
|
|
883
|
+
result = object(ob)
|
|
897
884
|
break
|
|
898
885
|
case '[':
|
|
899
886
|
if (tagName && tagName!=='array') {
|