@babel/generator
Advanced tools
Comparing version 7.18.9 to 7.18.10
@@ -97,3 +97,3 @@ "use strict"; | ||
function ArrayTypeAnnotation(node) { | ||
this.print(node.elementType, node); | ||
this.print(node.elementType, node, true); | ||
this.tokenChar(91); | ||
@@ -425,3 +425,3 @@ this.tokenChar(93); | ||
this.print(node.id, node); | ||
this.print(node.typeParameters, node); | ||
this.print(node.typeParameters, node, true); | ||
} | ||
@@ -781,3 +781,3 @@ | ||
function IndexedAccessType(node) { | ||
this.print(node.objectType, node); | ||
this.print(node.objectType, node, true); | ||
this.tokenChar(91); | ||
@@ -784,0 +784,0 @@ this.print(node.indexType, node); |
@@ -28,12 +28,3 @@ "use strict"; | ||
this.tokenChar(41); | ||
if (node.returnType) { | ||
if (node.type === "ArrowFunctionExpression") { | ||
this._noLineTerminator = true; | ||
this.print(node.returnType, node); | ||
this._noLineTerminator = false; | ||
} else { | ||
this.print(node.returnType, node); | ||
} | ||
} | ||
this.print(node.returnType, node, node.type === "ArrowFunctionExpression"); | ||
} | ||
@@ -40,0 +31,0 @@ |
@@ -340,4 +340,4 @@ "use strict"; | ||
function TSTypeReference(node) { | ||
this.print(node.typeName, node); | ||
this.print(node.typeParameters, node); | ||
this.print(node.typeName, node, true); | ||
this.print(node.typeParameters, node, true); | ||
} | ||
@@ -399,3 +399,3 @@ | ||
function TSArrayType(node) { | ||
this.print(node.elementType, node); | ||
this.print(node.elementType, node, true); | ||
this.token("[]"); | ||
@@ -482,3 +482,3 @@ } | ||
function TSIndexedAccessType(node) { | ||
this.print(node.objectType, node); | ||
this.print(node.objectType, node, true); | ||
this.tokenChar(91); | ||
@@ -485,0 +485,0 @@ this.print(node.indexType, node); |
@@ -26,6 +26,2 @@ "use strict"; | ||
} = _t; | ||
var WhitespaceFlag = { | ||
before: 1, | ||
after: 2 | ||
}; | ||
@@ -86,3 +82,3 @@ function crawlInternal(node, state) { | ||
if (state.hasCall && state.hasHelper || state.hasFunction) { | ||
return state.hasFunction ? WhitespaceFlag.before | WhitespaceFlag.after : WhitespaceFlag.after; | ||
return state.hasFunction ? 1 | 2 : 2; | ||
} | ||
@@ -92,3 +88,3 @@ }, | ||
SwitchCase(node, parent) { | ||
return (!!node.consequent.length || parent.cases[0] === node ? WhitespaceFlag.before : 0) | (!node.consequent.length && parent.cases[parent.cases.length - 1] === node ? WhitespaceFlag.after : 0); | ||
return (!!node.consequent.length || parent.cases[0] === node ? 1 : 0) | (!node.consequent.length && parent.cases[parent.cases.length - 1] === node ? 2 : 0); | ||
}, | ||
@@ -98,3 +94,3 @@ | ||
if (isFunction(node.left) || isFunction(node.right)) { | ||
return WhitespaceFlag.after; | ||
return 2; | ||
} | ||
@@ -105,3 +101,3 @@ }, | ||
if (isStringLiteral(node) && node.value === "use strict") { | ||
return WhitespaceFlag.after; | ||
return 2; | ||
} | ||
@@ -112,3 +108,3 @@ }, | ||
if (isFunction(node.callee) || isHelper(node)) { | ||
return WhitespaceFlag.before | WhitespaceFlag.after; | ||
return 1 | 2; | ||
} | ||
@@ -119,3 +115,3 @@ }, | ||
if (isFunction(node.callee)) { | ||
return WhitespaceFlag.before | WhitespaceFlag.after; | ||
return 1 | 2; | ||
} | ||
@@ -135,3 +131,3 @@ }, | ||
if (enabled) { | ||
return WhitespaceFlag.before | WhitespaceFlag.after; | ||
return 1 | 2; | ||
} | ||
@@ -143,3 +139,3 @@ } | ||
if (isBlockStatement(node.consequent)) { | ||
return WhitespaceFlag.before | WhitespaceFlag.after; | ||
return 1 | 2; | ||
} | ||
@@ -153,3 +149,3 @@ } | ||
if (parent.properties[0] === node) { | ||
return WhitespaceFlag.before; | ||
return 1; | ||
} | ||
@@ -162,3 +158,3 @@ }; | ||
if (parent.callProperties[0] === node && !((_parent$properties = parent.properties) != null && _parent$properties.length)) { | ||
return WhitespaceFlag.before; | ||
return 1; | ||
} | ||
@@ -171,3 +167,3 @@ }; | ||
if (parent.indexers[0] === node && !((_parent$properties2 = parent.properties) != null && _parent$properties2.length) && !((_parent$callPropertie = parent.callProperties) != null && _parent$callPropertie.length)) { | ||
return WhitespaceFlag.before; | ||
return 1; | ||
} | ||
@@ -180,3 +176,3 @@ }; | ||
if (parent.internalSlots[0] === node && !((_parent$properties3 = parent.properties) != null && _parent$properties3.length) && !((_parent$callPropertie2 = parent.callProperties) != null && _parent$callPropertie2.length) && !((_parent$indexers = parent.indexers) != null && _parent$indexers.length)) { | ||
return WhitespaceFlag.before; | ||
return 1; | ||
} | ||
@@ -187,3 +183,3 @@ }; | ||
[type].concat(FLIPPED_ALIAS_KEYS[type] || []).forEach(function (type) { | ||
const ret = amounts ? WhitespaceFlag.before | WhitespaceFlag.after : 0; | ||
const ret = amounts ? 1 | 2 : 0; | ||
@@ -190,0 +186,0 @@ nodes[type] = () => ret; |
@@ -12,11 +12,4 @@ "use strict"; | ||
var _t = require("@babel/types"); | ||
var generatorFunctions = require("./generators"); | ||
const { | ||
isProgram, | ||
isFile, | ||
isEmptyStatement | ||
} = _t; | ||
const SCIENTIFIC_NOTATION = /e/i; | ||
@@ -339,14 +332,16 @@ const ZERO_DECIMAL_INTEGER = /\.0+$/; | ||
print(node, parent) { | ||
print(node, parent, noLineTerminator) { | ||
if (!node) return; | ||
const oldConcise = this.format.concise; | ||
const nodeType = node.type; | ||
const format = this.format; | ||
const oldConcise = format.concise; | ||
if (node._compact) { | ||
this.format.concise = true; | ||
format.concise = true; | ||
} | ||
const printMethod = this[node.type]; | ||
const printMethod = this[nodeType]; | ||
if (!printMethod) { | ||
throw new ReferenceError(`unknown node of type ${JSON.stringify(node.type)} with constructor ${JSON.stringify(node == null ? void 0 : node.constructor.name)}`); | ||
if (printMethod === undefined) { | ||
throw new ReferenceError(`unknown node of type ${JSON.stringify(nodeType)} with constructor ${JSON.stringify(node.constructor.name)}`); | ||
} | ||
@@ -357,3 +352,3 @@ | ||
const oldInAux = this._insideAux; | ||
this._insideAux = !node.loc; | ||
this._insideAux = node.loc == undefined; | ||
@@ -364,3 +359,3 @@ this._maybeAddAuxComment(this._insideAux && !oldInAux); | ||
if (this.format.retainFunctionParens && node.type === "FunctionExpression" && node.extra && node.extra.parenthesized) { | ||
if (format.retainFunctionParens && nodeType === "FunctionExpression" && node.extra && node.extra.parenthesized) { | ||
shouldPrintParens = true; | ||
@@ -375,7 +370,15 @@ } else { | ||
const loc = isProgram(node) || isFile(node) ? null : node.loc; | ||
const loc = nodeType === "Program" || nodeType === "File" ? null : node.loc; | ||
this.withSource("start", loc, printMethod.bind(this, node, parent)); | ||
this._printTrailingComments(node); | ||
if (noLineTerminator && !this._noLineTerminator) { | ||
this._noLineTerminator = true; | ||
this._printTrailingComments(node); | ||
this._noLineTerminator = false; | ||
} else { | ||
this._printTrailingComments(node); | ||
} | ||
if (shouldPrintParens) this.tokenChar(41); | ||
@@ -385,3 +388,3 @@ | ||
this.format.concise = oldConcise; | ||
format.concise = oldConcise; | ||
this._insideAux = oldInAux; | ||
@@ -467,3 +470,3 @@ } | ||
if (!isEmptyStatement(node)) { | ||
if (node.type !== "EmptyStatement") { | ||
this.space(); | ||
@@ -470,0 +473,0 @@ } |
{ | ||
"name": "@babel/generator", | ||
"version": "7.18.9", | ||
"version": "7.18.10", | ||
"description": "Turns an AST into code.", | ||
@@ -22,3 +22,3 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"dependencies": { | ||
"@babel/types": "^7.18.9", | ||
"@babel/types": "^7.18.10", | ||
"@jridgewell/gen-mapping": "^0.3.2", | ||
@@ -29,3 +29,3 @@ "jsesc": "^2.5.1" | ||
"@babel/helper-fixtures": "^7.18.6", | ||
"@babel/parser": "^7.18.9", | ||
"@babel/parser": "^7.18.10", | ||
"@jridgewell/trace-mapping": "^0.3.8", | ||
@@ -32,0 +32,0 @@ "@types/jsesc": "^2.5.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
124161
4378
Updated@babel/types@^7.18.10