buble
Advanced tools
Comparing version 0.2.1 to 0.2.2
# buble changelog | ||
## 0.2.2 | ||
* Initialise children of Property nodes | ||
* Prevent false positives with reference detection | ||
## 0.2.1 | ||
@@ -4,0 +9,0 @@ |
@@ -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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
213715
34
2206
0