Socket
Socket
Sign inDemoInstall

buble

Package Overview
Dependencies
Maintainers
3
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.19.6 to 0.19.7

src/program/types/AwaitExpression.js

92

CHANGELOG.md
# buble changelog
## 0.19.7 (2019-03-11)
* Throw error on dynamic import expression if transform is not disabled
* Throw error on async and await if transform is not disabled
* Allow await outside of functions
* Don't bundle acorn dependencies ([#165](https://github.com/bublejs/buble/pull/165))
* Inline spread elements where possible ([#179](https://github.com/bublejs/buble/pull/179))
* Correctly handle operator precedence for array spread ([#177](https://github.com/bublejs/buble/issues/177))
* Correctly pass-through async arrow functions and methods ([#109](https://github.com/bublejs/buble/issues/109), [#146](https://github.com/bublejs/buble/issues/146))
* Move repository to https://github.com/bublejs/buble
* Exclude non-string keys from rest properties ([#149](https://github.com/bublejs/buble/issues/149))
## 0.19.6 (2018-10-23)
* Fix class expressions with heritage in arrow functions ([#150](https://github.com/Rich-Harris/buble/issues/150))
* Fix class expressions with heritage in arrow functions ([#150](https://github.com/bublejs/buble/issues/150))
* Support `objectAssign: true` in API as a short-hand for `objectAssign: "Object.assign"`
* Bundle all acorn dependencies (for now), but no others ([#159](https://github.com/Rich-Harris/buble/issues/159))
* Bundle all acorn dependencies (for now), but no others ([#159](https://github.com/bublejs/buble/issues/159))

@@ -15,12 +27,12 @@ ## 0.19.5 (2018-10-16)

* Allow disabling spread properties transpiling
* Fix specific edge case with spread and computed properties ([#139](https://github.com/Rich-Harris/buble/issues/139))
* Fix specific edge case with spread and computed properties ([#139](https://github.com/bublejs/buble/issues/139))
* Allow global `return` statements
* Don't create unnecessary `this` aliases with loops ([#120](https://github.com/Rich-Harris/buble/issues/120))
* Don't allow getters and setters if IE8 is transpile target ([#20](https://github.com/Rich-Harris/buble/issues/20))
* Don't create unnecessary `this` aliases with loops ([#120](https://github.com/bublejs/buble/issues/120))
* Don't allow getters and setters if IE8 is transpile target ([#20](https://github.com/bublejs/buble/issues/20))
## 0.19.4 (2018-10-06)
* Fix transpiling destructuring assignments in brace-less if statement's bodies ([#152](https://github.com/Rich-Harris/buble/issues/152))
* Fix transpiling const and let after brace-less if statements ([#132](https://github.com/Rich-Harris/buble/issues/132))
* Transpile binary and octal number literals if base prefix is upper-case ([#74](https://github.com/Rich-Harris/buble/issues/74))
* Fix transpiling destructuring assignments in brace-less if statement's bodies ([#152](https://github.com/bublejs/buble/issues/152))
* Fix transpiling const and let after brace-less if statements ([#132](https://github.com/bublejs/buble/issues/132))
* Transpile binary and octal number literals if base prefix is upper-case ([#74](https://github.com/bublejs/buble/issues/74))
* Mark classes as supported in Chrome 48

@@ -35,3 +47,3 @@ * Mark destructuring of arrow function arguments as not supported in Firefox < 52

* Correctly specify browser field in package.json ([#107](https://github.com/Rich-Harris/buble/issues/107))
* Correctly specify browser field in package.json ([#107](https://github.com/bublejs/buble/issues/107))
* Fix a compile error about using `super` outside of class methods

@@ -50,7 +62,7 @@ * Fix transpiling rest properties

* Add (pass-thru) support for aync generators and for-async-of
* Add support for dynamic import ([#102](https://github.com/Rich-Harris/buble/pull/102))
* Add support for JSX fragments ([#62](https://github.com/Rich-Harris/buble/issues/62))
* Add unpkg build and transpile browser build for older environments ([#93](https://github.com/Rich-Harris/buble/issues/93))
* Reuse tagged template quasis ([#67](https://github.com/Rich-Harris/buble/pull/67))
* Transpile trailing commas in new expressions ([#63](https://github.com/Rich-Harris/buble/issues/63))
* Add support for dynamic import ([#102](https://github.com/bublejs/buble/pull/102))
* Add support for JSX fragments ([#62](https://github.com/bublejs/buble/issues/62))
* Add unpkg build and transpile browser build for older environments ([#93](https://github.com/bublejs/buble/issues/93))
* Reuse tagged template quasis ([#67](https://github.com/bublejs/buble/pull/67))
* Transpile trailing commas in new expressions ([#63](https://github.com/bublejs/buble/issues/63))
* Add support for destructuring in for-in and for-of loop heads

@@ -62,4 +74,4 @@ * Add support for destructuring in catch clause params

* Don't remove commas in comments after the last argument ([#89](https://github.com/Rich-Harris/buble/issues/89))
* Support transformations involving aliasing of variables in block scopes ([#60](https://github.com/Rich-Harris/buble/issues/60))
* Don't remove commas in comments after the last argument ([#89](https://github.com/bublejs/buble/issues/89))
* Support transformations involving aliasing of variables in block scopes ([#60](https://github.com/bublejs/buble/issues/60))
* Evaluate expression only once with inline default pattern elements

@@ -69,12 +81,12 @@ * Fix nested object and array patterns, rest properties and default values in for loop heads

* Improve declaration of helper variables
* Allow modification of mutable variables that shadow a const before declaration ([#59](https://github.com/Rich-Harris/buble/issues/59))
* Allow modification of mutable variables that shadow a const before declaration ([#59](https://github.com/bublejs/buble/issues/59))
* Correctly detect modification of immutable variables through destructuring assignments
* In object methods, support destructuring declarations initialized with a variable having the same name as the method ([#86](https://github.com/Rich-Harris/buble/issues/86))
* Fix properties with string literal keys after computed properties ([#91](https://github.com/Rich-Harris/buble/pull/91))
* Fix methods after computed properties ([#101](https://github.com/Rich-Harris/buble/issues/101))
* In object methods, support destructuring declarations initialized with a variable having the same name as the method ([#86](https://github.com/bublejs/buble/issues/86))
* Fix properties with string literal keys after computed properties ([#91](https://github.com/bublejs/buble/pull/91))
* Fix methods after computed properties ([#101](https://github.com/bublejs/buble/issues/101))
* Fix short-hand generator methods
* Fix template literals in array after spread element ([#105](https://github.com/Rich-Harris/buble/issues/105))
* Fix arrow functions in array after spread element ([#100](https://github.com/Rich-Harris/buble/issues/100))
* Fix arrow functions in new expression after spread element ([#100](https://github.com/Rich-Harris/buble/issues/100))
* Restore decoding HTML entities in JSX ([#104](https://github.com/Rich-Harris/buble/issues/104))
* Fix template literals in array after spread element ([#105](https://github.com/bublejs/buble/issues/105))
* Fix arrow functions in array after spread element ([#100](https://github.com/bublejs/buble/issues/100))
* Fix arrow functions in new expression after spread element ([#100](https://github.com/bublejs/buble/issues/100))
* Restore decoding HTML entities in JSX ([#104](https://github.com/bublejs/buble/issues/104))
* Correct various entries in support matrix

@@ -84,19 +96,19 @@

* Allow anonymous functions and classes as default exports ([#37](https://github.com/Rich-Harris/buble/issues/37))
* Handle non-breaking spaces in JSX ([#46](https://github.com/Rich-Harris/buble/issues/46))
* Allow anonymous classes to be assigned to properties ([#33](https://github.com/Rich-Harris/buble/issues/33))
* Add `trailingFunctionCommas` transformation ([#50](https://github.com/Rich-Harris/buble/issues/50))
* Allow anonymous functions and classes as default exports ([#37](https://github.com/bublejs/buble/issues/37))
* Handle non-breaking spaces in JSX ([#46](https://github.com/bublejs/buble/issues/46))
* Allow anonymous classes to be assigned to properties ([#33](https://github.com/bublejs/buble/issues/33))
* Add `trailingFunctionCommas` transformation ([#50](https://github.com/bublejs/buble/issues/50))
## 0.17.3
* Move `chalk` to dependencies ([#35](https://github.com/Rich-Harris/buble/issues/35))
* Move `chalk` to dependencies ([#35](https://github.com/bublejs/buble/issues/35))
## 0.17.2
* Fix nested template literals regression ([#39](https://github.com/Rich-Harris/buble/issues/39))
* Fix nested template literals regression ([#39](https://github.com/bublejs/buble/issues/39))
## 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))
* Error on nested rest elements ([#31](https://github.com/bublejs/buble/pull/31))
* Allow destructuring with computed properties ([#34](https://github.com/bublejs/buble/pull/34))

@@ -106,13 +118,13 @@ ## 0.17.0

* Update dependencies
* Transpile arrow functions unconditionally if spread arguments need transpilation ([#22](https://github.com/Rich-Harris/buble/pull/22))
* Better object spread support ([#25](https://github.com/Rich-Harris/buble/pull/25))
* Rest properties ([#30](https://github.com/Rich-Harris/buble/pull/30))
* Fix ([#24](https://github.com/Rich-Harris/buble/pull/24))
* Transpile arrow functions unconditionally if spread arguments need transpilation ([#22](https://github.com/bublejs/buble/pull/22))
* Better object spread support ([#25](https://github.com/bublejs/buble/pull/25))
* Rest properties ([#30](https://github.com/bublejs/buble/pull/30))
* Fix ([#24](https://github.com/bublejs/buble/pull/24))
## 0.16.0
* Allow truthy dash-cased props ([#2](https://github.com/Rich-Harris/buble/pull/2))
* Make class accessors configurable ([#3](https://github.com/Rich-Harris/buble/pull/3))
* Support JSX pragma comments ([#5](https://github.com/Rich-Harris/buble/pull/5))
* Handle JSX with no spaces between attributes ([#6](https://github.com/Rich-Harris/buble/pull/6))
* Allow truthy dash-cased props ([#2](https://github.com/bublejs/buble/pull/2))
* Make class accessors configurable ([#3](https://github.com/bublejs/buble/pull/3))
* Support JSX pragma comments ([#5](https://github.com/bublejs/buble/pull/5))
* Handle JSX with no spaces between attributes ([#6](https://github.com/bublejs/buble/pull/6))

@@ -119,0 +131,0 @@ ## 0.15.2

{
"name": "buble",
"version": "0.19.6",
"version": "0.19.7",
"description": "The blazing fast, batteries-included ES2015 compiler",

@@ -30,3 +30,3 @@ "main": "dist/buble.cjs.js",

"prepublish": "npm test",
"lint": "eslint bin/ src/ test/test.js test/utils/ register.js rollup.*.js"
"lint": "eslint bin/ src/ test/test.js test/utils/ register.js rollup.*.js scripts/"
},

@@ -38,3 +38,3 @@ "bin": {

"type": "git",
"url": "git+https://github.com/Rich-Harris/buble.git"
"url": "git+https://github.com/bublejs/buble.git"
},

@@ -54,9 +54,6 @@ "keywords": [

"bugs": {
"url": "https://github.com/Rich-Harris/buble/issues"
"url": "https://github.com/bublejs/buble/issues"
},
"homepage": "https://github.com/Rich-Harris/buble#README",
"homepage": "https://github.com/bublejs/buble#README",
"devDependencies": {
"acorn": "^6.0.2",
"acorn-dynamic-import": "^4.0.0",
"acorn-jsx": "^5.0.0",
"console-group": "^0.3.3",

@@ -66,19 +63,24 @@ "eslint": "^4.19.1",

"mocha": "^5.2.0",
"rimraf": "^2.5.2",
"rimraf": "^2.6.3",
"rollup": "0.66.0",
"rollup-plugin-buble": "^0.19.2",
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-commonjs": "=9.1.8",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-node-resolve": "^3.4.0",
"rollup-pluginutils": "2.3.3",
"source-map": "^0.6.1",
"source-map-support": "^0.5.9"
"source-map-support": "^0.5.10",
"test262": "git+https://github.com/tc39/test262.git#4f1155c566a222238fd86f179c6635ecb4c289bb",
"test262-stream": "^1.2.0"
},
"dependencies": {
"chalk": "^2.4.1",
"magic-string": "^0.25.1",
"acorn": "^6.1.1",
"acorn-dynamic-import": "^4.0.0",
"acorn-jsx": "^5.0.1",
"chalk": "^2.4.2",
"magic-string": "^0.25.2",
"minimist": "^1.2.0",
"os-homedir": "^1.0.1",
"regexpu-core": "^4.2.0",
"vlq": "^1.0.0"
"regexpu-core": "^4.5.4"
}
}

@@ -1,6 +0,6 @@

var fs = require( 'fs' );
var path = require( 'path' );
var crypto = require( 'crypto' );
var homedir = require( 'os-homedir' );
var buble = require( './' );
var fs = require('fs');
var path = require('path');
var crypto = require('crypto');
var homedir = require('os-homedir');
var buble = require('./');

@@ -10,10 +10,10 @@ var original = require.extensions[ '.js' ];

var nodeVersion = /(?:0\.)?\d+/.exec( process.version )[0];
var nodeVersion = /(?:0\.)?\d+/.exec(process.version)[0];
var versions = [ '0.10', '0.12', '4', '5', '6' ];
if ( !~versions.indexOf( nodeVersion ) ) {
if ( +nodeVersion > 6 ) {
if (!~versions.indexOf(nodeVersion)) {
if (+nodeVersion > 6) {
nodeVersion = '6';
} else {
throw new Error( 'Unsupported version (' + nodeVersion + '). Please raise an issue at https://github.com/Rich-Harris/buble/issues' );
throw new Error('Unsupported version (' + nodeVersion + '). Please raise an issue at https://github.com/bublejs/buble/issues');
}

@@ -28,11 +28,11 @@ }

function mkdirp ( dir ) {
var parent = path.dirname( dir );
if ( dir === parent ) return;
mkdirp( parent );
function mkdirp (dir) {
var parent = path.dirname(dir);
if (dir === parent) return;
mkdirp(parent);
try {
fs.mkdirSync( dir );
} catch ( err ) {
if ( err.code !== 'EEXIST' ) throw err;
fs.mkdirSync(dir);
} catch (err) {
if (err.code !== 'EEXIST') throw err;
}

@@ -42,27 +42,27 @@ }

var home = homedir();
if ( home ) {
var cachedir = path.join( home, '.buble-cache', String(nodeVersion) );
mkdirp( cachedir );
fs.writeFileSync( path.join( home, '.buble-cache/README.txt' ), 'These files enable a faster startup when using buble/register. You can safely delete this folder at any time. See https://buble.surge.sh/guide/ for more information.' );
if (home) {
var cachedir = path.join(home, '.buble-cache', String(nodeVersion));
mkdirp(cachedir);
fs.writeFileSync(path.join(home, '.buble-cache/README.txt'), 'These files enable a faster startup when using buble/register. You can safely delete this folder at any time. See https://buble.surge.sh/guide/ for more information.');
}
var optionsStringified = JSON.stringify( options );
var optionsStringified = JSON.stringify(options);
require.extensions[ '.js' ] = function ( m, filename ) {
if ( nodeModulesPattern.test( filename ) ) return original( m, filename );
require.extensions[ '.js' ] = function (m, filename) {
if (nodeModulesPattern.test(filename)) return original(m, filename);
var source = fs.readFileSync( filename, 'utf-8' );
var hash = crypto.createHash( 'sha256' );
hash.update( buble.VERSION );
hash.update( optionsStringified );
hash.update( source );
var key = hash.digest( 'hex' ) + '.json';
var cachepath = path.join( cachedir, key );
var source = fs.readFileSync(filename, 'utf-8');
var hash = crypto.createHash('sha256');
hash.update(buble.VERSION);
hash.update(optionsStringified);
hash.update(source);
var key = hash.digest('hex') + '.json';
var cachepath = path.join(cachedir, key);
var compiled;
if ( cachedir ) {
if (cachedir) {
try {
compiled = JSON.parse( fs.readFileSync( cachepath, 'utf-8' ) );
} catch ( err ) {
compiled = JSON.parse(fs.readFileSync(cachepath, 'utf-8'));
} catch (err) {
// noop

@@ -72,16 +72,16 @@ }

if ( !compiled ) {
if (!compiled) {
try {
compiled = buble.transform( source, options );
compiled = buble.transform(source, options);
if ( cachedir ) {
fs.writeFileSync( cachepath, JSON.stringify( compiled ) );
if (cachedir) {
fs.writeFileSync(cachepath, JSON.stringify(compiled));
}
} catch ( err ) {
if ( err.snippet ) {
console.log( 'Error compiling ' + filename + ':\n---' );
console.log( err.snippet );
console.log( err.message );
console.log( '' );
process.exit( 1 );
} catch (err) {
if (err.snippet) {
console.log('Error compiling ' + filename + ':\n---');
console.log(err.snippet);
console.log(err.message);
console.log('');
process.exit(1);
}

@@ -93,3 +93,3 @@

m._compile( '"use strict";\n' + compiled.code, filename );
m._compile('"use strict";\n' + compiled.code, filename);
};

@@ -22,3 +22,3 @@ import { Parser } from 'acorn';

throw new Error(
`Unknown environment '${environment}'. Please raise an issue at https://github.com/Rich-Harris/buble/issues`
`Unknown environment '${environment}'. Please raise an issue at https://github.com/bublejs/buble/issues`
);

@@ -33,3 +33,3 @@

', '
)}. Please raise an issue at https://github.com/Rich-Harris/buble/issues`
)}. Please raise an issue at https://github.com/bublejs/buble/issues`
);

@@ -62,2 +62,3 @@ const support = versions[targetVersion];

sourceType: 'module',
allowAwaitOutsideFunction: true,
allowReturnOutsideFunction: true,

@@ -64,0 +65,0 @@ onComment: (block, text) => {

import Node from '../Node.js';
import spread, { isArguments } from '../../utils/spread.js';
import spread, { isArguments, inlineSpreads } from '../../utils/spread.js';

@@ -29,2 +29,3 @@ export default class ArrayExpression extends Node {

if (transforms.spreadRest) {
inlineSpreads(code, this, this.elements);
// erase trailing comma after last array element if not an array hole

@@ -31,0 +32,0 @@ if (this.elements.length) {

import Node from '../Node.js';
import CompileError from '../../utils/CompileError.js';
import removeTrailingComma from '../../utils/removeTrailingComma.js';

@@ -6,2 +7,5 @@

initialise(transforms) {
if (this.async && transforms.asyncAwait) {
CompileError.missingTransform("async arrow functions", "asyncAwait", this);
}
this.body.createScope();

@@ -12,3 +16,8 @@ super.initialise(transforms);

transpile(code, transforms) {
const naked = this.params.length === 1 && this.start === this.params[0].start;
let openParensPos = this.start;
for (let end = (this.body || this.params[0]).start - 1; code.original[openParensPos] !== '(' && openParensPos < end;) {
++openParensPos;
}
if (code.original[openParensPos] !== '(') openParensPos = -1;
const naked = openParensPos === -1;

@@ -31,8 +40,18 @@ if (transforms.arrow || this.needsArguments(transforms)) {

// standalone expression statement
const standalone = this.parent && this.parent.type === 'ExpressionStatement';
let start, text = standalone ? '!' : '';
if (this.async) text += 'async ';
text += 'function';
if (!standalone) text += ' ';
if (naked) {
start = this.params[0].start;
} else {
start = openParensPos;
}
// add function
if (this.parent && this.parent.type === 'ExpressionStatement') {
// standalone expression statement
code.prependRight(this.start, '!function');
if (start > this.start) {
code.overwrite(this.start, start, text);
} else {
code.prependRight(this.start, 'function ');
code.prependRight(this.start, text);
}

@@ -39,0 +58,0 @@ } else {

import Node from '../Node.js';
import spread, { isArguments } from '../../utils/spread.js';
import spread, { isArguments, inlineSpreads, needsParentheses } from '../../utils/spread.js';
import removeTrailingComma from '../../utils/removeTrailingComma.js';

@@ -24,2 +24,7 @@

if (transforms.spreadRest && this.arguments.length) {
inlineSpreads(code, this, this.arguments);
// this.arguments.length may have changed, must retest.
}
if (transforms.spreadRest && this.arguments.length) {
let hasSpreadElements = false;

@@ -76,3 +81,7 @@ let context;

if (this.arguments.length > 1) {
if (firstArgument.type !== 'SpreadElement') {
if (firstArgument.type === 'SpreadElement') {
if (needsParentheses(firstArgument.argument)) {
code.prependRight(firstArgument.start, `( `);
}
} else {
code.prependRight(firstArgument.start, `[ `);

@@ -90,3 +99,7 @@ }

if (firstArgument.type === 'SpreadElement') {
code.appendLeft(firstArgument.start, `${context}, `);
if (needsParentheses(firstArgument.argument)) {
code.appendLeft(firstArgument.start, `${context}, ( `);
} else {
code.appendLeft(firstArgument.start, `${context}, `);
}
} else {

@@ -93,0 +106,0 @@ code.appendLeft(firstArgument.start, `${context}, [ `);

@@ -96,5 +96,3 @@ import CompileError from '../../utils/CompileError.js';

if ((method.kind === 'get' || method.kind === 'set') && transforms.getterSetter) {
throw new CompileError(
"getters and setters are not supported. Use `transforms: { getterSetter: false }` to skip transformation and disable this error",
method);
CompileError.missingTransform("getters and setters", "getterSetter", method);
}

@@ -189,3 +187,3 @@

(isAccessor ? `.${method.kind}` : '') +
` = function` +
` = ${method.value.async ? 'async ' : ''}function` +
(method.value.generator ? '* ' : ' ') +

@@ -199,3 +197,13 @@ funcName;

code.prependRight(method.start, lhs);
let start = method.key.start;
if (method.computed && !fake_computed) {
while (code.original[start] != '[') {
--start;
}
}
if (method.start < start) {
code.overwrite(method.start, start, lhs);
} else {
code.prependRight(method.start, lhs);
}
});

@@ -202,0 +210,0 @@

@@ -5,3 +5,3 @@ import Node from '../Node.js';

initialise(transforms) {
this.name = ( this.id
this.name = (this.id
? this.id.name

@@ -16,3 +16,3 @@ : this.parent.type === 'VariableDeclarator'

? this.parent.left.property.name
: null ) || this.findScope(true).createIdentifier('anonymous');
: null) || this.findScope(true).createIdentifier('anonymous');

@@ -19,0 +19,0 @@ super.initialise(transforms);

@@ -7,5 +7,5 @@ import Node from '../Node.js';

if (transforms.moduleExport)
throw new CompileError('export is not supported', this);
CompileError.missingTransform("export", "moduleExport", this);
super.initialise(transforms);
}
}

@@ -7,5 +7,5 @@ import Node from '../Node.js';

if (transforms.moduleExport)
throw new CompileError('export is not supported', this);
CompileError.missingTransform("export", "moduleExport", this);
super.initialise(transforms);
}
}

@@ -8,6 +8,5 @@ import LoopStatement from './shared/LoopStatement.js';

if (transforms.forOf && !transforms.dangerousForOf)
throw new CompileError(
"for...of statements are not supported. Use `transforms: { forOf: false }` to skip transformation and disable this error, or `transforms: { dangerousForOf: true }` if you know what you're doing",
this
);
CompileError.missingTransform("for-of statements", "forOf", this, "dangerousForOf");
if (this.await && transforms.asyncAwait)
CompileError.missingTransform("for-await-of statements", "asyncAwait", this);
super.initialise(transforms);

@@ -14,0 +13,0 @@ }

@@ -8,4 +8,7 @@ import Node from '../Node.js';

if (this.generator && transforms.generator) {
throw new CompileError('Generators are not supported', this);
CompileError.missingTransform("generators", "generator", this);
}
if (this.async && transforms.asyncAwait) {
CompileError.missingTransform("async functions", "asyncAwait", this);
}

@@ -12,0 +15,0 @@ this.body.createScope();

@@ -8,4 +8,7 @@ import Node from '../Node.js';

if (this.generator && transforms.generator) {
throw new CompileError('Generators are not supported', this);
CompileError.missingTransform("generators", "generator", this);
}
if (this.async && transforms.asyncAwait) {
CompileError.missingTransform("async functions", "asyncAwait", this);
}

@@ -12,0 +15,0 @@ this.body.createScope();

@@ -7,5 +7,5 @@ import Node from '../Node.js';

if (transforms.moduleImport)
throw new CompileError('import is not supported', this);
CompileError.missingTransform("import", "moduleImport", this);
super.initialise(transforms);
}
}
import ArrayExpression from './ArrayExpression.js';
import ArrowFunctionExpression from './ArrowFunctionExpression.js';
import AssignmentExpression from './AssignmentExpression.js';
import AwaitExpression from './AwaitExpression.js';
import BinaryExpression from './BinaryExpression.js';

@@ -20,2 +21,3 @@ import BreakStatement from './BreakStatement.js';

import IfStatement from './IfStatement.js';
import Import from './Import.js';
import ImportDeclaration from './ImportDeclaration.js';

@@ -53,2 +55,3 @@ import ImportDefaultSpecifier from './ImportDefaultSpecifier.js';

AssignmentExpression,
AwaitExpression,
BinaryExpression,

@@ -71,2 +74,3 @@ BreakStatement,

IfStatement,
Import,
ImportDeclaration,

@@ -73,0 +77,0 @@ ImportDefaultSpecifier,

@@ -28,6 +28,3 @@ import Node from '../Node.js';

if (transforms.stickyRegExp && /y/.test(flags))
throw new CompileError(
'Regular expression sticky flag is not supported',
this
);
CompileError.missingTransform('the regular expression sticky flag', 'stickyRegExp', this);
if (transforms.unicodeRegExp && /u/.test(flags)) {

@@ -34,0 +31,0 @@ code.overwrite(

import Node from '../Node.js';
import spread, { isArguments } from '../../utils/spread.js';
import spread, { isArguments, inlineSpreads } from '../../utils/spread.js';
import removeTrailingComma from '../../utils/removeTrailingComma.js';

@@ -27,2 +27,7 @@

if (transforms.spreadRest && this.arguments.length) {
inlineSpreads(code, this, this.arguments);
// this.arguments.length may have changed, must retest.
}
if (transforms.spreadRest && this.arguments.length) {
const firstArgument = this.arguments[0];

@@ -29,0 +34,0 @@ const isNew = true;

@@ -17,4 +17,31 @@ import Node from '../Node.js';

if (prop.type === 'SpreadElement') {
spreadPropertyCount += 1;
if (firstSpreadProperty === null) firstSpreadProperty = i;
// First see if we can inline the spread, to save needing objectAssign.
const argument = prop.argument;
if (
argument.type === 'ObjectExpression' || (
argument.type === 'Literal' &&
typeof argument.value !== 'string'
)
) {
if (argument.type === 'ObjectExpression' && argument.properties.length > 0) {
// Strip the `...{` and the `}` with a possible trailing comma before it,
// leaving just the possible trailing comma after it.
code.remove(prop.start, argument.properties[0].start);
code.remove(argument.properties[argument.properties.length - 1].end, prop.end);
this.properties.splice(i, 1, ...argument.properties);
i--;
} else {
// An empty object, boolean, null, undefined, number or regexp (but NOT
// string) will spread to nothing, so just remove the element altogether,
// including a possible trailing comma.
code.remove(prop.start, i === this.properties.length - 1
? prop.end
: this.properties[i + 1].start);
this.properties.splice(i, 1);
i--;
}
} else {
spreadPropertyCount += 1;
if (firstSpreadProperty === null) firstSpreadProperty = i;
}
} else if (prop.computed && transforms.computedProperty) {

@@ -21,0 +48,0 @@ computedPropertyCount += 1;

@@ -8,5 +8,3 @@ import CompileError from '../../utils/CompileError.js';

if ((this.kind === 'get' || this.kind === 'set') && transforms.getterSetter) {
throw new CompileError(
"getters and setters are not supported. Use `transforms: { getterSetter: false }` to skip transformation and disable this error",
this);
CompileError.missingTransform("getters and setters", "getterSetter", this);
}

@@ -50,6 +48,6 @@ super.initialise(transforms);

if (this.value.generator) code.remove(this.start, this.key.start);
if (this.start < this.key.start) code.remove(this.start, this.key.start);
code.appendLeft(
this.key.end,
`: function${this.value.generator ? '*' : ''}${name}`
`: ${this.value.async ? 'async ' : ''}function${this.value.generator ? '*' : ''}${name}`
);

@@ -56,0 +54,0 @@ }

@@ -7,5 +7,5 @@ import Node from '../../Node.js';

if (transforms.moduleImport)
throw new CompileError('Modules are not supported', this);
CompileError.missingTransform('modules', 'moduleImport', this);
super.initialise(transforms);
}
}

@@ -10,5 +10,4 @@ import Node from '../Node.js';

) {
throw new CompileError(
"Tagged template strings are not supported. Use `transforms: { templateString: false }` to skip transformation and disable this error, or `transforms: { dangerousTaggedTemplateString: true }` if you know what you're doing",
this
CompileError.missingTransform(
"tagged template strings", "templateString", this, "dangerousTaggedTemplateString"
);

@@ -15,0 +14,0 @@ }

@@ -77,5 +77,5 @@ import Node from '../Node.js';

if (parenthesise) code.appendLeft(lastIndex, ')');
code.overwrite(lastIndex, this.end, "", { contentOnly: true } );
code.overwrite(lastIndex, this.end, "", { contentOnly: true });
}
}
}

@@ -30,2 +30,7 @@ import locate from './locate.js';

}
static missingTransform(feature, transformKey, node, dangerousKey = null) {
const maybeDangerous = dangerousKey ? `, or \`transforms: { ${dangerousKey}: true }\` if you know what you're doing` : '';
throw new CompileError(`Transforming ${feature} is not ${dangerousKey ? "fully supported" : "implemented"}. Use \`transforms: { ${transformKey}: false }\` to skip transformation and disable this error${maybeDangerous}.`, node);
}
}

@@ -141,9 +141,14 @@ import CompileError from '../utils/CompileError.js';

if (prop.type === 'Property') {
const isComputedKey = prop.computed || prop.key.type !== 'Identifier';
const key = isComputedKey
? code.slice(prop.key.start, prop.key.end)
: prop.key.name;
value = isComputedKey ? `${ref}[${key}]` : `${ref}.${key}`;
content = prop.value;
nonRestKeys.push(isComputedKey ? key : '"' + key + '"');
if (!prop.computed && prop.key.type === 'Identifier') {
value = `${ref}.${prop.key.name}`;
nonRestKeys.push(`"${prop.key.name}"`);
} else if (!prop.computed && prop.key.type === 'Literal') {
value = `${ref}[${prop.key.raw}]`;
nonRestKeys.push(JSON.stringify(String(prop.key.value)));
} else {
const expr = code.slice(prop.key.start, prop.key.end);
value = `${ref}[${expr}]`;
nonRestKeys.push(`String(${expr})`);
}
} else if (prop.type === 'RestElement') {

@@ -150,0 +155,0 @@ content = prop.argument;

@@ -0,1 +1,3 @@

import CompileError from './CompileError.js';
export function isArguments(node) {

@@ -5,2 +7,77 @@ return node.type === 'Identifier' && node.name === 'arguments';

export function inlineSpreads(
code,
node,
elements
) {
let i = elements.length;
while (i--) {
const element = elements[i];
if (!element || element.type !== 'SpreadElement') {
continue;
}
const argument = element.argument;
if (argument.type !== 'ArrayExpression') {
continue;
}
const subelements = argument.elements;
if (subelements.some(subelement => subelement === null)) {
// Not even going to try inlining spread arrays with holes.
// It's a lot of work (got to be VERY careful in comma counting for
// ArrayExpression, and turn blanks into undefined for
// CallExpression and NewExpression), and probably literally no one
// would ever benefit from it.
continue;
}
// We can inline it: drop the `...[` and `]` and sort out any commas.
const isLast = i === elements.length - 1;
if (subelements.length === 0) {
code.remove(
isLast && i !== 0
? elements[i - 1].end // Take the previous comma too
: element.start,
isLast
? node.end - 1 // Must remove trailing comma; element.end wouldn’t
: elements[i + 1].start);
} else {
// Strip the `...[` and the `]` with a possible trailing comma before it,
// leaving just the possible trailing comma after it.
code.remove(element.start, subelements[0].start);
code.remove(
// Strip a possible trailing comma after the last element
subelements[subelements.length - 1].end,
// And also a possible trailing comma after the spread
isLast
? node.end - 1
: element.end
);
}
elements.splice(i, 1, ...subelements);
i += subelements.length;
}
}
// Returns false if it’s safe to simply append a method call to the node,
// e.g. `a` → `a.concat()`.
//
// Returns true if it may not be and so parentheses should be employed,
// e.g. `a ? b : c` → `a ? b : c.concat()` would be wrong.
//
// This test may be overcautious; if desired it can be refined over time.
export function needsParentheses(node) {
switch (node.type) {
// Currently whitelisted are all relevant ES5 node types ('Literal' and
// 'ObjectExpression' are skipped as irrelevant for array/call spread.)
case 'ArrayExpression':
case 'CallExpression':
case 'Identifier':
case 'ParenthesizedExpression':
case 'ThisExpression':
return false;
default:
return true;
}
}
export default function spread(

@@ -51,4 +128,24 @@ code,

if (!previousElement) {
code.remove(start, element.start);
code.overwrite(element.end, elements[1].start, '.concat( ');
// We may need to parenthesize it to handle ternaries like [...a ? b : c].
let addClosingParen;
if (start !== element.start) {
if ((addClosingParen = needsParentheses(element.argument))) {
code.overwrite(start, element.start, '( ');
} else {
code.remove(start, element.start);
}
} else if (element.parent.type === 'CallExpression') {
// CallExpression inserts `( ` itself, we add the ).
// (Yeah, CallExpression did the needsParentheses call already,
// but we don’t have its result handy, so do it again. It’s cheap.)
addClosingParen = needsParentheses(element.argument);
} else {
// Should be unreachable, but doing this is more robust.
throw new CompileError(
'Unsupported spread construct, please raise an issue at https://github.com/bublejs/buble/issues',
element
);
}
code.overwrite(element.end, elements[1].start,
addClosingParen ? ' ).concat( ' : '.concat( ');
} else {

@@ -55,0 +152,0 @@ code.overwrite(previousElement.end, element.start, ' ].concat( ');

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

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