Socket
Socket
Sign inDemoInstall

buble

Package Overview
Dependencies
7
Maintainers
2
Versions
109
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.17.0 to 0.17.1

5

CHANGELOG.md
# buble changelog
## 0.17.1
* Error on nested rest elements ([#31](https://github.com/Rich-Harris/buble/pull/31))
* Allow destructuring with computed properties ([#34](https://github.com/Rich-Harris/buble/pull/34))
## 0.17.0

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

4

package.json
{
"name": "buble",
"version": "0.17.0",
"version": "0.17.1",
"description": "The blazing fast, batteries-included ES2015 compiler",

@@ -65,3 +65,3 @@ "main": "dist/buble.umd.js",

"acorn-jsx": "^3.0.1",
"acorn5-object-spread": "^3.1.0",
"acorn5-object-spread": "^4.0.0",
"magic-string": "^0.22.4",

@@ -68,0 +68,0 @@ "minimist": "^1.2.0",

@@ -22,6 +22,2 @@ export default function extractNames ( node ) {

RestElement ( names, node ) {
extractors[ node.argument.type ]( names, node.argument );
},
ArrayPattern ( names, node ) {

@@ -28,0 +24,0 @@ for ( const element of node.elements ) {

@@ -12,8 +12,13 @@ import Node from '../Node.js';

let computedPropertyCount = 0;
let firstSpreadProperty = null;
let firstComputedProperty = null;
for ( let prop of this.properties ) {
for ( let i = 0; i < this.properties.length; ++i ) {
const prop = this.properties[ i ];
if ( prop.type === 'SpreadElement' ) {
spreadPropertyCount += 1;
if ( firstSpreadProperty === null ) firstSpreadProperty = i;
} else if ( prop.computed ) {
computedPropertyCount += 1;
if ( firstComputedProperty === null ) firstComputedProperty = i;
} else if ( prop.type === 'Property' ) {

@@ -30,3 +35,3 @@ regularPropertyCount += 1;

let i = this.properties.length;
if ( regularPropertyCount ) {
if ( regularPropertyCount && !computedPropertyCount ) {
while ( i-- ) {

@@ -52,4 +57,13 @@ const prop = this.properties[i];

firstPropertyStart = this.properties[0].start;
code.overwrite( this.start, firstPropertyStart, `${this.program.options.objectAssign}({}, `);
code.overwrite( this.properties[ this.properties.length - 1 ].end, this.end, ')' );
if ( !computedPropertyCount ) {
code.overwrite( this.start, firstPropertyStart, `${this.program.options.objectAssign}({}, ` );
code.overwrite( this.properties[ this.properties.length - 1 ].end, this.end, ')' );
} else if ( this.properties[0].type === "SpreadElement" ) {
code.overwrite( this.start, firstPropertyStart, `${this.program.options.objectAssign}({}, ` );
code.remove( this.end - 1, this.end );
code.appendRight( this.end, ')' );
} else {
code.prependLeft( this.start, `${this.program.options.objectAssign}(` );
code.appendRight( this.end, ')' );
}
}

@@ -63,3 +77,3 @@

if ( this.parent.type === 'VariableDeclarator' && this.parent.parent.declarations.length === 1 ) {
if ( this.parent.type === 'VariableDeclarator' && this.parent.parent.declarations.length === 1 && this.parent.id.type === 'Identifier' ) {
isSimpleAssignment = true;

@@ -75,2 +89,4 @@ name = this.parent.id.alias || this.parent.id.name; // TODO is this right?

if ( spreadPropertyCount ) isSimpleAssignment = false;
// handle block scoping

@@ -86,8 +102,7 @@ const declaration = this.findScope( false ).findDeclaration( name );

} else {
name = this.findScope( true ).createIdentifier( 'obj' );
if ( firstSpreadProperty === null || firstComputedProperty < firstSpreadProperty ) {
name = this.findScope( true ).createIdentifier( 'obj' );
const statement = this.findNearest( /(?:Statement|Declaration)$/ );
code.appendLeft( statement.end, `\n${i0}var ${name};` );
code.prependRight( this.start, `( ${name} = ` );
code.prependRight( this.start, `( ${name} = ` );
} else name = null; // We don't actually need this variable
}

@@ -98,33 +113,39 @@

let sawNonComputedProperty = false;
let isFirst = true;
for ( let i = 0; i < len; i += 1 ) {
const prop = this.properties[i];
let moveStart = i > 0 ? this.properties[ i - 1 ].end : start;
if ( prop.computed ) {
if ( prop.type === "Property" && ( prop.computed || ( lastComputedProp && !spreadPropertyCount ) ) ) {
if ( i === 0 ) moveStart = this.start + 1; // Trim leading whitespace
lastComputedProp = prop;
let moveStart = i > 0 ? this.properties[ i - 1 ].end : start;
const propId = isSimpleAssignment ? `;\n${i0}${name}` : `, ${name}`;
if ( !name ) {
name = this.findScope( true ).createIdentifier( 'obj' );
if (moveStart < prop.start) {
code.overwrite( moveStart, prop.start, propId );
const propId = name + ( prop.computed ? "" : "." );
code.appendRight( prop.start, `( ${name} = {}, ${propId}` );
} else {
code.prependRight( prop.start, propId );
const propId = ( isSimpleAssignment ? `;\n${i0}${name}` : `, ${name}` ) + ( prop.computed ? "" : "." );
if ( moveStart < prop.start ) {
code.overwrite( moveStart, prop.start, propId );
} else {
code.prependRight( prop.start, propId );
}
}
let c = prop.key.end;
while ( code.original[c] !== ']' ) c += 1;
c += 1;
if ( prop.value.start > c ) code.remove( c, prop.value.start );
code.appendLeft( c, ' = ' );
code.move( moveStart, prop.end, end );
if ( i < len - 1 && ! sawNonComputedProperty ) {
// remove trailing comma
c = prop.end;
while ( code.original[c] !== ',' ) c += 1;
code.remove( prop.end, c + 1 );
if ( prop.computed ) {
while ( code.original[c] !== ']' ) c += 1;
c += 1;
}
if ( prop.shorthand ) {
code.overwrite( prop.start, prop.key.end, code.slice( prop.start, prop.key.end ).replace( /:/, ' =' ) );
} else {
if ( prop.value.start > c ) code.remove( c, prop.value.start );
code.appendLeft( c, ' = ' );
}

@@ -134,5 +155,39 @@ if ( prop.method && transforms.conciseMethodProperty ) {

}
} else if ( prop.type === "SpreadElement" ) {
if ( name && i > 0 ) {
if ( !lastComputedProp ) {
lastComputedProp = this.properties[ i - 1 ];
}
code.appendLeft( lastComputedProp.end, `, ${name} )` );
const statement = this.findNearest( /(?:Statement|Declaration)$/ );
code.appendLeft( statement.end, `\n${i0}var ${name};` );
lastComputedProp = null;
name = null;
}
} else {
if ( !isFirst && spreadPropertyCount ) {
// We are in an Object.assign context, so we need to wrap regular properties
code.prependRight( prop.start, '{' );
code.appendLeft( prop.end, '}' );
}
sawNonComputedProperty = true;
}
if (isFirst && ( prop.type === "SpreadElement" || prop.computed ) ) {
let beginEnd = sawNonComputedProperty ? this.properties[this.properties.length - 1].end : this.end - 1;
// Trim trailing comma because it can easily become a leading comma which is illegal
if ( code.original[beginEnd] == ',' ) ++beginEnd;
const closing = code.slice( beginEnd, end );
code.prependLeft( moveStart, closing );
code.remove( beginEnd, end );
isFirst = false;
}
// Clean up some extranous whitespace
let c = prop.end;
if ( i < len - 1 && ! sawNonComputedProperty ) {
while ( code.original[c] !== ',' ) c += 1;
} else if ( i == len - 1 ) c = this.end;
code.remove( prop.end, c );
}

@@ -145,4 +200,7 @@

if ( !isSimpleAssignment ) {
if ( !isSimpleAssignment && name ) {
code.appendLeft( lastComputedProp.end, `, ${name} )` );
const statement = this.findNearest( /(?:Statement|Declaration)$/ );
code.appendLeft( statement.end, `\n${i0}var ${name};` );
}

@@ -149,0 +207,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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