🚀. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more
Sign In

esrap

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esrap - npm Package Compare versions

Comparing version
2.2.8
to
2.2.9
+1
-1
package.json
{
"name": "esrap",
"version": "2.2.8",
"version": "2.2.9",
"description": "Parse in reverse",

@@ -5,0 +5,0 @@ "repository": {

@@ -1013,8 +1013,3 @@ /** @import { TSESTree } from '@typescript-eslint/types' */

if (
node.body.type === 'ObjectExpression' ||
(node.body.type === 'AssignmentExpression' && node.body.left.type === 'ObjectPattern') ||
(node.body.type === 'LogicalExpression' && node.body.left.type === 'ObjectExpression') ||
(node.body.type === 'ConditionalExpression' && node.body.test.type === 'ObjectExpression')
) {
if (arrow_concise_body_needs_wrap(node.body)) {
context.write('(');

@@ -2327,2 +2322,30 @@ context.visit(node.body);

/**
* Arrow functions with a concise body must wrap certain expressions in parentheses,
* otherwise `{` can start a block statement instead of an object literal (`as` /
* `satisfies` / `!` do not change that (e.g. `() => { x } as const`).
* @param {TSESTree.BlockStatement | TSESTree.Expression} body
* @returns {boolean}
*/
function arrow_concise_body_needs_wrap(body) {
if (body.type === 'BlockStatement') return false;
switch (body.type) {
case 'ObjectExpression':
return true;
case 'AssignmentExpression':
return body.left.type === 'ObjectPattern';
case 'LogicalExpression':
return body.left.type === 'ObjectExpression';
case 'ConditionalExpression':
return body.test.type === 'ObjectExpression';
case 'TSAsExpression':
case 'TSSatisfiesExpression':
case 'TSNonNullExpression':
return body.expression ? arrow_concise_body_needs_wrap(body.expression) : false;
default:
return false;
}
}
/**
*

@@ -2329,0 +2352,0 @@ * @param {TSESTree.Expression | TSESTree.PrivateIdentifier} node