babel-generator
Advanced tools
Comparing version 6.10.0 to 6.10.2
@@ -45,2 +45,3 @@ "use strict"; | ||
}; | ||
this._endsWithWord = false; | ||
} | ||
@@ -56,3 +57,3 @@ | ||
while (this.position.line < node.loc.start.line) { | ||
this._push("\n"); | ||
this.push("\n"); | ||
} | ||
@@ -111,14 +112,6 @@ } | ||
Buffer.prototype.semicolon = function semicolon() { | ||
this.push(";"); | ||
this.token(";"); | ||
}; | ||
/** | ||
* Ensure last character is a semicolon. | ||
*/ | ||
Buffer.prototype.ensureSemicolon = function ensureSemicolon() { | ||
if (!this.isLast(";")) this.semicolon(); | ||
}; | ||
/** | ||
* Add a right brace to the buffer. | ||
@@ -132,3 +125,3 @@ */ | ||
} | ||
this.push("}"); | ||
this.token("}"); | ||
}; | ||
@@ -141,3 +134,3 @@ | ||
Buffer.prototype.keyword = function keyword(name) { | ||
this.push(name); | ||
this.word(name); | ||
this.space(); | ||
@@ -147,9 +140,9 @@ }; | ||
/** | ||
* Add a space to the buffer unless it is compact (override with force). | ||
* Add a space to the buffer unless it is compact. | ||
*/ | ||
Buffer.prototype.space = function space(force) { | ||
if (!force && this.format.compact) return; | ||
Buffer.prototype.space = function space() { | ||
if (this.format.compact) return; | ||
if (force || this.buf && !this.isLast(" ") && !this.isLast("\n")) { | ||
if (this.buf && !this.endsWith(" ") && !this.endsWith("\n")) { | ||
this.push(" "); | ||
@@ -160,2 +153,30 @@ } | ||
/** | ||
* Writes a token that can't be safely parsed without taking whitespace into account. | ||
*/ | ||
Buffer.prototype.word = function word(str) { | ||
if (this._endsWithWord) this.push(" "); | ||
this.push(str); | ||
this._endsWithWord = true; | ||
}; | ||
/** | ||
* Writes a simple token. | ||
*/ | ||
Buffer.prototype.token = function token(str) { | ||
// space is mandatory to avoid outputting <!-- | ||
// http://javascript.spec.whatwg.org/#comment-syntax | ||
if (str === "--" && this.last === "!" || | ||
// Need spaces for operators of the same kind to avoid: `a+++b` | ||
str[0] === "+" && this.last === "+" || str[0] === "-" && this.last === "-") { | ||
this.push(" "); | ||
} | ||
this.push(str); | ||
}; | ||
/** | ||
* Remove the last character. | ||
@@ -170,3 +191,3 @@ */ | ||
Buffer.prototype._removeLast = function _removeLast(cha) { | ||
if (!this._isLast(cha)) return; | ||
if (!this.endsWith(cha)) return; | ||
this.buf = this.buf.slice(0, -1); | ||
@@ -207,3 +228,3 @@ this.last = this.buf[this.buf.length - 1]; | ||
this.newline(); | ||
this.push(")"); | ||
this.token(")"); | ||
} | ||
@@ -242,3 +263,5 @@ }; | ||
this._removeSpacesAfterLastNewline(); | ||
this._push((0, _repeat2.default)("\n", i)); | ||
for (var j = 0; j < i; j++) { | ||
this.push("\n"); | ||
} | ||
}; | ||
@@ -253,4 +276,6 @@ | ||
if (lastNewlineIndex >= 0 && this.get().length <= lastNewlineIndex) { | ||
var toRemove = this.buf.slice(lastNewlineIndex + 1); | ||
this.buf = this.buf.substring(0, lastNewlineIndex + 1); | ||
this.last = "\n"; | ||
this.position.unshift(toRemove); | ||
} | ||
@@ -279,2 +304,4 @@ }; | ||
Buffer.prototype.withSource = function withSource(prop, loc, cb) { | ||
if (!this.opts.sourceMaps) return cb(); | ||
// Use the call stack to manage a stack of "source location" data. | ||
@@ -298,22 +325,8 @@ var originalLine = this._sourcePosition.line; | ||
Buffer.prototype.push = function push(str, noIndent) { | ||
if (!this.format.compact && this._indent && !noIndent && str !== "\n") { | ||
// we have an indent level and we aren't pushing a newline | ||
var indent = this.getIndent(); | ||
// replace all newlines with newlines with the indentation | ||
str = str.replace(/\n/g, "\n" + indent); | ||
Buffer.prototype.push = function push(str) { | ||
if (!this.format.compact && this._indent && str[0] !== "\n") { | ||
// we've got a newline before us so prepend on the indentation | ||
if (this.isLast("\n")) this._push(indent); | ||
if (this.endsWith("\n")) str = this.getIndent() + str; | ||
} | ||
this._push(str); | ||
}; | ||
/** | ||
* Push a string to the buffer. | ||
*/ | ||
Buffer.prototype._push = function _push(str) { | ||
// see startTerminatorless() instance method | ||
@@ -332,3 +345,3 @@ var parenPushNewlineState = this.parenPushNewlineState; | ||
// we're going to break this terminator expression so we need to add a parentheses | ||
this._push("("); | ||
str = "(" + str; | ||
this.indent(); | ||
@@ -343,3 +356,3 @@ parenPushNewlineState.printed = true; | ||
// If there the line is ending, adding a new mapping marker is redundant | ||
if (str[0] !== "\n") this.map.mark(this._sourcePosition); | ||
if (this.opts.sourceMaps && str[0] !== "\n") this.map.mark(this._sourcePosition); | ||
@@ -350,2 +363,5 @@ // | ||
this.last = str[str.length - 1]; | ||
// Clear any state-tracking flags that may have been set. | ||
this._endsWithWord = false; | ||
}; | ||
@@ -358,2 +374,8 @@ | ||
Buffer.prototype.endsWith = function endsWith(str) { | ||
var _this = this; | ||
if (Array.isArray(str)) return str.some(function (s) { | ||
return _this.endsWith(s); | ||
}); | ||
if (str.length === 1) { | ||
@@ -366,21 +388,2 @@ return this.last === str; | ||
/** | ||
* Test if a character is last in the buffer. | ||
*/ | ||
Buffer.prototype.isLast = function isLast(cha) { | ||
if (this.format.compact) return false; | ||
return this._isLast(cha); | ||
}; | ||
Buffer.prototype._isLast = function _isLast(cha) { | ||
var last = this.last; | ||
if (Array.isArray(cha)) { | ||
return cha.indexOf(last) >= 0; | ||
} else { | ||
return cha === last; | ||
} | ||
}; | ||
return Buffer; | ||
@@ -387,0 +390,0 @@ }(); |
@@ -9,3 +9,11 @@ "use strict"; | ||
exports.Directive = Directive; | ||
exports.DirectiveLiteral = DirectiveLiteral; | ||
var _types = require("./types"); | ||
Object.defineProperty(exports, "DirectiveLiteral", { | ||
enumerable: true, | ||
get: function get() { | ||
return _types.StringLiteral; | ||
} | ||
}); | ||
function File(node) { | ||
@@ -25,3 +33,3 @@ this.print(node.program, node); | ||
function BlockStatement(node) { | ||
this.push("{"); | ||
this.token("{"); | ||
this.printInnerComments(node); | ||
@@ -41,3 +49,3 @@ if (node.body.length) { | ||
this.source("end", node.loc); | ||
this.push("}"); | ||
this.token("}"); | ||
} | ||
@@ -51,6 +59,2 @@ } | ||
this.semicolon(); | ||
} | ||
function DirectiveLiteral(node) { | ||
this.push(this._stringLiteral(node.value)); | ||
} |
@@ -9,7 +9,7 @@ "use strict"; | ||
function ClassDeclaration(node) { | ||
this.printJoin(node.decorators, node, { separator: "" }); | ||
this.push("class"); | ||
this.printJoin(node.decorators, node); | ||
this.word("class"); | ||
if (node.id) { | ||
this.push(" "); | ||
this.space(); | ||
this.print(node.id, node); | ||
@@ -21,3 +21,5 @@ } | ||
if (node.superClass) { | ||
this.push(" extends "); | ||
this.space(); | ||
this.word("extends"); | ||
this.space(); | ||
this.print(node.superClass, node); | ||
@@ -28,4 +30,6 @@ this.print(node.superTypeParameters, node); | ||
if (node.implements) { | ||
this.push(" implements "); | ||
this.printJoin(node.implements, node, { separator: ", " }); | ||
this.space(); | ||
this.word("implements"); | ||
this.space(); | ||
this.printList(node.implements, node); | ||
} | ||
@@ -39,6 +43,6 @@ | ||
function ClassBody(node) { | ||
this.push("{"); | ||
this.token("{"); | ||
this.printInnerComments(node); | ||
if (node.body.length === 0) { | ||
this.push("}"); | ||
this.token("}"); | ||
} else { | ||
@@ -56,5 +60,8 @@ this.newline(); | ||
function ClassProperty(node) { | ||
this.printJoin(node.decorators, node, { separator: "" }); | ||
this.printJoin(node.decorators, node); | ||
if (node.static) this.push("static "); | ||
if (node.static) { | ||
this.word("static"); | ||
this.space(); | ||
} | ||
this.print(node.key, node); | ||
@@ -64,3 +71,3 @@ this.print(node.typeAnnotation, node); | ||
this.space(); | ||
this.push("="); | ||
this.token("="); | ||
this.space(); | ||
@@ -73,10 +80,12 @@ this.print(node.value, node); | ||
function ClassMethod(node) { | ||
this.printJoin(node.decorators, node, { separator: "" }); | ||
this.printJoin(node.decorators, node); | ||
if (node.static) { | ||
this.push("static "); | ||
this.word("static"); | ||
this.space(); | ||
} | ||
if (node.kind === "constructorCall") { | ||
this.push("call "); | ||
this.word("call"); | ||
this.space(); | ||
} | ||
@@ -83,0 +92,0 @@ |
@@ -51,15 +51,9 @@ "use strict"; | ||
function UnaryExpression(node) { | ||
var needsSpace = /[a-z]$/.test(node.operator); | ||
var arg = node.argument; | ||
if (t.isUpdateExpression(arg) || t.isUnaryExpression(arg)) { | ||
needsSpace = true; | ||
if (node.operator === "void" || node.operator === "delete" || node.operator === "typeof") { | ||
this.word(node.operator); | ||
this.space(); | ||
} else { | ||
this.token(node.operator); | ||
} | ||
if (t.isUnaryExpression(arg) && arg.operator === "!") { | ||
needsSpace = false; | ||
} | ||
this.push(node.operator); | ||
if (needsSpace) this.push(" "); | ||
this.print(node.argument, node); | ||
@@ -69,3 +63,3 @@ } | ||
function DoExpression(node) { | ||
this.push("do"); | ||
this.word("do"); | ||
this.space(); | ||
@@ -76,5 +70,5 @@ this.print(node.body, node); | ||
function ParenthesizedExpression(node) { | ||
this.push("("); | ||
this.token("("); | ||
this.print(node.expression, node); | ||
this.push(")"); | ||
this.token(")"); | ||
} | ||
@@ -84,7 +78,7 @@ | ||
if (node.prefix) { | ||
this.push(node.operator); | ||
this.token(node.operator); | ||
this.print(node.argument, node); | ||
} else { | ||
this.print(node.argument, node); | ||
this.push(node.operator); | ||
this.token(node.operator); | ||
} | ||
@@ -96,7 +90,7 @@ } | ||
this.space(); | ||
this.push("?"); | ||
this.token("?"); | ||
this.space(); | ||
this.print(node.consequent, node); | ||
this.space(); | ||
this.push(":"); | ||
this.token(":"); | ||
this.space(); | ||
@@ -107,9 +101,10 @@ this.print(node.alternate, node); | ||
function NewExpression(node, parent) { | ||
this.push("new "); | ||
this.word("new"); | ||
this.space(); | ||
this.print(node.callee, node); | ||
if (node.arguments.length === 0 && this.format.minified && !t.isCallExpression(parent, { callee: node }) && !t.isMemberExpression(parent) && !t.isNewExpression(parent)) return; | ||
this.push("("); | ||
this.token("("); | ||
this.printList(node.arguments, node); | ||
this.push(")"); | ||
this.token(")"); | ||
} | ||
@@ -122,11 +117,11 @@ | ||
function ThisExpression() { | ||
this.push("this"); | ||
this.word("this"); | ||
} | ||
function Super() { | ||
this.push("super"); | ||
this.word("super"); | ||
} | ||
function Decorator(node) { | ||
this.push("@"); | ||
this.token("@"); | ||
this.print(node.expression, node); | ||
@@ -136,2 +131,7 @@ this.newline(); | ||
function commaSeparatorNewline() { | ||
this.token(","); | ||
this.push("\n"); | ||
} | ||
function CallExpression(node) { | ||
@@ -141,3 +141,3 @@ this.print(node.callee, node); | ||
this.push("("); | ||
this.token("("); | ||
@@ -148,3 +148,3 @@ var isPrettyCall = node._prettyCall && !this.format.retainLines && !this.format.compact; | ||
if (isPrettyCall) { | ||
separator = ",\n"; | ||
separator = commaSeparatorNewline; | ||
this.newline(); | ||
@@ -161,3 +161,3 @@ this.indent(); | ||
this.push(")"); | ||
this.token(")"); | ||
} | ||
@@ -167,10 +167,10 @@ | ||
return function (node) { | ||
this.push(keyword); | ||
this.word(keyword); | ||
if (node.delegate) { | ||
this.push("*"); | ||
this.token("*"); | ||
} | ||
if (node.argument) { | ||
this.push(" "); | ||
this.space(); | ||
var terminatorState = this.startTerminatorless(); | ||
@@ -199,3 +199,3 @@ this.print(node.argument, node); | ||
this.space(); | ||
this.push("="); | ||
this.token("="); | ||
this.space(); | ||
@@ -211,3 +211,3 @@ this.print(node.right, node); | ||
if (parens) { | ||
this.push("("); | ||
this.token("("); | ||
} | ||
@@ -217,25 +217,14 @@ | ||
var spaces = !this.format.compact || node.operator === "in" || node.operator === "instanceof"; | ||
if (spaces) this.push(" "); | ||
this.push(node.operator); | ||
if (!spaces) { | ||
// space is mandatory to avoid outputting <!-- | ||
// http://javascript.spec.whatwg.org/#comment-syntax | ||
spaces = node.operator === "<" && t.isUnaryExpression(node.right, { prefix: true, operator: "!" }) && t.isUnaryExpression(node.right.argument, { prefix: true, operator: "--" }); | ||
// Need spaces for operators of the same kind to avoid: `a+++b` | ||
if (!spaces) { | ||
var right = getLeftMost(node.right); | ||
spaces = t.isUnaryExpression(right, { prefix: true, operator: node.operator }) || t.isUpdateExpression(right, { prefix: true, operator: node.operator + node.operator }); | ||
} | ||
this.space(); | ||
if (node.operator === "in" || node.operator === "instanceof") { | ||
this.word(node.operator); | ||
} else { | ||
this.token(node.operator); | ||
} | ||
this.space(); | ||
if (spaces) this.push(" "); | ||
this.print(node.right, node); | ||
if (parens) { | ||
this.push(")"); | ||
this.token(")"); | ||
} | ||
@@ -246,3 +235,3 @@ } | ||
this.print(node.object, node); | ||
this.push("::"); | ||
this.token("::"); | ||
this.print(node.callee, node); | ||
@@ -266,5 +255,5 @@ } | ||
if (computed) { | ||
this.push("["); | ||
this.token("["); | ||
this.print(node.property, node); | ||
this.push("]"); | ||
this.token("]"); | ||
} else { | ||
@@ -274,7 +263,7 @@ if (t.isNumericLiteral(node.object)) { | ||
if ((0, _isInteger2.default)(+val) && !NON_DECIMAL_LITERAL.test(val) && !SCIENTIFIC_NOTATION.test(val) && !ZERO_DECIMAL_INTEGER.test(val) && !this.endsWith(".")) { | ||
this.push("."); | ||
this.token("."); | ||
} | ||
} | ||
this.push("."); | ||
this.token("."); | ||
this.print(node.property, node); | ||
@@ -286,11 +275,4 @@ } | ||
this.print(node.meta, node); | ||
this.push("."); | ||
this.token("."); | ||
this.print(node.property, node); | ||
} | ||
function getLeftMost(binaryExpr) { | ||
if (!t.isBinaryExpression(binaryExpr)) { | ||
return binaryExpr; | ||
} | ||
return getLeftMost(binaryExpr.left); | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
exports.TypeParameterDeclaration = exports.NumericLiteralTypeAnnotation = exports.GenericTypeAnnotation = exports.ClassImplements = undefined; | ||
exports.TypeParameterDeclaration = exports.StringLiteralTypeAnnotation = exports.NumericLiteralTypeAnnotation = exports.GenericTypeAnnotation = exports.ClassImplements = undefined; | ||
exports.AnyTypeAnnotation = AnyTypeAnnotation; | ||
@@ -34,4 +34,9 @@ exports.ArrayTypeAnnotation = ArrayTypeAnnotation; | ||
}); | ||
Object.defineProperty(exports, "StringLiteralTypeAnnotation", { | ||
enumerable: true, | ||
get: function get() { | ||
return _types.StringLiteral; | ||
} | ||
}); | ||
exports.NumberTypeAnnotation = NumberTypeAnnotation; | ||
exports.StringLiteralTypeAnnotation = StringLiteralTypeAnnotation; | ||
exports.StringTypeAnnotation = StringTypeAnnotation; | ||
@@ -61,3 +66,3 @@ exports.ThisTypeAnnotation = ThisTypeAnnotation; | ||
function AnyTypeAnnotation() { | ||
this.push("any"); | ||
this.word("any"); | ||
} /* eslint max-len: 0 */ | ||
@@ -67,20 +72,23 @@ | ||
this.print(node.elementType, node); | ||
this.push("["); | ||
this.push("]"); | ||
this.token("["); | ||
this.token("]"); | ||
} | ||
function BooleanTypeAnnotation() { | ||
this.push("bool"); | ||
this.word("bool"); | ||
} | ||
function BooleanLiteralTypeAnnotation(node) { | ||
this.push(node.value ? "true" : "false"); | ||
this.word(node.value ? "true" : "false"); | ||
} | ||
function NullLiteralTypeAnnotation() { | ||
this.push("null"); | ||
this.word("null"); | ||
} | ||
function DeclareClass(node) { | ||
this.push("declare class "); | ||
this.word("declare"); | ||
this.space(); | ||
this.word("class"); | ||
this.space(); | ||
this._interfaceish(node); | ||
@@ -90,3 +98,6 @@ } | ||
function DeclareFunction(node) { | ||
this.push("declare function "); | ||
this.word("declare"); | ||
this.space(); | ||
this.word("function"); | ||
this.space(); | ||
this.print(node.id, node); | ||
@@ -98,3 +109,4 @@ this.print(node.id.typeAnnotation.typeAnnotation, node); | ||
function DeclareInterface(node) { | ||
this.push("declare "); | ||
this.word("declare"); | ||
this.space(); | ||
this.InterfaceDeclaration(node); | ||
@@ -104,3 +116,6 @@ } | ||
function DeclareModule(node) { | ||
this.push("declare module "); | ||
this.word("declare"); | ||
this.space(); | ||
this.word("module"); | ||
this.space(); | ||
this.print(node.id, node); | ||
@@ -112,3 +127,4 @@ this.space(); | ||
function DeclareTypeAlias(node) { | ||
this.push("declare "); | ||
this.word("declare"); | ||
this.space(); | ||
this.TypeAlias(node); | ||
@@ -118,3 +134,6 @@ } | ||
function DeclareVariable(node) { | ||
this.push("declare var "); | ||
this.word("declare"); | ||
this.space(); | ||
this.word("var"); | ||
this.space(); | ||
this.print(node.id, node); | ||
@@ -126,3 +145,3 @@ this.print(node.id.typeAnnotation, node); | ||
function ExistentialTypeParam() { | ||
this.push("*"); | ||
this.token("*"); | ||
} | ||
@@ -132,3 +151,3 @@ | ||
this.print(node.typeParameters, node); | ||
this.push("("); | ||
this.token("("); | ||
this.printList(node.params, node); | ||
@@ -138,17 +157,17 @@ | ||
if (node.params.length) { | ||
this.push(","); | ||
this.token(","); | ||
this.space(); | ||
} | ||
this.push("..."); | ||
this.token("..."); | ||
this.print(node.rest, node); | ||
} | ||
this.push(")"); | ||
this.token(")"); | ||
// this node type is overloaded, not sure why but it makes it EXTREMELY annoying | ||
if (parent.type === "ObjectTypeProperty" || parent.type === "ObjectTypeCallProperty" || parent.type === "DeclareFunction") { | ||
this.push(":"); | ||
this.token(":"); | ||
} else { | ||
this.space(); | ||
this.push("=>"); | ||
this.token("=>"); | ||
} | ||
@@ -162,4 +181,4 @@ | ||
this.print(node.name, node); | ||
if (node.optional) this.push("?"); | ||
this.push(":"); | ||
if (node.optional) this.token("?"); | ||
this.token(":"); | ||
this.space(); | ||
@@ -180,8 +199,12 @@ this.print(node.typeAnnotation, node); | ||
if (node.extends.length) { | ||
this.push(" extends "); | ||
this.printJoin(node.extends, node, { separator: ", " }); | ||
this.space(); | ||
this.word("extends"); | ||
this.space(); | ||
this.printList(node.extends, node); | ||
} | ||
if (node.mixins && node.mixins.length) { | ||
this.push(" mixins "); | ||
this.printJoin(node.mixins, node, { separator: ", " }); | ||
this.space(); | ||
this.word("mixins"); | ||
this.space(); | ||
this.printList(node.mixins, node); | ||
} | ||
@@ -193,16 +216,23 @@ this.space(); | ||
function InterfaceDeclaration(node) { | ||
this.push("interface "); | ||
this.word("interface"); | ||
this.space(); | ||
this._interfaceish(node); | ||
} | ||
function andSeparator() { | ||
this.space(); | ||
this.token("&"); | ||
this.space(); | ||
} | ||
function IntersectionTypeAnnotation(node) { | ||
this.printJoin(node.types, node, { separator: " & " }); | ||
this.printJoin(node.types, node, { separator: andSeparator }); | ||
} | ||
function MixedTypeAnnotation() { | ||
this.push("mixed"); | ||
this.word("mixed"); | ||
} | ||
function NullableTypeAnnotation(node) { | ||
this.push("?"); | ||
this.token("?"); | ||
this.print(node.typeAnnotation, node); | ||
@@ -212,25 +242,22 @@ } | ||
function NumberTypeAnnotation() { | ||
this.push("number"); | ||
this.word("number"); | ||
} | ||
function StringLiteralTypeAnnotation(node) { | ||
this.push(this._stringLiteral(node.value)); | ||
} | ||
function StringTypeAnnotation() { | ||
this.push("string"); | ||
this.word("string"); | ||
} | ||
function ThisTypeAnnotation() { | ||
this.push("this"); | ||
this.word("this"); | ||
} | ||
function TupleTypeAnnotation(node) { | ||
this.push("["); | ||
this.printJoin(node.types, node, { separator: ", " }); | ||
this.push("]"); | ||
this.token("["); | ||
this.printList(node.types, node); | ||
this.token("]"); | ||
} | ||
function TypeofTypeAnnotation(node) { | ||
this.push("typeof "); | ||
this.word("typeof"); | ||
this.space(); | ||
this.print(node.argument, node); | ||
@@ -240,7 +267,8 @@ } | ||
function TypeAlias(node) { | ||
this.push("type "); | ||
this.word("type"); | ||
this.space(); | ||
this.print(node.id, node); | ||
this.print(node.typeParameters, node); | ||
this.space(); | ||
this.push("="); | ||
this.token("="); | ||
this.space(); | ||
@@ -252,5 +280,5 @@ this.print(node.right, node); | ||
function TypeAnnotation(node) { | ||
this.push(":"); | ||
this.token(":"); | ||
this.space(); | ||
if (node.optional) this.push("?"); | ||
if (node.optional) this.token("?"); | ||
this.print(node.typeAnnotation, node); | ||
@@ -261,8 +289,8 @@ } | ||
if (node.variance === "plus") { | ||
this.push("+"); | ||
this.token("+"); | ||
} else if (node.variance === "minus") { | ||
this.push("-"); | ||
this.token("-"); | ||
} | ||
this.push(node.name); | ||
this.word(node.name); | ||
@@ -275,3 +303,3 @@ if (node.bound) { | ||
this.space(); | ||
this.push("="); | ||
this.token("="); | ||
this.space(); | ||
@@ -285,5 +313,4 @@ this.print(node.default, node); | ||
this.push("<"); | ||
this.printJoin(node.params, node, { | ||
separator: ", ", | ||
this.token("<"); | ||
this.printList(node.params, node, { | ||
iterator: function iterator(node) { | ||
@@ -293,3 +320,3 @@ _this.print(node.typeAnnotation, node); | ||
}); | ||
this.push(">"); | ||
this.token(">"); | ||
} | ||
@@ -301,3 +328,3 @@ | ||
this.push("{"); | ||
this.token("{"); | ||
var props = node.properties.concat(node.callProperties, node.indexers); | ||
@@ -309,3 +336,2 @@ | ||
this.printJoin(props, node, { | ||
separator: false, | ||
indent: true, | ||
@@ -323,7 +349,10 @@ iterator: function iterator() { | ||
this.push("}"); | ||
this.token("}"); | ||
} | ||
function ObjectTypeCallProperty(node) { | ||
if (node.static) this.push("static "); | ||
if (node.static) { | ||
this.word("static"); | ||
this.space(); | ||
} | ||
this.print(node.value, node); | ||
@@ -333,10 +362,13 @@ } | ||
function ObjectTypeIndexer(node) { | ||
if (node.static) this.push("static "); | ||
this.push("["); | ||
if (node.static) { | ||
this.word("static"); | ||
this.space(); | ||
} | ||
this.token("["); | ||
this.print(node.id, node); | ||
this.push(":"); | ||
this.token(":"); | ||
this.space(); | ||
this.print(node.key, node); | ||
this.push("]"); | ||
this.push(":"); | ||
this.token("]"); | ||
this.token(":"); | ||
this.space(); | ||
@@ -347,7 +379,10 @@ this.print(node.value, node); | ||
function ObjectTypeProperty(node) { | ||
if (node.static) this.push("static "); | ||
if (node.static) { | ||
this.word("static"); | ||
this.space(); | ||
} | ||
this.print(node.key, node); | ||
if (node.optional) this.push("?"); | ||
if (node.optional) this.token("?"); | ||
if (!t.isFunctionTypeAnnotation(node.value)) { | ||
this.push(":"); | ||
this.token(":"); | ||
this.space(); | ||
@@ -360,19 +395,25 @@ } | ||
this.print(node.qualification, node); | ||
this.push("."); | ||
this.token("."); | ||
this.print(node.id, node); | ||
} | ||
function orSeparator() { | ||
this.space(); | ||
this.token("|"); | ||
this.space(); | ||
} | ||
function UnionTypeAnnotation(node) { | ||
this.printJoin(node.types, node, { separator: " | " }); | ||
this.printJoin(node.types, node, { separator: orSeparator }); | ||
} | ||
function TypeCastExpression(node) { | ||
this.push("("); | ||
this.token("("); | ||
this.print(node.expression, node); | ||
this.print(node.typeAnnotation, node); | ||
this.push(")"); | ||
this.token(")"); | ||
} | ||
function VoidTypeAnnotation() { | ||
this.push("void"); | ||
this.word("void"); | ||
} |
@@ -26,3 +26,3 @@ "use strict"; | ||
if (node.value) { | ||
this.push("="); | ||
this.token("="); | ||
this.print(node.value, node); | ||
@@ -33,3 +33,3 @@ } | ||
function JSXIdentifier(node) { | ||
this.push(node.name); | ||
this.word(node.name); | ||
} | ||
@@ -39,3 +39,3 @@ | ||
this.print(node.namespace, node); | ||
this.push(":"); | ||
this.token(":"); | ||
this.print(node.name, node); | ||
@@ -46,3 +46,3 @@ } | ||
this.print(node.object, node); | ||
this.push("."); | ||
this.token("."); | ||
this.print(node.property, node); | ||
@@ -52,15 +52,16 @@ } | ||
function JSXSpreadAttribute(node) { | ||
this.push("{..."); | ||
this.token("{"); | ||
this.token("..."); | ||
this.print(node.argument, node); | ||
this.push("}"); | ||
this.token("}"); | ||
} | ||
function JSXExpressionContainer(node) { | ||
this.push("{"); | ||
this.token("{"); | ||
this.print(node.expression, node); | ||
this.push("}"); | ||
this.token("}"); | ||
} | ||
function JSXText(node) { | ||
this.push(node.value, true); | ||
this.token(node.value); | ||
} | ||
@@ -95,18 +96,27 @@ | ||
function spaceSeparator() { | ||
this.space(); | ||
} | ||
function JSXOpeningElement(node) { | ||
this.push("<"); | ||
this.token("<"); | ||
this.print(node.name, node); | ||
if (node.attributes.length > 0) { | ||
this.push(" "); | ||
this.printJoin(node.attributes, node, { separator: " " }); | ||
this.space(); | ||
this.printJoin(node.attributes, node, { separator: spaceSeparator }); | ||
} | ||
this.push(node.selfClosing ? " />" : ">"); | ||
if (node.selfClosing) { | ||
this.space(); | ||
this.token("/>"); | ||
} else { | ||
this.token(">"); | ||
} | ||
} | ||
function JSXClosingElement(node) { | ||
this.push("</"); | ||
this.token("</"); | ||
this.print(node.name, node); | ||
this.push(">"); | ||
this.token(">"); | ||
} | ||
function JSXEmptyExpression() {} |
@@ -20,10 +20,10 @@ "use strict"; | ||
this.print(node.typeParameters, node); | ||
this.push("("); | ||
this.token("("); | ||
this.printList(node.params, node, { | ||
iterator: function iterator(node) { | ||
if (node.optional) _this.push("?"); | ||
if (node.optional) _this.token("?"); | ||
_this.print(node.typeAnnotation, node); | ||
} | ||
}); | ||
this.push(")"); | ||
this.token(")"); | ||
@@ -41,3 +41,3 @@ if (node.returnType) { | ||
if (node.generator) { | ||
this.push("*"); | ||
this.token("*"); | ||
} | ||
@@ -47,11 +47,15 @@ } | ||
if (kind === "get" || kind === "set") { | ||
this.push(kind + " "); | ||
this.word(kind); | ||
this.space(); | ||
} | ||
if (node.async) this.push("async "); | ||
if (node.async) { | ||
this.word("async"); | ||
this.space(); | ||
} | ||
if (node.computed) { | ||
this.push("["); | ||
this.token("["); | ||
this.print(key, node); | ||
this.push("]"); | ||
this.token("]"); | ||
} else { | ||
@@ -67,8 +71,11 @@ this.print(key, node); | ||
function FunctionExpression(node) { | ||
if (node.async) this.push("async "); | ||
this.push("function"); | ||
if (node.generator) this.push("*"); | ||
if (node.async) { | ||
this.word("async"); | ||
this.space(); | ||
} | ||
this.word("function"); | ||
if (node.generator) this.token("*"); | ||
if (node.id) { | ||
this.push(" "); | ||
this.space(); | ||
this.print(node.id, node); | ||
@@ -86,3 +93,6 @@ } else { | ||
function ArrowFunctionExpression(node) { | ||
if (node.async) this.push("async "); | ||
if (node.async) { | ||
this.word("async"); | ||
this.space(); | ||
} | ||
@@ -95,5 +105,7 @@ if (node.params.length === 1 && t.isIdentifier(node.params[0])) { | ||
this.push(" => "); | ||
this.space(); | ||
this.token("=>"); | ||
this.space(); | ||
this.print(node.body, node); | ||
} |
@@ -24,3 +24,5 @@ "use strict"; | ||
if (node.local && node.local.name !== node.imported.name) { | ||
this.push(" as "); | ||
this.space(); | ||
this.word("as"); | ||
this.space(); | ||
this.print(node.local, node); | ||
@@ -41,3 +43,5 @@ } | ||
if (node.exported && node.local.name !== node.exported.name) { | ||
this.push(" as "); | ||
this.space(); | ||
this.word("as"); | ||
this.space(); | ||
this.print(node.exported, node); | ||
@@ -48,3 +52,6 @@ } | ||
function ExportNamespaceSpecifier(node) { | ||
this.push("* as "); | ||
this.token("*"); | ||
this.space(); | ||
this.word("as"); | ||
this.space(); | ||
this.print(node.exported, node); | ||
@@ -54,8 +61,14 @@ } | ||
function ExportAllDeclaration(node) { | ||
this.push("export *"); | ||
this.word("export"); | ||
this.space(); | ||
this.token("*"); | ||
if (node.exported) { | ||
this.push(" as "); | ||
this.space(); | ||
this.word("as"); | ||
this.space(); | ||
this.print(node.exported, node); | ||
} | ||
this.push(" from "); | ||
this.space(); | ||
this.word("from"); | ||
this.space(); | ||
this.print(node.source, node); | ||
@@ -66,3 +79,4 @@ this.semicolon(); | ||
function ExportNamedDeclaration() { | ||
this.push("export "); | ||
this.word("export"); | ||
this.space(); | ||
ExportDeclaration.apply(this, arguments); | ||
@@ -72,3 +86,6 @@ } | ||
function ExportDefaultDeclaration() { | ||
this.push("export default "); | ||
this.word("export"); | ||
this.space(); | ||
this.word("default"); | ||
this.space(); | ||
ExportDeclaration.apply(this, arguments); | ||
@@ -81,6 +98,7 @@ } | ||
this.print(declar, node); | ||
if (t.isStatement(declar) || t.isFunction(declar) || t.isClass(declar)) return; | ||
if (!t.isStatement(declar)) this.semicolon(); | ||
} else { | ||
if (node.exportKind === "type") { | ||
this.push("type "); | ||
this.word("type"); | ||
this.space(); | ||
} | ||
@@ -98,3 +116,4 @@ | ||
if (specifiers.length) { | ||
this.push(", "); | ||
this.token(","); | ||
this.space(); | ||
} | ||
@@ -107,25 +126,29 @@ } else { | ||
if (specifiers.length || !specifiers.length && !hasSpecial) { | ||
this.push("{"); | ||
this.token("{"); | ||
if (specifiers.length) { | ||
this.space(); | ||
this.printJoin(specifiers, node, { separator: ", " }); | ||
this.printList(specifiers, node); | ||
this.space(); | ||
} | ||
this.push("}"); | ||
this.token("}"); | ||
} | ||
if (node.source) { | ||
this.push(" from "); | ||
this.space(); | ||
this.word("from"); | ||
this.space(); | ||
this.print(node.source, node); | ||
} | ||
this.semicolon(); | ||
} | ||
this.ensureSemicolon(); | ||
} | ||
function ImportDeclaration(node) { | ||
this.push("import "); | ||
this.word("import"); | ||
this.space(); | ||
if (node.importKind === "type" || node.importKind === "typeof") { | ||
this.push(node.importKind + " "); | ||
this.word(node.importKind); | ||
this.space(); | ||
} | ||
@@ -141,3 +164,4 @@ | ||
if (specifiers.length) { | ||
this.push(", "); | ||
this.token(","); | ||
this.space(); | ||
} | ||
@@ -150,10 +174,12 @@ } else { | ||
if (specifiers.length) { | ||
this.push("{"); | ||
this.token("{"); | ||
this.space(); | ||
this.printJoin(specifiers, node, { separator: ", " }); | ||
this.printList(specifiers, node); | ||
this.space(); | ||
this.push("}"); | ||
this.token("}"); | ||
} | ||
this.push(" from "); | ||
this.space(); | ||
this.word("from"); | ||
this.space(); | ||
} | ||
@@ -166,4 +192,7 @@ | ||
function ImportNamespaceSpecifier(node) { | ||
this.push("* as "); | ||
this.token("*"); | ||
this.space(); | ||
this.word("as"); | ||
this.space(); | ||
this.print(node.local, node); | ||
} |
@@ -24,6 +24,2 @@ "use strict"; | ||
var _repeat = require("lodash/repeat"); | ||
var _repeat2 = _interopRequireDefault(_repeat); | ||
var _babelTypes = require("babel-types"); | ||
@@ -37,9 +33,7 @@ | ||
var NON_ALPHABETIC_UNARY_OPERATORS = t.UPDATE_OPERATORS.concat(t.NUMBER_UNARY_OPERATORS).concat(["!"]); | ||
function WithStatement(node) { | ||
this.keyword("with"); | ||
this.push("("); | ||
this.token("("); | ||
this.print(node.object, node); | ||
this.push(")"); | ||
this.token(")"); | ||
this.printBlock(node); | ||
@@ -50,5 +44,5 @@ } | ||
this.keyword("if"); | ||
this.push("("); | ||
this.token("("); | ||
this.print(node.test, node); | ||
this.push(")"); | ||
this.token(")"); | ||
this.space(); | ||
@@ -58,3 +52,3 @@ | ||
if (needsBlock) { | ||
this.push("{"); | ||
this.token("{"); | ||
this.newline(); | ||
@@ -69,8 +63,9 @@ this.indent(); | ||
this.newline(); | ||
this.push("}"); | ||
this.token("}"); | ||
} | ||
if (node.alternate) { | ||
if (this.isLast("}")) this.space(); | ||
this.push("else "); | ||
if (this.endsWith("}")) this.space(); | ||
this.word("else"); | ||
this.space(); | ||
this.printAndIndentOnComments(node.alternate, node); | ||
@@ -88,3 +83,3 @@ } | ||
this.keyword("for"); | ||
this.push("("); | ||
this.token("("); | ||
@@ -94,3 +89,3 @@ this._inForStatementInitCounter++; | ||
this._inForStatementInitCounter--; | ||
this.push(";"); | ||
this.token(";"); | ||
@@ -101,3 +96,3 @@ if (node.test) { | ||
} | ||
this.push(";"); | ||
this.token(";"); | ||
@@ -109,3 +104,3 @@ if (node.update) { | ||
this.push(")"); | ||
this.token(")"); | ||
this.printBlock(node); | ||
@@ -116,5 +111,5 @@ } | ||
this.keyword("while"); | ||
this.push("("); | ||
this.token("("); | ||
this.print(node.test, node); | ||
this.push(")"); | ||
this.token(")"); | ||
this.printBlock(node); | ||
@@ -126,7 +121,9 @@ } | ||
this.keyword("for"); | ||
this.push("("); | ||
this.token("("); | ||
this.print(node.left, node); | ||
this.push(" " + op + " "); | ||
this.space(); | ||
this.word(op); | ||
this.space(); | ||
this.print(node.right, node); | ||
this.push(")"); | ||
this.token(")"); | ||
this.printBlock(node); | ||
@@ -140,9 +137,11 @@ }; | ||
function DoWhileStatement(node) { | ||
this.push("do "); | ||
this.word("do"); | ||
this.space(); | ||
this.print(node.body, node); | ||
this.space(); | ||
this.keyword("while"); | ||
this.push("("); | ||
this.token("("); | ||
this.print(node.test, node); | ||
this.push(");"); | ||
this.token(")"); | ||
this.semicolon(); | ||
} | ||
@@ -154,9 +153,7 @@ | ||
return function (node) { | ||
this.push(prefix); | ||
this.word(prefix); | ||
var label = node[key]; | ||
if (label) { | ||
if (!(this.format.minified && (t.isUnaryExpression(label, { prefix: true }) || t.isUpdateExpression(label, { prefix: true })) && NON_ALPHABETIC_UNARY_OPERATORS.indexOf(label.operator) > -1)) { | ||
this.push(" "); | ||
} | ||
this.space(); | ||
@@ -179,3 +176,4 @@ var terminatorState = this.startTerminatorless(); | ||
this.print(node.label, node); | ||
this.push(": "); | ||
this.token(":"); | ||
this.space(); | ||
this.print(node.body, node); | ||
@@ -200,3 +198,4 @@ } | ||
this.space(); | ||
this.push("finally "); | ||
this.word("finally"); | ||
this.space(); | ||
this.print(node.finalizer, node); | ||
@@ -208,5 +207,5 @@ } | ||
this.keyword("catch"); | ||
this.push("("); | ||
this.token("("); | ||
this.print(node.param, node); | ||
this.push(")"); | ||
this.token(")"); | ||
this.space(); | ||
@@ -218,7 +217,7 @@ this.print(node.body, node); | ||
this.keyword("switch"); | ||
this.push("("); | ||
this.token("("); | ||
this.print(node.discriminant, node); | ||
this.push(")"); | ||
this.token(")"); | ||
this.space(); | ||
this.push("{"); | ||
this.token("{"); | ||
@@ -232,3 +231,3 @@ this.printSequence(node.cases, node, { | ||
this.push("}"); | ||
this.token("}"); | ||
} | ||
@@ -238,7 +237,9 @@ | ||
if (node.test) { | ||
this.push("case "); | ||
this.word("case"); | ||
this.space(); | ||
this.print(node.test, node); | ||
this.push(":"); | ||
this.token(":"); | ||
} else { | ||
this.push("default:"); | ||
this.word("default"); | ||
this.token(":"); | ||
} | ||
@@ -253,7 +254,27 @@ | ||
function DebuggerStatement() { | ||
this.push("debugger;"); | ||
this.word("debugger"); | ||
this.semicolon(); | ||
} | ||
function variableDeclarationIdent() { | ||
// "let " or "var " indentation. | ||
this.token(","); | ||
this.push("\n"); | ||
for (var i = 0; i < 4; i++) { | ||
this.push(" "); | ||
} | ||
} | ||
function constDeclarationIdent() { | ||
// "const " indentation. | ||
this.token(","); | ||
this.push("\n"); | ||
for (var i = 0; i < 6; i++) { | ||
this.push(" "); | ||
} | ||
} | ||
function VariableDeclaration(node, parent) { | ||
this.push(node.kind + " "); | ||
this.word(node.kind); | ||
this.space(); | ||
@@ -296,5 +317,5 @@ var hasInits = false; | ||
var sep = void 0; | ||
var separator = void 0; | ||
if (!this.format.compact && !this.format.concise && hasInits && !this.format.retainLines) { | ||
sep = ",\n" + (0, _repeat2.default)(" ", node.kind.length + 1); | ||
separator = node.kind === "const" ? constDeclarationIdent : variableDeclarationIdent; | ||
} | ||
@@ -304,3 +325,3 @@ | ||
this.printList(node.declarations, node, { separator: sep }); | ||
this.printList(node.declarations, node, { separator: separator }); | ||
@@ -320,3 +341,3 @@ if (t.isFor(parent)) { | ||
this.space(); | ||
this.push("="); | ||
this.token("="); | ||
this.space(); | ||
@@ -323,0 +344,0 @@ this.print(node.init, node); |
@@ -12,9 +12,14 @@ "use strict"; | ||
function TemplateElement(node) { | ||
this._push(node.value.raw); | ||
function TemplateElement(node, parent) { | ||
var isFirst = parent.quasis[0] === node; | ||
var isLast = parent.quasis[parent.quasis.length - 1] === node; | ||
var value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${"); | ||
if (!isFirst) this.space(); | ||
this.token(value); | ||
if (!isLast) this.space(); | ||
} | ||
function TemplateLiteral(node) { | ||
this.push("`"); | ||
var quasis = node.quasis; | ||
@@ -26,9 +31,5 @@ | ||
if (i + 1 < quasis.length) { | ||
this._push("${ "); | ||
this.print(node.expressions[i], node); | ||
this.push(" }"); | ||
} | ||
} | ||
this._push("`"); | ||
} |
@@ -21,3 +21,2 @@ "use strict"; | ||
exports.StringLiteral = StringLiteral; | ||
exports._stringLiteral = _stringLiteral; | ||
@@ -39,9 +38,9 @@ var _babelTypes = require("babel-types"); | ||
if (node.variance === "plus") { | ||
this.push("+"); | ||
this.token("+"); | ||
} else if (node.variance === "minus") { | ||
this.push("-"); | ||
this.token("-"); | ||
} | ||
} | ||
this.push(node.name); | ||
this.word(node.name); | ||
} /* eslint max-len: 0 */ | ||
@@ -51,3 +50,3 @@ /* eslint quotes: 0 */ | ||
function RestElement(node) { | ||
this.push("..."); | ||
this.token("..."); | ||
this.print(node.argument, node); | ||
@@ -62,3 +61,3 @@ } | ||
this.push("{"); | ||
this.token("{"); | ||
this.printInnerComments(node); | ||
@@ -72,3 +71,3 @@ | ||
this.push("}"); | ||
this.token("}"); | ||
} | ||
@@ -78,3 +77,3 @@ | ||
function ObjectMethod(node) { | ||
this.printJoin(node.decorators, node, { separator: "" }); | ||
this.printJoin(node.decorators, node); | ||
this._method(node); | ||
@@ -84,8 +83,8 @@ } | ||
function ObjectProperty(node) { | ||
this.printJoin(node.decorators, node, { separator: "" }); | ||
this.printJoin(node.decorators, node); | ||
if (node.computed) { | ||
this.push("["); | ||
this.token("["); | ||
this.print(node.key, node); | ||
this.push("]"); | ||
this.token("]"); | ||
} else { | ||
@@ -106,3 +105,3 @@ // print `({ foo: foo = 5 } = {})` as `({ foo = 5 } = {});` | ||
this.push(":"); | ||
this.token(":"); | ||
this.space(); | ||
@@ -116,3 +115,3 @@ this.print(node.value, node); | ||
this.push("["); | ||
this.token("["); | ||
this.printInnerComments(node); | ||
@@ -125,3 +124,3 @@ | ||
this.print(elem, node); | ||
if (i < len - 1) this.push(","); | ||
if (i < len - 1) this.token(","); | ||
} else { | ||
@@ -133,7 +132,7 @@ // If the array expression ends with a hole, that hole | ||
// both (all) of the holes. | ||
this.push(","); | ||
this.token(","); | ||
} | ||
} | ||
this.push("]"); | ||
this.token("]"); | ||
} | ||
@@ -143,23 +142,31 @@ | ||
function RegExpLiteral(node) { | ||
this.push("/" + node.pattern + "/" + node.flags); | ||
this.word("/" + node.pattern + "/" + node.flags); | ||
} | ||
function BooleanLiteral(node) { | ||
this.push(node.value ? "true" : "false"); | ||
this.word(node.value ? "true" : "false"); | ||
} | ||
function NullLiteral() { | ||
this.push("null"); | ||
this.word("null"); | ||
} | ||
function NumericLiteral(node) { | ||
this.push(node.value + ""); | ||
var raw = this.getPossibleRaw(node); | ||
if (raw != null) { | ||
this.word(raw); | ||
return; | ||
} | ||
this.word(node.value + ""); | ||
} | ||
function StringLiteral(node, parent) { | ||
this.push(this._stringLiteral(node.value, parent)); | ||
} | ||
var raw = this.getPossibleRaw(node); | ||
if (raw != null) { | ||
this.token(raw); | ||
return; | ||
} | ||
function _stringLiteral(val, parent) { | ||
val = (0, _stringify2.default)(val); | ||
var val = (0, _stringify2.default)(node.value); | ||
@@ -185,3 +192,3 @@ // escape illegal js but valid json unicode characters | ||
return val; | ||
return this.token(val); | ||
} |
@@ -19,3 +19,3 @@ "use strict"; | ||
exports.default = function (ast, opts, code) { | ||
var gen = new CodeGenerator(ast, opts, code); | ||
var gen = new Generator(ast, opts, code); | ||
return gen.generate(); | ||
@@ -57,7 +57,7 @@ }; | ||
var CodeGenerator = exports.CodeGenerator = function (_Printer) { | ||
(0, _inherits3.default)(CodeGenerator, _Printer); | ||
var Generator = function (_Printer) { | ||
(0, _inherits3.default)(Generator, _Printer); | ||
function CodeGenerator(ast, opts, code) { | ||
(0, _classCallCheck3.default)(this, CodeGenerator); | ||
function Generator(ast, opts, code) { | ||
(0, _classCallCheck3.default)(this, Generator); | ||
@@ -68,3 +68,3 @@ opts = opts || {}; | ||
var tokens = ast.tokens || []; | ||
var format = CodeGenerator.normalizeOptions(code, opts, tokens); | ||
var format = Generator.normalizeOptions(code, opts, tokens); | ||
@@ -93,5 +93,5 @@ var position = new _position2.default(); | ||
* - If `opts.compact = "auto"` and the code is over 100KB, `compact` will be set to `true`. | ||
*/ | ||
*/ | ||
CodeGenerator.normalizeOptions = function normalizeOptions(code, opts, tokens) { | ||
Generator.normalizeOptions = function normalizeOptions(code, opts, tokens) { | ||
var style = " "; | ||
@@ -112,3 +112,3 @@ if (code && typeof code === "string") { | ||
concise: opts.concise, | ||
quotes: opts.quotes || CodeGenerator.findCommonStringDelimiter(code, tokens), | ||
quotes: opts.quotes || Generator.findCommonStringDelimiter(code, tokens), | ||
indent: { | ||
@@ -145,3 +145,3 @@ adjustMultilineComment: true, | ||
CodeGenerator.findCommonStringDelimiter = function findCommonStringDelimiter(code, tokens) { | ||
Generator.findCommonStringDelimiter = function findCommonStringDelimiter(code, tokens) { | ||
var occurences = { | ||
@@ -181,3 +181,3 @@ single: 0, | ||
CodeGenerator.prototype.generate = function generate() { | ||
Generator.prototype.generate = function generate() { | ||
this.print(this.ast); | ||
@@ -192,3 +192,23 @@ this.printAuxAfterComment(); | ||
return Generator; | ||
}(_printer2.default); | ||
/** | ||
* We originally exported the Generator class above, but to make it extra clear that it is a private API, | ||
* we have moved that to an internal class instance and simplified the interface to the two public methods | ||
* that we wish to support. | ||
*/ | ||
var CodeGenerator = exports.CodeGenerator = function () { | ||
function CodeGenerator(ast, opts, code) { | ||
(0, _classCallCheck3.default)(this, CodeGenerator); | ||
this._generator = new Generator(ast, opts, code); | ||
} | ||
CodeGenerator.prototype.generate = function generate() { | ||
return this._generator.generate(); | ||
}; | ||
return CodeGenerator; | ||
}(_printer2.default); | ||
}(); |
@@ -101,3 +101,3 @@ "use strict"; | ||
var needsParens = n.needsParens(node, parent, this._printStack); | ||
if (needsParens) this.push("("); | ||
if (needsParens) this.token("("); | ||
@@ -114,3 +114,3 @@ this.printLeadingComments(node, parent); | ||
this.withSource("start", loc, function () { | ||
_this2._print(node, parent); | ||
_this2[node.type](node, parent); | ||
}); | ||
@@ -123,3 +123,3 @@ | ||
if (needsParens) this.push(")"); | ||
if (needsParens) this.token(")"); | ||
@@ -159,2 +159,4 @@ // end | ||
Printer.prototype.getPossibleRaw = function getPossibleRaw(node) { | ||
if (this.format.minified) return; | ||
var extra = node.extra; | ||
@@ -166,20 +168,2 @@ if (extra && extra.raw != null && extra.rawValue != null && node.value === extra.rawValue) { | ||
Printer.prototype._print = function _print(node, parent) { | ||
// In minified mode we need to produce as little bytes as needed | ||
// and need to make sure that string quoting is consistent. | ||
// That means we have to always reprint as opposed to getting | ||
// the raw value. | ||
if (!this.format.minified) { | ||
var extra = this.getPossibleRaw(node); | ||
if (extra) { | ||
this.push(""); | ||
this._push(extra); | ||
return; | ||
} | ||
} | ||
var printMethod = this[node.type]; | ||
printMethod.call(this, node, parent); | ||
}; | ||
Printer.prototype.printJoin = function printJoin(nodes, parent) { | ||
@@ -211,3 +195,3 @@ var _this3 = this; | ||
if (opts.separator && i < len - 1) { | ||
_this3.push(opts.separator); | ||
opts.separator.call(_this3); | ||
} | ||
@@ -280,4 +264,3 @@ } | ||
if (opts.separator == null) { | ||
opts.separator = ","; | ||
if (!this.format.compact) opts.separator += " "; | ||
opts.separator = commaSeparator; | ||
} | ||
@@ -366,10 +349,7 @@ | ||
if (!_this4.endsWith(["[", "{"])) _this4.space(); | ||
var column = _this4.position.column; | ||
var val = _this4.generateComment(comment); | ||
if (column && !_this4.isLast(["\n", " ", "[", "{"])) { | ||
_this4._push(" "); | ||
column++; | ||
} | ||
// | ||
@@ -387,6 +367,2 @@ if (comment.type === "CommentBlock" && _this4.format.indent.adjustMultilineComment) { | ||
if (column === 0) { | ||
val = _this4.getIndent() + val; | ||
} | ||
// force a newline for line comments when retainLines is set in case the next printed node | ||
@@ -399,3 +375,3 @@ // doesn't catch up | ||
// | ||
_this4._push(val); | ||
_this4.push(val); | ||
@@ -432,5 +408,10 @@ // whitespace after | ||
exports.default = Printer; | ||
var _arr = [require("./generators/template-literals"), require("./generators/expressions"), require("./generators/statements"), require("./generators/classes"), require("./generators/methods"), require("./generators/modules"), require("./generators/types"), require("./generators/flow"), require("./generators/base"), require("./generators/jsx")]; | ||
function commaSeparator() { | ||
this.token(","); | ||
this.space(); | ||
} | ||
var _arr = [require("./generators/template-literals"), require("./generators/expressions"), require("./generators/statements"), require("./generators/classes"), require("./generators/methods"), require("./generators/modules"), require("./generators/types"), require("./generators/flow"), require("./generators/base"), require("./generators/jsx")]; | ||
for (var _i2 = 0; _i2 < _arr.length; _i2++) { | ||
@@ -437,0 +418,0 @@ var generator = _arr[_i2]; |
{ | ||
"name": "babel-generator", | ||
"version": "6.10.0", | ||
"version": "6.10.2", | ||
"description": "Turns an AST into code.", | ||
@@ -16,3 +16,3 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"babel-runtime": "^6.9.0", | ||
"babel-types": "^6.10.0", | ||
"babel-types": "^6.10.2", | ||
"detect-indent": "^3.0.1", | ||
@@ -19,0 +19,0 @@ "lodash": "^4.2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
97515
21
2897
0
84
Updatedbabel-types@^6.10.2