prettier 3.0.0-alpha.11 → 3.0.0-alpha.12
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/LICENSE +25 -53
- package/bin/prettier.cjs +0 -0
- package/doc.js +35 -86
- package/doc.mjs +48 -94
- package/index.cjs +43 -90
- package/index.d.ts +0 -4
- package/index.mjs +500 -453
- package/internal/cli.mjs +41 -40
- package/package.json +1 -1
- package/plugins/acorn.js +11 -11
- package/plugins/acorn.mjs +11 -11
- package/plugins/angular.js +2 -2
- package/plugins/angular.mjs +2 -2
- package/plugins/babel.js +11 -11
- package/plugins/babel.mjs +11 -11
- package/plugins/estree.js +30 -30
- package/plugins/estree.mjs +30 -30
- package/plugins/flow.js +17 -17
- package/plugins/flow.mjs +17 -17
- package/plugins/glimmer.js +18 -18
- package/plugins/glimmer.mjs +1 -1
- package/plugins/graphql.js +12 -12
- package/plugins/graphql.mjs +1 -1
- package/plugins/html.js +15 -15
- package/plugins/html.mjs +1 -1
- package/plugins/markdown.js +45 -45
- package/plugins/markdown.mjs +45 -45
- package/plugins/meriyah.js +5 -5
- package/plugins/meriyah.mjs +5 -5
- package/plugins/postcss.js +26 -26
- package/plugins/postcss.mjs +6 -6
- package/plugins/typescript.js +7 -7
- package/plugins/typescript.mjs +17 -17
- package/plugins/yaml.js +55 -55
- package/plugins/yaml.mjs +1 -1
- package/standalone.js +26 -28
- package/standalone.mjs +27 -29
package/plugins/yaml.mjs
CHANGED
|
@@ -158,4 +158,4 @@ ${t}`}function Ye(t){return t.position.start.offset}function hr(t){return t.posi
|
|
|
158
158
|
`).map((s,i,o)=>i===0&&i===o.length-1?s:i!==0&&i!==o.length-1?s.trim():i===0?s.trimEnd():s.trimStart());return n.proseWrap==="preserve"?r.map(s=>s.length===0?[]:[s]):r.map(s=>s.length===0?[]:wr(s)).reduce((s,i,o)=>o!==0&&r[o-1].length>0&&i.length>0&&!(t==="quoteDouble"&&D(!1,D(!1,s,-1),-1).endsWith("\\"))?[...s.slice(0,-1),[...D(!1,s,-1),...i]]:[...s,i],[]).map(s=>n.proseWrap==="never"?[s.join(" ")]:s)}function Or(t,{parentIndent:e,isLastDescendant:n,options:r}){let s=t.position.start.line===t.position.end.line?"":r.originalText.slice(t.position.start.offset,t.position.end.offset).match(/^[^\n]*\n(.*)$/s)[1],i;if(t.indent===null){let c=s.match(/^(?<leadingSpace> *)[^\n\r ]/m);i=c?c.groups.leadingSpace.length:Number.POSITIVE_INFINITY}else i=t.indent-1+e;let o=s.split(`
|
|
159
159
|
`).map(c=>c.slice(i));if(r.proseWrap==="preserve"||t.type==="blockLiteral")return a(o.map(c=>c.length===0?[]:[c]));return a(o.map(c=>c.length===0?[]:wr(c)).reduce((c,l,f)=>f!==0&&o[f-1].length>0&&l.length>0&&!/^\s/.test(l[0])&&!/^\s|\s$/.test(D(!1,c,-1))?[...c.slice(0,-1),[...D(!1,c,-1),...l]]:[...c,l],[]).map(c=>c.reduce((l,f)=>l.length>0&&/\s$/.test(D(!1,l,-1))?[...l.slice(0,-1),D(!1,l,-1)+" "+f]:[...l,f],[])).map(c=>r.proseWrap==="never"?[c.join(" ")]:c));function a(c){if(t.chomping==="keep")return D(!1,c,-1).length===0?c.slice(0,-1):c;let l=0;for(let f=c.length-1;f>=0&&c[f].length===0;f--)l++;return l===0?c:l>=2&&!n?c.slice(0,-(l-1)):c.slice(0,-l)}}function ft(t){if(!t)return!0;switch(t.type){case"plain":case"quoteDouble":case"quoteSingle":case"alias":case"flowMapping":case"flowSequence":return!0;default:return!1}}var ut=null;function pt(t){if(ut!==null&&typeof ut.property){let e=ut;return ut=pt.prototype=null,e}return ut=pt.prototype=t??Object.create(null),new pt}var Ui=10;for(let t=0;t<=Ui;t++)pt();function wn(t){return pt(t)}function Ki(t,e="type"){wn(t);function n(r){let s=r[e],i=t[s];if(!Array.isArray(i))throw Object.assign(new Error(`Missing visitor keys for '${s}'.`),{node:r});return i}return n}var Nr=Ki;var Vi=Object.fromEntries(Object.entries({root:["children"],document:["head","body","children"],documentHead:["children"],documentBody:["children"],directive:[],alias:[],blockLiteral:[],blockFolded:["children"],plain:["children"],quoteSingle:[],quoteDouble:[],mapping:["children"],mappingItem:["key","value","children"],mappingKey:["content","children"],mappingValue:["content","children"],sequence:["children"],sequenceItem:["content","children"],flowMapping:["children"],flowMappingItem:["key","value","children"],flowSequence:["children"],flowSequenceItem:["content","children"],comment:[],tag:[],anchor:[]}).map(([t,e])=>[t,[...e,"anchor","tag","indicatorComment","leadingComments","middleComments","trailingComment","endComments"]])),Lr=Vi;var Wi=Nr(Lr),Ar=Wi;function ji(t){return En(t,Qi)}function Qi(t){switch(t.type){case"document":$e(t,"head",()=>t.children[0]),$e(t,"body",()=>t.children[1]);break;case"documentBody":case"sequenceItem":case"flowSequenceItem":case"mappingKey":case"mappingValue":$e(t,"content",()=>t.children[0]);break;case"mappingItem":case"flowMappingItem":$e(t,"key",()=>t.children[0]),$e(t,"value",()=>t.children[1]);break}return t}var Tr=ji;var bn=new WeakMap;function xt(t,e){let{node:n,root:r}=t,s;return bn.has(r)?s=bn.get(r):(s=new Set,bn.set(r,s)),!s.has(n.position.end.line)&&(s.add(n.position.end.line),Er(n,e)&&!On(t.parent))?vt:""}function On(t){return Y(t)&&!H(t,["documentHead","documentBody","flowMapping","flowSequence"])}function _(t,e){return at(" ".repeat(t),e)}function Rt(t,e,n){let{node:r}=t,s=r.type==="flowMapping",i=s?"{":"[",o=s?"}":"]",a=vt;s&&r.children.length>0&&n.bracketSpacing&&(a=re);let c=D(!1,r.children,-1),l=(c==null?void 0:c.type)==="flowMappingItem"&&Fe(c.key)&&Fe(c.value);return[i,_(n.tabWidth,[a,Ji(t,e,n),n.trailingComma==="none"?"":ct(","),Y(r)?[O,I(O,t.map(e,"endComments"))]:""]),l?"":a,o]}function Ji(t,e,n){return t.map(({isLast:r,node:s,next:i})=>[e(),r?"":[",",re,s.position.start.line!==i.position.start.line?xt(t,n.originalText):""]],"children")}function Gi(t,e,n){var M;let{node:r,parent:s}=t,{key:i,value:o}=r,a=Fe(i),c=Fe(o);if(a&&c)return": ";let l=e("key"),f=Hi(r)?" ":"";if(c)return r.type==="flowMappingItem"&&s.type==="flowMapping"?l:r.type==="mappingItem"&&Nn(i.content,n)&&!X(i.content)&&((M=s.tag)==null?void 0:M.value)!=="tag:yaml.org,2002:set"?[l,f,":"]:["? ",_(2,l)];let m=e("value");if(a)return[": ",_(2,m)];if(ee(o)||!ft(i.content))return["? ",_(2,l),O,...t.map(()=>[e(),O],"value","leadingComments"),": ",_(2,m)];if(Xi(i.content)&&!ee(i.content)&&!oe(i.content)&&!X(i.content)&&!Y(i)&&!ee(o.content)&&!oe(o.content)&&!Y(o)&&Nn(o.content,n))return[l,f,": ",m];let d=Symbol("mappingKey"),y=De([ct("? "),De(_(2,l),{id:d})]),h=[O,": ",_(2,m)],g=[f,":"];ee(o.content)||Y(o)&&o.content&&!H(o.content,["mapping","sequence"])||s.type==="mapping"&&X(i.content)&&ft(o.content)||H(o.content,["mapping","sequence"])&&o.content.tag===null&&o.content.anchor===null?g.push(O):o.content&&g.push(re),g.push(m);let w=_(n.tabWidth,g);return Nn(i.content,n)&&!ee(i.content)&&!oe(i.content)&&!Y(i)?hn([[l,w]]):hn([[y,ct(h,w,{groupId:d})]])}function Nn(t,e){if(!t)return!0;switch(t.type){case"plain":case"quoteSingle":case"quoteDouble":break;case"alias":return!0;default:return!1}if(e.proseWrap==="preserve")return t.position.start.line===t.position.end.line;if(/\\$/m.test(e.originalText.slice(t.position.start.offset,t.position.end.offset)))return!1;switch(e.proseWrap){case"never":return!t.value.includes(`
|
|
160
160
|
`);case"always":return!/[\n ]/.test(t.value);default:return!1}}function Hi(t){var e;return((e=t.key.content)==null?void 0:e.type)==="alias"}function Xi(t){if(!t)return!0;switch(t.type){case"plain":case"quoteDouble":case"quoteSingle":return t.position.start.line===t.position.end.line;case"alias":return!0;default:return!1}}var Mr=Gi;function zi(t,e,n){let{node:r}=t,s=t.ancestors.filter(l=>l.type==="sequence"||l.type==="mapping").length,i=Pt(t),o=[r.type==="blockFolded"?">":"|"];r.indent!==null&&o.push(r.indent.toString()),r.chomping!=="clip"&&o.push(r.chomping==="keep"?"+":"-"),Sn(r)&&o.push(" ",e("indicatorComment"));let a=Or(r,{parentIndent:s,isLastDescendant:i,options:n}),c=[];for(let[l,f]of a.entries())l===0&&c.push(O),c.push(Ct(I(re,f))),l!==a.length-1?c.push(f.length===0?O:ir(lt)):r.chomping==="keep"&&i&&c.push(mn(f.length===0?O:lt));return r.indent===null?o.push(or(_(n.tabWidth,c))):o.push(mn(_(r.indent-1+s,c))),o}var Cr=zi;function Zi(t,e,n){let{node:r}=t,s=[];r.type!=="mappingValue"&&ee(r)&&s.push([I(O,t.map(n,"leadingComments")),O]);let{tag:i,anchor:o}=r;i&&s.push(n("tag")),i&&o&&s.push(" "),o&&s.push(n("anchor"));let a="";return H(r,["mapping","sequence","comment","directive","mappingItem","sequenceItem"])&&!Pt(t)&&(a=xt(t,e.originalText)),(i||o)&&(H(r,["sequence","mapping"])&&!oe(r)?s.push(O):s.push(" ")),oe(r)&&s.push([r.middleComments.length===1?"":O,I(O,t.map(n,"middleComments")),O]),Sr(t)?s.push(cr(e.originalText.slice(r.position.start.offset,r.position.end.offset).trimEnd())):s.push(De(eo(t,e,n))),X(r)&&!H(r,["document","documentHead"])&&s.push(ar([r.type==="mappingValue"&&!r.content?"":" ",t.parent.type==="mappingKey"&&t.getParentNode(2).type==="mapping"&&ft(r)?"":kt,n("trailingComment")])),On(r)&&s.push(_(r.type==="sequenceItem"?2:0,[O,I(O,t.map(({node:c})=>[lr(e.originalText,Ye(c))?O:"",n()],"endComments"))])),s.push(a),s}function eo(t,e,n){let{node:r}=t;switch(r.type){case"root":{let s=[];t.each(({node:o,next:a,isFirst:c})=>{c||s.push(O),s.push(n()),kr(o,a)?(s.push(O,"..."),X(o)&&s.push(" ",n("trailingComment"))):a&&!X(a.head)&&s.push(O,"---")},"children");let i=_t(r);return(!H(i,["blockLiteral","blockFolded"])||i.chomping!=="keep")&&s.push(O),s}case"document":{let s=[];return no(t,e)==="head"&&((r.head.children.length>0||r.head.endComments.length>0)&&s.push(n("head")),X(r.head)?s.push(["---"," ",n(["head","trailingComment"])]):s.push("---")),to(r)&&s.push(n("body")),I(O,s)}case"documentHead":return I(O,[...t.map(n,"children"),...t.map(n,"endComments")]);case"documentBody":{let{children:s,endComments:i}=r,o="";if(s.length>0&&i.length>0){let a=_t(r);H(a,["blockFolded","blockLiteral"])?a.chomping!=="keep"&&(o=[O,O]):o=O}return[I(O,t.map(n,"children")),o,I(O,t.map(n,"endComments"))]}case"directive":return["%",I(" ",[r.name,...r.parameters])];case"comment":return["#",r.value];case"alias":return["*",r.value];case"tag":return e.originalText.slice(r.position.start.offset,r.position.end.offset);case"anchor":return["&",r.value];case"plain":return mt(r.type,e.originalText.slice(r.position.start.offset,r.position.end.offset),e);case"quoteDouble":case"quoteSingle":{let s="'",i='"',o=e.originalText.slice(r.position.start.offset+1,r.position.end.offset-1);if(r.type==="quoteSingle"&&o.includes("\\")||r.type==="quoteDouble"&&/\\[^"]/.test(o)){let c=r.type==="quoteDouble"?i:s;return[c,mt(r.type,o,e),c]}if(o.includes(i))return[s,mt(r.type,r.type==="quoteDouble"?At(!1,At(!1,o,'\\"',i),"'",s.repeat(2)):o,e),s];if(o.includes(s))return[i,mt(r.type,r.type==="quoteSingle"?At(!1,o,"''",s):o,e),i];let a=e.singleQuote?s:i;return[a,mt(r.type,o,e),a]}case"blockFolded":case"blockLiteral":return Cr(t,n,e);case"mapping":case"sequence":return I(O,t.map(n,"children"));case"sequenceItem":return["- ",_(2,r.content?n("content"):"")];case"mappingKey":case"mappingValue":return r.content?n("content"):"";case"mappingItem":case"flowMappingItem":return Mr(t,n,e);case"flowMapping":return Rt(t,n,e);case"flowSequence":return Rt(t,n,e);case"flowSequenceItem":return n("content");default:throw new fr(r,"YAML")}}function to(t){return t.body.children.length>0||Y(t.body)}function kr(t,e){return X(t)||e&&(e.head.children.length>0||Y(e.head))}function no(t,e){let n=t.node;if(t.isFirst&&/---(?:\s|$)/.test(e.originalText.slice(Ye(n),Ye(n)+4))||n.head.children.length>0||Y(n.head)||X(n.head))return"head";let r=t.next;return kr(n,r)?!1:r?"root":!1}function mt(t,e,n){let r=br(t,e,n);return I(O,r.map(s=>Ct(I(re,s))))}function ro(t,e){if(H(e))switch(delete e.position,e.type){case"comment":if(ur(e.value))return null;break;case"quoteDouble":case"quoteSingle":e.type="quote";break}}var so={preprocess:Tr,embed:dr,print:Zi,massageAstNode:ro,insertPragma:mr,getVisitorKeys:Ar},vr=so;var cn={};nr(cn,{yaml:()=>ja});var Dt=`
|
|
161
|
-
`,Ir="\r",Pr=function(){function t(e){this.length=e.length;for(var n=[0],r=0;r<e.length;)switch(e[r]){case Dt:r+=Dt.length,n.push(r);break;case Ir:r+=Ir.length,e[r]===Dt&&(r+=Dt.length),n.push(r);break;default:r++;break}this.offsets=n}return t.prototype.locationForIndex=function(e){if(e<0||e>this.length)return null;for(var n=0,r=this.offsets;r[n+1]<=e;)n++;var s=e-r[n];return{line:n,column:s}},t.prototype.indexForLocation=function(e){var n=e.line,r=e.column;return n<0||n>=this.offsets.length||r<0||r>this.lengthOfLine(n)?null:this.offsets[n]+r},t.prototype.lengthOfLine=function(e){var n=this.offsets[e],r=e===this.offsets.length-1?this.length:this.offsets[e+1];return r-n},t}();function F(t,e=null){"children"in t&&t.children.forEach(n=>F(n,t)),"anchor"in t&&t.anchor&&F(t.anchor,t),"tag"in t&&t.tag&&F(t.tag,t),"leadingComments"in t&&t.leadingComments.forEach(n=>F(n,t)),"middleComments"in t&&t.middleComments.forEach(n=>F(n,t)),"indicatorComment"in t&&t.indicatorComment&&F(t.indicatorComment,t),"trailingComment"in t&&t.trailingComment&&F(t.trailingComment,t),"endComments"in t&&t.endComments.forEach(n=>F(n,t)),Object.defineProperty(t,"_parent",{value:e,enumerable:!1})}function Se(t){return`${t.line}:${t.column}`}function _r(t){F(t);let e=io(t),n=t.children.slice();t.comments.sort((r,s)=>r.position.start.offset-s.position.end.offset).filter(r=>!r._parent).forEach(r=>{for(;n.length>1&&r.position.start.line>n[0].position.end.line;)n.shift();oo(r,e,n[0])})}function io(t){let e=Array.from(new Array(t.position.end.line),()=>({}));for(let n of t.comments)e[n.position.start.line-1].comment=n;return xr(e,t),e}function xr(t,e){if(e.position.start.offset!==e.position.end.offset){if("leadingComments"in e){let{start:n}=e.position,{leadingAttachableNode:r}=t[n.line-1];(!r||n.column<r.position.start.column)&&(t[n.line-1].leadingAttachableNode=e)}if("trailingComment"in e&&e.position.end.column>1&&e.type!=="document"&&e.type!=="documentHead"){let{end:n}=e.position,{trailingAttachableNode:r}=t[n.line-1];(!r||n.column>=r.position.end.column)&&(t[n.line-1].trailingAttachableNode=e)}if(e.type!=="root"&&e.type!=="document"&&e.type!=="documentHead"&&e.type!=="documentBody"){let{start:n,end:r}=e.position,s=[r.line].concat(n.line===r.line?[]:n.line);for(let i of s){let o=t[i-1].trailingNode;(!o||r.column>=o.position.end.column)&&(t[i-1].trailingNode=e)}}"children"in e&&e.children.forEach(n=>{xr(t,n)})}}function oo(t,e,n){let r=t.position.start.line,{trailingAttachableNode:s}=e[r-1];if(s){if(s.trailingComment)throw new Error(`Unexpected multiple trailing comment at ${Se(t.position.start)}`);F(t,s),s.trailingComment=t;return}for(let o=r;o>=n.position.start.line;o--){let{trailingNode:a}=e[o-1],c;if(a)c=a;else if(o!==r&&e[o-1].comment)c=e[o-1].comment._parent;else continue;if((c.type==="sequence"||c.type==="mapping")&&(c=c.children[0]),c.type==="mappingItem"){let[l,f]=c.children;c=Rr(l)?l:f}for(;;){if(ao(c,t)){F(t,c),c.endComments.push(t);return}if(!c._parent)break;c=c._parent}break}for(let o=r+1;o<=n.position.end.line;o++){let{leadingAttachableNode:a}=e[o-1];if(a){F(t,a),a.leadingComments.push(t);return}}let i=n.children[1];F(t,i),i.endComments.push(t)}function ao(t,e){if(t.position.start.offset<e.position.start.offset&&t.position.end.offset>e.position.end.offset)switch(t.type){case"flowMapping":case"flowSequence":return t.children.length===0||e.position.start.line>t.children[t.children.length-1].position.end.line}if(e.position.end.offset<t.position.end.offset)return!1;switch(t.type){case"sequenceItem":return e.position.start.column>t.position.start.column;case"mappingKey":case"mappingValue":return e.position.start.column>t._parent.position.start.column&&(t.children.length===0||t.children.length===1&&t.children[0].type!=="blockFolded"&&t.children[0].type!=="blockLiteral")&&(t.type==="mappingValue"||Rr(t));default:return!1}}function Rr(t){return t.position.start!==t.position.end&&(t.children.length===0||t.position.start.offset!==t.children[0].position.start.offset)}function b(t,e){return{type:t,position:e}}function Dr(t,e,n){return{...b("root",t),children:e,comments:n}}function ht(t){switch(t.type){case"DOCUMENT":for(let e=t.contents.length-1;e>=0;e--)t.contents[e].type==="BLANK_LINE"?t.contents.splice(e,1):ht(t.contents[e]);for(let e=t.directives.length-1;e>=0;e--)t.directives[e].type==="BLANK_LINE"&&t.directives.splice(e,1);break;case"FLOW_MAP":case"FLOW_SEQ":case"MAP":case"SEQ":for(let e=t.items.length-1;e>=0;e--){let n=t.items[e];"char"in n||(n.type==="BLANK_LINE"?t.items.splice(e,1):ht(n))}break;case"MAP_KEY":case"MAP_VALUE":case"SEQ_ITEM":t.node&&ht(t.node);break;case"ALIAS":case"BLANK_LINE":case"BLOCK_FOLDED":case"BLOCK_LITERAL":case"COMMENT":case"DIRECTIVE":case"PLAIN":case"QUOTE_DOUBLE":case"QUOTE_SINGLE":break;default:throw new Error(`Unexpected node type ${JSON.stringify(t.type)}`)}}function z(){return{leadingComments:[]}}function ae(t=null){return{trailingComment:t}}function q(){return{...z(),...ae()}}function Yr(t,e,n){return{...b("alias",t),...q(),...e,value:n}}function Br(t,e){let n=t.cstNode;return Yr(e.transformRange({origStart:n.valueRange.origStart-1,origEnd:n.valueRange.origEnd}),e.transformContent(t),n.rawValue)}function $r(t){return{...t,type:"blockFolded"}}function Fr(t,e,n,r,s,i){return{...b("blockValue",t),...z(),...e,chomping:n,indent:r,value:s,indicatorComment:i}}var ce;(function(t){t.Tag="!",t.Anchor="&",t.Comment="#"})(ce||(ce={}));function qr(t,e){return{...b("anchor",t),value:e}}function qe(t,e){return{...b("comment",t),value:e}}function Ur(t,e,n){return{anchor:e,tag:t,middleComments:n}}function Kr(t,e){return{...b("tag",t),value:e}}function Yt(t,e,n=()=>!1){let r=t.cstNode,s=[],i=null,o=null,a=null;for(let c of r.props){let l=e.text[c.origStart];switch(l){case ce.Tag:i=i||c,o=Kr(e.transformRange(c),t.tag);break;case ce.Anchor:i=i||c,a=qr(e.transformRange(c),r.anchor);break;case ce.Comment:{let f=qe(e.transformRange(c),e.text.slice(c.origStart+1,c.origEnd));e.comments.push(f),!n(f)&&i&&i.origEnd<=c.origStart&&c.origEnd<=r.valueRange.origStart&&s.push(f);break}default:throw new Error(`Unexpected leading character ${JSON.stringify(l)}`)}}return Ur(o,a,s)}var Ln;(function(t){t.CLIP="clip",t.STRIP="strip",t.KEEP="keep"})(Ln||(Ln={}));function Bt(t,e){let n=t.cstNode,r=1,s=n.chomping==="CLIP"?0:1,o=n.header.origEnd-n.header.origStart-r-s!==0,a=e.transformRange({origStart:n.header.origStart,origEnd:n.valueRange.origEnd}),c=null,l=Yt(t,e,f=>{if(!(a.start.offset<f.position.start.offset&&f.position.end.offset<a.end.offset))return!1;if(c)throw new Error(`Unexpected multiple indicator comments at ${Se(f.position.start)}`);return c=f,!0});return Fr(a,l,Ln[n.chomping],o?n.blockIndent:null,n.strValue,c)}function Vr(t,e){return $r(Bt(t,e))}function Wr(t){return{...t,type:"blockLiteral"}}function jr(t,e){return Wr(Bt(t,e))}function Qr(t,e){return qe(e.transformRange(t.range),t.comment)}function Jr(t,e,n){return{...b("directive",t),...q(),name:e,parameters:n}}function Ue(t,e){for(let n of t.props){let r=e.text[n.origStart];switch(r){case ce.Comment:e.comments.push(qe(e.transformRange(n),e.text.slice(n.origStart+1,n.origEnd)));break;default:throw new Error(`Unexpected leading character ${JSON.stringify(r)}`)}}}function Gr(t,e){return Ue(t,e),Jr(e.transformRange(t.range),t.name,t.parameters)}function Hr(t,e,n,r){return{...b("document",t),...ae(r),children:[e,n]}}function W(t,e){return{start:t,end:e}}function An(t){return{start:t,end:t}}function U(t=[]){return{endComments:t}}function Xr(t,e,n){return{...b("documentBody",t),...U(n),children:e?[e]:[]}}function K(t){return t[t.length-1]}function $t(t,e){let n=t.match(e);return n?n.index:-1}function zr(t,e,n){let r=t.cstNode,{comments:s,endComments:i,documentTrailingComment:o,documentHeadTrailingComment:a}=co(r,e,n),c=e.transformNode(t.contents),{position:l,documentEndPoint:f}=lo(r,c,e);return e.comments.push(...s,...i),{documentBody:Xr(l,c,i),documentEndPoint:f,documentTrailingComment:o,documentHeadTrailingComment:a}}function co(t,e,n){let r=[],s=[],i=[],o=[],a=!1;for(let c=t.contents.length-1;c>=0;c--){let l=t.contents[c];if(l.type==="COMMENT"){let f=e.transformNode(l);n&&n.line===f.position.start.line?o.unshift(f):a?r.unshift(f):f.position.start.offset>=t.valueRange.origEnd?i.unshift(f):r.unshift(f)}else a=!0}if(i.length>1)throw new Error(`Unexpected multiple document trailing comments at ${Se(i[1].position.start)}`);if(o.length>1)throw new Error(`Unexpected multiple documentHead trailing comments at ${Se(o[1].position.start)}`);return{comments:r,endComments:s,documentTrailingComment:K(i)||null,documentHeadTrailingComment:K(o)||null}}function lo(t,e,n){let r=$t(n.text.slice(t.valueRange.origEnd),/^\.\.\./),s=r===-1?t.valueRange.origEnd:Math.max(0,t.valueRange.origEnd-1);n.text[s-1]==="\r"&&s--;let i=n.transformRange({origStart:e!==null?e.position.start.offset:s,origEnd:s}),o=r===-1?i.end:n.transformOffset(t.valueRange.origEnd+3);return{position:i,documentEndPoint:o}}function Zr(t,e,n,r){return{...b("documentHead",t),...U(n),...ae(r),children:e}}function es(t,e){let n=t.cstNode,{directives:r,comments:s,endComments:i}=fo(n,e),{position:o,endMarkerPoint:a}=uo(n,r,e);return e.comments.push(...s,...i),{createDocumentHeadWithTrailingComment:l=>(l&&e.comments.push(l),Zr(o,r,i,l)),documentHeadEndMarkerPoint:a}}function fo(t,e){let n=[],r=[],s=[],i=!1;for(let o=t.directives.length-1;o>=0;o--){let a=e.transformNode(t.directives[o]);a.type==="comment"?i?r.unshift(a):s.unshift(a):(i=!0,n.unshift(a))}return{directives:n,comments:r,endComments:s}}function uo(t,e,n){let r=$t(n.text.slice(0,t.valueRange.origStart),/---\s*$/);r>0&&!/[\r\n]/.test(n.text[r-1])&&(r=-1);let s=r===-1?{origStart:t.valueRange.origStart,origEnd:t.valueRange.origStart}:{origStart:r,origEnd:r+3};return e.length!==0&&(s.origStart=e[0].position.start.offset),{position:n.transformRange(s),endMarkerPoint:r===-1?null:n.transformOffset(r)}}function ts(t,e){let{createDocumentHeadWithTrailingComment:n,documentHeadEndMarkerPoint:r}=es(t,e),{documentBody:s,documentEndPoint:i,documentTrailingComment:o,documentHeadTrailingComment:a}=zr(t,e,r),c=n(a);return o&&e.comments.push(o),Hr(W(c.position.start,i),c,s,o)}function Ft(t,e,n){return{...b("flowCollection",t),...q(),...U(),...e,children:n}}function ns(t,e,n){return{...Ft(t,e,n),type:"flowMapping"}}function qt(t,e,n){return{...b("flowMappingItem",t),...z(),children:[e,n]}}function le(t,e){let n=[];for(let r of t)r&&"type"in r&&r.type==="COMMENT"?e.comments.push(e.transformNode(r)):n.push(r);return n}function Ut(t){let[e,n]=["?",":"].map(r=>{let s=t.find(i=>"char"in i&&i.char===r);return s?{origStart:s.origOffset,origEnd:s.origOffset+1}:null});return{additionalKeyRange:e,additionalValueRange:n}}function Kt(t,e){let n=e;return r=>t.slice(n,n=r)}function Vt(t){let e=[],n=Kt(t,1),r=!1;for(let s=1;s<t.length-1;s++){let i=t[s];if("char"in i&&i.char===","){e.push(n(s)),n(s+1),r=!1;continue}r=!0}return r&&e.push(n(t.length-1)),e}function Tn(t,e){return{...b("mappingKey",t),...ae(),...U(),children:e?[e]:[]}}function Mn(t,e){return{...b("mappingValue",t),...q(),...U(),children:e?[e]:[]}}function Ke(t,e,n,r,s){let i=e.transformNode(t.key),o=e.transformNode(t.value),a=i||r?Tn(e.transformRange({origStart:r?r.origStart:i.position.start.offset,origEnd:i?i.position.end.offset:r.origStart+1}),i):null,c=o||s?Mn(e.transformRange({origStart:s?s.origStart:o.position.start.offset,origEnd:o?o.position.end.offset:s.origStart+1}),o):null;return n(W(a?a.position.start:c.position.start,c?c.position.end:a.position.end),a||Tn(An(c.position.start),null),c||Mn(An(a.position.end),null))}function rs(t,e){let n=le(t.cstNode.items,e),r=Vt(n),s=t.items.map((a,c)=>{let l=r[c],{additionalKeyRange:f,additionalValueRange:m}=Ut(l);return Ke(a,e,qt,f,m)}),i=n[0],o=K(n);return ns(e.transformRange({origStart:i.origOffset,origEnd:o.origOffset+1}),e.transformContent(t),s)}function ss(t,e,n){return{...Ft(t,e,n),type:"flowSequence"}}function is(t,e){return{...b("flowSequenceItem",t),children:[e]}}function os(t,e){let n=le(t.cstNode.items,e),r=Vt(n),s=t.items.map((a,c)=>{if(a.type!=="PAIR"){let l=e.transformNode(a);return is(W(l.position.start,l.position.end),l)}else{let l=r[c],{additionalKeyRange:f,additionalValueRange:m}=Ut(l);return Ke(a,e,qt,f,m)}}),i=n[0],o=K(n);return ss(e.transformRange({origStart:i.origOffset,origEnd:o.origOffset+1}),e.transformContent(t),s)}function as(t,e,n){return{...b("mapping",t),...z(),...e,children:n}}function cs(t,e,n){return{...b("mappingItem",t),...z(),children:[e,n]}}function ls(t,e){let n=t.cstNode;n.items.filter(o=>o.type==="MAP_KEY"||o.type==="MAP_VALUE").forEach(o=>Ue(o,e));let r=le(n.items,e),s=po(r),i=t.items.map((o,a)=>{let c=s[a],[l,f]=c[0].type==="MAP_VALUE"?[null,c[0].range]:[c[0].range,c.length===1?null:c[1].range];return Ke(o,e,cs,l,f)});return as(W(i[0].position.start,K(i).position.end),e.transformContent(t),i)}function po(t){let e=[],n=Kt(t,0),r=!1;for(let s=0;s<t.length;s++){if(t[s].type==="MAP_VALUE"){e.push(n(s+1)),r=!1;continue}r&&e.push(n(s)),r=!0}return r&&e.push(n(1/0)),e}function fs(t,e,n){return{...b("plain",t),...q(),...e,value:n}}function us(t,e,n){for(let r=e;r>=0;r--)if(n.test(t[r]))return r;return-1}function ps(t,e){let n=t.cstNode;return fs(e.transformRange({origStart:n.valueRange.origStart,origEnd:us(e.text,n.valueRange.origEnd-1,/\S/)+1}),e.transformContent(t),n.strValue)}function ms(t){return{...t,type:"quoteDouble"}}function hs(t,e,n){return{...b("quoteValue",t),...e,...q(),value:n}}function Wt(t,e){let n=t.cstNode;return hs(e.transformRange(n.valueRange),e.transformContent(t),n.strValue)}function gs(t,e){return ms(Wt(t,e))}function ds(t){return{...t,type:"quoteSingle"}}function ys(t,e){return ds(Wt(t,e))}function Es(t,e,n){return{...b("sequence",t),...z(),...U(),...e,children:n}}function Ss(t,e){return{...b("sequenceItem",t),...q(),...U(),children:e?[e]:[]}}function ws(t,e){let r=le(t.cstNode.items,e).map((s,i)=>{Ue(s,e);let o=e.transformNode(t.items[i]);return Ss(W(e.transformOffset(s.valueRange.origStart),o===null?e.transformOffset(s.valueRange.origStart+1):o.position.end),o)});return Es(W(r[0].position.start,K(r).position.end),e.transformContent(t),r)}function bs(t,e){if(t===null||t.type===void 0&&t.value===null)return null;switch(t.type){case"ALIAS":return Br(t,e);case"BLOCK_FOLDED":return Vr(t,e);case"BLOCK_LITERAL":return jr(t,e);case"COMMENT":return Qr(t,e);case"DIRECTIVE":return Gr(t,e);case"DOCUMENT":return ts(t,e);case"FLOW_MAP":return rs(t,e);case"FLOW_SEQ":return os(t,e);case"MAP":return ls(t,e);case"PLAIN":return ps(t,e);case"QUOTE_DOUBLE":return gs(t,e);case"QUOTE_SINGLE":return ys(t,e);case"SEQ":return ws(t,e);default:throw new Error(`Unexpected node type ${t.type}`)}}function Os(t,e,n){let r=new SyntaxError(t);return r.name="YAMLSyntaxError",r.source=e,r.position=n,r}function Ns(t,e){let n=t.source.range||t.source.valueRange;return Os(t.message,e.text,e.transformRange(n))}function Ls(t,e,n){return{offset:t,line:e,column:n}}function As(t,e){t<0?t=0:t>e.text.length&&(t=e.text.length);let n=e.locator.locationForIndex(t);return Ls(t,n.line+1,n.column+1)}function Ts(t,e){return W(e.transformOffset(t.origStart),e.transformOffset(t.origEnd))}function Ms(t){if(!t.setOrigRanges()){let e=n=>{if(mo(n))return n.origStart=n.start,n.origEnd=n.end,!0;if(ho(n))return n.origOffset=n.offset,!0};t.forEach(n=>Cn(n,e))}}function Cn(t,e){if(!(!t||typeof t!="object")&&e(t)!==!0)for(let n of Object.keys(t)){if(n==="context"||n==="error")continue;let r=t[n];Array.isArray(r)?r.forEach(s=>Cn(s,e)):Cn(r,e)}}function mo(t){return typeof t.start=="number"}function ho(t){return typeof t.offset=="number"}function kn(t){if("children"in t){if(t.children.length===1){let e=t.children[0];if(e.type==="plain"&&e.tag===null&&e.anchor===null&&e.value==="")return t.children.splice(0,1),t}t.children.forEach(kn)}return t}function vn(t,e,n,r){let s=e(t);return i=>{r(s,i)&&n(t,s=i)}}function In(t){if(t===null||!("children"in t))return;let e=t.children;if(e.forEach(In),t.type==="document"){let[i,o]=t.children;i.position.start.offset===i.position.end.offset?i.position.start=i.position.end=o.position.start:o.position.start.offset===o.position.end.offset&&(o.position.start=o.position.end=i.position.end)}let n=vn(t.position,go,yo,wo),r=vn(t.position,Eo,So,bo);"endComments"in t&&t.endComments.length!==0&&(n(t.endComments[0].position.start),r(K(t.endComments).position.end));let s=e.filter(i=>i!==null);if(s.length!==0){let i=s[0],o=K(s);n(i.position.start),r(o.position.end),"leadingComments"in i&&i.leadingComments.length!==0&&n(i.leadingComments[0].position.start),"tag"in i&&i.tag&&n(i.tag.position.start),"anchor"in i&&i.anchor&&n(i.anchor.position.start),"trailingComment"in o&&o.trailingComment&&r(o.trailingComment.position.end)}}function go(t){return t.start}function yo(t,e){t.start=e}function Eo(t){return t.end}function So(t,e){t.end=e}function wo(t,e){return e.offset<t.offset}function bo(t,e){return e.offset>t.offset}var di=rr(hi(),1);var G=rr(gi(),1),_m=G.default.findPair,xm=G.default.toJSON,Rm=G.default.parseMap,Dm=G.default.parseSeq,Ym=G.default.stringifyNumber,Bm=G.default.stringifyString,$m=G.default.Type,qa=G.default.YAMLError,Fm=G.default.YAMLReferenceError,er=G.default.YAMLSemanticError,Ua=G.default.YAMLSyntaxError,qm=G.default.YAMLWarning;var{Document:yi,parseCST:Ei}=di.default;function Si(t){let e=Ei(t);Ms(e);let n=e.map(a=>new yi({merge:!1,keepCstNodes:!0}).parse(a)),r=new Pr(t),s=[],i={text:t,locator:r,comments:s,transformOffset:a=>As(a,i),transformRange:a=>Ts(a,i),transformNode:a=>bs(a,i),transformContent:a=>Yt(a,i)};for(let a of n)for(let c of a.errors)if(!(c instanceof er&&c.message==='Map keys must be unique; "<<" is repeated'))throw Ns(c,i);n.forEach(a=>ht(a.cstNode));let o=Dr(i.transformRange({origStart:0,origEnd:i.text.length}),n.map(i.transformNode),s);return _r(o),In(o),kn(o),o}function Va(t,e){let n=new SyntaxError(t+" ("+e.loc.start.line+":"+e.loc.start.column+")");return Object.assign(n,e)}var wi=Va;function Wa(t){try{let e=Si(t);return delete e.comments,e}catch(e){throw e!=null&&e.position?wi(e.message,{loc:e.position,cause:e}):e}}var ja={astFormat:"yaml",parse:Wa,hasPragma:pr,locStart:Ye,locEnd:hr};var bi=[{linguistLanguageId:407,name:"YAML",type:"data",color:"#cb171e",tmScope:"source.yaml",aliases:["yml"],extensions:[".yml",".mir",".reek",".rviz",".sublime-syntax",".syntax",".yaml",".yaml-tmlanguage",".yaml.sed",".yml.mysql"],filenames:[".clang-format",".clang-tidy",".gemrc","CITATION.cff","glide.lock",".prettierrc",".stylelintrc",".lintstagedrc"],aceMode:"yaml",codemirrorMode:"yaml",codemirrorMimeType:"text/x-yaml",parsers:["yaml"],vscodeLanguageIds:["yaml","ansible","home-assistant"]}];var ln={bracketSpacing:{category:"Common",type:"boolean",default:!0,description:"Print spaces between brackets.",oppositeDescription:"Do not print spaces between brackets."},singleQuote:{category:"Common",type:"boolean",default:!1,description:"Use single quotes instead of double quotes."},proseWrap:{category:"Common",type:"choice",default:"preserve",description:"How to wrap prose.",choices:[{value:"always",description:"Wrap prose if it exceeds the print width."},{value:"never",description:"Do not wrap prose."},{value:"preserve",description:"Wrap prose as-is."}]},bracketSameLine:{category:"Common",type:"boolean",default:!1,description:"Put > of opening tags on the last line instead of on a new line."},singleAttributePerLine:{category:"Common",type:"boolean",default:!1,description:"Enforce single attribute per line in HTML, Vue and JSX."}};var Qa={bracketSpacing:ln.bracketSpacing,singleQuote:ln.singleQuote,proseWrap:ln.proseWrap},Oi=Qa;var Ja={yaml:vr};export{tr as default,bi as languages,Oi as options,cn as parsers,Ja as printers};
|
|
161
|
+
`,Ir="\r",Pr=function(){function t(e){this.length=e.length;for(var n=[0],r=0;r<e.length;)switch(e[r]){case Dt:r+=Dt.length,n.push(r);break;case Ir:r+=Ir.length,e[r]===Dt&&(r+=Dt.length),n.push(r);break;default:r++;break}this.offsets=n}return t.prototype.locationForIndex=function(e){if(e<0||e>this.length)return null;for(var n=0,r=this.offsets;r[n+1]<=e;)n++;var s=e-r[n];return{line:n,column:s}},t.prototype.indexForLocation=function(e){var n=e.line,r=e.column;return n<0||n>=this.offsets.length||r<0||r>this.lengthOfLine(n)?null:this.offsets[n]+r},t.prototype.lengthOfLine=function(e){var n=this.offsets[e],r=e===this.offsets.length-1?this.length:this.offsets[e+1];return r-n},t}();function F(t,e=null){"children"in t&&t.children.forEach(n=>F(n,t)),"anchor"in t&&t.anchor&&F(t.anchor,t),"tag"in t&&t.tag&&F(t.tag,t),"leadingComments"in t&&t.leadingComments.forEach(n=>F(n,t)),"middleComments"in t&&t.middleComments.forEach(n=>F(n,t)),"indicatorComment"in t&&t.indicatorComment&&F(t.indicatorComment,t),"trailingComment"in t&&t.trailingComment&&F(t.trailingComment,t),"endComments"in t&&t.endComments.forEach(n=>F(n,t)),Object.defineProperty(t,"_parent",{value:e,enumerable:!1})}function Se(t){return`${t.line}:${t.column}`}function _r(t){F(t);let e=io(t),n=t.children.slice();t.comments.sort((r,s)=>r.position.start.offset-s.position.end.offset).filter(r=>!r._parent).forEach(r=>{for(;n.length>1&&r.position.start.line>n[0].position.end.line;)n.shift();oo(r,e,n[0])})}function io(t){let e=Array.from(new Array(t.position.end.line),()=>({}));for(let n of t.comments)e[n.position.start.line-1].comment=n;return xr(e,t),e}function xr(t,e){if(e.position.start.offset!==e.position.end.offset){if("leadingComments"in e){let{start:n}=e.position,{leadingAttachableNode:r}=t[n.line-1];(!r||n.column<r.position.start.column)&&(t[n.line-1].leadingAttachableNode=e)}if("trailingComment"in e&&e.position.end.column>1&&e.type!=="document"&&e.type!=="documentHead"){let{end:n}=e.position,{trailingAttachableNode:r}=t[n.line-1];(!r||n.column>=r.position.end.column)&&(t[n.line-1].trailingAttachableNode=e)}if(e.type!=="root"&&e.type!=="document"&&e.type!=="documentHead"&&e.type!=="documentBody"){let{start:n,end:r}=e.position,s=[r.line].concat(n.line===r.line?[]:n.line);for(let i of s){let o=t[i-1].trailingNode;(!o||r.column>=o.position.end.column)&&(t[i-1].trailingNode=e)}}"children"in e&&e.children.forEach(n=>{xr(t,n)})}}function oo(t,e,n){let r=t.position.start.line,{trailingAttachableNode:s}=e[r-1];if(s){if(s.trailingComment)throw new Error(`Unexpected multiple trailing comment at ${Se(t.position.start)}`);F(t,s),s.trailingComment=t;return}for(let o=r;o>=n.position.start.line;o--){let{trailingNode:a}=e[o-1],c;if(a)c=a;else if(o!==r&&e[o-1].comment)c=e[o-1].comment._parent;else continue;if((c.type==="sequence"||c.type==="mapping")&&(c=c.children[0]),c.type==="mappingItem"){let[l,f]=c.children;c=Rr(l)?l:f}for(;;){if(ao(c,t)){F(t,c),c.endComments.push(t);return}if(!c._parent)break;c=c._parent}break}for(let o=r+1;o<=n.position.end.line;o++){let{leadingAttachableNode:a}=e[o-1];if(a){F(t,a),a.leadingComments.push(t);return}}let i=n.children[1];F(t,i),i.endComments.push(t)}function ao(t,e){if(t.position.start.offset<e.position.start.offset&&t.position.end.offset>e.position.end.offset)switch(t.type){case"flowMapping":case"flowSequence":return t.children.length===0||e.position.start.line>t.children[t.children.length-1].position.end.line}if(e.position.end.offset<t.position.end.offset)return!1;switch(t.type){case"sequenceItem":return e.position.start.column>t.position.start.column;case"mappingKey":case"mappingValue":return e.position.start.column>t._parent.position.start.column&&(t.children.length===0||t.children.length===1&&t.children[0].type!=="blockFolded"&&t.children[0].type!=="blockLiteral")&&(t.type==="mappingValue"||Rr(t));default:return!1}}function Rr(t){return t.position.start!==t.position.end&&(t.children.length===0||t.position.start.offset!==t.children[0].position.start.offset)}function b(t,e){return{type:t,position:e}}function Dr(t,e,n){return{...b("root",t),children:e,comments:n}}function ht(t){switch(t.type){case"DOCUMENT":for(let e=t.contents.length-1;e>=0;e--)t.contents[e].type==="BLANK_LINE"?t.contents.splice(e,1):ht(t.contents[e]);for(let e=t.directives.length-1;e>=0;e--)t.directives[e].type==="BLANK_LINE"&&t.directives.splice(e,1);break;case"FLOW_MAP":case"FLOW_SEQ":case"MAP":case"SEQ":for(let e=t.items.length-1;e>=0;e--){let n=t.items[e];"char"in n||(n.type==="BLANK_LINE"?t.items.splice(e,1):ht(n))}break;case"MAP_KEY":case"MAP_VALUE":case"SEQ_ITEM":t.node&&ht(t.node);break;case"ALIAS":case"BLANK_LINE":case"BLOCK_FOLDED":case"BLOCK_LITERAL":case"COMMENT":case"DIRECTIVE":case"PLAIN":case"QUOTE_DOUBLE":case"QUOTE_SINGLE":break;default:throw new Error(`Unexpected node type ${JSON.stringify(t.type)}`)}}function z(){return{leadingComments:[]}}function ae(t=null){return{trailingComment:t}}function q(){return{...z(),...ae()}}function Yr(t,e,n){return{...b("alias",t),...q(),...e,value:n}}function Br(t,e){let n=t.cstNode;return Yr(e.transformRange({origStart:n.valueRange.origStart-1,origEnd:n.valueRange.origEnd}),e.transformContent(t),n.rawValue)}function $r(t){return{...t,type:"blockFolded"}}function Fr(t,e,n,r,s,i){return{...b("blockValue",t),...z(),...e,chomping:n,indent:r,value:s,indicatorComment:i}}var ce;(function(t){t.Tag="!",t.Anchor="&",t.Comment="#"})(ce||(ce={}));function qr(t,e){return{...b("anchor",t),value:e}}function qe(t,e){return{...b("comment",t),value:e}}function Ur(t,e,n){return{anchor:e,tag:t,middleComments:n}}function Kr(t,e){return{...b("tag",t),value:e}}function Yt(t,e,n=()=>!1){let r=t.cstNode,s=[],i=null,o=null,a=null;for(let c of r.props){let l=e.text[c.origStart];switch(l){case ce.Tag:i=i||c,o=Kr(e.transformRange(c),t.tag);break;case ce.Anchor:i=i||c,a=qr(e.transformRange(c),r.anchor);break;case ce.Comment:{let f=qe(e.transformRange(c),e.text.slice(c.origStart+1,c.origEnd));e.comments.push(f),!n(f)&&i&&i.origEnd<=c.origStart&&c.origEnd<=r.valueRange.origStart&&s.push(f);break}default:throw new Error(`Unexpected leading character ${JSON.stringify(l)}`)}}return Ur(o,a,s)}var Ln;(function(t){t.CLIP="clip",t.STRIP="strip",t.KEEP="keep"})(Ln||(Ln={}));function Bt(t,e){let n=t.cstNode,r=1,s=n.chomping==="CLIP"?0:1,o=n.header.origEnd-n.header.origStart-r-s!==0,a=e.transformRange({origStart:n.header.origStart,origEnd:n.valueRange.origEnd}),c=null,l=Yt(t,e,f=>{if(!(a.start.offset<f.position.start.offset&&f.position.end.offset<a.end.offset))return!1;if(c)throw new Error(`Unexpected multiple indicator comments at ${Se(f.position.start)}`);return c=f,!0});return Fr(a,l,Ln[n.chomping],o?n.blockIndent:null,n.strValue,c)}function Vr(t,e){return $r(Bt(t,e))}function Wr(t){return{...t,type:"blockLiteral"}}function jr(t,e){return Wr(Bt(t,e))}function Qr(t,e){return qe(e.transformRange(t.range),t.comment)}function Jr(t,e,n){return{...b("directive",t),...q(),name:e,parameters:n}}function Ue(t,e){for(let n of t.props){let r=e.text[n.origStart];switch(r){case ce.Comment:e.comments.push(qe(e.transformRange(n),e.text.slice(n.origStart+1,n.origEnd)));break;default:throw new Error(`Unexpected leading character ${JSON.stringify(r)}`)}}}function Gr(t,e){return Ue(t,e),Jr(e.transformRange(t.range),t.name,t.parameters)}function Hr(t,e,n,r){return{...b("document",t),...ae(r),children:[e,n]}}function W(t,e){return{start:t,end:e}}function An(t){return{start:t,end:t}}function U(t=[]){return{endComments:t}}function Xr(t,e,n){return{...b("documentBody",t),...U(n),children:e?[e]:[]}}function K(t){return t[t.length-1]}function $t(t,e){let n=t.match(e);return n?n.index:-1}function zr(t,e,n){let r=t.cstNode,{comments:s,endComments:i,documentTrailingComment:o,documentHeadTrailingComment:a}=co(r,e,n),c=e.transformNode(t.contents),{position:l,documentEndPoint:f}=lo(r,c,e);return e.comments.push(...s,...i),{documentBody:Xr(l,c,i),documentEndPoint:f,documentTrailingComment:o,documentHeadTrailingComment:a}}function co(t,e,n){let r=[],s=[],i=[],o=[],a=!1;for(let c=t.contents.length-1;c>=0;c--){let l=t.contents[c];if(l.type==="COMMENT"){let f=e.transformNode(l);n&&n.line===f.position.start.line?o.unshift(f):a?r.unshift(f):f.position.start.offset>=t.valueRange.origEnd?i.unshift(f):r.unshift(f)}else a=!0}if(i.length>1)throw new Error(`Unexpected multiple document trailing comments at ${Se(i[1].position.start)}`);if(o.length>1)throw new Error(`Unexpected multiple documentHead trailing comments at ${Se(o[1].position.start)}`);return{comments:r,endComments:s,documentTrailingComment:K(i)||null,documentHeadTrailingComment:K(o)||null}}function lo(t,e,n){let r=$t(n.text.slice(t.valueRange.origEnd),/^\.\.\./),s=r===-1?t.valueRange.origEnd:Math.max(0,t.valueRange.origEnd-1);n.text[s-1]==="\r"&&s--;let i=n.transformRange({origStart:e!==null?e.position.start.offset:s,origEnd:s}),o=r===-1?i.end:n.transformOffset(t.valueRange.origEnd+3);return{position:i,documentEndPoint:o}}function Zr(t,e,n,r){return{...b("documentHead",t),...U(n),...ae(r),children:e}}function es(t,e){let n=t.cstNode,{directives:r,comments:s,endComments:i}=fo(n,e),{position:o,endMarkerPoint:a}=uo(n,r,e);return e.comments.push(...s,...i),{createDocumentHeadWithTrailingComment:l=>(l&&e.comments.push(l),Zr(o,r,i,l)),documentHeadEndMarkerPoint:a}}function fo(t,e){let n=[],r=[],s=[],i=!1;for(let o=t.directives.length-1;o>=0;o--){let a=e.transformNode(t.directives[o]);a.type==="comment"?i?r.unshift(a):s.unshift(a):(i=!0,n.unshift(a))}return{directives:n,comments:r,endComments:s}}function uo(t,e,n){let r=$t(n.text.slice(0,t.valueRange.origStart),/---\s*$/);r>0&&!/[\r\n]/.test(n.text[r-1])&&(r=-1);let s=r===-1?{origStart:t.valueRange.origStart,origEnd:t.valueRange.origStart}:{origStart:r,origEnd:r+3};return e.length!==0&&(s.origStart=e[0].position.start.offset),{position:n.transformRange(s),endMarkerPoint:r===-1?null:n.transformOffset(r)}}function ts(t,e){let{createDocumentHeadWithTrailingComment:n,documentHeadEndMarkerPoint:r}=es(t,e),{documentBody:s,documentEndPoint:i,documentTrailingComment:o,documentHeadTrailingComment:a}=zr(t,e,r),c=n(a);return o&&e.comments.push(o),Hr(W(c.position.start,i),c,s,o)}function Ft(t,e,n){return{...b("flowCollection",t),...q(),...U(),...e,children:n}}function ns(t,e,n){return{...Ft(t,e,n),type:"flowMapping"}}function qt(t,e,n){return{...b("flowMappingItem",t),...z(),children:[e,n]}}function le(t,e){let n=[];for(let r of t)r&&"type"in r&&r.type==="COMMENT"?e.comments.push(e.transformNode(r)):n.push(r);return n}function Ut(t){let[e,n]=["?",":"].map(r=>{let s=t.find(i=>"char"in i&&i.char===r);return s?{origStart:s.origOffset,origEnd:s.origOffset+1}:null});return{additionalKeyRange:e,additionalValueRange:n}}function Kt(t,e){let n=e;return r=>t.slice(n,n=r)}function Vt(t){let e=[],n=Kt(t,1),r=!1;for(let s=1;s<t.length-1;s++){let i=t[s];if("char"in i&&i.char===","){e.push(n(s)),n(s+1),r=!1;continue}r=!0}return r&&e.push(n(t.length-1)),e}function Tn(t,e){return{...b("mappingKey",t),...ae(),...U(),children:e?[e]:[]}}function Mn(t,e){return{...b("mappingValue",t),...q(),...U(),children:e?[e]:[]}}function Ke(t,e,n,r,s){let i=e.transformNode(t.key),o=e.transformNode(t.value),a=i||r?Tn(e.transformRange({origStart:r?r.origStart:i.position.start.offset,origEnd:i?i.position.end.offset:r.origStart+1}),i):null,c=o||s?Mn(e.transformRange({origStart:s?s.origStart:o.position.start.offset,origEnd:o?o.position.end.offset:s.origStart+1}),o):null;return n(W(a?a.position.start:c.position.start,c?c.position.end:a.position.end),a||Tn(An(c.position.start),null),c||Mn(An(a.position.end),null))}function rs(t,e){let n=le(t.cstNode.items,e),r=Vt(n),s=t.items.map((a,c)=>{let l=r[c],{additionalKeyRange:f,additionalValueRange:m}=Ut(l);return Ke(a,e,qt,f,m)}),i=n[0],o=K(n);return ns(e.transformRange({origStart:i.origOffset,origEnd:o.origOffset+1}),e.transformContent(t),s)}function ss(t,e,n){return{...Ft(t,e,n),type:"flowSequence"}}function is(t,e){return{...b("flowSequenceItem",t),children:[e]}}function os(t,e){let n=le(t.cstNode.items,e),r=Vt(n),s=t.items.map((a,c)=>{if(a.type!=="PAIR"){let l=e.transformNode(a);return is(W(l.position.start,l.position.end),l)}else{let l=r[c],{additionalKeyRange:f,additionalValueRange:m}=Ut(l);return Ke(a,e,qt,f,m)}}),i=n[0],o=K(n);return ss(e.transformRange({origStart:i.origOffset,origEnd:o.origOffset+1}),e.transformContent(t),s)}function as(t,e,n){return{...b("mapping",t),...z(),...e,children:n}}function cs(t,e,n){return{...b("mappingItem",t),...z(),children:[e,n]}}function ls(t,e){let n=t.cstNode;n.items.filter(o=>o.type==="MAP_KEY"||o.type==="MAP_VALUE").forEach(o=>Ue(o,e));let r=le(n.items,e),s=po(r),i=t.items.map((o,a)=>{let c=s[a],[l,f]=c[0].type==="MAP_VALUE"?[null,c[0].range]:[c[0].range,c.length===1?null:c[1].range];return Ke(o,e,cs,l,f)});return as(W(i[0].position.start,K(i).position.end),e.transformContent(t),i)}function po(t){let e=[],n=Kt(t,0),r=!1;for(let s=0;s<t.length;s++){if(t[s].type==="MAP_VALUE"){e.push(n(s+1)),r=!1;continue}r&&e.push(n(s)),r=!0}return r&&e.push(n(1/0)),e}function fs(t,e,n){return{...b("plain",t),...q(),...e,value:n}}function us(t,e,n){for(let r=e;r>=0;r--)if(n.test(t[r]))return r;return-1}function ps(t,e){let n=t.cstNode;return fs(e.transformRange({origStart:n.valueRange.origStart,origEnd:us(e.text,n.valueRange.origEnd-1,/\S/)+1}),e.transformContent(t),n.strValue)}function ms(t){return{...t,type:"quoteDouble"}}function hs(t,e,n){return{...b("quoteValue",t),...e,...q(),value:n}}function Wt(t,e){let n=t.cstNode;return hs(e.transformRange(n.valueRange),e.transformContent(t),n.strValue)}function gs(t,e){return ms(Wt(t,e))}function ds(t){return{...t,type:"quoteSingle"}}function ys(t,e){return ds(Wt(t,e))}function Es(t,e,n){return{...b("sequence",t),...z(),...U(),...e,children:n}}function Ss(t,e){return{...b("sequenceItem",t),...q(),...U(),children:e?[e]:[]}}function ws(t,e){let r=le(t.cstNode.items,e).map((s,i)=>{Ue(s,e);let o=e.transformNode(t.items[i]);return Ss(W(e.transformOffset(s.valueRange.origStart),o===null?e.transformOffset(s.valueRange.origStart+1):o.position.end),o)});return Es(W(r[0].position.start,K(r).position.end),e.transformContent(t),r)}function bs(t,e){if(t===null||t.type===void 0&&t.value===null)return null;switch(t.type){case"ALIAS":return Br(t,e);case"BLOCK_FOLDED":return Vr(t,e);case"BLOCK_LITERAL":return jr(t,e);case"COMMENT":return Qr(t,e);case"DIRECTIVE":return Gr(t,e);case"DOCUMENT":return ts(t,e);case"FLOW_MAP":return rs(t,e);case"FLOW_SEQ":return os(t,e);case"MAP":return ls(t,e);case"PLAIN":return ps(t,e);case"QUOTE_DOUBLE":return gs(t,e);case"QUOTE_SINGLE":return ys(t,e);case"SEQ":return ws(t,e);default:throw new Error(`Unexpected node type ${t.type}`)}}function Os(t,e,n){let r=new SyntaxError(t);return r.name="YAMLSyntaxError",r.source=e,r.position=n,r}function Ns(t,e){let n=t.source.range||t.source.valueRange;return Os(t.message,e.text,e.transformRange(n))}function Ls(t,e,n){return{offset:t,line:e,column:n}}function As(t,e){t<0?t=0:t>e.text.length&&(t=e.text.length);let n=e.locator.locationForIndex(t);return Ls(t,n.line+1,n.column+1)}function Ts(t,e){return W(e.transformOffset(t.origStart),e.transformOffset(t.origEnd))}function Ms(t){if(!t.setOrigRanges()){let e=n=>{if(mo(n))return n.origStart=n.start,n.origEnd=n.end,!0;if(ho(n))return n.origOffset=n.offset,!0};t.forEach(n=>Cn(n,e))}}function Cn(t,e){if(!(!t||typeof t!="object")&&e(t)!==!0)for(let n of Object.keys(t)){if(n==="context"||n==="error")continue;let r=t[n];Array.isArray(r)?r.forEach(s=>Cn(s,e)):Cn(r,e)}}function mo(t){return typeof t.start=="number"}function ho(t){return typeof t.offset=="number"}function kn(t){if("children"in t){if(t.children.length===1){let e=t.children[0];if(e.type==="plain"&&e.tag===null&&e.anchor===null&&e.value==="")return t.children.splice(0,1),t}t.children.forEach(kn)}return t}function vn(t,e,n,r){let s=e(t);return i=>{r(s,i)&&n(t,s=i)}}function In(t){if(t===null||!("children"in t))return;let e=t.children;if(e.forEach(In),t.type==="document"){let[i,o]=t.children;i.position.start.offset===i.position.end.offset?i.position.start=i.position.end=o.position.start:o.position.start.offset===o.position.end.offset&&(o.position.start=o.position.end=i.position.end)}let n=vn(t.position,go,yo,wo),r=vn(t.position,Eo,So,bo);"endComments"in t&&t.endComments.length!==0&&(n(t.endComments[0].position.start),r(K(t.endComments).position.end));let s=e.filter(i=>i!==null);if(s.length!==0){let i=s[0],o=K(s);n(i.position.start),r(o.position.end),"leadingComments"in i&&i.leadingComments.length!==0&&n(i.leadingComments[0].position.start),"tag"in i&&i.tag&&n(i.tag.position.start),"anchor"in i&&i.anchor&&n(i.anchor.position.start),"trailingComment"in o&&o.trailingComment&&r(o.trailingComment.position.end)}}function go(t){return t.start}function yo(t,e){t.start=e}function Eo(t){return t.end}function So(t,e){t.end=e}function wo(t,e){return e.offset<t.offset}function bo(t,e){return e.offset>t.offset}var di=rr(hi(),1);var G=rr(gi(),1),_m=G.default.findPair,xm=G.default.toJSON,Rm=G.default.parseMap,Dm=G.default.parseSeq,Ym=G.default.stringifyNumber,Bm=G.default.stringifyString,$m=G.default.Type,qa=G.default.YAMLError,Fm=G.default.YAMLReferenceError,er=G.default.YAMLSemanticError,Ua=G.default.YAMLSyntaxError,qm=G.default.YAMLWarning;var{Document:yi,parseCST:Ei}=di.default;function Si(t){let e=Ei(t);Ms(e);let n=e.map(a=>new yi({merge:!1,keepCstNodes:!0}).parse(a)),r=new Pr(t),s=[],i={text:t,locator:r,comments:s,transformOffset:a=>As(a,i),transformRange:a=>Ts(a,i),transformNode:a=>bs(a,i),transformContent:a=>Yt(a,i)};for(let a of n)for(let c of a.errors)if(!(c instanceof er&&c.message==='Map keys must be unique; "<<" is repeated'))throw Ns(c,i);n.forEach(a=>ht(a.cstNode));let o=Dr(i.transformRange({origStart:0,origEnd:i.text.length}),n.map(i.transformNode),s);return _r(o),In(o),kn(o),o}function Va(t,e){let n=new SyntaxError(t+" ("+e.loc.start.line+":"+e.loc.start.column+")");return Object.assign(n,e)}var wi=Va;function Wa(t){try{let e=Si(t);return delete e.comments,e}catch(e){throw e!=null&&e.position?wi(e.message,{loc:e.position,cause:e}):e}}var ja={astFormat:"yaml",parse:Wa,hasPragma:pr,locStart:Ye,locEnd:hr};var bi=[{linguistLanguageId:407,name:"YAML",type:"data",color:"#cb171e",tmScope:"source.yaml",aliases:["yml"],extensions:[".yml",".mir",".reek",".rviz",".sublime-syntax",".syntax",".yaml",".yaml-tmlanguage",".yaml.sed",".yml.mysql"],filenames:[".clang-format",".clang-tidy",".gemrc","CITATION.cff","glide.lock",".prettierrc",".stylelintrc",".lintstagedrc"],aceMode:"yaml",codemirrorMode:"yaml",codemirrorMimeType:"text/x-yaml",parsers:["yaml"],vscodeLanguageIds:["yaml","ansible","home-assistant"]}];var ln={bracketSpacing:{category:"Common",type:"boolean",default:!0,description:"Print spaces between brackets.",oppositeDescription:"Do not print spaces between brackets."},singleQuote:{category:"Common",type:"boolean",default:!1,description:"Use single quotes instead of double quotes."},proseWrap:{category:"Common",type:"choice",default:"preserve",description:"How to wrap prose.",choices:[{value:"always",description:"Wrap prose if it exceeds the print width."},{value:"never",description:"Do not wrap prose."},{value:"preserve",description:"Wrap prose as-is."}]},bracketSameLine:{category:"Common",type:"boolean",default:!1,description:"Put > of opening tags on the last line instead of on a new line."},singleAttributePerLine:{category:"Common",type:"boolean",default:!1,description:"Enforce single attribute per line in HTML, Vue and JSX."}};var Qa={bracketSpacing:ln.bracketSpacing,singleQuote:ln.singleQuote,proseWrap:ln.proseWrap},Oi=Qa;var Ja={yaml:vr};var yh=tr;export{yh as default,bi as languages,Oi as options,cn as parsers,Ja as printers};
|