graphql-print
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,8 +0,8 @@ | ||
"use strict";var B=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var te=(c,u)=>{for(var f in u)B(c,f,{get:u[f],enumerable:!0})},ie=(c,u,f,L)=>{if(u&&typeof u=="object"||typeof u=="function")for(let y of ee(u))!ne.call(c,y)&&y!==f&&B(c,y,{get:()=>u[y],enumerable:!(L=Z(u,y))||L.enumerable});return c};var ae=c=>ie(B({},"__esModule",{value:!0}),c);var le={};te(le,{print:()=>se});module.exports=ae(le);var s=require("graphql");function o(c){return{type:"text",value:c}}function F(c,u=[],f){return{type:"soft_line",alt:c,prefix:u,indentation:f}}function d(c){return{type:"hard_line",indentation:c}}var _=[s.TokenKind.BRACE_L,s.TokenKind.BRACE_R],oe=[s.TokenKind.BRACKET_L,s.TokenKind.BRACKET_R],j=[s.TokenKind.PAREN_L,s.TokenKind.PAREN_R];function se(c,u={}){return(Array.isArray(c)?c:[c]).map(f=>re(f,u)).join(` | ||
`)}function re(c,{indentationStep:u=" ",maxLineLength:f=80,preserveComments:L=!1,minified:y=!1}){let l={type:"text",value:y?"":" "};function a(e){var r,m;if(!L||!e)return[];let n=[],t=e.prev;for(;(t==null?void 0:t.kind)===s.TokenKind.COMMENT&&t.line!==((r=t.prev)==null?void 0:r.line);)n.unshift({type:"block_comment",token:t}),t=t.prev;let i=e.kind===s.TokenKind.BLOCK_STRING?0:e.line;return((m=e.next)==null?void 0:m.kind)===s.TokenKind.COMMENT&&e.next.line===i&&n.push({type:"inline_comment",token:e.next}),n}function C(e,[n,t],i,r,m=!1){var M,S;let v=a(P((M=e[0].l)==null?void 0:M.startToken,n)),h=a(T((S=e[e.length-1].l)==null?void 0:S.endToken,t)),N=!y&&(m||ce(e)||h.length>0);return[...v,o(n),N?d("+"):F(i,void 0,"+"),...k(e,[N?d():F(r)]),N?d("-"):F(h.length>0?[o(` | ||
`)]:i,void 0,"-"),...h,o(t)]}function U(e){return E(e)?[]:C(e,j,[],[o(","),l])}function w(e,n){if(E(e))return[];let[t,i]=n===s.Kind.DIRECTIVE_DEFINITION||n===s.Kind.FIELD_DEFINITION?[j,!1]:[_,!0];return C(e,t,[],[o(",")],i)}function Y(e){return E(e)?[]:C(e,_,[],[o(",")],!0)}function H(e){return E(e)?[]:C(e,_,[],[o(",")],!0)}function K(e){return E(e)?[]:C(e,_,[],[o(",")],!0)}function O(e,n,t){var M,S;if(E(e))return[];let[i,r,m]=n===s.Kind.UNION_TYPE_DEFINITION||n===s.Kind.UNION_TYPE_EXTENSION?["=",l,s.TokenKind.PIPE]:n===s.Kind.DIRECTIVE_DEFINITION?["on",o(" "),s.TokenKind.PIPE]:["implements",o(" "),s.TokenKind.AMP],v=!1,h=[];for(let x=0;x<e.length;x++){let V=e[x],q=(M=V.l)==null?void 0:M.endToken,z=a(q),b=(S=V.l)==null?void 0:S.endToken.prev;for(;b&&(x===0?b.kind===s.TokenKind.COMMENT:b.kind!==m);)b=b.prev;x===0&&(b==null?void 0:b.kind)!==m&&(b=null);let G=a(b);v=v||z.length>0||G.length>0,h.push({comments:[...G,...z],type:D(V.p).rest})}let N=a(t);N.length===0&&N.push(r),N.push(o(i),r);for(let x=0;x<h.length;x++)N.push(...h[x].comments),y&&x>0&&N.push(o(m)),y||(v&&h[x].comments.length===0&&N.push(d()),v?N.push(o(m+" ")):N.push(F(x===0?[]:[o(" "+m+" ")],[o(m+" ")]))),N.push(...h[x].type);return N}function p(e){return E(e)?[]:[l,...e]}function I(e,n){return e?[...e.p,...!y&&(!L||n.length===0)?[d()]:[]]:[]}function X(e){var r;if(!e)return[];let{comments:n,rest:t}=D(e.p),i=a(P((r=e.l)==null?void 0:r.endToken,s.TokenKind.EQUALS));return[...i,...n,...i.length>0||n.length>0?[]:[l],o("="),l,...t]}let $=(0,s.visit)(c,{Argument:{leave(e){var t,i;let n=e.loc;return{p:[...a((t=e.name.l)==null?void 0:t.endToken),...a(T((i=e.name.l)==null?void 0:i.endToken.next,s.TokenKind.COLON)),...e.name.p,o(":"),l,...e.value.p],l:n}}},BooleanValue:{leave(e){let n=e.loc;return{p:[...a(n==null?void 0:n.endToken),o(""+e.value)],l:n}}},Directive:{leave(e){var t;let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a((t=e.name.l)==null?void 0:t.endToken),o("@"),...e.name.p,...U(e.arguments)],l:n}}},DirectiveDefinition:{leave(e){var M;let n=e.loc,t=T(n==null?void 0:n.startToken,s.TokenKind.NAME),i=T(t==null?void 0:t.next,s.TokenKind.AT),r=T(i==null?void 0:i.next,s.TokenKind.NAME,"on"),m;if(e.repeatable)for(m=r==null?void 0:r.prev;m&&m.kind===s.TokenKind.COMMENT;)m=m.prev;let v=a(m),h=O(e.locations,e.kind,r),N=[...a(t),...a(i),...a((M=e.name.l)==null?void 0:M.endToken)];return{p:[...I(e.description,N),...N,o("directive"),l,o(s.TokenKind.AT),...e.name.p,...w(e.arguments,e.kind),...v,o(e.repeatable?v.length>0?"repeatable":" repeatable":""),...h],l:n}}},Document:{leave(e){let n=e.loc,t=a(n==null?void 0:n.endToken);return{p:[...k(e.definitions.map(i=>{for(;i.p[0].type==="hard_line";)i.p.shift();return i}),[d(),...y?[]:[d()]]),...y||t.length===0?[]:[d(),d()],...t],l:n}}},EnumTypeDefinition:{leave(e){var i;let n=e.loc,t=[...a(T(n==null?void 0:n.startToken,s.TokenKind.NAME)),...a((i=e.name.l)==null?void 0:i.endToken)];return{p:[...I(e.description,t),...t,o("enum "),...e.name.p,...p(k(e.directives||[],[l])),...p(H(e.values))],l:n}}},EnumTypeExtension:{leave(e){var t;let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a(T(n==null?void 0:n.startToken.next,s.TokenKind.NAME)),...a((t=e.name.l)==null?void 0:t.endToken),o("extend enum "),...e.name.p,...p(k(e.directives||[],[l])),...p(H(e.values))],l:n}}},EnumValue:{leave(e){let n=e.loc;return{p:[...a(n==null?void 0:n.endToken),o(e.value)],l:n}}},EnumValueDefinition:{leave(e){var i;let n=e.loc,t=a((i=e.name.l)==null?void 0:i.endToken);return{p:[...I(e.description,t),...t,...e.name.p,...p(k(e.directives||[],[l]))],l:n}}},Field:{leave(e){var t,i,r,m,v;let n=e.loc;return{p:[...a((i=(t=e.alias)==null?void 0:t.l)==null?void 0:i.endToken),...a(e.alias?T((r=n==null?void 0:n.startToken)==null?void 0:r.next,s.TokenKind.COLON):null),...a((m=e.name.l)==null?void 0:m.endToken),...e.alias?[...e.alias.p,o(":"),l]:[],...e.name.p,...U(e.arguments),...p(k(e.directives||[],[l])),...p(((v=e.selectionSet)==null?void 0:v.p)||[])],l:n}}},FieldDefinition:{leave(e){var r,m;let n=e.loc,t=P((r=e.type.l)==null?void 0:r.startToken.prev,s.TokenKind.COLON),i=[...a((m=e.name.l)==null?void 0:m.endToken),...a(t)];return{p:[...I(e.description,i),...i,...e.name.p,...w(e.arguments,e.kind),o(":"),l,...e.type.p,...p(k(e.directives||[],[l]))],l:n}}},FloatValue:{leave(e){let n=e.loc;return{p:[...a(n==null?void 0:n.endToken),o(e.value)],l:n}}},FragmentDefinition:{leave(e){var t,i;let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a((t=e.name.l)==null?void 0:t.endToken),...a(P((i=e.typeCondition.l)==null?void 0:i.endToken.prev,s.TokenKind.NAME)),o("fragment "),...e.name.p,o(" on "),...e.typeCondition.p,...p(k(e.directives||[],[l])),...p(e.selectionSet.p)],l:n}}},FragmentSpread:{leave(e){var t;let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a((t=e.name.l)==null?void 0:t.endToken),o("..."),...e.name.p,...p(k(e.directives||[],[l]))],l:n}}},InlineFragment:{leave(e){var t;let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a(e.typeCondition?P((t=e.typeCondition.l)==null?void 0:t.endToken.prev,s.TokenKind.NAME):null),o("..."),...e.typeCondition?[o("on "),...e.typeCondition.p]:[],...p(k(e.directives||[],[l])),...p(e.selectionSet.p)],l:n}}},InputObjectTypeDefinition:{leave(e){var i;let n=e.loc,t=[...a(T(n==null?void 0:n.startToken,s.TokenKind.NAME)),...a((i=e.name.l)==null?void 0:i.endToken)];return{p:[...I(e.description,t),...t,o("input "),...e.name.p,...p(k(e.directives||[],[l])),...p(w(e.fields,e.kind))],l:n}}},InputObjectTypeExtension:{leave(e){var t,i;let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a(T((t=n==null?void 0:n.startToken)==null?void 0:t.next,s.TokenKind.NAME)),...a((i=e.name.l)==null?void 0:i.endToken),o("extend input "),...e.name.p,...p(k(e.directives||[],[l])),...p(w(e.fields,e.kind))],l:n}}},InputValueDefinition:{leave(e){var i,r;let n=e.loc,t=[...a((i=e.name.l)==null?void 0:i.endToken),...a(T((r=e.name.l)==null?void 0:r.endToken.next,s.TokenKind.COLON))];return{p:[...I(e.description,t),...t,...e.name.p,o(":"),l,...e.type.p,...X(e.defaultValue),...p(k(e.directives||[],[l]))],l:n}}},InterfaceTypeDefinition:{leave(e){var i,r;let n=e.loc,t=[...a(T(n==null?void 0:n.startToken,s.TokenKind.NAME)),...a((i=e.name.l)==null?void 0:i.endToken)];return{p:[...I(e.description,t),...t,o("interface "),...e.name.p,...O(e.interfaces,e.kind,E(e.interfaces)?null:T((r=e.name.l)==null?void 0:r.endToken.next,s.TokenKind.NAME)),...p(k(e.directives||[],[l])),...p(K(e.fields))],l:n}}},InterfaceTypeExtension:{leave(e){var t,i;let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a(T(n==null?void 0:n.startToken.next,s.TokenKind.NAME)),...a((t=e.name.l)==null?void 0:t.endToken),o("extend interface "),...e.name.p,...O(e.interfaces,e.kind,E(e.interfaces)?null:T((i=e.name.l)==null?void 0:i.endToken.next,s.TokenKind.NAME)),...p(k(e.directives||[],[l])),...p(K(e.fields))],l:n}}},IntValue:{leave(e){let n=e.loc;return{p:[...a(n==null?void 0:n.endToken),o(e.value)],l:n}}},ListType:{leave(e){let n=e.loc,{comments:t,rest:i}=D(e.type.p);return{p:[...a(n==null?void 0:n.startToken),...t,...a(n==null?void 0:n.endToken),o("["),...i,o("]")],l:n}}},ListValue:{leave(e){let n=e.loc;return{p:E(e.values)?[...a(n==null?void 0:n.startToken),o(s.TokenKind.BRACKET_L),...a(n==null?void 0:n.endToken),o(s.TokenKind.BRACKET_R)]:C(e.values,oe,[],[o(","),l]),l:n}}},Name:{leave(e){let n=e.loc;return{p:[o(e.value)],l:n}}},NamedType:{leave(e){let n=e.loc;return{p:[...a(n==null?void 0:n.endToken),...e.name.p],l:n}}},NonNullType:{leave(e){let n=e.loc,{comments:t,rest:i}=D(e.type.p);return{p:[...t,...a(n==null?void 0:n.endToken),...i,o("!")],l:n}}},NullValue:{leave(e){let n=e.loc;return{p:[...a(n==null?void 0:n.endToken),o("null")],l:n}}},ObjectField:{leave(e){var t,i;let n=e.loc;return{p:[...a((t=e.name.l)==null?void 0:t.endToken),...a(T((i=e.name.l)==null?void 0:i.endToken.next,s.TokenKind.COLON)),...e.name.p,o(":"),l,...e.value.p],l:n}}},ObjectTypeDefinition:{leave(e){var i,r;let n=e.loc,t=[...a(T(n==null?void 0:n.startToken,s.TokenKind.NAME)),...a((i=e.name.l)==null?void 0:i.endToken)];return{p:[...I(e.description,t),...t,o("type "),...e.name.p,...O(e.interfaces,e.kind,E(e.interfaces)?null:T((r=e.name.l)==null?void 0:r.endToken.next,s.TokenKind.NAME)),...p(k(e.directives||[],[l])),...p(K(e.fields))],l:n}}},ObjectTypeExtension:{leave(e){var t,i;let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a(T(n==null?void 0:n.startToken.next,s.TokenKind.NAME)),...a((t=e.name.l)==null?void 0:t.endToken),o("extend type "),...e.name.p,...O(e.interfaces,e.kind,E(e.interfaces)?null:T((i=e.name.l)==null?void 0:i.endToken.next,s.TokenKind.NAME)),...p(k(e.directives||[],[l])),...p(K(e.fields))],l:n}}},ObjectValue:{leave(e){let n=e.loc;return{p:E(e.fields)?[...a(n==null?void 0:n.startToken),o(s.TokenKind.BRACE_L),...a(n==null?void 0:n.endToken),o(s.TokenKind.BRACE_R)]:C(e.fields,_,[l],[o(","),l]),l:n}}},OperationDefinition:{leave(e){var i,r;let n=e.loc,t=n==null?void 0:n.startToken;return(t==null?void 0:t.kind)===s.TokenKind.BRACE_L?e.selectionSet:{p:[...a(t),...a((r=(i=e.name)==null?void 0:i.l)==null?void 0:r.endToken),o(e.operation),...e.name?[o(" "),...e.name.p]:[],...E(e.variableDefinitions)?[]:C(e.variableDefinitions,j,[],[o(","),l]),...p(k(e.directives||[],[l])),...p(e.selectionSet.p)],l:n}}},OperationTypeDefinition:{leave(e){let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a(T(n==null?void 0:n.startToken.next,s.TokenKind.COLON)),o(e.operation),o(":"),l,...e.type.p],l:n}}},ScalarTypeDefinition:{leave(e){var i;let n=e.loc,t=[...a(T(n==null?void 0:n.startToken,s.TokenKind.NAME)),...a((i=e.name.l)==null?void 0:i.endToken)];return{p:[...I(e.description,t),...t,o("scalar "),...e.name.p,...p(k(e.directives||[],[l]))],l:n}}},ScalarTypeExtension:{leave(e){var t;let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a(T(n==null?void 0:n.startToken.next,s.TokenKind.NAME)),...a((t=e.name.l)==null?void 0:t.endToken),o("extend scalar "),...e.name.p,...p(k(e.directives||[],[l]))],l:n}}},SchemaDefinition:{leave(e){let n=e.loc,t=a(T(n==null?void 0:n.startToken,s.TokenKind.NAME));return{p:[...I(e.description,t),...t,o("schema"),...p(k(e.directives||[],[l])),...p(Y(e.operationTypes))],l:n}}},SchemaExtension:{leave(e){let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a(T(n==null?void 0:n.startToken.next,s.TokenKind.NAME)),o("extend schema"),...p(k(e.directives||[],[l])),...p(Y(e.operationTypes))],l:n}}},SelectionSet:{leave(e){let n=e.loc;return{p:C(e.selections,_,[],[o(",")],!0),l:n}}},StringValue:{leave(e){var r,m;let n=e.loc,t=n==null?void 0:n.endToken,i=[];if(L&&n&&t){let v=t.prev;for(;(v==null?void 0:v.kind)===s.TokenKind.COMMENT&&v.line!==((r=v.prev)==null?void 0:r.line);)i.unshift({type:"block_comment",token:v}),v=v.prev;let h=t.kind===s.TokenKind.BLOCK_STRING?n.source.body.slice(0,t.end).split(` | ||
`).length:t.line;((m=t.next)==null?void 0:m.kind)===s.TokenKind.COMMENT&&t.next.line===h&&i.push({type:"inline_comment",token:t.next})}return{p:[...i,...e.block?[o('"""'),.../[\n\r]/.test(e.value)?[d()]:[],o(e.value.replace(/"""/g,'\\"""')),.../[\n\r]/.test(e.value)?[d()]:[],o('"""')]:[o(JSON.stringify(e.value))]],l:n}}},UnionTypeDefinition:{leave(e){var i,r;let n=e.loc,t=[...a(T(n==null?void 0:n.startToken,s.TokenKind.NAME)),...a((i=e.name.l)==null?void 0:i.endToken)];return{p:[...I(e.description,t),...t,o("union "),...e.name.p,...p(k(e.directives||[],[l])),...O(e.types,e.kind,E(e.types)?null:T((r=e.name.l)==null?void 0:r.endToken.next,s.TokenKind.EQUALS))],l:n}}},UnionTypeExtension:{leave(e){var t,i;let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a(T(n==null?void 0:n.startToken.next,s.TokenKind.NAME)),...a((t=e.name.l)==null?void 0:t.endToken),o("extend union "),...e.name.p,...p(k(e.directives||[],[l])),...O(e.types,e.kind,E(e.types)?null:T((i=e.name.l)==null?void 0:i.endToken.next,s.TokenKind.EQUALS))],l:n}}},Variable:{leave(e){let n=e.loc;return{p:[...a(n==null?void 0:n.startToken),...a(n==null?void 0:n.endToken),o("$"),...e.name.p],l:n}}},VariableDefinition:{leave(e){let n=e.loc,{comments:t,rest:i}=D(e.variable.p);return{p:[...t,...a(T(n==null?void 0:n.startToken.next,s.TokenKind.COLON)),...i,o(":"),l,...e.type.p,...X(e.defaultValue),...p(k(e.directives||[],[l]))],l:n}}}}).p.reduce((e,n)=>{switch(n.type){case"block_comment":case"inline_comment":if(L){if(e.length>0){let t=e[e.length-1].type;t==="text"?e.push(d()):t==="soft_line"&&(e[e.length-1]=d())}e.push(...k(n.token.value.trim().split(` | ||
`).map(t=>({p:[o("#"),l,o(t)],l:void 0})),[d()])),e.push(d())}break;default:e.push(n);break}return e},[]),g="",R=[],A="";function J(e){e==="+"&&(A+=u),e==="-"&&(A=A.slice(u.length))}function Q(e,n){let t="";for(let i=0;i<e.length;i++){let r=e[i];switch(r.type){case"text":t+=r.value;break;case"soft_line":if(n){t=t.trimEnd(),J(r.indentation),t+=` | ||
`+A;for(let m of r.prefix)t+=m.value}else for(let m of r.alt)t+=m.value;break}}return t.trimEnd()}function W(){let e=A+Q(R,!1);y||e.length<=f?g+=e:(g+=A,g+=Q(R,!0)),R=[]}for(let e of $)e.type==="hard_line"?(W(),J(e.indentation),g+=` | ||
`):R.push(e);return W(),g.replace(/^\n*/,"").replace(/\n*$/,y?"":` | ||
`)}function D(c){return c.reduce((u,f)=>{switch(f.type){case"block_comment":case"inline_comment":u.comments.push(f);break;default:u.rest.push(f);break}return u},{comments:[],rest:[]})}function P(c,u){for(;c&&c.kind!==u;)c=c.prev;return c}function T(c,u,f){for(;c&&!(c.kind===u&&(f?c.value===f:!0));)c=c.next;return c}function E(c){return!c||c.length===0}function k(c,u){let f=[];for(let L=0;L<c.length;L++){L>0&&f.push(...u);let y=c[L];f.push(...y.p)}return f}function ce(c){for(let u=0;u<c.length;u++)for(let f=0;f<c[u].p.length;f++){let L=c[u].p[f];if(L.type==="hard_line"||L.type==="block_comment"||L.type==="inline_comment")return!0}return!1}0&&(module.exports={print}); | ||
"use strict";var U=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var se=(i,c)=>{for(var a in c)U(i,a,{get:c[a],enumerable:!0})},ae=(i,c,a,u)=>{if(c&&typeof c=="object"||typeof c=="function")for(let l of ie(c))!oe.call(i,l)&&l!==a&&U(i,l,{get:()=>c[l],enumerable:!(u=re(c,l))||u.enumerable});return i};var ce=i=>ae(U({},"__esModule",{value:!0}),i);var fe={};se(fe,{print:()=>Te});module.exports=ce(fe);var s=require("graphql");function ee(i,c){let a=[{v:!1,i,k:null,e:[],p:null}],u=i;do{let l=a[0].v?a.shift():a[0];if(l.v){let p=ue(l.i,l.e),g=a.length===0,o=Array.isArray(p)?p:c[p.kind](p);g&&(u=o),l.p&&l.p.e.push([l.k,o])}else{l.v=!0;let{i:p}=l;if(Array.isArray(p))for(let g=p.length-1;g>=0;g--)a.unshift({v:!1,i:p[g],k:g,e:[],p:l});else{let g=p;for(let o in g)if(o!=="loc"){let v=g[o];le(v)&&a.unshift({v:!1,i:v,k:o,e:[],p:l})}}}}while(a.length>0);return u}function le(i){return typeof i=="object"&&i!==null||Array.isArray(i)}function ue(i,c){if(c.length===0)return i;if(Array.isArray(i)){let u=Array.from({length:i.length});for(let[l,p]of c)u[l]=p;return u}let a={...i};for(let[u,l]of c)a[u]=l;return a}function w(i,c="",a){return{t:"soft_line",a:i,p:c,i:a}}function h(i){return{t:"hard_line",i}}var _=[s.TokenKind.BRACE_L,s.TokenKind.BRACE_R],pe=[s.TokenKind.BRACKET_L,s.TokenKind.BRACKET_R],Y=[s.TokenKind.PAREN_L,s.TokenKind.PAREN_R];function Te(i,c={}){if(!Array.isArray(i))return ne(i,c);let a="";for(let u=0;u<i.length;u++)u>0&&(a+=` | ||
`),a+=ne(i[u],c);return a}function ne(i,{indentationStep:c=" ",maxLineLength:a=80,preserveComments:u=!1,minified:l=!1}){var Q;let p=l?"":" ",g=(Q=i.loc)==null?void 0:Q.source.body;function o(...e){var t,r;if(!u)return[];let n=[];for(let m=0;m<e.length;m++){let k=e[m];if(!k)continue;let E=n.length,y=k.prev;for(;(y==null?void 0:y.kind)===s.TokenKind.COMMENT&&y.line!==((t=y.prev)==null?void 0:t.line);)n.splice(E,0,{t:"comment",v:y.value}),y=y.prev;let N=k.kind===s.TokenKind.BLOCK_STRING&&g?g.slice(0,k.end).split(` | ||
`).length:k.line;((r=k.next)==null?void 0:r.kind)===s.TokenKind.COMMENT&&k.next.line===N&&n.push({t:"comment",v:k.next.value})}return n}function v(e,[n,t],r,m,k=!1){var O,D;let E=o(P((O=e[0].l)==null?void 0:O.startToken,n)),y=o(f((D=e[e.length-1].l)==null?void 0:D.endToken,t)),N=!l&&(k||y.length>0||me(e));return[...E,n,N?h("+"):w(r,void 0,"+"),...H(e,[N?h():w(m)]),N?h("-"):w(y.length>0?` | ||
`:r,void 0,"-"),...y,t]}function X(e){return R(e)?[]:v(e,Y,"",","+p)}function K(e,n){if(R(e))return[];let[t,r]=n===s.Kind.DIRECTIVE_DEFINITION||n===s.Kind.FIELD_DEFINITION?[Y,!1]:[_,!0];return v(e,t,"",",",r)}function q(e){return R(e)?[]:v(e,_,"",",",!0)}function z(e){return R(e)?[]:v(e,_,"",",",!0)}function V(e){return R(e)?[]:v(e,_,"",",",!0)}function b(e,n){var O,D,G;if(R(e))return[];let[t,r,m,k]=n===s.Kind.UNION_TYPE_DEFINITION||n===s.Kind.UNION_TYPE_EXTENSION?[s.TokenKind.EQUALS,void 0,p,s.TokenKind.PIPE]:n===s.Kind.DIRECTIVE_DEFINITION?[s.TokenKind.NAME,"on"," ",s.TokenKind.PIPE]:[s.TokenKind.NAME,"implements"," ",s.TokenKind.AMP],E=!1,y=[];for(let A=0;A<e.length;A++){let j=e[A],te=(O=j.l)==null?void 0:O.endToken,$=o(te),I=(D=j.l)==null?void 0:D.endToken.prev;for(;I&&(A===0?I.kind===s.TokenKind.COMMENT:I.kind!==k);)I=I.prev;A===0&&(I==null?void 0:I.kind)!==k&&(I=null);let Z=o(I);E=E||$.length>0||Z.length>0,y.push({comments:[...Z,...$],type:F(j.p).rest})}let N=o(P((G=e[0].l)==null?void 0:G.startToken.prev,t,r));N.length===0&&N.push(m),N.push(r||t,m);for(let A=0;A<y.length;A++)N.push(...y[A].comments),l&&A>0&&N.push(k),l||(E&&y[A].comments.length===0&&N.push(h()),E?N.push(k+" "):N.push(w(A===0?"":" "+k+" ",k+" "))),N.push(...y[A].type);return N}function d(e){return R(e)?[]:[p,...e]}function S(e,n){return e?[...e.p,...!l&&(!u||n.length===0)?[h()]:[]]:[]}function J(e){var m;if(!e)return[];let{comments:n,rest:t}=F(e.p),r=o(P((m=e.l)==null?void 0:m.endToken,s.TokenKind.EQUALS));return[...r,...n,...r.length>0||n.length>0?[]:[p],"=",p,...t]}function T(e){return d(H(e||[],[p]))}let L=ee(i,{Argument(e){var n,t;return{p:[...o((n=e.name.l)==null?void 0:n.endToken,f((t=e.name.l)==null?void 0:t.endToken.next,s.TokenKind.COLON)),...e.name.p,":",p,...e.value.p],l:e.loc}},BooleanValue(e){let n=e.loc;return{p:[...o(n==null?void 0:n.endToken),""+e.value],l:n}},Directive(e){var t;let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,(t=e.name.l)==null?void 0:t.endToken),"@",...e.name.p,...X(e.arguments)],l:n}},DirectiveDefinition(e){var y,N,O;let n=e.loc,t=f(n==null?void 0:n.startToken,s.TokenKind.NAME),r=f(t==null?void 0:t.next,s.TokenKind.AT),m=e.repeatable?o(P((N=(y=e.locations[0])==null?void 0:y.l)==null?void 0:N.startToken,s.TokenKind.NAME,"repeatable")):[],k=b(e.locations,e.kind),E=o(t,r,(O=e.name.l)==null?void 0:O.endToken);return{p:[...S(e.description,E),...E,"directive",p,s.TokenKind.AT,...e.name.p,...K(e.arguments,e.kind),...m,e.repeatable?m.length>0?"repeatable":" repeatable":"",...k],l:n}},Document(e){let n=e.loc;return{p:[...H(e.definitions,[h(),...l?[]:[h()]]),...l?[]:[h(),h()],...o(n==null?void 0:n.endToken)],l:n}},EnumTypeDefinition(e){var r;let n=e.loc,t=o(f(n==null?void 0:n.startToken,s.TokenKind.NAME),(r=e.name.l)==null?void 0:r.endToken);return{p:[...S(e.description,t),...t,"enum ",...e.name.p,...T(e.directives),...d(z(e.values))],l:n}},EnumTypeExtension(e){var t;let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,f(n==null?void 0:n.startToken.next,s.TokenKind.NAME),(t=e.name.l)==null?void 0:t.endToken),"extend enum ",...e.name.p,...T(e.directives),...d(z(e.values))],l:n}},EnumValue(e){let n=e.loc;return{p:[...o(n==null?void 0:n.endToken),e.value],l:n}},EnumValueDefinition(e){var t;let n=o((t=e.name.l)==null?void 0:t.endToken);return{p:[...S(e.description,n),...n,...e.name.p,...T(e.directives)],l:e.loc}},Field(e){var t,r,m,k,E;let n=e.loc;return{p:[...o((r=(t=e.alias)==null?void 0:t.l)==null?void 0:r.endToken,e.alias?f((m=n==null?void 0:n.startToken)==null?void 0:m.next,s.TokenKind.COLON):null,(k=e.name.l)==null?void 0:k.endToken),...e.alias?[...e.alias.p,":",p]:[],...e.name.p,...X(e.arguments),...T(e.directives),...d(((E=e.selectionSet)==null?void 0:E.p)||[])],l:n}},FieldDefinition(e){var r,m;let n=P((r=e.type.l)==null?void 0:r.startToken.prev,s.TokenKind.COLON),t=o((m=e.name.l)==null?void 0:m.endToken,n);return{p:[...S(e.description,t),...t,...e.name.p,...K(e.arguments,e.kind),":",p,...e.type.p,...T(e.directives)],l:e.loc}},FloatValue(e){let n=e.loc;return{p:[...o(n==null?void 0:n.endToken),e.value],l:n}},FragmentDefinition(e){var t,r;let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,(t=e.name.l)==null?void 0:t.endToken,P((r=e.typeCondition.l)==null?void 0:r.endToken.prev,s.TokenKind.NAME)),"fragment ",...e.name.p," on ",...e.typeCondition.p,...T(e.directives),...d(e.selectionSet.p)],l:n}},FragmentSpread(e){var t;let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,(t=e.name.l)==null?void 0:t.endToken),"...",...e.name.p,...T(e.directives)],l:n}},InlineFragment(e){var t;let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,e.typeCondition?P((t=e.typeCondition.l)==null?void 0:t.endToken.prev,s.TokenKind.NAME):null),"...",...e.typeCondition?["on ",...e.typeCondition.p]:[],...T(e.directives),...d(e.selectionSet.p)],l:n}},InputObjectTypeDefinition(e){var r;let n=e.loc,t=o(f(n==null?void 0:n.startToken,s.TokenKind.NAME),(r=e.name.l)==null?void 0:r.endToken);return{p:[...S(e.description,t),...t,"input ",...e.name.p,...T(e.directives),...d(K(e.fields,e.kind))],l:n}},InputObjectTypeExtension(e){var t,r;let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,f((t=n==null?void 0:n.startToken)==null?void 0:t.next,s.TokenKind.NAME),(r=e.name.l)==null?void 0:r.endToken),"extend input ",...e.name.p,...T(e.directives),...d(K(e.fields,e.kind))],l:n}},InputValueDefinition(e){var t,r;let n=o((t=e.name.l)==null?void 0:t.endToken,f((r=e.name.l)==null?void 0:r.endToken.next,s.TokenKind.COLON));return{p:[...S(e.description,n),...n,...e.name.p,":",p,...e.type.p,...J(e.defaultValue),...T(e.directives)],l:e.loc}},InterfaceTypeDefinition(e){var r;let n=e.loc,t=o(f(n==null?void 0:n.startToken,s.TokenKind.NAME),(r=e.name.l)==null?void 0:r.endToken);return{p:[...S(e.description,t),...t,"interface ",...e.name.p,...b(e.interfaces,e.kind),...T(e.directives),...d(V(e.fields))],l:n}},InterfaceTypeExtension(e){var t;let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,f(n==null?void 0:n.startToken.next,s.TokenKind.NAME),(t=e.name.l)==null?void 0:t.endToken),"extend interface ",...e.name.p,...b(e.interfaces,e.kind),...T(e.directives),...d(V(e.fields))],l:n}},IntValue(e){let n=e.loc;return{p:[...o(n==null?void 0:n.endToken),e.value],l:n}},ListType(e){let n=e.loc,{comments:t,rest:r}=F(e.type.p);return{p:[...o(n==null?void 0:n.startToken),...t,...o(n==null?void 0:n.endToken),"[",...r,"]"],l:n}},ListValue(e){let n=e.loc;return{p:R(e.values)?[...o(n==null?void 0:n.startToken),s.TokenKind.BRACKET_L,...o(n==null?void 0:n.endToken),s.TokenKind.BRACKET_R]:v(e.values,pe,"",","+p),l:n}},Name(e){return{p:[e.value],l:e.loc}},NamedType(e){let n=e.loc;return{p:[...o(n==null?void 0:n.endToken),...e.name.p],l:n}},NonNullType(e){let n=e.loc,{comments:t,rest:r}=F(e.type.p);return{p:[...t,...o(n==null?void 0:n.endToken),...r,"!"],l:n}},NullValue(e){let n=e.loc;return{p:[...o(n==null?void 0:n.endToken),"null"],l:n}},ObjectField(e){var t,r;let n=e.loc;return{p:[...o((t=e.name.l)==null?void 0:t.endToken,f((r=e.name.l)==null?void 0:r.endToken.next,s.TokenKind.COLON)),...e.name.p,":",p,...e.value.p],l:n}},ObjectTypeDefinition(e){var r;let n=e.loc,t=[...o(f(n==null?void 0:n.startToken,s.TokenKind.NAME),(r=e.name.l)==null?void 0:r.endToken)];return{p:[...S(e.description,t),...t,"type ",...e.name.p,...b(e.interfaces,e.kind),...T(e.directives),...d(V(e.fields))],l:n}},ObjectTypeExtension(e){var t;let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,f(n==null?void 0:n.startToken.next,s.TokenKind.NAME),(t=e.name.l)==null?void 0:t.endToken),"extend type ",...e.name.p,...b(e.interfaces,e.kind),...T(e.directives),...d(V(e.fields))],l:n}},ObjectValue(e){let n=e.loc;return{p:R(e.fields)?[...o(n==null?void 0:n.startToken),s.TokenKind.BRACE_L,...o(n==null?void 0:n.endToken),s.TokenKind.BRACE_R]:v(e.fields,_,p,","+p),l:n}},OperationDefinition(e){var r,m;let n=e.loc,t=n==null?void 0:n.startToken;return(t==null?void 0:t.kind)===s.TokenKind.BRACE_L?e.selectionSet:{p:[...o(t,(m=(r=e.name)==null?void 0:r.l)==null?void 0:m.endToken),e.operation,...e.name?[" ",...e.name.p]:[],...R(e.variableDefinitions)?[]:v(e.variableDefinitions,Y,"",","+p),...T(e.directives),...d(e.selectionSet.p)],l:n}},OperationTypeDefinition(e){let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,f(n==null?void 0:n.startToken.next,s.TokenKind.COLON)),e.operation,":",p,...e.type.p],l:n}},ScalarTypeDefinition(e){var r;let n=e.loc,t=o(f(n==null?void 0:n.startToken,s.TokenKind.NAME),(r=e.name.l)==null?void 0:r.endToken);return{p:[...S(e.description,t),...t,"scalar ",...e.name.p,...T(e.directives)],l:n}},ScalarTypeExtension(e){var t;let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,f(n==null?void 0:n.startToken.next,s.TokenKind.NAME),(t=e.name.l)==null?void 0:t.endToken),"extend scalar ",...e.name.p,...T(e.directives)],l:n}},SchemaDefinition(e){let n=e.loc,t=o(f(n==null?void 0:n.startToken,s.TokenKind.NAME));return{p:[...S(e.description,t),...t,"schema",...T(e.directives),...d(q(e.operationTypes))],l:n}},SchemaExtension(e){let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,f(n==null?void 0:n.startToken.next,s.TokenKind.NAME)),"extend schema",...T(e.directives),...d(q(e.operationTypes))],l:n}},SelectionSet(e){return{p:v(e.selections,_,"",",",!0),l:e.loc}},StringValue(e){let n=e.loc;return{p:[...o(n==null?void 0:n.endToken),...e.block?['"""',.../[\n\r]/.test(e.value)?[h()]:[],e.value.replace(/"""/g,'\\"""'),.../[\n\r]/.test(e.value)?[h()]:[],'"""']:[JSON.stringify(e.value)]],l:n}},UnionTypeDefinition(e){var r;let n=e.loc,t=o(f(n==null?void 0:n.startToken,s.TokenKind.NAME),(r=e.name.l)==null?void 0:r.endToken);return{p:[...S(e.description,t),...t,"union ",...e.name.p,...T(e.directives),...b(e.types,e.kind)],l:n}},UnionTypeExtension(e){var t;let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,f(n==null?void 0:n.startToken.next,s.TokenKind.NAME),(t=e.name.l)==null?void 0:t.endToken),"extend union ",...e.name.p,...T(e.directives),...b(e.types,e.kind)],l:n}},Variable(e){let n=e.loc;return{p:[...o(n==null?void 0:n.startToken,n==null?void 0:n.endToken),"$",...e.name.p],l:n}},VariableDefinition(e){let n=e.loc,{comments:t,rest:r}=F(e.variable.p);return{p:[...t,...o(f(n==null?void 0:n.startToken.next,s.TokenKind.COLON)),...r,":",p,...e.type.p,...J(e.defaultValue),...T(e.directives)],l:n}}});L.p.push(h());let B="",M="",C="",x="";function W(e){l||(e==="+"&&(x+=c),e==="-"&&(x=x.slice(c.length)))}for(let e=0;e<L.p.length;e++){let n=L.p[e],t=e<L.p.length-1&&typeof L.p[e+1]!="string"&&L.p[e+1].t==="comment";typeof n=="string"?(M+=n,C+=n,t&&L.p.splice(e+1,0,h())):n.t==="hard_line"||n.t==="soft_line"&&t?(M=M.trimEnd(),C=C.trimEnd(),B+=x+(l||x.length+M.length<=a?M:C),W(n.i),B+=` | ||
`,M="",C=""):n.t==="soft_line"?(C=C.trimEnd(),W(n.i),C+=` | ||
`+x,C+=n.p,M+=n.a):u&&(B+=x+"#"+p+n.v.trim()+` | ||
`)}return B.trim()+(l?"":` | ||
`)}function F(i){let c=[],a=[];for(let u=0;u<i.length;u++){let l=i[u];typeof l!="string"&&l.t==="comment"?c.push(l):a.push(l)}return{comments:c,rest:a}}function P(i,c,a){for(;i&&!(i.kind===c&&(a?i.value===a:!0));)i=i.prev;return i}function f(i,c,a){for(;i&&!(i.kind===c&&(a?i.value===a:!0));)i=i.next;return i}function R(i){return!i||i.length===0}function H(i,c){let a=[];for(let u=0;u<i.length;u++)u>0&&a.push(...c),a.push(...i[u].p);return a}function me(i){for(let c=0;c<i.length;c++)for(let a=0;a<i[c].p.length;a++){let u=i[c].p[a];if(typeof u!="string"&&(u.t==="hard_line"||u.t==="comment"))return!0}return!1}0&&(module.exports={print}); |
{ | ||
"name": "graphql-print", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Print any GraphQL AST node, pretty or minified, with or without comments", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34085
120