MCPcopy Index your code
hub / github.com/json5/json5 / push

Function push

lib/parse.js:962–1025  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

960}
961
962function push () {
963 let value
964
965 switch (token.type) {
966 case 'punctuator':
967 switch (token.value) {
968 case '{':
969 value = {}
970 break
971
972 case '[':
973 value = []
974 break
975 }
976
977 break
978
979 case 'null':
980 case 'boolean':
981 case 'numeric':
982 case 'string':
983 value = token.value
984 break
985
986 // This code is unreachable.
987 // default:
988 // throw invalidToken()
989 }
990
991 if (root === undefined) {
992 root = value
993 } else {
994 const parent = stack[stack.length - 1]
995 if (Array.isArray(parent)) {
996 parent.push(value)
997 } else {
998 Object.defineProperty(parent, key, {
999 value,
1000 writable: true,
1001 enumerable: true,
1002 configurable: true,
1003 })
1004 }
1005 }
1006
1007 if (value !== null && typeof value === 'object') {
1008 stack.push(value)
1009
1010 if (Array.isArray(value)) {
1011 parseState = 'beforeArrayValue'
1012 } else {
1013 parseState = 'beforePropertyName'
1014 }
1015 } else {
1016 const current = stack[stack.length - 1]
1017 if (current == null) {
1018 parseState = 'end'
1019 } else if (Array.isArray(current)) {

Callers 3

startFunction · 0.85
beforePropertyValueFunction · 0.85
beforeArrayValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…