MCPcopy Create free account
hub / github.com/Make-md/makemd / writeToStreamAndMap

Method writeToStreamAndMap

main.js:56–56  ·  view source on GitHub ↗
(t,r)

Source from the content-addressed store, hash-verified

54`,o):(e.write("/*"),aJe(e,o.value,r,n),e.write("*/"+n))}}function oJe(e){let t=e;for(;t!=null;){let{type:r}=t;if(r[0]==="C"&&r[1]==="a")return!0;if(r[0]==="M"&&r[1]==="e"&&r[2]==="m")t=t.object;else return!1}}function pY(e,t){let{generator:r}=e,{declarations:n}=t;e.write(t.kind+" ");let{length:i}=n;if(i>0){r.VariableDeclarator(n[0],e);for(let a=1;a<i;a++)e.write(", "),r.VariableDeclarator(n[a],e)}}var upe,cpe,fpe,dpe,ppe,mpe,sJe={Program(e,t){let r=t.indent.repeat(t.indentLevel),{lineEnd:n,writeComments:i}=t;i&&e.comments!=null&&$c(t,e.comments,r,n);let a=e.body,{length:o}=a;for(let s=0;s<o;s++){let l=a[s];i&&l.comments!=null&&$c(t,l.comments,r,n),t.write(r),this[l.type](l,t),t.write(n)}i&&e.trailingComments!=null&&$c(t,e.trailingComments,r,n)},BlockStatement:mpe=function(e,t){let r=t.indent.repeat(t.indentLevel++),{lineEnd:n,writeComments:i}=t,a=r+t.indent;t.write("{");let o=e.body;if(o!=null&&o.length>0){t.write(n),i&&e.comments!=null&&$c(t,e.comments,a,n);let{length:s}=o;for(let l=0;l<s;l++){let u=o[l];i&&u.comments!=null&&$c(t,u.comments,a,n),t.write(a),this[u.type](u,t),t.write(n)}t.write(r)}else i&&e.comments!=null&&(t.write(n),$c(t,e.comments,a,n),t.write(r));i&&e.trailingComments!=null&&$c(t,e.trailingComments,a,n),t.write("}"),t.indentLevel--},ClassBody:mpe,StaticBlock(e,t){t.write("static "),this.BlockStatement(e,t)},EmptyStatement(e,t){t.write(";")},ExpressionStatement(e,t){let r=t.expressionsPrecedence[e.expression.type];r===zm||r===3&&e.expression.left.type[0]==="O"?(t.write("("),this[e.expression.type](e.expression,t),t.write(")")):this[e.expression.type](e.expression,t),t.write(";")},IfStatement(e,t){t.write("if ("),this[e.test.type](e.test,t),t.write(") "),this[e.consequent.type](e.consequent,t),e.alternate!=null&&(t.write(" else "),this[e.alternate.type](e.alternate,t))},LabeledStatement(e,t){this[e.label.type](e.label,t),t.write(": "),this[e.body.type](e.body,t)},BreakStatement(e,t){t.write("break"),e.label!=null&&(t.write(" "),this[e.label.type](e.label,t)),t.write(";")},ContinueStatement(e,t){t.write("continue"),e.label!=null&&(t.write(" "),this[e.label.type](e.label,t)),t.write(";")},WithStatement(e,t){t.write("with ("),this[e.object.type](e.object,t),t.write(") "),this[e.body.type](e.body,t)},SwitchStatement(e,t){let r=t.indent.repeat(t.indentLevel++),{lineEnd:n,writeComments:i}=t;t.indentLevel++;let a=r+t.indent,o=a+t.indent;t.write("switch ("),this[e.discriminant.type](e.discriminant,t),t.write(") {"+n);let{cases:s}=e,{length:l}=s;for(let u=0;u<l;u++){let c=s[u];i&&c.comments!=null&&$c(t,c.comments,a,n),c.test?(t.write(a+"case "),this[c.test.type](c.test,t),t.write(":"+n)):t.write(a+"default:"+n);let{consequent:f}=c,{length:d}=f;for(let p=0;p<d;p++){let h=f[p];i&&h.comments!=null&&$c(t,h.comments,o,n),t.write(o),this[h.type](h,t),t.write(n)}}t.indentLevel-=2,t.write(r+"}")},ReturnStatement(e,t){t.write("return"),e.argument&&(t.write(" "),this[e.argument.type](e.argument,t)),t.write(";")},ThrowStatement(e,t){t.write("throw "),this[e.argument.type](e.argument,t),t.write(";")},TryStatement(e,t){if(t.write("try "),this[e.block.type](e.block,t),e.handler){let{handler:r}=e;r.param==null?t.write(" catch "):(t.write(" catch ("),this[r.param.type](r.param,t),t.write(") ")),this[r.body.type](r.body,t)}e.finalizer&&(t.write(" finally "),this[e.finalizer.type](e.finalizer,t))},WhileStatement(e,t){t.write("while ("),this[e.test.type](e.test,t),t.write(") "),this[e.body.type](e.body,t)},DoWhileStatement(e,t){t.write("do "),this[e.body.type](e.body,t),t.write(" while ("),this[e.test.type](e.test,t),t.write(");")},ForStatement(e,t){if(t.write("for ("),e.init!=null){let{init:r}=e;r.type[0]==="V"?pY(t,r):this[r.type](r,t)}t.write("; "),e.test&&this[e.test.type](e.test,t),t.write("; "),e.update&&this[e.update.type](e.update,t),t.write(") "),this[e.body.type](e.body,t)},ForInStatement:upe=function(e,t){t.write(`for ${e.await?"await ":""}(`);let{left:r}=e;r.type[0]==="V"?pY(t,r):this[r.type](r,t),t.write(e.type[3]==="I"?" in ":" of "),this[e.right.type](e.right,t),t.write(") "),this[e.body.type](e.body,t)},ForOfStatement:upe,DebuggerStatement(e,t){t.write("debugger;",e)},FunctionDeclaration:cpe=function(e,t){t.write((e.async?"async ":"")+(e.generator?"function* ":"function ")+(e.id?e.id.name:""),e),iE(t,e.params),t.write(" "),this[e.body.type](e.body,t)},FunctionExpression:cpe,VariableDeclaration(e,t){pY(t,e),t.write(";")},VariableDeclarator(e,t){this[e.id.type](e.id,t),e.init!=null&&(t.write(" = "),this[e.init.type](e.init,t))},ClassDeclaration(e,t){if(t.write("class "+(e.id?`${e.id.name} `:""),e),e.superClass){t.write("extends ");let{superClass:r}=e,{type:n}=r,i=t.expressionsPrecedence[n];(n[0]!=="C"||n[1]!=="l"||n[5]!=="E")&&(i===zm||i<t.expressionsPrecedence.ClassExpression)?(t.write("("),this[e.superClass.type](r,t),t.write(")")):this[r.type](r,t),t.write(" ")}this.ClassBody(e.body,t)},ImportDeclaration(e,t){t.write("import ");let{specifiers:r,attributes:n}=e,{length:i}=r,a=0;if(i>0){for(;a<i;){a>0&&t.write(", ");let o=r[a],s=o.type[6];if(s==="D")t.write(o.local.name,o),a++;else if(s==="N")t.write("* as "+o.local.name,o),a++;else break}if(a<i){for(t.write("{");;){let o=r[a],{name:s}=o.imported;if(t.write(s,o),s!==o.local.name&&t.write(" as "+o.local.name),++a<i)t.write(", ");else break}t.write("}")}t.write(" from ")}if(this.Literal(e.source,t),n&&n.length>0){t.write(" with { ");for(let o=0;o<n.length;o++)this.ImportAttribute(n[o],t),o<n.length-1&&t.write(", ");t.write(" }")}t.write(";")},ImportAttribute(e,t){this.Identifier(e.key,t),t.write(": "),this.Literal(e.value,t)},ImportExpression(e,t){t.write("import("),this[e.source.type](e.source,t),t.write(")")},ExportDefaultDeclaration(e,t){t.write("export default "),this[e.declaration.type](e.declaration,t),t.expressionsPrecedence[e.declaration.type]!=null&&e.declaration.type[0]!=="F"&&t.write(";")},ExportNamedDeclaration(e,t){if(t.write("export "),e.declaration)this[e.declaration.type](e.declaration,t);else{t.write("{");let{specifiers:r}=e,{length:n}=r;if(n>0)for(let i=0;;){let a=r[i],{name:o}=a.local;if(t.write(o,a),o!==a.exported.name&&t.write(" as "+a.exported.name),++i<n)t.write(", ");else break}if(t.write("}"),e.source&&(t.write(" from "),this.Literal(e.source,t)),e.attributes&&e.attributes.length>0){t.write(" with { ");for(let i=0;i<e.attributes.length;i++)this.ImportAttribute(e.attributes[i],t),i<e.attributes.length-1&&t.write(", ");t.write(" }")}t.write(";")}},ExportAllDeclaration(e,t){if(e.exported!=null?t.write("export * as "+e.exported.name+" from "):t.write("export * from "),this.Literal(e.source,t),e.attributes&&e.attributes.length>0){t.write(" with { ");for(let r=0;r<e.attributes.length;r++)this.ImportAttribute(e.attributes[r],t),r<e.attributes.length-1&&t.write(", ");t.write(" }")}t.write(";")},MethodDefinition(e,t){e.static&&t.write("static ");let r=e.kind[0];(r==="g"||r==="s")&&t.write(e.kind+" "),e.value.async&&t.write("async "),e.value.generator&&t.write("*"),e.computed?(t.write("["),this[e.key.type](e.key,t),t.write("]")):this[e.key.type](e.key,t),iE(t,e.value.params),t.write(" "),this[e.value.body.type](e.value.body,t)},ClassExpression(e,t){this.ClassDeclaration(e,t)},ArrowFunctionExpression(e,t){t.write(e.async?"async ":"",e);let{params:r}=e;r!=null&&(r.length===1&&r[0].type[0]==="I"?t.write(r[0].name,r[0]):iE(t,e.params)),t.write(" => "),e.body.type[0]==="O"?(t.write("("),this.ObjectExpression(e.body,t),t.write(")")):this[e.body.type](e.body,t)},ThisExpression(e,t){t.write("this",e)},Super(e,t){t.write("super",e)},RestElement:fpe=function(e,t){t.write("..."),this[e.argument.type](e.argument,t)},SpreadElement:fpe,YieldExpression(e,t){t.write(e.delegate?"yield*":"yield"),e.argument&&(t.write(" "),this[e.argument.type](e.argument,t))},AwaitExpression(e,t){t.write("await ",e),OP(t,e.argument,e)},TemplateLiteral(e,t){let{quasis:r,expressions:n}=e;t.write("`");let{length:i}=n;for(let o=0;o<i;o++){let s=n[o],l=r[o];t.write(l.value.raw,l),t.write("${"),this[s.type](s,t),t.write("}")}let a=r[r.length-1];t.write(a.value.raw,a),t.write("`")},TemplateElement(e,t){t.write(e.value.raw,e)},TaggedTemplateExpression(e,t){OP(t,e.tag,e),this[e.quasi.type](e.quasi,t)},ArrayExpression:ppe=function(e,t){if(t.write("["),e.elements.length>0){let{elements:r}=e,{length:n}=r;for(let i=0;;){let a=r[i];if(a!=null&&this[a.type](a,t),++i<n)t.write(", ");else{a==null&&t.write(", ");break}}}t.write("]")},ArrayPattern:ppe,ObjectExpression(e,t){let r=t.indent.repeat(t.indentLevel++),{lineEnd:n,writeComments:i}=t,a=r+t.indent;if(t.write("{"),e.properties.length>0){t.write(n),i&&e.comments!=null&&$c(t,e.comments,a,n);let o=","+n,{properties:s}=e,{length:l}=s;for(let u=0;;){let c=s[u];if(i&&c.comments!=null&&$c(t,c.comments,a,n),t.write(a),this[c.type](c,t),++u<l)t.write(o);else break}t.write(n),i&&e.trailingComments!=null&&$c(t,e.trailingComments,a,n),t.write(r+"}")}else i?e.comments!=null?(t.write(n),$c(t,e.comments,a,n),e.trailingComments!=null&&$c(t,e.trailingComments,a,n),t.write(r+"}")):e.trailingComments!=null?(t.write(n),$c(t,e.trailingComments,a,n),t.write(r+"}")):t.write("}"):t.write("}");t.indentLevel--},Property(e,t){e.method||e.kind[0]!=="i"?this.MethodDefinition(e,t):(e.shorthand||(e.computed?(t.write("["),this[e.key.type](e.key,t),t.write("]")):this[e.key.type](e.key,t),t.write(": ")),this[e.value.type](e.value,t))},PropertyDefinition(e,t){if(e.static&&t.write("static "),e.computed&&t.write("["),this[e.key.type](e.key,t),e.computed&&t.write("]"),e.value==null){e.key.type[0]!=="F"&&t.write(";");return}t.write(" = "),this[e.value.type](e.value,t),t.write(";")},ObjectPattern(e,t){if(t.write("{"),e.properties.length>0){let{properties:r}=e,{length:n}=r;for(let i=0;this[r[i].type](r[i],t),++i<n;)t.write(", ")}t.write("}")},SequenceExpression(e,t){iE(t,e.expressions)},UnaryExpression(e,t){if(e.prefix){let{operator:r,argument:n,argument:{type:i}}=e;t.write(r);let a=hpe(t,n,e);!a&&(r.length>1||i[0]==="U"&&(i[1]==="n"||i[1]==="p")&&n.prefix&&n.operator[0]===r&&(r==="+"||r==="-"))&&t.write(" "),a?(t.write(r.length>1?" (":"("),this[i](n,t),t.write(")")):this[i](n,t)}else this[e.argument.type](e.argument,t),t.write(e.operator)},UpdateExpression(e,t){e.prefix?(t.write(e.operator),this[e.argument.type](e.argument,t)):(this[e.argument.type](e.argument,t),t.write(e.operator))},AssignmentExpression(e,t){this[e.left.type](e.left,t),t.write(" "+e.operator+" "),this[e.right.type](e.right,t)},AssignmentPattern(e,t){this[e.left.type](e.left,t),t.write(" = "),this[e.right.type](e.right,t)},BinaryExpression:dpe=function(e,t){let r=e.operator==="in";r&&t.write("("),OP(t,e.left,e,!1),t.write(" "+e.operator+" "),OP(t,e.right,e,!0),r&&t.write(")")},LogicalExpression:dpe,ConditionalExpression(e,t){let{test:r}=e,n=t.expressionsPrecedence[r.type];n===zm||n<=t.expressionsPrecedence.ConditionalExpression?(t.write("("),this[r.type](r,t),t.write(")")):this[r.type](r,t),t.write(" ? "),this[e.consequent.type](e.consequent,t),t.write(" : "),this[e.alternate.type](e.alternate,t)},NewExpression(e,t){t.write("new ");let r=t.expressionsPrecedence[e.callee.type];r===zm||r<t.expressionsPrecedence.CallExpression||oJe(e.callee)?(t.write("("),this[e.callee.type](e.callee,t),t.write(")")):this[e.callee.type](e.callee,t),iE(t,e.arguments)},CallExpression(e,t){let r=t.expressionsPrecedence[e.callee.type];r===zm||r<t.expressionsPrecedence.CallExpression?(t.write("("),this[e.callee.type](e.callee,t),t.write(")")):this[e.callee.type](e.callee,t),e.optional&&t.write("?."),iE(t,e.arguments)},ChainExpression(e,t){this[e.expression.type](e.expression,t)},MemberExpression(e,t){let r=t.expressionsPrecedence[e.object.type];r===zm||r<t.expressionsPrecedence.MemberExpression?(t.write("("),this[e.object.type](e.object,t),t.write(")")):this[e.object.type](e.object,t),e.computed?(e.optional&&t.write("?."),t.write("["),this[e.property.type](e.property,t),t.write("]")):(e.optional?t.write("?."):t.write("."),this[e.property.type](e.property,t))},MetaProperty(e,t){t.write(e.meta.name+"."+e.property.name,e)},Identifier(e,t){t.write(e.name,e)},PrivateIdentifier(e,t){t.write(`#${e.name}`,e)},Literal(e,t){e.raw!=null?t.write(e.raw,e):e.regex!=null?this.RegExpLiteral(e,t):e.bigint!=null?t.write(e.bigint+"n",e):t.write(nJe(e.value),e)},RegExpLiteral(e,t){let{regex:r}=e;t.write(`/${r.pattern}/${r.flags}`,e)}},lJe={};var mY=class{constructor(t){let r=t??lJe;this.output="",r.output!=null?(this.output=r.output,this.write=this.writeToStream):this.output="",this.generator=r.generator!=null?r.generator:sJe,this.expressionsPrecedence=r.expressionsPrecedence!=null?r.expressionsPrecedence:iJe,this.indent=r.indent!=null?r.indent:" ",this.lineEnd=r.lineEnd!=null?r.lineEnd:`
55`,this.indentLevel=r.startingIndentLevel!=null?r.startingIndentLevel:0,this.writeComments=r.comments?r.comments:!1,r.sourceMap!=null&&(this.write=r.output==null?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=r.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split(`
56`).length-1,this.mapping={original:null,generated:this,name:void 0,source:r.sourceMap.file||r.sourceMap._file})}write(t){this.output+=t}writeToStream(t){this.output.write(t)}writeAndMap(t,r){this.output+=t,this.map(t,r)}writeToStreamAndMap(t,r){this.output.write(t),this.map(t,r)}map(t,r){if(r!=null){let{type:a}=r;if(a[0]==="L"&&a[2]==="n"){this.column=0,this.line++;return}if(r.loc!=null){let{mapping:o}=this;o.original=r.loc.start,o.name=r.name,this.sourceMap.addMapping(o)}if(a[0]==="T"&&a[8]==="E"||a[0]==="L"&&a[1]==="i"&&typeof r.value=="string"){let{length:o}=t,{column:s,line:l}=this;for(let u=0;u<o;u++)t[u]===`
57`?(s=0,l++):s++;this.column=s,this.line=l;return}}let{length:n}=t,{lineEnd:i}=this;n>0&&(this.lineEndSize>0&&(i.length===1?t[n-1]===i:t.endsWith(i))?(this.line+=this.lineEndSize,this.column=0):this.column+=n)}toString(){return this.output}};function gpe(e,t){let r=new mY(t);return r.generator[e.type](e,r),r.output}var og=(e,t,r)=>{let n,i=uo(e),a=i.includes(`
58`);i.startsWith("{")&&i.endsWith("}")&&(i=`(${i})`);let o=!1;if(a){let s=i.split(`
59`).filter(l=>l.trim()!=="");s[s.length-1].includes("return")&&(o=!0),s[s.length-1]=`${s[s.length-1].replace("return ","")}`,i=s.join(`

Callers

nothing calls this directly

Calls 2

writeMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected