Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mrleebo/prisma-ast

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mrleebo/prisma-ast - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

28

dist/prisma-ast.cjs.development.js

@@ -226,3 +226,11 @@ 'use strict';

DEF: function DEF() {
_this.SUBRULE(_this.value);
_this.OR([{
ALT: function ALT() {
return _this.SUBRULE(_this.keyedArg);
}
}, {
ALT: function ALT() {
return _this.SUBRULE(_this.value);
}
}]);
}

@@ -753,6 +761,10 @@ });

});
var keyedParams = ctx.keyedArg && ctx.keyedArg.map(function (item) {
return _this6.visit([item]);
});
var pars = (params || keyedParams) && [].concat(params != null ? params : [], keyedParams != null ? keyedParams : []);
return {
type: 'function',
name: name,
params: params
params: pars
};

@@ -1024,4 +1036,3 @@ };

{
var params = field.fieldType.params.map(printValue);
return field.fieldType.name + "(" + params + ")" + suffix;
return "" + printFunction(field.fieldType) + suffix;
}

@@ -1037,2 +1048,7 @@

function printFunction(func) {
var params = func.params ? func.params.map(printValue) : '';
return func.name + "(" + params + ")";
}
function printValue(value) {

@@ -1048,6 +1064,6 @@ switch (typeof value) {

case 'function':
return value.name + "(" + (value.params ? value.params.map(printValue) : '') + ")";
return printFunction(value);
case 'array':
return "[" + value.args.join(', ') + "]";
return "[" + value.args.map(printValue).join(', ') + "]";

@@ -1054,0 +1070,0 @@ default:

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("chevrotain"),t=require("os"),n=e.createToken({name:"Identifier",pattern:/[a-zA-Z]\w*/}),r=e.createToken({name:"Datasource",pattern:/datasource/,push_mode:"block"}),a=e.createToken({name:"Generator",pattern:/generator/,push_mode:"block"}),u=e.createToken({name:"Model",pattern:/model/,push_mode:"block"}),i=e.createToken({name:"Enum",pattern:/enum/,push_mode:"block"}),o=e.createToken({name:"True",pattern:/true/,longer_alt:n}),c=e.createToken({name:"False",pattern:/false/,longer_alt:n}),s=e.createToken({name:"Null",pattern:/null/,longer_alt:n}),m=e.createToken({name:"Comment",pattern:e.Lexer.NA}),p=e.createToken({name:"DocComment",pattern:/\/\/\/\s*(.+)/,categories:[m]}),l=e.createToken({name:"LineComment",pattern:/\/\/\s*(.+)/,categories:[m]}),f=e.createToken({name:"Attribute",pattern:e.Lexer.NA}),L=e.createToken({name:"ModelAttribute",pattern:/@@/,label:"'@@'",categories:[f]}),E=e.createToken({name:"FieldAttribute",pattern:/@/,label:"'@'",categories:[f]}),y=e.createToken({name:"Dot",pattern:/\./,label:"'.'"}),d=e.createToken({name:"QuestionMark",pattern:/\?/,label:"'?'"}),h=e.createToken({name:"Array",pattern:/\[\]/,label:"'[]'"}),b=e.createToken({name:"LCurly",pattern:/{/,label:"'{'"}),v=e.createToken({name:"RCurly",pattern:/}/,label:"'}'",pop_mode:!0}),g=e.createToken({name:"LRound",pattern:/\(/,label:"'('"}),A=e.createToken({name:"RRound",pattern:/\)/,label:"')'"}),U=e.createToken({name:"LSquare",pattern:/\[/,label:"'['"}),k=e.createToken({name:"RSquare",pattern:/\]/,label:"']'"}),S=e.createToken({name:"Comma",pattern:/,/,label:"','"}),O=e.createToken({name:"Colon",pattern:/:/,label:"':'"}),T=e.createToken({name:"Equals",pattern:/=/,label:"'='"}),B=e.createToken({name:"StringLiteral",pattern:/"(:?[^\\"\n\r]+|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/}),N=e.createToken({name:"NumberLiteral",pattern:/-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/}),M=e.createToken({name:"WhiteSpace",pattern:/\s+/,group:e.Lexer.SKIPPED}),C=e.createToken({name:"LineBreak",pattern:/\n|\r\n/,line_breaks:!0,label:"LineBreak"}),R=[m,p,l,C,M],w={modes:{global:[].concat(R,[r,a,u,i]),block:[].concat(R,[f,L,E,y,d,h,b,v,U,k,g,A,S,O,T,o,c,s,B,N,n])},defaultMode:"global"},j=new e.Lexer(w);function x(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var _=new(function(e){function t(){var t;return(t=e.call(this,w)||this).break=t.RULE("break",(function(){t.CONSUME1(C),t.CONSUME2(C)})),t.keyedArg=t.RULE("keyedArg",(function(){t.CONSUME(n,{LABEL:"keyName"}),t.CONSUME(O),t.SUBRULE(t.value)})),t.array=t.RULE("array",(function(){t.CONSUME(U),t.MANY_SEP({SEP:S,DEF:function(){t.SUBRULE(t.value)}}),t.CONSUME(k)})),t.func=t.RULE("func",(function(){t.CONSUME(n,{LABEL:"funcName"}),t.CONSUME(g),t.MANY_SEP({SEP:S,DEF:function(){t.SUBRULE(t.value)}}),t.CONSUME(A)})),t.value=t.RULE("value",(function(){t.OR([{ALT:function(){return t.CONSUME(B,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(N,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.array,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.func,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(o,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(c,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(s,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"value"})}}])})),t.property=t.RULE("property",(function(){t.CONSUME(n,{LABEL:"propertyName"}),t.CONSUME(T),t.SUBRULE(t.value,{LABEL:"propertyValue"})})),t.assignment=t.RULE("assignment",(function(){t.CONSUME(n,{LABEL:"assignmentName"}),t.CONSUME(T),t.SUBRULE(t.value,{LABEL:"assignmentValue"})})),t.field=t.RULE("field",(function(){t.CONSUME(n,{LABEL:"fieldName"}),t.SUBRULE(t.value,{LABEL:"fieldType"}),t.OPTION1((function(){t.OR([{ALT:function(){return t.CONSUME(h,{LABEL:"array"})}},{ALT:function(){return t.CONSUME(d,{LABEL:"optional"})}}])})),t.MANY((function(){t.SUBRULE(t.attribute,{LABEL:"attributeList"})})),t.OPTION2((function(){t.CONSUME(m,{LABEL:"comment"})}))})),t.block=t.RULE("block",(function(e){var n=(void 0===e?{}:e).componentType,r="enum"===n,a="model"===n;t.CONSUME(b),t.CONSUME1(C),t.MANY((function(){t.OR([{ALT:function(){return t.SUBRULE(t.comment,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return t.SUBRULE(t.property,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.attribute,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return t.SUBRULE(t.field,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return t.SUBRULE(t.enum,{LABEL:"list"})}},{GATE:function(){return!a},ALT:function(){return t.SUBRULE(t.assignment,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.break,{LABEL:"list"})}},{ALT:function(){return t.CONSUME2(C)}}])})),t.CONSUME(v)})),t.enum=t.RULE("enum",(function(){t.CONSUME(n,{LABEL:"enumName"}),t.OPTION((function(){t.CONSUME(m,{LABEL:"comment"})}))})),t.attribute=t.RULE("attribute",(function(){t.OR1([{ALT:function(){return t.CONSUME(L,{LABEL:"modelAttribute"})}},{ALT:function(){return t.CONSUME(E,{LABEL:"fieldAttribute"})}}]),t.OR2([{ALT:function(){t.CONSUME1(n,{LABEL:"groupName"}),t.CONSUME(y),t.CONSUME2(n,{LABEL:"attributeName"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"attributeName"})}}]),t.OPTION((function(){t.CONSUME(g),t.MANY_SEP({SEP:S,DEF:function(){t.SUBRULE(t.attributeArg)}}),t.CONSUME(A)}))})),t.attributeArg=t.RULE("attributeArg",(function(){t.OR([{ALT:function(){return t.SUBRULE(t.keyedArg,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.value,{LABEL:"value"})}}])})),t.component=t.RULE("component",(function(){var e=t.OR1([{ALT:function(){return t.CONSUME(r,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(a,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(u,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(i,{LABEL:"type"})}}]);t.OR2([{ALT:function(){t.CONSUME1(n,{LABEL:"groupName"}),t.CONSUME(y),t.CONSUME2(n,{LABEL:"componentName"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"componentName"})}}]),t.SUBRULE(t.block,{ARGS:[{componentType:e.image}]})})),t.comment=t.RULE("comment",(function(){t.CONSUME(m,{LABEL:"text"})})),t.schema=t.RULE("schema",(function(){t.MANY((function(){t.OR([{ALT:function(){return t.SUBRULE(t.comment,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.component,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.break,{LABEL:"list"})}},{ALT:function(){return t.CONSUME(C)}}])}))})),t.performSelfAnalysis(),t}return x(t,e),t}(e.CstParser)),P=function(e){function t(){var t;return(t=e.call(this)||this).validateVisitor(),t}x(t,e);var n=t.prototype;return n.schema=function(e){var t,n=this;return{type:"schema",list:(null==(t=e.list)?void 0:t.map((function(e){return n.visit([e])})))||[]}},n.component=function(e){var t=e.type[0].image,n=e.componentName[0].image,r=this.visit(e.block);switch(t){case"datasource":return{type:"datasource",name:n,assignments:r};case"generator":return{type:"generator",name:n,assignments:r};case"model":return{type:"model",name:n,properties:r};case"enum":return{type:"enum",name:n,enumerators:r};default:throw new Error("Unexpected block type: "+t)}},n.break=function(){return{type:"break"}},n.comment=function(e){return{type:"comment",text:e.text[0].image}},n.block=function(e){var t,n=this;return null==(t=e.list)?void 0:t.map((function(e){return n.visit([e])}))},n.assignment=function(e){var t=this.visit(e.assignmentValue);return{type:"assignment",key:e.assignmentName[0].image,value:t}},n.field=function(e){var t,n,r=this,a=this.visit(e.fieldType),u=e.fieldName[0].image,i=e.attributeList&&e.attributeList.map((function(e){return r.visit([e])})),o=null==(t=e.comment)||null==(n=t[0])?void 0:n.image;return{type:"field",name:u,fieldType:a,array:null!=e.array,optional:null!=e.optional,attributes:i,comment:o}},n.attribute=function(e){var t=this,n=e.attributeName[0].image,r=(e.groupName||[{}])[0].image,a=e.attributeArg&&e.attributeArg.map((function(e){return t.visit(e)}));return{type:"attribute",name:n,kind:null!=e.modelAttribute?"model":"field",group:r,args:a}},n.attributeArg=function(e){return{type:"attributeArgument",value:this.visit(e.value)}},n.func=function(e){var t=this;return{type:"function",name:e.funcName[0].image,params:e.value&&e.value.map((function(e){return t.visit([e])}))}},n.array=function(e){var t=this;return{type:"array",args:e.value&&e.value.map((function(e){return t.visit([e])}))}},n.keyedArg=function(e){return{type:"keyValue",key:e.keyName[0].image,value:this.visit(e.value)}},n.value=function(e){return"image"in e.value[0]?e.value[0].image:this.visit(e.value)},n.enum=function(e){var t,n;return{type:"enumerator",name:e.enumName[0].image,comment:null==(t=e.comment)||null==(n=t[0])?void 0:n.image}},t}(_.getBaseCstVisitorConstructorWithDefaults());function I(e){var t=j.tokenize(e);_.input=t.tokens;var n=_.schema();if(_.errors.length>0)throw _.errors[0];return(new P).visit(n)}var V=["break","comment"],D=["generator","datasource","model","enum","break","comment"];function F(e,n){void 0===n&&(n={});var r=n.sort,a=n.locales,u=void 0===a?void 0:a,i=n.sortOrder,o=void 0===i?void 0:i,c=e.list;if(void 0!==r&&r){c=e.list=c.filter((function(e){return"break"!==e.type}));var s=function(e,t,n){return void 0===n&&(n=D),function(r,a){if(-1!==V.indexOf(r.type)!=(-1!==V.indexOf(a.type)))return e.list.indexOf(r)-e.list.indexOf(a);n!==D&&(n=n.concat(D));var u=n.indexOf(r.type)-n.indexOf(a.type);return 0!==u?u:"name"in r&&"name"in a?r.name.localeCompare(a.name,t):0}}(e,u,o);c.sort(s)}return c.map(G).filter(Boolean).join(t.EOL).replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL)+t.EOL}function G(e){switch(e.type){case"comment":return Y(e);case"datasource":return r=H((n=e).assignments),"\ndatasource "+n.name+" {\n "+r+"\n}";case"enum":return function(e){var n=e.enumerators.map(z).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" ");return"\nenum "+e.name+" {\n "+n+"\n}"}(e);case"generator":return function(e){var t=H(e.assignments);return"\ngenerator "+e.name+" {\n "+t+"\n}"}(e);case"model":return function(e){var n,r,a,u,i,o=(r=0,a=(n=e.properties).reduce((function(e,t,n,a){return"break"===t.type||(n>0&&"break"===a[n-1].type&&(e[++r]=[]),e[r].push(t)),e}),[[]]),u=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?t.name.length:0)}),0)})),i=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?Q(t).length:0)}),0)})),n.map((function(e,t,n){return t>0&&"break"!==e.type&&"break"===n[t-1].type&&(u.shift(),i.shift()),function(e,t,n){switch(void 0===t&&(t=0),void 0===n&&(n=0),e.type){case"attribute":return W(e);case"field":return function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=0);var r=e.name.padEnd(t),a=Q(e).padEnd(n),u=e.attributes?e.attributes.map(W):[],i=e.comment;return[r,a].concat(u).filter(Boolean).join(" ").trim()+(i?" "+i:"")}(e,t,n);case"comment":return Y(e);case"break":return q();default:throw new Error("Unrecognized property type")}}(e,u[0],i[0])})).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" "));return"\nmodel "+e.name+" {\n "+o+"\n}"}(e);case"break":return q();default:throw new Error("Unrecognized block type")}var n,r}function Y(e){return e.text}function q(){return t.EOL}function z(e){switch(e.type){case"enumerator":return[e.name,e.comment].filter(Boolean).join(" ");case"attribute":return W(e);case"comment":return Y(e);case"break":return q();default:throw new Error("Unexpected enumerator type")}}function W(e){var t=e.args&&e.args.length>0?"("+e.args.map(K).filter(Boolean).join(", ")+")":"",n=[e.name];return e.group&&n.unshift(e.group),("field"===e.kind?"@":"@@")+n.join(".")+t}function K(e){return Z(e.value)}function Q(e){var t=e.array?"[]":e.optional?"?":"";if("object"==typeof e.fieldType)switch(e.fieldType.type){case"function":var n=e.fieldType.params.map(Z);return e.fieldType.name+"("+n+")"+t;default:throw new Error("Unexpected field type")}return""+e.fieldType+t}function Z(e){switch(typeof e){case"object":if("type"in e)switch(e.type){case"keyValue":return e.key+": "+Z(e.value);case"function":return e.name+"("+(e.params?e.params.map(Z):"")+")";case"array":return"["+e.args.join(", ")+"]";default:throw new Error("Unexpected value type")}throw new Error("Unexpected object value");default:return String(e)}}function H(e){var n=0,r=e.reduce((function(e,t,r,a){return"break"===t.type||(r>0&&"break"===a[r-1].type&&(e[++n]=[]),e[n].push(t)),e}),[[]]).map((function(e){return e.reduce((function(e,t){return Math.max(e,"assignment"===t.type?t.key.length:0)}),0)}));return e.map((function(e,t,n){return t>0&&"break"!==e.type&&"break"===n[t-1].type&&r.shift(),function(e,t){switch(void 0===t&&(t=0),e.type){case"comment":return Y(e);case"break":return q();case"assignment":return e.key.padEnd(t)+" = "+Z(e.value);default:throw new Error("Unexpected assignment type")}}(e,r[0])})).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" ")}var J=function(){function e(e){void 0===e&&(e=""),this.schema=I(e)}var t=e.prototype;return t.print=function(e){return void 0===e&&(e={}),F(this.schema,e)},t.getSchema=function(){return this.schema},t.generator=function(e,t){var n=this.schema.list.reduce((function(t,n){return"generator"===n.type&&n.name===e?n:t}),{type:"generator",name:e,assignments:[{type:"assignment",key:"provider",value:'"'+t+'"'}]});return this.schema.list.push(n),this._subject=n,this},t.drop=function(e){var t=this.schema.list.findIndex((function(t){return"name"in t&&t.name===e}));return this.schema.list.splice(t,1),this},t.datasource=function(e,t){var n={type:"datasource",name:"db",assignments:[{type:"assignment",key:"url",value:"string"==typeof t?'"'+t+'"':{type:"function",name:"env",params:['"'+t.env+'"']}},{type:"assignment",key:"provider",value:e}]},r=this.schema.list.findIndex((function(e){return"datasource"===e.type}));return this.schema.list.splice(r,-1!==r?1:0,n),this._subject=n,this},t.model=function(e){var t={type:"model",name:e,properties:[]};return this.schema.list.push(t),this._subject=t,this},t.enum=function(e,t){void 0===t&&(t=[]);var n={type:"enum",name:e,enumerators:t.map((function(e){return{type:"enumerator",name:e}}))};return this.schema.list.push(n),this._subject=n,this},t.enumerator=function(e){var t=this.getSubject();if(!t||!("type"in t)||"enum"!==t.type)throw new Error("Subject must be a prisma model!");return t.enumerators.push({type:"enumerator",name:e}),this},t.getSubject=function(){return this._subject},t.getParent=function(){return this._parent},t.blockAttribute=function(e,t){var n=this.getSubject();if(!n||!("type"in n)||"model"!==n.type){var r=this.getParent();if(!r||!("type"in r)||"model"!==r.type)throw new Error("Subject must be a prisma model!");n=this._subject=r}var a=t?"string"==typeof t?[{type:"attributeArgument",value:'"'+t+'"'}]:Array.isArray(t)?[{type:"attributeArgument",value:{type:"array",args:t}}]:Object.entries(t).map((function(e){return{type:"attributeArgument",value:{type:"keyValue",key:e[0],value:e[1]}}})):[];return n.properties.push({type:"attribute",kind:"model",name:e,args:a}),this},t.attribute=function(e,t){var n=this.getParent(),r=this.getSubject();if(!n||!("type"in n)||"model"!==n.type)throw new Error("Parent must be a prisma model!");if(!r||!("type"in r)||"field"!==r.type)throw new Error("Subject must be a prisma field!");r.attributes||(r.attributes=[]);var a=r.attributes.reduce((function(t,n){return"attribute"===n.type&&n.name===e?n:t}),{type:"attribute",kind:"field",name:e});if(Array.isArray(t)){var u=function e(t){var n,r;return"string"==typeof t?t:{type:"function",name:t.name,params:null!=(n=null==(r=t.function)?void 0:r.map(e))?n:[]}};t.length>0&&(a.args=t.map((function(e){return{type:"attributeArgument",value:u(e)}})))}else"object"==typeof t&&(a.args=Object.entries(t).map((function(e){return{type:"attributeArgument",value:{type:"keyValue",key:e[0],value:{type:"array",args:e[1]}}}})));return r.attributes.includes(a)||r.attributes.push(a),this},t.assignment=function(e,t){var n=this.getSubject();if(!n||!("type"in n)||!["generator","datasource"].includes(n.type))throw new Error("Subject must be a prisma generator or datasource!");var r=n.assignments.reduce((function(n,r){return"assignment"===r.type&&r.key===e?function(e,n){return e.value='"'+t+'"',e}(r):n}),{type:"assignment",key:e,value:'"'+t+'"'});return n.assignments.includes(r)||n.assignments.push(r),this},t.blockInsert=function(e){var t=this.getSubject(),n=["datasource","enum","generator","model"];if(!t||!("type"in t)||!n.includes(t.type)){var r=this.getParent();if(!r||!("type"in r)||!n.includes(r.type))throw new Error("Subject must be a prisma block!");t=this._subject=r}switch(t.type){case"datasource":t.assignments.push(e);break;case"enum":t.enumerators.push(e);break;case"generator":t.assignments.push(e);break;case"model":t.properties.push(e)}return this},t.break=function(){return this.blockInsert({type:"break"})},t.comment=function(e,t){return void 0===t&&(t=!1),this.blockInsert({type:"comment",text:"//"+(t?"/":"")+" "+e})},t.schemaComment=function(e,t){return void 0===t&&(t=!1),this.schema.list.push({type:"comment",text:"//"+(t?"/":"")+" "+e}),this},t.field=function(e,t){var n=this.getSubject();if(!n||!("type"in n)||"model"!==n.type){var r=this.getParent();if(!r||!("type"in r)||"model"!==r.type)throw new Error("Subject must be a prisma model!");n=this._subject=r}var a={type:"field",name:e,fieldType:t};return n.properties.push(a),this._parent=n,this._subject=a,this},t.then=function(e){return e(this._subject),this},e}();exports.ConcretePrismaSchemaBuilder=J,exports.createPrismaSchemaBuilder=function(e){return new J(e)},exports.getSchema=I,exports.printSchema=F;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("chevrotain"),t=require("os"),n=e.createToken({name:"Identifier",pattern:/[a-zA-Z]\w*/}),r=e.createToken({name:"Datasource",pattern:/datasource/,push_mode:"block"}),a=e.createToken({name:"Generator",pattern:/generator/,push_mode:"block"}),u=e.createToken({name:"Model",pattern:/model/,push_mode:"block"}),i=e.createToken({name:"Enum",pattern:/enum/,push_mode:"block"}),o=e.createToken({name:"True",pattern:/true/,longer_alt:n}),c=e.createToken({name:"False",pattern:/false/,longer_alt:n}),s=e.createToken({name:"Null",pattern:/null/,longer_alt:n}),m=e.createToken({name:"Comment",pattern:e.Lexer.NA}),l=e.createToken({name:"DocComment",pattern:/\/\/\/\s*(.+)/,categories:[m]}),p=e.createToken({name:"LineComment",pattern:/\/\/\s*(.+)/,categories:[m]}),f=e.createToken({name:"Attribute",pattern:e.Lexer.NA}),L=e.createToken({name:"ModelAttribute",pattern:/@@/,label:"'@@'",categories:[f]}),E=e.createToken({name:"FieldAttribute",pattern:/@/,label:"'@'",categories:[f]}),y=e.createToken({name:"Dot",pattern:/\./,label:"'.'"}),d=e.createToken({name:"QuestionMark",pattern:/\?/,label:"'?'"}),h=e.createToken({name:"Array",pattern:/\[\]/,label:"'[]'"}),b=e.createToken({name:"LCurly",pattern:/{/,label:"'{'"}),v=e.createToken({name:"RCurly",pattern:/}/,label:"'}'",pop_mode:!0}),g=e.createToken({name:"LRound",pattern:/\(/,label:"'('"}),A=e.createToken({name:"RRound",pattern:/\)/,label:"')'"}),U=e.createToken({name:"LSquare",pattern:/\[/,label:"'['"}),k=e.createToken({name:"RSquare",pattern:/\]/,label:"']'"}),S=e.createToken({name:"Comma",pattern:/,/,label:"','"}),O=e.createToken({name:"Colon",pattern:/:/,label:"':'"}),T=e.createToken({name:"Equals",pattern:/=/,label:"'='"}),B=e.createToken({name:"StringLiteral",pattern:/"(:?[^\\"\n\r]+|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/}),N=e.createToken({name:"NumberLiteral",pattern:/-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/}),M=e.createToken({name:"WhiteSpace",pattern:/\s+/,group:e.Lexer.SKIPPED}),C=e.createToken({name:"LineBreak",pattern:/\n|\r\n/,line_breaks:!0,label:"LineBreak"}),R=[m,l,p,C,M],w={modes:{global:[].concat(R,[r,a,u,i]),block:[].concat(R,[f,L,E,y,d,h,b,v,U,k,g,A,S,O,T,o,c,s,B,N,n])},defaultMode:"global"},j=new e.Lexer(w);function x(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,(Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var _=new(function(e){function t(){var t;return(t=e.call(this,w)||this).break=t.RULE("break",(function(){t.CONSUME1(C),t.CONSUME2(C)})),t.keyedArg=t.RULE("keyedArg",(function(){t.CONSUME(n,{LABEL:"keyName"}),t.CONSUME(O),t.SUBRULE(t.value)})),t.array=t.RULE("array",(function(){t.CONSUME(U),t.MANY_SEP({SEP:S,DEF:function(){t.SUBRULE(t.value)}}),t.CONSUME(k)})),t.func=t.RULE("func",(function(){t.CONSUME(n,{LABEL:"funcName"}),t.CONSUME(g),t.MANY_SEP({SEP:S,DEF:function(){t.OR([{ALT:function(){return t.SUBRULE(t.keyedArg)}},{ALT:function(){return t.SUBRULE(t.value)}}])}}),t.CONSUME(A)})),t.value=t.RULE("value",(function(){t.OR([{ALT:function(){return t.CONSUME(B,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(N,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.array,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.func,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(o,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(c,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(s,{LABEL:"value"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"value"})}}])})),t.property=t.RULE("property",(function(){t.CONSUME(n,{LABEL:"propertyName"}),t.CONSUME(T),t.SUBRULE(t.value,{LABEL:"propertyValue"})})),t.assignment=t.RULE("assignment",(function(){t.CONSUME(n,{LABEL:"assignmentName"}),t.CONSUME(T),t.SUBRULE(t.value,{LABEL:"assignmentValue"})})),t.field=t.RULE("field",(function(){t.CONSUME(n,{LABEL:"fieldName"}),t.SUBRULE(t.value,{LABEL:"fieldType"}),t.OPTION1((function(){t.OR([{ALT:function(){return t.CONSUME(h,{LABEL:"array"})}},{ALT:function(){return t.CONSUME(d,{LABEL:"optional"})}}])})),t.MANY((function(){t.SUBRULE(t.attribute,{LABEL:"attributeList"})})),t.OPTION2((function(){t.CONSUME(m,{LABEL:"comment"})}))})),t.block=t.RULE("block",(function(e){var n=(void 0===e?{}:e).componentType,r="enum"===n,a="model"===n;t.CONSUME(b),t.CONSUME1(C),t.MANY((function(){t.OR([{ALT:function(){return t.SUBRULE(t.comment,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return t.SUBRULE(t.property,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.attribute,{LABEL:"list"})}},{GATE:function(){return a},ALT:function(){return t.SUBRULE(t.field,{LABEL:"list"})}},{GATE:function(){return r},ALT:function(){return t.SUBRULE(t.enum,{LABEL:"list"})}},{GATE:function(){return!a},ALT:function(){return t.SUBRULE(t.assignment,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.break,{LABEL:"list"})}},{ALT:function(){return t.CONSUME2(C)}}])})),t.CONSUME(v)})),t.enum=t.RULE("enum",(function(){t.CONSUME(n,{LABEL:"enumName"}),t.OPTION((function(){t.CONSUME(m,{LABEL:"comment"})}))})),t.attribute=t.RULE("attribute",(function(){t.OR1([{ALT:function(){return t.CONSUME(L,{LABEL:"modelAttribute"})}},{ALT:function(){return t.CONSUME(E,{LABEL:"fieldAttribute"})}}]),t.OR2([{ALT:function(){t.CONSUME1(n,{LABEL:"groupName"}),t.CONSUME(y),t.CONSUME2(n,{LABEL:"attributeName"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"attributeName"})}}]),t.OPTION((function(){t.CONSUME(g),t.MANY_SEP({SEP:S,DEF:function(){t.SUBRULE(t.attributeArg)}}),t.CONSUME(A)}))})),t.attributeArg=t.RULE("attributeArg",(function(){t.OR([{ALT:function(){return t.SUBRULE(t.keyedArg,{LABEL:"value"})}},{ALT:function(){return t.SUBRULE(t.value,{LABEL:"value"})}}])})),t.component=t.RULE("component",(function(){var e=t.OR1([{ALT:function(){return t.CONSUME(r,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(a,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(u,{LABEL:"type"})}},{ALT:function(){return t.CONSUME(i,{LABEL:"type"})}}]);t.OR2([{ALT:function(){t.CONSUME1(n,{LABEL:"groupName"}),t.CONSUME(y),t.CONSUME2(n,{LABEL:"componentName"})}},{ALT:function(){return t.CONSUME(n,{LABEL:"componentName"})}}]),t.SUBRULE(t.block,{ARGS:[{componentType:e.image}]})})),t.comment=t.RULE("comment",(function(){t.CONSUME(m,{LABEL:"text"})})),t.schema=t.RULE("schema",(function(){t.MANY((function(){t.OR([{ALT:function(){return t.SUBRULE(t.comment,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.component,{LABEL:"list"})}},{ALT:function(){return t.SUBRULE(t.break,{LABEL:"list"})}},{ALT:function(){return t.CONSUME(C)}}])}))})),t.performSelfAnalysis(),t}return x(t,e),t}(e.CstParser)),P=function(e){function t(){var t;return(t=e.call(this)||this).validateVisitor(),t}x(t,e);var n=t.prototype;return n.schema=function(e){var t,n=this;return{type:"schema",list:(null==(t=e.list)?void 0:t.map((function(e){return n.visit([e])})))||[]}},n.component=function(e){var t=e.type[0].image,n=e.componentName[0].image,r=this.visit(e.block);switch(t){case"datasource":return{type:"datasource",name:n,assignments:r};case"generator":return{type:"generator",name:n,assignments:r};case"model":return{type:"model",name:n,properties:r};case"enum":return{type:"enum",name:n,enumerators:r};default:throw new Error("Unexpected block type: "+t)}},n.break=function(){return{type:"break"}},n.comment=function(e){return{type:"comment",text:e.text[0].image}},n.block=function(e){var t,n=this;return null==(t=e.list)?void 0:t.map((function(e){return n.visit([e])}))},n.assignment=function(e){var t=this.visit(e.assignmentValue);return{type:"assignment",key:e.assignmentName[0].image,value:t}},n.field=function(e){var t,n,r=this,a=this.visit(e.fieldType),u=e.fieldName[0].image,i=e.attributeList&&e.attributeList.map((function(e){return r.visit([e])})),o=null==(t=e.comment)||null==(n=t[0])?void 0:n.image;return{type:"field",name:u,fieldType:a,array:null!=e.array,optional:null!=e.optional,attributes:i,comment:o}},n.attribute=function(e){var t=this,n=e.attributeName[0].image,r=(e.groupName||[{}])[0].image,a=e.attributeArg&&e.attributeArg.map((function(e){return t.visit(e)}));return{type:"attribute",name:n,kind:null!=e.modelAttribute?"model":"field",group:r,args:a}},n.attributeArg=function(e){return{type:"attributeArgument",value:this.visit(e.value)}},n.func=function(e){var t=this,n=e.funcName[0].image,r=e.value&&e.value.map((function(e){return t.visit([e])})),a=e.keyedArg&&e.keyedArg.map((function(e){return t.visit([e])}));return{type:"function",name:n,params:(r||a)&&[].concat(null!=r?r:[],null!=a?a:[])}},n.array=function(e){var t=this;return{type:"array",args:e.value&&e.value.map((function(e){return t.visit([e])}))}},n.keyedArg=function(e){return{type:"keyValue",key:e.keyName[0].image,value:this.visit(e.value)}},n.value=function(e){return"image"in e.value[0]?e.value[0].image:this.visit(e.value)},n.enum=function(e){var t,n;return{type:"enumerator",name:e.enumName[0].image,comment:null==(t=e.comment)||null==(n=t[0])?void 0:n.image}},t}(_.getBaseCstVisitorConstructorWithDefaults());function I(e){var t=j.tokenize(e);_.input=t.tokens;var n=_.schema();if(_.errors.length>0)throw _.errors[0];return(new P).visit(n)}var V=["break","comment"],D=["generator","datasource","model","enum","break","comment"];function F(e,n){void 0===n&&(n={});var r=n.sort,a=n.locales,u=void 0===a?void 0:a,i=n.sortOrder,o=void 0===i?void 0:i,c=e.list;if(void 0!==r&&r){c=e.list=c.filter((function(e){return"break"!==e.type}));var s=function(e,t,n){return void 0===n&&(n=D),function(r,a){if(-1!==V.indexOf(r.type)!=(-1!==V.indexOf(a.type)))return e.list.indexOf(r)-e.list.indexOf(a);n!==D&&(n=n.concat(D));var u=n.indexOf(r.type)-n.indexOf(a.type);return 0!==u?u:"name"in r&&"name"in a?r.name.localeCompare(a.name,t):0}}(e,u,o);c.sort(s)}return c.map(G).filter(Boolean).join(t.EOL).replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL)+t.EOL}function G(e){switch(e.type){case"comment":return Y(e);case"datasource":return r=J((n=e).assignments),"\ndatasource "+n.name+" {\n "+r+"\n}";case"enum":return function(e){var n=e.enumerators.map(z).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" ");return"\nenum "+e.name+" {\n "+n+"\n}"}(e);case"generator":return function(e){var t=J(e.assignments);return"\ngenerator "+e.name+" {\n "+t+"\n}"}(e);case"model":return function(e){var n,r,a,u,i,o=(r=0,a=(n=e.properties).reduce((function(e,t,n,a){return"break"===t.type||(n>0&&"break"===a[n-1].type&&(e[++r]=[]),e[r].push(t)),e}),[[]]),u=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?t.name.length:0)}),0)})),i=a.map((function(e){return e.reduce((function(e,t){return Math.max(e,"field"===t.type?Q(t).length:0)}),0)})),n.map((function(e,t,n){return t>0&&"break"!==e.type&&"break"===n[t-1].type&&(u.shift(),i.shift()),function(e,t,n){switch(void 0===t&&(t=0),void 0===n&&(n=0),e.type){case"attribute":return W(e);case"field":return function(e,t,n){void 0===t&&(t=0),void 0===n&&(n=0);var r=e.name.padEnd(t),a=Q(e).padEnd(n),u=e.attributes?e.attributes.map(W):[],i=e.comment;return[r,a].concat(u).filter(Boolean).join(" ").trim()+(i?" "+i:"")}(e,t,n);case"comment":return Y(e);case"break":return q();default:throw new Error("Unrecognized property type")}}(e,u[0],i[0])})).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" "));return"\nmodel "+e.name+" {\n "+o+"\n}"}(e);case"break":return q();default:throw new Error("Unrecognized block type")}var n,r}function Y(e){return e.text}function q(){return t.EOL}function z(e){switch(e.type){case"enumerator":return[e.name,e.comment].filter(Boolean).join(" ");case"attribute":return W(e);case"comment":return Y(e);case"break":return q();default:throw new Error("Unexpected enumerator type")}}function W(e){var t=e.args&&e.args.length>0?"("+e.args.map(K).filter(Boolean).join(", ")+")":"",n=[e.name];return e.group&&n.unshift(e.group),("field"===e.kind?"@":"@@")+n.join(".")+t}function K(e){return H(e.value)}function Q(e){var t=e.array?"[]":e.optional?"?":"";if("object"==typeof e.fieldType)switch(e.fieldType.type){case"function":return""+Z(e.fieldType)+t;default:throw new Error("Unexpected field type")}return""+e.fieldType+t}function Z(e){var t=e.params?e.params.map(H):"";return e.name+"("+t+")"}function H(e){switch(typeof e){case"object":if("type"in e)switch(e.type){case"keyValue":return e.key+": "+H(e.value);case"function":return Z(e);case"array":return"["+e.args.map(H).join(", ")+"]";default:throw new Error("Unexpected value type")}throw new Error("Unexpected object value");default:return String(e)}}function J(e){var n=0,r=e.reduce((function(e,t,r,a){return"break"===t.type||(r>0&&"break"===a[r-1].type&&(e[++n]=[]),e[n].push(t)),e}),[[]]).map((function(e){return e.reduce((function(e,t){return Math.max(e,"assignment"===t.type?t.key.length:0)}),0)}));return e.map((function(e,t,n){return t>0&&"break"!==e.type&&"break"===n[t-1].type&&r.shift(),function(e,t){switch(void 0===t&&(t=0),e.type){case"comment":return Y(e);case"break":return q();case"assignment":return e.key.padEnd(t)+" = "+H(e.value);default:throw new Error("Unexpected assignment type")}}(e,r[0])})).filter(Boolean).join(t.EOL+" ").replace(/(\r?\n\s*){3,}/g,t.EOL+t.EOL+" ")}var X=function(){function e(e){void 0===e&&(e=""),this.schema=I(e)}var t=e.prototype;return t.print=function(e){return void 0===e&&(e={}),F(this.schema,e)},t.getSchema=function(){return this.schema},t.generator=function(e,t){var n=this.schema.list.reduce((function(t,n){return"generator"===n.type&&n.name===e?n:t}),{type:"generator",name:e,assignments:[{type:"assignment",key:"provider",value:'"'+t+'"'}]});return this.schema.list.push(n),this._subject=n,this},t.drop=function(e){var t=this.schema.list.findIndex((function(t){return"name"in t&&t.name===e}));return this.schema.list.splice(t,1),this},t.datasource=function(e,t){var n={type:"datasource",name:"db",assignments:[{type:"assignment",key:"url",value:"string"==typeof t?'"'+t+'"':{type:"function",name:"env",params:['"'+t.env+'"']}},{type:"assignment",key:"provider",value:e}]},r=this.schema.list.findIndex((function(e){return"datasource"===e.type}));return this.schema.list.splice(r,-1!==r?1:0,n),this._subject=n,this},t.model=function(e){var t={type:"model",name:e,properties:[]};return this.schema.list.push(t),this._subject=t,this},t.enum=function(e,t){void 0===t&&(t=[]);var n={type:"enum",name:e,enumerators:t.map((function(e){return{type:"enumerator",name:e}}))};return this.schema.list.push(n),this._subject=n,this},t.enumerator=function(e){var t=this.getSubject();if(!t||!("type"in t)||"enum"!==t.type)throw new Error("Subject must be a prisma model!");return t.enumerators.push({type:"enumerator",name:e}),this},t.getSubject=function(){return this._subject},t.getParent=function(){return this._parent},t.blockAttribute=function(e,t){var n=this.getSubject();if(!n||!("type"in n)||"model"!==n.type){var r=this.getParent();if(!r||!("type"in r)||"model"!==r.type)throw new Error("Subject must be a prisma model!");n=this._subject=r}var a=t?"string"==typeof t?[{type:"attributeArgument",value:'"'+t+'"'}]:Array.isArray(t)?[{type:"attributeArgument",value:{type:"array",args:t}}]:Object.entries(t).map((function(e){return{type:"attributeArgument",value:{type:"keyValue",key:e[0],value:e[1]}}})):[];return n.properties.push({type:"attribute",kind:"model",name:e,args:a}),this},t.attribute=function(e,t){var n=this.getParent(),r=this.getSubject();if(!n||!("type"in n)||"model"!==n.type)throw new Error("Parent must be a prisma model!");if(!r||!("type"in r)||"field"!==r.type)throw new Error("Subject must be a prisma field!");r.attributes||(r.attributes=[]);var a=r.attributes.reduce((function(t,n){return"attribute"===n.type&&n.name===e?n:t}),{type:"attribute",kind:"field",name:e});if(Array.isArray(t)){var u=function e(t){var n,r;return"string"==typeof t?t:{type:"function",name:t.name,params:null!=(n=null==(r=t.function)?void 0:r.map(e))?n:[]}};t.length>0&&(a.args=t.map((function(e){return{type:"attributeArgument",value:u(e)}})))}else"object"==typeof t&&(a.args=Object.entries(t).map((function(e){return{type:"attributeArgument",value:{type:"keyValue",key:e[0],value:{type:"array",args:e[1]}}}})));return r.attributes.includes(a)||r.attributes.push(a),this},t.assignment=function(e,t){var n=this.getSubject();if(!n||!("type"in n)||!["generator","datasource"].includes(n.type))throw new Error("Subject must be a prisma generator or datasource!");var r=n.assignments.reduce((function(n,r){return"assignment"===r.type&&r.key===e?function(e,n){return e.value='"'+t+'"',e}(r):n}),{type:"assignment",key:e,value:'"'+t+'"'});return n.assignments.includes(r)||n.assignments.push(r),this},t.blockInsert=function(e){var t=this.getSubject(),n=["datasource","enum","generator","model"];if(!t||!("type"in t)||!n.includes(t.type)){var r=this.getParent();if(!r||!("type"in r)||!n.includes(r.type))throw new Error("Subject must be a prisma block!");t=this._subject=r}switch(t.type){case"datasource":t.assignments.push(e);break;case"enum":t.enumerators.push(e);break;case"generator":t.assignments.push(e);break;case"model":t.properties.push(e)}return this},t.break=function(){return this.blockInsert({type:"break"})},t.comment=function(e,t){return void 0===t&&(t=!1),this.blockInsert({type:"comment",text:"//"+(t?"/":"")+" "+e})},t.schemaComment=function(e,t){return void 0===t&&(t=!1),this.schema.list.push({type:"comment",text:"//"+(t?"/":"")+" "+e}),this},t.field=function(e,t){var n=this.getSubject();if(!n||!("type"in n)||"model"!==n.type){var r=this.getParent();if(!r||!("type"in r)||"model"!==r.type)throw new Error("Subject must be a prisma model!");n=this._subject=r}var a={type:"field",name:e,fieldType:t};return n.properties.push(a),this._parent=n,this._subject=a,this},t.then=function(e){return e(this._subject),this},e}();exports.ConcretePrismaSchemaBuilder=X,exports.createPrismaSchemaBuilder=function(e){return new X(e)},exports.getSchema=I,exports.printSchema=F;
//# sourceMappingURL=prisma-ast.cjs.production.min.js.map

@@ -222,3 +222,11 @@ import { Lexer, createToken, CstParser } from 'chevrotain';

DEF: function DEF() {
_this.SUBRULE(_this.value);
_this.OR([{
ALT: function ALT() {
return _this.SUBRULE(_this.keyedArg);
}
}, {
ALT: function ALT() {
return _this.SUBRULE(_this.value);
}
}]);
}

@@ -749,6 +757,10 @@ });

});
var keyedParams = ctx.keyedArg && ctx.keyedArg.map(function (item) {
return _this6.visit([item]);
});
var pars = (params || keyedParams) && [].concat(params != null ? params : [], keyedParams != null ? keyedParams : []);
return {
type: 'function',
name: name,
params: params
params: pars
};

@@ -1020,4 +1032,3 @@ };

{
var params = field.fieldType.params.map(printValue);
return field.fieldType.name + "(" + params + ")" + suffix;
return "" + printFunction(field.fieldType) + suffix;
}

@@ -1033,2 +1044,7 @@

function printFunction(func) {
var params = func.params ? func.params.map(printValue) : '';
return func.name + "(" + params + ")";
}
function printValue(value) {

@@ -1044,6 +1060,6 @@ switch (typeof value) {

case 'function':
return value.name + "(" + (value.params ? value.params.map(printValue) : '') + ")";
return printFunction(value);
case 'array':
return "[" + value.args.join(', ') + "]";
return "[" + value.args.map(printValue).join(', ') + "]";

@@ -1050,0 +1066,0 @@ default:

@@ -46,2 +46,3 @@ import { CstNode, IToken } from '@chevrotain/types';

value: CstNode[];
keyedArg: CstNode[];
}): Types.Func;

@@ -48,0 +49,0 @@ array(ctx: CstNode & {

{
"version": "0.4.0",
"version": "0.4.1",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

# @mrleebo/prisma-ast
This library uses an abstract syntax tree to parse schema.prisma files into an object in JavaScript.
This library uses an abstract syntax tree to parse schema.prisma files into an object in JavaScript. It also allows you to update your Prisma schema files using a Builder object pattern that is fully implemented in TypeScript.

@@ -5,0 +5,0 @@ It is similar to [@prisma/sdk](https://github.com/prisma/prisma/tree/master/src/packages/sdk) except that it preserves comments and model attributes. It also doesn't attempt to validate the correctness of the schema at all; the focus is instead on the ability to parse the schema into an object, manipulate it using JavaScript, and re-print the schema back to a file without losing information that isn't captured by other parsers.

@@ -38,3 +38,6 @@ import { CstParser } from 'chevrotain';

DEF: () => {
this.SUBRULE(this.value);
this.OR([
{ ALT: () => this.SUBRULE(this.keyedArg) },
{ ALT: () => this.SUBRULE(this.value) }
])
},

@@ -41,0 +44,0 @@ });

@@ -191,4 +191,3 @@ import * as Types from './getSchema';

case 'function': {
const params = field.fieldType.params.map(printValue);
return `${field.fieldType.name}(${params})${suffix}`;
return `${printFunction(field.fieldType)}${suffix}`;
}

@@ -203,2 +202,7 @@ default:

function printFunction(func: Types.Func) {
const params = func.params ? func.params.map(printValue) : '';
return `${func.name}(${params})`;
}
function printValue(value: Types.KeyValue | Types.Value): string {

@@ -212,7 +216,5 @@ switch (typeof value) {

case 'function':
return `${value.name}(${
value.params ? value.params.map(printValue) : ''
})`;
return printFunction(value);
case 'array':
return `[${value.args.join(', ')}]`;
return `[${value.args.map(printValue).join(', ')}]`;
default:

@@ -219,0 +221,0 @@ throw new Error(`Unexpected value type`);

@@ -112,6 +112,8 @@ import { CstNode, IToken } from '@chevrotain/types';

func(ctx: CstNode & { funcName: [IToken]; value: CstNode[] }): Types.Func {
func(ctx: CstNode & { funcName: [IToken]; value: CstNode[]; keyedArg: CstNode[] }): Types.Func {
const [{ image: name }] = ctx.funcName;
const params = ctx.value && ctx.value.map(item => this.visit([item]));
return { type: 'function', name, params };
const keyedParams = ctx.keyedArg && ctx.keyedArg.map(item => this.visit([item]));
const pars = (params || keyedParams) && [...(params ?? []), ...(keyedParams ?? [])];
return { type: 'function', name, params: pars };
}

@@ -118,0 +120,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc