Socket
Socket
Sign inDemoInstall

buble

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

buble - npm Package Compare versions

Comparing version 0.5.8 to 0.6.0

5

CHANGELOG.md
# buble changelog
## 0.6.0
* Strip unnecessary empty strings from template literals
* Intelligent destructuring for object patterns in parameters ([#17](https://gitlab.com/Rich-Harris/buble/issues/17))
## 0.5.8

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

2

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

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

@@ -115,4 +115,2 @@ import wrap from './wrap.js';

if ( addedStuff ) code.insert( start, `\n${indentation}` );
const key = prop.key.name;

@@ -125,3 +123,12 @@

const value = prop.value.name;
code.insert( start, `var ${value} = ${ref}.${key};` );
const declaration = this.scope.findDeclaration( value );
if ( declaration.instances.length === 1 ) {
const instance = declaration.instances[0];
code.overwrite( instance.start, instance.end, `${ref}.${key}` );
} else {
if ( addedStuff ) code.insert( start, `\n${indentation}` );
code.insert( start, `var ${value} = ${ref}.${key};` );
addedStuff = true;
}
} else if ( prop.value.type === 'AssignmentPattern' ) {

@@ -131,2 +138,4 @@ code.remove( prop.value.start, prop.value.right.start );

if ( addedStuff ) code.insert( start, `\n${indentation}` );
const value = prop.value.left.name;

@@ -137,2 +146,4 @@ code

.insert( start, ` : ${ref}_${key};` );
addedStuff = true;
}

@@ -144,3 +155,2 @@

addedStuff = true;
lastIndex = prop.end;

@@ -147,0 +157,0 @@ });

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

const ordered = this.expressions.concat( this.quasis ).sort( ( a, b ) => a.start - b.start );
let ordered = this.expressions.concat( this.quasis )
.sort( ( a, b ) => a.start - b.start || a.end - b.end )
.filter( ( node, i ) => {
// include all expressions
if ( node.type !== 'TemplateElement' ) return true;
// include all non-empty strings
if ( node.value.raw ) return true;
// exclude all empty strings not at the head
return !i;
});
// special case – we may be able to skip the first element,
// if it's the empty string, but only if the second and
// third elements aren't both expressions (since they maybe
// be numeric, and `1 + 2 + '3' === '33'`)
if ( ordered.length >= 3 ) {
const [ first, , third ] = ordered;
if ( first.type === 'TemplateElement' && first.value.raw === '' && third.type === 'TemplateElement' ) {
ordered.shift();
}
}
const parenthesise = this.parent.type !== 'AssignmentExpression' &&

@@ -19,18 +41,26 @@ this.parent.type !== 'VariableDeclarator' &&

let lastIndex = this.start;
let closeParenthesis = false;
let closeParens = false;
ordered.forEach( ( node, i ) => {
if ( node.type === 'TemplateElement' ) {
const stringified = JSON.stringify( node.value.cooked );
const replacement = ( closeParenthesis ? ')' : '' ) + ( ( node.tail && !node.value.cooked.length && i !== 0 ) ? '' : `${i ? ' + ' : ''}${stringified}` );
let replacement = '';
if ( closeParens ) replacement += ')';
if ( !node.tail || node.value.cooked.length ) {
if ( i ) replacement += ' + ';
replacement += JSON.stringify( node.value.cooked );
}
code.overwrite( lastIndex, node.end, replacement );
closeParenthesis = false;
closeParens = false;
} else {
const parenthesise = node.type !== 'Identifier'; // TODO other cases where it's safe
const open = parenthesise ? ( i ? ' + (' : '(' ) : ' + ';
code.overwrite( lastIndex, node.start, open );
let replacement = '';
if ( i ) replacement += ' + ';
if ( parenthesise ) replacement += '(';
closeParenthesis = parenthesise;
code.overwrite( lastIndex, node.start, replacement );
closeParens = parenthesise;
}

@@ -37,0 +67,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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc