@babel/generator
Advanced tools
Comparing version 7.24.7 to 7.24.8
@@ -281,8 +281,2 @@ "use strict"; | ||
} | ||
withSource(prop, loc, cb) { | ||
if (this._map) { | ||
this.source(prop, loc); | ||
} | ||
cb(); | ||
} | ||
_normalizePosition(prop, loc, columnOffset) { | ||
@@ -289,0 +283,0 @@ const pos = loc[prop]; |
@@ -51,5 +51,7 @@ "use strict"; | ||
} | ||
const exit = this.enterForStatementInit(false); | ||
this.printSequence(node.body, node, { | ||
indent: true | ||
}); | ||
exit(); | ||
this.rightBrace(node); | ||
@@ -56,0 +58,0 @@ } |
@@ -61,5 +61,7 @@ "use strict"; | ||
this.newline(); | ||
const exit = this.enterForStatementInit(false); | ||
this.printSequence(node.body, node, { | ||
indent: true | ||
}); | ||
exit(); | ||
if (!this.endsWith(10)) this.newline(); | ||
@@ -66,0 +68,0 @@ this.rightBrace(node); |
@@ -34,3 +34,2 @@ "use strict"; | ||
var _t = require("@babel/types"); | ||
var n = require("../node/index.js"); | ||
const { | ||
@@ -103,3 +102,5 @@ isCallExpression, | ||
this.tokenChar(40); | ||
const exit = this.enterForStatementInit(false); | ||
this.printList(node.arguments, node); | ||
exit(); | ||
this.rightParens(node); | ||
@@ -116,18 +117,2 @@ } | ||
} | ||
function isDecoratorMemberExpression(node) { | ||
switch (node.type) { | ||
case "Identifier": | ||
return true; | ||
case "MemberExpression": | ||
return !node.computed && node.property.type === "Identifier" && isDecoratorMemberExpression(node.object); | ||
default: | ||
return false; | ||
} | ||
} | ||
function shouldParenthesizeDecoratorExpression(node) { | ||
if (node.type === "ParenthesizedExpression") { | ||
return false; | ||
} | ||
return !isDecoratorMemberExpression(node.type === "CallExpression" ? node.callee : node); | ||
} | ||
function _shouldPrintDecoratorsBeforeExport(node) { | ||
@@ -141,12 +126,3 @@ if (typeof this.format.decoratorsBeforeExport === "boolean") { | ||
this.tokenChar(64); | ||
const { | ||
expression | ||
} = node; | ||
if (shouldParenthesizeDecoratorExpression(expression)) { | ||
this.tokenChar(40); | ||
this.print(expression, node); | ||
this.tokenChar(41); | ||
} else { | ||
this.print(expression, node); | ||
} | ||
this.print(node.expression, node); | ||
this.newline(); | ||
@@ -191,3 +167,5 @@ } | ||
this.tokenChar(40); | ||
const exit = this.enterForStatementInit(false); | ||
this.printList(node.arguments, node); | ||
exit(); | ||
this.rightParens(node); | ||
@@ -200,3 +178,5 @@ } | ||
this.tokenChar(40); | ||
const exit = this.enterForStatementInit(false); | ||
this.printList(node.arguments, node); | ||
exit(); | ||
this.rightParens(node); | ||
@@ -245,7 +225,3 @@ } | ||
} | ||
function AssignmentExpression(node, parent) { | ||
const parens = this.inForStatementInitCounter && node.operator === "in" && !n.needsParens(node, parent); | ||
if (parens) { | ||
this.tokenChar(40); | ||
} | ||
function AssignmentExpression(node) { | ||
this.print(node.left, node); | ||
@@ -260,5 +236,2 @@ this.space(); | ||
this.print(node.right, node); | ||
if (parens) { | ||
this.tokenChar(41); | ||
} | ||
} | ||
@@ -280,5 +253,7 @@ function BindExpression(node) { | ||
if (computed) { | ||
const exit = this.enterForStatementInit(false); | ||
this.tokenChar(91); | ||
this.print(node.property, node); | ||
this.tokenChar(93); | ||
exit(); | ||
} else { | ||
@@ -285,0 +260,0 @@ this.tokenChar(46); |
@@ -32,2 +32,3 @@ "use strict"; | ||
function _parameters(parameters, parent) { | ||
const exit = this.enterForStatementInit(false); | ||
const paramLength = parameters.length; | ||
@@ -41,2 +42,3 @@ for (let i = 0; i < paramLength; i++) { | ||
} | ||
exit(); | ||
} | ||
@@ -43,0 +45,0 @@ function _param(parameter, parent) { |
@@ -78,5 +78,7 @@ "use strict"; | ||
this.tokenChar(40); | ||
this.inForStatementInitCounter++; | ||
this.print(node.init, node); | ||
this.inForStatementInitCounter--; | ||
{ | ||
const exit = this.enterForStatementInit(true); | ||
this.print(node.init, node); | ||
exit(); | ||
} | ||
this.tokenChar(59); | ||
@@ -113,3 +115,7 @@ if (node.test) { | ||
this.tokenChar(40); | ||
this.print(node.left, node); | ||
{ | ||
const exit = isForOf ? null : this.enterForStatementInit(true); | ||
this.print(node.left, node); | ||
exit == null || exit(); | ||
} | ||
this.space(); | ||
@@ -239,3 +245,9 @@ this.word(isForOf ? "of" : "in"); | ||
} = node; | ||
this.word(kind, kind === "using" || kind === "await using"); | ||
if (kind === "await using") { | ||
this.word("await"); | ||
this.space(); | ||
this.word("using", true); | ||
} else { | ||
this.word(kind, kind === "using"); | ||
} | ||
this.space(); | ||
@@ -242,0 +254,0 @@ let hasInits = false; |
@@ -48,2 +48,3 @@ "use strict"; | ||
if (props.length) { | ||
const exit = this.enterForStatementInit(false); | ||
this.space(); | ||
@@ -55,2 +56,3 @@ this.printList(props, node, { | ||
this.space(); | ||
exit(); | ||
} | ||
@@ -90,2 +92,3 @@ this.sourceWithOffset("end", node.loc, -1); | ||
this.tokenChar(91); | ||
const exit = this.enterForStatementInit(false); | ||
for (let i = 0; i < elems.length; i++) { | ||
@@ -101,2 +104,3 @@ const elem = elems[i]; | ||
} | ||
exit(); | ||
this.tokenChar(93); | ||
@@ -103,0 +107,0 @@ } |
@@ -16,5 +16,7 @@ "use strict"; | ||
isCallExpression, | ||
isDecorator, | ||
isExpressionStatement, | ||
isMemberExpression, | ||
isNewExpression | ||
isNewExpression, | ||
isParenthesizedExpression | ||
} = _t; | ||
@@ -25,5 +27,5 @@ function expandAliases(obj) { | ||
const fn = map.get(type); | ||
map.set(type, fn ? function (node, parent, stack) { | ||
map.set(type, fn ? function (node, parent, stack, inForInit) { | ||
var _fn; | ||
return (_fn = fn(node, parent, stack)) != null ? _fn : func(node, parent, stack); | ||
return (_fn = fn(node, parent, stack, inForInit)) != null ? _fn : func(node, parent, stack, inForInit); | ||
} : func); | ||
@@ -69,3 +71,3 @@ } | ||
} | ||
function needsParens(node, parent, printStack) { | ||
function needsParens(node, parent, printStack, inForInit) { | ||
var _expandedParens$get; | ||
@@ -76,5 +78,18 @@ if (!parent) return false; | ||
} | ||
return (_expandedParens$get = expandedParens.get(node.type)) == null ? void 0 : _expandedParens$get(node, parent, printStack); | ||
if (isDecorator(parent)) { | ||
return !isDecoratorMemberExpression(node) && !(isCallExpression(node) && isDecoratorMemberExpression(node.callee)) && !isParenthesizedExpression(node); | ||
} | ||
return (_expandedParens$get = expandedParens.get(node.type)) == null ? void 0 : _expandedParens$get(node, parent, printStack, inForInit); | ||
} | ||
function isDecoratorMemberExpression(node) { | ||
switch (node.type) { | ||
case "Identifier": | ||
return true; | ||
case "MemberExpression": | ||
return !node.computed && node.property.type === "Identifier" && isDecoratorMemberExpression(node.object); | ||
default: | ||
return false; | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -115,8 +115,4 @@ "use strict"; | ||
} | ||
function BinaryExpression(node, parent) { | ||
if (node.operator === "in") { | ||
const parentType = parent.type; | ||
return parentType === "VariableDeclarator" || parentType === "ForStatement" || parentType === "ForInStatement" || parentType === "ForOfStatement"; | ||
} | ||
return false; | ||
function BinaryExpression(node, parent, stack, inForStatementInit) { | ||
return node.operator === "in" && inForStatementInit; | ||
} | ||
@@ -132,3 +128,3 @@ function SequenceExpression(node, parent) { | ||
const parentType = parent.type; | ||
return parentType === "BinaryExpression" || parentType === "LogicalExpression" || parentType === "UnaryExpression" || parentType === "SpreadElement" || hasPostfixPart(node, parent) || parentType === "AwaitExpression" && isYieldExpression(node) || parentType === "ConditionalExpression" && node === parent.test || isClassExtendsClause(node, parent); | ||
return parentType === "BinaryExpression" || parentType === "LogicalExpression" || parentType === "UnaryExpression" || parentType === "SpreadElement" || hasPostfixPart(node, parent) || parentType === "AwaitExpression" && isYieldExpression(node) || parentType === "ConditionalExpression" && node === parent.test || isClassExtendsClause(node, parent) || isTSTypeExpression(parentType); | ||
} | ||
@@ -197,3 +193,6 @@ function ClassExpression(node, parent, printStack) { | ||
} | ||
return node.name === "async" && isForOfStatement(parent) && node === parent.left; | ||
return node.name === "async" && isForOfStatement(parent, { | ||
left: node, | ||
await: false | ||
}); | ||
} | ||
@@ -200,0 +199,0 @@ function isFirstInContext(printStack, checkParam) { |
@@ -27,3 +27,3 @@ "use strict"; | ||
constructor(format, map) { | ||
this.inForStatementInitCounter = 0; | ||
this.inForStatementInit = false; | ||
this._printStack = []; | ||
@@ -47,2 +47,10 @@ this._indent = 0; | ||
} | ||
enterForStatementInit(val) { | ||
const old = this.inForStatementInit; | ||
if (old === val) return () => {}; | ||
this.inForStatementInit = val; | ||
return () => { | ||
this.inForStatementInit = old; | ||
}; | ||
} | ||
generate(ast) { | ||
@@ -180,10 +188,2 @@ this.print(ast); | ||
} | ||
withSource(prop, loc, cb) { | ||
if (!loc) { | ||
cb(); | ||
return; | ||
} | ||
this._catchUp(prop, loc); | ||
this._buf.withSource(prop, loc, cb); | ||
} | ||
sourceIdentifierName(identifierName, pos) { | ||
@@ -330,3 +330,3 @@ if (!this._buf._canMarkIdName) return; | ||
const parenthesized = (_node$extra = node.extra) == null ? void 0 : _node$extra.parenthesized; | ||
let shouldPrintParens = forceParens || parenthesized && format.retainFunctionParens && nodeType === "FunctionExpression" || needsParens(node, parent, this._printStack); | ||
let shouldPrintParens = forceParens || parenthesized && format.retainFunctionParens && nodeType === "FunctionExpression" || needsParens(node, parent, this._printStack, this.inForStatementInit); | ||
if (!shouldPrintParens && parenthesized && (_node$leadingComments = node.leadingComments) != null && _node$leadingComments.length && node.leadingComments[0].type === "CommentBlock") { | ||
@@ -348,5 +348,7 @@ const parentType = parent == null ? void 0 : parent.type; | ||
} | ||
let exitInForStatementInit; | ||
if (shouldPrintParens) { | ||
this.tokenChar(40); | ||
this._endsWithInnerRaw = false; | ||
exitInForStatementInit = this.enterForStatementInit(false); | ||
} | ||
@@ -361,2 +363,3 @@ this._lastCommentLine = 0; | ||
this._noLineTerminator = noLineTerminatorAfter; | ||
exitInForStatementInit(); | ||
} else if (noLineTerminatorAfter && !this._noLineTerminator) { | ||
@@ -363,0 +366,0 @@ this._noLineTerminator = true; |
{ | ||
"name": "@babel/generator", | ||
"version": "7.24.7", | ||
"version": "7.24.8", | ||
"description": "Turns an AST into code.", | ||
@@ -22,3 +22,3 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"dependencies": { | ||
"@babel/types": "^7.24.7", | ||
"@babel/types": "^7.24.8", | ||
"@jridgewell/gen-mapping": "^0.3.5", | ||
@@ -29,4 +29,4 @@ "@jridgewell/trace-mapping": "^0.3.25", | ||
"devDependencies": { | ||
"@babel/helper-fixtures": "^7.24.7", | ||
"@babel/parser": "^7.24.7", | ||
"@babel/helper-fixtures": "^7.24.8", | ||
"@babel/parser": "^7.24.8", | ||
"@jridgewell/sourcemap-codec": "^1.4.15", | ||
@@ -33,0 +33,0 @@ "@types/jsesc": "^2.5.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
494256
4770
Updated@babel/types@^7.24.8