Socket
Socket
Sign inDemoInstall

buble

Package Overview
Dependencies
3
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1 to 0.2.2

src/utils/isReference.js

5

CHANGELOG.md
# buble changelog
## 0.2.2
* Initialise children of Property nodes
* Prevent false positives with reference detection
## 0.2.1

@@ -4,0 +9,0 @@

57

dist/buble.es.js

@@ -322,19 +322,50 @@ import { parse } from 'acorn';

function isReference ( node, parent ) {
if ( node.type === 'MemberExpression' ) {
return !node.computed && isReference( node.object, node );
}
if ( node.type === 'Identifier' ) {
// the only time we could have an identifier node without a parent is
// if it's the entire body of a function without a block statement –
// i.e. an arrow function expression like `a => a`
if ( !parent ) return true;
// TODO is this right?
if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) {
return parent.computed || node === parent.object;
}
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
if ( parent.type === 'Property' ) return parent.computed || node === parent.value;
// disregard the `bar` in `class Foo { bar () {...} }`
if ( parent.type === 'MethodDefinition' ) return false;
// disregard the `bar` in `export { foo as bar }`
if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return;
return true;
}
}
class Identifier extends Node {
initialise () {
if ( this.name === 'arguments' && !this.findScope().contains( this.name ) ) {
const lexicalBoundary = this.findLexicalBoundary();
const arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
if ( isReference( this, this.parent ) ) {
if ( this.name === 'arguments' && !this.findScope().contains( this.name ) ) {
const lexicalBoundary = this.findLexicalBoundary();
const arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
const argumentsAlias = lexicalBoundary.getArgumentsAlias();
if ( argumentsAlias ) this.alias = argumentsAlias;
if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
const argumentsAlias = lexicalBoundary.getArgumentsAlias();
if ( argumentsAlias ) this.alias = argumentsAlias;
}
}
}
const declaration = this.findScope( false ).findDeclaration( this.name );
if ( declaration ) {
declaration.instances.push( this );
} else {
this.program.assumedGlobals[ this.name ] = true;
const declaration = this.findScope( false ).findDeclaration( this.name );
if ( declaration ) {
declaration.instances.push( this );
} else {
this.program.assumedGlobals[ this.name ] = true;
}
}

@@ -360,2 +391,4 @@ }

}
super.initialise();
}

@@ -362,0 +395,0 @@

@@ -326,19 +326,50 @@ (function (global, factory) {

function isReference ( node, parent ) {
if ( node.type === 'MemberExpression' ) {
return !node.computed && isReference( node.object, node );
}
if ( node.type === 'Identifier' ) {
// the only time we could have an identifier node without a parent is
// if it's the entire body of a function without a block statement –
// i.e. an arrow function expression like `a => a`
if ( !parent ) return true;
// TODO is this right?
if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) {
return parent.computed || node === parent.object;
}
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
if ( parent.type === 'Property' ) return parent.computed || node === parent.value;
// disregard the `bar` in `class Foo { bar () {...} }`
if ( parent.type === 'MethodDefinition' ) return false;
// disregard the `bar` in `export { foo as bar }`
if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return;
return true;
}
}
class Identifier extends Node {
initialise () {
if ( this.name === 'arguments' && !this.findScope().contains( this.name ) ) {
const lexicalBoundary = this.findLexicalBoundary();
const arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
if ( isReference( this, this.parent ) ) {
if ( this.name === 'arguments' && !this.findScope().contains( this.name ) ) {
const lexicalBoundary = this.findLexicalBoundary();
const arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
const argumentsAlias = lexicalBoundary.getArgumentsAlias();
if ( argumentsAlias ) this.alias = argumentsAlias;
if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
const argumentsAlias = lexicalBoundary.getArgumentsAlias();
if ( argumentsAlias ) this.alias = argumentsAlias;
}
}
}
const declaration = this.findScope( false ).findDeclaration( this.name );
if ( declaration ) {
declaration.instances.push( this );
} else {
this.program.assumedGlobals[ this.name ] = true;
const declaration = this.findScope( false ).findDeclaration( this.name );
if ( declaration ) {
declaration.instances.push( this );
} else {
this.program.assumedGlobals[ this.name ] = true;
}
}

@@ -364,2 +395,4 @@ }

}
super.initialise();
}

@@ -366,0 +399,0 @@

{
"name": "buble",
"version": "0.2.1",
"version": "0.2.2",
"description": "Common sense JavaScript transpilation",

@@ -5,0 +5,0 @@ "main": "dist/buble.umd.js",

import Node from '../Node.js';
import isReference from '../../utils/isReference.js';
export default class Identifier extends Node {
initialise () {
if ( this.name === 'arguments' && !this.findScope().contains( this.name ) ) {
const lexicalBoundary = this.findLexicalBoundary();
const arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
if ( isReference( this, this.parent ) ) {
if ( this.name === 'arguments' && !this.findScope().contains( this.name ) ) {
const lexicalBoundary = this.findLexicalBoundary();
const arrowFunction = this.findNearest( 'ArrowFunctionExpression' );
if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
const argumentsAlias = lexicalBoundary.getArgumentsAlias();
if ( argumentsAlias ) this.alias = argumentsAlias;
if ( arrowFunction && arrowFunction.depth > lexicalBoundary.depth ) {
const argumentsAlias = lexicalBoundary.getArgumentsAlias();
if ( argumentsAlias ) this.alias = argumentsAlias;
}
}
}
const declaration = this.findScope( false ).findDeclaration( this.name );
if ( declaration ) {
declaration.instances.push( this );
} else {
this.program.assumedGlobals[ this.name ] = true;
const declaration = this.findScope( false ).findDeclaration( this.name );
if ( declaration ) {
declaration.instances.push( this );
} else {
this.program.assumedGlobals[ this.name ] = true;
}
}

@@ -21,0 +24,0 @@ }

@@ -9,2 +9,4 @@ import Node from '../Node.js';

}
super.initialise();
}

@@ -11,0 +13,0 @@

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc