Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ast-types

Package Overview
Dependencies
Maintainers
1
Versions
172
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ast-types - npm Package Compare versions

Comparing version 0.3.27 to 0.3.28

28

lib/node-path.js

@@ -100,3 +100,16 @@ var assert = require("assert");

NPp.needsParens = function() {
/**
* Determine whether this.node needs to be wrapped in parentheses in order
* for a parser to reproduce the same local AST structure.
*
* For instance, in the expression `(1 + 2) * 3`, the BinaryExpression
* whose operator is "+" needs parentheses, because `1 + 2 * 3` would
* parse differently.
*
* If assumeExpressionContext === true, we don't worry about edge cases
* like an anonymous FunctionExpression appearing lexically first in its
* enclosing statement and thus needing parentheses to avoid being parsed
* as a FunctionDeclaration with a missing name.
*/
NPp.needsParens = function(assumeExpressionContext) {
if (!this.parent)

@@ -219,10 +232,7 @@ return false;

if (n.FunctionExpression.check(node) &&
if (assumeExpressionContext !== true &&
!this.canBeFirstInStatement() &&
this.firstInStatement())
return true;
if (n.ObjectExpression.check(node) &&
this.firstInStatement())
return true;
return false;

@@ -271,2 +281,8 @@ };

NPp.canBeFirstInStatement = function() {
var node = this.node;
return !n.FunctionExpression.check(node)
&& !n.ObjectExpression.check(node);
};
NPp.firstInStatement = function() {

@@ -273,0 +289,0 @@ return firstInStatement(this);

@@ -21,3 +21,3 @@ {

],
"version": "0.3.27",
"version": "0.3.28",
"homepage": "http://github.com/benjamn/ast-types",

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

@@ -492,2 +492,20 @@ var assert = require("assert");

});
it("should support .needsParens(true)", function() {
var programPath = new NodePath(parse("(function(){})"));
var funExpPath = programPath.get("body", 0, "expression");
n.FunctionExpression.assert(funExpPath.value);
assert.strictEqual(funExpPath.needsParens(), true);
assert.strictEqual(funExpPath.canBeFirstInStatement(), false);
assert.strictEqual(funExpPath.firstInStatement(), true);
assert.strictEqual(funExpPath.needsParens(true), false);
programPath = new NodePath(parse("({ foo: 42 })"));
var objLitPath = programPath.get("body", 0, "expression");
n.ObjectExpression.assert(objLitPath.value);
assert.strictEqual(objLitPath.needsParens(), true);
assert.strictEqual(objLitPath.canBeFirstInStatement(), false);
assert.strictEqual(objLitPath.firstInStatement(), true);
assert.strictEqual(objLitPath.needsParens(true), false);
});
});

@@ -494,0 +512,0 @@

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