@babel/generator
Advanced tools
Comparing version 7.0.0-beta.42 to 7.0.0-beta.43
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _trimRight = _interopRequireDefault(require("trim-right")); | ||
function _trimRight() { | ||
const data = _interopRequireDefault(require("trim-right")); | ||
_trimRight = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var SPACES_RE = /^[ \t]+$/; | ||
const SPACES_RE = /^[ \t]+$/; | ||
var Buffer = function () { | ||
function Buffer(map) { | ||
class Buffer { | ||
constructor(map) { | ||
this._map = null; | ||
@@ -31,10 +41,8 @@ this._buf = []; | ||
var _proto = Buffer.prototype; | ||
_proto.get = function get() { | ||
get() { | ||
this._flush(); | ||
var map = this._map; | ||
var result = { | ||
code: (0, _trimRight.default)(this._buf.join("")), | ||
const map = this._map; | ||
const result = { | ||
code: (0, _trimRight().default)(this._buf.join("")), | ||
map: null, | ||
@@ -48,11 +56,14 @@ rawMappings: map && map.getRawMappings() | ||
enumerable: true, | ||
get: function get() { | ||
get() { | ||
return this.map = map.get(); | ||
}, | ||
set: function set(value) { | ||
set(value) { | ||
Object.defineProperty(this, "map", { | ||
value: value, | ||
value, | ||
writable: true | ||
}); | ||
} | ||
}); | ||
@@ -62,17 +73,18 @@ } | ||
return result; | ||
}; | ||
} | ||
_proto.append = function append(str) { | ||
append(str) { | ||
this._flush(); | ||
var _sourcePosition = this._sourcePosition, | ||
line = _sourcePosition.line, | ||
column = _sourcePosition.column, | ||
filename = _sourcePosition.filename, | ||
identifierName = _sourcePosition.identifierName; | ||
const { | ||
line, | ||
column, | ||
filename, | ||
identifierName | ||
} = this._sourcePosition; | ||
this._append(str, line, column, identifierName, filename); | ||
}; | ||
} | ||
_proto.queue = function queue(str) { | ||
queue(str) { | ||
if (str === "\n") { | ||
@@ -84,20 +96,19 @@ while (this._queue.length > 0 && SPACES_RE.test(this._queue[0][0])) { | ||
var _sourcePosition2 = this._sourcePosition, | ||
line = _sourcePosition2.line, | ||
column = _sourcePosition2.column, | ||
filename = _sourcePosition2.filename, | ||
identifierName = _sourcePosition2.identifierName; | ||
const { | ||
line, | ||
column, | ||
filename, | ||
identifierName | ||
} = this._sourcePosition; | ||
this._queue.unshift([str, line, column, identifierName, filename]); | ||
}; | ||
} | ||
_proto._flush = function _flush() { | ||
var item; | ||
_flush() { | ||
let item; | ||
while (item = this._queue.pop()) { | ||
this._append.apply(this, item); | ||
} | ||
}; | ||
while (item = this._queue.pop()) this._append(...item); | ||
} | ||
_proto._append = function _append(str, line, column, identifierName, filename) { | ||
_append(str, line, column, identifierName, filename) { | ||
if (this._map && str[0] !== "\n") { | ||
@@ -111,3 +122,3 @@ this._map.mark(this._position.line, this._position.column, line, column, identifierName, filename); | ||
for (var i = 0; i < str.length; i++) { | ||
for (let i = 0; i < str.length; i++) { | ||
if (str[i] === "\n") { | ||
@@ -120,22 +131,22 @@ this._position.line++; | ||
} | ||
}; | ||
} | ||
_proto.removeTrailingNewline = function removeTrailingNewline() { | ||
removeTrailingNewline() { | ||
if (this._queue.length > 0 && this._queue[0][0] === "\n") { | ||
this._queue.shift(); | ||
} | ||
}; | ||
} | ||
_proto.removeLastSemicolon = function removeLastSemicolon() { | ||
removeLastSemicolon() { | ||
if (this._queue.length > 0 && this._queue[0][0] === ";") { | ||
this._queue.shift(); | ||
} | ||
}; | ||
} | ||
_proto.endsWith = function endsWith(suffix) { | ||
endsWith(suffix) { | ||
if (suffix.length === 1) { | ||
var last; | ||
let last; | ||
if (this._queue.length > 0) { | ||
var str = this._queue[0][0]; | ||
const str = this._queue[0][0]; | ||
last = str[str.length - 1]; | ||
@@ -149,5 +160,3 @@ } else { | ||
var end = this._last + this._queue.reduce(function (acc, item) { | ||
return item[0] + acc; | ||
}, ""); | ||
const end = this._last + this._queue.reduce((acc, item) => item[0] + acc, ""); | ||
@@ -159,11 +168,11 @@ if (suffix.length <= end.length) { | ||
return false; | ||
}; | ||
} | ||
_proto.hasContent = function hasContent() { | ||
hasContent() { | ||
return this._queue.length > 0 || !!this._last; | ||
}; | ||
} | ||
_proto.source = function source(prop, loc) { | ||
source(prop, loc) { | ||
if (prop && !loc) return; | ||
var pos = loc ? loc[prop] : null; | ||
const pos = loc ? loc[prop] : null; | ||
this._sourcePosition.identifierName = loc && loc.identifierName || null; | ||
@@ -173,10 +182,10 @@ this._sourcePosition.line = pos ? pos.line : null; | ||
this._sourcePosition.filename = loc && loc.filename || null; | ||
}; | ||
} | ||
_proto.withSource = function withSource(prop, loc, cb) { | ||
withSource(prop, loc, cb) { | ||
if (!this._map) return cb(); | ||
var originalLine = this._sourcePosition.line; | ||
var originalColumn = this._sourcePosition.column; | ||
var originalFilename = this._sourcePosition.filename; | ||
var originalIdentifierName = this._sourcePosition.identifierName; | ||
const originalLine = this._sourcePosition.line; | ||
const originalColumn = this._sourcePosition.column; | ||
const originalFilename = this._sourcePosition.filename; | ||
const originalIdentifierName = this._sourcePosition.identifierName; | ||
this.source(prop, loc); | ||
@@ -188,21 +197,17 @@ cb(); | ||
this._sourcePosition.identifierName = originalIdentifierName; | ||
}; | ||
} | ||
_proto.getCurrentColumn = function getCurrentColumn() { | ||
var extra = this._queue.reduce(function (acc, item) { | ||
return item[0] + acc; | ||
}, ""); | ||
getCurrentColumn() { | ||
const extra = this._queue.reduce((acc, item) => item[0] + acc, ""); | ||
var lastIndex = extra.lastIndexOf("\n"); | ||
const lastIndex = extra.lastIndexOf("\n"); | ||
return lastIndex === -1 ? this._position.column + extra.length : extra.length - 1 - lastIndex; | ||
}; | ||
} | ||
_proto.getCurrentLine = function getCurrentLine() { | ||
var extra = this._queue.reduce(function (acc, item) { | ||
return item[0] + acc; | ||
}, ""); | ||
getCurrentLine() { | ||
const extra = this._queue.reduce((acc, item) => item[0] + acc, ""); | ||
var count = 0; | ||
let count = 0; | ||
for (var i = 0; i < extra.length; i++) { | ||
for (let i = 0; i < extra.length; i++) { | ||
if (extra[i] === "\n") count++; | ||
@@ -212,7 +217,6 @@ } | ||
return this._position.line + count; | ||
}; | ||
} | ||
return Buffer; | ||
}(); | ||
} | ||
exports.default = Buffer; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.File = File; | ||
@@ -9,8 +11,11 @@ exports.Program = Program; | ||
exports.Directive = Directive; | ||
exports.DirectiveLiteral = void 0; | ||
Object.defineProperty(exports, "DirectiveLiteral", { | ||
enumerable: true, | ||
get: function () { | ||
return _types.StringLiteral; | ||
} | ||
}); | ||
var _types = require("./types"); | ||
exports.DirectiveLiteral = _types.StringLiteral; | ||
function File(node) { | ||
@@ -30,3 +35,3 @@ this.print(node.program, node); | ||
this.printInnerComments(node); | ||
var hasDirectives = node.directives && node.directives.length; | ||
const hasDirectives = node.directives && node.directives.length; | ||
@@ -33,0 +38,0 @@ if (node.body.length || hasDirectives) { |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.ClassExpression = exports.ClassDeclaration = ClassDeclaration; | ||
@@ -10,8 +12,16 @@ exports.ClassBody = ClassBody; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
function ClassDeclaration(node, parent) { | ||
if (!t.isExportDefaultDeclaration(parent) && !t.isExportNamedDeclaration(parent)) { | ||
if (!t().isExportDefaultDeclaration(parent) && !t().isExportNamedDeclaration(parent)) { | ||
this.printJoin(node.decorators, node); | ||
@@ -18,0 +28,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.UnaryExpression = UnaryExpression; | ||
@@ -27,4 +29,12 @@ exports.DoExpression = DoExpression; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var n = _interopRequireWildcard(require("../node")); | ||
@@ -86,5 +96,5 @@ | ||
if (this.format.minified && node.arguments.length === 0 && !node.optional && !t.isCallExpression(parent, { | ||
if (this.format.minified && node.arguments.length === 0 && !node.optional && !t().isCallExpression(parent, { | ||
callee: node | ||
}) && !t.isMemberExpression(parent) && !t.isNewExpression(parent)) { | ||
}) && !t().isMemberExpression(parent) && !t().isNewExpression(parent)) { | ||
return; | ||
@@ -125,9 +135,9 @@ } | ||
if (!node.computed && t.isMemberExpression(node.property)) { | ||
if (!node.computed && t().isMemberExpression(node.property)) { | ||
throw new TypeError("Got a MemberExpression for MemberExpression property"); | ||
} | ||
var computed = node.computed; | ||
let computed = node.computed; | ||
if (t.isLiteral(node.property) && typeof node.property.value === "number") { | ||
if (t().isLiteral(node.property) && typeof node.property.value === "number") { | ||
computed = true; | ||
@@ -188,3 +198,3 @@ } | ||
this.space(); | ||
var terminatorState = this.startTerminatorless(); | ||
const terminatorState = this.startTerminatorless(); | ||
this.print(node.argument, node); | ||
@@ -196,5 +206,5 @@ this.endTerminatorless(terminatorState); | ||
var YieldExpression = buildYieldAwait("yield"); | ||
const YieldExpression = buildYieldAwait("yield"); | ||
exports.YieldExpression = YieldExpression; | ||
var AwaitExpression = buildYieldAwait("await"); | ||
const AwaitExpression = buildYieldAwait("await"); | ||
exports.AwaitExpression = AwaitExpression; | ||
@@ -222,3 +232,3 @@ | ||
function AssignmentExpression(node, parent) { | ||
var parens = this.inForStatementInitCounter && node.operator === "in" && !n.needsParens(node, parent); | ||
const parens = this.inForStatementInitCounter && node.operator === "in" && !n.needsParens(node, parent); | ||
@@ -255,9 +265,9 @@ if (parens) { | ||
if (!node.computed && t.isMemberExpression(node.property)) { | ||
if (!node.computed && t().isMemberExpression(node.property)) { | ||
throw new TypeError("Got a MemberExpression for MemberExpression property"); | ||
} | ||
var computed = node.computed; | ||
let computed = node.computed; | ||
if (t.isLiteral(node.property) && typeof node.property.value === "number") { | ||
if (t().isLiteral(node.property) && typeof node.property.value === "number") { | ||
computed = true; | ||
@@ -264,0 +274,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.AnyTypeAnnotation = AnyTypeAnnotation; | ||
@@ -52,6 +54,25 @@ exports.ArrayTypeAnnotation = ArrayTypeAnnotation; | ||
exports.VoidTypeAnnotation = VoidTypeAnnotation; | ||
exports.StringLiteralTypeAnnotation = exports.NumberLiteralTypeAnnotation = void 0; | ||
Object.defineProperty(exports, "NumberLiteralTypeAnnotation", { | ||
enumerable: true, | ||
get: function () { | ||
return _types2.NumericLiteral; | ||
} | ||
}); | ||
Object.defineProperty(exports, "StringLiteralTypeAnnotation", { | ||
enumerable: true, | ||
get: function () { | ||
return _types2.StringLiteral; | ||
} | ||
}); | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _modules = require("./modules"); | ||
@@ -61,5 +82,2 @@ | ||
exports.NumberLiteralTypeAnnotation = _types2.NumericLiteral; | ||
exports.StringLiteralTypeAnnotation = _types2.StringLiteral; | ||
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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
@@ -90,3 +108,3 @@ | ||
function DeclareClass(node, parent) { | ||
if (!t.isDeclareExportDeclaration(parent)) { | ||
if (!t().isDeclareExportDeclaration(parent)) { | ||
this.word("declare"); | ||
@@ -103,3 +121,3 @@ this.space(); | ||
function DeclareFunction(node, parent) { | ||
if (!t.isDeclareExportDeclaration(parent)) { | ||
if (!t().isDeclareExportDeclaration(parent)) { | ||
this.word("declare"); | ||
@@ -167,3 +185,3 @@ this.space(); | ||
function DeclareOpaqueType(node, parent) { | ||
if (!t.isDeclareExportDeclaration(parent)) { | ||
if (!t().isDeclareExportDeclaration(parent)) { | ||
this.word("declare"); | ||
@@ -177,3 +195,3 @@ this.space(); | ||
function DeclareVariable(node, parent) { | ||
if (!t.isDeclareExportDeclaration(parent)) { | ||
if (!t().isDeclareExportDeclaration(parent)) { | ||
this.word("declare"); | ||
@@ -213,5 +231,5 @@ this.space(); | ||
if (node.declaration) { | ||
var declar = node.declaration; | ||
const declar = node.declaration; | ||
this.print(declar, node); | ||
if (!t.isStatement(declar)) this.semicolon(); | ||
if (!t().isStatement(declar)) this.semicolon(); | ||
} else { | ||
@@ -439,4 +457,2 @@ this.token("{"); | ||
function ObjectTypeAnnotation(node) { | ||
var _this = this; | ||
if (node.exact) { | ||
@@ -448,3 +464,3 @@ this.token("{|"); | ||
var props = node.properties.concat(node.callProperties || [], node.indexers || []); | ||
const props = node.properties.concat(node.callProperties || [], node.indexers || []); | ||
@@ -454,12 +470,12 @@ if (props.length) { | ||
this.printJoin(props, node, { | ||
addNewlines: function addNewlines(leading) { | ||
addNewlines(leading) { | ||
if (leading && !props[0]) return 1; | ||
}, | ||
indent: true, | ||
statement: true, | ||
iterator: function iterator() { | ||
iterator: () => { | ||
if (props.length !== 1) { | ||
_this.token(","); | ||
_this.space(); | ||
this.token(","); | ||
this.space(); | ||
} | ||
@@ -466,0 +482,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
@@ -9,3 +11,8 @@ var _templateLiterals = require("./template-literals"); | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _templateLiterals[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _templateLiterals[key]; | ||
} | ||
}); | ||
}); | ||
@@ -17,3 +24,8 @@ | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _expressions[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _expressions[key]; | ||
} | ||
}); | ||
}); | ||
@@ -25,3 +37,8 @@ | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _statements[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _statements[key]; | ||
} | ||
}); | ||
}); | ||
@@ -33,3 +50,8 @@ | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _classes[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _classes[key]; | ||
} | ||
}); | ||
}); | ||
@@ -41,3 +63,8 @@ | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _methods[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _methods[key]; | ||
} | ||
}); | ||
}); | ||
@@ -49,3 +76,8 @@ | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _modules[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _modules[key]; | ||
} | ||
}); | ||
}); | ||
@@ -57,3 +89,8 @@ | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _types[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _types[key]; | ||
} | ||
}); | ||
}); | ||
@@ -65,3 +102,8 @@ | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _flow[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _flow[key]; | ||
} | ||
}); | ||
}); | ||
@@ -73,3 +115,8 @@ | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _base[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _base[key]; | ||
} | ||
}); | ||
}); | ||
@@ -81,3 +128,8 @@ | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _jsx[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _jsx[key]; | ||
} | ||
}); | ||
}); | ||
@@ -89,3 +141,8 @@ | ||
if (key === "default" || key === "__esModule") return; | ||
exports[key] = _typescript[key]; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _typescript[key]; | ||
} | ||
}); | ||
}); |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.JSXAttribute = JSXAttribute; | ||
@@ -66,3 +68,3 @@ exports.JSXIdentifier = JSXIdentifier; | ||
function JSXText(node) { | ||
var raw = this.getPossibleRaw(node); | ||
const raw = this.getPossibleRaw(node); | ||
@@ -77,10 +79,8 @@ if (raw != null) { | ||
function JSXElement(node) { | ||
var open = node.openingElement; | ||
const open = node.openingElement; | ||
this.print(open, node); | ||
if (open.selfClosing) return; | ||
this.indent(); | ||
var _arr = node.children; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var child = _arr[_i]; | ||
for (const child of node.children) { | ||
this.print(child, node); | ||
@@ -129,6 +129,4 @@ } | ||
this.indent(); | ||
var _arr2 = node.children; | ||
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | ||
var child = _arr2[_i2]; | ||
for (const child of node.children) { | ||
this.print(child, node); | ||
@@ -135,0 +133,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports._params = _params; | ||
@@ -13,4 +15,12 @@ exports._parameters = _parameters; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
@@ -29,3 +39,3 @@ | ||
function _parameters(parameters, parent) { | ||
for (var i = 0; i < parameters.length; i++) { | ||
for (let i = 0; i < parameters.length; i++) { | ||
this._param(parameters[i], parent); | ||
@@ -48,4 +58,4 @@ | ||
function _methodHead(node) { | ||
var kind = node.kind; | ||
var key = node.key; | ||
const kind = node.kind; | ||
const key = node.key; | ||
@@ -126,5 +136,5 @@ if (kind === "get" || kind === "set") { | ||
var firstParam = node.params[0]; | ||
const firstParam = node.params[0]; | ||
if (node.params.length === 1 && t.isIdentifier(firstParam) && !hasTypes(node, firstParam)) { | ||
if (node.params.length === 1 && t().isIdentifier(firstParam) && !hasTypes(node, firstParam)) { | ||
this.print(firstParam, node); | ||
@@ -131,0 +141,0 @@ } else { |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.ImportSpecifier = ImportSpecifier; | ||
@@ -15,4 +17,12 @@ exports.ImportDefaultSpecifier = ImportDefaultSpecifier; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
@@ -81,3 +91,3 @@ | ||
function ExportNamedDeclaration(node) { | ||
if (t.isClassDeclaration(node.declaration)) { | ||
if (t().isClassDeclaration(node.declaration)) { | ||
this.printJoin(node.declaration.decorators, node); | ||
@@ -92,3 +102,3 @@ } | ||
function ExportDefaultDeclaration(node) { | ||
if (t.isClassDeclaration(node.declaration)) { | ||
if (t().isClassDeclaration(node.declaration)) { | ||
this.printJoin(node.declaration.decorators, node); | ||
@@ -106,5 +116,5 @@ } | ||
if (node.declaration) { | ||
var declar = node.declaration; | ||
const declar = node.declaration; | ||
this.print(declar, node); | ||
if (!t.isStatement(declar)) this.semicolon(); | ||
if (!t().isStatement(declar)) this.semicolon(); | ||
} else { | ||
@@ -116,9 +126,9 @@ if (node.exportKind === "type") { | ||
var specifiers = node.specifiers.slice(0); | ||
var hasSpecial = false; | ||
const specifiers = node.specifiers.slice(0); | ||
let hasSpecial = false; | ||
while (true) { | ||
var first = specifiers[0]; | ||
const first = specifiers[0]; | ||
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) { | ||
if (t().isExportDefaultSpecifier(first) || t().isExportNamespaceSpecifier(first)) { | ||
hasSpecial = true; | ||
@@ -168,9 +178,9 @@ this.print(specifiers.shift(), node); | ||
var specifiers = node.specifiers.slice(0); | ||
const specifiers = node.specifiers.slice(0); | ||
if (specifiers && specifiers.length) { | ||
while (true) { | ||
var first = specifiers[0]; | ||
const first = specifiers[0]; | ||
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) { | ||
if (t().isImportDefaultSpecifier(first) || t().isImportNamespaceSpecifier(first)) { | ||
this.print(specifiers.shift(), node); | ||
@@ -177,0 +187,0 @@ |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.WithStatement = WithStatement; | ||
@@ -19,4 +21,12 @@ exports.IfStatement = IfStatement; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
@@ -40,3 +50,3 @@ | ||
this.space(); | ||
var needsBlock = node.alternate && t.isIfStatement(getLastStatement(node.consequent)); | ||
const needsBlock = node.alternate && t().isIfStatement(getLastStatement(node.consequent)); | ||
@@ -66,3 +76,3 @@ if (needsBlock) { | ||
function getLastStatement(statement) { | ||
if (!t.isStatement(statement.body)) return statement; | ||
if (!t().isStatement(statement.body)) return statement; | ||
return getLastStatement(statement.body); | ||
@@ -105,3 +115,3 @@ } | ||
var buildForXStatement = function buildForXStatement(op) { | ||
const buildForXStatement = function (op) { | ||
return function (node) { | ||
@@ -127,5 +137,5 @@ this.word("for"); | ||
var ForInStatement = buildForXStatement("in"); | ||
const ForInStatement = buildForXStatement("in"); | ||
exports.ForInStatement = ForInStatement; | ||
var ForOfStatement = buildForXStatement("of"); | ||
const ForOfStatement = buildForXStatement("of"); | ||
exports.ForOfStatement = ForOfStatement; | ||
@@ -146,15 +156,11 @@ | ||
function buildLabelStatement(prefix, key) { | ||
if (key === void 0) { | ||
key = "label"; | ||
} | ||
function buildLabelStatement(prefix, key = "label") { | ||
return function (node) { | ||
this.word(prefix); | ||
var label = node[key]; | ||
const label = node[key]; | ||
if (label) { | ||
this.space(); | ||
var isLabel = key == "label"; | ||
var terminatorState = this.startTerminatorless(isLabel); | ||
const isLabel = key == "label"; | ||
const terminatorState = this.startTerminatorless(isLabel); | ||
this.print(label, node); | ||
@@ -168,9 +174,9 @@ this.endTerminatorless(terminatorState); | ||
var ContinueStatement = buildLabelStatement("continue"); | ||
const ContinueStatement = buildLabelStatement("continue"); | ||
exports.ContinueStatement = ContinueStatement; | ||
var ReturnStatement = buildLabelStatement("return", "argument"); | ||
const ReturnStatement = buildLabelStatement("return", "argument"); | ||
exports.ReturnStatement = ReturnStatement; | ||
var BreakStatement = buildLabelStatement("break"); | ||
const BreakStatement = buildLabelStatement("break"); | ||
exports.BreakStatement = BreakStatement; | ||
var ThrowStatement = buildLabelStatement("throw", "argument"); | ||
const ThrowStatement = buildLabelStatement("throw", "argument"); | ||
exports.ThrowStatement = ThrowStatement; | ||
@@ -229,5 +235,7 @@ | ||
indent: true, | ||
addNewlines: function addNewlines(leading, cas) { | ||
addNewlines(leading, cas) { | ||
if (!leading && node.cases[node.cases.length - 1] === cas) return -1; | ||
} | ||
}); | ||
@@ -264,5 +272,3 @@ this.token("}"); | ||
this.newline(); | ||
if (this.endsWith("\n")) for (var i = 0; i < 4; i++) { | ||
this.space(true); | ||
} | ||
if (this.endsWith("\n")) for (let i = 0; i < 4; i++) this.space(true); | ||
} | ||
@@ -273,5 +279,3 @@ | ||
this.newline(); | ||
if (this.endsWith("\n")) for (var i = 0; i < 6; i++) { | ||
this.space(true); | ||
} | ||
if (this.endsWith("\n")) for (let i = 0; i < 6; i++) this.space(true); | ||
} | ||
@@ -287,10 +291,6 @@ | ||
this.space(); | ||
var hasInits = false; | ||
let hasInits = false; | ||
if (!t.isFor(parent)) { | ||
var _arr = node.declarations; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var declar = _arr[_i]; | ||
if (!t().isFor(parent)) { | ||
for (const declar of node.declarations) { | ||
if (declar.init) { | ||
@@ -302,3 +302,3 @@ hasInits = true; | ||
var separator; | ||
let separator; | ||
@@ -310,6 +310,6 @@ if (hasInits) { | ||
this.printList(node.declarations, node, { | ||
separator: separator | ||
separator | ||
}); | ||
if (t.isFor(parent)) { | ||
if (t().isFor(parent)) { | ||
if (parent.left === node || parent.init === node) return; | ||
@@ -316,0 +316,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.TaggedTemplateExpression = TaggedTemplateExpression; | ||
@@ -14,5 +16,5 @@ exports.TemplateElement = TemplateElement; | ||
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 ? "`" : "${"); | ||
const isFirst = parent.quasis[0] === node; | ||
const isLast = parent.quasis[parent.quasis.length - 1] === node; | ||
const value = (isFirst ? "`" : "}") + node.value.raw + (isLast ? "`" : "${"); | ||
this.token(value); | ||
@@ -22,5 +24,5 @@ } | ||
function TemplateLiteral(node) { | ||
var quasis = node.quasis; | ||
const quasis = node.quasis; | ||
for (var i = 0; i < quasis.length; i++) { | ||
for (let i = 0; i < quasis.length; i++) { | ||
this.print(quasis[i], node); | ||
@@ -27,0 +29,0 @@ |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Identifier = Identifier; | ||
@@ -16,6 +18,22 @@ exports.SpreadElement = exports.RestElement = RestElement; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
var _jsesc = _interopRequireDefault(require("jsesc")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _jsesc() { | ||
const data = _interopRequireDefault(require("jsesc")); | ||
_jsesc = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -35,3 +53,3 @@ | ||
function ObjectExpression(node) { | ||
var props = node.properties; | ||
const props = node.properties; | ||
this.token("{"); | ||
@@ -69,3 +87,3 @@ this.printInnerComments(node); | ||
} else { | ||
if (t.isAssignmentPattern(node.value) && t.isIdentifier(node.key) && node.key.name === node.value.left.name) { | ||
if (t().isAssignmentPattern(node.value) && t().isIdentifier(node.key) && node.key.name === node.value.left.name) { | ||
this.print(node.value, node); | ||
@@ -77,3 +95,3 @@ return; | ||
if (node.shorthand && t.isIdentifier(node.key) && t.isIdentifier(node.value) && node.key.name === node.value.name) { | ||
if (node.shorthand && t().isIdentifier(node.key) && t().isIdentifier(node.value) && node.key.name === node.value.name) { | ||
return; | ||
@@ -89,9 +107,9 @@ } | ||
function ArrayExpression(node) { | ||
var elems = node.elements; | ||
var len = elems.length; | ||
const elems = node.elements; | ||
const len = elems.length; | ||
this.token("["); | ||
this.printInnerComments(node); | ||
for (var i = 0; i < elems.length; i++) { | ||
var elem = elems[i]; | ||
for (let i = 0; i < elems.length; i++) { | ||
const elem = elems[i]; | ||
@@ -111,3 +129,3 @@ if (elem) { | ||
function RegExpLiteral(node) { | ||
this.word("/" + node.pattern + "/" + node.flags); | ||
this.word(`/${node.pattern}/${node.flags}`); | ||
} | ||
@@ -124,4 +142,4 @@ | ||
function NumericLiteral(node) { | ||
var raw = this.getPossibleRaw(node); | ||
var value = node.value + ""; | ||
const raw = this.getPossibleRaw(node); | ||
const value = node.value + ""; | ||
@@ -138,3 +156,3 @@ if (raw == null) { | ||
function StringLiteral(node) { | ||
var raw = this.getPossibleRaw(node); | ||
const raw = this.getPossibleRaw(node); | ||
@@ -146,3 +164,3 @@ if (!this.format.minified && raw != null) { | ||
var opts = { | ||
const opts = { | ||
quotes: "double", | ||
@@ -156,4 +174,4 @@ wrap: true | ||
var val = (0, _jsesc.default)(node.value, opts); | ||
const val = (0, _jsesc().default)(node.value, opts); | ||
return this.token(val); | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.TSTypeAnnotation = TSTypeAnnotation; | ||
@@ -145,4 +147,6 @@ exports.TSTypeParameterDeclaration = exports.TSTypeParameterInstantiation = TSTypeParameterInstantiation; | ||
function TSPropertySignature(node) { | ||
var readonly = node.readonly, | ||
initializer = node.initializer; | ||
const { | ||
readonly, | ||
initializer | ||
} = node; | ||
@@ -190,3 +194,5 @@ if (readonly) { | ||
function TSIndexSignature(node) { | ||
var readonly = node.readonly; | ||
const { | ||
readonly | ||
} = node; | ||
@@ -262,4 +268,6 @@ if (readonly) { | ||
function tsPrintFunctionOrConstructorType(node) { | ||
var typeParameters = node.typeParameters, | ||
parameters = node.parameters; | ||
const { | ||
typeParameters, | ||
parameters | ||
} = node; | ||
this.print(typeParameters, node); | ||
@@ -311,16 +319,4 @@ this.token("("); | ||
for (var _iterator = members, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var _member = _ref; | ||
this.print(_member, node); | ||
for (const member of members) { | ||
this.print(member, node); | ||
this.newline(); | ||
@@ -357,3 +353,3 @@ } | ||
this.printJoin(node.types, node, { | ||
separator: function separator() { | ||
separator() { | ||
this.space(); | ||
@@ -363,2 +359,3 @@ this.token(sep); | ||
} | ||
}); | ||
@@ -409,5 +406,7 @@ } | ||
function TSMappedType(node) { | ||
var readonly = node.readonly, | ||
typeParameter = node.typeParameter, | ||
optional = node.optional; | ||
const { | ||
readonly, | ||
typeParameter, | ||
optional | ||
} = node; | ||
this.token("{"); | ||
@@ -417,2 +416,3 @@ this.space(); | ||
if (readonly) { | ||
tokenIfPlusMinus(this, readonly); | ||
this.word("readonly"); | ||
@@ -431,2 +431,3 @@ this.space(); | ||
if (optional) { | ||
tokenIfPlusMinus(this, optional); | ||
this.token("?"); | ||
@@ -442,2 +443,8 @@ } | ||
function tokenIfPlusMinus(self, tok) { | ||
if (tok !== true) { | ||
self.token(tok); | ||
} | ||
} | ||
function TSLiteralType(node) { | ||
@@ -453,7 +460,9 @@ this.print(node.literal, node); | ||
function TSInterfaceDeclaration(node) { | ||
var declare = node.declare, | ||
id = node.id, | ||
typeParameters = node.typeParameters, | ||
extendz = node.extends, | ||
body = node.body; | ||
const { | ||
declare, | ||
id, | ||
typeParameters, | ||
extends: extendz, | ||
body | ||
} = node; | ||
@@ -486,6 +495,8 @@ if (declare) { | ||
function TSTypeAliasDeclaration(node) { | ||
var declare = node.declare, | ||
id = node.id, | ||
typeParameters = node.typeParameters, | ||
typeAnnotation = node.typeAnnotation; | ||
const { | ||
declare, | ||
id, | ||
typeParameters, | ||
typeAnnotation | ||
} = node; | ||
@@ -509,4 +520,6 @@ if (declare) { | ||
function TSAsExpression(node) { | ||
var expression = node.expression, | ||
typeAnnotation = node.typeAnnotation; | ||
const { | ||
expression, | ||
typeAnnotation | ||
} = node; | ||
this.print(expression, node); | ||
@@ -520,4 +533,6 @@ this.space(); | ||
function TSTypeAssertion(node) { | ||
var typeAnnotation = node.typeAnnotation, | ||
expression = node.expression; | ||
const { | ||
typeAnnotation, | ||
expression | ||
} = node; | ||
this.token("<"); | ||
@@ -531,6 +546,8 @@ this.print(typeAnnotation, node); | ||
function TSEnumDeclaration(node) { | ||
var declare = node.declare, | ||
isConst = node.const, | ||
id = node.id, | ||
members = node.members; | ||
const { | ||
declare, | ||
const: isConst, | ||
id, | ||
members | ||
} = node; | ||
@@ -555,4 +572,6 @@ if (declare) { | ||
function TSEnumMember(node) { | ||
var id = node.id, | ||
initializer = node.initializer; | ||
const { | ||
id, | ||
initializer | ||
} = node; | ||
this.print(id, node); | ||
@@ -571,4 +590,6 @@ | ||
function TSModuleDeclaration(node) { | ||
var declare = node.declare, | ||
id = node.id; | ||
const { | ||
declare, | ||
id | ||
} = node; | ||
@@ -592,3 +613,3 @@ if (declare) { | ||
var body = node.body; | ||
let body = node.body; | ||
@@ -610,5 +631,7 @@ while (body.type === "TSModuleDeclaration") { | ||
function TSImportEqualsDeclaration(node) { | ||
var isExport = node.isExport, | ||
id = node.id, | ||
moduleReference = node.moduleReference; | ||
const { | ||
isExport, | ||
id, | ||
moduleReference | ||
} = node; | ||
@@ -661,4 +684,6 @@ if (isExport) { | ||
function tsPrintSignatureDeclarationBase(node) { | ||
var typeParameters = node.typeParameters, | ||
parameters = node.parameters; | ||
const { | ||
typeParameters, | ||
parameters | ||
} = node; | ||
this.print(typeParameters, node); | ||
@@ -665,0 +690,0 @@ this.token("("); |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = _default; | ||
@@ -13,32 +15,18 @@ exports.CodeGenerator = void 0; | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
class Generator extends _printer.default { | ||
constructor(ast, opts = {}, code) { | ||
const format = normalizeOptions(code, opts); | ||
const map = opts.sourceMaps ? new _sourceMap.default(opts, code) : null; | ||
super(format, map); | ||
this.ast = ast; | ||
} | ||
var Generator = function (_Printer) { | ||
_inheritsLoose(Generator, _Printer); | ||
function Generator(ast, opts, code) { | ||
var _this; | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
var format = normalizeOptions(code, opts); | ||
var map = opts.sourceMaps ? new _sourceMap.default(opts, code) : null; | ||
_this = _Printer.call(this, format, map) || this; | ||
_this.ast = ast; | ||
return _this; | ||
generate() { | ||
return super.generate(this.ast); | ||
} | ||
var _proto = Generator.prototype; | ||
} | ||
_proto.generate = function generate() { | ||
return _Printer.prototype.generate.call(this, this.ast); | ||
}; | ||
return Generator; | ||
}(_printer.default); | ||
function normalizeOptions(code, opts) { | ||
var format = { | ||
const format = { | ||
auxiliaryCommentBefore: opts.auxiliaryCommentBefore, | ||
@@ -64,9 +52,5 @@ auxiliaryCommentAfter: opts.auxiliaryCommentAfter, | ||
format.shouldPrintComment = format.shouldPrintComment || function () { | ||
return format.comments; | ||
}; | ||
format.shouldPrintComment = format.shouldPrintComment || (() => format.comments); | ||
} else { | ||
format.shouldPrintComment = format.shouldPrintComment || function (value) { | ||
return format.comments || value.indexOf("@license") >= 0 || value.indexOf("@preserve") >= 0; | ||
}; | ||
format.shouldPrintComment = format.shouldPrintComment || (value => format.comments || value.indexOf("@license") >= 0 || value.indexOf("@preserve") >= 0); | ||
} | ||
@@ -78,3 +62,3 @@ | ||
if (format.compact) { | ||
console.error("[BABEL] Note: The code generator has deoptimised the styling of " + (opts.filename + " as it exceeds the max of " + "500KB" + ".")); | ||
console.error("[BABEL] Note: The code generator has deoptimised the styling of " + `${opts.filename} as it exceeds the max of ${"500KB"}.`); | ||
} | ||
@@ -90,15 +74,12 @@ } | ||
var CodeGenerator = function () { | ||
function CodeGenerator(ast, opts, code) { | ||
class CodeGenerator { | ||
constructor(ast, opts, code) { | ||
this._generator = new Generator(ast, opts, code); | ||
} | ||
var _proto2 = CodeGenerator.prototype; | ||
_proto2.generate = function generate() { | ||
generate() { | ||
return this._generator.generate(); | ||
}; | ||
} | ||
return CodeGenerator; | ||
}(); | ||
} | ||
@@ -108,4 +89,4 @@ exports.CodeGenerator = CodeGenerator; | ||
function _default(ast, opts, code) { | ||
var gen = new Generator(ast, opts, code); | ||
const gen = new Generator(ast, opts, code); | ||
return gen.generate(); | ||
} |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.needsWhitespace = needsWhitespace; | ||
@@ -13,13 +15,21 @@ exports.needsWhitespaceBefore = needsWhitespaceBefore; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
function expandAliases(obj) { | ||
var newObj = {}; | ||
const newObj = {}; | ||
function add(type, func) { | ||
var fn = newObj[type]; | ||
const fn = newObj[type]; | ||
newObj[type] = fn ? function (node, parent, stack) { | ||
var result = fn(node, parent, stack); | ||
const result = fn(node, parent, stack); | ||
return result == null ? func(node, parent, stack) : result; | ||
@@ -29,23 +39,8 @@ } : func; | ||
var _arr = Object.keys(obj); | ||
for (const type of Object.keys(obj)) { | ||
const aliases = t().FLIPPED_ALIAS_KEYS[type]; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
var type = _arr[_i]; | ||
var aliases = t.FLIPPED_ALIAS_KEYS[type]; | ||
if (aliases) { | ||
for (var _iterator = aliases, _isArray = Array.isArray(_iterator), _i2 = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i2 >= _iterator.length) break; | ||
_ref = _iterator[_i2++]; | ||
} else { | ||
_i2 = _iterator.next(); | ||
if (_i2.done) break; | ||
_ref = _i2.value; | ||
} | ||
var _alias = _ref; | ||
add(_alias, obj[type]); | ||
for (const alias of aliases) { | ||
add(alias, obj[type]); | ||
} | ||
@@ -60,8 +55,8 @@ } else { | ||
var expandedParens = expandAliases(parens); | ||
var expandedWhitespaceNodes = expandAliases(whitespace.nodes); | ||
var expandedWhitespaceList = expandAliases(whitespace.list); | ||
const expandedParens = expandAliases(parens); | ||
const expandedWhitespaceNodes = expandAliases(whitespace.nodes); | ||
const expandedWhitespaceList = expandAliases(whitespace.list); | ||
function find(obj, node, parent, printStack) { | ||
var fn = obj[node.type]; | ||
const fn = obj[node.type]; | ||
return fn ? fn(node, parent, printStack) : null; | ||
@@ -71,7 +66,7 @@ } | ||
function isOrHasCallExpression(node) { | ||
if (t.isCallExpression(node)) { | ||
if (t().isCallExpression(node)) { | ||
return true; | ||
} | ||
if (t.isMemberExpression(node)) { | ||
if (t().isMemberExpression(node)) { | ||
return isOrHasCallExpression(node.object) || !node.computed && isOrHasCallExpression(node.property); | ||
@@ -86,13 +81,13 @@ } else { | ||
if (t.isExpressionStatement(node)) { | ||
if (t().isExpressionStatement(node)) { | ||
node = node.expression; | ||
} | ||
var linesInfo = find(expandedWhitespaceNodes, node, parent); | ||
let linesInfo = find(expandedWhitespaceNodes, node, parent); | ||
if (!linesInfo) { | ||
var items = find(expandedWhitespaceList, node, parent); | ||
const items = find(expandedWhitespaceList, node, parent); | ||
if (items) { | ||
for (var i = 0; i < items.length; i++) { | ||
for (let i = 0; i < items.length; i++) { | ||
linesInfo = needsWhitespace(items[i], node, type); | ||
@@ -122,3 +117,3 @@ if (linesInfo) break; | ||
if (t.isNewExpression(parent) && parent.callee === node) { | ||
if (t().isNewExpression(parent) && parent.callee === node) { | ||
if (isOrHasCallExpression(node)) return true; | ||
@@ -125,0 +120,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.FunctionTypeAnnotation = exports.NullableTypeAnnotation = NullableTypeAnnotation; | ||
@@ -23,7 +25,15 @@ exports.UpdateExpression = UpdateExpression; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
var PRECEDENCE = { | ||
const PRECEDENCE = { | ||
"||": 0, | ||
@@ -55,16 +65,14 @@ "&&": 1, | ||
var isClassExtendsClause = function isClassExtendsClause(node, parent) { | ||
return (t.isClassDeclaration(parent) || t.isClassExpression(parent)) && parent.superClass === node; | ||
}; | ||
const isClassExtendsClause = (node, parent) => (t().isClassDeclaration(parent) || t().isClassExpression(parent)) && parent.superClass === node; | ||
function NullableTypeAnnotation(node, parent) { | ||
return t.isArrayTypeAnnotation(parent); | ||
return t().isArrayTypeAnnotation(parent); | ||
} | ||
function UpdateExpression(node, parent) { | ||
return t.isMemberExpression(parent, { | ||
return t().isMemberExpression(parent, { | ||
object: node | ||
}) || t.isCallExpression(parent, { | ||
}) || t().isCallExpression(parent, { | ||
callee: node | ||
}) || t.isNewExpression(parent, { | ||
}) || t().isNewExpression(parent, { | ||
callee: node | ||
@@ -85,3 +93,3 @@ }) || isClassExtendsClause(node, parent); | ||
function Binary(node, parent) { | ||
if (node.operator === "**" && t.isBinaryExpression(parent, { | ||
if (node.operator === "**" && t().isBinaryExpression(parent, { | ||
operator: "**" | ||
@@ -96,13 +104,13 @@ })) { | ||
if ((t.isCallExpression(parent) || t.isNewExpression(parent)) && parent.callee === node || t.isUnaryLike(parent) || t.isMemberExpression(parent) && parent.object === node || t.isAwaitExpression(parent)) { | ||
if ((t().isCallExpression(parent) || t().isNewExpression(parent)) && parent.callee === node || t().isUnaryLike(parent) || t().isMemberExpression(parent) && parent.object === node || t().isAwaitExpression(parent)) { | ||
return true; | ||
} | ||
if (t.isBinary(parent)) { | ||
var parentOp = parent.operator; | ||
var parentPos = PRECEDENCE[parentOp]; | ||
var nodeOp = node.operator; | ||
var nodePos = PRECEDENCE[nodeOp]; | ||
if (t().isBinary(parent)) { | ||
const parentOp = parent.operator; | ||
const parentPos = PRECEDENCE[parentOp]; | ||
const nodeOp = node.operator; | ||
const nodePos = PRECEDENCE[nodeOp]; | ||
if (parentPos === nodePos && parent.right === node && !t.isLogicalExpression(parent) || parentPos > nodePos) { | ||
if (parentPos === nodePos && parent.right === node && !t().isLogicalExpression(parent) || parentPos > nodePos) { | ||
return true; | ||
@@ -116,3 +124,3 @@ } | ||
function UnionTypeAnnotation(node, parent) { | ||
return t.isArrayTypeAnnotation(parent) || t.isNullableTypeAnnotation(parent) || t.isIntersectionTypeAnnotation(parent) || t.isUnionTypeAnnotation(parent); | ||
return t().isArrayTypeAnnotation(parent) || t().isNullableTypeAnnotation(parent) || t().isIntersectionTypeAnnotation(parent) || t().isUnionTypeAnnotation(parent); | ||
} | ||
@@ -129,7 +137,7 @@ | ||
function BinaryExpression(node, parent) { | ||
return node.operator === "in" && (t.isVariableDeclarator(parent) || t.isFor(parent)); | ||
return node.operator === "in" && (t().isVariableDeclarator(parent) || t().isFor(parent)); | ||
} | ||
function SequenceExpression(node, parent) { | ||
if (t.isForStatement(parent) || t.isThrowStatement(parent) || t.isReturnStatement(parent) || t.isIfStatement(parent) && parent.test === node || t.isWhileStatement(parent) && parent.test === node || t.isForInStatement(parent) && parent.right === node || t.isSwitchStatement(parent) && parent.discriminant === node || t.isExpressionStatement(parent) && parent.expression === node) { | ||
if (t().isForStatement(parent) || t().isThrowStatement(parent) || t().isReturnStatement(parent) || t().isIfStatement(parent) && parent.test === node || t().isWhileStatement(parent) && parent.test === node || t().isForInStatement(parent) && parent.right === node || t().isSwitchStatement(parent) && parent.discriminant === node || t().isExpressionStatement(parent) && parent.expression === node) { | ||
return false; | ||
@@ -142,3 +150,3 @@ } | ||
function YieldExpression(node, parent) { | ||
return t.isBinary(parent) || t.isUnaryLike(parent) || t.isCallExpression(parent) || t.isMemberExpression(parent) || t.isNewExpression(parent) || t.isConditionalExpression(parent) && node === parent.test || isClassExtendsClause(node, parent); | ||
return t().isBinary(parent) || t().isUnaryLike(parent) || t().isCallExpression(parent) || t().isMemberExpression(parent) || t().isNewExpression(parent) || t().isConditionalExpression(parent) && node === parent.test || isClassExtendsClause(node, parent); | ||
} | ||
@@ -153,9 +161,9 @@ | ||
function UnaryLike(node, parent) { | ||
return t.isMemberExpression(parent, { | ||
return t().isMemberExpression(parent, { | ||
object: node | ||
}) || t.isCallExpression(parent, { | ||
}) || t().isCallExpression(parent, { | ||
callee: node | ||
}) || t.isNewExpression(parent, { | ||
}) || t().isNewExpression(parent, { | ||
callee: node | ||
}) || t.isBinaryExpression(parent, { | ||
}) || t().isBinaryExpression(parent, { | ||
operator: "**", | ||
@@ -173,9 +181,9 @@ left: node | ||
function ArrowFunctionExpression(node, parent) { | ||
return t.isExportDeclaration(parent) || ConditionalExpression(node, parent); | ||
return t().isExportDeclaration(parent) || ConditionalExpression(node, parent); | ||
} | ||
function ConditionalExpression(node, parent) { | ||
if (t.isUnaryLike(parent) || t.isBinary(parent) || t.isConditionalExpression(parent, { | ||
if (t().isUnaryLike(parent) || t().isBinary(parent) || t().isConditionalExpression(parent, { | ||
test: node | ||
}) || t.isAwaitExpression(parent) || t.isTaggedTemplateExpression(parent) || t.isTSTypeAssertion(parent) || t.isTSAsExpression(parent)) { | ||
}) || t().isAwaitExpression(parent) || t().isTaggedTemplateExpression(parent) || t().isTSTypeAssertion(parent) || t().isTSAsExpression(parent)) { | ||
return true; | ||
@@ -188,6 +196,6 @@ } | ||
function AssignmentExpression(node) { | ||
if (t.isObjectPattern(node.left)) { | ||
if (t().isObjectPattern(node.left)) { | ||
return true; | ||
} else { | ||
return ConditionalExpression.apply(void 0, arguments); | ||
return ConditionalExpression(...arguments); | ||
} | ||
@@ -200,20 +208,17 @@ } | ||
function isFirstInStatement(printStack, _temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
_ref$considerArrow = _ref.considerArrow, | ||
considerArrow = _ref$considerArrow === void 0 ? false : _ref$considerArrow, | ||
_ref$considerDefaultE = _ref.considerDefaultExports, | ||
considerDefaultExports = _ref$considerDefaultE === void 0 ? false : _ref$considerDefaultE; | ||
var i = printStack.length - 1; | ||
var node = printStack[i]; | ||
function isFirstInStatement(printStack, { | ||
considerArrow = false, | ||
considerDefaultExports = false | ||
} = {}) { | ||
let i = printStack.length - 1; | ||
let node = printStack[i]; | ||
i--; | ||
var parent = printStack[i]; | ||
let parent = printStack[i]; | ||
while (i > 0) { | ||
if (t.isExpressionStatement(parent, { | ||
if (t().isExpressionStatement(parent, { | ||
expression: node | ||
}) || t.isTaggedTemplateExpression(parent) || considerDefaultExports && t.isExportDefaultDeclaration(parent, { | ||
}) || t().isTaggedTemplateExpression(parent) || considerDefaultExports && t().isExportDefaultDeclaration(parent, { | ||
declaration: node | ||
}) || considerArrow && t.isArrowFunctionExpression(parent, { | ||
}) || considerArrow && t().isArrowFunctionExpression(parent, { | ||
body: node | ||
@@ -224,11 +229,11 @@ })) { | ||
if (t.isCallExpression(parent, { | ||
if (t().isCallExpression(parent, { | ||
callee: node | ||
}) || t.isSequenceExpression(parent) && parent.expressions[0] === node || t.isMemberExpression(parent, { | ||
}) || t().isSequenceExpression(parent) && parent.expressions[0] === node || t().isMemberExpression(parent, { | ||
object: node | ||
}) || t.isConditional(parent, { | ||
}) || t().isConditional(parent, { | ||
test: node | ||
}) || t.isBinary(parent, { | ||
}) || t().isBinary(parent, { | ||
left: node | ||
}) || t.isAssignmentExpression(parent, { | ||
}) || t().isAssignmentExpression(parent, { | ||
left: node | ||
@@ -235,0 +240,0 @@ })) { |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.list = exports.nodes = void 0; | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
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)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
function crawl(node, state) { | ||
if (state === void 0) { | ||
state = {}; | ||
} | ||
if (t.isMemberExpression(node)) { | ||
function crawl(node, state = {}) { | ||
if (t().isMemberExpression(node)) { | ||
crawl(node.object, state); | ||
if (node.computed) crawl(node.property, state); | ||
} else if (t.isBinary(node) || t.isAssignmentExpression(node)) { | ||
} else if (t().isBinary(node) || t().isAssignmentExpression(node)) { | ||
crawl(node.left, state); | ||
crawl(node.right, state); | ||
} else if (t.isCallExpression(node)) { | ||
} else if (t().isCallExpression(node)) { | ||
state.hasCall = true; | ||
crawl(node.callee, state); | ||
} else if (t.isFunction(node)) { | ||
} else if (t().isFunction(node)) { | ||
state.hasFunction = true; | ||
} else if (t.isIdentifier(node)) { | ||
} else if (t().isIdentifier(node)) { | ||
state.hasHelper = state.hasHelper || isHelper(node.callee); | ||
@@ -34,10 +40,10 @@ } | ||
function isHelper(node) { | ||
if (t.isMemberExpression(node)) { | ||
if (t().isMemberExpression(node)) { | ||
return isHelper(node.object) || isHelper(node.property); | ||
} else if (t.isIdentifier(node)) { | ||
} else if (t().isIdentifier(node)) { | ||
return node.name === "require" || node.name[0] === "_"; | ||
} else if (t.isCallExpression(node)) { | ||
} else if (t().isCallExpression(node)) { | ||
return isHelper(node.callee); | ||
} else if (t.isBinary(node) || t.isAssignmentExpression(node)) { | ||
return t.isIdentifier(node.left) && isHelper(node.left) || isHelper(node.right); | ||
} else if (t().isBinary(node) || t().isAssignmentExpression(node)) { | ||
return t().isIdentifier(node.left) && isHelper(node.left) || isHelper(node.right); | ||
} else { | ||
@@ -49,8 +55,8 @@ return false; | ||
function isType(node) { | ||
return t.isLiteral(node) || t.isObjectExpression(node) || t.isArrayExpression(node) || t.isIdentifier(node) || t.isMemberExpression(node); | ||
return t().isLiteral(node) || t().isObjectExpression(node) || t().isArrayExpression(node) || t().isIdentifier(node) || t().isMemberExpression(node); | ||
} | ||
var nodes = { | ||
AssignmentExpression: function AssignmentExpression(node) { | ||
var state = crawl(node.right); | ||
const nodes = { | ||
AssignmentExpression(node) { | ||
const state = crawl(node.right); | ||
@@ -64,3 +70,4 @@ if (state.hasCall && state.hasHelper || state.hasFunction) { | ||
}, | ||
SwitchCase: function SwitchCase(node, parent) { | ||
SwitchCase(node, parent) { | ||
return { | ||
@@ -71,4 +78,5 @@ before: node.consequent.length || parent.cases[0] === node, | ||
}, | ||
LogicalExpression: function LogicalExpression(node) { | ||
if (t.isFunction(node.left) || t.isFunction(node.right)) { | ||
LogicalExpression(node) { | ||
if (t().isFunction(node.left) || t().isFunction(node.right)) { | ||
return { | ||
@@ -79,3 +87,4 @@ after: true | ||
}, | ||
Literal: function Literal(node) { | ||
Literal(node) { | ||
if (node.value === "use strict") { | ||
@@ -87,4 +96,5 @@ return { | ||
}, | ||
CallExpression: function CallExpression(node) { | ||
if (t.isFunction(node.callee) || isHelper(node)) { | ||
CallExpression(node) { | ||
if (t().isFunction(node.callee) || isHelper(node)) { | ||
return { | ||
@@ -96,9 +106,10 @@ before: true, | ||
}, | ||
VariableDeclaration: function VariableDeclaration(node) { | ||
for (var i = 0; i < node.declarations.length; i++) { | ||
var declar = node.declarations[i]; | ||
var enabled = isHelper(declar.id) && !isType(declar.init); | ||
VariableDeclaration(node) { | ||
for (let i = 0; i < node.declarations.length; i++) { | ||
const declar = node.declarations[i]; | ||
let enabled = isHelper(declar.id) && !isType(declar.init); | ||
if (!enabled) { | ||
var state = crawl(declar.init); | ||
const state = crawl(declar.init); | ||
enabled = isHelper(declar.init) && state.hasCall || state.hasFunction; | ||
@@ -115,4 +126,5 @@ } | ||
}, | ||
IfStatement: function IfStatement(node) { | ||
if (t.isBlockStatement(node.consequent)) { | ||
IfStatement(node) { | ||
if (t().isBlockStatement(node.consequent)) { | ||
return { | ||
@@ -124,2 +136,3 @@ before: true, | ||
} | ||
}; | ||
@@ -152,20 +165,18 @@ exports.nodes = nodes; | ||
var list = { | ||
VariableDeclaration: function VariableDeclaration(node) { | ||
return node.declarations.map(function (decl) { | ||
return decl.init; | ||
}); | ||
const list = { | ||
VariableDeclaration(node) { | ||
return node.declarations.map(decl => decl.init); | ||
}, | ||
ArrayExpression: function ArrayExpression(node) { | ||
ArrayExpression(node) { | ||
return node.elements; | ||
}, | ||
ObjectExpression: function ObjectExpression(node) { | ||
ObjectExpression(node) { | ||
return node.properties; | ||
} | ||
}; | ||
exports.list = list; | ||
[["Function", true], ["Class", true], ["Loop", true], ["LabeledStatement", true], ["SwitchStatement", true], ["TryStatement", true]].forEach(function (_ref) { | ||
var type = _ref[0], | ||
amounts = _ref[1]; | ||
[["Function", true], ["Class", true], ["Loop", true], ["LabeledStatement", true], ["SwitchStatement", true], ["TryStatement", true]].forEach(function ([type, amounts]) { | ||
if (typeof amounts === "boolean") { | ||
@@ -178,3 +189,3 @@ amounts = { | ||
[type].concat(t.FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) { | ||
[type].concat(t().FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) { | ||
nodes[type] = function () { | ||
@@ -181,0 +192,0 @@ return amounts; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _isInteger = _interopRequireDefault(require("lodash/isInteger")); | ||
function _isInteger() { | ||
const data = _interopRequireDefault(require("lodash/isInteger")); | ||
var _repeat = _interopRequireDefault(require("lodash/repeat")); | ||
_isInteger = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _repeat() { | ||
const data = _interopRequireDefault(require("lodash/repeat")); | ||
_repeat = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var _buffer = _interopRequireDefault(require("./buffer")); | ||
@@ -14,4 +32,12 @@ | ||
var t = _interopRequireWildcard(require("@babel/types")); | ||
function t() { | ||
const data = _interopRequireWildcard(require("@babel/types")); | ||
t = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
var generatorFunctions = _interopRequireWildcard(require("./generators")); | ||
@@ -23,8 +49,8 @@ | ||
var SCIENTIFIC_NOTATION = /e/i; | ||
var ZERO_DECIMAL_INTEGER = /\.0+$/; | ||
var NON_DECIMAL_LITERAL = /^0[box]/; | ||
const SCIENTIFIC_NOTATION = /e/i; | ||
const ZERO_DECIMAL_INTEGER = /\.0+$/; | ||
const NON_DECIMAL_LITERAL = /^0[box]/; | ||
var Printer = function () { | ||
function Printer(format, map) { | ||
class Printer { | ||
constructor(format, map) { | ||
this.inForStatementInitCounter = 0; | ||
@@ -45,5 +71,3 @@ this._printStack = []; | ||
var _proto = Printer.prototype; | ||
_proto.generate = function generate(ast) { | ||
generate(ast) { | ||
this.print(ast); | ||
@@ -54,25 +78,21 @@ | ||
return this._buf.get(); | ||
}; | ||
} | ||
_proto.indent = function indent() { | ||
indent() { | ||
if (this.format.compact || this.format.concise) return; | ||
this._indent++; | ||
}; | ||
} | ||
_proto.dedent = function dedent() { | ||
dedent() { | ||
if (this.format.compact || this.format.concise) return; | ||
this._indent--; | ||
}; | ||
} | ||
_proto.semicolon = function semicolon(force) { | ||
if (force === void 0) { | ||
force = false; | ||
} | ||
semicolon(force = false) { | ||
this._maybeAddAuxComment(); | ||
this._append(";", !force); | ||
}; | ||
} | ||
_proto.rightBrace = function rightBrace() { | ||
rightBrace() { | ||
if (this.format.minified) { | ||
@@ -83,9 +103,5 @@ this._buf.removeLastSemicolon(); | ||
this.token("}"); | ||
}; | ||
} | ||
_proto.space = function space(force) { | ||
if (force === void 0) { | ||
force = false; | ||
} | ||
space(force = false) { | ||
if (this.format.compact) return; | ||
@@ -96,5 +112,5 @@ | ||
} | ||
}; | ||
} | ||
_proto.word = function word(str) { | ||
word(str) { | ||
if (this._endsWithWord || this.endsWith("/") && str.indexOf("/") === 0) { | ||
@@ -109,10 +125,10 @@ this._space(); | ||
this._endsWithWord = true; | ||
}; | ||
} | ||
_proto.number = function number(str) { | ||
number(str) { | ||
this.word(str); | ||
this._endsWithInteger = (0, _isInteger.default)(+str) && !NON_DECIMAL_LITERAL.test(str) && !SCIENTIFIC_NOTATION.test(str) && !ZERO_DECIMAL_INTEGER.test(str) && str[str.length - 1] !== "."; | ||
}; | ||
this._endsWithInteger = (0, _isInteger().default)(+str) && !NON_DECIMAL_LITERAL.test(str) && !SCIENTIFIC_NOTATION.test(str) && !ZERO_DECIMAL_INTEGER.test(str) && str[str.length - 1] !== "."; | ||
} | ||
_proto.token = function token(str) { | ||
token(str) { | ||
if (str === "--" && this.endsWith("!") || str[0] === "+" && this.endsWith("+") || str[0] === "-" && this.endsWith("-") || str[0] === "." && this._endsWithInteger) { | ||
@@ -125,5 +141,5 @@ this._space(); | ||
this._append(str); | ||
}; | ||
} | ||
_proto.newline = function newline(i) { | ||
newline(i) { | ||
if (this.format.retainLines || this.format.compact) return; | ||
@@ -142,40 +158,36 @@ | ||
for (var j = 0; j < i; j++) { | ||
for (let j = 0; j < i; j++) { | ||
this._newline(); | ||
} | ||
}; | ||
} | ||
_proto.endsWith = function endsWith(str) { | ||
endsWith(str) { | ||
return this._buf.endsWith(str); | ||
}; | ||
} | ||
_proto.removeTrailingNewline = function removeTrailingNewline() { | ||
removeTrailingNewline() { | ||
this._buf.removeTrailingNewline(); | ||
}; | ||
} | ||
_proto.source = function source(prop, loc) { | ||
source(prop, loc) { | ||
this._catchUp(prop, loc); | ||
this._buf.source(prop, loc); | ||
}; | ||
} | ||
_proto.withSource = function withSource(prop, loc, cb) { | ||
withSource(prop, loc, cb) { | ||
this._catchUp(prop, loc); | ||
this._buf.withSource(prop, loc, cb); | ||
}; | ||
} | ||
_proto._space = function _space() { | ||
_space() { | ||
this._append(" ", true); | ||
}; | ||
} | ||
_proto._newline = function _newline() { | ||
_newline() { | ||
this._append("\n", true); | ||
}; | ||
} | ||
_proto._append = function _append(str, queue) { | ||
if (queue === void 0) { | ||
queue = false; | ||
} | ||
_append(str, queue = false) { | ||
this._maybeAddParen(str); | ||
@@ -188,22 +200,20 @@ | ||
this._endsWithInteger = false; | ||
}; | ||
} | ||
_proto._maybeIndent = function _maybeIndent(str) { | ||
_maybeIndent(str) { | ||
if (this._indent && this.endsWith("\n") && str[0] !== "\n") { | ||
this._buf.queue(this._getIndent()); | ||
} | ||
}; | ||
} | ||
_proto._maybeAddParen = function _maybeAddParen(str) { | ||
var parenPushNewlineState = this._parenPushNewlineState; | ||
_maybeAddParen(str) { | ||
const parenPushNewlineState = this._parenPushNewlineState; | ||
if (!parenPushNewlineState) return; | ||
this._parenPushNewlineState = null; | ||
var i; | ||
let i; | ||
for (i = 0; i < str.length && str[i] === " "; i++) { | ||
continue; | ||
} | ||
for (i = 0; i < str.length && str[i] === " "; i++) continue; | ||
if (i === str.length) return; | ||
var cha = str[i]; | ||
const cha = str[i]; | ||
@@ -213,3 +223,3 @@ if (cha !== "\n") { | ||
if (i + 1 === str.length) return; | ||
var chaPost = str[i + 1]; | ||
const chaPost = str[i + 1]; | ||
if (chaPost !== "/" && chaPost !== "*") return; | ||
@@ -221,26 +231,22 @@ } | ||
parenPushNewlineState.printed = true; | ||
}; | ||
} | ||
_proto._catchUp = function _catchUp(prop, loc) { | ||
_catchUp(prop, loc) { | ||
if (!this.format.retainLines) return; | ||
var pos = loc ? loc[prop] : null; | ||
const pos = loc ? loc[prop] : null; | ||
if (pos && pos.line !== null) { | ||
var count = pos.line - this._buf.getCurrentLine(); | ||
const count = pos.line - this._buf.getCurrentLine(); | ||
for (var i = 0; i < count; i++) { | ||
for (let i = 0; i < count; i++) { | ||
this._newline(); | ||
} | ||
} | ||
}; | ||
} | ||
_proto._getIndent = function _getIndent() { | ||
return (0, _repeat.default)(this.format.indent.style, this._indent); | ||
}; | ||
_getIndent() { | ||
return (0, _repeat().default)(this.format.indent.style, this._indent); | ||
} | ||
_proto.startTerminatorless = function startTerminatorless(isLabel) { | ||
if (isLabel === void 0) { | ||
isLabel = false; | ||
} | ||
startTerminatorless(isLabel = false) { | ||
if (isLabel) { | ||
@@ -254,5 +260,5 @@ this._noLineTerminator = true; | ||
} | ||
}; | ||
} | ||
_proto.endTerminatorless = function endTerminatorless(state) { | ||
endTerminatorless(state) { | ||
this._noLineTerminator = false; | ||
@@ -265,9 +271,7 @@ | ||
} | ||
}; | ||
} | ||
_proto.print = function print(node, parent) { | ||
var _this = this; | ||
print(node, parent) { | ||
if (!node) return; | ||
var oldConcise = this.format.concise; | ||
const oldConcise = this.format.concise; | ||
@@ -278,6 +282,6 @@ if (node._compact) { | ||
var printMethod = this[node.type]; | ||
const printMethod = this[node.type]; | ||
if (!printMethod) { | ||
throw new ReferenceError("unknown node of type " + JSON.stringify(node.type) + " with constructor " + JSON.stringify(node && node.constructor.name)); | ||
throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node && node.constructor.name)}`); | ||
} | ||
@@ -287,3 +291,3 @@ | ||
var oldInAux = this._insideAux; | ||
const oldInAux = this._insideAux; | ||
this._insideAux = !node.loc; | ||
@@ -293,3 +297,3 @@ | ||
var needsParens = n.needsParens(node, parent, this._printStack); | ||
let needsParens = n.needsParens(node, parent, this._printStack); | ||
@@ -304,5 +308,5 @@ if (this.format.retainFunctionParens && node.type === "FunctionExpression" && node.extra && node.extra.parenthesized) { | ||
var loc = t.isProgram(node) || t.isFile(node) ? null : node.loc; | ||
this.withSource("start", loc, function () { | ||
_this[node.type](node, parent); | ||
const loc = t().isProgram(node) || t().isFile(node) ? null : node.loc; | ||
this.withSource("start", loc, () => { | ||
this[node.type](node, parent); | ||
}); | ||
@@ -318,13 +322,13 @@ | ||
this._insideAux = oldInAux; | ||
}; | ||
} | ||
_proto._maybeAddAuxComment = function _maybeAddAuxComment(enteredPositionlessNode) { | ||
_maybeAddAuxComment(enteredPositionlessNode) { | ||
if (enteredPositionlessNode) this._printAuxBeforeComment(); | ||
if (!this._insideAux) this._printAuxAfterComment(); | ||
}; | ||
} | ||
_proto._printAuxBeforeComment = function _printAuxBeforeComment() { | ||
_printAuxBeforeComment() { | ||
if (this._printAuxAfterOnNextUserNode) return; | ||
this._printAuxAfterOnNextUserNode = true; | ||
var comment = this.format.auxiliaryCommentBefore; | ||
const comment = this.format.auxiliaryCommentBefore; | ||
@@ -337,8 +341,8 @@ if (comment) { | ||
} | ||
}; | ||
} | ||
_proto._printAuxAfterComment = function _printAuxAfterComment() { | ||
_printAuxAfterComment() { | ||
if (!this._printAuxAfterOnNextUserNode) return; | ||
this._printAuxAfterOnNextUserNode = false; | ||
var comment = this.format.auxiliaryCommentAfter; | ||
const comment = this.format.auxiliaryCommentAfter; | ||
@@ -351,6 +355,6 @@ if (comment) { | ||
} | ||
}; | ||
} | ||
_proto.getPossibleRaw = function getPossibleRaw(node) { | ||
var extra = node.extra; | ||
getPossibleRaw(node) { | ||
const extra = node.extra; | ||
@@ -360,17 +364,13 @@ if (extra && extra.raw != null && extra.rawValue != null && node.value === extra.rawValue) { | ||
} | ||
}; | ||
} | ||
_proto.printJoin = function printJoin(nodes, parent, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
printJoin(nodes, parent, opts = {}) { | ||
if (!nodes || !nodes.length) return; | ||
if (opts.indent) this.indent(); | ||
var newlineOpts = { | ||
const newlineOpts = { | ||
addNewlines: opts.addNewlines | ||
}; | ||
for (var i = 0; i < nodes.length; i++) { | ||
var node = nodes[i]; | ||
for (let i = 0; i < nodes.length; i++) { | ||
const node = nodes[i]; | ||
if (!node) continue; | ||
@@ -392,15 +392,15 @@ if (opts.statement) this._printNewline(true, node, parent, newlineOpts); | ||
if (opts.indent) this.dedent(); | ||
}; | ||
} | ||
_proto.printAndIndentOnComments = function printAndIndentOnComments(node, parent) { | ||
var indent = node.leadingComments && node.leadingComments.length > 0; | ||
printAndIndentOnComments(node, parent) { | ||
const indent = node.leadingComments && node.leadingComments.length > 0; | ||
if (indent) this.indent(); | ||
this.print(node, parent); | ||
if (indent) this.dedent(); | ||
}; | ||
} | ||
_proto.printBlock = function printBlock(parent) { | ||
var node = parent.body; | ||
printBlock(parent) { | ||
const node = parent.body; | ||
if (!t.isEmptyStatement(node)) { | ||
if (!t().isEmptyStatement(node)) { | ||
this.space(); | ||
@@ -410,17 +410,13 @@ } | ||
this.print(node, parent); | ||
}; | ||
} | ||
_proto._printTrailingComments = function _printTrailingComments(node, parent) { | ||
_printTrailingComments(node, parent) { | ||
this._printComments(this._getComments(false, node, parent)); | ||
}; | ||
} | ||
_proto._printLeadingComments = function _printLeadingComments(node, parent) { | ||
_printLeadingComments(node, parent) { | ||
this._printComments(this._getComments(true, node, parent)); | ||
}; | ||
} | ||
_proto.printInnerComments = function printInnerComments(node, indent) { | ||
if (indent === void 0) { | ||
indent = true; | ||
} | ||
printInnerComments(node, indent = true) { | ||
if (!node.innerComments || !node.innerComments.length) return; | ||
@@ -432,18 +428,10 @@ if (indent) this.indent(); | ||
if (indent) this.dedent(); | ||
}; | ||
} | ||
_proto.printSequence = function printSequence(nodes, parent, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
printSequence(nodes, parent, opts = {}) { | ||
opts.statement = true; | ||
return this.printJoin(nodes, parent, opts); | ||
}; | ||
} | ||
_proto.printList = function printList(items, parent, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
printList(items, parent, opts = {}) { | ||
if (opts.separator == null) { | ||
@@ -454,5 +442,5 @@ opts.separator = commaSeparator; | ||
return this.printJoin(items, parent, opts); | ||
}; | ||
} | ||
_proto._printNewline = function _printNewline(leading, node, parent, opts) { | ||
_printNewline(leading, node, parent, opts) { | ||
if (this.format.retainLines || this.format.compact) return; | ||
@@ -465,3 +453,3 @@ | ||
var lines = 0; | ||
let lines = 0; | ||
@@ -471,3 +459,3 @@ if (this._buf.hasContent()) { | ||
if (opts.addNewlines) lines += opts.addNewlines(leading, node) || 0; | ||
var needs = leading ? n.needsWhitespaceBefore : n.needsWhitespaceAfter; | ||
const needs = leading ? n.needsWhitespaceBefore : n.needsWhitespaceAfter; | ||
if (needs(node, parent)) lines++; | ||
@@ -477,11 +465,9 @@ } | ||
this.newline(lines); | ||
}; | ||
} | ||
_proto._getComments = function _getComments(leading, node) { | ||
_getComments(leading, node) { | ||
return node && (leading ? node.leadingComments : node.trailingComments) || []; | ||
}; | ||
} | ||
_proto._printComment = function _printComment(comment) { | ||
var _this2 = this; | ||
_printComment(comment) { | ||
if (!this.format.shouldPrintComment(comment.value)) return; | ||
@@ -498,49 +484,35 @@ if (comment.ignore) return; | ||
var isBlockComment = comment.type === "CommentBlock"; | ||
const isBlockComment = comment.type === "CommentBlock"; | ||
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 + "*/"; | ||
let val = !isBlockComment && !this._noLineTerminator ? `//${comment.value}\n` : `/*${comment.value}*/`; | ||
if (isBlockComment && this.format.indent.adjustMultilineComment) { | ||
var offset = comment.loc && comment.loc.start.column; | ||
const offset = comment.loc && comment.loc.start.column; | ||
if (offset) { | ||
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g"); | ||
const newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g"); | ||
val = val.replace(newlineRegex, "\n"); | ||
} | ||
var indentSize = Math.max(this._getIndent().length, this._buf.getCurrentColumn()); | ||
val = val.replace(/\n(?!$)/g, "\n" + (0, _repeat.default)(" ", indentSize)); | ||
const indentSize = Math.max(this._getIndent().length, this._buf.getCurrentColumn()); | ||
val = val.replace(/\n(?!$)/g, `\n${(0, _repeat().default)(" ", indentSize)}`); | ||
} | ||
if (this.endsWith("/")) this._space(); | ||
this.withSource("start", comment.loc, function () { | ||
_this2._append(val); | ||
this.withSource("start", comment.loc, () => { | ||
this._append(val); | ||
}); | ||
this.newline(isBlockComment && !this._noLineTerminator ? 1 : 0); | ||
}; | ||
} | ||
_proto._printComments = function _printComments(comments) { | ||
_printComments(comments) { | ||
if (!comments || !comments.length) return; | ||
for (var _iterator = comments, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var _comment2 = _ref; | ||
this._printComment(_comment2); | ||
for (const comment of comments) { | ||
this._printComment(comment); | ||
} | ||
}; | ||
} | ||
return Printer; | ||
}(); | ||
} | ||
@@ -547,0 +519,0 @@ exports.default = Printer; |
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _sourceMap = _interopRequireDefault(require("source-map")); | ||
function _sourceMap() { | ||
const data = _interopRequireDefault(require("source-map")); | ||
_sourceMap = function () { | ||
return data; | ||
}; | ||
return data; | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var SourceMap = function () { | ||
function SourceMap(opts, code) { | ||
class SourceMap { | ||
constructor(opts, code) { | ||
this._cachedMap = null; | ||
@@ -18,10 +28,8 @@ this._code = code; | ||
var _proto = SourceMap.prototype; | ||
_proto.get = function get() { | ||
get() { | ||
if (!this._cachedMap) { | ||
var map = this._cachedMap = new _sourceMap.default.SourceMapGenerator({ | ||
const map = this._cachedMap = new (_sourceMap().default.SourceMapGenerator)({ | ||
sourceRoot: this._opts.sourceRoot | ||
}); | ||
var code = this._code; | ||
const code = this._code; | ||
@@ -31,3 +39,3 @@ if (typeof code === "string") { | ||
} else if (typeof code === "object") { | ||
Object.keys(code).forEach(function (sourceFileName) { | ||
Object.keys(code).forEach(sourceFileName => { | ||
map.setSourceContent(sourceFileName, code[sourceFileName]); | ||
@@ -41,9 +49,9 @@ }); | ||
return this._cachedMap.toJSON(); | ||
}; | ||
} | ||
_proto.getRawMappings = function getRawMappings() { | ||
getRawMappings() { | ||
return this._rawMappings.slice(); | ||
}; | ||
} | ||
_proto.mark = function mark(generatedLine, generatedColumn, line, column, identifierName, filename) { | ||
mark(generatedLine, generatedColumn, line, column, identifierName, filename) { | ||
if (this._lastGenLine !== generatedLine && line === null) return; | ||
@@ -72,7 +80,6 @@ | ||
}); | ||
}; | ||
} | ||
return SourceMap; | ||
}(); | ||
} | ||
exports.default = SourceMap; |
{ | ||
"name": "@babel/generator", | ||
"version": "7.0.0-beta.42", | ||
"version": "7.0.0-beta.43", | ||
"description": "Turns an AST into code.", | ||
@@ -14,3 +14,3 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"dependencies": { | ||
"@babel/types": "7.0.0-beta.42", | ||
"@babel/types": "7.0.0-beta.43", | ||
"jsesc": "^2.5.1", | ||
@@ -22,5 +22,5 @@ "lodash": "^4.2.0", | ||
"devDependencies": { | ||
"@babel/helper-fixtures": "7.0.0-beta.42", | ||
"babylon": "7.0.0-beta.42" | ||
"@babel/helper-fixtures": "7.0.0-beta.43", | ||
"babylon": "7.0.0-beta.43" | ||
} | ||
} |
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
3505
104766
+ Added@babel/types@7.0.0-beta.43(transitive)
- Removed@babel/types@7.0.0-beta.42(transitive)
Updated@babel/types@7.0.0-beta.43