@glimmer/syntax
Version:
1 lines • 71.7 kB
JavaScript
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" ";case 34:return""";case 38:return"&";default:return t}}function m(t){switch(t.charCodeAt(0)){case 160:return" ";case 38:return"&";case 60:return"<";case 62:return">";default:return t}}function f(t){return c.test(t)?t.replace(h,d):t}function g(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 b=new Set(["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"]);function k(){return[...b]}const w=/^\S/u;function y(t){return b.has(t.toLowerCase())&&t[0]?.toLowerCase()===t[0]}class v{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&&w.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(g);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||y(t.tag)||(this.buffer+=`</${t.tag}>`)}AttrNode(t){if(this.handledByOverride(t))return;let{name:e,value:s}=t;this.buffer+=e,!e.startsWith("@")&&"TextNode"==s.type&&0===s.chars.length||(this.buffer+="=",this.AttrNodeValue(s))}AttrNodeValue(t){if("TextNode"===t.type){let e='"';"raw"===this.options.entityEncoding&&t.chars.includes('"')&&!t.chars.includes("'")&&(e="'"),this.buffer+=e,this.TextNode(t,e),this.buffer+=e}else this.Node(t)}TextNode(t,e){this.handledByOverride(t)||("raw"===this.options.entityEncoding?e&&t.chars.includes(e)?this.buffer+=f(t.chars):this.buffer+=t.chars:this.buffer+=e?f(t.chars):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,'"'):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 S(t,e={entityEncoding:"transformed"}){return t?new v(e).print(t):""}function x(t,e){return t in P&&(void 0===e||P[t].includes(e))}const P={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 E(t){return!!t&&t.length>0}function N(t){return 0===t.length?void 0:t[t.length-1]}function C(t){return 0===t.length?void 0:t[0]}const A=Object.freeze({line:1,column:0}),T=Object.freeze({source:"(synthetic)",start:A,end:A}),L=Object.freeze({source:"(nonexistent)",start:A,end:A}),B=Object.freeze({source:"(broken)",start:A,end:A}),O="CharPosition",H="HbsPosition",F="InternalsSynthetic",$="NonExistent",z="Broken",M="MATCH_ANY",I="IS_INVISIBLE";class _{constructor(t){this._whens=t}first(t){for(const e of this._whens){const s=e.match(t);if(E(s))return s[0]}return null}}class V{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 z:case F:case $:return I;default:return t}}(t),s=[],r=this._map.get(e),n=this._map.get(M);return r&&s.push(r),n&&s.push(n),s}constructor(){this._map=new Map}}function U(t){return t(new D).validate()}class D{validate(){return(t,e)=>this.matchFor(t.kind,e.kind)(t,e)}matchFor(t,e){const s=this._whens.match(t);return E(s),new _(s).first(e)}when(t,e,s){return this._whens.get(t,(()=>new V)).add(e,s),this}constructor(){this._whens=new V}}class j{static synthetic(t){let e=J.synthetic(t);return new j({loc:e,chars:t})}static load(t,e){return new j({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 W($,L).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===$?J.NON_EXISTENT:s===z?J.broken(B):void t(s)}static forHbsLoc(t,e){const s=new X(t,e.start),r=new X(t,e.end);return new R(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 W(F,L,t).wrap()}static broken(t=B){return new W(z,t).wrap()}constructor(t){var e;this.data=t,this.isInvisible=(e=t.kind)!==O&&e!==H}getStart(){return this.data.getStart().wrap()}getEnd(){return this.data.getEnd().wrap()}get loc(){const t=this.data.toHbsSpan();return null===t?B: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 JSON.stringify(e),JSON.stringify(t),new j({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=O,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 R(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 R{#e;#s;constructor(t,e,s=null){this.source=t,this.hbsPositions=e,this.kind=H,this.#e=null,this.#s=s}serialize(){const t=this.toCharPosSpan();return null===t?z: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 X(this.source,t,null)),void 0!==e&&(this.updateProvided(e,"end"),this.hbsPositions.end=new X(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 W{constructor(t,e,s=null){this.kind=t,this.loc=e,this.string=s}serialize(){switch(this.kind){case z:case $:return this.kind;case F: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 Z(this.kind,this.loc.start)}getEnd(){return new Z(this.kind,this.loc.end)}toCharPosSpan(){return this}toHbsSpan(){return null}toHbsLoc(){return B}}const G=U((t=>t.when(H,H,((t,e)=>new R(t.source,{start:t,end:e}).wrap())).when(O,O,((t,e)=>new K(t.source,{start:t,end:e}).wrap())).when(O,H,((t,e)=>{const s=e.toCharPos();return null===s?new W(z,B).wrap():G(t,s)})).when(H,O,((t,e)=>{const s=t.toCharPos();return null===s?new W(z,B).wrap():G(s,e)})).when(I,M,(t=>new W(t.kind,B).wrap())).when(M,I,((t,e)=>new W(e.kind,B).wrap())))),Y="BROKEN";class q{static forHbsPos(t,e){return new X(t,e,null).wrap()}static broken(t=A){return new Z(z,t).wrap()}constructor(t){this.data=t}get offset(){const t=this.data.toCharPos();return null===t?null:t.offset}eql(t){return tt(this.data,t.data)}until(t){return G(this.data,t.data)}move(t){const e=this.data.toCharPos();if(null===e)return q.broken();{const s=e.offset+t;return e.source.validate(s)?new Q(e.source,s).wrap():q.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=O,this._locPos=null}toCharPos(){return this}toJSON(){const t=this.toHbsPos();return null===t?A:t.toJSON()}wrap(){return new q(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 X(this.source,e,this.charPos)}return t===Y?null:t}}class X{constructor(t,e,s=null){this.source=t,this.hbsPos=e,this.kind=H,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 q(this)}toHbsPos(){return this}}class Z{constructor(t,e){this.kind=t,this.pos=e}toCharPos(){return null}toJSON(){return this.pos}wrap(){return new q(this)}get offset(){return null}}const tt=U((t=>t.when(H,H,(({hbsPos:t},{hbsPos:e})=>t.column===e.column&&t.line===e.line)).when(O,O,(({charPos:t},{charPos:e})=>t===e)).when(O,H,(({offset:t},e)=>t===e.toCharPos()?.offset)).when(H,O,((t,{offset:e})=>t.toCharPos()?.offset===e)).when(M,M,(()=>!1))));class et{static from(t,e={}){return new et(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 q.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 st{static range(t,e=J.NON_EXISTENT){return new st(t.map(rt)).getRangeOffset(e)}constructor(t=[]){this._span=t}add(t){this._span.push(t)}getRangeOffset(t){if(E(this._span)){let t=C(this._span),e=N(this._span);return t.extend(e)}return t}}function rt(t){if(Array.isArray(t)){let e=C(t),s=N(t);return rt(e).extend(rt(s))}return t instanceof J?t:t.loc}function nt(t){return!Array.isArray(t)||0!==t.length}function at(t,e){return nt(t)?rt(t):e}var it=Object.freeze({__proto__:null,NON_EXISTENT_LOCATION:L,SYNTHETIC_LOCATION:T,Source:et,SourceOffset:q,SourceSlice:j,SourceSpan:J,SpanList:st,UNKNOWN_POSITION:A,hasSpan:nt,loc:rt,maybeLoc:at});function ot(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 lt={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"]},ct=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 ht(t,e,s){return new ct("Cannot remove a node unless it is part of an array",t,e,s)}function ut(t,e,s){return new ct("Cannot replace a node with multiple nodes unless it is part of an array",t,e,s)}function pt(t,e){return new ct("Replacing and removing in key handlers is not yet supported.",t,null,e)}class dt{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 mt(this)}}}class mt{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 ft(t){return"function"==typeof t?t:t.enter}function gt(t){return"function"==typeof t?void 0:t.exit}function bt(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=ft(l),r=gt(l)),void 0!==s&&(n=s(a,e)),null!=n){if(JSON.stringify(a)!==JSON.stringify(n))return Array.isArray(n)?(yt(t,n,i,o),n):bt(t,new dt(n,i,o))||n;n=void 0}if(void 0===n){let s=lt[a.type];for(let r=0;r<s.length;r++)wt(t,l,e,s[r]);void 0!==r&&(n=r(a,e))}return n}function kt(t,e,s){t[e]=s}function wt(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=ft(t),a=gt(t))}if(void 0!==n&&void 0!==n(i,r))throw pt(i,r);if(Array.isArray(o))yt(t,o,s,r);else{let e=bt(t,new dt(o,s,r));void 0!==e&&function(t,e,s,r){if(null===r)throw ht(s,t,e);if(Array.isArray(r)){if(1!==r.length)throw 0===r.length?ht(s,t,e):ut(s,t,e);kt(t,e,r[0])}else kt(t,e,r)}(i,r,o,e)}if(void 0!==a&&void 0!==a(i,r))throw pt(i,r)}}function yt(t,e,s,r){for(let n=0;n<e.length;n++){let a=e[n],i=bt(t,new dt(a,s,r));void 0!==i&&(n+=vt(e,n,i)-1)}}function vt(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 St(t,e){bt(e,new dt(t))}class xt{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 Pt(this,t.body,e);case"ElementNode":return void Pt(this,t.children,e);case"BlockStatement":return this.visit(t.program,e),void this.visit(t.inverse||null,e);default:return}}}function Pt(t,e,s){for(const r of e)t.visit(r,s)}function Et(t,e){(function(t){switch(t.type){case"Block":case"Template":return t.body;case"ElementNode":return t.children}})(t).push(e)}function Nt(t){return"StringLiteral"===t.type||"BooleanLiteral"===t.type||"NumberLiteral"===t.type||"NullLiteral"===t.type||"UndefinedLiteral"===t.type}let Ct;function At(){return Ct||(Ct=new et("","(synthetic)")),Ct}function Tt(t,e){return Vt.var({name:t,loc:zt(e||null)})}function Lt(t,e){let s=zt(e||null);if("string"!=typeof t){if("type"in t)return t;{t.head.indexOf(".");let{head:r,tail:n}=t;return Vt.path({head:Vt.head({original:r,loc:s.sliceStartChars({chars:r.length})}),tail:n,loc:zt(e||null)})}}let{head:r,tail:n}=function(t,e){let[s,...r]=t.split("."),n=Vt.head({original:s,loc:zt(e||null)});return Vt.path({head:n,tail:r,loc:zt(e||null)})}(t,s);return Vt.path({head:r,tail:n,loc:s})}function Bt(t,e,s){return Vt.literal({type:t,value:e,loc:zt(s||null)})}function Ot(t=[],e){return Vt.hash({pairs:t,loc:zt(e||null)})}function Ht(t){return t.map((t=>"string"==typeof t?Vt.var({name:t,loc:J.synthetic(t)}):t))}function Ft(t=[],e=[],s=!1,r){return Vt.blockItself({body:t,params:Ht(e),chained:s,loc:zt(r||null)})}function $t(t=[],e=[],s){return Vt.template({body:t,blockParams:e,loc:zt(s||null)})}function zt(...t){if(1===t.length){let e=t[0];return e&&"object"==typeof e?J.forHbsLoc(At(),e):J.forHbsLoc(At(),T)}{let[e,s,r,n,a]=t,i=a?new et("",a):At();return J.forHbsLoc(i,{start:{line:e,column:s},end:{line:r||e,column:n||s}})}}var Mt={mustache:function(t,e=[],s=Ot([]),r=!1,n,a){return Vt.mustache({path:Lt(t),params:e,hash:s,trusting:r,strip:a,loc:zt(n||null)})},block:function(t,e,s,r,n=null,a,i,o,l){let c,h=null;return c="Template"===r.type?Vt.blockItself({params:Ht(r.blockParams),body:r.body,loc:r.loc}):r,"Template"===n?.type?(n.blockParams.length,h=Vt.blockItself({params:[],body:n.body,loc:n.loc})):h=n,Vt.block({path:Lt(t),params:e||[],hash:s||Ot([]),defaultBlock:c,elseBlock:h,loc:zt(a||null),openStrip:i,inverseStrip:o,closeStrip:l})},comment:function(t,e){return Vt.comment({value:t,loc:zt(e||null)})},mustacheComment:function(t,e){return Vt.mustacheComment({value:t,loc:zt(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=Lt(t.slice(0,-1)),r=!0):s=Lt(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=Lt(t.name),r=t.selfClosing);let p=a?.map((t=>"string"==typeof t?Tt(t):t)),d=null;return h?d=zt(h):void 0===h&&(d=r||y(s.original)?null:zt(null)),Vt.element({path:s,selfClosing:r||!1,attributes:n||[],params:p||[],modifiers:i||[],comments:o||[],children:l||[],openTag:zt(c||null),closeTag:d,loc:zt(u||null)})},elementModifier:function(t,e,s,r){return Vt.elementModifier({path:Lt(t),params:e||[],hash:s||Ot([]),loc:zt(r||null)})},attr:function(t,e,s){return Vt.attr({name:t,value:e,loc:zt(s||null)})},text:function(t="",e){return Vt.text({chars:t,loc:zt(e||null)})},sexpr:function(t,e=[],s=Ot([]),r){return Vt.sexpr({path:Lt(t),params:e,hash:s,loc:zt(r||null)})},concat:function(t,e){if(!E(t))throw new Error("b.concat requires at least one part");return Vt.concat({parts:t,loc:zt(e||null)})},hash:Ot,pair:function(t,e,s){return Vt.pair({key:t,value:e,loc:zt(s||null)})},literal:Bt,program:function(t,e,s){return e&&e.length?Ft(t,e,!1,s):$t(t,[],s)},blockItself:Ft,template:$t,loc:zt,pos:function(t,e){return Vt.pos({line:t,column:e})},path:Lt,fullPath:function(t,e=[],s){return Vt.path({head:t,tail:e,loc:zt(s||null)})},head:function(t,e){return Vt.head({original:t,loc:zt(e||null)})},at:function(t,e){return Vt.atName({name:t,loc:zt(e||null)})},var:Tt,this:function(t){return Vt.this({loc:zt(t||null)})},string:It("StringLiteral"),boolean:It("BooleanLiteral"),number:It("NumberLiteral"),undefined:()=>Bt("UndefinedLiteral",void 0),null:()=>Bt("NullLiteral",null)};function It(t){return function(e,s){return Bt(t,e,s)}}const _t={close:!1,open:!1},Vt=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=>Vt.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=_t}){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=_t,inverseStrip:o=_t,closeStrip:l=_t}){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=>Vt.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=Mt.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 Ut{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 N(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 Dt="beforeAttributeName";class jt extends Ut{parse(t,e){t.loc;let s=Vt.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=Vt.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 ot(`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 ot("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=Rt(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(L)):(o=t,n=e.sliceStartChars({skipStart:o,chars:r.length}),o+=r.length),i.push(Vt.var({name:r,loc:n}))}}else a=Rt(this.source,t,n);const o=this.Program(a.program,i),l=a.inverse?this.Program(a.inverse,[]):null,c=Vt.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});Et(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 ot("Illegal use of ...attributes",this.source.spanFor(t.loc));if(Nt(t.path))s=Vt.mustache({path:this.acceptNode(t.path),params:[],hash:Vt.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=Vt.mustache({path:e,params:i,hash:o,trusting:!r,loc:this.source.spanFor(n),strip:a})}switch(e.state){case"tagOpen":case"tagName":throw ot("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(Dt);break;case"afterAttributeValueQuoted":Kt(this.currentStartTag,s),e.transitionTo(Dt);break;case"beforeAttributeValue":this.beginAttributeValue(!1),this.appendDynamicAttributeValuePart(s),e.transitionTo("attributeValueUnquoted");break;case"attributeValueDoubleQuoted":case"attributeValueSingleQuoted":case"attributeValueUnquoted":this.appendDynamicAttributeValuePart(s);break;default:Et(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=Vt.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":Et(this.currentElement(),n);break;default:throw ot(`Using a Handlebars comment when in the \`${e.state}\` state is not supported`,this.source.spanFor(t.loc))}return n}PartialStatement(t){throw ot("Handlebars partials are not supported",this.source.spanFor(t.loc))}PartialBlockStatement(t){throw ot("Handlebars partial blocks are not supported",this.source.spanFor(t.loc))}Decorator(t){throw ot("Handlebars decorators are not supported",this.source.spanFor(t.loc))}DecoratorBlock(t){throw ot("Handlebars decorator blocks are not supported",this.source.spanFor(t.loc))}SubExpression(t){const{path:e,params:s,hash:r}=Jt(this,t);return Vt.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 ot('Using "./" is not supported in Glimmer and unnecessary',this.source.spanFor(t.loc));if("../"===e.slice(0,3))throw ot('Changing context using "../" is not supported in Glimmer',this.source.spanFor(t.loc));if(-1!==e.indexOf("."))throw ot("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 ot("'.' 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=Vt.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 ot("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=Vt.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 ot("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=Vt.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 Vt.path({head:r,tail:s,loc:this.source.spanFor(t.loc)})}Hash(t){const e=t.pairs.map((t=>Vt.pair({key:t.key,value:this.acceptNode(t.value),loc:this.source.spanFor(t.loc)})));return Vt.hash({pairs:e,loc:this.source.spanFor(t.loc)})}StringLiteral(t){return Vt.literal({type:"StringLiteral",value:t.value,loc:this.source.spanFor(t.loc)})}BooleanLiteral(t){return Vt.literal({type:"BooleanLiteral",value:t.value,loc:this.source.spanFor(t.loc)})}NumberLiteral(t){return Vt.literal({type:"NumberLiteral",value:t.value,loc:this.source.spanFor(t.loc)})}UndefinedLiteral(t){return Vt.literal({type:"UndefinedLiteral",value:void 0,loc:this.source.spanFor(t.loc)})}NullLiteral(t){return Vt.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",ot(`${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=E(r)?N(r).loc:s.loc;return{path:s,params:r,hash:e.hash?t.Hash(e.hash):Vt.hash({pairs:[],loc:t.source.spanFor(n).collapse("end")})}}function Kt(t,e){const{path:s,params:r,hash:n,loc:a}=e;if(Nt(s)){const r=`{{${function(t){return"UndefinedLiteral"===t.type?"undefined":JSON.stringify(t.value)}(s)}}}`;throw ot(`In <${t.name} ... ${r} ..., ${r} is not a valid modifier`,e.loc)}const i=Vt.elementModifier({path:s,params:r,hash:n,loc:a});t.modifiers.push(i)}function Rt(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 Wt(t){return/[\t\n\f ]/u.test(t)}class Gt extends jt{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(){Et(this.currentElement(),Vt.comment(this.finish(this.currentComment)))}beginData(){this.currentNode={type:"TextNode",chars:"",start:this.offset()}}appendToData(t){this.currentData.chars+=t}finishData(){Et(this.currentElement(),Vt.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 ot("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()}));(b.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=Vt.path({head:Vt.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=Vt.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()),Et(n,Vt.element(r))}markTagAsSelfClosing(){let t=this.currentTag;if("StartTag"!==t.type)throw ot("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=Vt.text({chars:t,loc:e.collapsed()})}}finishAttributeValue(){this.finalizeTextPart();let t=this.currentTag,e=this.offset();if("EndTag"===t.type)throw ot("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 ot("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=Vt.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,Wt(t))r={state:"BeforeStartPipe"},this.tokenizer.transitionTo("afterAttributeName"),this.tokenizer.consume();else{if("|"===t)throw ot('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,Wt(t)?this.tokenizer.consume():"|"===t?(r={state:"BeforeBlockParamName"},this.tokenizer.transitionTo("beforeAttributeName"),this.tokenizer.consume()):r={state:"Done"}},BeforeBlockParamName:t=>{if(r.state,Wt(t))this.tokenizer.consume();else if(""===t)r={state:"Done"},this.pendingError={mustache(t){throw ot("Invalid block parameters syntax: mustaches cannot be used inside parameters list",t)},eof(t){throw ot('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 ot("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 ot('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 ot("Invalid block parameters syntax: mustaches cannot be used inside parameters list",t)},eof(t){throw ot('Invalid block parameters syntax: expecting the tag to be closed with ">" or "/>" after parameters list',s.start.until(t))}};else if("|"===n||Wt(n)){let s=r.start.until(this.offset());if("this"===r.name||t.test(r.name))throw ot(`Invalid block parameters syntax: invalid identifier name \`${r.name}\``,s);e.params.push(Vt.var({name:r.name,loc:s})),r="|"===n?{state:"AfterEndPipe"}:{state:"BeforeBlockParamName"},this.tokenizer.consume()}else{if(">"===n||"/"===n)throw ot('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,Wt(t)?this.tokenizer.consume():""===t?(r={state:"Done"},this.pendingError={mustache(t){throw ot("Invalid block parameters syntax: modifiers cannot follow parameters list",t)},eof(t){throw ot('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||Wt(t))throw ot(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 ot(t,this.offset().collapsed())}assembleConcatenatedValue(t){let e=C(t),s=N(t);return Vt.concat({parts:t,loc:this.source.spanFor(e.loc).extend(this.source.spanFor(s.loc))})}validateEndTag(t,e,s){if(b.has(t.name)&&!s)throw ot(`<${t.name}> elements do not need end tags. You should remove it`,t.loc);if("ElementNode"!==e.type)throw ot(`Closing tag </${t.name}> without an open tag`,t.loc);if(e.tag!==t.name)throw ot(`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 ot("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 E(t)?t[0]:Vt.text({chars:"",loc:r})}constructor(...t){super(...t),this.tagOpenLine=0,this.tagOpenColumn=0}}const Yt={parse:Qt,builders:Mt,print:S,traverse:St,Walker:xt};class qt extends a{constructor(){super({})}parse(){}}function Qt(t,s={}){let a,i,o,l=s.mode||"precompile";"string"==typeof t?(a=new et(t,s.meta?.moduleName),i="codemod"===l?r(t,s.parseOptions):n(t,s.parseOptions)):t instanceof et?(a=t,i="codemod"===l?r(t.source,s.parseOptions):n(t.source,s.parseOptions)):(a=new et("",s.meta?.moduleName),i=t),"codemod"===l&&(o=new qt);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)St(h,t(e({},s,{syntax:Yt},{plugins:void 0})).visitor);return h}function Xt(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 Zt(t,e={includeHtmlElements:!1,includeKeywords:!1}){const s=Qt(t),r=new Set,n=[];St(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)})),Xt(r,t,n,e)},exit({blockParams:t}){t.forEach((()=>{n.pop()}))}},PathExpression(t){Xt(r,t,n,e)}});let a=[];return r.forEach((t=>a.push(t))),e.includeKeywords||(a=a.filter((t=>!x(t)))),a}function te(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 ee extends(te().fields()){static empty(t){return new ee({loc:t,positional:se.empty(t),named:re.empty(t)})}static named(t){return new ee({loc:t.loc,positional:se.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 se extends(te().fields()){static empty(t){return new se({loc:t,exprs:[]})}get size(){return this.exprs.length}nth(t){return this.exprs[t]||null}isEmpty(){return 0===this.exprs.length}}class re extends(te().fields()){static empty(t){return new re({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 ne{constructor(t){this.loc=t.name.loc.extend(t.value.loc),this.name=t.name,this.value=t.value}}class ae extends(te("HtmlAttr").fields()){}class ie extends(te("SplatAttr").fields()){}class oe extends(te().fields()){toNamedArgument(){return new ne({name:this.name,value:this.value})}}class le extends(te("ElementModifier").fields()){}class ce extends(te("GlimmerComment").fields()){}class he extends(te("HtmlText").fields()){}class ue extends(te("HtmlComment").fields()){}class pe extends(te("AppendContent").fields()){get callee(){return"Call"===this.value.type?this.value.callee:this.value}get args(){return"Call"===this.value.type?this.value.args:ee.empty(this.value.loc.collapse("end"))}}class de extends(te("InvokeBlock").fields()){}class me extends(te("InvokeComponent").fields()){get args(){let t=this.componentArgs.map((t=>t.toNamedArgument()));return ee.named(new re({loc:st.range(t,this.callee.loc.collapse("end")),entries:t}))}}class fe extends(te("SimpleElement").fields()){get args(){let t=this.componentArgs.map((t=>t.toNamedArgument()));return ee.named(ne