deno.land / x / astring@v1.8.6 / docs / demo / astring.min.js

astring.min.js
نووسراو ببینە
1
2
3
(function(a,b){if("function"==typeof define&&define.amd)define(["exports"],b);else if("undefined"!=typeof exports)b(exports);else{var c={exports:{}};b(c.exports),a.astring=c.exports}})("undefined"==typeof globalThis?"undefined"==typeof self?this:self:globalThis,function(a){"use strict";var b=String.prototype;function c(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function d(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function e(a,b,c){return b&&d(a.prototype,b),c&&d(a,c),a}function f(a,b){var c=a.generator;if(a.write("("),null!=b&&0<b.length){c[b[0].type](b[0],a);for(var d,e=b.length,f=1;f<e;f++)d=b[f],a.write(", "),c[d.type](d,a)}a.write(")")}function g(a,b,c,d){var e=a.expressionsPrecedence[b.type];if(e===17)return!0;var f=a.expressionsPrecedence[c.type];return e===f?(13===e||14===e)&&("**"===b.operator&&"**"===c.operator?!d:d?o[b.operator]<=o[c.operator]:o[b.operator]<o[c.operator]):!d&&15===e&&14===f&&"**"===c.operator||e<f}function h(a,b,c,d){var e=a.generator;g(a,b,c,d)?(a.write("("),e[b.type](b,a),a.write(")")):e[b.type](b,a)}function j(a,b,c,d){var e=b.split("\n"),f=e.length-1;if(a.write(e[0].trim()),0<f){a.write(d);for(var g=1;g<f;g++)a.write(c+e[g].trim()+d);a.write(c+e[f].trim())}}function k(a,b,c,d){for(var e,f=b.length,g=0;g<f;g++)e=b[g],a.write(c),"L"===e.type[0]?a.write("// "+e.value.trim()+"\n",e):(a.write("/*"),j(a,e.value,c,d),a.write("*/"+d))}function l(a){for(var d=a;null!=d;){var b=d,c=b.type;if("C"===c[0]&&"a"===c[1])return!0;if("M"===c[0]&&"e"===c[1]&&"m"===c[2])d=d.object;else return!1}}function m(a,b){var c=a.generator,d=b.declarations;a.write(b.kind+" ");var e=d.length;if(0<e){c.VariableDeclarator(d[0],a);for(var f=1;f<e;f++)a.write(", "),c.VariableDeclarator(d[f],a)}}Object.defineProperty(a,"__esModule",{value:!0}),a.generate=function(a,b){var c=new z(b);return c.generator[a.type](a,c),c.output},a.baseGenerator=a.GENERATOR=a.EXPRESSIONS_PRECEDENCE=a.NEEDS_PARENTHESES=void 0;var n=JSON.stringify;if(!b.repeat)throw new Error("String.prototype.repeat is undefined, see https://github.com/davidbonnet/astring#installation");if(!b.endsWith)throw new Error("String.prototype.endsWith is undefined, see https://github.com/davidbonnet/astring#installation");var o={"||":3,"&&":4,"|":5,"??":5,"^":6,"&":7,"==":8,"!=":8,"===":8,"!==":8,"<":9,">":9,"<=":9,">=":9,in:9,instanceof:9,"<<":10,">>":10,">>>":10,"+":11,"-":11,"*":12,"%":12,"/":12,"**":13},p=17;a.NEEDS_PARENTHESES=p;var q={ArrayExpression:20,TaggedTemplateExpression:20,ThisExpression:20,Identifier:20,PrivateIdentifier:20,Literal:18,TemplateLiteral:20,Super:20,SequenceExpression:20,MemberExpression:19,ChainExpression:19,CallExpression:19,NewExpression:19,ArrowFunctionExpression:p,ClassExpression:p,FunctionExpression:p,ObjectExpression:p,UpdateExpression:16,UnaryExpression:15,AwaitExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,YieldExpression:2,RestElement:1};a.EXPRESSIONS_PRECEDENCE=q;var r,s,t,u,v,w,x={Program:function Program(a,b){var c=b.indent.repeat(b.indentLevel),d=b.lineEnd,e=b.writeComments;e&&null!=a.comments&&k(b,a.comments,c,d);for(var f,g=a.body,h=g.length,j=0;j<h;j++)f=g[j],e&&null!=f.comments&&k(b,f.comments,c,d),b.write(c),this[f.type](f,b),b.write(d);e&&null!=a.trailingComments&&k(b,a.trailingComments,c,d)},BlockStatement:w=function(a,b){var c=b.indent.repeat(b.indentLevel++),d=b.lineEnd,e=b.writeComments,f=c+b.indent;b.write("{");var g=a.body;if(null!=g&&0<g.length){b.write(d),e&&null!=a.comments&&k(b,a.comments,f,d);for(var h,j=g.length,l=0;l<j;l++)h=g[l],e&&null!=h.comments&&k(b,h.comments,f,d),b.write(f),this[h.type](h,b),b.write(d);b.write(c)}else e&&null!=a.comments&&(b.write(d),k(b,a.comments,f,d),b.write(c));e&&null!=a.trailingComments&&k(b,a.trailingComments,f,d),b.write("}"),b.indentLevel--},ClassBody:w,StaticBlock:function StaticBlock(a,b){b.write("static "),this.BlockStatement(a,b)},EmptyStatement:function EmptyStatement(a,b){b.write(";")},ExpressionStatement:function ExpressionStatement(a,b){var c=b.expressionsPrecedence[a.expression.type];c===p||3===c&&"O"===a.expression.left.type[0]?(b.write("("),this[a.expression.type](a.expression,b),b.write(")")):this[a.expression.type](a.expression,b),b.write(";")},IfStatement:function IfStatement(a,b){b.write("if ("),this[a.test.type](a.test,b),b.write(") "),this[a.consequent.type](a.consequent,b),null!=a.alternate&&(b.write(" else "),this[a.alternate.type](a.alternate,b))},LabeledStatement:function LabeledStatement(a,b){this[a.label.type](a.label,b),b.write(": "),this[a.body.type](a.body,b)},BreakStatement:function BreakStatement(a,b){b.write("break"),null!=a.label&&(b.write(" "),this[a.label.type](a.label,b)),b.write(";")},ContinueStatement:function ContinueStatement(a,b){b.write("continue"),null!=a.label&&(b.write(" "),this[a.label.type](a.label,b)),b.write(";")},WithStatement:function WithStatement(a,b){b.write("with ("),this[a.object.type](a.object,b),b.write(") "),this[a.body.type](a.body,b)},SwitchStatement:function SwitchStatement(a,b){var c=b.indent.repeat(b.indentLevel++),d=b.lineEnd,e=b.writeComments;b.indentLevel++;var f=c+b.indent,g=f+b.indent;b.write("switch ("),this[a.discriminant.type](a.discriminant,b),b.write(") {"+d);for(var h,j=a.cases,l=j.length,m=0;m<l;m++){h=j[m],e&&null!=h.comments&&k(b,h.comments,f,d),h.test?(b.write(f+"case "),this[h.test.type](h.test,b),b.write(":"+d)):b.write(f+"default:"+d);for(var n,o=h.consequent,p=o.length,q=0;q<p;q++)n=o[q],e&&null!=n.comments&&k(b,n.comments,g,d),b.write(g),this[n.type](n,b),b.write(d)}b.indentLevel-=2,b.write(c+"}")},ReturnStatement:function ReturnStatement(a,b){b.write("return"),a.argument&&(b.write(" "),this[a.argument.type](a.argument,b)),b.write(";")},ThrowStatement:function ThrowStatement(a,b){b.write("throw "),this[a.argument.type](a.argument,b),b.write(";")},TryStatement:function TryStatement(a,b){if(b.write("try "),this[a.block.type](a.block,b),a.handler){var c=a.handler;null==c.param?b.write(" catch "):(b.write(" catch ("),this[c.param.type](c.param,b),b.write(") ")),this[c.body.type](c.body,b)}a.finalizer&&(b.write(" finally "),this[a.finalizer.type](a.finalizer,b))},WhileStatement:function WhileStatement(a,b){b.write("while ("),this[a.test.type](a.test,b),b.write(") "),this[a.body.type](a.body,b)},DoWhileStatement:function DoWhileStatement(a,b){b.write("do "),this[a.body.type](a.body,b),b.write(" while ("),this[a.test.type](a.test,b),b.write(");")},ForStatement:function ForStatement(a,b){if(b.write("for ("),null!=a.init){var c=a.init;"V"===c.type[0]?m(b,c):this[c.type](c,b)}b.write("; "),a.test&&this[a.test.type](a.test,b),b.write("; "),a.update&&this[a.update.type](a.update,b),b.write(") "),this[a.body.type](a.body,b)},ForInStatement:r=function(a,b){b.write("for ".concat(a["await"]?"await ":"","("));var c=a.left;"V"===c.type[0]?m(b,c):this[c.type](c,b),b.write("I"===a.type[3]?" in ":" of "),this[a.right.type](a.right,b),b.write(") "),this[a.body.type](a.body,b)},ForOfStatement:r,DebuggerStatement:function DebuggerStatement(a,b){b.write("debugger;",a)},FunctionDeclaration:s=function(a,b){b.write((a.async?"async ":"")+(a.generator?"function* ":"function ")+(a.id?a.id.name:""),a),f(b,a.params),b.write(" "),this[a.body.type](a.body,b)},FunctionExpression:s,VariableDeclaration:function VariableDeclaration(a,b){m(b,a),b.write(";")},VariableDeclarator:function VariableDeclarator(a,b){this[a.id.type](a.id,b),null!=a.init&&(b.write(" = "),this[a.init.type](a.init,b))},ClassDeclaration:function ClassDeclaration(a,b){if(b.write("class "+(a.id?"".concat(a.id.name," "):""),a),a.superClass){b.write("extends ");var c=a.superClass,d=c.type,e=b.expressionsPrecedence[d];("C"!==d[0]||"l"!==d[1]||"E"!==d[5])&&(e===p||e<b.expressionsPrecedence.ClassExpression)?(b.write("("),this[a.superClass.type](c,b),b.write(")")):this[c.type](c,b),b.write(" ")}this.ClassBody(a.body,b)},ImportDeclaration:function ImportDeclaration(a,b){b.write("import ");var c=a.specifiers,d=c.length,e=0;if(0<d){for(;e<d;){0<e&&b.write(", ");var f=c[e],g=f.type[6];if("D"===g)b.write(f.local.name,f),e++;else if("N"===g)b.write("* as "+f.local.name,f),e++;else break}if(e<d){for(b.write("{");;){var h=c[e],j=h.imported.name;if(b.write(j,h),j!==h.local.name&&b.write(" as "+h.local.name),++e<d)b.write(", ");else break}b.write("}")}b.write(" from ")}this.Literal(a.source,b),b.write(";")},ImportExpression:function ImportExpression(a,b){b.write("import("),this[a.source.type](a.source,b),b.write(")")},ExportDefaultDeclaration:function ExportDefaultDeclaration(a,b){b.write("export default "),this[a.declaration.type](a.declaration,b),null!=b.expressionsPrecedence[a.declaration.type]&&"F"!==a.declaration.type[0]&&b.write(";")},ExportNamedDeclaration:function ExportNamedDeclaration(a,b){if(b.write("export "),a.declaration)this[a.declaration.type](a.declaration,b);else{b.write("{");var c=a.specifiers,d=c.length;if(0<d)for(var g=0;;){var e=c[g],f=e.local.name;if(b.write(f,e),f!==e.exported.name&&b.write(" as "+e.exported.name),++g<d)b.write(", ");else break}b.write("}"),a.source&&(b.write(" from "),this.Literal(a.source,b)),b.write(";")}},ExportAllDeclaration:function ExportAllDeclaration(a,b){null==a.exported?b.write("export * from "):b.write("export * as "+a.exported.name+" from "),this.Literal(a.source,b),b.write(";")},MethodDefinition:function MethodDefinition(a,b){a["static"]&&b.write("static ");var c=a.kind[0];("g"===c||"s"===c)&&b.write(a.kind+" "),a.value.async&&b.write("async "),a.value.generator&&b.write("*"),a.computed?(b.write("["),this[a.key.type](a.key,b),b.write("]")):this[a.key.type](a.key,b),f(b,a.value.params),b.write(" "),this[a.value.body.type](a.value.body,b)},ClassExpression:function ClassExpression(a,b){this.ClassDeclaration(a,b)},ArrowFunctionExpression:function ArrowFunctionExpression(a,b){b.write(a.async?"async ":"",a);var c=a.params;null!=c&&(1===c.length&&"I"===c[0].type[0]?b.write(c[0].name,c[0]):f(b,a.params)),b.write(" => "),"O"===a.body.type[0]?(b.write("("),this.ObjectExpression(a.body,b),b.write(")")):this[a.body.type](a.body,b)},ThisExpression:function ThisExpression(a,b){b.write("this",a)},Super:function Super(a,b){b.write("super",a)},RestElement:t=function(a,b){b.write("..."),this[a.argument.type](a.argument,b)},SpreadElement:t,YieldExpression:function YieldExpression(a,b){b.write(a.delegate?"yield*":"yield"),a.argument&&(b.write(" "),this[a.argument.type](a.argument,b))},AwaitExpression:function AwaitExpression(a,b){b.write("await ",a),h(b,a.argument,a)},TemplateLiteral:function TemplateLiteral(a,b){var c=a.quasis,d=a.expressions;b.write("`");for(var e=d.length,f=0;f<e;f++){var g=d[f],h=c[f];b.write(h.value.raw,h),b.write("${"),this[g.type](g,b),b.write("}")}var j=c[c.length-1];b.write(j.value.raw,j),b.write("`")},TemplateElement:function TemplateElement(a,b){b.write(a.value.raw,a)},TaggedTemplateExpression:function TaggedTemplateExpression(a,b){h(b,a.tag,a),this[a.quasi.type](a.quasi,b)},ArrayExpression:v=function(a,b){if(b.write("["),0<a.elements.length)for(var c,d=a.elements,e=d.length,f=0;;)if(c=d[f],null!=c&&this[c.type](c,b),++f<e)b.write(", ");else{null==c&&b.write(", ");break}b.write("]")},ArrayPattern:v,ObjectExpression:function ObjectExpression(a,b){var c=b.indent.repeat(b.indentLevel++),d=b.lineEnd,e=b.writeComments,f=c+b.indent;if(b.write("{"),0<a.properties.length){b.write(d),e&&null!=a.comments&&k(b,a.comments,f,d);for(var g,h=a.properties,j=h.length,l=0;;)if(g=h[l],e&&null!=g.comments&&k(b,g.comments,f,d),b.write(f),this[g.type](g,b),++l<j)b.write(","+d);else break;b.write(d),e&&null!=a.trailingComments&&k(b,a.trailingComments,f,d),b.write(c+"}")}else e?null==a.comments?null==a.trailingComments?b.write("}"):(b.write(d),k(b,a.trailingComments,f,d),b.write(c+"}")):(b.write(d),k(b,a.comments,f,d),null!=a.trailingComments&&k(b,a.trailingComments,f,d),b.write(c+"}")):b.write("}");b.indentLevel--},Property:function Property(a,b){a.method||"i"!==a.kind[0]?this.MethodDefinition(a,b):(!a.shorthand&&(a.computed?(b.write("["),this[a.key.type](a.key,b),b.write("]")):this[a.key.type](a.key,b),b.write(": ")),this[a.value.type](a.value,b))},PropertyDefinition:function PropertyDefinition(a,b){a["static"]&&b.write("static "),this[a.key.type](a.key,b);null==a.value||(b.write(" = "),this[a.value.type](a.value,b))},ObjectPattern:function ObjectPattern(a,b){if(b.write("{"),0<a.properties.length)for(var c=a.properties,d=c.length,e=0;;)if(this[c[e].type](c[e],b),++e<d)b.write(", ");else break;b.write("}")},SequenceExpression:function SequenceExpression(a,b){f(b,a.expressions)},UnaryExpression:function UnaryExpression(a,b){if(a.prefix){var c=a.operator,d=a.argument,e=a.argument.type;b.write(c);var f=g(b,d,a);!f&&(1<c.length||"U"===e[0]&&("n"===e[1]||"p"===e[1])&&d.prefix&&d.operator[0]===c&&("+"===c||"-"===c))&&b.write(" "),f?(b.write(1<c.length?" (":"("),this[e](d,b),b.write(")")):this[e](d,b)}else this[a.argument.type](a.argument,b),b.write(a.operator)},UpdateExpression:function UpdateExpression(a,b){a.prefix?(b.write(a.operator),this[a.argument.type](a.argument,b)):(this[a.argument.type](a.argument,b),b.write(a.operator))},AssignmentExpression:function AssignmentExpression(a,b){this[a.left.type](a.left,b),b.write(" "+a.operator+" "),this[a.right.type](a.right,b)},AssignmentPattern:function AssignmentPattern(a,b){this[a.left.type](a.left,b),b.write(" = "),this[a.right.type](a.right,b)},BinaryExpression:u=function(a,b){var c="in"===a.operator;c&&b.write("("),h(b,a.left,a,!1),b.write(" "+a.operator+" "),h(b,a.right,a,!0),c&&b.write(")")},LogicalExpression:u,ConditionalExpression:function ConditionalExpression(a,b){var c=a.test,d=b.expressionsPrecedence[c.type];d===p||d<=b.expressionsPrecedence.ConditionalExpression?(b.write("("),this[c.type](c,b),b.write(")")):this[c.type](c,b),b.write(" ? "),this[a.consequent.type](a.consequent,b),b.write(" : "),this[a.alternate.type](a.alternate,b)},NewExpression:function NewExpression(a,b){b.write("new ");var c=b.expressionsPrecedence[a.callee.type];c===p||c<b.expressionsPrecedence.CallExpression||l(a.callee)?(b.write("("),this[a.callee.type](a.callee,b),b.write(")")):this[a.callee.type](a.callee,b),f(b,a.arguments)},CallExpression:function CallExpression(a,b){var c=b.expressionsPrecedence[a.callee.type];c===p||c<b.expressionsPrecedence.CallExpression?(b.write("("),this[a.callee.type](a.callee,b),b.write(")")):this[a.callee.type](a.callee,b),a.optional&&b.write("?."),f(b,a.arguments)},ChainExpression:function ChainExpression(a,b){this[a.expression.type](a.expression,b)},MemberExpression:function MemberExpression(a,b){var c=b.expressionsPrecedence[a.object.type];c===p||c<b.expressionsPrecedence.MemberExpression?(b.write("("),this[a.object.type](a.object,b),b.write(")")):this[a.object.type](a.object,b),a.computed?(a.optional&&b.write("?."),b.write("["),this[a.property.type](a.property,b),b.write("]")):(a.optional?b.write("?."):b.write("."),this[a.property.type](a.property,b))},MetaProperty:function MetaProperty(a,b){b.write(a.meta.name+"."+a.property.name,a)},Identifier:function Identifier(a,b){b.write(a.name,a)},PrivateIdentifier:function PrivateIdentifier(a,b){b.write("#".concat(a.name),a)},Literal:function Literal(a,b){null==a.raw?null==a.regex?null==a.bigint?b.write(n(a.value),a):b.write(a.bigint+"n",a):this.RegExpLiteral(a,b):b.write(a.raw,a)},RegExpLiteral:function RegExpLiteral(a,b){var c=a.regex;b.write("/".concat(c.pattern,"/").concat(c.flags),a)}};a.GENERATOR=x;var y={};a.baseGenerator=x;var z=function(){function a(b){c(this,a);var d=null==b?y:b;this.output="",null==d.output?this.output="":(this.output=d.output,this.write=this.writeToStream),this.generator=null==d.generator?x:d.generator,this.expressionsPrecedence=null==d.expressionsPrecedence?q:d.expressionsPrecedence,this.indent=null==d.indent?" ":d.indent,this.lineEnd=null==d.lineEnd?"\n":d.lineEnd,this.indentLevel=null==d.startingIndentLevel?0:d.startingIndentLevel,this.writeComments=!!d.comments&&d.comments,null!=d.sourceMap&&(this.write=null==d.output?this.writeAndMap:this.writeToStreamAndMap,this.sourceMap=d.sourceMap,this.line=1,this.column=0,this.lineEndSize=this.lineEnd.split("\n").length-1,this.mapping={original:null,generated:this,name:void 0,source:d.sourceMap.file||d.sourceMap._file})}return e(a,[{key:"write",value:function write(a){this.output+=a}},{key:"writeToStream",value:function writeToStream(a){this.output.write(a)}},{key:"writeAndMap",value:function writeAndMap(a,b){this.output+=a,this.map(a,b)}},{key:"writeToStreamAndMap",value:function writeToStreamAndMap(a,b){this.output.write(a),this.map(a,b)}},{key:"map",value:function map(a,b){if(null!=b){var c=b.type;if("L"===c[0]&&"n"===c[2])return this.column=0,void this.line++;if(null!=b.loc){var d=this.mapping;d.original=b.loc.start,d.name=b.name,this.sourceMap.addMapping(d)}if("T"===c[0]&&"E"===c[8]||"L"===c[0]&&"i"===c[1]&&"string"==typeof b.value){for(var e=a.length,f=this.column,g=this.line,h=0;h<e;h++)"\n"===a[h]?(f=0,g++):f++;return this.column=f,void(this.line=g)}}var j=a.length,k=this.lineEnd;0<j&&(0<this.lineEndSize&&(1===k.length?a[j-1]===k:a.endsWith(k))?(this.line+=this.lineEndSize,this.column=0):this.column+=j)}},{key:"toString",value:function toString(){return this.output}}]),a}()});
//# sourceMappingURL=astring.min.js.map
astring

Version Info

Tagged at
a year ago