8 lines
9.6 KiB
JavaScript
8 lines
9.6 KiB
JavaScript
var json = (function () {
|
|||
|
|
var commonjsGlobal$1 = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
||
|
|
|
||
|
|
function createError$1(e,t){const n=new SyntaxError(e+" ("+t.start.line+":"+t.start.column+")");return n.loc=t,n}function createCommonjsModule$$1(e,t){return t={exports:{}},e(t,t.exports),t.exports}function parse(e){const t=parse$1;try{const n=t(e);return toBabylon(n)}catch(e){const t=e.message.indexOf("\n"),n=e.message.slice(0,t),r=n.lastIndexOf(" "),o=n.slice(0,r),l=n.slice(r+1),a=l.split(":").map(Number);throw createError("(json-to-ast) "+o,{start:{line:a[0],column:a[1]}})}}function toBabylon(e){const t={type:{object:"ObjectExpression",property:"ObjectProperty",identifier:"json-identifier",array:"ArrayExpression"}[e.type],start:e.loc.start.offset,end:e.loc.end.offset,loc:e.loc};switch(e.type){case"object":return Object.assign(t,{properties:e.children.map(toBabylon)});case"property":return Object.assign(t,{key:toBabylon(e.key),value:toBabylon(e.value)});case"identifier":return Object.assign(t,{value:e.value});case"array":return Object.assign(t,{elements:e.children.map(toBabylon)});case"literal":{const n={String:"StringLiteral",Number:"NumericLiteral",Boolean:"BooleanLiteral"},r=JSON.parse(e.rawValue),o=null===r?"NullLiteral":n[r.constructor.name];return Object.assign(t,{type:o,value:r,extra:{raw:e.rawValue}})}}}var parserCreateError=createError$1; var commonjsGlobal$$1="undefined"!=typeof window?window:"undefined"!=typeof commonjsGlobal$1?commonjsGlobal$1:"undefined"!=typeof self?self:{}; var parse$1=createCommonjsModule$$1(function(e,t){!function(t,n){n(e);}(0,function(e){function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t);}function o(e,t,n){return e.split(/\n|\r\n?|\f/)[t-1]+"\n"+(new Array(n).join(" ")+"^")}function l(e){return e>="1"&&e<="9"}function a(e){return e>="0"&&e<="9"}function c(e){return a(e)||e>="a"&&e<="f"||e>="A"&&e<="F"}function s(e){return"e"===e||"E"===e}function u(e,t,n,r){var o=e.charAt(t);if("\r"===o)t++,n++,r=1,"\n"===e.charAt(t)&&t++;else if("\n"===o)t++,n++,r=1;else{if("\t"!==o&&" "!==o)return null;t++,r++;}return{index:t,line:n,column:r}}function i(e,t,n,r){var o=e.charAt(t);return o in x?{type:x[o],line:n,column:r+1,index:t+1,value:null}:null}function f(e,t,n,r){for(var o in S)if(S.hasOwnProperty(o)&&e.substr(t,o.length)===o){var l=S[o],a=l.type,c=l.value;return{type:a,line:n,column:r+o.length,index:t+o.length,value:c}}return null}function p(e,t,n,r){for(var o=t,l="",a=N._START_;t<e.length;){var s=e.charAt(t);switch(a){case N._START_:if('"'!==s)return null;a=N.START_QUOTE_OR_CHAR,t++;break;case N.START_QUOTE_OR_CHAR:if("\\"===s)a=N.ESCAPE,l+=s,t++;else{if('"'===s)return t++,{type:I.STRING,line:n,column:r+t-o,index:t,value:l};l+=s,t++;}break;case N.ESCAPE:if(!(s in k))return null;if(l+=s,t++,"u"===s)for(var u=0;u<4;u++){var i=e.charAt(t);if(!i||!c(i))return null;l+=i,t++;}a=N.START_QUOTE_OR_CHAR;}}}function T(e,t,n,r){var o=t,c=t,u=P._START_;e:for(;t<e.length;){var i=e.charAt(t);switch(u){case P._START_:if("-"===i)u=P.MINUS;else if("0"===i)c=t+1,u=P.ZERO;else{if(!l(i))return null;c=t+1,u=P.DIGIT;}break;case P.MINUS:if("0"===i)c=t+1,u=P.ZERO;else{if(!l(i))return null;c=t+1,u=P.DIGIT;}break;case P.ZERO:if("."===i)u=P.POINT;else{if(!s(i))break e;u=P.EXP;}break;case P.DIGIT:if(a(i))c=t+1;else if("."===i)u=P.POINT;else{if(!s(i))break e;u=P.EXP;}break;case P.POINT:if(!a(i))break e;c=t+1,u=P.DIGIT_FRACTION;break;case P.DIGIT_FRACTION:if(a(i))c=t+1;else{if(!s(i))break e;u=P.EXP;}break;case P.EXP:if("+"===i||"-"===i)u=P.EXP_DIGIT_OR_SIGN;else{if(!a(i))break e;c=t+1,u=P.EXP_DIGIT_OR_SIGN;}break;case P.EXP_DIGIT_OR_SIGN:if(!a(i))break e;c=t+1;}t++;}return c>0?{type:I.NUMBER,line:n,column:r+c-
|
||
|
|
|
||
|
|
return parserJson_1;
|
||
|
|
|
||
|
|
}());
|