Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

astring

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astring - npm Package Compare versions

Comparing version 1.4.0 to 1.4.1

11

CHANGELOG.md

@@ -1,5 +0,14 @@

# Change Log
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [1.4.1](https://github.com/davidbonnet/astring/compare/v1.4.0...v1.4.1) (2019-07-20)
### Bug Fixes
* **#74:** correct exponentiation precedence ([b267927](https://github.com/davidbonnet/astring/commit/b267927)), closes [#74](https://github.com/davidbonnet/astring/issues/74) [#74](https://github.com/davidbonnet/astring/issues/74)
<a name="1.4.0"></a>

@@ -6,0 +15,0 @@ # [1.4.0](https://github.com/davidbonnet/astring/compare/v1.3.1...v1.4.0) (2019-03-30)

28

dist/astring.js

@@ -39,4 +39,4 @@ "use strict";

'>=': 9,
in: 9,
instanceof: 9,
"in": 9,
"instanceof": 9,
'<<': 10,

@@ -108,3 +108,3 @@ '>>': 10,

if (nodePrecedence !== parentNodePrecedence) {
return nodePrecedence < parentNodePrecedence;
return !isRightHand && nodePrecedence === 15 && parentNodePrecedence === 14 && parentNode.operator === '**' || nodePrecedence < parentNodePrecedence;
}

@@ -466,3 +466,3 @@

ForInStatement: ForInStatement = function ForInStatement(node, state) {
state.write("for ".concat(node.await ? 'await ' : '', "("));
state.write("for ".concat(node["await"] ? 'await ' : '', "("));
var left = node.left;

@@ -621,3 +621,3 @@

MethodDefinition: function MethodDefinition(node, state) {
if (node.static) {
if (node["static"]) {
state.write('static ');

@@ -900,12 +900,14 @@ }

BinaryExpression: BinaryExpression = function BinaryExpression(node, state) {
if (node.operator === 'in') {
var isIn = node.operator === 'in';
if (isIn) {
state.write('(');
formatBinaryExpressionPart(state, node.left, node, false);
state.write(' ' + node.operator + ' ');
formatBinaryExpressionPart(state, node.right, node, true);
}
formatBinaryExpressionPart(state, node.left, node, false);
state.write(' ' + node.operator + ' ');
formatBinaryExpressionPart(state, node.right, node, true);
if (isIn) {
state.write(')');
} else {
formatBinaryExpressionPart(state, node.left, node, false);
state.write(' ' + node.operator + ' ');
formatBinaryExpressionPart(state, node.right, node, true);
}

@@ -912,0 +914,0 @@ },

@@ -1,3 +0,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}})(this,function(a){"use strict";var m=String.prototype;function b(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function c(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 d(a,b,d){return b&&c(a.prototype,b),d&&c(a,d),a}function e(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 f(a,b,c){var d=w[a.type];if(d===17)return!0;var e=w[b.type];return d===e?(13===d||14===d)&&("**"===a.operator&&"**"===b.operator?!c:c?u[a.operator]<=u[b.operator]:u[a.operator]<u[b.operator]):d<e}function g(a,b,c,d){var e=a.generator;f(b,c,d)?(a.write("("),e[b.type](b,a),a.write(")")):e[b.type](b,a)}function h(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 j(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"):(a.write("/*"),h(a,e.value,c,d),a.write("*/"+d))}function k(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 l(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=void 0;var n=JSON.stringify;if(!m.repeat)throw new Error("String.prototype.repeat is undefined, see https://github.com/davidbonnet/astring#installation");if(!m.endsWith)throw new Error("String.prototype.endsWith is undefined, see https://github.com/davidbonnet/astring#installation");var o,p,q,r,s,t,u={"||":3,"&&":4,"|":5,"^":6,"&":7,"==":8,"!=":8,"===":8,"!==":8,"<":9,">":9,"<=":9,">=":9,in:9,instanceof:9,"<<":10,">>":10,">>>":10,"+":11,"-":11,"*":12,"%":12,"/":12,"**":13},v=17,w={ArrayExpression:20,TaggedTemplateExpression:20,ThisExpression:20,Identifier:20,Literal:18,TemplateLiteral:20,Super:20,SequenceExpression:20,MemberExpression:19,CallExpression:19,NewExpression:19,ArrowFunctionExpression:v,ClassExpression:v,FunctionExpression:v,ObjectExpression:v,UpdateExpression:16,UnaryExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,AwaitExpression:2,YieldExpression:2,RestElement:1},x={Program:function l(a,b){var c=b.indent.repeat(b.indentLevel),d=b.lineEnd,e=b.writeComments;e&&null!=a.comments&&j(b,a.comments,c,d);for(var f,g=a.body,h=g.length,k=0;k<h;k++)f=g[k],e&&null!=f.comments&&j(b,f.comments,c,d),b.write(c),this[f.type](f,b),b.write(d);e&&null!=a.trailingComments&&j(b,a.trailingComments,c,d)},BlockStatement:t=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&&j(b,a.comments,f,d);for(var h,k=g.length,l=0;l<k;l++)h=g[l],e&&null!=h.comments&&j(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),j(b,a.comments,f,d),b.write(c));e&&null!=a.trailingComments&&j(b,a.trailingComments,f,d),b.write("}"),b.indentLevel--},ClassBody:t,EmptyStatement:function c(a,b){b.write(";")},ExpressionStatement:function d(a,b){var c=w[a.expression.type];c===v||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 c(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 c(a,b){this[a.label.type](a.label,b),b.write(": "),this[a.body.type](a.body,b)},BreakStatement:function c(a,b){b.write("break"),null!=a.label&&(b.write(" "),this[a.label.type](a.label,b)),b.write(";")},ContinueStatement:function c(a,b){b.write("continue"),null!=a.label&&(b.write(" "),this[a.label.type](a.label,b)),b.write(";")},WithStatement:function c(a,b){b.write("with ("),this[a.object.type](a.object,b),b.write(") "),this[a.body.type](a.body,b)},SwitchStatement:function r(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,k=a.cases,l=k.length,m=0;m<l;m++){h=k[m],e&&null!=h.comments&&j(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&&j(b,n.comments,g,d),b.write(g),this[n.type](n,b),b.write(d)}b.indentLevel-=2,b.write(c+"}")},ReturnStatement:function c(a,b){b.write("return"),a.argument&&(b.write(" "),this[a.argument.type](a.argument,b)),b.write(";")},ThrowStatement:function c(a,b){b.write("throw "),this[a.argument.type](a.argument,b),b.write(";")},TryStatement:function d(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 c(a,b){b.write("while ("),this[a.test.type](a.test,b),b.write(") "),this[a.body.type](a.body,b)},DoWhileStatement:function c(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 d(a,b){if(b.write("for ("),null!=a.init){var c=a.init;"V"===c.type[0]?l(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:o=function(a,b){b.write("for ".concat(a.await?"await ":"","("));var c=a.left;"V"===c.type[0]?l(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:o,DebuggerStatement:function c(a,b){b.write("debugger;"+b.lineEnd)},FunctionDeclaration:p=function(a,b){b.write((a.async?"async ":"")+(a.generator?"function* ":"function ")+(a.id?a.id.name:""),a),e(b,a.params),b.write(" "),this[a.body.type](a.body,b)},FunctionExpression:p,VariableDeclaration:function c(a,b){l(b,a),b.write(";")},VariableDeclarator:function c(a,b){this[a.id.type](a.id,b),null!=a.init&&(b.write(" = "),this[a.init.type](a.init,b))},ClassDeclaration:function c(a,b){b.write("class "+(a.id?"".concat(a.id.name," "):""),a),a.superClass&&(b.write("extends "),this[a.superClass.type](a.superClass,b),b.write(" ")),this.ClassBody(a.body,b)},ImportDeclaration:function k(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(";")},ExportDefaultDeclaration:function c(a,b){b.write("export default "),this[a.declaration.type](a.declaration,b),w[a.declaration.type]&&"F"!==a.declaration.type[0]&&b.write(";")},ExportNamedDeclaration:function g(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 h=0;;){var e=c[h],f=e.local.name;if(b.write(f,e),f!==e.exported.name&&b.write(" as "+e.exported.name),++h<d)b.write(", ");else break}b.write("}"),a.source&&(b.write(" from "),this.Literal(a.source,b)),b.write(";")}},ExportAllDeclaration:function c(a,b){b.write("export * from "),this.Literal(a.source,b),b.write(";")},MethodDefinition:function d(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),e(b,a.value.params),b.write(" "),this[a.value.body.type](a.value.body,b)},ClassExpression:function c(a,b){this.ClassDeclaration(a,b)},ArrowFunctionExpression:function d(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]):e(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 c(a,b){b.write("this",a)},Super:function c(a,b){b.write("super",a)},RestElement:q=function(a,b){b.write("..."),this[a.argument.type](a.argument,b)},SpreadElement:q,YieldExpression:function c(a,b){b.write(a.delegate?"yield*":"yield"),a.argument&&(b.write(" "),this[a.argument.type](a.argument,b))},AwaitExpression:function c(a,b){b.write("await "),a.argument&&this[a.argument.type](a.argument,b)},TemplateLiteral:function h(a,b){var c=a.quasis,d=a.expressions;b.write("`");for(var e,f=d.length,g=0;g<f;g++)e=d[g],b.write(c[g].value.raw),b.write("${"),this[e.type](e,b),b.write("}");b.write(c[c.length-1].value.raw),b.write("`")},TaggedTemplateExpression:function c(a,b){this[a.tag.type](a.tag,b),this[a.quasi.type](a.quasi,b)},ArrayExpression:s=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:s,ObjectExpression:function m(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&&j(b,a.comments,f,d);for(var g,h=a.properties,k=h.length,l=0;;)if(g=h[l],e&&null!=g.comments&&j(b,g.comments,f,d),b.write(f),this[g.type](g,b),++l<k)b.write(","+d);else break;b.write(d),e&&null!=a.trailingComments&&j(b,a.trailingComments,f,d),b.write(c+"}")}else e?null==a.comments?null==a.trailingComments?b.write("}"):(b.write(d),j(b,a.trailingComments,f,d),b.write(c+"}")):(b.write(d),j(b,a.comments,f,d),null!=a.trailingComments&&j(b,a.trailingComments,f,d),b.write(c+"}")):b.write("}");b.indentLevel--},Property:function c(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))},ObjectPattern:function f(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 c(a,b){e(b,a.expressions)},UnaryExpression:function c(a,b){a.prefix?(b.write(a.operator),1<a.operator.length&&b.write(" "),w[a.argument.type]<w.UnaryExpression?(b.write("("),this[a.argument.type](a.argument,b),b.write(")")):this[a.argument.type](a.argument,b)):(this[a.argument.type](a.argument,b),b.write(a.operator))},UpdateExpression:function c(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 c(a,b){this[a.left.type](a.left,b),b.write(" "+a.operator+" "),this[a.right.type](a.right,b)},AssignmentPattern:function c(a,b){this[a.left.type](a.left,b),b.write(" = "),this[a.right.type](a.right,b)},BinaryExpression:r=function(a,b){"in"===a.operator?(b.write("("),g(b,a.left,a,!1),b.write(" "+a.operator+" "),g(b,a.right,a,!0),b.write(")")):(g(b,a.left,a,!1),b.write(" "+a.operator+" "),g(b,a.right,a,!0))},LogicalExpression:r,ConditionalExpression:function c(a,b){w[a.test.type]>w.ConditionalExpression?this[a.test.type](a.test,b):(b.write("("),this[a.test.type](a.test,b),b.write(")")),b.write(" ? "),this[a.consequent.type](a.consequent,b),b.write(" : "),this[a.alternate.type](a.alternate,b)},NewExpression:function c(a,b){b.write("new "),w[a.callee.type]<w.CallExpression||k(a.callee)?(b.write("("),this[a.callee.type](a.callee,b),b.write(")")):this[a.callee.type](a.callee,b),e(b,a.arguments)},CallExpression:function c(a,b){w[a.callee.type]<w.CallExpression?(b.write("("),this[a.callee.type](a.callee,b),b.write(")")):this[a.callee.type](a.callee,b),e(b,a.arguments)},MemberExpression:function c(a,b){w[a.object.type]<w.MemberExpression?(b.write("("),this[a.object.type](a.object,b),b.write(")")):this[a.object.type](a.object,b),a.computed?(b.write("["),this[a.property.type](a.property,b),b.write("]")):(b.write("."),this[a.property.type](a.property,b))},MetaProperty:function c(a,b){b.write(a.meta.name+"."+a.property.name,a)},Identifier:function c(a,b){b.write(a.name,a)},Literal:function c(a,b){null==a.raw?null==a.regex?b.write(n(a.value),a):this.RegExpLiteral(a,b):b.write(a.raw,a)},RegExpLiteral:function d(a,b){var c=a.regex;b.write("/".concat(c.pattern,"/").concat(c.flags),a)}};a.baseGenerator=x;var y={},z=function(){function a(c){b(this,a);var d=null==c?y:c;this.output="",null==d.output?this.output="":(this.output=d.output,this.write=this.writeToStream),this.generator=null==d.generator?x:d.generator,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 d(a,[{key:"write",value:function b(a){this.output+=a}},{key:"writeToStream",value:function b(a){this.output.write(a)}},{key:"writeAndMap",value:function c(a,b){this.output+=a,this.map(a,b)}},{key:"writeToStreamAndMap",value:function c(a,b){this.output.write(a),this.map(a,b)}},{key:"map",value:function d(a,b){if(null!=b&&null!=b.loc){var c=this.mapping;c.original=b.loc.start,c.name=b.name,this.sourceMap.addMapping(c)}0<a.length&&(0<this.lineEndSize?a.endsWith(this.lineEnd)?(this.line+=this.lineEndSize,this.column=0):"\n"===a[a.length-1]?(this.line++,this.column=0):this.column+=a.length:"\n"===a[a.length-1]?(this.line++,this.column=0):this.column+=a.length)}},{key:"toString",value:function a(){return this.output}}]),a}()});
(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}})(this,function(a){"use strict";var m=String.prototype;function b(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function c(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 d(a,b,d){return b&&c(a.prototype,b),d&&c(a,d),a}function e(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 f(a,b,c){var d=w[a.type];if(d===17)return!0;var e=w[b.type];return d===e?(13===d||14===d)&&("**"===a.operator&&"**"===b.operator?!c:c?u[a.operator]<=u[b.operator]:u[a.operator]<u[b.operator]):!c&&15===d&&14===e&&"**"===b.operator||d<e}function g(a,b,c,d){var e=a.generator;f(b,c,d)?(a.write("("),e[b.type](b,a),a.write(")")):e[b.type](b,a)}function h(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 j(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"):(a.write("/*"),h(a,e.value,c,d),a.write("*/"+d))}function k(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 l(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=void 0;var n=JSON.stringify;if(!m.repeat)throw new Error("String.prototype.repeat is undefined, see https://github.com/davidbonnet/astring#installation");if(!m.endsWith)throw new Error("String.prototype.endsWith is undefined, see https://github.com/davidbonnet/astring#installation");var o,p,q,r,s,t,u={"||":3,"&&":4,"|":5,"^":6,"&":7,"==":8,"!=":8,"===":8,"!==":8,"<":9,">":9,"<=":9,">=":9,in:9,instanceof:9,"<<":10,">>":10,">>>":10,"+":11,"-":11,"*":12,"%":12,"/":12,"**":13},v=17,w={ArrayExpression:20,TaggedTemplateExpression:20,ThisExpression:20,Identifier:20,Literal:18,TemplateLiteral:20,Super:20,SequenceExpression:20,MemberExpression:19,CallExpression:19,NewExpression:19,ArrowFunctionExpression:v,ClassExpression:v,FunctionExpression:v,ObjectExpression:v,UpdateExpression:16,UnaryExpression:15,BinaryExpression:14,LogicalExpression:13,ConditionalExpression:4,AssignmentExpression:3,AwaitExpression:2,YieldExpression:2,RestElement:1},x={Program:function Program(a,b){var c=b.indent.repeat(b.indentLevel),d=b.lineEnd,e=b.writeComments;e&&null!=a.comments&&j(b,a.comments,c,d);for(var f,g=a.body,h=g.length,k=0;k<h;k++)f=g[k],e&&null!=f.comments&&j(b,f.comments,c,d),b.write(c),this[f.type](f,b),b.write(d);e&&null!=a.trailingComments&&j(b,a.trailingComments,c,d)},BlockStatement:t=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&&j(b,a.comments,f,d);for(var h,k=g.length,l=0;l<k;l++)h=g[l],e&&null!=h.comments&&j(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),j(b,a.comments,f,d),b.write(c));e&&null!=a.trailingComments&&j(b,a.trailingComments,f,d),b.write("}"),b.indentLevel--},ClassBody:t,EmptyStatement:function EmptyStatement(a,b){b.write(";")},ExpressionStatement:function ExpressionStatement(a,b){var c=w[a.expression.type];c===v||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,k=a.cases,l=k.length,m=0;m<l;m++){h=k[m],e&&null!=h.comments&&j(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&&j(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]?l(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:o=function(a,b){b.write("for ".concat(a["await"]?"await ":"","("));var c=a.left;"V"===c.type[0]?l(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:o,DebuggerStatement:function DebuggerStatement(a,b){b.write("debugger;"+b.lineEnd)},FunctionDeclaration:p=function(a,b){b.write((a.async?"async ":"")+(a.generator?"function* ":"function ")+(a.id?a.id.name:""),a),e(b,a.params),b.write(" "),this[a.body.type](a.body,b)},FunctionExpression:p,VariableDeclaration:function VariableDeclaration(a,b){l(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){b.write("class "+(a.id?"".concat(a.id.name," "):""),a),a.superClass&&(b.write("extends "),this[a.superClass.type](a.superClass,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(";")},ExportDefaultDeclaration:function ExportDefaultDeclaration(a,b){b.write("export default "),this[a.declaration.type](a.declaration,b),w[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){b.write("export * 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),e(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]):e(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:q=function(a,b){b.write("..."),this[a.argument.type](a.argument,b)},SpreadElement:q,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.argument&&this[a.argument.type](a.argument,b)},TemplateLiteral:function TemplateLiteral(a,b){var c=a.quasis,d=a.expressions;b.write("`");for(var e,f=d.length,g=0;g<f;g++)e=d[g],b.write(c[g].value.raw),b.write("${"),this[e.type](e,b),b.write("}");b.write(c[c.length-1].value.raw),b.write("`")},TaggedTemplateExpression:function TaggedTemplateExpression(a,b){this[a.tag.type](a.tag,b),this[a.quasi.type](a.quasi,b)},ArrayExpression:s=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:s,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&&j(b,a.comments,f,d);for(var g,h=a.properties,k=h.length,l=0;;)if(g=h[l],e&&null!=g.comments&&j(b,g.comments,f,d),b.write(f),this[g.type](g,b),++l<k)b.write(","+d);else break;b.write(d),e&&null!=a.trailingComments&&j(b,a.trailingComments,f,d),b.write(c+"}")}else e?null==a.comments?null==a.trailingComments?b.write("}"):(b.write(d),j(b,a.trailingComments,f,d),b.write(c+"}")):(b.write(d),j(b,a.comments,f,d),null!=a.trailingComments&&j(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))},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){e(b,a.expressions)},UnaryExpression:function UnaryExpression(a,b){a.prefix?(b.write(a.operator),1<a.operator.length&&b.write(" "),w[a.argument.type]<w.UnaryExpression?(b.write("("),this[a.argument.type](a.argument,b),b.write(")")):this[a.argument.type](a.argument,b)):(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:r=function(a,b){var c="in"===a.operator;c&&b.write("("),g(b,a.left,a,!1),b.write(" "+a.operator+" "),g(b,a.right,a,!0),c&&b.write(")")},LogicalExpression:r,ConditionalExpression:function ConditionalExpression(a,b){w[a.test.type]>w.ConditionalExpression?this[a.test.type](a.test,b):(b.write("("),this[a.test.type](a.test,b),b.write(")")),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 "),w[a.callee.type]<w.CallExpression||k(a.callee)?(b.write("("),this[a.callee.type](a.callee,b),b.write(")")):this[a.callee.type](a.callee,b),e(b,a.arguments)},CallExpression:function CallExpression(a,b){w[a.callee.type]<w.CallExpression?(b.write("("),this[a.callee.type](a.callee,b),b.write(")")):this[a.callee.type](a.callee,b),e(b,a.arguments)},MemberExpression:function MemberExpression(a,b){w[a.object.type]<w.MemberExpression?(b.write("("),this[a.object.type](a.object,b),b.write(")")):this[a.object.type](a.object,b),a.computed?(b.write("["),this[a.property.type](a.property,b),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)},Literal:function Literal(a,b){null==a.raw?null==a.regex?b.write(n(a.value),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.baseGenerator=x;var y={},z=function(){function a(c){b(this,a);var d=null==c?y:c;this.output="",null==d.output?this.output="":(this.output=d.output,this.write=this.writeToStream),this.generator=null==d.generator?x:d.generator,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 d(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&&null!=b.loc){var c=this.mapping;c.original=b.loc.start,c.name=b.name,this.sourceMap.addMapping(c)}0<a.length&&(0<this.lineEndSize?a.endsWith(this.lineEnd)?(this.line+=this.lineEndSize,this.column=0):"\n"===a[a.length-1]?(this.line++,this.column=0):this.column+=a.length:"\n"===a[a.length-1]?(this.line++,this.column=0):this.column+=a.length)}},{key:"toString",value:function toString(){return this.output}}]),a}()});
//# sourceMappingURL=astring.min.js.map
{
"name": "astring",
"version": "1.4.0",
"version": "1.4.1",
"description": "JavaScript code generator from an ESTree-compliant AST.",

@@ -19,3 +19,3 @@ "main": "./dist/astring.js",

"test:scripts": "npm run test:scripts:build && tap test/_scripts.js",
"benchmark": "node ./src/tests/benchmark.js",
"benchmark": "node --require esm ./src/tests/benchmark.js",
"prettier": "prettier --write \"{src,scripts}/**/*.js\" \"bin/astring\"",

@@ -40,21 +40,29 @@ "prepush": "npm test",

"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.2.3",
"acorn": "^6.1.1",
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/generator": "^7.5.0",
"@babel/parser": "^7.5.0",
"@babel/preset-env": "^7.4.5",
"acorn": "^6.2.0",
"astravel": "^0.5.0",
"ava": "^1.1.0",
"ava": "^2.1.0",
"babel-preset-minify": "^0.5.0",
"benchmark": "^2.0.0",
"benchmark": "^2.1.4",
"buble": "^0.19.8",
"cross-env": "^5.2.0",
"eslint": "^5.0.0",
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-import": "^2.6.0",
"esm": "^3.1.1",
"glob": "^7.1.1",
"husky": "^1.3.1",
"escodegen": "^1.11.1",
"eslint": "^6.0.1",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-import": "^2.18.0",
"esm": "^3.2.25",
"glob": "^7.1.4",
"husky": "^2.7.0",
"lodash": "^4.17.14",
"meriyah": "^1.3.4",
"normalize-newline": "^3.0.0",
"nyc": "^13.3.0",
"prettier": "^1.14.3",
"standard-version": "^4.4.0"
"nyc": "^14.1.1",
"prettier": "^1.18.2",
"standard-version": "^6.0.1",
"sucrase": "^3.10.1",
"uglify-js": "^3.6.0"
},

@@ -95,28 +103,30 @@ "prettier": {

},
"overrides": {
"files": [
"src/tests/fixtures/**/*.js"
],
"rules": {
"no-unused-vars": 0,
"no-undef": 0,
"no-var": 0,
"no-empty": 0,
"no-unused-labels": 0,
"no-cond-assign": 0,
"no-constant-condition": 0,
"constructor-super": 0,
"no-unreachable": 0,
"no-unsafe-negation": 0,
"getter-return": 0,
"no-irregular-whitespace": 0,
"no-redeclare": 0,
"no-dupe-keys": 0,
"no-duplicate-case": 0,
"no-useless-escape": 0,
"no-control-regex": 0,
"no-sparse-arrays": 0,
"no-debugger": 0
"overrides": [
{
"files": [
"src/tests/fixtures/**/*.js"
],
"rules": {
"no-unused-vars": 0,
"no-undef": 0,
"no-var": 0,
"no-empty": 0,
"no-unused-labels": 0,
"no-cond-assign": 0,
"no-constant-condition": 0,
"constructor-super": 0,
"no-unreachable": 0,
"no-unsafe-negation": 0,
"getter-return": 0,
"no-irregular-whitespace": 0,
"no-redeclare": 0,
"no-dupe-keys": 0,
"no-duplicate-case": 0,
"no-useless-escape": 0,
"no-control-regex": 0,
"no-sparse-arrays": 0,
"no-debugger": 0
}
}
}
]
},

@@ -123,0 +133,0 @@ "ava": {

@@ -32,4 +32,7 @@ # Astring

- [`baseGenerator: object`](#basegenerator-object)
- [Benchmark](#benchmark)
- [Generating code](#generating-code)
- [Parsing and generating code](#parsing-and-generating-code)
- [Examples](#examples)
- [Generating code](#generating-code)
- [Generating code](#generating-code-1)
- [Generating source maps](#generating-source-maps)

@@ -107,2 +110,22 @@ - [Using writable streams](#using-writable-streams)

## Benchmark
### Generating code
Operations per second for generating each sample code from a pre-parsed AST:
| code sample (length) | escodegen | astring | uglify | babel | prettier |
| :------------------- | --------: | --------: | ------: | ------: | -------: |
| tiny code (11) | 1,257,527 | 7,185,642 | 129,467 | 156,184 | 333 |
| everything (8532) | 1,366 | 8,008 | 0 | 346 | 64 |
### Parsing and generating code
Operations per second for parsing and generating each sample code:
| code sample (length) | acorn + astring | meriyah + astring | buble | sucrase |
| :------------------- | --------------: | ----------------: | -----: | ------: |
| tiny code (11) | 92,578 | 864,665 | 25,911 | 575,370 |
| everything (8532) | 706 | 1,425 | 132 | 1,403 |
## Examples

@@ -109,0 +132,0 @@

@@ -116,3 +116,9 @@ // Astring is a tiny and fast JavaScript code generator from an ESTree-compliant AST.

// Different node types
return nodePrecedence < parentNodePrecedence
return (
(!isRightHand &&
nodePrecedence === 15 &&
parentNodePrecedence === 14 &&
parentNode.operator === '**') ||
nodePrecedence < parentNodePrecedence
)
}

@@ -847,13 +853,12 @@ if (nodePrecedence !== 13 && nodePrecedence !== 14) {

BinaryExpression: (BinaryExpression = function(node, state) {
if (node.operator === 'in') {
const isIn = node.operator === 'in'
if (isIn) {
// Avoids confusion in `for` loops initializers
state.write('(')
formatBinaryExpressionPart(state, node.left, node, false)
state.write(' ' + node.operator + ' ')
formatBinaryExpressionPart(state, node.right, node, true)
}
formatBinaryExpressionPart(state, node.left, node, false)
state.write(' ' + node.operator + ' ')
formatBinaryExpressionPart(state, node.right, node, true)
if (isIn) {
state.write(')')
} else {
formatBinaryExpressionPart(state, node.left, node, false)
state.write(' ' + node.operator + ' ')
formatBinaryExpressionPart(state, node.right, node, true)
}

@@ -860,0 +865,0 @@ }),

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc