Socket
Socket
Sign inDemoInstall

@babel/generator

Package Overview
Dependencies
Maintainers
4
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/generator - npm Package Compare versions

Comparing version 7.24.10 to 7.25.0

8

lib/generators/expressions.js

@@ -34,2 +34,3 @@ "use strict";

var _t = require("@babel/types");
var _index = require("../node/index.js");
const {

@@ -208,2 +209,3 @@ isCallExpression,

function ExpressionStatement(node) {
this.tokenContext |= _index.TokenContext.expressionStatement;
this.print(node.expression, node);

@@ -214,4 +216,6 @@ this.semicolon();

this.print(node.left, node);
if (node.left.optional) this.tokenChar(63);
this.print(node.left.typeAnnotation, node);
if (node.left.type === "Identifier") {
if (node.left.optional) this.tokenChar(63);
this.print(node.left.typeAnnotation, node);
}
this.space();

@@ -218,0 +222,0 @@ this.tokenChar(61);

@@ -82,2 +82,3 @@ "use strict";

var _modules = require("./modules.js");
var _index = require("../node/index.js");
var _types2 = require("./types.js");

@@ -468,6 +469,10 @@ const {

}
function TypeAnnotation(node) {
function TypeAnnotation(node, parent) {
this.tokenChar(58);
this.space();
if (node.optional) this.tokenChar(63);
if (parent.type === "ArrowFunctionExpression") {
this.tokenContext |= _index.TokenContext.arrowFlowReturnType;
} else if (node.optional) {
this.tokenChar(63);
}
this.print(node.typeAnnotation, node);

@@ -474,0 +479,0 @@ }

@@ -15,2 +15,3 @@ "use strict";

var _t = require("@babel/types");
var _index = require("../node/index.js");
const {

@@ -130,2 +131,3 @@ isIdentifier

this.space();
this.tokenContext |= _index.TokenContext.arrowBody;
this.print(node.body, node);

@@ -132,0 +134,0 @@ }

@@ -20,2 +20,3 @@ "use strict";

var _t = require("@babel/types");
var _index = require("../node/index.js");
const {

@@ -186,2 +187,3 @@ isClassDeclaration,

this.space();
this.tokenContext |= _index.TokenContext.exportDefault;
const declar = node.declaration;

@@ -188,0 +190,0 @@ this.print(declar, node);

@@ -25,2 +25,3 @@ "use strict";

var _t = require("@babel/types");
var _index = require("../node/index.js");
const {

@@ -81,2 +82,3 @@ isFor,

const exit = this.enterForStatementInit(true);
this.tokenContext |= _index.TokenContext.forHead;
this.print(node.init, node);

@@ -118,2 +120,3 @@ exit();

const exit = isForOf ? null : this.enterForStatementInit(true);
this.tokenContext |= isForOf ? _index.TokenContext.forOfHead : _index.TokenContext.forInHead;
this.print(node.left, node);

@@ -120,0 +123,0 @@ exit == null || exit();

@@ -6,2 +6,3 @@ "use strict";

});
exports.TokenContext = void 0;
exports.needsParens = needsParens;

@@ -23,2 +24,11 @@ exports.needsWhitespace = needsWhitespace;

} = _t;
const TokenContext = exports.TokenContext = {
expressionStatement: 1,
arrowBody: 2,
exportDefault: 4,
forHead: 8,
forInHead: 16,
forOfHead: 32,
arrowFlowReturnType: 64
};
function expandAliases(obj) {

@@ -71,3 +81,3 @@ const map = new Map();

}
function needsParens(node, parent, printStack, inForInit) {
function needsParens(node, parent, tokenContext, inForInit) {
var _expandedParens$get;

@@ -81,3 +91,3 @@ if (!parent) return false;

}
return (_expandedParens$get = expandedParens.get(node.type)) == null ? void 0 : _expandedParens$get(node, parent, printStack, inForInit);
return (_expandedParens$get = expandedParens.get(node.type)) == null ? void 0 : _expandedParens$get(node, parent, tokenContext, inForInit);
}

@@ -84,0 +94,0 @@ function isDecoratorMemberExpression(node) {

@@ -31,5 +31,5 @@ "use strict";

var _t = require("@babel/types");
var _index = require("./index.js");
const {
isArrayTypeAnnotation,
isArrowFunctionExpression,
isBinaryExpression,

@@ -68,6 +68,5 @@ isCallExpression,

}
function FunctionTypeAnnotation(node, parent, printStack) {
if (printStack.length < 3) return;
function FunctionTypeAnnotation(node, parent, tokenContext) {
const parentType = parent.type;
return parentType === "UnionTypeAnnotation" || parentType === "IntersectionTypeAnnotation" || parentType === "ArrayTypeAnnotation" || parentType === "TypeAnnotation" && isArrowFunctionExpression(printStack[printStack.length - 3]);
return parentType === "UnionTypeAnnotation" || parentType === "IntersectionTypeAnnotation" || parentType === "ArrayTypeAnnotation" || Boolean(tokenContext & _index.TokenContext.arrowFlowReturnType);
}

@@ -77,7 +76,7 @@ function UpdateExpression(node, parent) {

}
function ObjectExpression(node, parent, printStack) {
return isFirstInContext(printStack, 1 | 2);
function ObjectExpression(node, parent, tokenContext) {
return Boolean(tokenContext & (_index.TokenContext.expressionStatement | _index.TokenContext.arrowBody));
}
function DoExpression(node, parent, printStack) {
return !node.async && isFirstInContext(printStack, 1);
function DoExpression(node, parent, tokenContext) {
return !node.async && Boolean(tokenContext & _index.TokenContext.expressionStatement);
}

@@ -112,2 +111,5 @@ function Binary(node, parent) {

function TSAsExpression(node, parent) {
if ((parent.type === "AssignmentExpression" || parent.type === "AssignmentPattern") && parent.left === node) {
return true;
}
if (parent.type === "BinaryExpression" && (parent.operator === "|" || parent.operator === "&") && node === parent.left) {

@@ -130,3 +132,3 @@ return true;

}
function BinaryExpression(node, parent, stack, inForStatementInit) {
function BinaryExpression(node, parent, tokenContext, inForStatementInit) {
return node.operator === "in" && inForStatementInit;

@@ -145,4 +147,4 @@ }

}
function ClassExpression(node, parent, printStack) {
return isFirstInContext(printStack, 1 | 4);
function ClassExpression(node, parent, tokenContext) {
return Boolean(tokenContext & (_index.TokenContext.expressionStatement | _index.TokenContext.exportDefault));
}

@@ -152,4 +154,4 @@ function UnaryLike(node, parent) {

}
function FunctionExpression(node, parent, printStack) {
return isFirstInContext(printStack, 1 | 4);
function FunctionExpression(node, parent, tokenContext) {
return Boolean(tokenContext & (_index.TokenContext.expressionStatement | _index.TokenContext.exportDefault));
}

@@ -189,3 +191,3 @@ function ArrowFunctionExpression(node, parent) {

}
function Identifier(node, parent, printStack) {
function Identifier(node, parent, tokenContext) {
var _node$extra;

@@ -208,3 +210,6 @@ const parentType = parent.type;

});
return isFirstInContext(printStack, isFollowedByBracket ? 1 | 8 | 16 | 32 : 32);
if (isFollowedByBracket && tokenContext & (_index.TokenContext.expressionStatement | _index.TokenContext.forHead | _index.TokenContext.forInHead)) {
return true;
}
return Boolean(tokenContext & _index.TokenContext.forOfHead);
}

@@ -216,30 +221,3 @@ return node.name === "async" && isForOfStatement(parent, {

}
function isFirstInContext(printStack, checkParam) {
const expressionStatement = checkParam & 1;
const arrowBody = checkParam & 2;
const exportDefault = checkParam & 4;
const forHead = checkParam & 8;
const forInHead = checkParam & 16;
const forOfHead = checkParam & 32;
let i = printStack.length - 1;
if (i <= 0) return;
let node = printStack[i];
i--;
let parent = printStack[i];
while (i >= 0) {
const parentType = parent.type;
if (expressionStatement && parentType === "ExpressionStatement" && parent.expression === node || exportDefault && parentType === "ExportDefaultDeclaration" && node === parent.declaration || arrowBody && parentType === "ArrowFunctionExpression" && parent.body === node || forHead && parentType === "ForStatement" && parent.init === node || forInHead && parentType === "ForInStatement" && parent.left === node || forOfHead && parentType === "ForOfStatement" && parent.left === node) {
return true;
}
if (i > 0 && (hasPostfixPart(node, parent) && parentType !== "NewExpression" || parentType === "SequenceExpression" && parent.expressions[0] === node || parentType === "UpdateExpression" && !parent.prefix || parentType === "ConditionalExpression" && parent.test === node || (parentType === "BinaryExpression" || parentType === "LogicalExpression") && parent.left === node || parentType === "AssignmentExpression" && parent.left === node || (parentType === "TSAsExpression" || parentType === "TSSatisfiesExpression") && parent.expression === node)) {
node = parent;
i--;
parent = printStack[i];
} else {
return false;
}
}
return false;
}
//# sourceMappingURL=parentheses.js.map

@@ -28,3 +28,4 @@ "use strict";

this.inForStatementInit = false;
this._printStack = [];
this.tokenContext = 0;
this._currentNode = null;
this._indent = 0;

@@ -100,2 +101,3 @@ this._indentRepeat = 0;

word(str, noLineTerminatorAfter = false) {
this.tokenContext = 0;
this._maybePrintInnerComments();

@@ -122,2 +124,3 @@ if (this._endsWithWord || str.charCodeAt(0) === 47 && this.endsWith(47)) {

token(str, maybeNewline = false) {
this.tokenContext = 0;
this._maybePrintInnerComments();

@@ -134,2 +137,3 @@ const lastChar = this.getLastChar();

tokenChar(char) {
this.tokenContext = 0;
this._maybePrintInnerComments();

@@ -326,3 +330,4 @@ const lastChar = this.getLastChar();

}
this._printStack.push(node);
const oldNode = this._currentNode;
this._currentNode = node;
const oldInAux = this._insideAux;

@@ -332,3 +337,3 @@ this._insideAux = node.loc == null;

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, this.inForStatementInit);
let shouldPrintParens = forceParens || parenthesized && format.retainFunctionParens && nodeType === "FunctionExpression" || needsParens(node, parent, this.tokenContext, this.inForStatementInit);
if (!shouldPrintParens && parenthesized && (_node$leadingComments = node.leadingComments) != null && _node$leadingComments.length && node.leadingComments[0].type === "CommentBlock") {

@@ -371,3 +376,3 @@ const parentType = parent == null ? void 0 : parent.type;

}
this._printStack.pop();
this._currentNode = oldNode;
format.concise = oldConcise;

@@ -488,3 +493,3 @@ this._insideAux = oldInAux;

printInnerComments() {
const node = this._printStack[this._printStack.length - 1];
const node = this._currentNode;
const comments = node.innerComments;

@@ -491,0 +496,0 @@ if (!(comments != null && comments.length)) return;

{
"name": "@babel/generator",
"version": "7.24.10",
"version": "7.25.0",
"description": "Turns an AST into code.",

@@ -22,3 +22,3 @@ "author": "The Babel Team (https://babel.dev/team)",

"dependencies": {
"@babel/types": "^7.24.9",
"@babel/types": "^7.25.0",
"@jridgewell/gen-mapping": "^0.3.5",

@@ -30,3 +30,3 @@ "@jridgewell/trace-mapping": "^0.3.25",

"@babel/helper-fixtures": "^7.24.8",
"@babel/parser": "^7.24.8",
"@babel/parser": "^7.25.0",
"@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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc