babel-generator
Advanced tools
Comparing version 7.0.0-alpha.15 to 7.0.0-alpha.16
@@ -12,4 +12,2 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var SPACES_RE = /^[ \t]+$/; | ||
@@ -19,4 +17,2 @@ | ||
function Buffer(map) { | ||
_classCallCheck(this, Buffer); | ||
this._map = null; | ||
@@ -36,3 +32,2 @@ this._buf = []; | ||
}; | ||
this._map = map; | ||
@@ -59,3 +54,6 @@ } | ||
set: function set(value) { | ||
Object.defineProperty(this, "map", { value: value, writable: true }); | ||
Object.defineProperty(this, "map", { | ||
value: value, | ||
writable: true | ||
}); | ||
} | ||
@@ -70,2 +68,3 @@ }); | ||
this._flush(); | ||
var _sourcePosition = this._sourcePosition, | ||
@@ -98,2 +97,3 @@ line = _sourcePosition.line, | ||
var item = void 0; | ||
while (item = this._queue.pop()) { | ||
@@ -110,2 +110,3 @@ this._append.apply(this, item); | ||
this._buf.push(str); | ||
this._last = str[str.length - 1]; | ||
@@ -138,2 +139,3 @@ | ||
var last = void 0; | ||
if (this._queue.length > 0) { | ||
@@ -152,2 +154,3 @@ var str = this._queue[0][0]; | ||
}, ""); | ||
if (suffix.length <= end.length) { | ||
@@ -166,5 +169,3 @@ return end.slice(-suffix.length) === suffix; | ||
if (prop && !loc) return; | ||
var pos = loc ? loc[prop] : null; | ||
this._sourcePosition.identifierName = loc && loc.identifierName || null; | ||
@@ -178,3 +179,2 @@ this._sourcePosition.line = pos ? pos.line : null; | ||
if (!this._map) return cb(); | ||
var originalLine = this._sourcePosition.line; | ||
@@ -184,7 +184,4 @@ var originalColumn = this._sourcePosition.column; | ||
var originalIdentifierName = this._sourcePosition.identifierName; | ||
this.source(prop, loc); | ||
cb(); | ||
this._sourcePosition.line = originalLine; | ||
@@ -200,4 +197,4 @@ this._sourcePosition.column = originalColumn; | ||
}, ""); | ||
var lastIndex = extra.lastIndexOf("\n"); | ||
return lastIndex === -1 ? this._position.column + extra.length : extra.length - 1 - lastIndex; | ||
@@ -212,2 +209,3 @@ }; | ||
var count = 0; | ||
for (var i = 0; i < extra.length; i++) { | ||
@@ -214,0 +212,0 @@ if (extra[i] === "\n") count++; |
@@ -18,2 +18,3 @@ "use strict"; | ||
}); | ||
function File(node) { | ||
@@ -25,6 +26,4 @@ this.print(node.program, node); | ||
this.printInnerComments(node, false); | ||
this.printSequence(node.directives, node); | ||
if (node.directives && node.directives.length) this.newline(); | ||
this.printSequence(node.body, node); | ||
@@ -36,3 +35,2 @@ } | ||
this.printInnerComments(node); | ||
var hasDirectives = node.directives && node.directives.length; | ||
@@ -42,13 +40,12 @@ | ||
this.newline(); | ||
this.printSequence(node.directives, node, { indent: true }); | ||
this.printSequence(node.directives, node, { | ||
indent: true | ||
}); | ||
if (hasDirectives) this.newline(); | ||
this.printSequence(node.body, node, { indent: true }); | ||
this.printSequence(node.body, node, { | ||
indent: true | ||
}); | ||
this.removeTrailingNewline(); | ||
this.source("end", node.loc); | ||
if (!this.endsWith("\n")) this.newline(); | ||
this.rightBrace(); | ||
@@ -55,0 +52,0 @@ } else { |
@@ -50,5 +50,7 @@ "use strict"; | ||
exports.ClassExpression = ClassDeclaration; | ||
function ClassBody(node) { | ||
this.token("{"); | ||
this.printInnerComments(node); | ||
if (node.body.length === 0) { | ||
@@ -58,9 +60,6 @@ this.token("}"); | ||
this.newline(); | ||
this.indent(); | ||
this.printSequence(node.body, node); | ||
this.dedent(); | ||
if (!this.endsWith("\n")) this.newline(); | ||
this.rightBrace(); | ||
@@ -77,2 +76,3 @@ } | ||
} | ||
if (node.computed) { | ||
@@ -84,5 +84,8 @@ this.token("["); | ||
this._variance(node); | ||
this.print(node.key, node); | ||
} | ||
this.print(node.typeAnnotation, node); | ||
if (node.value) { | ||
@@ -94,2 +97,3 @@ this.space(); | ||
} | ||
this.semicolon(); | ||
@@ -96,0 +100,0 @@ } |
@@ -84,3 +84,6 @@ "use strict"; | ||
this.print(node.callee, node); | ||
if (this.format.minified && node.arguments.length === 0 && !node.optional && !t.isCallExpression(parent, { callee: node }) && !t.isMemberExpression(parent) && !t.isNewExpression(parent)) { | ||
if (this.format.minified && node.arguments.length === 0 && !node.optional && !t.isCallExpression(parent, { | ||
callee: node | ||
}) && !t.isMemberExpression(parent) && !t.isNewExpression(parent)) { | ||
return; | ||
@@ -92,2 +95,3 @@ } | ||
} | ||
this.token("("); | ||
@@ -116,9 +120,2 @@ this.printList(node.arguments, node); | ||
function commaSeparatorNewline() { | ||
this.token(","); | ||
this.newline(); | ||
if (!this.endsWith("\n")) this.space(); | ||
} | ||
function CallExpression(node) { | ||
@@ -130,20 +127,5 @@ this.print(node.callee, node); | ||
} | ||
this.token("("); | ||
var isPrettyCall = node._prettyCall; | ||
var separator = void 0; | ||
if (isPrettyCall) { | ||
separator = commaSeparatorNewline; | ||
this.newline(); | ||
this.indent(); | ||
} | ||
this.printList(node.arguments, node, { separator: separator }); | ||
if (isPrettyCall) { | ||
this.newline(); | ||
this.dedent(); | ||
} | ||
this.printList(node.arguments, node); | ||
this.token(")"); | ||
@@ -203,4 +185,4 @@ } | ||
this.print(node.left, node); | ||
this.space(); | ||
this.space(); | ||
if (node.operator === "in" || node.operator === "instanceof") { | ||
@@ -211,4 +193,4 @@ this.word(node.operator); | ||
} | ||
this.space(); | ||
this.print(node.right, node); | ||
@@ -229,2 +211,3 @@ | ||
exports.LogicalExpression = AssignmentExpression; | ||
function MemberExpression(node) { | ||
@@ -238,2 +221,3 @@ this.print(node.object, node); | ||
var computed = node.computed; | ||
if (t.isLiteral(node.property) && typeof node.property.value === "number") { | ||
@@ -246,2 +230,3 @@ computed = true; | ||
} | ||
if (computed) { | ||
@@ -255,2 +240,3 @@ this.token("["); | ||
} | ||
this.print(node.property, node); | ||
@@ -257,0 +243,0 @@ } |
@@ -12,2 +12,4 @@ "use strict"; | ||
exports.DeclareFunction = DeclareFunction; | ||
exports.InferredPredicate = InferredPredicate; | ||
exports.DeclaredPredicate = DeclaredPredicate; | ||
exports.DeclareInterface = DeclareInterface; | ||
@@ -69,2 +71,4 @@ exports.DeclareModule = DeclareModule; | ||
var _modules = require("./modules"); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
@@ -99,4 +103,6 @@ | ||
} | ||
this.word("class"); | ||
this.space(); | ||
this._interfaceish(node); | ||
@@ -110,2 +116,3 @@ } | ||
} | ||
this.word("function"); | ||
@@ -115,5 +122,24 @@ this.space(); | ||
this.print(node.id.typeAnnotation.typeAnnotation, node); | ||
if (node.predicate) { | ||
this.space(); | ||
this.print(node.predicate, node); | ||
} | ||
this.semicolon(); | ||
} | ||
function InferredPredicate() { | ||
this.token("%"); | ||
this.word("checks"); | ||
} | ||
function DeclaredPredicate(node) { | ||
this.token("%"); | ||
this.word("checks"); | ||
this.token("("); | ||
this.print(node.value, node); | ||
this.token(")"); | ||
} | ||
function DeclareInterface(node) { | ||
@@ -155,2 +181,3 @@ this.word("declare"); | ||
} | ||
this.word("var"); | ||
@@ -168,2 +195,3 @@ this.space(); | ||
this.space(); | ||
if (node.default) { | ||
@@ -177,13 +205,7 @@ this.word("default"); | ||
function DeclareExportAllDeclaration(node) { | ||
function DeclareExportAllDeclaration() { | ||
this.word("declare"); | ||
this.space(); | ||
this.word("export"); | ||
this.space(); | ||
this.token("*"); | ||
this.space(); | ||
this.word("from"); | ||
this.space(); | ||
this.print(node.source, node); | ||
this.semicolon(); | ||
_modules.ExportAllDeclaration.apply(this, arguments); | ||
} | ||
@@ -198,2 +220,3 @@ | ||
this.token("{"); | ||
if (node.specifiers.length) { | ||
@@ -204,2 +227,3 @@ this.space(); | ||
} | ||
this.token("}"); | ||
@@ -232,2 +256,3 @@ | ||
} | ||
this.token("..."); | ||
@@ -265,5 +290,7 @@ this.print(node.rest, node); | ||
exports.GenericTypeAnnotation = InterfaceExtends; | ||
function _interfaceish(node) { | ||
this.print(node.id, node); | ||
this.print(node.typeParameters, node); | ||
if (node.extends.length) { | ||
@@ -275,2 +302,3 @@ this.space(); | ||
} | ||
if (node.mixins && node.mixins.length) { | ||
@@ -282,2 +310,3 @@ this.space(); | ||
} | ||
this.space(); | ||
@@ -300,2 +329,3 @@ this.print(node.body, node); | ||
this.space(); | ||
this._interfaceish(node); | ||
@@ -311,3 +341,5 @@ } | ||
function IntersectionTypeAnnotation(node) { | ||
this.printJoin(node.types, node, { separator: andSeparator }); | ||
this.printJoin(node.types, node, { | ||
separator: andSeparator | ||
}); | ||
} | ||
@@ -395,2 +427,3 @@ | ||
exports.TypeParameterDeclaration = TypeParameterInstantiation; | ||
function ObjectTypeAnnotation(node) { | ||
@@ -409,3 +442,2 @@ var _this = this; | ||
this.space(); | ||
this.printJoin(props, node, { | ||
@@ -415,3 +447,2 @@ addNewlines: function addNewlines(leading) { | ||
}, | ||
indent: true, | ||
@@ -422,2 +453,3 @@ statement: true, | ||
_this.token(","); | ||
_this.space(); | ||
@@ -427,3 +459,2 @@ } | ||
}); | ||
this.space(); | ||
@@ -444,2 +475,3 @@ } | ||
} | ||
this.print(node.value, node); | ||
@@ -453,3 +485,5 @@ } | ||
} | ||
this._variance(node); | ||
this.token("["); | ||
@@ -471,3 +505,5 @@ this.print(node.id, node); | ||
} | ||
this._variance(node); | ||
this.print(node.key, node); | ||
@@ -498,3 +534,5 @@ if (node.optional) this.token("?"); | ||
function UnionTypeAnnotation(node) { | ||
this.printJoin(node.types, node, { separator: orSeparator }); | ||
this.printJoin(node.types, node, { | ||
separator: orSeparator | ||
}); | ||
} | ||
@@ -501,0 +539,0 @@ |
@@ -16,4 +16,6 @@ "use strict"; | ||
exports.JSXEmptyExpression = JSXEmptyExpression; | ||
function JSXAttribute(node) { | ||
this.print(node.name, node); | ||
if (node.value) { | ||
@@ -75,22 +77,11 @@ this.token("="); | ||
if (open.selfClosing) return; | ||
this.indent(); | ||
for (var _iterator = node.children, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
var _arr = node.children; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var child = _ref; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var child = _arr[_i]; | ||
this.print(child, node); | ||
} | ||
this.dedent(); | ||
this.print(node.closingElement, node); | ||
@@ -106,6 +97,10 @@ } | ||
this.print(node.name, node); | ||
if (node.attributes.length > 0) { | ||
this.space(); | ||
this.printJoin(node.attributes, node, { separator: spaceSeparator }); | ||
this.printJoin(node.attributes, node, { | ||
separator: spaceSeparator | ||
}); | ||
} | ||
if (node.selfClosing) { | ||
@@ -112,0 +107,0 @@ this.space(); |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports._method = _method; | ||
exports._predicate = _predicate; | ||
exports.FunctionExpression = FunctionExpression; | ||
@@ -25,2 +26,3 @@ exports.ArrowFunctionExpression = ArrowFunctionExpression; | ||
if (node.optional) _this.token("?"); | ||
_this.print(node.typeAnnotation, node); | ||
@@ -65,2 +67,3 @@ } | ||
this._params(node); | ||
this.space(); | ||
@@ -70,2 +73,13 @@ this.print(node.body, node); | ||
function _predicate(node) { | ||
if (node.predicate) { | ||
if (!node.returnType) { | ||
this.token(":"); | ||
} | ||
this.space(); | ||
this.print(node.predicate, node); | ||
} | ||
} | ||
function FunctionExpression(node) { | ||
@@ -76,2 +90,3 @@ if (node.async) { | ||
} | ||
this.word("function"); | ||
@@ -88,2 +103,5 @@ if (node.generator) this.token("*"); | ||
this._params(node); | ||
this._predicate(node); | ||
this.space(); | ||
@@ -94,2 +112,3 @@ this.print(node.body, node); | ||
exports.FunctionDeclaration = FunctionExpression; | ||
function ArrowFunctionExpression(node) { | ||
@@ -109,6 +128,7 @@ if (node.async) { | ||
this._predicate(node); | ||
this.space(); | ||
this.token("=>"); | ||
this.space(); | ||
this.print(node.body, node); | ||
@@ -115,0 +135,0 @@ } |
@@ -28,2 +28,3 @@ "use strict"; | ||
this.print(node.imported, node); | ||
if (node.local && node.local.name !== node.imported.name) { | ||
@@ -47,2 +48,3 @@ this.space(); | ||
this.print(node.local, node); | ||
if (node.exported && node.local.name !== node.exported.name) { | ||
@@ -67,2 +69,8 @@ this.space(); | ||
this.space(); | ||
if (node.exportKind === "type") { | ||
this.word("type"); | ||
this.space(); | ||
} | ||
this.token("*"); | ||
@@ -110,9 +118,11 @@ this.space(); | ||
var specifiers = node.specifiers.slice(0); | ||
var hasSpecial = false; | ||
var hasSpecial = false; | ||
while (true) { | ||
var first = specifiers[0]; | ||
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) { | ||
hasSpecial = true; | ||
this.print(specifiers.shift(), node); | ||
if (specifiers.length) { | ||
@@ -129,2 +139,3 @@ this.token(","); | ||
this.token("{"); | ||
if (specifiers.length) { | ||
@@ -135,2 +146,3 @@ this.space(); | ||
} | ||
this.token("}"); | ||
@@ -160,7 +172,10 @@ } | ||
var specifiers = node.specifiers.slice(0); | ||
if (specifiers && specifiers.length) { | ||
while (true) { | ||
var first = specifiers[0]; | ||
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) { | ||
this.print(specifiers.shift(), node); | ||
if (specifiers.length) { | ||
@@ -167,0 +182,0 @@ this.token(","); |
@@ -41,4 +41,4 @@ "use strict"; | ||
this.space(); | ||
var needsBlock = node.alternate && t.isIfStatement(getLastStatement(node.consequent)); | ||
var needsBlock = node.alternate && t.isIfStatement(getLastStatement(node.consequent)); | ||
if (needsBlock) { | ||
@@ -75,3 +75,2 @@ this.token("{"); | ||
this.token("("); | ||
this.inForStatementInitCounter++; | ||
@@ -86,2 +85,3 @@ this.print(node.init, node); | ||
} | ||
this.token(";"); | ||
@@ -111,2 +111,3 @@ | ||
this.space(); | ||
if (op === "of" && node.await) { | ||
@@ -116,2 +117,3 @@ this.word("await"); | ||
} | ||
this.token("("); | ||
@@ -146,11 +148,10 @@ this.print(node.left, node); | ||
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "label"; | ||
return function (node) { | ||
this.word(prefix); | ||
var label = node[key]; | ||
var label = node[key]; | ||
if (label) { | ||
this.space(); | ||
var terminatorState = this.startTerminatorless(); | ||
var isLabel = key == "label"; | ||
var terminatorState = this.startTerminatorless(isLabel); | ||
this.print(label, node); | ||
@@ -199,6 +200,10 @@ this.endTerminatorless(terminatorState); | ||
this.space(); | ||
this.token("("); | ||
this.print(node.param, node); | ||
this.token(")"); | ||
this.space(); | ||
if (node.param) { | ||
this.token("("); | ||
this.print(node.param, node); | ||
this.token(")"); | ||
this.space(); | ||
} | ||
this.print(node.body, node); | ||
@@ -215,3 +220,2 @@ } | ||
this.token("{"); | ||
this.printSequence(node.cases, node, { | ||
@@ -223,3 +227,2 @@ indent: true, | ||
}); | ||
this.token("}"); | ||
@@ -241,3 +244,5 @@ } | ||
this.newline(); | ||
this.printSequence(node.consequent, node, { indent: true }); | ||
this.printSequence(node.consequent, node, { | ||
indent: true | ||
}); | ||
} | ||
@@ -270,20 +275,10 @@ } | ||
this.space(); | ||
var hasInits = false; | ||
if (!t.isFor(parent)) { | ||
for (var _iterator = node.declarations, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
var _arr = node.declarations; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var declar = _arr[_i]; | ||
var declar = _ref; | ||
if (declar.init) { | ||
@@ -296,2 +291,3 @@ hasInits = true; | ||
var separator = void 0; | ||
if (hasInits) { | ||
@@ -301,3 +297,5 @@ separator = node.kind === "const" ? constDeclarationIndent : variableDeclarationIndent; | ||
this.printList(node.declarations, node, { separator: separator }); | ||
this.printList(node.declarations, node, { | ||
separator: separator | ||
}); | ||
@@ -314,2 +312,3 @@ if (t.isFor(parent)) { | ||
this.print(node.id.typeAnnotation, node); | ||
if (node.init) { | ||
@@ -316,0 +315,0 @@ this.space(); |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.TemplateLiteral = TemplateLiteral; | ||
function TaggedTemplateExpression(node) { | ||
@@ -16,5 +17,3 @@ this.print(node.tag, node); | ||
var isLast = parent.quasis[parent.quasis.length - 1] === node; | ||
var value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${"); | ||
this.token(value); | ||
@@ -21,0 +20,0 @@ } |
@@ -39,5 +39,5 @@ "use strict"; | ||
exports.SpreadElement = RestElement; | ||
function ObjectExpression(node) { | ||
var props = node.properties; | ||
this.token("{"); | ||
@@ -48,3 +48,6 @@ this.printInnerComments(node); | ||
this.space(); | ||
this.printList(props, node, { indent: true, statement: true }); | ||
this.printList(props, node, { | ||
indent: true, | ||
statement: true | ||
}); | ||
this.space(); | ||
@@ -57,4 +60,6 @@ } | ||
exports.ObjectPattern = ObjectExpression; | ||
function ObjectMethod(node) { | ||
this.printJoin(node.decorators, node); | ||
this._method(node); | ||
@@ -91,3 +96,2 @@ } | ||
var len = elems.length; | ||
this.token("["); | ||
@@ -98,2 +102,3 @@ this.printInnerComments(node); | ||
var elem = elems[i]; | ||
if (elem) { | ||
@@ -112,2 +117,3 @@ if (i > 0) this.space(); | ||
exports.ArrayPattern = ArrayExpression; | ||
function RegExpLiteral(node) { | ||
@@ -128,2 +134,3 @@ this.word("/" + node.pattern + "/" + node.flags); | ||
var value = node.value + ""; | ||
if (raw == null) { | ||
@@ -140,2 +147,3 @@ this.number(value); | ||
var raw = this.getPossibleRaw(node); | ||
if (!this.format.minified && raw != null) { | ||
@@ -150,8 +158,9 @@ this.token(raw); | ||
}; | ||
if (this.format.jsonCompatibleStrings) { | ||
opts.json = true; | ||
} | ||
var val = (0, _jsesc2.default)(node.value, opts); | ||
return this.token(val); | ||
} |
@@ -27,22 +27,16 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var Generator = function (_Printer) { | ||
_inherits(Generator, _Printer); | ||
_inheritsLoose(Generator, _Printer); | ||
function Generator(ast) { | ||
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var code = arguments[2]; | ||
_classCallCheck(this, Generator); | ||
var _this; | ||
var code = arguments[2]; | ||
var format = normalizeOptions(code, opts); | ||
var map = opts.sourceMaps ? new _sourceMap2.default(opts, code) : null; | ||
var _this = _possibleConstructorReturn(this, _Printer.call(this, format, map)); | ||
_this = _Printer.call(this, format, map) || this; | ||
_this.ast = ast; | ||
@@ -108,4 +102,2 @@ return _this; | ||
function CodeGenerator(ast, opts, code) { | ||
_classCallCheck(this, CodeGenerator); | ||
this._generator = new Generator(ast, opts, code); | ||
@@ -112,0 +104,0 @@ } |
@@ -30,3 +30,2 @@ "use strict"; | ||
var result = fn(node, parent, stack); | ||
return result == null ? func(node, parent, stack) : result; | ||
@@ -36,32 +35,22 @@ } : func; | ||
for (var _iterator = Object.keys(obj), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
var _Object$keys = Object.keys(obj); | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
for (var _i = 0; _i < _Object$keys.length; _i++) { | ||
var type = _Object$keys[_i]; | ||
var aliases = t.FLIPPED_ALIAS_KEYS[type]; | ||
var type = _ref; | ||
var aliases = t.FLIPPED_ALIAS_KEYS[type]; | ||
if (aliases) { | ||
for (var _iterator2 = aliases, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
for (var _iterator = aliases, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
if (_isArray) { | ||
if (_i2 >= _iterator.length) break; | ||
_ref = _iterator[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
_i2 = _iterator.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
_ref = _i2.value; | ||
} | ||
var alias = _ref2; | ||
var alias = _ref; | ||
add(alias, obj[type]); | ||
@@ -109,2 +98,3 @@ } | ||
var items = find(expandedWhitespaceList, node, parent); | ||
if (items) { | ||
@@ -111,0 +101,0 @@ for (var i = 0; i < items.length; i++) { |
@@ -58,2 +58,3 @@ "use strict"; | ||
exports.FunctionTypeAnnotation = NullableTypeAnnotation; | ||
function UpdateExpression(node, parent) { | ||
@@ -64,3 +65,5 @@ return t.isMemberExpression(parent) && parent.object === node; | ||
function ObjectExpression(node, parent, printStack) { | ||
return isFirstInStatement(printStack, { considerArrow: true }); | ||
return isFirstInStatement(printStack, { | ||
considerArrow: true | ||
}); | ||
} | ||
@@ -73,3 +76,5 @@ | ||
function Binary(node, parent) { | ||
if (node.operator === "**" && t.isBinaryExpression(parent, { operator: "**" })) { | ||
if (node.operator === "**" && t.isBinaryExpression(parent, { | ||
operator: "**" | ||
})) { | ||
return parent.left === node; | ||
@@ -85,3 +90,2 @@ } | ||
var parentPos = PRECEDENCE[parentOp]; | ||
var nodeOp = node.operator; | ||
@@ -115,12 +119,26 @@ var nodePos = PRECEDENCE[nodeOp]; | ||
exports.AwaitExpression = YieldExpression; | ||
function ClassExpression(node, parent, printStack) { | ||
return isFirstInStatement(printStack, { considerDefaultExports: true }); | ||
return isFirstInStatement(printStack, { | ||
considerDefaultExports: true | ||
}); | ||
} | ||
function UnaryLike(node, parent) { | ||
return t.isMemberExpression(parent, { object: node }) || t.isCallExpression(parent, { callee: node }) || t.isNewExpression(parent, { callee: node }) || t.isBinaryExpression(parent, { operator: "**", left: node }); | ||
return t.isMemberExpression(parent, { | ||
object: node | ||
}) || t.isCallExpression(parent, { | ||
callee: node | ||
}) || t.isNewExpression(parent, { | ||
callee: node | ||
}) || t.isBinaryExpression(parent, { | ||
operator: "**", | ||
left: node | ||
}); | ||
} | ||
function FunctionExpression(node, parent, printStack) { | ||
return isFirstInStatement(printStack, { considerDefaultExports: true }); | ||
return isFirstInStatement(printStack, { | ||
considerDefaultExports: true | ||
}); | ||
} | ||
@@ -133,3 +151,5 @@ | ||
function ConditionalExpression(node, parent) { | ||
if (t.isUnaryLike(parent) || t.isBinary(parent) || t.isConditionalExpression(parent, { test: node }) || t.isAwaitExpression(parent) || t.isTaggedTemplateExpression(parent)) { | ||
if (t.isUnaryLike(parent) || t.isBinary(parent) || t.isConditionalExpression(parent, { | ||
test: node | ||
}) || t.isAwaitExpression(parent) || t.isTaggedTemplateExpression(parent)) { | ||
return true; | ||
@@ -160,8 +180,25 @@ } | ||
var parent = printStack[i]; | ||
while (i > 0) { | ||
if (t.isExpressionStatement(parent, { expression: node }) || t.isTaggedTemplateExpression(parent) || considerDefaultExports && t.isExportDefaultDeclaration(parent, { declaration: node }) || considerArrow && t.isArrowFunctionExpression(parent, { body: node })) { | ||
if (t.isExpressionStatement(parent, { | ||
expression: node | ||
}) || t.isTaggedTemplateExpression(parent) || considerDefaultExports && t.isExportDefaultDeclaration(parent, { | ||
declaration: node | ||
}) || considerArrow && t.isArrowFunctionExpression(parent, { | ||
body: node | ||
})) { | ||
return true; | ||
} | ||
if (t.isCallExpression(parent, { callee: node }) || t.isSequenceExpression(parent) && parent.expressions[0] === node || t.isMemberExpression(parent, { object: node }) || t.isConditional(parent, { test: node }) || t.isBinary(parent, { left: node }) || t.isAssignmentExpression(parent, { left: node })) { | ||
if (t.isCallExpression(parent, { | ||
callee: node | ||
}) || t.isSequenceExpression(parent) && parent.expressions[0] === node || t.isMemberExpression(parent, { | ||
object: node | ||
}) || t.isConditional(parent, { | ||
test: node | ||
}) || t.isBinary(parent, { | ||
left: node | ||
}) || t.isAssignmentExpression(parent, { | ||
left: node | ||
})) { | ||
node = parent; | ||
@@ -168,0 +205,0 @@ i--; |
@@ -60,2 +60,3 @@ "use strict"; | ||
var state = crawl(node.right); | ||
if (state.hasCall && state.hasHelper || state.hasFunction) { | ||
@@ -99,4 +100,4 @@ return { | ||
var declar = node.declarations[i]; | ||
var enabled = isHelper(declar.id) && !isType(declar.init); | ||
var enabled = isHelper(declar.id) && !isType(declar.init); | ||
if (!enabled) { | ||
@@ -160,3 +161,2 @@ var state = crawl(declar.init); | ||
}; | ||
[["Function", true], ["Class", true], ["Loop", true], ["LabeledStatement", true], ["SwitchStatement", true], ["TryStatement", true]].forEach(function (_ref) { | ||
@@ -167,4 +167,8 @@ var type = _ref[0], | ||
if (typeof amounts === "boolean") { | ||
amounts = { after: amounts, before: amounts }; | ||
amounts = { | ||
after: amounts, | ||
before: amounts | ||
}; | ||
} | ||
[type].concat(t.FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) { | ||
@@ -171,0 +175,0 @@ nodes[type] = function () { |
@@ -34,4 +34,2 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var SCIENTIFIC_NOTATION = /e/i; | ||
@@ -43,4 +41,2 @@ var ZERO_DECIMAL_INTEGER = /\.0+$/; | ||
function Printer(format, map) { | ||
_classCallCheck(this, Printer); | ||
this.inForStatementInitCounter = 0; | ||
@@ -52,2 +48,3 @@ this._printStack = []; | ||
this._parenPushNewlineState = null; | ||
this._noLineTerminator = false; | ||
this._printAuxAfterOnNextUserNode = false; | ||
@@ -57,3 +54,2 @@ this._printedComments = new WeakSet(); | ||
this._endsWithWord = false; | ||
this.format = format || {}; | ||
@@ -65,2 +61,3 @@ this._buf = new _buffer2.default(map); | ||
this.print(ast); | ||
this._maybeAddAuxComment(); | ||
@@ -73,3 +70,2 @@ | ||
if (this.format.compact || this.format.concise) return; | ||
this._indent++; | ||
@@ -80,3 +76,2 @@ }; | ||
if (this.format.compact || this.format.concise) return; | ||
this._indent--; | ||
@@ -89,2 +84,3 @@ }; | ||
this._maybeAddAuxComment(); | ||
this._append(";", !force); | ||
@@ -97,2 +93,3 @@ }; | ||
} | ||
this.token("}"); | ||
@@ -103,3 +100,2 @@ }; | ||
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
if (this.format.compact) return; | ||
@@ -116,2 +112,3 @@ | ||
this._maybeAddAuxComment(); | ||
this._append(str); | ||
@@ -124,3 +121,2 @@ | ||
this.word(str); | ||
this._endsWithInteger = (0, _isInteger2.default)(+str) && !NON_DECIMAL_LITERAL.test(str) && !SCIENTIFIC_NOTATION.test(str) && !ZERO_DECIMAL_INTEGER.test(str) && str[str.length - 1] !== "."; | ||
@@ -135,2 +131,3 @@ }; | ||
this._maybeAddAuxComment(); | ||
this._append(str); | ||
@@ -148,5 +145,3 @@ }; | ||
if (this.endsWith("\n\n")) return; | ||
if (typeof i !== "number") i = 1; | ||
i = Math.min(2, i); | ||
@@ -193,6 +188,6 @@ if (this.endsWith("{\n") || this.endsWith(":\n")) i--; | ||
this._maybeAddParen(str); | ||
this._maybeIndent(str); | ||
if (queue) this._buf.queue(str);else this._buf.append(str); | ||
this._endsWithWord = false; | ||
@@ -212,9 +207,11 @@ this._endsWithInteger = false; | ||
this._parenPushNewlineState = null; | ||
var i = void 0; | ||
var i = void 0; | ||
for (i = 0; i < str.length && str[i] === " "; i++) { | ||
continue; | ||
}if (i === str.length) return; | ||
} | ||
if (i === str.length) return; | ||
var cha = str[i]; | ||
if (cha === "\n" || cha === "/") { | ||
@@ -229,4 +226,4 @@ this.token("("); | ||
if (!this.format.retainLines) return; | ||
var pos = loc ? loc[prop] : null; | ||
var pos = loc ? loc[prop] : null; | ||
if (pos && pos.line !== null) { | ||
@@ -246,9 +243,18 @@ var count = pos.line - this._buf.getCurrentLine(); | ||
Printer.prototype.startTerminatorless = function startTerminatorless() { | ||
return this._parenPushNewlineState = { | ||
printed: false | ||
}; | ||
var isLabel = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
if (isLabel) { | ||
this._noLineTerminator = true; | ||
return null; | ||
} else { | ||
return this._parenPushNewlineState = { | ||
printed: false | ||
}; | ||
} | ||
}; | ||
Printer.prototype.endTerminatorless = function endTerminatorless(state) { | ||
if (state.printed) { | ||
this._noLineTerminator = false; | ||
if (state && state.printed) { | ||
this.dedent(); | ||
@@ -264,4 +270,4 @@ this.newline(); | ||
if (!node) return; | ||
var oldConcise = this.format.concise; | ||
var oldConcise = this.format.concise; | ||
if (node._compact) { | ||
@@ -272,2 +278,3 @@ this.format.concise = true; | ||
var printMethod = this[node.type]; | ||
if (!printMethod) { | ||
@@ -281,8 +288,11 @@ throw new ReferenceError("unknown node of type " + JSON.stringify(node.type) + " with constructor " + JSON.stringify(node && node.constructor.name)); | ||
this._insideAux = !node.loc; | ||
this._maybeAddAuxComment(this._insideAux && !oldInAux); | ||
var needsParens = n.needsParens(node, parent, this._printStack); | ||
if (this.format.retainFunctionParens && node.type === "FunctionExpression" && node.extra && node.extra.parenthesized) { | ||
needsParens = true; | ||
} | ||
if (needsParens) this.token("("); | ||
@@ -315,4 +325,4 @@ | ||
this._printAuxAfterOnNextUserNode = true; | ||
var comment = this.format.auxiliaryCommentBefore; | ||
var comment = this.format.auxiliaryCommentBefore; | ||
if (comment) { | ||
@@ -329,4 +339,4 @@ this._printComment({ | ||
this._printAuxAfterOnNextUserNode = false; | ||
var comment = this.format.auxiliaryCommentAfter; | ||
var comment = this.format.auxiliaryCommentAfter; | ||
if (comment) { | ||
@@ -342,2 +352,3 @@ this._printComment({ | ||
var extra = node.extra; | ||
if (extra && extra.raw != null && extra.rawValue != null && node.value === extra.rawValue) { | ||
@@ -350,7 +361,4 @@ return extra.raw; | ||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
if (!nodes || !nodes.length) return; | ||
if (opts.indent) this.indent(); | ||
var newlineOpts = { | ||
@@ -363,5 +371,3 @@ addNewlines: opts.addNewlines | ||
if (!node) continue; | ||
if (opts.statement) this._printNewline(true, node, parent, newlineOpts); | ||
this.print(node, parent); | ||
@@ -410,6 +416,7 @@ | ||
var indent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
if (!node.innerComments) return; | ||
if (indent) this.indent(); | ||
this._printComments(node.innerComments); | ||
if (indent) this.dedent(); | ||
@@ -420,3 +427,2 @@ }; | ||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
opts.statement = true; | ||
@@ -449,3 +455,2 @@ return this.printJoin(nodes, parent, opts); | ||
if (opts.addNewlines) lines += opts.addNewlines(leading, node) || 0; | ||
var needs = leading ? n.needsWhitespaceBefore : n.needsWhitespaceAfter; | ||
@@ -466,6 +471,5 @@ if (needs(node, parent)) lines++; | ||
if (!this.format.shouldPrintComment(comment.value)) return; | ||
if (comment.ignore) return; | ||
if (this._printedComments.has(comment)) return; | ||
if (this._printedComments.has(comment)) return; | ||
this._printedComments.add(comment); | ||
@@ -479,11 +483,9 @@ | ||
var isBlockComment = comment.type === "CommentBlock"; | ||
this.newline(this._buf.hasContent() && isBlockComment ? 1 : 0); | ||
this.newline(this._buf.hasContent() && !this._noLineTerminator && isBlockComment ? 1 : 0); | ||
if (!this.endsWith("[") && !this.endsWith("{")) this.space(); | ||
var val = !isBlockComment && !this._noLineTerminator ? "//" + comment.value + "\n" : "/*" + comment.value + "*/"; | ||
var val = !isBlockComment ? "//" + comment.value + "\n" : "/*" + comment.value + "*/"; | ||
if (isBlockComment && this.format.indent.adjustMultilineComment) { | ||
var offset = comment.loc && comment.loc.start.column; | ||
if (offset) { | ||
@@ -499,8 +501,6 @@ var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g"); | ||
if (this.endsWith("/")) this._space(); | ||
this.withSource("start", comment.loc, function () { | ||
_this2._append(val); | ||
}); | ||
this.newline(isBlockComment ? 1 : 0); | ||
this.newline(isBlockComment && !this._noLineTerminator ? 1 : 0); | ||
}; | ||
@@ -533,3 +533,2 @@ | ||
exports.default = Printer; | ||
Object.assign(Printer.prototype, generatorFunctions); | ||
@@ -536,0 +535,0 @@ |
@@ -14,8 +14,4 @@ "use strict"; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var SourceMap = function () { | ||
function SourceMap(opts, code) { | ||
_classCallCheck(this, SourceMap); | ||
this._cachedMap = null; | ||
@@ -33,4 +29,4 @@ this._code = code; | ||
}); | ||
var code = this._code; | ||
var code = this._code; | ||
if (typeof code === "string") { | ||
@@ -37,0 +33,0 @@ map.setSourceContent(this._opts.sourceFileName, code); |
{ | ||
"name": "babel-generator", | ||
"version": "7.0.0-alpha.15", | ||
"version": "7.0.0-alpha.16", | ||
"description": "Turns an AST into code.", | ||
@@ -14,5 +14,5 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"dependencies": { | ||
"babel-messages": "7.0.0-alpha.15", | ||
"babel-types": "7.0.0-alpha.15", | ||
"jsesc": "^1.3.0", | ||
"babel-messages": "7.0.0-alpha.16", | ||
"babel-types": "7.0.0-alpha.16", | ||
"jsesc": "^2.5.1", | ||
"lodash": "^4.2.0", | ||
@@ -23,5 +23,5 @@ "source-map": "^0.5.0", | ||
"devDependencies": { | ||
"babel-helper-fixtures": "7.0.0-alpha.15", | ||
"babylon": "^7.0.0-beta.15" | ||
"babel-helper-fixtures": "7.0.0-alpha.16", | ||
"babylon": "^7.0.0-beta.17" | ||
} | ||
} |
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
2710
89333
+ Addedbabel-messages@7.0.0-alpha.16(transitive)
+ Addedbabel-types@7.0.0-alpha.16(transitive)
+ Addedjsesc@2.5.2(transitive)
+ Addedto-fast-properties@2.0.0(transitive)
- Removedbabel-messages@7.0.0-alpha.15(transitive)
- Removedbabel-types@7.0.0-alpha.15(transitive)
- Removedjsesc@1.3.0(transitive)
- Removedto-fast-properties@1.0.3(transitive)
Updatedbabel-types@7.0.0-alpha.16
Updatedjsesc@^2.5.1