@tslite/codec 0.4.2 → 0.5.1

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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- 'use strict';var printer=require('@tslite/printer'),core=require('@tslite/core'),a=require('@tslite/core/builders');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var a__namespace=/*#__PURE__*/_interopNamespace(a);var c=e=>{if(e.type==="Literal")return e.value;if(e.type==="ArrayExpression")return e.elements.map(c);if(e.type==="ObjectExpression")return u(e);let t=r(e);if(t&&typeof t=="object"&&"type"in t){let{type:s,...l}=t;return {"#expr":s,...l}}return {"#expr":"Unknown",value:t}},d=e=>e.type==="Literal"?e.value:printer.print(e);function u(e){let t=e.properties.flatMap(s=>{if(s.type==="SpreadElement"){let i=c(s.argument);return typeof i=="object"&&i!==null&&!Array.isArray(i)&&!("#expr"in i)?Object.entries(i):[["...spread",{"#expr":"SpreadElement",argument:r(s)?.argument}]]}let l=d(s.key);return s.computed?[[`[${l}]`,c(s.value)]]:[[l,c(s.value)]]});return Object.fromEntries(t)}var p=e=>{let t={};for(let s in e)e[s]==false||e[s]==null||(t[s]=e[s]);return t},r=e=>!e||typeof e!="object"?e:Array.isArray(e)?e.map(r):f[e.type]?.(e),f={ArrayExpression:e=>({type:"ArrayExpression",elements:r(e.elements||[])}),ArrayPattern:e=>({type:"ArrayPattern",elements:r(e.elements||[])}),ArrowFunctionExpression:e=>({type:"ArrowFunctionExpression",params:r(e.params||[]),body:r(e.body),...p({async:e.async})}),AssignmentExpression:e=>({type:"AssignmentExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),AssignmentProperty:e=>({type:"Property",key:r(e.key),value:r(e.value),...p({shorthand:e.shorthand})}),AwaitExpression:e=>({type:"AwaitExpression",argument:r(e.argument)}),BinaryExpression:e=>({type:"BinaryExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),BlockStatement:e=>({type:"BlockStatement",body:r(e.body||[])}),BreakStatement:e=>({type:"BreakStatement",...p({label:r(e.label)})}),CallExpression:e=>({type:"CallExpression",callee:r(e.callee),arguments:r(e.arguments||[]),...p({optional:e.optional})}),CatchClause:e=>({type:"CatchClause",param:r(e.param||[]),body:r(e.body)}),ChainExpression:e=>({type:"ChainExpression",expression:r(e.expression)}),ConditionalExpression:e=>({type:"ConditionalExpression",test:r(e.test),consequent:r(e.consequent),alternate:r(e.alternate)}),ContinueStatement:e=>({type:"ContinueStatement",...p({label:r(e.label)})}),DoWhileStatement:e=>({type:"DoWhileStatement",body:r(e.body),test:r(e.test)}),EmptyStatement:()=>({type:"EmptyStatement"}),ExpressionStatement:e=>({type:"ExpressionStatement",expression:r(e.expression)}),ForInStatement:e=>({type:"ForInStatement",left:r(e.left),right:r(e.right),body:r(e.body)}),ForOfStatement:e=>({type:"ForOfStatement",left:r(e.left),right:r(e.right),body:r(e.body),...p({await:e.await})}),ForStatement:e=>({type:"ForStatement",body:r(e.body),...p({init:r(e.init),test:r(e.test),update:r(e.update)})}),FunctionDeclaration:e=>({type:"FunctionDeclaration",id:r(e.id),params:r(e.params||[]),body:r(e.body),...p(core.pick(e,["async"]))}),FunctionExpression:e=>({type:"FunctionExpression",params:r(e.params||[]),body:r(e.body),...p({id:e.id?r(e.id):false,async:e.async})}),Identifier:e=>({type:"Identifier",name:e.name}),Placeholder:()=>({type:"Placeholder"}),IfStatement:e=>({type:"IfStatement",test:r(e.test),consequent:r(e.consequent),alternate:r(e.alternate)}),JsonExpression:e=>({type:"JsonExpression",body:e.body}),Literal:e=>({type:"Literal",value:e.value,raw:e.raw}),LogicalExpression:e=>({type:"LogicalExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),MemberExpression:e=>({type:"MemberExpression",object:r(e.object),property:r(e.property),...p(core.pick(e,["computed","optional"]))}),NewExpression:e=>({type:"NewExpression",callee:r(e.callee),arguments:r(e.arguments||[])}),ObjectExpression:e=>({type:"JsonExpression",body:u(e)}),ObjectPattern:e=>({type:"ObjectPattern",properties:r(e.properties||[])}),Program:e=>({type:"Program",body:r(e.body)}),Property:e=>({type:"Property",key:r(e.key),value:r(e.value),...p(core.pick(e,["kind","shorthand","computed"]))}),ReturnStatement:e=>({type:"ReturnStatement",argument:r(e.argument)}),SwitchCase:e=>({type:"SwitchCase",test:r(e.test),consequent:r(e.consequent)}),SwitchStatement:e=>({type:"SwitchStatement",discriminant:r(e.discriminant),cases:r(e.cases)}),TemplateElement:e=>({type:"TemplateElement",value:e.value,...p({tail:e.tail})}),TemplateLiteral:e=>({type:"TemplateLiteral",quasis:r(e.quasis),expressions:r(e.expressions)}),ThrowStatement:e=>({type:"ThrowStatement",argument:r(e.argument)}),TryStatement:e=>({type:"TryStatement",block:r(e.block),handler:r(e.handler),finalizer:r(e.finalizer)}),UnaryExpression:e=>({type:"UnaryExpression",operator:e.operator,argument:r(e.argument)}),UpdateExpression:e=>({type:"UpdateExpression",operator:e.operator,argument:r(e.argument),...p({prefix:e.prefix})}),VariableDeclaration:e=>({type:"VariableDeclaration",kind:e.kind,declarations:r(e.declarations||[])}),VariableDeclarator:e=>({type:"VariableDeclarator",id:r(e.id),init:r(e.init)}),WhileStatement:e=>({type:"WhileStatement",test:r(e.test),body:r(e.body)}),SpreadElement:e=>({type:"SpreadElement",argument:r(e.argument)}),RestElement:e=>({type:"RestElement",argument:r(e.argument)})};function n(e,t=new WeakMap){if(e==null)return e;if(typeof e!="object")throw new core.TSLiteError("not-an-object","AST node must be an object");if(t.has(e))throw new core.TSLiteError("circular-reference","Circular reference detected in AST",{phase:"ast"});t.set(e,true);try{if(Array.isArray(e))return e.map(l=>n(l,t));let s=e;if(s.type==="JsonExpression")return b(s.body,t);if(typeof s.type=="string"&&S[s.type])return S[s.type](s,t);throw new core.TSLiteError("unknown-node-type",`Unknown node type: ${s.type}`,{type:s.type})}finally{t.delete(e);}}function b(e,t=new WeakMap){if(e===null||typeof e!="object")return a__namespace.literal(e);if(t.has(e))throw new core.TSLiteError("circular-reference","Circular reference detected in JSON",{phase:"json"});t.set(e,true);try{if(Array.isArray(e))return a__namespace.arrayExpression(e.map(i=>b(i,t)));let s=e;if("#expr"in s){let i=s["#expr"];if(!core.isValidExpressionEntryType(i))throw core.invalidExpressionEntryError(i);let m={...s,type:i};return delete m["#expr"],w(m,t)}let l=Object.entries(s).map(([i,m])=>a__namespace.property(a__namespace.identifier(i),b(m,t),!1,!1));return a__namespace.objectExpression(l)}finally{t.delete(e);}}function w(e,t){if(typeof e.type!="string")throw new core.TSLiteError("missing-node-type","AST node must have a type property");if(!S[e.type])throw new core.TSLiteError("unknown-node-type",`Unknown AST node type: ${e.type}`,{type:e.type});return S[e.type](e,t)}var S={ArrayExpression:(e,t)=>a__namespace.arrayExpression(o(e.elements,t)),ArrayPattern:(e,t)=>a__namespace.arrayPattern(o(e.elements,t)),ArrowFunctionExpression:(e,t)=>a__namespace.arrowFunctionExpression(o(e.params,t),n(e.body,t),e.async||false,e.generator||false),AssignmentExpression:(e,t)=>a__namespace.assignmentExpression(e.operator,n(e.left,t),n(e.right,t)),AssignmentProperty:(e,t)=>a__namespace.assignmentProperty(n(e.key,t),n(e.value,t),e.shorthand||false),AwaitExpression:(e,t)=>a__namespace.awaitExpression(n(e.argument,t)),BinaryExpression:(e,t)=>a__namespace.binaryExpression(e.operator,n(e.left,t),n(e.right,t)),BlockStatement:(e,t)=>a__namespace.blockStatement(o(e.body,t)),BreakStatement:(e,t)=>a__namespace.breakStatement(e.label?n(e.label,t):null),CallExpression:(e,t)=>a__namespace.callExpression(n(e.callee,t),o(e.arguments,t),e.optional||false),CatchClause:(e,t)=>a__namespace.catchClause(e.param?n(e.param,t):null,n(e.body,t)),ChainExpression:(e,t)=>a__namespace.chainExpression(n(e.expression,t)),ConditionalExpression:(e,t)=>a__namespace.conditionalExpression(n(e.test,t),n(e.consequent,t),n(e.alternate,t)),ContinueStatement:(e,t)=>a__namespace.continueStatement(e.label?n(e.label,t):null),DoWhileStatement:(e,t)=>a__namespace.doWhileStatement(n(e.body,t),n(e.test,t)),EmptyStatement:()=>a__namespace.emptyStatement(),ExpressionStatement:(e,t)=>a__namespace.expressionStatement(n(e.expression,t)),ForInStatement:(e,t)=>a__namespace.forInStatement(n(e.left,t),n(e.right,t),n(e.body,t)),ForOfStatement:(e,t)=>a__namespace.forOfStatement(n(e.left,t),n(e.right,t),n(e.body,t),e.await||false),ForStatement:(e,t)=>a__namespace.forStatement(e.init?n(e.init,t):null,e.test?n(e.test,t):null,e.update?n(e.update,t):null,n(e.body,t)),FunctionDeclaration:(e,t)=>a__namespace.functionDeclaration(n(e.id,t),o(e.params,t),n(e.body,t),e.generator||false,e.async||false),FunctionExpression:(e,t)=>a__namespace.functionExpression(e.id?n(e.id,t):null,o(e.params,t),n(e.body,t),e.async||false,e.generator||false),Identifier:e=>a__namespace.identifier(e.name),Placeholder:()=>a__namespace.placeholder(),IfStatement:(e,t)=>a__namespace.ifStatement(n(e.test,t),n(e.consequent,t),e.alternate?n(e.alternate,t):null),Literal:e=>a__namespace.literal(e.value),LogicalExpression:(e,t)=>a__namespace.logicalExpression(e.operator,n(e.left,t),n(e.right,t)),MemberExpression:(e,t)=>a__namespace.memberExpression(n(e.object,t),n(e.property,t),e.computed||false,e.optional||false),NewExpression:(e,t)=>a__namespace.newExpression(n(e.callee,t),o(e.arguments,t)),ObjectExpression:(e,t)=>a__namespace.objectExpression(o(e.properties,t)),ObjectPattern:(e,t)=>a__namespace.objectPattern(o(e.properties,t)),Program:(e,t)=>a__namespace.program(o(e.body,t)),Property:(e,t)=>a__namespace.property(n(e.key,t),n(e.value,t),e.shorthand||false,e.computed||false),RestElement:(e,t)=>a__namespace.restElement(n(e.argument,t)),ReturnStatement:(e,t)=>a__namespace.returnStatement(e.argument?n(e.argument,t):null),SpreadElement:(e,t)=>a__namespace.spreadElement(n(e.argument,t)),SwitchCase:(e,t)=>a__namespace.switchCase(e.test?n(e.test,t):null,o(e.consequent,t)),SwitchStatement:(e,t)=>a__namespace.switchStatement(n(e.discriminant,t),o(e.cases,t)),TemplateElement:e=>a__namespace.templateElement(e.value,e.tail||false),TemplateLiteral:(e,t)=>a__namespace.templateLiteral(o(e.quasis,t),o(e.expressions,t)),ThrowStatement:(e,t)=>a__namespace.throwStatement(n(e.argument,t)),TryStatement:(e,t)=>a__namespace.tryStatement(n(e.block,t),e.handler?n(e.handler,t):null,e.finalizer?n(e.finalizer,t):null),UnaryExpression:(e,t)=>a__namespace.unaryExpression(e.operator,n(e.argument,t)),UpdateExpression:(e,t)=>a__namespace.updateExpression(e.operator,n(e.argument,t),e.prefix||false),VariableDeclaration:(e,t)=>a__namespace.variableDeclaration(e.kind,o(e.declarations,t)),VariableDeclarator:(e,t)=>a__namespace.variableDeclarator(n(e.id,t),e.init?n(e.init,t):null),WhileStatement:(e,t)=>a__namespace.whileStatement(n(e.test,t),n(e.body,t))};function o(e,t){return e?e.map(s=>s!=null?n(s,t):null):[]}exports.decode=n;exports.encode=r;exports.fromJson=b;exports.objectToJson=u;exports.valueToJson=c;
1
+ 'use strict';var printer=require('@tslite/printer'),core=require('@tslite/core'),a=require('@tslite/core/builders');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var a__namespace=/*#__PURE__*/_interopNamespace(a);var c=e=>{if(e.type==="Literal")return e.value;if(e.type==="ArrayExpression")return e.elements.map(c);if(e.type==="ObjectExpression")return b(e);let t=r(e);if(t&&typeof t=="object"&&"type"in t){let{type:s,...l}=t;return {"#expr":s,...l}}return {"#expr":"Unknown",value:t}},d=e=>e.type==="Literal"?e.value:printer.print(e);function b(e){let t=e.properties.flatMap(s=>{if(s.type==="SpreadElement"){let i=c(s.argument);return typeof i=="object"&&i!==null&&!Array.isArray(i)&&!("#expr"in i)?Object.entries(i):[["...spread",{"#expr":"SpreadElement",argument:r(s)?.argument}]]}let l=d(s.key);return s.computed?[[`[${l}]`,c(s.value)]]:[[l,c(s.value)]]});return Object.fromEntries(t)}var p=e=>{let t={};for(let s in e)e[s]==false||e[s]==null||(t[s]=e[s]);return t},r=e=>!e||typeof e!="object"?e:Array.isArray(e)?e.map(r):f[e.type]?.(e),f={ArrayExpression:e=>({type:"ArrayExpression",elements:r(e.elements||[])}),ArrayPattern:e=>({type:"ArrayPattern",elements:r(e.elements||[])}),ArrowFunctionExpression:e=>({type:"ArrowFunctionExpression",params:r(e.params||[]),body:r(e.body),...p({async:e.async})}),AssignmentExpression:e=>({type:"AssignmentExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),AssignmentProperty:e=>({type:"Property",key:r(e.key),value:r(e.value),...p({shorthand:e.shorthand})}),AwaitExpression:e=>({type:"AwaitExpression",argument:r(e.argument)}),BinaryExpression:e=>({type:"BinaryExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),BlockStatement:e=>({type:"BlockStatement",body:r(e.body||[])}),BreakStatement:e=>({type:"BreakStatement",...p({label:r(e.label)})}),CallExpression:e=>({type:"CallExpression",callee:r(e.callee),arguments:r(e.arguments||[]),...p({optional:e.optional})}),CatchClause:e=>({type:"CatchClause",param:r(e.param||[]),body:r(e.body)}),ChainExpression:e=>({type:"ChainExpression",expression:r(e.expression)}),ConditionalExpression:e=>({type:"ConditionalExpression",test:r(e.test),consequent:r(e.consequent),alternate:r(e.alternate)}),ContinueStatement:e=>({type:"ContinueStatement",...p({label:r(e.label)})}),DoWhileStatement:e=>({type:"DoWhileStatement",body:r(e.body),test:r(e.test)}),EmptyStatement:()=>({type:"EmptyStatement"}),ExpressionStatement:e=>({type:"ExpressionStatement",expression:r(e.expression)}),ForInStatement:e=>({type:"ForInStatement",left:r(e.left),right:r(e.right),body:r(e.body)}),ForOfStatement:e=>({type:"ForOfStatement",left:r(e.left),right:r(e.right),body:r(e.body),...p({await:e.await})}),ForStatement:e=>({type:"ForStatement",body:r(e.body),...p({init:r(e.init),test:r(e.test),update:r(e.update)})}),FunctionDeclaration:e=>({type:"FunctionDeclaration",id:r(e.id),params:r(e.params||[]),body:r(e.body),...p(core.pick(e,["async"]))}),FunctionExpression:e=>({type:"FunctionExpression",params:r(e.params||[]),body:r(e.body),...p({id:e.id?r(e.id):false,async:e.async})}),Identifier:e=>({type:"Identifier",name:e.name}),Placeholder:()=>({type:"Placeholder"}),IfStatement:e=>({type:"IfStatement",test:r(e.test),consequent:r(e.consequent),alternate:r(e.alternate)}),JsonExpression:e=>({type:"JsonExpression",body:e.body}),Literal:e=>({type:"Literal",value:e.value,raw:e.raw}),LogicalExpression:e=>({type:"LogicalExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),MemberExpression:e=>({type:"MemberExpression",object:r(e.object),property:r(e.property),...p(core.pick(e,["computed","optional"]))}),ObjectExpression:e=>({type:"JsonExpression",body:b(e)}),ObjectPattern:e=>({type:"ObjectPattern",properties:r(e.properties||[])}),Program:e=>({type:"Program",body:r(e.body)}),Property:e=>({type:"Property",key:r(e.key),value:r(e.value),...p(core.pick(e,["kind","shorthand","computed"]))}),ReturnStatement:e=>({type:"ReturnStatement",argument:r(e.argument)}),SwitchCase:e=>({type:"SwitchCase",test:r(e.test),consequent:r(e.consequent)}),SwitchStatement:e=>({type:"SwitchStatement",discriminant:r(e.discriminant),cases:r(e.cases)}),TemplateElement:e=>({type:"TemplateElement",value:e.value,...p({tail:e.tail})}),TemplateLiteral:e=>({type:"TemplateLiteral",quasis:r(e.quasis),expressions:r(e.expressions)}),ThrowStatement:e=>({type:"ThrowStatement",argument:r(e.argument)}),TryStatement:e=>({type:"TryStatement",block:r(e.block),handler:r(e.handler),finalizer:r(e.finalizer)}),UnaryExpression:e=>({type:"UnaryExpression",operator:e.operator,argument:r(e.argument)}),UpdateExpression:e=>({type:"UpdateExpression",operator:e.operator,argument:r(e.argument),...p({prefix:e.prefix})}),VariableDeclaration:e=>({type:"VariableDeclaration",kind:e.kind,declarations:r(e.declarations||[])}),VariableDeclarator:e=>({type:"VariableDeclarator",id:r(e.id),init:r(e.init)}),WhileStatement:e=>({type:"WhileStatement",test:r(e.test),body:r(e.body)}),SpreadElement:e=>({type:"SpreadElement",argument:r(e.argument)}),RestElement:e=>({type:"RestElement",argument:r(e.argument)})};function n(e,t=new WeakMap){if(e==null)return e;if(typeof e!="object")throw new core.TSLiteError("not-an-object","AST node must be an object");if(t.has(e))throw new core.TSLiteError("circular-reference","Circular reference detected in AST",{phase:"ast"});t.set(e,true);try{if(Array.isArray(e))return e.map(l=>n(l,t));let s=e;if(s.type==="JsonExpression")return u(s.body,t);if(typeof s.type=="string"&&S[s.type])return S[s.type](s,t);throw new core.TSLiteError("unknown-node-type",`Unknown node type: ${s.type}`,{type:s.type})}finally{t.delete(e);}}function u(e,t=new WeakMap){if(e===null||typeof e!="object")return a__namespace.literal(e);if(t.has(e))throw new core.TSLiteError("circular-reference","Circular reference detected in JSON",{phase:"json"});t.set(e,true);try{if(Array.isArray(e))return a__namespace.arrayExpression(e.map(i=>u(i,t)));let s=e;if("#expr"in s){let i=s["#expr"];if(!core.isValidExpressionEntryType(i))throw core.invalidExpressionEntryError(i);let m={...s,type:i};return delete m["#expr"],w(m,t)}let l=Object.entries(s).map(([i,m])=>a__namespace.property(a__namespace.identifier(i),u(m,t),!1,!1));return a__namespace.objectExpression(l)}finally{t.delete(e);}}function w(e,t){if(typeof e.type!="string")throw new core.TSLiteError("missing-node-type","AST node must have a type property");if(!S[e.type])throw new core.TSLiteError("unknown-node-type",`Unknown AST node type: ${e.type}`,{type:e.type});return S[e.type](e,t)}var S={ArrayExpression:(e,t)=>a__namespace.arrayExpression(o(e.elements,t)),ArrayPattern:(e,t)=>a__namespace.arrayPattern(o(e.elements,t)),ArrowFunctionExpression:(e,t)=>a__namespace.arrowFunctionExpression(o(e.params,t),n(e.body,t),e.async||false,e.generator||false),AssignmentExpression:(e,t)=>a__namespace.assignmentExpression(e.operator,n(e.left,t),n(e.right,t)),AssignmentProperty:(e,t)=>a__namespace.assignmentProperty(n(e.key,t),n(e.value,t),e.shorthand||false),AwaitExpression:(e,t)=>a__namespace.awaitExpression(n(e.argument,t)),BinaryExpression:(e,t)=>a__namespace.binaryExpression(e.operator,n(e.left,t),n(e.right,t)),BlockStatement:(e,t)=>a__namespace.blockStatement(o(e.body,t)),BreakStatement:(e,t)=>a__namespace.breakStatement(e.label?n(e.label,t):null),CallExpression:(e,t)=>a__namespace.callExpression(n(e.callee,t),o(e.arguments,t),e.optional||false),CatchClause:(e,t)=>a__namespace.catchClause(e.param?n(e.param,t):null,n(e.body,t)),ChainExpression:(e,t)=>a__namespace.chainExpression(n(e.expression,t)),ConditionalExpression:(e,t)=>a__namespace.conditionalExpression(n(e.test,t),n(e.consequent,t),n(e.alternate,t)),ContinueStatement:(e,t)=>a__namespace.continueStatement(e.label?n(e.label,t):null),DoWhileStatement:(e,t)=>a__namespace.doWhileStatement(n(e.body,t),n(e.test,t)),EmptyStatement:()=>a__namespace.emptyStatement(),ExpressionStatement:(e,t)=>a__namespace.expressionStatement(n(e.expression,t)),ForInStatement:(e,t)=>a__namespace.forInStatement(n(e.left,t),n(e.right,t),n(e.body,t)),ForOfStatement:(e,t)=>a__namespace.forOfStatement(n(e.left,t),n(e.right,t),n(e.body,t),e.await||false),ForStatement:(e,t)=>a__namespace.forStatement(e.init?n(e.init,t):null,e.test?n(e.test,t):null,e.update?n(e.update,t):null,n(e.body,t)),FunctionDeclaration:(e,t)=>a__namespace.functionDeclaration(n(e.id,t),o(e.params,t),n(e.body,t),e.generator||false,e.async||false),FunctionExpression:(e,t)=>a__namespace.functionExpression(e.id?n(e.id,t):null,o(e.params,t),n(e.body,t),e.async||false,e.generator||false),Identifier:e=>a__namespace.identifier(e.name),Placeholder:()=>a__namespace.placeholder(),IfStatement:(e,t)=>a__namespace.ifStatement(n(e.test,t),n(e.consequent,t),e.alternate?n(e.alternate,t):null),Literal:e=>a__namespace.literal(e.value),LogicalExpression:(e,t)=>a__namespace.logicalExpression(e.operator,n(e.left,t),n(e.right,t)),MemberExpression:(e,t)=>a__namespace.memberExpression(n(e.object,t),n(e.property,t),e.computed||false,e.optional||false),ObjectExpression:(e,t)=>a__namespace.objectExpression(o(e.properties,t)),ObjectPattern:(e,t)=>a__namespace.objectPattern(o(e.properties,t)),Program:(e,t)=>a__namespace.program(o(e.body,t)),Property:(e,t)=>a__namespace.property(n(e.key,t),n(e.value,t),e.shorthand||false,e.computed||false),RestElement:(e,t)=>a__namespace.restElement(n(e.argument,t)),ReturnStatement:(e,t)=>a__namespace.returnStatement(e.argument?n(e.argument,t):null),SpreadElement:(e,t)=>a__namespace.spreadElement(n(e.argument,t)),SwitchCase:(e,t)=>a__namespace.switchCase(e.test?n(e.test,t):null,o(e.consequent,t)),SwitchStatement:(e,t)=>a__namespace.switchStatement(n(e.discriminant,t),o(e.cases,t)),TemplateElement:e=>a__namespace.templateElement(e.value,e.tail||false),TemplateLiteral:(e,t)=>a__namespace.templateLiteral(o(e.quasis,t),o(e.expressions,t)),ThrowStatement:(e,t)=>a__namespace.throwStatement(n(e.argument,t)),TryStatement:(e,t)=>a__namespace.tryStatement(n(e.block,t),e.handler?n(e.handler,t):null,e.finalizer?n(e.finalizer,t):null),UnaryExpression:(e,t)=>a__namespace.unaryExpression(e.operator,n(e.argument,t)),UpdateExpression:(e,t)=>a__namespace.updateExpression(e.operator,n(e.argument,t),e.prefix||false),VariableDeclaration:(e,t)=>a__namespace.variableDeclaration(e.kind,o(e.declarations,t)),VariableDeclarator:(e,t)=>a__namespace.variableDeclarator(n(e.id,t),e.init?n(e.init,t):null),WhileStatement:(e,t)=>a__namespace.whileStatement(n(e.test,t),n(e.body,t))};function o(e,t){return e?e.map(s=>s!=null?n(s,t):null):[]}exports.decode=n;exports.encode=r;exports.fromJson=u;exports.objectToJson=b;exports.valueToJson=c;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import {print}from'@tslite/printer';import {pick,TSLiteError,isValidExpressionEntryType,invalidExpressionEntryError}from'@tslite/core';import*as a from'@tslite/core/builders';var c=e=>{if(e.type==="Literal")return e.value;if(e.type==="ArrayExpression")return e.elements.map(c);if(e.type==="ObjectExpression")return u(e);let t=r(e);if(t&&typeof t=="object"&&"type"in t){let{type:s,...l}=t;return {"#expr":s,...l}}return {"#expr":"Unknown",value:t}},d=e=>e.type==="Literal"?e.value:print(e);function u(e){let t=e.properties.flatMap(s=>{if(s.type==="SpreadElement"){let i=c(s.argument);return typeof i=="object"&&i!==null&&!Array.isArray(i)&&!("#expr"in i)?Object.entries(i):[["...spread",{"#expr":"SpreadElement",argument:r(s)?.argument}]]}let l=d(s.key);return s.computed?[[`[${l}]`,c(s.value)]]:[[l,c(s.value)]]});return Object.fromEntries(t)}var p=e=>{let t={};for(let s in e)e[s]==false||e[s]==null||(t[s]=e[s]);return t},r=e=>!e||typeof e!="object"?e:Array.isArray(e)?e.map(r):f[e.type]?.(e),f={ArrayExpression:e=>({type:"ArrayExpression",elements:r(e.elements||[])}),ArrayPattern:e=>({type:"ArrayPattern",elements:r(e.elements||[])}),ArrowFunctionExpression:e=>({type:"ArrowFunctionExpression",params:r(e.params||[]),body:r(e.body),...p({async:e.async})}),AssignmentExpression:e=>({type:"AssignmentExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),AssignmentProperty:e=>({type:"Property",key:r(e.key),value:r(e.value),...p({shorthand:e.shorthand})}),AwaitExpression:e=>({type:"AwaitExpression",argument:r(e.argument)}),BinaryExpression:e=>({type:"BinaryExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),BlockStatement:e=>({type:"BlockStatement",body:r(e.body||[])}),BreakStatement:e=>({type:"BreakStatement",...p({label:r(e.label)})}),CallExpression:e=>({type:"CallExpression",callee:r(e.callee),arguments:r(e.arguments||[]),...p({optional:e.optional})}),CatchClause:e=>({type:"CatchClause",param:r(e.param||[]),body:r(e.body)}),ChainExpression:e=>({type:"ChainExpression",expression:r(e.expression)}),ConditionalExpression:e=>({type:"ConditionalExpression",test:r(e.test),consequent:r(e.consequent),alternate:r(e.alternate)}),ContinueStatement:e=>({type:"ContinueStatement",...p({label:r(e.label)})}),DoWhileStatement:e=>({type:"DoWhileStatement",body:r(e.body),test:r(e.test)}),EmptyStatement:()=>({type:"EmptyStatement"}),ExpressionStatement:e=>({type:"ExpressionStatement",expression:r(e.expression)}),ForInStatement:e=>({type:"ForInStatement",left:r(e.left),right:r(e.right),body:r(e.body)}),ForOfStatement:e=>({type:"ForOfStatement",left:r(e.left),right:r(e.right),body:r(e.body),...p({await:e.await})}),ForStatement:e=>({type:"ForStatement",body:r(e.body),...p({init:r(e.init),test:r(e.test),update:r(e.update)})}),FunctionDeclaration:e=>({type:"FunctionDeclaration",id:r(e.id),params:r(e.params||[]),body:r(e.body),...p(pick(e,["async"]))}),FunctionExpression:e=>({type:"FunctionExpression",params:r(e.params||[]),body:r(e.body),...p({id:e.id?r(e.id):false,async:e.async})}),Identifier:e=>({type:"Identifier",name:e.name}),Placeholder:()=>({type:"Placeholder"}),IfStatement:e=>({type:"IfStatement",test:r(e.test),consequent:r(e.consequent),alternate:r(e.alternate)}),JsonExpression:e=>({type:"JsonExpression",body:e.body}),Literal:e=>({type:"Literal",value:e.value,raw:e.raw}),LogicalExpression:e=>({type:"LogicalExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),MemberExpression:e=>({type:"MemberExpression",object:r(e.object),property:r(e.property),...p(pick(e,["computed","optional"]))}),NewExpression:e=>({type:"NewExpression",callee:r(e.callee),arguments:r(e.arguments||[])}),ObjectExpression:e=>({type:"JsonExpression",body:u(e)}),ObjectPattern:e=>({type:"ObjectPattern",properties:r(e.properties||[])}),Program:e=>({type:"Program",body:r(e.body)}),Property:e=>({type:"Property",key:r(e.key),value:r(e.value),...p(pick(e,["kind","shorthand","computed"]))}),ReturnStatement:e=>({type:"ReturnStatement",argument:r(e.argument)}),SwitchCase:e=>({type:"SwitchCase",test:r(e.test),consequent:r(e.consequent)}),SwitchStatement:e=>({type:"SwitchStatement",discriminant:r(e.discriminant),cases:r(e.cases)}),TemplateElement:e=>({type:"TemplateElement",value:e.value,...p({tail:e.tail})}),TemplateLiteral:e=>({type:"TemplateLiteral",quasis:r(e.quasis),expressions:r(e.expressions)}),ThrowStatement:e=>({type:"ThrowStatement",argument:r(e.argument)}),TryStatement:e=>({type:"TryStatement",block:r(e.block),handler:r(e.handler),finalizer:r(e.finalizer)}),UnaryExpression:e=>({type:"UnaryExpression",operator:e.operator,argument:r(e.argument)}),UpdateExpression:e=>({type:"UpdateExpression",operator:e.operator,argument:r(e.argument),...p({prefix:e.prefix})}),VariableDeclaration:e=>({type:"VariableDeclaration",kind:e.kind,declarations:r(e.declarations||[])}),VariableDeclarator:e=>({type:"VariableDeclarator",id:r(e.id),init:r(e.init)}),WhileStatement:e=>({type:"WhileStatement",test:r(e.test),body:r(e.body)}),SpreadElement:e=>({type:"SpreadElement",argument:r(e.argument)}),RestElement:e=>({type:"RestElement",argument:r(e.argument)})};function n(e,t=new WeakMap){if(e==null)return e;if(typeof e!="object")throw new TSLiteError("not-an-object","AST node must be an object");if(t.has(e))throw new TSLiteError("circular-reference","Circular reference detected in AST",{phase:"ast"});t.set(e,true);try{if(Array.isArray(e))return e.map(l=>n(l,t));let s=e;if(s.type==="JsonExpression")return b(s.body,t);if(typeof s.type=="string"&&S[s.type])return S[s.type](s,t);throw new TSLiteError("unknown-node-type",`Unknown node type: ${s.type}`,{type:s.type})}finally{t.delete(e);}}function b(e,t=new WeakMap){if(e===null||typeof e!="object")return a.literal(e);if(t.has(e))throw new TSLiteError("circular-reference","Circular reference detected in JSON",{phase:"json"});t.set(e,true);try{if(Array.isArray(e))return a.arrayExpression(e.map(i=>b(i,t)));let s=e;if("#expr"in s){let i=s["#expr"];if(!isValidExpressionEntryType(i))throw invalidExpressionEntryError(i);let m={...s,type:i};return delete m["#expr"],w(m,t)}let l=Object.entries(s).map(([i,m])=>a.property(a.identifier(i),b(m,t),!1,!1));return a.objectExpression(l)}finally{t.delete(e);}}function w(e,t){if(typeof e.type!="string")throw new TSLiteError("missing-node-type","AST node must have a type property");if(!S[e.type])throw new TSLiteError("unknown-node-type",`Unknown AST node type: ${e.type}`,{type:e.type});return S[e.type](e,t)}var S={ArrayExpression:(e,t)=>a.arrayExpression(o(e.elements,t)),ArrayPattern:(e,t)=>a.arrayPattern(o(e.elements,t)),ArrowFunctionExpression:(e,t)=>a.arrowFunctionExpression(o(e.params,t),n(e.body,t),e.async||false,e.generator||false),AssignmentExpression:(e,t)=>a.assignmentExpression(e.operator,n(e.left,t),n(e.right,t)),AssignmentProperty:(e,t)=>a.assignmentProperty(n(e.key,t),n(e.value,t),e.shorthand||false),AwaitExpression:(e,t)=>a.awaitExpression(n(e.argument,t)),BinaryExpression:(e,t)=>a.binaryExpression(e.operator,n(e.left,t),n(e.right,t)),BlockStatement:(e,t)=>a.blockStatement(o(e.body,t)),BreakStatement:(e,t)=>a.breakStatement(e.label?n(e.label,t):null),CallExpression:(e,t)=>a.callExpression(n(e.callee,t),o(e.arguments,t),e.optional||false),CatchClause:(e,t)=>a.catchClause(e.param?n(e.param,t):null,n(e.body,t)),ChainExpression:(e,t)=>a.chainExpression(n(e.expression,t)),ConditionalExpression:(e,t)=>a.conditionalExpression(n(e.test,t),n(e.consequent,t),n(e.alternate,t)),ContinueStatement:(e,t)=>a.continueStatement(e.label?n(e.label,t):null),DoWhileStatement:(e,t)=>a.doWhileStatement(n(e.body,t),n(e.test,t)),EmptyStatement:()=>a.emptyStatement(),ExpressionStatement:(e,t)=>a.expressionStatement(n(e.expression,t)),ForInStatement:(e,t)=>a.forInStatement(n(e.left,t),n(e.right,t),n(e.body,t)),ForOfStatement:(e,t)=>a.forOfStatement(n(e.left,t),n(e.right,t),n(e.body,t),e.await||false),ForStatement:(e,t)=>a.forStatement(e.init?n(e.init,t):null,e.test?n(e.test,t):null,e.update?n(e.update,t):null,n(e.body,t)),FunctionDeclaration:(e,t)=>a.functionDeclaration(n(e.id,t),o(e.params,t),n(e.body,t),e.generator||false,e.async||false),FunctionExpression:(e,t)=>a.functionExpression(e.id?n(e.id,t):null,o(e.params,t),n(e.body,t),e.async||false,e.generator||false),Identifier:e=>a.identifier(e.name),Placeholder:()=>a.placeholder(),IfStatement:(e,t)=>a.ifStatement(n(e.test,t),n(e.consequent,t),e.alternate?n(e.alternate,t):null),Literal:e=>a.literal(e.value),LogicalExpression:(e,t)=>a.logicalExpression(e.operator,n(e.left,t),n(e.right,t)),MemberExpression:(e,t)=>a.memberExpression(n(e.object,t),n(e.property,t),e.computed||false,e.optional||false),NewExpression:(e,t)=>a.newExpression(n(e.callee,t),o(e.arguments,t)),ObjectExpression:(e,t)=>a.objectExpression(o(e.properties,t)),ObjectPattern:(e,t)=>a.objectPattern(o(e.properties,t)),Program:(e,t)=>a.program(o(e.body,t)),Property:(e,t)=>a.property(n(e.key,t),n(e.value,t),e.shorthand||false,e.computed||false),RestElement:(e,t)=>a.restElement(n(e.argument,t)),ReturnStatement:(e,t)=>a.returnStatement(e.argument?n(e.argument,t):null),SpreadElement:(e,t)=>a.spreadElement(n(e.argument,t)),SwitchCase:(e,t)=>a.switchCase(e.test?n(e.test,t):null,o(e.consequent,t)),SwitchStatement:(e,t)=>a.switchStatement(n(e.discriminant,t),o(e.cases,t)),TemplateElement:e=>a.templateElement(e.value,e.tail||false),TemplateLiteral:(e,t)=>a.templateLiteral(o(e.quasis,t),o(e.expressions,t)),ThrowStatement:(e,t)=>a.throwStatement(n(e.argument,t)),TryStatement:(e,t)=>a.tryStatement(n(e.block,t),e.handler?n(e.handler,t):null,e.finalizer?n(e.finalizer,t):null),UnaryExpression:(e,t)=>a.unaryExpression(e.operator,n(e.argument,t)),UpdateExpression:(e,t)=>a.updateExpression(e.operator,n(e.argument,t),e.prefix||false),VariableDeclaration:(e,t)=>a.variableDeclaration(e.kind,o(e.declarations,t)),VariableDeclarator:(e,t)=>a.variableDeclarator(n(e.id,t),e.init?n(e.init,t):null),WhileStatement:(e,t)=>a.whileStatement(n(e.test,t),n(e.body,t))};function o(e,t){return e?e.map(s=>s!=null?n(s,t):null):[]}export{n as decode,r as encode,b as fromJson,u as objectToJson,c as valueToJson};
1
+ import {print}from'@tslite/printer';import {pick,TSLiteError,isValidExpressionEntryType,invalidExpressionEntryError}from'@tslite/core';import*as a from'@tslite/core/builders';var c=e=>{if(e.type==="Literal")return e.value;if(e.type==="ArrayExpression")return e.elements.map(c);if(e.type==="ObjectExpression")return b(e);let t=r(e);if(t&&typeof t=="object"&&"type"in t){let{type:s,...l}=t;return {"#expr":s,...l}}return {"#expr":"Unknown",value:t}},d=e=>e.type==="Literal"?e.value:print(e);function b(e){let t=e.properties.flatMap(s=>{if(s.type==="SpreadElement"){let i=c(s.argument);return typeof i=="object"&&i!==null&&!Array.isArray(i)&&!("#expr"in i)?Object.entries(i):[["...spread",{"#expr":"SpreadElement",argument:r(s)?.argument}]]}let l=d(s.key);return s.computed?[[`[${l}]`,c(s.value)]]:[[l,c(s.value)]]});return Object.fromEntries(t)}var p=e=>{let t={};for(let s in e)e[s]==false||e[s]==null||(t[s]=e[s]);return t},r=e=>!e||typeof e!="object"?e:Array.isArray(e)?e.map(r):f[e.type]?.(e),f={ArrayExpression:e=>({type:"ArrayExpression",elements:r(e.elements||[])}),ArrayPattern:e=>({type:"ArrayPattern",elements:r(e.elements||[])}),ArrowFunctionExpression:e=>({type:"ArrowFunctionExpression",params:r(e.params||[]),body:r(e.body),...p({async:e.async})}),AssignmentExpression:e=>({type:"AssignmentExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),AssignmentProperty:e=>({type:"Property",key:r(e.key),value:r(e.value),...p({shorthand:e.shorthand})}),AwaitExpression:e=>({type:"AwaitExpression",argument:r(e.argument)}),BinaryExpression:e=>({type:"BinaryExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),BlockStatement:e=>({type:"BlockStatement",body:r(e.body||[])}),BreakStatement:e=>({type:"BreakStatement",...p({label:r(e.label)})}),CallExpression:e=>({type:"CallExpression",callee:r(e.callee),arguments:r(e.arguments||[]),...p({optional:e.optional})}),CatchClause:e=>({type:"CatchClause",param:r(e.param||[]),body:r(e.body)}),ChainExpression:e=>({type:"ChainExpression",expression:r(e.expression)}),ConditionalExpression:e=>({type:"ConditionalExpression",test:r(e.test),consequent:r(e.consequent),alternate:r(e.alternate)}),ContinueStatement:e=>({type:"ContinueStatement",...p({label:r(e.label)})}),DoWhileStatement:e=>({type:"DoWhileStatement",body:r(e.body),test:r(e.test)}),EmptyStatement:()=>({type:"EmptyStatement"}),ExpressionStatement:e=>({type:"ExpressionStatement",expression:r(e.expression)}),ForInStatement:e=>({type:"ForInStatement",left:r(e.left),right:r(e.right),body:r(e.body)}),ForOfStatement:e=>({type:"ForOfStatement",left:r(e.left),right:r(e.right),body:r(e.body),...p({await:e.await})}),ForStatement:e=>({type:"ForStatement",body:r(e.body),...p({init:r(e.init),test:r(e.test),update:r(e.update)})}),FunctionDeclaration:e=>({type:"FunctionDeclaration",id:r(e.id),params:r(e.params||[]),body:r(e.body),...p(pick(e,["async"]))}),FunctionExpression:e=>({type:"FunctionExpression",params:r(e.params||[]),body:r(e.body),...p({id:e.id?r(e.id):false,async:e.async})}),Identifier:e=>({type:"Identifier",name:e.name}),Placeholder:()=>({type:"Placeholder"}),IfStatement:e=>({type:"IfStatement",test:r(e.test),consequent:r(e.consequent),alternate:r(e.alternate)}),JsonExpression:e=>({type:"JsonExpression",body:e.body}),Literal:e=>({type:"Literal",value:e.value,raw:e.raw}),LogicalExpression:e=>({type:"LogicalExpression",operator:e.operator,left:r(e.left),right:r(e.right)}),MemberExpression:e=>({type:"MemberExpression",object:r(e.object),property:r(e.property),...p(pick(e,["computed","optional"]))}),ObjectExpression:e=>({type:"JsonExpression",body:b(e)}),ObjectPattern:e=>({type:"ObjectPattern",properties:r(e.properties||[])}),Program:e=>({type:"Program",body:r(e.body)}),Property:e=>({type:"Property",key:r(e.key),value:r(e.value),...p(pick(e,["kind","shorthand","computed"]))}),ReturnStatement:e=>({type:"ReturnStatement",argument:r(e.argument)}),SwitchCase:e=>({type:"SwitchCase",test:r(e.test),consequent:r(e.consequent)}),SwitchStatement:e=>({type:"SwitchStatement",discriminant:r(e.discriminant),cases:r(e.cases)}),TemplateElement:e=>({type:"TemplateElement",value:e.value,...p({tail:e.tail})}),TemplateLiteral:e=>({type:"TemplateLiteral",quasis:r(e.quasis),expressions:r(e.expressions)}),ThrowStatement:e=>({type:"ThrowStatement",argument:r(e.argument)}),TryStatement:e=>({type:"TryStatement",block:r(e.block),handler:r(e.handler),finalizer:r(e.finalizer)}),UnaryExpression:e=>({type:"UnaryExpression",operator:e.operator,argument:r(e.argument)}),UpdateExpression:e=>({type:"UpdateExpression",operator:e.operator,argument:r(e.argument),...p({prefix:e.prefix})}),VariableDeclaration:e=>({type:"VariableDeclaration",kind:e.kind,declarations:r(e.declarations||[])}),VariableDeclarator:e=>({type:"VariableDeclarator",id:r(e.id),init:r(e.init)}),WhileStatement:e=>({type:"WhileStatement",test:r(e.test),body:r(e.body)}),SpreadElement:e=>({type:"SpreadElement",argument:r(e.argument)}),RestElement:e=>({type:"RestElement",argument:r(e.argument)})};function n(e,t=new WeakMap){if(e==null)return e;if(typeof e!="object")throw new TSLiteError("not-an-object","AST node must be an object");if(t.has(e))throw new TSLiteError("circular-reference","Circular reference detected in AST",{phase:"ast"});t.set(e,true);try{if(Array.isArray(e))return e.map(l=>n(l,t));let s=e;if(s.type==="JsonExpression")return u(s.body,t);if(typeof s.type=="string"&&S[s.type])return S[s.type](s,t);throw new TSLiteError("unknown-node-type",`Unknown node type: ${s.type}`,{type:s.type})}finally{t.delete(e);}}function u(e,t=new WeakMap){if(e===null||typeof e!="object")return a.literal(e);if(t.has(e))throw new TSLiteError("circular-reference","Circular reference detected in JSON",{phase:"json"});t.set(e,true);try{if(Array.isArray(e))return a.arrayExpression(e.map(i=>u(i,t)));let s=e;if("#expr"in s){let i=s["#expr"];if(!isValidExpressionEntryType(i))throw invalidExpressionEntryError(i);let m={...s,type:i};return delete m["#expr"],w(m,t)}let l=Object.entries(s).map(([i,m])=>a.property(a.identifier(i),u(m,t),!1,!1));return a.objectExpression(l)}finally{t.delete(e);}}function w(e,t){if(typeof e.type!="string")throw new TSLiteError("missing-node-type","AST node must have a type property");if(!S[e.type])throw new TSLiteError("unknown-node-type",`Unknown AST node type: ${e.type}`,{type:e.type});return S[e.type](e,t)}var S={ArrayExpression:(e,t)=>a.arrayExpression(o(e.elements,t)),ArrayPattern:(e,t)=>a.arrayPattern(o(e.elements,t)),ArrowFunctionExpression:(e,t)=>a.arrowFunctionExpression(o(e.params,t),n(e.body,t),e.async||false,e.generator||false),AssignmentExpression:(e,t)=>a.assignmentExpression(e.operator,n(e.left,t),n(e.right,t)),AssignmentProperty:(e,t)=>a.assignmentProperty(n(e.key,t),n(e.value,t),e.shorthand||false),AwaitExpression:(e,t)=>a.awaitExpression(n(e.argument,t)),BinaryExpression:(e,t)=>a.binaryExpression(e.operator,n(e.left,t),n(e.right,t)),BlockStatement:(e,t)=>a.blockStatement(o(e.body,t)),BreakStatement:(e,t)=>a.breakStatement(e.label?n(e.label,t):null),CallExpression:(e,t)=>a.callExpression(n(e.callee,t),o(e.arguments,t),e.optional||false),CatchClause:(e,t)=>a.catchClause(e.param?n(e.param,t):null,n(e.body,t)),ChainExpression:(e,t)=>a.chainExpression(n(e.expression,t)),ConditionalExpression:(e,t)=>a.conditionalExpression(n(e.test,t),n(e.consequent,t),n(e.alternate,t)),ContinueStatement:(e,t)=>a.continueStatement(e.label?n(e.label,t):null),DoWhileStatement:(e,t)=>a.doWhileStatement(n(e.body,t),n(e.test,t)),EmptyStatement:()=>a.emptyStatement(),ExpressionStatement:(e,t)=>a.expressionStatement(n(e.expression,t)),ForInStatement:(e,t)=>a.forInStatement(n(e.left,t),n(e.right,t),n(e.body,t)),ForOfStatement:(e,t)=>a.forOfStatement(n(e.left,t),n(e.right,t),n(e.body,t),e.await||false),ForStatement:(e,t)=>a.forStatement(e.init?n(e.init,t):null,e.test?n(e.test,t):null,e.update?n(e.update,t):null,n(e.body,t)),FunctionDeclaration:(e,t)=>a.functionDeclaration(n(e.id,t),o(e.params,t),n(e.body,t),e.generator||false,e.async||false),FunctionExpression:(e,t)=>a.functionExpression(e.id?n(e.id,t):null,o(e.params,t),n(e.body,t),e.async||false,e.generator||false),Identifier:e=>a.identifier(e.name),Placeholder:()=>a.placeholder(),IfStatement:(e,t)=>a.ifStatement(n(e.test,t),n(e.consequent,t),e.alternate?n(e.alternate,t):null),Literal:e=>a.literal(e.value),LogicalExpression:(e,t)=>a.logicalExpression(e.operator,n(e.left,t),n(e.right,t)),MemberExpression:(e,t)=>a.memberExpression(n(e.object,t),n(e.property,t),e.computed||false,e.optional||false),ObjectExpression:(e,t)=>a.objectExpression(o(e.properties,t)),ObjectPattern:(e,t)=>a.objectPattern(o(e.properties,t)),Program:(e,t)=>a.program(o(e.body,t)),Property:(e,t)=>a.property(n(e.key,t),n(e.value,t),e.shorthand||false,e.computed||false),RestElement:(e,t)=>a.restElement(n(e.argument,t)),ReturnStatement:(e,t)=>a.returnStatement(e.argument?n(e.argument,t):null),SpreadElement:(e,t)=>a.spreadElement(n(e.argument,t)),SwitchCase:(e,t)=>a.switchCase(e.test?n(e.test,t):null,o(e.consequent,t)),SwitchStatement:(e,t)=>a.switchStatement(n(e.discriminant,t),o(e.cases,t)),TemplateElement:e=>a.templateElement(e.value,e.tail||false),TemplateLiteral:(e,t)=>a.templateLiteral(o(e.quasis,t),o(e.expressions,t)),ThrowStatement:(e,t)=>a.throwStatement(n(e.argument,t)),TryStatement:(e,t)=>a.tryStatement(n(e.block,t),e.handler?n(e.handler,t):null,e.finalizer?n(e.finalizer,t):null),UnaryExpression:(e,t)=>a.unaryExpression(e.operator,n(e.argument,t)),UpdateExpression:(e,t)=>a.updateExpression(e.operator,n(e.argument,t),e.prefix||false),VariableDeclaration:(e,t)=>a.variableDeclaration(e.kind,o(e.declarations,t)),VariableDeclarator:(e,t)=>a.variableDeclarator(n(e.id,t),e.init?n(e.init,t):null),WhileStatement:(e,t)=>a.whileStatement(n(e.test,t),n(e.body,t))};function o(e,t){return e?e.map(s=>s!=null?n(s,t):null):[]}export{n as decode,r as encode,u as fromJson,b as objectToJson,c as valueToJson};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tslite/codec",
3
- "version": "0.4.2",
3
+ "version": "0.5.1",
4
4
  "description": "TSLite codec — serializes AST to hybrid #expr JSON and back (encode/decode)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -40,8 +40,8 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@tslite/core": "0.6.0",
44
- "@tslite/printer": "0.4.0"
43
+ "@tslite/printer": "0.5.1",
44
+ "@tslite/core": "0.8.0"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "tsup",