UNPKG

@glimmer/syntax

Version:
1 lines 71.2 kB
import{assertNever as t,assign as e,dict as s}from"@glimmer/util";import{parseWithoutProcessing as r,parse as n}from"@handlebars/parser";import{EntityParser as a,EventedTokenizer as i,HTML5NamedCharRefs as o}from"simple-html-tokenizer";import{SexpOpcodes as l}from"@glimmer/wire-format";const c=/["\x26\xa0]/u,h=new RegExp(c.source,"gu"),u=/[&<>\xa0]/u,p=new RegExp(u.source,"gu");function d(t){switch(t.charCodeAt(0)){case 160:return"&nbsp;";case 34:return"&quot;";case 38:return"&amp;";default:return t}}function m(t){switch(t.charCodeAt(0)){case 160:return"&nbsp;";case 38:return"&amp;";case 60:return"&lt;";case 62:return"&gt;";default:return t}}function f(t,e){return t.loc.isInvisible||e.loc.isInvisible?0:t.loc.startPosition.line<e.loc.startPosition.line||t.loc.startPosition.line===e.loc.startPosition.line&&t.loc.startPosition.column<e.loc.startPosition.column?-1:t.loc.startPosition.line===e.loc.startPosition.line&&t.loc.startPosition.column===e.loc.startPosition.column?0:1}const g=new Set(["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]);function b(){return[...g]}const k=/^\S/u;function w(t){return g.has(t.toLowerCase())&&t[0]?.toLowerCase()===t[0]}class y{constructor(t){this.buffer="",this.options=t}handledByOverride(t,e=!1){if(void 0!==this.options.override){let s=this.options.override(t,this.options);if("string"==typeof s)return e&&k.test(s)&&(s=` ${s}`),this.buffer+=s,!0}return!1}Node(t){switch(t.type){case"MustacheStatement":case"BlockStatement":case"MustacheCommentStatement":case"CommentStatement":case"TextNode":case"ElementNode":case"AttrNode":case"Block":case"Template":return this.TopLevelStatement(t);case"StringLiteral":case"BooleanLiteral":case"NumberLiteral":case"UndefinedLiteral":case"NullLiteral":case"PathExpression":case"SubExpression":return this.Expression(t);case"ConcatStatement":return this.ConcatStatement(t);case"Hash":return this.Hash(t);case"HashPair":return this.HashPair(t);case"ElementModifierStatement":return this.ElementModifierStatement(t)}}Expression(t){switch(t.type){case"StringLiteral":case"BooleanLiteral":case"NumberLiteral":case"UndefinedLiteral":case"NullLiteral":return this.Literal(t);case"PathExpression":return this.PathExpression(t);case"SubExpression":return this.SubExpression(t)}}Literal(t){switch(t.type){case"StringLiteral":return this.StringLiteral(t);case"BooleanLiteral":return this.BooleanLiteral(t);case"NumberLiteral":return this.NumberLiteral(t);case"UndefinedLiteral":return this.UndefinedLiteral(t);case"NullLiteral":return this.NullLiteral(t)}}TopLevelStatement(t){switch(t.type){case"MustacheStatement":return this.MustacheStatement(t);case"BlockStatement":return this.BlockStatement(t);case"MustacheCommentStatement":return this.MustacheCommentStatement(t);case"CommentStatement":return this.CommentStatement(t);case"TextNode":return this.TextNode(t);case"ElementNode":return this.ElementNode(t);case"Block":return this.Block(t);case"Template":return this.Template(t);case"AttrNode":return this.AttrNode(t)}}Template(t){this.TopLevelStatements(t.body)}Block(t){t.chained&&(t.body[0].chained=!0),this.handledByOverride(t)||this.TopLevelStatements(t.body)}TopLevelStatements(t){t.forEach((t=>this.TopLevelStatement(t)))}ElementNode(t){this.handledByOverride(t)||(this.OpenElementNode(t),this.TopLevelStatements(t.children),this.CloseElementNode(t))}OpenElementNode(t){this.buffer+=`<${t.tag}`;const e=[...t.attributes,...t.modifiers,...t.comments].sort(f);for(const t of e)switch(this.buffer+=" ",t.type){case"AttrNode":this.AttrNode(t);break;case"ElementModifierStatement":this.ElementModifierStatement(t);break;case"MustacheCommentStatement":this.MustacheCommentStatement(t)}t.blockParams.length&&this.BlockParams(t.blockParams),t.selfClosing&&(this.buffer+=" /"),this.buffer+=">"}CloseElementNode(t){t.selfClosing||w(t.tag)||(this.buffer+=`</${t.tag}>`)}AttrNode(t){if(this.handledByOverride(t))return;let{name:e,value:s}=t;this.buffer+=e,("TextNode"!==s.type||s.chars.length>0)&&(this.buffer+="=",this.AttrNodeValue(s))}AttrNodeValue(t){"TextNode"===t.type?(this.buffer+='"',this.TextNode(t,!0),this.buffer+='"'):this.Node(t)}TextNode(t,e){var s;this.handledByOverride(t)||("raw"===this.options.entityEncoding?this.buffer+=t.chars:this.buffer+=e?(s=t.chars,c.test(s)?s.replace(h,d):s):function(t){return u.test(t)?t.replace(p,m):t}(t.chars))}MustacheStatement(t){this.handledByOverride(t)||(this.buffer+=t.trusting?"{{{":"{{",t.strip.open&&(this.buffer+="~"),this.Expression(t.path),this.Params(t.params),this.Hash(t.hash),t.strip.close&&(this.buffer+="~"),this.buffer+=t.trusting?"}}}":"}}")}BlockStatement(t){this.handledByOverride(t)||(t.chained?(this.buffer+=t.inverseStrip.open?"{{~":"{{",this.buffer+="else "):this.buffer+=t.openStrip.open?"{{~#":"{{#",this.Expression(t.path),this.Params(t.params),this.Hash(t.hash),t.program.blockParams.length&&this.BlockParams(t.program.blockParams),t.chained?this.buffer+=t.inverseStrip.close?"~}}":"}}":this.buffer+=t.openStrip.close?"~}}":"}}",this.Block(t.program),t.inverse&&(t.inverse.chained||(this.buffer+=t.inverseStrip.open?"{{~":"{{",this.buffer+="else",this.buffer+=t.inverseStrip.close?"~}}":"}}"),this.Block(t.inverse)),t.chained||(this.buffer+=t.closeStrip.open?"{{~/":"{{/",this.Expression(t.path),this.buffer+=t.closeStrip.close?"~}}":"}}"))}BlockParams(t){this.buffer+=` as |${t.join(" ")}|`}ConcatStatement(t){this.handledByOverride(t)||(this.buffer+='"',t.parts.forEach((t=>{"TextNode"===t.type?this.TextNode(t,!0):this.Node(t)})),this.buffer+='"')}MustacheCommentStatement(t){this.handledByOverride(t)||(this.buffer+=`{{!--${t.value}--}}`)}ElementModifierStatement(t){this.handledByOverride(t)||(this.buffer+="{{",this.Expression(t.path),this.Params(t.params),this.Hash(t.hash),this.buffer+="}}")}CommentStatement(t){this.handledByOverride(t)||(this.buffer+=`\x3c!--${t.value}--\x3e`)}PathExpression(t){this.handledByOverride(t)||(this.buffer+=t.original)}SubExpression(t){this.handledByOverride(t)||(this.buffer+="(",this.Expression(t.path),this.Params(t.params),this.Hash(t.hash),this.buffer+=")")}Params(t){t.length&&t.forEach((t=>{this.buffer+=" ",this.Expression(t)}))}Hash(t){this.handledByOverride(t,!0)||t.pairs.forEach((t=>{this.buffer+=" ",this.HashPair(t)}))}HashPair(t){this.handledByOverride(t)||(this.buffer+=t.key,this.buffer+="=",this.Node(t.value))}StringLiteral(t){this.handledByOverride(t)||(this.buffer+=JSON.stringify(t.value))}BooleanLiteral(t){this.handledByOverride(t)||(this.buffer+=String(t.value))}NumberLiteral(t){this.handledByOverride(t)||(this.buffer+=String(t.value))}UndefinedLiteral(t){this.handledByOverride(t)||(this.buffer+="undefined")}NullLiteral(t){this.handledByOverride(t)||(this.buffer+="null")}print(t){let{options:e}=this;if(e.override){let s=e.override(t,e);if(void 0!==s)return s}return this.buffer="",this.Node(t),this.buffer}}function v(t,e={entityEncoding:"transformed"}){return t?new y(e).print(t):""}function S(t,e){return t in x&&(void 0===e||x[t].includes(e))}const x={action:["Call","Modifier"],component:["Call","Append","Block"],debugger:["Append"],"each-in":["Block"],each:["Block"],"has-block-params":["Call","Append"],"has-block":["Call","Append"],helper:["Call","Append"],if:["Call","Append","Block"],"in-element":["Block"],let:["Block"],log:["Call","Append"],modifier:["Call","Modifier"],mount:["Append"],mut:["Call","Append"],outlet:["Append"],readonly:["Call","Append"],unbound:["Call","Append"],unless:["Call","Append","Block"],yield:["Append"]};function P(t){return!!t&&t.length>0}function E(t){return 0===t.length?void 0:t[t.length-1]}function N(t){return 0===t.length?void 0:t[0]}const C=Object.freeze({line:1,column:0}),A=Object.freeze({source:"(synthetic)",start:C,end:C}),T=Object.freeze({source:"(nonexistent)",start:C,end:C}),L=Object.freeze({source:"(broken)",start:C,end:C}),B="CharPosition",O="HbsPosition",H="InternalsSynthetic",F="NonExistent",$="Broken",z="MATCH_ANY",M="IS_INVISIBLE";class I{constructor(t){this._whens=t}first(t){for(const e of this._whens){const s=e.match(t);if(P(s))return s[0]}return null}}class _{get(t,e){let s=this._map.get(t);return s||(s=e(),this._map.set(t,s),s)}add(t,e){this._map.set(t,e)}match(t){const e=function(t){switch(t){case $:case H:case F:return M;default:return t}}(t),s=[],r=this._map.get(e),n=this._map.get(z);return r&&s.push(r),n&&s.push(n),s}constructor(){this._map=new Map}}function V(t){return t(new U).validate()}class U{validate(){return(t,e)=>this.matchFor(t.kind,e.kind)(t,e)}matchFor(t,e){const s=this._whens.match(t);return P(),new I(s).first(e)}when(t,e,s){return this._whens.get(t,(()=>new _)).add(e,s),this}constructor(){this._whens=new _}}class D{static synthetic(t){let e=j.synthetic(t);return new D({loc:e,chars:t})}static load(t,e){return new D({loc:j.load(t,e[1]),chars:e[0]})}constructor(t){this.loc=t.loc,this.chars=t.chars}getString(){return this.chars}serialize(){return[this.chars,this.loc.serialize()]}}class j{static get NON_EXISTENT(){return new R(F,T).wrap()}static load(e,s){return"number"==typeof s?j.forCharPositions(e,s,s):"string"==typeof s?j.synthetic(s):Array.isArray(s)?j.forCharPositions(e,s[0],s[1]):s===F?j.NON_EXISTENT:s===$?j.broken(L):void t(s)}static forHbsLoc(t,e){const s=new Q(t,e.start),r=new Q(t,e.end);return new J(t,{start:s,end:r},e).wrap()}static forCharPositions(t,e,s){const r=new q(t,e),n=new q(t,s);return new K(t,{start:r,end:n}).wrap()}static synthetic(t){return new R(H,T,t).wrap()}static broken(t=L){return new R($,t).wrap()}constructor(t){var e;this.data=t,this.isInvisible=(e=t.kind)!==B&&e!==O}getStart(){return this.data.getStart().wrap()}getEnd(){return this.data.getEnd().wrap()}get loc(){const t=this.data.toHbsSpan();return null===t?L:t.toHbsLoc()}get module(){return this.data.getModule()}get startPosition(){return this.loc.start}get endPosition(){return this.loc.end}toJSON(){return this.loc}withStart(t){return G(t.data,this.data.getEnd())}withEnd(t){return G(this.data.getStart(),t.data)}asString(){return this.data.asString()}toSlice(t){const e=this.data.asString();return new D({loc:this,chars:t||e})}get start(){return this.loc.start}set start(t){this.data.locDidUpdate({start:t})}get end(){return this.loc.end}set end(t){this.data.locDidUpdate({end:t})}get source(){return this.module}collapse(t){switch(t){case"start":return this.getStart().collapsed();case"end":return this.getEnd().collapsed()}}extend(t){return G(this.data.getStart(),t.data.getEnd())}serialize(){return this.data.serialize()}slice({skipStart:t=0,skipEnd:e=0}){return G(this.getStart().move(t).data,this.getEnd().move(-e).data)}sliceStartChars({skipStart:t=0,chars:e}){return G(this.getStart().move(t).data,this.getStart().move(t+e).data)}sliceEndChars({skipEnd:t=0,chars:e}){return G(this.getEnd().move(t-e).data,this.getStart().move(-t).data)}}class K{#t;constructor(t,e){this.source=t,this.charPositions=e,this.kind=B,this.#t=null}wrap(){return new j(this)}asString(){return this.source.slice(this.charPositions.start.charPos,this.charPositions.end.charPos)}getModule(){return this.source.module}getStart(){return this.charPositions.start}getEnd(){return this.charPositions.end}locDidUpdate(){}toHbsSpan(){let t=this.#t;if(null===t){const e=this.charPositions.start.toHbsPos(),s=this.charPositions.end.toHbsPos();t=this.#t=null===e||null===s?Y:new J(this.source,{start:e,end:s})}return t===Y?null:t}serialize(){const{start:{charPos:t},end:{charPos:e}}=this.charPositions;return t===e?t:[t,e]}toCharPosSpan(){return this}}class J{#e;#s;constructor(t,e,s=null){this.source=t,this.hbsPositions=e,this.kind=O,this.#e=null,this.#s=s}serialize(){const t=this.toCharPosSpan();return null===t?$:t.wrap().serialize()}wrap(){return new j(this)}updateProvided(t,e){this.#s&&(this.#s[e]=t),this.#e=null,this.#s={start:t,end:t}}locDidUpdate({start:t,end:e}){void 0!==t&&(this.updateProvided(t,"start"),this.hbsPositions.start=new Q(this.source,t,null)),void 0!==e&&(this.updateProvided(e,"end"),this.hbsPositions.end=new Q(this.source,e,null))}asString(){const t=this.toCharPosSpan();return null===t?"":t.asString()}getModule(){return this.source.module}getStart(){return this.hbsPositions.start}getEnd(){return this.hbsPositions.end}toHbsLoc(){return{start:this.hbsPositions.start.hbsPos,end:this.hbsPositions.end.hbsPos}}toHbsSpan(){return this}toCharPosSpan(){let t=this.#e;if(null===t){const e=this.hbsPositions.start.toCharPos(),s=this.hbsPositions.end.toCharPos();if(!e||!s)return t=this.#e=Y,null;t=this.#e=new K(this.source,{start:e,end:s})}return t===Y?null:t}}class R{constructor(t,e,s=null){this.kind=t,this.loc=e,this.string=s}serialize(){switch(this.kind){case $:case F:return this.kind;case H:return this.string||""}}wrap(){return new j(this)}asString(){return this.string||""}locDidUpdate({start:t,end:e}){void 0!==t&&(this.loc.start=t),void 0!==e&&(this.loc.end=e)}getModule(){return"an unknown module"}getStart(){return new X(this.kind,this.loc.start)}getEnd(){return new X(this.kind,this.loc.end)}toCharPosSpan(){return this}toHbsSpan(){return null}toHbsLoc(){return L}}const G=V((t=>t.when(O,O,((t,e)=>new J(t.source,{start:t,end:e}).wrap())).when(B,B,((t,e)=>new K(t.source,{start:t,end:e}).wrap())).when(B,O,((t,e)=>{const s=e.toCharPos();return null===s?new R($,L).wrap():G(t,s)})).when(O,B,((t,e)=>{const s=t.toCharPos();return null===s?new R($,L).wrap():G(s,e)})).when(M,z,(t=>new R(t.kind,L).wrap())).when(z,M,((t,e)=>new R(e.kind,L).wrap())))),Y="BROKEN";class W{static forHbsPos(t,e){return new Q(t,e,null).wrap()}static broken(t=C){return new X($,t).wrap()}constructor(t){this.data=t}get offset(){const t=this.data.toCharPos();return null===t?null:t.offset}eql(t){return Z(this.data,t.data)}until(t){return G(this.data,t.data)}move(t){const e=this.data.toCharPos();if(null===e)return W.broken();{const s=e.offset+t;return e.source.validate(s)?new q(e.source,s).wrap():W.broken()}}collapsed(){return G(this.data,this.data)}toJSON(){return this.data.toJSON()}}class q{constructor(t,e){this.source=t,this.charPos=e,this.kind=B,this._locPos=null}toCharPos(){return this}toJSON(){const t=this.toHbsPos();return null===t?C:t.toJSON()}wrap(){return new W(this)}get offset(){return this.charPos}toHbsPos(){let t=this._locPos;if(null===t){const e=this.source.hbsPosFor(this.charPos);this._locPos=t=null===e?Y:new Q(this.source,e,this.charPos)}return t===Y?null:t}}class Q{constructor(t,e,s=null){this.source=t,this.hbsPos=e,this.kind=O,this._charPos=null===s?null:new q(t,s)}toCharPos(){let t=this._charPos;if(null===t){const e=this.source.charPosFor(this.hbsPos);this._charPos=t=null===e?Y:new q(this.source,e)}return t===Y?null:t}toJSON(){return this.hbsPos}wrap(){return new W(this)}toHbsPos(){return this}}class X{constructor(t,e){this.kind=t,this.pos=e}toCharPos(){return null}toJSON(){return this.pos}wrap(){return new W(this)}get offset(){return null}}const Z=V((t=>t.when(O,O,(({hbsPos:t},{hbsPos:e})=>t.column===e.column&&t.line===e.line)).when(B,B,(({charPos:t},{charPos:e})=>t===e)).when(B,O,(({offset:t},e)=>t===e.toCharPos()?.offset)).when(O,B,((t,{offset:e})=>t.toCharPos()?.offset===e)).when(z,z,(()=>!1))));class tt{static from(t,e={}){return new tt(t,e.meta?.moduleName)}constructor(t,e="an unknown module"){this.source=t,this.module=e}validate(t){return t>=0&&t<=this.source.length}slice(t,e){return this.source.slice(t,e)}offsetFor(t,e){return W.forHbsPos(this,{line:t,column:e})}spanFor({start:t,end:e}){return j.forHbsLoc(this,{start:{line:t.line,column:t.column},end:{line:e.line,column:e.column}})}hbsPosFor(t){let e=0,s=0;if(t>this.source.length)return null;for(;;){let r=this.source.indexOf("\n",s);if(t<=r||-1===r)return{line:e+1,column:t-s};e+=1,s=r+1}}charPosFor(t){let{line:e,column:s}=t,r=this.source.length,n=0,a=0;for(;a<r;){let t=this.source.indexOf("\n",a);if(-1===t&&(t=this.source.length),n===e-1)return a+s>t?t:a+s;if(-1===t)return 0;n+=1,a=t+1}return r}}class et{static range(t,e=j.NON_EXISTENT){return new et(t.map(st)).getRangeOffset(e)}constructor(t=[]){this._span=t}add(t){this._span.push(t)}getRangeOffset(t){if(P(this._span)){let t=N(this._span),e=E(this._span);return t.extend(e)}return t}}function st(t){if(Array.isArray(t)){let e=N(t),s=E(t);return st(e).extend(st(s))}return t instanceof j?t:t.loc}function rt(t){return!Array.isArray(t)||0!==t.length}function nt(t,e){return rt(t)?st(t):e}var at=Object.freeze({__proto__:null,NON_EXISTENT_LOCATION:T,SYNTHETIC_LOCATION:A,Source:tt,SourceOffset:W,SourceSlice:D,SourceSpan:j,SpanList:et,UNKNOWN_POSITION:C,hasSpan:rt,loc:st,maybeLoc:nt});function it(t,e){let{module:s,loc:r}=e,{line:n,column:a}=r.start,i=e.asString(),o=i?`\n\n|\n| ${i.split("\n").join("\n| ")}\n|\n\n`:"",l=new Error(`${t}: ${o}(error occurred in '${s}' @ line ${n} : column ${a})`);return l.name="SyntaxError",l.location=e,l.code=i,l}const ot={Template:["body"],Block:["body"],MustacheStatement:["path","params","hash"],BlockStatement:["path","params","hash","program","inverse"],ElementModifierStatement:["path","params","hash"],CommentStatement:[],MustacheCommentStatement:[],ElementNode:["attributes","modifiers","children","comments"],AttrNode:["value"],TextNode:[],ConcatStatement:["parts"],SubExpression:["path","params","hash"],PathExpression:[],StringLiteral:[],BooleanLiteral:[],NumberLiteral:[],NullLiteral:[],UndefinedLiteral:[],Hash:["pairs"],HashPair:["value"]},lt=function(){function t(t,e,s,r){let n=Error.call(this,t);this.key=r,this.message=t,this.node=e,this.parent=s,n.stack&&(this.stack=n.stack)}return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}();function ct(t,e,s){return new lt("Cannot remove a node unless it is part of an array",t,e,s)}function ht(t,e,s){return new lt("Cannot replace a node with multiple nodes unless it is part of an array",t,e,s)}function ut(t,e){return new lt("Replacing and removing in key handlers is not yet supported.",t,null,e)}class pt{constructor(t,e=null,s=null){this.node=t,this.parent=e,this.parentKey=s}get parentNode(){return this.parent?this.parent.node:null}parents(){return{[Symbol.iterator]:()=>new dt(this)}}}class dt{constructor(t){this.path=t}next(){return this.path.parent?(this.path=this.path.parent,{done:!1,value:this.path}):{done:!0,value:null}}}function mt(t){return"function"==typeof t?t:t.enter}function ft(t){return"function"==typeof t?void 0:t.exit}function gt(t,e){let s,r,n,{node:a,parent:i,parentKey:o}=e,l=function(t,e){if(t.Program&&("Template"===e&&!t.Template||"Block"===e&&!t.Block))return t.Program;let s=t[e];return void 0!==s?s:t.All}(t,a.type);if(void 0!==l&&(s=mt(l),r=ft(l)),void 0!==s&&(n=s(a,e)),null!=n){if(JSON.stringify(a)!==JSON.stringify(n))return Array.isArray(n)?(wt(t,n,i,o),n):gt(t,new pt(n,i,o))||n;n=void 0}if(void 0===n){let s=ot[a.type];for(let r=0;r<s.length;r++)kt(t,l,e,s[r]);void 0!==r&&(n=r(a,e))}return n}function bt(t,e,s){t[e]=s}function kt(t,e,s,r){let n,a,{node:i}=s,o=function(t,e){return t[e]}(i,r);if(o){if(void 0!==e){let t=function(t,e){let s="function"!=typeof t?t.keys:void 0;if(void 0===s)return;let r=s[e];return void 0!==r?r:s.All}(e,r);void 0!==t&&(n=mt(t),a=ft(t))}if(void 0!==n&&void 0!==n(i,r))throw ut(i,r);if(Array.isArray(o))wt(t,o,s,r);else{let e=gt(t,new pt(o,s,r));void 0!==e&&function(t,e,s,r){if(null===r)throw ct(s,t,e);if(Array.isArray(r)){if(1!==r.length)throw 0===r.length?ct(s,t,e):ht(s,t,e);bt(t,e,r[0])}else bt(t,e,r)}(i,r,o,e)}if(void 0!==a&&void 0!==a(i,r))throw ut(i,r)}}function wt(t,e,s,r){for(let n=0;n<e.length;n++){let a=e[n],i=gt(t,new pt(a,s,r));void 0!==i&&(n+=yt(e,n,i)-1)}}function yt(t,e,s){return null===s?(t.splice(e,1),0):Array.isArray(s)?(t.splice(e,1,...s),s.length):(t.splice(e,1,s),1)}function vt(t,e){gt(e,new pt(t))}class St{constructor(t){this.order=t,this.stack=[]}visit(t,e){t&&(this.stack.push(t),"post"===this.order?(this.children(t,e),e(t,this)):(e(t,this),this.children(t,e)),this.stack.pop())}children(t,e){switch(t.type){case"Block":case"Template":return void xt(this,t.body,e);case"ElementNode":return void xt(this,t.children,e);case"BlockStatement":return this.visit(t.program,e),void this.visit(t.inverse||null,e);default:return}}}function xt(t,e,s){for(const r of e)t.visit(r,s)}function Pt(t,e){(function(t){switch(t.type){case"Block":case"Template":return t.body;case"ElementNode":return t.children}})(t).push(e)}function Et(t){return"StringLiteral"===t.type||"BooleanLiteral"===t.type||"NumberLiteral"===t.type||"NullLiteral"===t.type||"UndefinedLiteral"===t.type}let Nt;function Ct(){return Nt||(Nt=new tt("","(synthetic)")),Nt}function At(t,e){return _t.var({name:t,loc:$t(e||null)})}function Tt(t,e){let s=$t(e||null);if("string"!=typeof t){if("type"in t)return t;{t.head.indexOf(".");let{head:r,tail:n}=t;return _t.path({head:_t.head({original:r,loc:s.sliceStartChars({chars:r.length})}),tail:n,loc:$t(e||null)})}}let{head:r,tail:n}=function(t,e){let[s,...r]=t.split("."),n=_t.head({original:s,loc:$t(e||null)});return _t.path({head:n,tail:r,loc:$t(e||null)})}(t,s);return _t.path({head:r,tail:n,loc:s})}function Lt(t,e,s){return _t.literal({type:t,value:e,loc:$t(s||null)})}function Bt(t=[],e){return _t.hash({pairs:t,loc:$t(e||null)})}function Ot(t){return t.map((t=>"string"==typeof t?_t.var({name:t,loc:j.synthetic(t)}):t))}function Ht(t=[],e=[],s=!1,r){return _t.blockItself({body:t,params:Ot(e),chained:s,loc:$t(r||null)})}function Ft(t=[],e=[],s){return _t.template({body:t,blockParams:e,loc:$t(s||null)})}function $t(...t){if(1===t.length){let e=t[0];return e&&"object"==typeof e?j.forHbsLoc(Ct(),e):j.forHbsLoc(Ct(),A)}{let[e,s,r,n,a]=t,i=a?new tt("",a):Ct();return j.forHbsLoc(i,{start:{line:e,column:s},end:{line:r||e,column:n||s}})}}var zt={mustache:function(t,e=[],s=Bt([]),r=!1,n,a){return _t.mustache({path:Tt(t),params:e,hash:s,trusting:r,strip:a,loc:$t(n||null)})},block:function(t,e,s,r,n=null,a,i,o,l){let c,h=null;return c="Template"===r.type?_t.blockItself({params:Ot(r.blockParams),body:r.body,loc:r.loc}):r,"Template"===n?.type?(n.blockParams.length,h=_t.blockItself({params:[],body:n.body,loc:n.loc})):h=n,_t.block({path:Tt(t),params:e||[],hash:s||Bt([]),defaultBlock:c,elseBlock:h,loc:$t(a||null),openStrip:i,inverseStrip:o,closeStrip:l})},comment:function(t,e){return _t.comment({value:t,loc:$t(e||null)})},mustacheComment:function(t,e){return _t.mustacheComment({value:t,loc:$t(e||null)})},element:function(t,e={}){let s,r,{attrs:n,blockParams:a,modifiers:i,comments:o,children:l,openTag:c,closeTag:h,loc:u}=e;"string"==typeof t?t.endsWith("/")?(s=Tt(t.slice(0,-1)),r=!0):s=Tt(t):"type"in t?(t.type,t.type,s=t):"path"in t?(t.path.type,t.path.type,s=t.path,r=t.selfClosing):(s=Tt(t.name),r=t.selfClosing);let p=a?.map((t=>"string"==typeof t?At(t):t)),d=null;return h?d=$t(h):void 0===h&&(d=r||w(s.original)?null:$t(null)),_t.element({path:s,selfClosing:r||!1,attributes:n||[],params:p||[],modifiers:i||[],comments:o||[],children:l||[],openTag:$t(c||null),closeTag:d,loc:$t(u||null)})},elementModifier:function(t,e,s,r){return _t.elementModifier({path:Tt(t),params:e||[],hash:s||Bt([]),loc:$t(r||null)})},attr:function(t,e,s){return _t.attr({name:t,value:e,loc:$t(s||null)})},text:function(t="",e){return _t.text({chars:t,loc:$t(e||null)})},sexpr:function(t,e=[],s=Bt([]),r){return _t.sexpr({path:Tt(t),params:e,hash:s,loc:$t(r||null)})},concat:function(t,e){if(!P(t))throw new Error("b.concat requires at least one part");return _t.concat({parts:t,loc:$t(e||null)})},hash:Bt,pair:function(t,e,s){return _t.pair({key:t,value:e,loc:$t(s||null)})},literal:Lt,program:function(t,e,s){return e&&e.length?Ht(t,e,!1,s):Ft(t,[],s)},blockItself:Ht,template:Ft,loc:$t,pos:function(t,e){return _t.pos({line:t,column:e})},path:Tt,fullPath:function(t,e=[],s){return _t.path({head:t,tail:e,loc:$t(s||null)})},head:function(t,e){return _t.head({original:t,loc:$t(e||null)})},at:function(t,e){return _t.atName({name:t,loc:$t(e||null)})},var:At,this:function(t){return _t.this({loc:$t(t||null)})},string:Mt("StringLiteral"),boolean:Mt("BooleanLiteral"),number:Mt("NumberLiteral"),undefined:()=>Lt("UndefinedLiteral",void 0),null:()=>Lt("NullLiteral",null)};function Mt(t){return function(e,s){return Lt(t,e,s)}}const It={close:!1,open:!1},_t=new class{pos({line:t,column:e}){return{line:t,column:e}}blockItself({body:t,params:e,chained:s=!1,loc:r}){return{type:"Block",body:t,params:e,get blockParams(){return this.params.map((t=>t.name))},set blockParams(t){this.params=t.map((t=>_t.var({name:t,loc:j.synthetic(t)})))},chained:s,loc:r}}template({body:t,blockParams:e,loc:s}){return{type:"Template",body:t,blockParams:e,loc:s}}mustache({path:t,params:e,hash:s,trusting:r,loc:n,strip:a=It}){return function({path:t,params:e,hash:s,trusting:r,strip:n,loc:a}){const i={type:"MustacheStatement",path:t,params:e,hash:s,trusting:r,strip:n,loc:a};return Object.defineProperty(i,"escaped",{enumerable:!1,get(){return!this.trusting},set(t){this.trusting=!t}}),i}({path:t,params:e,hash:s,trusting:r,strip:a,loc:n})}block({path:t,params:e,hash:s,defaultBlock:r,elseBlock:n=null,loc:a,openStrip:i=It,inverseStrip:o=It,closeStrip:l=It}){return{type:"BlockStatement",path:t,params:e,hash:s,program:r,inverse:n,loc:a,openStrip:i,inverseStrip:o,closeStrip:l}}comment({value:t,loc:e}){return{type:"CommentStatement",value:t,loc:e}}mustacheComment({value:t,loc:e}){return{type:"MustacheCommentStatement",value:t,loc:e}}concat({parts:t,loc:e}){return{type:"ConcatStatement",parts:t,loc:e}}element({path:t,selfClosing:e,attributes:s,modifiers:r,params:n,comments:a,children:i,openTag:o,closeTag:l,loc:c}){let h=e;return{type:"ElementNode",path:t,attributes:s,modifiers:r,params:n,comments:a,children:i,openTag:o,closeTag:l,loc:c,get tag(){return this.path.original},set tag(t){this.path.original=t},get blockParams(){return this.params.map((t=>t.name))},set blockParams(t){this.params=t.map((t=>_t.var({name:t,loc:j.synthetic(t)})))},get selfClosing(){return h},set selfClosing(t){h=t,this.closeTag=t?null:j.synthetic(`</${this.tag}>`)}}}elementModifier({path:t,params:e,hash:s,loc:r}){return{type:"ElementModifierStatement",path:t,params:e,hash:s,loc:r}}attr({name:t,value:e,loc:s}){return{type:"AttrNode",name:t,value:e,loc:s}}text({chars:t,loc:e}){return{type:"TextNode",chars:t,loc:e}}sexpr({path:t,params:e,hash:s,loc:r}){return{type:"SubExpression",path:t,params:e,hash:s,loc:r}}path({head:t,tail:e,loc:s}){return function({head:t,tail:e,loc:s}){const r={type:"PathExpression",head:t,tail:e,get original(){return[this.head.original,...this.tail].join(".")},set original(t){let[e,...s]=t.split(".");this.head=zt.head(e,this.head.loc),this.tail=s},loc:s};return Object.defineProperty(r,"parts",{enumerable:!1,get(){let t=this.original.split(".");return"this"===t[0]?t.shift():t[0].startsWith("@")&&(t[0]=t[0].slice(1)),Object.freeze(t)},set(t){let e=[...t];"this"===e[0]||e[0]?.startsWith("@")||("ThisHead"===this.head.type?e.unshift("this"):"AtHead"===this.head.type&&(e[0]=`@${e[0]}`)),this.original=e.join(".")}}),Object.defineProperty(r,"this",{enumerable:!1,get(){return"ThisHead"===this.head.type}}),Object.defineProperty(r,"data",{enumerable:!1,get(){return"AtHead"===this.head.type}}),r}({head:t,tail:e,loc:s})}head({original:t,loc:e}){return"this"===t?this.this({loc:e}):"@"===t[0]?this.atName({name:t,loc:e}):this.var({name:t,loc:e})}this({loc:t}){return{type:"ThisHead",get original(){return"this"},loc:t}}atName({name:t,loc:e}){let s="";const r={type:"AtHead",get name(){return s},set name(t){t[0],t.indexOf("."),s=t},get original(){return this.name},set original(t){this.name=t},loc:e};return r.name=t,r}var({name:t,loc:e}){let s="";const r={type:"VarHead",get name(){return s},set name(t){t[0],t.indexOf("."),s=t},get original(){return this.name},set original(t){this.name=t},loc:e};return r.name=t,r}hash({pairs:t,loc:e}){return{type:"Hash",pairs:t,loc:e}}pair({key:t,value:e,loc:s}){return{type:"HashPair",key:t,value:e,loc:s}}literal({type:t,value:e,loc:s}){return function({type:t,value:e,loc:s}){const r={type:t,value:e,loc:s};return Object.defineProperty(r,"original",{enumerable:!1,get(){return this.value},set(t){this.value=t}}),r}({type:t,value:e,loc:s})}};class Vt{constructor(t,e=new a(o),s="precompile"){this.elementStack=[],this.currentAttribute=null,this.currentNode=null,this.source=t,this.lines=t.source.split(/\r\n?|\n/u),this.tokenizer=new i(this,e,s)}offset(){let{line:t,column:e}=this.tokenizer;return this.source.offsetFor(t,e)}pos({line:t,column:e}){return this.source.offsetFor(t,e)}finish(t){return e({},t,{loc:t.start.until(this.offset())})}get currentAttr(){return this.currentAttribute}get currentTag(){let t=this.currentNode;return t&&("StartTag"===t.type||t.type),t}get currentStartTag(){let t=this.currentNode;return t&&t.type,t}get currentEndTag(){let t=this.currentNode;return t&&t.type,t}get currentComment(){let t=this.currentNode;return t&&t.type,t}get currentData(){let t=this.currentNode;return t&&t.type,t}acceptNode(t){return this[t.type](t)}currentElement(){return E(this.elementStack)}sourceForNode(t,e){let s,r,n,a=t.loc.start.line-1,i=a-1,o=t.loc.start.column,l=[];for(e?(r=e.loc.end.line-1,n=e.loc.end.column):(r=t.loc.end.line-1,n=t.loc.end.column);i<r;)i++,s=this.lines[i],i===a?a===r?l.push(s.slice(o,n)):l.push(s.slice(o)):i===r?l.push(s.slice(0,n)):l.push(s);return l.join("\n")}}const Ut="beforeAttributeName";class Dt extends Vt{parse(t,e){t.loc;let s=_t.template({body:[],blockParams:e,loc:this.source.spanFor(t.loc)}),r=this.parseProgram(s,t);return this.pendingError?.eof(r.loc.getEnd()),r}Program(t,e){t.loc;let s=_t.blockItself({body:[],params:e,chained:t.chained,loc:this.source.spanFor(t.loc)});return this.parseProgram(s,t)}parseProgram(t,e){if(0===e.body.length)return t;let s;try{this.elementStack.push(t);for(let t of e.body)this.acceptNode(t)}finally{s=this.elementStack.pop()}if(t!==s){if("ElementNode"===s?.type)throw it(`Unclosed element \`${s.tag}\``,s.loc);t.type}return t}BlockStatement(t){if("comment"===this.tokenizer.state)return t.loc,void this.appendToCommentData(this.sourceForNode(t));if("data"!==this.tokenizer.state&&"beforeData"!==this.tokenizer.state)throw it("A block may only be used inside an HTML element or another block.",this.source.spanFor(t.loc));const{path:e,params:s,hash:r}=jt(this,t),n=this.source.spanFor(t.loc);let a,i=[];if(t.program.blockParams?.length){let e=r.loc.collapse("end");e=t.program.loc?e.withEnd(this.source.spanFor(t.program.loc).getStart()):t.program.body[0]?e.withEnd(this.source.spanFor(t.program.body[0].loc).getStart()):e.withEnd(n.getEnd()),a=Jt(this.source,t,e);const s=e.asString();let o=s.indexOf("|")+1;const l=s.indexOf("|",o);for(const r of t.program.blockParams){let t,n;t=o>=l?-1:s.indexOf(r,o),-1===t||t+r.length>l?(o=l,n=this.source.spanFor(T)):(o=t,n=e.sliceStartChars({skipStart:o,chars:r.length}),o+=r.length),i.push(_t.var({name:r,loc:n}))}}else a=Jt(this.source,t,n);const o=this.Program(a.program,i),l=a.inverse?this.Program(a.inverse,[]):null,c=_t.block({path:e,params:s,hash:r,defaultBlock:o,elseBlock:l,loc:this.source.spanFor(t.loc),openStrip:t.openStrip,inverseStrip:t.inverseStrip,closeStrip:t.closeStrip});Pt(this.currentElement(),c)}MustacheStatement(t){this.pendingError?.mustache(this.source.spanFor(t.loc));const{tokenizer:e}=this;if("comment"===e.state)return void this.appendToCommentData(this.sourceForNode(t));let s;const{escaped:r,loc:n,strip:a}=t;if("original"in t.path&&"...attributes"===t.path.original)throw it("Illegal use of ...attributes",this.source.spanFor(t.loc));if(Et(t.path))s=_t.mustache({path:this.acceptNode(t.path),params:[],hash:_t.hash({pairs:[],loc:this.source.spanFor(t.path.loc).collapse("end")}),trusting:!r,loc:this.source.spanFor(n),strip:a});else{const{path:e,params:i,hash:o}=jt(this,t);s=_t.mustache({path:e,params:i,hash:o,trusting:!r,loc:this.source.spanFor(n),strip:a})}switch(e.state){case"tagOpen":case"tagName":throw it("Cannot use mustaches in an elements tagname",s.loc);case"beforeAttributeName":Kt(this.currentStartTag,s);break;case"attributeName":case"afterAttributeName":this.beginAttributeValue(!1),this.finishAttributeValue(),Kt(this.currentStartTag,s),e.transitionTo(Ut);break;case"afterAttributeValueQuoted":Kt(this.currentStartTag,s),e.transitionTo(Ut);break;case"beforeAttributeValue":this.beginAttributeValue(!1),this.appendDynamicAttributeValuePart(s),e.transitionTo("attributeValueUnquoted");break;case"attributeValueDoubleQuoted":case"attributeValueSingleQuoted":case"attributeValueUnquoted":this.appendDynamicAttributeValuePart(s);break;default:Pt(this.currentElement(),s)}return s}appendDynamicAttributeValuePart(t){this.finalizeTextPart();const e=this.currentAttr;e.isDynamic=!0,e.parts.push(t)}finalizeTextPart(){const t=this.currentAttr.currentPart;null!==t&&(this.currentAttr.parts.push(t),this.startTextPart())}startTextPart(){this.currentAttr.currentPart=null}ContentStatement(t){!function(t,e){let s=e.loc.start.line,r=e.loc.start.column;const n=function(t,e){if(""===e)return{lines:t.split("\n").length-1,columns:0};const[s]=t.split(e),r=s.split(/\n/u),n=r.length-1;return{lines:n,columns:r[n].length}}(e.original,e.value);s+=n.lines,n.lines?r=n.columns:r+=n.columns,t.line=s,t.column=r}(this.tokenizer,t),this.tokenizer.tokenizePart(t.value),this.tokenizer.flushData()}CommentStatement(t){const{tokenizer:e}=this;if("comment"===e.state)return this.appendToCommentData(this.sourceForNode(t)),null;const{value:s,loc:r}=t,n=_t.mustacheComment({value:s,loc:this.source.spanFor(r)});switch(e.state){case"beforeAttributeName":case"afterAttributeName":this.currentStartTag.comments.push(n);break;case"beforeData":case"data":Pt(this.currentElement(),n);break;default:throw it(`Using a Handlebars comment when in the \`${e.state}\` state is not supported`,this.source.spanFor(t.loc))}return n}PartialStatement(t){throw it("Handlebars partials are not supported",this.source.spanFor(t.loc))}PartialBlockStatement(t){throw it("Handlebars partial blocks are not supported",this.source.spanFor(t.loc))}Decorator(t){throw it("Handlebars decorators are not supported",this.source.spanFor(t.loc))}DecoratorBlock(t){throw it("Handlebars decorator blocks are not supported",this.source.spanFor(t.loc))}SubExpression(t){const{path:e,params:s,hash:r}=jt(this,t);return _t.sexpr({path:e,params:s,hash:r,loc:this.source.spanFor(t.loc)})}PathExpression(t){const{original:e}=t;let s;if(-1!==e.indexOf("/")){if("./"===e.slice(0,2))throw it('Using "./" is not supported in Glimmer and unnecessary',this.source.spanFor(t.loc));if("../"===e.slice(0,3))throw it('Changing context using "../" is not supported in Glimmer',this.source.spanFor(t.loc));if(-1!==e.indexOf("."))throw it("Mixing '.' and '/' in paths is not supported in Glimmer; use only '.' to separate property paths",this.source.spanFor(t.loc));s=[t.parts.join("/")]}else{if("."===e)throw it("'.' is not a supported path in Glimmer; check for a path with a trailing '.'",this.source.spanFor(t.loc));s=t.parts}let r,n=!1;if(/^this(?:\..+)?$/u.test(e)&&(n=!0),n)r=_t.this({loc:this.source.spanFor({start:t.loc.start,end:{line:t.loc.start.line,column:t.loc.start.column+4}})});else if(t.data){const e=s.shift();if(void 0===e)throw it("Attempted to parse a path expression, but it was not valid. Paths beginning with @ must start with a-z.",this.source.spanFor(t.loc));r=_t.atName({name:`@${e}`,loc:this.source.spanFor({start:t.loc.start,end:{line:t.loc.start.line,column:t.loc.start.column+e.length+1}})})}else{const e=s.shift();if(void 0===e)throw it("Attempted to parse a path expression, but it was not valid. Paths must start with a-z or A-Z.",this.source.spanFor(t.loc));r=_t.var({name:e,loc:this.source.spanFor({start:t.loc.start,end:{line:t.loc.start.line,column:t.loc.start.column+e.length}})})}return _t.path({head:r,tail:s,loc:this.source.spanFor(t.loc)})}Hash(t){const e=t.pairs.map((t=>_t.pair({key:t.key,value:this.acceptNode(t.value),loc:this.source.spanFor(t.loc)})));return _t.hash({pairs:e,loc:this.source.spanFor(t.loc)})}StringLiteral(t){return _t.literal({type:"StringLiteral",value:t.value,loc:this.source.spanFor(t.loc)})}BooleanLiteral(t){return _t.literal({type:"BooleanLiteral",value:t.value,loc:this.source.spanFor(t.loc)})}NumberLiteral(t){return _t.literal({type:"NumberLiteral",value:t.value,loc:this.source.spanFor(t.loc)})}UndefinedLiteral(t){return _t.literal({type:"UndefinedLiteral",value:void 0,loc:this.source.spanFor(t.loc)})}NullLiteral(t){return _t.literal({type:"NullLiteral",value:null,loc:this.source.spanFor(t.loc)})}constructor(...t){super(...t),this.pendingError=null}}function jt(t,e){let s;switch(e.path.type){case"PathExpression":s=t.PathExpression(e.path);break;case"SubExpression":s=t.SubExpression(e.path);break;case"StringLiteral":case"UndefinedLiteral":case"NullLiteral":case"NumberLiteral":case"BooleanLiteral":{let s;throw s="BooleanLiteral"===e.path.type?e.path.original.toString():"StringLiteral"===e.path.type?`"${e.path.original}"`:"NullLiteral"===e.path.type?"null":"NumberLiteral"===e.path.type?e.path.value.toString():"undefined",it(`${e.path.type} "${"StringLiteral"===e.path.type?e.path.original:s}" cannot be called as a sub-expression, replace (${s}) with ${s}`,t.source.spanFor(e.path.loc))}}const r=e.params.map((e=>t.acceptNode(e))),n=P(r)?E(r).loc:s.loc;return{path:s,params:r,hash:e.hash?t.Hash(e.hash):_t.hash({pairs:[],loc:t.source.spanFor(n).collapse("end")})}}function Kt(t,e){const{path:s,params:r,hash:n,loc:a}=e;if(Et(s)){const r=`{{${function(t){return"UndefinedLiteral"===t.type?"undefined":JSON.stringify(t.value)}(s)}}}`;throw it(`In <${t.name} ... ${r} ..., ${r} is not a valid modifier`,e.loc)}const i=_t.elementModifier({path:s,params:r,hash:n,loc:a});t.modifiers.push(i)}function Jt(t,e,s){if(!e.program.loc){const r=e.program.body.at(0),n=e.program.body.at(-1);if(r&&n)e.program.loc={...r.loc,end:n.loc.end};else{const r=t.spanFor(e.loc);e.program.loc=s.withEnd(r.getEnd())}}let r=t.spanFor(e.program.loc).getEnd();return e.inverse&&!e.inverse.loc&&(e.inverse.loc=r.collapsed()),e}function Rt(t){return/[\t\n\f ]/u.test(t)}class Gt extends Dt{reset(){this.currentNode=null}beginComment(){this.currentNode={type:"CommentStatement",value:"",start:this.source.offsetFor(this.tagOpenLine,this.tagOpenColumn)}}appendToCommentData(t){this.currentComment.value+=t}finishComment(){Pt(this.currentElement(),_t.comment(this.finish(this.currentComment)))}beginData(){this.currentNode={type:"TextNode",chars:"",start:this.offset()}}appendToData(t){this.currentData.chars+=t}finishData(){Pt(this.currentElement(),_t.text(this.finish(this.currentData)))}tagOpen(){this.tagOpenLine=this.tokenizer.line,this.tagOpenColumn=this.tokenizer.column}beginStartTag(){this.currentNode={type:"StartTag",name:"",nameStart:null,nameEnd:null,attributes:[],modifiers:[],comments:[],params:[],selfClosing:!1,start:this.source.offsetFor(this.tagOpenLine,this.tagOpenColumn)}}beginEndTag(){this.currentNode={type:"EndTag",name:"",start:this.source.offsetFor(this.tagOpenLine,this.tagOpenColumn)}}finishTag(){let t=this.finish(this.currentTag);if("StartTag"===t.type){if(this.finishStartTag(),":"===t.name)throw it("Invalid named block named detected, you may have created a named block without a name, or you may have began your name with a number. Named blocks must have names that are at least one character long, and begin with a lower case letter",this.source.spanFor({start:this.currentTag.start.toJSON(),end:this.offset().toJSON()}));(g.has(t.name)||t.selfClosing)&&this.finishEndTag(!0)}else t.type,t.type,this.finishEndTag(!1)}finishStartTag(){let{name:t,nameStart:e,nameEnd:s}=this.currentStartTag,r=e.until(s),[n,...a]=t.split("."),i=_t.path({head:_t.head({original:n,loc:r.sliceStartChars({chars:n.length})}),tail:a,loc:r}),{attributes:o,modifiers:l,comments:c,params:h,selfClosing:u,loc:p}=this.finish(this.currentStartTag),d=_t.element({path:i,selfClosing:u,attributes:o,modifiers:l,comments:c,params:h,children:[],openTag:p,closeTag:u?null:j.broken(),loc:p});this.elementStack.push(d)}finishEndTag(t){let{start:e}=this.currentTag,s=this.finish(this.currentTag),r=this.elementStack.pop();this.validateEndTag(s,r,t);let n=this.currentElement();t?r.closeTag=null:r.selfClosing?r.closeTag:r.closeTag=e.until(this.offset()),r.loc=r.loc.withEnd(this.offset()),Pt(n,_t.element(r))}markTagAsSelfClosing(){let t=this.currentTag;if("StartTag"!==t.type)throw it("Invalid end tag: closing tag must not be self-closing",this.source.spanFor({start:t.start.toJSON(),end:this.offset().toJSON()}));t.selfClosing=!0}appendToTagName(t){let e=this.currentTag;if(e.name+=t,"StartTag"===e.type){let t=this.offset();null===e.nameStart&&(e.nameEnd,e.nameStart=t.move(-1)),e.nameEnd=t}}beginAttribute(){let t=this.offset();this.currentAttribute={name:"",parts:[],currentPart:null,isQuoted:!1,isDynamic:!1,start:t,valueSpan:t.collapsed()}}appendToAttributeName(t){this.currentAttr.name+=t,"as"===this.currentAttr.name&&this.parsePossibleBlockParams()}beginAttributeValue(t){this.currentAttr.isQuoted=t,this.startTextPart(),this.currentAttr.valueSpan=this.offset().collapsed()}appendToAttributeValue(t){let e=this.currentAttr.parts,s=e[e.length-1],r=this.currentAttr.currentPart;if(r)r.chars+=t,r.loc=r.loc.withEnd(this.offset());else{let e=this.offset();e="\n"===t?s?s.loc.getEnd():this.currentAttr.valueSpan.getStart():e.move(-1),this.currentAttr.currentPart=_t.text({chars:t,loc:e.collapsed()})}}finishAttributeValue(){this.finalizeTextPart();let t=this.currentTag,e=this.offset();if("EndTag"===t.type)throw it("Invalid end tag: closing tag must not have attributes",this.source.spanFor({start:t.start.toJSON(),end:e.toJSON()}));let{name:s,parts:r,start:n,isQuoted:a,isDynamic:i,valueSpan:o}=this.currentAttr;if(s.startsWith("|")&&0===r.length&&!a&&!i)throw it("Invalid block parameters syntax: block parameters must be preceded by the `as` keyword",n.until(n.move(s.length)));let l=this.assembleAttributeValue(r,a,i,n.until(e));l.loc=o.withEnd(e);let c=_t.attr({name:s,value:l,loc:n.until(e)});this.currentStartTag.attributes.push(c)}parsePossibleBlockParams(){const t=/[!"#%&'()*+./;<=>@[\\\]^`{|}~]/u;this.tokenizer.state;const e=this.currentStartTag,s=this.currentAttr;let r={state:"PossibleAs"};const n={PossibleAs:t=>{if(r.state,Rt(t))r={state:"BeforeStartPipe"},this.tokenizer.transitionTo("afterAttributeName"),this.tokenizer.consume();else{if("|"===t)throw it('Invalid block parameters syntax: expecting at least one space character between "as" and "|"',s.start.until(this.offset().move(1)));r={state:"Done"}}},BeforeStartPipe:t=>{r.state,Rt(t)?this.tokenizer.consume():"|"===t?(r={state:"BeforeBlockParamName"},this.tokenizer.transitionTo("beforeAttributeName"),this.tokenizer.consume()):r={state:"Done"}},BeforeBlockParamName:t=>{if(r.state,Rt(t))this.tokenizer.consume();else if(""===t)r={state:"Done"},this.pendingError={mustache(t){throw it("Invalid block parameters syntax: mustaches cannot be used inside parameters list",t)},eof(t){throw it('Invalid block parameters syntax: expecting the tag to be closed with ">" or "/>" after parameters list',s.start.until(t))}};else if("|"===t){if(0===e.params.length)throw it("Invalid block parameters syntax: empty parameters list, expecting at least one identifier",s.start.until(this.offset().move(1)));r={state:"AfterEndPipe"},this.tokenizer.consume()}else{if(">"===t||"/"===t)throw it('Invalid block parameters syntax: incomplete parameters list, expecting "|" but the tag was closed prematurely',s.start.until(this.offset().move(1)));r={state:"BlockParamName",name:t,start:this.offset()},this.tokenizer.consume()}},BlockParamName:n=>{if(r.state,""===n)r={state:"Done"},this.pendingError={mustache(t){throw it("Invalid block parameters syntax: mustaches cannot be used inside parameters list",t)},eof(t){throw it('Invalid block parameters syntax: expecting the tag to be closed with ">" or "/>" after parameters list',s.start.until(t))}};else if("|"===n||Rt(n)){let s=r.start.until(this.offset());if("this"===r.name||t.test(r.name))throw it(`Invalid block parameters syntax: invalid identifier name \`${r.name}\``,s);e.params.push(_t.var({name:r.name,loc:s})),r="|"===n?{state:"AfterEndPipe"}:{state:"BeforeBlockParamName"},this.tokenizer.consume()}else{if(">"===n||"/"===n)throw it('Invalid block parameters syntax: expecting "|" but the tag was closed prematurely',s.start.until(this.offset().move(1)));r.name+=n,this.tokenizer.consume()}},AfterEndPipe:t=>{r.state,Rt(t)?this.tokenizer.consume():""===t?(r={state:"Done"},this.pendingError={mustache(t){throw it("Invalid block parameters syntax: modifiers cannot follow parameters list",t)},eof(t){throw it('Invalid block parameters syntax: expecting the tag to be closed with ">" or "/>" after parameters list',s.start.until(t))}}):">"===t||"/"===t?r={state:"Done"}:(r={state:"Error",message:'Invalid block parameters syntax: expecting the tag to be closed with ">" or "/>" after parameters list',start:this.offset()},this.tokenizer.consume())},Error:t=>{if(r.state,""===t||"/"===t||">"===t||Rt(t))throw it(r.message,r.start.until(this.offset()));this.tokenizer.consume()},Done:()=>{}};let a;do{a=this.tokenizer.peek(),n[r.state](a)}while("Done"!==r.state&&""!==a);r.state}reportSyntaxError(t){throw it(t,this.offset().collapsed())}assembleConcatenatedValue(t){let e=N(t),s=E(t);return _t.concat({parts:t,loc:this.source.spanFor(e.loc).extend(this.source.spanFor(s.loc))})}validateEndTag(t,e,s){if(g.has(t.name)&&!s)throw it(`<${t.name}> elements do not need end tags. You should remove it`,t.loc);if("ElementNode"!==e.type)throw it(`Closing tag </${t.name}> without an open tag`,t.loc);if(e.tag!==t.name)throw it(`Closing tag </${t.name}> did not match last open tag <${e.tag}> (on line ${e.loc.startPosition.line})`,t.loc)}assembleAttributeValue(t,e,s,r){if(s){if(e)return this.assembleConcatenatedValue(t);{const[e,s]=t;if(void 0===s||"TextNode"===s.type&&"/"===s.chars)return e;throw it("An unquoted attribute value must be a string or a mustache, preceded by whitespace or a '=' character, and followed by whitespace, a '>' character, or '/>'",r)}}return P(t)?t[0]:_t.text({chars:"",loc:r})}constructor(...t){super(...t),this.tagOpenLine=0,this.tagOpenColumn=0}}const Yt={parse:qt,builders:zt,print:v,traverse:vt,Walker:St};class Wt extends a{constructor(){super({})}parse(){}}function qt(t,s={}){let a,i,o,l=s.mode||"precompile";"string"==typeof t?(a=new tt(t,s.meta?.moduleName),i="codemod"===l?r(t,s.parseOptions):n(t,s.parseOptions)):t instanceof tt?(a=t,i="codemod"===l?r(t.source,s.parseOptions):n(t.source,s.parseOptions)):(a=new tt("",s.meta?.moduleName),i=t),"codemod"===l&&(o=new Wt);let c=j.forCharPositions(a,0,a.source.length);i.loc={source:"(program)",start:c.startPosition,end:c.endPosition};let h=new Gt(a,o,l).parse(i,s.locals??[]);if(s.plugins?.ast)for(const t of s.plugins.ast)vt(h,t(e({},s,{syntax:Yt},{plugins:void 0})).visitor);return h}function Qt(t,e,s,r){const n=function(t,e,s){if("PathExpression"===t.type){if("AtHead"===t.head.type||"ThisHead"===t.head.type)return;const s=t.head.name;if(-1===e.indexOf(s))return s}else if("ElementNode"===t.type){const{tag:r}=t,n=r.charAt(0);if(":"===n||"@"===n)return;if(!s.includeHtmlElements&&-1===r.indexOf(".")&&r.toLowerCase()===r)return;if("this."===r.substr(0,5))return;if(r.includes(".")){let[t]=r.split(".");if(e.includes(t))return}if(e.includes(r))return;return r}}(e,s,r);if(void 0!==n&&"@"!==n[0]){const e=n.split(".")[0];e&&!s.includes(e)&&t.add(e)}}function Xt(t,e={includeHtmlElements:!1,includeKeywords:!1}){const s=qt(t),r=new Set,n=[];vt(s,{Block:{enter({blockParams:t}){t.forEach((t=>{n.push(t)}))},exit({blockParams:t}){t.forEach((()=>{n.pop()}))}},ElementNode:{enter(t){t.blockParams.forEach((t=>{n.push(t)})),Qt(r,t,n,e)},exit({blockParams:t}){t.forEach((()=>{n.pop()}))}},PathExpression(t){Qt(r,t,n,e)}});let a=[];return r.forEach((t=>a.push(t))),e.includeKeywords||(a=a.filter((t=>!S(t)))),a}function Zt(t){if(void 0!==t){const s=t;return{fields:()=>class{constructor(t){this.type=s,e(this,t)}}}}return{fields:()=>class{constructor(t){e(this,t)}}}}class te extends(Zt().fields()){static empty(t){return new te({loc:t,positional:ee.empty(t),named:se.empty(t)})}static named(t){return new te({loc:t.loc,positional:ee.empty(t.loc.collapse("end")),named:t})}nth(t){return this.positional.nth(t)}get(t){return this.named.get(t)}isEmpty(){return this.positional.isEmpty()&&this.named.isEmpty()}}class ee extends(Zt().fields()){static empty(t){return new ee({loc:t,exprs:[]})}get size(){return this.exprs.length}nth(t){return this.exprs[t]||null}isEmpty(){return 0===this.exprs.length}}class se extends(Zt().fields()){static empty(t){return new se({loc:t,entries:[]})}get size(){return this.entries.length}get(t){let e=this.entries.filter((e=>e.name.chars===t))[0];return e?e.value:null}isEmpty(){return 0===this.entries.length}}class re{constructor(t){this.loc=t.name.loc.extend(t.value.loc),this.name=t.name,this.value=t.value}}class ne extends(Zt("HtmlAttr").fields()){}class ae extends(Zt("SplatAttr").fields()){}class ie extends(Zt().fields()){toNamedArgument(){return new re({name:this.name,value:this.value})}}class oe extends(Zt("ElementModifier").fields()){}class le extends(Zt("GlimmerComment").fields()){}class ce extends(Zt("HtmlText").fields()){}class he extends(Zt("HtmlComment").fields()){}class ue extends(Zt("AppendContent").fields()){get callee(){return"Call"===this.value.type?this.value.callee:this.value}get args(){return"Call"===this.value.type?this.value.args:te.empty(this.value.loc.collapse("end"))}}class pe extends(Zt("InvokeBlock").fields()){}class de extends(Zt("InvokeComponent").fields()){get args(){let t=this.componentArgs.map((t=>t.toNamedArgument()));return te.named(new se({loc:et.range(t,this.callee.loc.collapse("end")),entries:t}))}}class me extends(Zt("SimpleElement").fields()){get args(){let t=this.componentArgs.map((t=>t.toNamedArgument()));return te.named(new se({loc:et.range(t,this.tag.loc.collapse("end")),entries:t}))}}class fe extends(Zt("Literal").fields()){toSlice(){return new D({loc:this.loc,chars:this.value})}}class ge extends(Zt("Path").fields()){}class be extends(Zt("K