Socket
Socket
Sign inDemoInstall

babel-core

Package Overview
Dependencies
67
Maintainers
1
Versions
257
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0-beta3 to 5.0.0-beta4

lib/babel/transformation/helpers/build-runtime-transformer.js

8

bin/babel/index.js

@@ -22,3 +22,3 @@ #!/usr/bin/env node

if (option.type === "boolean" && option.default === true) {
arg = "no-" + key;
arg = "no-" + arg;
}

@@ -32,3 +32,7 @@

commander.option(arg, option.description);
var desc = [];
if (option.deprecated) desc.push("[DEPRECATED] " + option.deprecated);
if (option.description) desc.push(option.description);
commander.option(arg, desc.join(" "));
})

@@ -35,0 +39,0 @@

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

(function(global){var babelHelpers=global.babelHelpers={};babelHelpers.inherits=function(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)subClass.__proto__=superClass};babelHelpers.defaults=function(obj,defaults){var keys=Object.getOwnPropertyNames(defaults);for(var i=0;i<keys.length;i++){var key=keys[i];var value=Object.getOwnPropertyDescriptor(defaults,key);if(value&&value.configurable&&obj[key]===undefined){Object.defineProperty(obj,key,value)}}return obj};babelHelpers.createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if(descriptor.value)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();babelHelpers.createDecoratedClass=function(){function defineProperties(target,descriptors,initializers){for(var i=0;i<descriptors.length;i++){var descriptor=descriptors[i];var decorators=descriptor.decorators;var key=descriptor.key;delete descriptor.key;delete descriptor.decorators;descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor||descriptor.initializer)descriptor.writable=true;if(decorators){for(var f=0;f<decorators.length;f++){var decorator=decorators[f];if(typeof decorator==="function"){descriptor=decorator(target,key,descriptor)||descriptor}else{throw new TypeError("The decorator for method "+descriptor.key+" is of the invalid type "+typeof decorator)}}initializers[key]=descriptor.initializer}Object.defineProperty(target,key,descriptor)}}return function(Constructor,protoProps,staticProps,protoInitializers,staticInitializers){if(protoProps)defineProperties(Constructor.prototype,protoProps,protoInitializers);if(staticProps)defineProperties(Constructor,staticProps,staticInitializers);return Constructor}}();babelHelpers.taggedTemplateLiteral=function(strings,raw){return Object.freeze(Object.defineProperties(strings,{raw:{value:Object.freeze(raw)}}))};babelHelpers.taggedTemplateLiteralLoose=function(strings,raw){strings.raw=raw;return strings};babelHelpers.interopRequire=function(obj){return obj&&obj.__esModule?obj["default"]:obj};babelHelpers.toArray=function(arr){return Array.isArray(arr)?arr:Array.from(arr)};babelHelpers.toConsumableArray=function(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++)arr2[i]=arr[i];return arr2}else{return Array.from(arr)}};babelHelpers.slicedToArray=function(arr,i){if(Array.isArray(arr)){return arr}else if(Symbol.iterator in Object(arr)){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"])_i["return"]()}finally{if(_d)throw _e}}return _arr}else{throw new TypeError("Invalid attempt to destructure non-iterable instance")}};babelHelpers.slicedToArrayLoose=function(arr,i){if(Array.isArray(arr)){return arr}else if(Symbol.iterator in Object(arr)){var _arr=[];for(var _iterator=arr[Symbol.iterator](),_step;!(_step=_iterator.next()).done;){_arr.push(_step.value);if(i&&_arr.length===i)break}return _arr}else{throw new TypeError("Invalid attempt to destructure non-iterable instance")}};babelHelpers.objectWithoutProperties=function(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i]}return target};babelHelpers.hasOwn=Object.prototype.hasOwnProperty;babelHelpers.slice=Array.prototype.slice;babelHelpers.bind=Function.prototype.bind;babelHelpers.defineProperty=function(obj,key,value){return Object.defineProperty(obj,key,{value:value,enumerable:key==null||typeof Symbol=="undefined"||key.constructor!==Symbol,configurable:true,writable:true})};babelHelpers.asyncToGenerator=function(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){var callNext=step.bind(null,"next");var callThrow=step.bind(null,"throw");function step(key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(callNext,callThrow)}}callNext()})}};babelHelpers.interopRequireWildcard=function(obj){return obj&&obj.__esModule?obj:{"default":obj}};babelHelpers._typeof=function(obj){return obj&&obj.constructor===Symbol?"symbol":typeof obj};babelHelpers._extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};babelHelpers.get=function get(object,property,receiver){var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined}else{return get(parent,property,receiver)}}else if("value"in desc&&desc.writable){return desc.value}else{var getter=desc.get;if(getter===undefined){return undefined}return getter.call(receiver)}};babelHelpers.set=function set(object,property,value,receiver){var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent!==null){return set(parent,property,value,receiver)}}else if("value"in desc&&desc.writable){return desc.value=value}else{var setter=desc.set;if(setter!==undefined){return setter.call(receiver,value)}}};babelHelpers.classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}};babelHelpers.objectDestructuringEmpty=function(obj){if(obj==null)throw new TypeError("Cannot destructure undefined")};babelHelpers.temporalUndefined={};babelHelpers.temporalAssertDefined=function(val,name,undef){if(val===undef){throw new ReferenceError(name+" is not defined - temporal dead zone")}return true};babelHelpers.selfGlobal=typeof global==="undefined"?self:global})(typeof global==="undefined"?self:global);
(function(global){var babelHelpers=global.babelHelpers={};babelHelpers.inherits=function(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function, not "+typeof superClass)}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:false,writable:true,configurable:true}});if(superClass)subClass.__proto__=superClass};babelHelpers.defaults=function(obj,defaults){var keys=Object.getOwnPropertyNames(defaults);for(var i=0;i<keys.length;i++){var key=keys[i];var value=Object.getOwnPropertyDescriptor(defaults,key);if(value&&value.configurable&&obj[key]===undefined){Object.defineProperty(obj,key,value)}}return obj};babelHelpers.createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if(descriptor.value)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();babelHelpers.createDecoratedClass=function(){function defineProperties(target,descriptors,initializers){for(var i=0;i<descriptors.length;i++){var descriptor=descriptors[i];var decorators=descriptor.decorators;var key=descriptor.key;delete descriptor.key;delete descriptor.decorators;descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor||descriptor.initializer)descriptor.writable=true;if(decorators){for(var f=0;f<decorators.length;f++){var decorator=decorators[f];if(typeof decorator==="function"){descriptor=decorator(target,key,descriptor)||descriptor}else{throw new TypeError("The decorator for method "+descriptor.key+" is of the invalid type "+typeof decorator)}}if(initializers)initializers[key]=descriptor.initializer}Object.defineProperty(target,key,descriptor)}}return function(Constructor,protoProps,staticProps,protoInitializers,staticInitializers){if(protoProps)defineProperties(Constructor.prototype,protoProps,protoInitializers);if(staticProps)defineProperties(Constructor,staticProps,staticInitializers);return Constructor}}();babelHelpers.taggedTemplateLiteral=function(strings,raw){return Object.freeze(Object.defineProperties(strings,{raw:{value:Object.freeze(raw)}}))};babelHelpers.taggedTemplateLiteralLoose=function(strings,raw){strings.raw=raw;return strings};babelHelpers.interopRequire=function(obj){return obj&&obj.__esModule?obj["default"]:obj};babelHelpers.toArray=function(arr){return Array.isArray(arr)?arr:Array.from(arr)};babelHelpers.toConsumableArray=function(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++)arr2[i]=arr[i];return arr2}else{return Array.from(arr)}};babelHelpers.slicedToArray=function(arr,i){if(Array.isArray(arr)){return arr}else if(Symbol.iterator in Object(arr)){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break}}catch(err){_d=true;_e=err}finally{try{if(!_n&&_i["return"])_i["return"]()}finally{if(_d)throw _e}}return _arr}else{throw new TypeError("Invalid attempt to destructure non-iterable instance")}};babelHelpers.slicedToArrayLoose=function(arr,i){if(Array.isArray(arr)){return arr}else if(Symbol.iterator in Object(arr)){var _arr=[];for(var _iterator=arr[Symbol.iterator](),_step;!(_step=_iterator.next()).done;){_arr.push(_step.value);if(i&&_arr.length===i)break}return _arr}else{throw new TypeError("Invalid attempt to destructure non-iterable instance")}};babelHelpers.objectWithoutProperties=function(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i]}return target};babelHelpers.hasOwn=Object.prototype.hasOwnProperty;babelHelpers.slice=Array.prototype.slice;babelHelpers.bind=Function.prototype.bind;babelHelpers.defineProperty=function(obj,key,value){return Object.defineProperty(obj,key,{value:value,enumerable:key==null||typeof Symbol=="undefined"||key.constructor!==Symbol,configurable:true,writable:true})};babelHelpers.asyncToGenerator=function(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){var callNext=step.bind(null,"next");var callThrow=step.bind(null,"throw");function step(key,arg){try{var info=gen[key](arg);var value=info.value}catch(error){reject(error);return}if(info.done){resolve(value)}else{Promise.resolve(value).then(callNext,callThrow)}}callNext()})}};babelHelpers.interopRequireWildcard=function(obj){return obj&&obj.__esModule?obj:{"default":obj}};babelHelpers._typeof=function(obj){return obj&&obj.constructor===Symbol?"symbol":typeof obj};babelHelpers._extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}return target};babelHelpers.get=function get(object,property,receiver){var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent===null){return undefined}else{return get(parent,property,receiver)}}else if("value"in desc&&desc.writable){return desc.value}else{var getter=desc.get;if(getter===undefined){return undefined}return getter.call(receiver)}};babelHelpers.set=function set(object,property,value,receiver){var desc=Object.getOwnPropertyDescriptor(object,property);if(desc===undefined){var parent=Object.getPrototypeOf(object);if(parent!==null){return set(parent,property,value,receiver)}}else if("value"in desc&&desc.writable){return desc.value=value}else{var setter=desc.set;if(setter!==undefined){return setter.call(receiver,value)}}};babelHelpers.classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}};babelHelpers.objectDestructuringEmpty=function(obj){if(obj==null)throw new TypeError("Cannot destructure undefined")};babelHelpers.temporalUndefined={};babelHelpers.temporalAssertDefined=function(val,name,undef){if(val===undef){throw new ReferenceError(name+" is not defined - temporal dead zone")}return true};babelHelpers.selfGlobal=typeof global==="undefined"?self:global;babelHelpers.defaultProps=function(defaultProps,props){if(defaultProps){for(var propName in defaultProps){if(typeof props[propName]==="undefined"){props[propName]=defaultProps[propName]}}}return props}})(typeof global==="undefined"?self:global);

@@ -220,2 +220,3 @@ "use strict";

this.flow_objectTypeSemicolon();
return this.finishNode(node, "ObjectTypeIndexer");

@@ -257,2 +258,3 @@ };

node.optional = false;
this.flow_objectTypeSemicolon();
return this.finishNode(node, "ObjectTypeProperty");

@@ -265,2 +267,3 @@ };

node.value = this.flow_parseObjectTypeMethodish(valueNode);
this.flow_objectTypeSemicolon();
return this.finishNode(node, "ObjectTypeCallProperty");

@@ -315,9 +318,6 @@ };

node["static"] = isStatic;
this.flow_objectTypeSemicolon();
nodeStart.properties.push(this.finishNode(node, "ObjectTypeProperty"));
}
}
if (!this.eat(tt.semi) && this.type !== tt.braceR) {
this.unexpected();
}
}

@@ -330,2 +330,8 @@

pp.flow_objectTypeSemicolon = function () {
if (!this.eat(tt.semi) && this.type !== tt.braceR) {
this.unexpected();
}
};
pp.flow_parseGenericType = function (start, id) {

@@ -332,0 +338,0 @@ var node = this.startNodeAt(start);

@@ -487,3 +487,3 @@ "use strict";

if (this.type === tt.at) {
this.parseDecorator();
this.decorators.push(this.parseDecorator());
continue;

@@ -572,9 +572,19 @@ }

if (this.eat(tt.star)) {
this.expectContextual("from");
node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
this.semicolon();
this.checkExport(node);
return this.finishNode(node, "ExportAllDeclaration");
}
if (this.eat(tt._default)) {
if (this.options.features["es7.exportExtensions"] && this.eatContextual("as")) {
var specifier = this.startNode();
specifier.exported = this.parseIdent();
node.specifiers = [this.finishNode(specifier, "ExportNamespaceSpecifier")];
this.parseExportSpecifiersMaybe(node);
this.parseExportFrom(node);
} else {
this.parseExportFrom(node);
return this.finishNode(node, "ExportAllDeclaration");
}
} else if (this.isExportDefaultSpecifier()) {
var specifier = this.startNode();
specifier.exported = this.parseIdent(true);
node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")];
this.parseExportSpecifiersMaybe(node);
this.parseExportFrom(node);
} else if (this.eat(tt._default)) {
// export default ...

@@ -593,5 +603,3 @@ var expr = this.parseMaybeAssign();

return this.finishNode(node, "ExportDefaultDeclaration");
}
// export var|const|let|function|class ...
if (this.type.keyword || this.shouldParseExportDeclaration()) {
} else if (this.type.keyword || this.shouldParseExportDeclaration()) {
node.declaration = this.parseStatement(true);

@@ -615,2 +623,28 @@ node.specifiers = [];

pp.isExportDefaultSpecifier = function () {
if (this.type === tt.name) {
return this.value !== "type" && this.value !== "async";
}
if (this.type !== tt._default) {
return false;
}
var lookahead = this.lookahead();
return lookahead.type === tt.comma || lookahead.type === tt.name && lookahead.value === "from";
};
pp.parseExportSpecifiersMaybe = function (node) {
if (this.eat(tt.comma)) {
node.specifiers = node.specifiers.concat(this.parseExportSpecifiers());
}
};
pp.parseExportFrom = function (node) {
this.expectContextual("from");
node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected();
this.semicolon();
this.checkExport(node);
};
pp.shouldParseExportDeclaration = function () {

@@ -617,0 +651,0 @@ return this.options.features["es7.asyncFunctions"] && this.isContextual("async");

@@ -32,2 +32,3 @@ "use strict";

exports.acorn = _acorn.acorn;
exports.options = _interopRequire(require("../transformation/file/options"));
exports.Transformer = _interopRequire(require("../transformation/transformer"));

@@ -34,0 +35,0 @@ exports.transform = _interopRequire(_transformation);

@@ -16,3 +16,7 @@ "use strict";

var FILENAME = process.env.BABEL_CACHE_PATH || path.join(os.tmpdir(), "babel.json");
function getUserHome() {
return process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
}
var FILENAME = process.env.BABEL_CACHE_PATH || path.join(getUserHome() || os.tmpdir(), ".babel.json");
var data = {};

@@ -19,0 +23,0 @@

@@ -181,3 +181,3 @@ "use strict";

var runtimePackage = require("babel-runtime/package");
var version = require("../../package").version;
var version = require("../../../../package").version;
if (runtimePackage.version !== version) {

@@ -184,0 +184,0 @@ throw new ReferenceError("The verison of babel-runtime of " + runtimePackage.runtime + " that you have installed does not match the babel verison of " + version);

@@ -5,2 +5,3 @@ "use strict";

exports.ClassBody = ClassBody;
exports.ClassProperty = ClassProperty;
exports.MethodDefinition = MethodDefinition;

@@ -10,6 +11,3 @@ exports.__esModule = true;

function ClassDeclaration(node, print) {
if (node.decorators && node.decorators.length) {
print.list(node.decorators);
}
print.list(node.decorators);
this.push("class");

@@ -56,7 +54,20 @@

function MethodDefinition(node, print) {
if (node.decorators && node.decorators.length) {
print.list(node.decorators);
function ClassProperty(node, print) {
print.list(node.decorators);
if (node["static"]) this.push("static ");
print(node.key);
print(node.typeAnnotation);
if (node.value) {
this.space();
this.push("=");
this.space();
print(node.value);
}
this.semicolon();
}
function MethodDefinition(node, print) {
print.list(node.decorators);
if (node["static"]) {

@@ -63,0 +74,0 @@ this.push("static ");

@@ -8,3 +8,2 @@ "use strict";

exports.BooleanTypeAnnotation = BooleanTypeAnnotation;
exports.ClassProperty = ClassProperty;
exports.DeclareClass = DeclareClass;

@@ -55,9 +54,2 @@ exports.DeclareFunction = DeclareFunction;

function ClassProperty(node, print) {
if (node["static"]) this.push("static ");
print(node.key);
print(node.typeAnnotation);
this.semicolon();
}
function DeclareClass(node, print) {

@@ -208,9 +200,24 @@ this.push("declare class ");

function ObjectTypeAnnotation(node, print) {
var _this = this;
this.push("{");
var props = node.properties.concat(node.callProperties, node.indexers);
if (props.length) {
this.space();
print.list(props, { indent: true, separator: "; " });
print.list(props, {
separator: false,
indent: true,
iterator: function () {
if (props.length !== 1) {
_this.semicolon();
_this.space();
}
}
});
this.space();
}
this.push("}");

@@ -217,0 +224,0 @@ }

@@ -9,3 +9,5 @@ "use strict";

exports.ImportDefaultSpecifier = ImportDefaultSpecifier;
exports.ExportDefaultSpecifier = ExportDefaultSpecifier;
exports.ExportSpecifier = ExportSpecifier;
exports.ExportNamespaceSpecifier = ExportNamespaceSpecifier;
exports.ExportAllDeclaration = ExportAllDeclaration;

@@ -34,2 +36,6 @@ exports.ExportNamedDeclaration = ExportNamedDeclaration;

function ExportDefaultSpecifier(node, print) {
print(node.exported);
}
function ExportSpecifier(node, print) {

@@ -43,4 +49,14 @@ print(node.local);

function ExportNamespaceSpecifier(node, print) {
this.push("* as ");
print(node.exported);
}
function ExportAllDeclaration(node, print) {
this.push("export * from ");
this.push("export *");
if (node.exported) {
this.push(" as ");
print(node.exported);
}
this.push(" from ");
print(node.source);

@@ -64,13 +80,26 @@ this.semicolon();

if (node.declaration) {
print(node.declaration);
if (t.isStatement(node.declaration)) return;
var declar = node.declaration;
print(declar);
if (t.isStatement(declar) || t.isFunction(declar) || t.isClass(declar)) return;
} else {
this.push("{");
if (specifiers.length) {
this.space();
print.join(specifiers, { separator: ", " });
this.space();
var first = specifiers[0];
var hasSpecial = false;
if (t.isExportDefaultSpecifier(first) || t.isExportNamespaceSpecifier(first)) {
hasSpecial = true;
print(specifiers.shift());
if (specifiers.length) {
this.push(", ");
}
}
this.push("}");
if (specifiers.length || !specifiers.length && !hasSpecial) {
this.push("{");
if (specifiers.length) {
this.space();
print.join(specifiers, { separator: ", " });
this.space();
}
this.push("}");
}
if (node.source) {

@@ -94,21 +123,16 @@ this.push(" from ");

if (specfiers && specfiers.length) {
var foundImportSpecifier = false;
for (var i = 0; i < node.specifiers.length; i++) {
var spec = node.specifiers[i];
if (i > 0) {
var first = node.specifiers[0];
if (t.isImportDefaultSpecifier(first) || t.isImportNamespaceSpecifier(first)) {
print(node.specifiers.shift());
if (node.specifiers.length) {
this.push(", ");
}
if (!t.isImportDefaultSpecifier(spec) && !t.isImportNamespaceSpecifier(spec) && !foundImportSpecifier) {
foundImportSpecifier = true;
this.push("{ ");
}
print(spec);
}
if (foundImportSpecifier) {
this.push(" }");
if (node.specifiers.length) {
this.push("{");
this.space();
print.join(node.specifiers, { separator: ", " });
this.space();
this.push("}");
}

@@ -115,0 +139,0 @@

@@ -232,5 +232,7 @@ "use strict";

if (!t.isFor(parent)) {
this.semicolon();
if (t.isFor(parent)) {
if (parent.left === node || parent.init === node) return;
}
this.semicolon();
}

@@ -237,0 +239,0 @@

@@ -118,3 +118,10 @@ "use strict";

if (this.format.quotes === "single") {
val = val.slice(1, -1);
val = val.replace(/\\"/g, "\"");
val = val.replace(/'/g, "\\'");
val = "'" + val + "'";
}
this.push(val);
}

@@ -39,3 +39,3 @@ "use strict";

this.tokens = ast.tokens || [];
this.format = CodeGenerator.normalizeOptions(code, opts);
this.format = CodeGenerator.normalizeOptions(code, opts, this.tokens);
this.opts = opts;

@@ -50,3 +50,3 @@ this.ast = ast;

CodeGenerator.normalizeOptions = function normalizeOptions(code, opts) {
CodeGenerator.normalizeOptions = function normalizeOptions(code, opts, tokens) {
var style = " ";

@@ -61,2 +61,3 @@ if (code) {

compact: opts.compact,
quotes: CodeGenerator.findCommonStringDelimeter(code, tokens),
indent: {

@@ -80,2 +81,32 @@ adjustMultilineComment: true,

CodeGenerator.findCommonStringDelimeter = function findCommonStringDelimeter(code, tokens) {
var occurences = {
single: 0,
double: 0
};
var checked = 0;
for (var i = 0; i < tokens.length; i++) {
var token = tokens[i];
if (token.type.label !== "string") continue;
if (checked >= 3) continue;
var raw = code.slice(token.start, token.end);
if (raw[0] === "'") {
occurences.single++;
} else {
occurences.double++;
}
checked++;
}
if (occurences.single > occurences.double) {
return "single";
} else {
return "double";
}
};
CodeGenerator.generators = {

@@ -132,5 +163,4 @@ templateLiterals: require("./generators/template-literals"),

var opts = arguments[1] === undefined ? {} : arguments[1];
var _opts = opts;
if (!_opts.separator) _opts.separator = ", ";
if (opts.separator == null) opts.separator = ", ";
print.join(items, opts);

@@ -137,0 +167,0 @@ };

@@ -34,4 +34,6 @@ "use strict";

parseOpts.plugins.jsx = true;
parseOpts.plugins.flow = true;
if (opts.nonStandard) {
parseOpts.plugins.jsx = true;
parseOpts.plugins.flow = true;
}

@@ -38,0 +40,0 @@ var ast = acorn.parse(code, parseOpts);

@@ -32,3 +32,4 @@ "use strict";

missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues",
unsupportedOutputType: "Unsupported output type $1"
unsupportedOutputType: "Unsupported output type $1",
illegalMethodName: "Illegal method name $1"
};

@@ -35,0 +36,0 @@

@@ -30,2 +30,4 @@ "use strict";

def("DoExpression").bases("Expression").build("body").field("body", [def("Statement")]);
def("ExportDefaultDeclaration").bases("Declaration").build("declaration").field("declaration", or(def("Declaration"), def("Expression"), null));

@@ -32,0 +34,0 @@

@@ -89,3 +89,3 @@ "use strict";

File.helpers = ["inherits", "defaults", "create-class", "create-decorated-class", "tagged-template-literal", "tagged-template-literal-loose", "interop-require", "to-array", "to-consumable-array", "sliced-to-array", "sliced-to-array-loose", "object-without-properties", "has-own", "slice", "bind", "define-property", "async-to-generator", "interop-require-wildcard", "typeof", "extends", "get", "set", "class-call-check", "object-destructuring-empty", "temporal-undefined", "temporal-assert-defined", "self-global"];
File.helpers = ["inherits", "defaults", "create-class", "create-decorated-class", "tagged-template-literal", "tagged-template-literal-loose", "interop-require", "to-array", "to-consumable-array", "sliced-to-array", "sliced-to-array-loose", "object-without-properties", "has-own", "slice", "bind", "define-property", "async-to-generator", "interop-require-wildcard", "typeof", "extends", "get", "set", "class-call-check", "object-destructuring-empty", "temporal-undefined", "temporal-assert-defined", "self-global", "default-props"];
File.options = require("./options");

@@ -114,2 +114,7 @@

if (!val && option.optional) continue;
if (val && option.deprecated) {
throw new Error("Deprecated option " + key + ": " + option.deprecated);
}
if (val == null) val = option["default"] || val;

@@ -430,2 +435,3 @@

highlightCode: opts.highlightCode,
nonStandard: opts.nonStandard,
filename: opts.filename,

@@ -587,3 +593,5 @@ plugins: {}

result.map = this.mergeSourceMap(result.map);
if (result.map) {
result.map = this.mergeSourceMap(result.map);
}

@@ -590,0 +598,0 @@ if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") {

@@ -8,2 +8,3 @@ "use strict";

exports.transformerList = transformerList;
exports.number = number;
exports.boolean = boolean;

@@ -28,2 +29,6 @@ exports.booleanString = booleanString;

function number(key, val) {
return +val;
}
function boolean(key, val) {

@@ -30,0 +35,0 @@ return !!val;

{
"filename": {
"type": "string",
"description": "Filename to use when reading from stdin - this will be used in source-maps, errors etc",
"description": "filename to use when reading from stdin - this will be used in source-maps, errors etc",
"default": "unknown",

@@ -19,7 +19,14 @@ "shorthand": "f"

"moduleId": {
"description": "specify a custom name for module ids",
"type": "string"
},
"nonStandard": {
"type": "boolean",
"default": true,
"description": "enable support for JSX and Flow"
},
"highlightTheme": {
"hidden": true
"experimental": {
"deprecated": "use `--stage 0`/`{ stage: 0 }` instead"
},

@@ -43,7 +50,7 @@

"experimental": {
"description": "Enable all ES7+ transformers",
"stage": {
"description": "ECMAScript proposal stage version to allow [0-4]",
"shorthand": "e",
"type": "boolean",
"default": false
"type": "number",
"default": 2
},

@@ -53,3 +60,3 @@

"type": "transformerList",
"description": "Blacklist of transformers to NOT use",
"description": "blacklist of transformers to NOT use",
"shorthand": "b"

@@ -61,3 +68,3 @@ },

"optional": true,
"description": "Whitelist of transformers to ONLY use",
"description": "whitelist of transformers to ONLY use",
"shorthand": "l"

@@ -68,3 +75,3 @@ },

"type": "transformerList",
"description": "List of optional transformers to enable"
"description": "list of optional transformers to enable"
},

@@ -74,3 +81,3 @@

"type": "string",
"description": "Module formatter type to use [common]",
"description": "module formatter type to use [common]",
"default": "common",

@@ -83,3 +90,4 @@ "shorthand": "m"

"default": false,
"shorthand": "M"
"shorthand": "M",
"description": "insert an explicit id for modules"
},

@@ -89,3 +97,3 @@

"type": "transformerList",
"description": "List of transformers to enable loose mode ON",
"description": "list of transformers to enable loose mode ON",
"shorthand": "L"

@@ -96,3 +104,3 @@ },

"type": "string",
"description": "Custom pragma to use with JSX (same functionality as @jsx comments)",
"description": "custom pragma to use with JSX (same functionality as @jsx comments)",
"default": "React.createElement",

@@ -103,7 +111,9 @@ "shorthand": "P"

"ignore": {
"type": "list"
"type": "list",
"description": "list of glob paths to **not** compile"
},
"only": {
"type": "list"
"type": "list",
"description": "list of glob paths to **only** compile"
},

@@ -125,8 +135,10 @@

"type": "boolean",
"default": true
"default": true,
"description": "output comments in generated output"
},
"compact": {
"type": "string",
"default": "auto"
"type": "booleanstring",
"default": "auto",
"description": "do not include superfluous whitespace characters and line terminators [true|false|auto]"
},

@@ -136,3 +148,3 @@

"type": "boolean",
"description": "Keep extensions when generating module ids",
"description": "keep extensions when generating module ids",
"default": false,

@@ -145,3 +157,4 @@ "shorthand": "k"

"default": "",
"shorthand": "a"
"shorthand": "a",
"description": "attach a comment before all helper declarations and auxiliary code"
},

@@ -152,3 +165,4 @@

"default": false,
"shorthand": "r"
"shorthand": "r",
"description": "uses a reference to `babelHelpers` instead of placing helpers at the top of your code."
},

@@ -169,2 +183,3 @@

"type": "booleanString",
"description": "[true|false|inline]",
"default": false,

@@ -175,16 +190,20 @@ "shorthand": "s"

"sourceMapName": {
"type": "string"
"type": "string",
"description": "set `file` on returned source map"
},
"sourceFileName": {
"type": "string"
"type": "string",
"description": "set `sources[0]` on returned source map"
},
"sourceRoot": {
"type": "string"
"type": "string",
"description": "the root from which all sources are relative"
},
"moduleRoot": {
"type": "string"
"type": "string",
"description": "optional prefix for the AMD module formatter that will be prepend to the filename on module definitions"
}
}

@@ -157,17 +157,4 @@ "use strict";

for (var i = 0; i < node.children.length; i++) {
var child = node.children[i];
callExpr.arguments = callExpr.arguments.concat(react.buildChildren(node));
if (t.isLiteral(child) && typeof child.value === "string") {
cleanJSXElementLiteralChild(child, callExpr.arguments);
continue;
} else if (t.isJSXEmptyExpression(child)) {
continue;
}
callExpr.arguments.push(child);
}
callExpr.arguments = flatten(callExpr.arguments);
if (callExpr.arguments.length >= 3) {

@@ -181,65 +168,2 @@ callExpr._prettyCall = true;

var isStringLiteral = function isStringLiteral(node) {
return t.isLiteral(node) && isString(node.value);
};
var flatten = function flatten(args) {
var flattened = [];
var last;
for (var i = 0; i < args.length; i++) {
var arg = args[i];
if (isStringLiteral(arg) && isStringLiteral(last)) {
last.value += arg.value;
} else {
last = arg;
flattened.push(arg);
}
}
return flattened;
};
var cleanJSXElementLiteralChild = function cleanJSXElementLiteralChild(child, args) {
var lines = child.value.split(/\r\n|\n|\r/);
var lastNonEmptyLine = 0;
var i;
for (i = 0; i < lines.length; i++) {
if (lines[i].match(/[^ \t]/)) {
lastNonEmptyLine = i;
}
}
for (i = 0; i < lines.length; i++) {
var line = lines[i];
var isFirstLine = i === 0;
var isLastLine = i === lines.length - 1;
var isLastNonEmptyLine = i === lastNonEmptyLine;
// replace rendered whitespace tabs with spaces
var trimmedLine = line.replace(/\t/g, " ");
// trim whitespace touching a newline
if (!isFirstLine) {
trimmedLine = trimmedLine.replace(/^[ ]+/, "");
}
// trim whitespace touching an endline
if (!isLastLine) {
trimmedLine = trimmedLine.replace(/[ ]+$/, "");
}
if (trimmedLine) {
if (!isLastNonEmptyLine) {
trimmedLine += " ";
}
args.push(t.literal(trimmedLine));
}
}
};
// display names

@@ -246,0 +170,0 @@

@@ -71,3 +71,3 @@ "use strict";

var bindingInfo = null; // todo: proper scope not being passed in es6/classes // scope.getOwnBindingInfo(name);
var bindingInfo = scope.getOwnBindingInfo(name);

@@ -74,0 +74,0 @@ if (bindingInfo) {

@@ -5,6 +5,11 @@ "use strict";

var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
exports.isCreateClass = isCreateClass;
exports.isCompatTag = isCompatTag;
exports.buildChildren = buildChildren;
exports.__esModule = true;
var isString = _interopRequire(require("lodash/lang/isString"));
var t = _interopRequireWildcard(require("../../types"));

@@ -37,2 +42,72 @@

return tagName && /^[a-z]|\-/.test(tagName);
}
function isStringLiteral(node) {
return t.isLiteral(node) && isString(node.value);
}
function cleanJSXElementLiteralChild(child, args) {
var lines = child.value.split(/\r\n|\n|\r/);
var lastNonEmptyLine = 0;
var i;
for (i = 0; i < lines.length; i++) {
if (lines[i].match(/[^ \t]/)) {
lastNonEmptyLine = i;
}
}
var str = "";
for (i = 0; i < lines.length; i++) {
var line = lines[i];
var isFirstLine = i === 0;
var isLastLine = i === lines.length - 1;
var isLastNonEmptyLine = i === lastNonEmptyLine;
// replace rendered whitespace tabs with spaces
var trimmedLine = line.replace(/\t/g, " ");
// trim whitespace touching a newline
if (!isFirstLine) {
trimmedLine = trimmedLine.replace(/^[ ]+/, "");
}
// trim whitespace touching an endline
if (!isLastLine) {
trimmedLine = trimmedLine.replace(/[ ]+$/, "");
}
if (trimmedLine) {
if (!isLastNonEmptyLine) {
trimmedLine += " ";
}
str += trimmedLine;
}
}
if (str) args.push(t.literal(str));
}
function buildChildren(node) {
var elems = [];
for (var i = 0; i < node.children.length; i++) {
var child = node.children[i];
if (t.isJSXExpressionContainer(child)) child = child.expression;
if (t.isLiteral(child) && typeof child.value === "string") {
cleanJSXElementLiteralChild(child, elems);
continue;
} else if (t.isJSXEmptyExpression(child)) {
continue;
}
elems.push(child);
}
return elems;
}

@@ -80,3 +80,6 @@ "use strict";

if (!t.isExportDefaultDeclaration(node)) {
formatter.hasNonDefaultExports = true;
var onlyDefault = node.specifiers && node.specifiers.length === 1 && t.isSpecifierDefault(node.specifiers[0]);
if (!onlyDefault) {
formatter.hasNonDefaultExports = true;
}
}

@@ -110,8 +113,10 @@

this.getLocalImports();
}
DefaultFormatter.prototype.init = function init() {
this.remapAssignments();
}
};
DefaultFormatter.prototype.doDefaultExportInterop = function doDefaultExportInterop(node) {
return t.isExportDefaultDeclaration(node) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
return (t.isExportDefaultDeclaration(node) || t.isSpecifierDefault(node)) && !this.noInteropRequireExport && !this.hasNonDefaultExports;
};

@@ -118,0 +123,0 @@

@@ -115,2 +115,6 @@ "use strict";

AMDFormatter.prototype.exportSpecifier = function exportSpecifier() {
CommonFormatter.prototype.exportSpecifier.apply(this, arguments);
};
AMDFormatter.prototype.exportDeclaration = function exportDeclaration(node) {

@@ -117,0 +121,0 @@ if (this.doDefaultExportInterop(node)) {

@@ -41,2 +41,4 @@ "use strict";

}
DefaultFormatter.prototype.init.call(this);
};

@@ -81,2 +83,13 @@

CommonJSFormatter.prototype.exportSpecifier = function exportSpecifier(specifier, node, nodes) {
if (this.doDefaultExportInterop(specifier)) {
nodes.push(util.template("exports-default-assign", {
VALUE: specifier.local
}, true));
return;
} else {
DefaultFormatter.prototype.exportSpecifier.apply(this, arguments);
}
};
CommonJSFormatter.prototype.exportDeclaration = function exportDeclaration(node, nodes) {

@@ -83,0 +96,0 @@ if (this.doDefaultExportInterop(node)) {

@@ -25,2 +25,6 @@ "use strict";

var canHoist = function canHoist(node, file) {
return node._blockHoist && !file.transformers.runtime.canTransform();
};
var hoistVariablesVisitor = {

@@ -41,3 +45,3 @@ enter: function enter(node, parent, scope, hoistDeclarators) {

// ignore block hoisted nodes as these can be left in
if (node._blockHoist) return;
if (canHoist(node, scope.file)) return;

@@ -77,3 +81,3 @@ var nodes = [];

if (t.isFunctionDeclaration(node) || node._blockHoist) {
if (t.isFunctionDeclaration(node) || canHoist(node, scope.file)) {
handlerBody.push(node);

@@ -115,3 +119,5 @@ this.remove();

SystemFormatter.prototype.init = function init() {};
SystemFormatter.prototype.init = function init() {
DefaultFormatter.prototype.init.call(this);
};

@@ -118,0 +124,0 @@ SystemFormatter.prototype._addImportSource = function _addImportSource(node, exportNode) {

@@ -44,4 +44,5 @@ "use strict";

// experimental
if (transformer.metadata.experimental && opts.experimental) return true;
// stage
var stage = transformer.metadata.stage;
if (stage != null && stage >= opts.stage) return true;

@@ -48,0 +49,0 @@ // optional

@@ -50,2 +50,6 @@ "use strict";

if (this.metadata.stage != null) {
this.metadata.optional = true;
}
this.handlers = this.normalize(transformer);

@@ -92,6 +96,2 @@

Transformer.prototype.buildPass = function buildPass(file) {
if (!(file instanceof File)) {
throw new Error("Multiple versions of babel are interacting, this is either due to a version mismatch in a plugin or it was resolved incorrectly");
}
return new TransformerPass(file, this);

@@ -98,0 +98,0 @@ };

{
"useStrict": "strict"
"useStrict": "strict",
"es5.runtime": "runtime",
"es6.runtime": "runtime"
}
{
"selfContained": "runtime",
"unicode-regex": "regex.unicode",
"spec.typeofSymbol": "es6.symbols",
"spec.typeofSymbol": "es6.spec.symbols",
"es6.symbols": "es6.spec.symbols",
"es6.blockScopingTDZ": "es6.spec.blockScoping",

@@ -6,0 +8,0 @@ "minification.deadCodeElimination": "utility.deadCodeElimination",

@@ -67,3 +67,3 @@ "use strict";

if (isLetInitable(node) && file.transformers["es6.blockScopingTDZ"].canTransform()) {
if (isLetInitable(node) && file.transformers["es6.spec.blockScoping"].canTransform()) {
var nodes = [node];

@@ -146,2 +146,5 @@

// not a part of our scope
if (!state.letReferences[node.name]) return;
// this scope has a variable with the same name so it couldn't belong

@@ -151,5 +154,2 @@ // to our let scope

// not a part of our scope
if (!state.letReferences[node.name]) return;
state.closurify = true;

@@ -185,2 +185,14 @@ }

var continuationVisitor = {
enter: function enter(node, parent, scope, state) {
if (this.isAssignmentExpression() || this.isUpdateExpression()) {
var bindings = this.getBindingIdentifiers();
for (var name in bindings) {
if (state.outsideReferences[name] !== scope.getBindingIdentifier(name)) continue;
state.reassignments[name] = true;
}
}
}
};
var loopNodeTo = function loopNodeTo(node) {

@@ -379,2 +391,3 @@ if (t.isBreakStatement(node)) {

var params = values(outsideRefs);
var args = values(outsideRefs);

@@ -385,2 +398,5 @@ // build the closure that we're going to wrap the block with

// continuation
this.addContinuations(fn);
// replace the current block body with the one we're going to build

@@ -390,3 +406,3 @@ block.body = this.body;

// build a call and a unique id that we can assign the return value to
var call = t.callExpression(fn, params);
var call = t.callExpression(fn, args);
var ret = this.scope.generateUidIdentifier("ret");

@@ -412,2 +428,32 @@

/**
* If any of the outer let variables are reassigned then we need to rename them in
* the closure so we can get direct access to the outer variable to continue the
* iteration with bindings based on each iteration.
*
* Reference: https://github.com/babel/babel/issues/1078
*/
BlockScoping.prototype.addContinuations = function addContinuations(fn) {
var state = {
reassignments: {},
outsideReferences: this.outsideLetReferences
};
this.scope.traverse(fn, continuationVisitor, state);
for (var i = 0; i < fn.params.length; i++) {
var param = fn.params[i];
if (!state.reassignments[param.name]) continue;
var newParam = this.scope.generateUidIdentifier(param.name);
fn.params[i] = newParam;
this.scope.rename(param.name, newParam.name, fn);
// assign outer reference as it's been modified internally and needs to be retained
fn.body.body.push(t.expressionStatement(t.assignmentExpression("=", param, newParam)));
}
};
/**
* Description

@@ -568,3 +614,3 @@ */

} else {
// #998
// https://github.com/babel/babel/issues/998
for (var i = 0; i < cases.length; i++) {

@@ -571,0 +617,0 @@ var caseConsequent = cases[i].consequent[0];

@@ -31,2 +31,4 @@ "use strict";

var PROPERTY_COLLISION_METHOD_NAME = "__initializeProperties";
var check = t.isClass;

@@ -44,2 +46,16 @@

var collectPropertyReferencesVisitor = {
Identifier: {
enter: function enter(node, parent, scope, state) {
if (this.parentPath.isClassProperty({ key: node })) {
return;
}
if (this.isReferenced() && scope.getBinding(node.name) === state.scope.getBinding(node.name)) {
state.references[node.name] = true;;
}
}
}
};
var verifyConstructorVisitor = traverse.explode({

@@ -102,2 +118,3 @@ MethodDefinition: {

this.instancePropBody = [];
this.instancePropRefs = {};
this.staticPropBody = [];

@@ -262,2 +279,4 @@ this.body = [];

if (node.kind === "set") kind = "set";
t.inheritsComments(node.value, node);
map[kind] = node.value;

@@ -282,5 +301,7 @@ };

var node = classBody[i];
var path = classBodyPaths[i];
if (t.isMethodDefinition(node)) {
var isConstructor = node.kind === "constructor";
if (isConstructor) this.verifyConstructor(classBodyPaths[i]);
if (isConstructor) this.verifyConstructor(path);

@@ -300,3 +321,3 @@ var replaceSupers = new ReplaceSupers({

if (isConstructor) {
this.pushConstructor(node);
this.pushConstructor(node, path);
} else {

@@ -385,5 +406,16 @@ this.pushMethod(node);

var body = this.instancePropBody;
if (body.length) {
// todo: check for scope conflicts and shift into a method
if (!body.length) return;
if (this.hasPropertyCollision()) {
var call = t.expressionStatement(t.callExpression(t.memberExpression(t.thisExpression(), t.identifier(PROPERTY_COLLISION_METHOD_NAME)), []));
this.pushMethod(t.methodDefinition(t.identifier(PROPERTY_COLLISION_METHOD_NAME), t.functionExpression(null, [], t.blockStatement(body))), true);
if (this.hasSuper) {
this.bareSuper.insertAfter(call);
} else {
this.constructorBody.body.unshift(call);
}
} else {
if (this.hasSuper) {
if (this.hasConstructor) {

@@ -404,2 +436,18 @@ this.bareSuper.insertAfter(body);

ClassTransformer.prototype.hasPropertyCollision = function hasPropertyCollision() {
if (this.userConstructorPath) {
for (var name in this.instancePropRefs) {
if (this.userConstructorPath.scope.hasOwnBinding(name)) {
return true;
}
}
}
return false;
};
/**
* Description
*/
ClassTransformer.prototype.verifyConstructor = function verifyConstructor(path) {

@@ -426,3 +474,7 @@ var state = {

ClassTransformer.prototype.pushMethod = function pushMethod(node) {
ClassTransformer.prototype.pushMethod = function pushMethod(node, allowedIllegal) {
if (!allowedIllegal && t.isLiteral(t.toComputedKey(node), { value: PROPERTY_COLLISION_METHOD_NAME })) {
throw this.file.errorWithNode(node, messages.get("illegalMethodName", PROPERTY_COLLISION_METHOD_NAME));
}
if (node.kind === "method") {

@@ -457,2 +509,7 @@ nameMethod.property(node, this.file, this.scope);

this.scope.traverse(node, collectPropertyReferencesVisitor, {
references: this.instancePropRefs,
scope: this.scope
});
if (node.decorators) {

@@ -495,6 +552,13 @@ var body = [];

ClassTransformer.prototype.pushConstructor = function pushConstructor(method) {
ClassTransformer.prototype.pushConstructor = function pushConstructor(method, path) {
// https://github.com/babel/babel/issues/1077
var fnPath = path.get("value");
if (fnPath.scope.hasOwnBinding(this.classRef.name)) {
fnPath.scope.rename(this.classRef.name);
}
var construct = this.constructor;
var fn = method.value;
this.userConstructorPath = fnPath;
this.userConstructor = fn;

@@ -501,0 +565,0 @@ this.hasConstructor = true;

@@ -15,3 +15,3 @@ "use strict";

function check(node) {
return t.isVariableDeclaration(node, { kind: "const" });
return t.isVariableDeclaration(node, { kind: "const" }) || t.isImportDeclaration(node);
}

@@ -52,3 +52,3 @@

this.traverse(visitor, {
constants: scope.getAllBindingsOfKind("const"),
constants: scope.getAllBindingsOfKind("const", "module"),
file: file

@@ -55,0 +55,0 @@ });

@@ -77,3 +77,3 @@ "use strict";

if (file.transformers["es6.blockScopingTDZ"].canTransform() && param.isIdentifier()) {
if (file.transformers["es6.spec.blockScoping"].canTransform() && param.isIdentifier()) {
pushDefNode(param.node, t.identifier("undefined"), i);

@@ -80,0 +80,0 @@ }

@@ -203,6 +203,8 @@ "use strict";

}, this));
var statement = reduceRight(declarations, function (expr, decl) {
var assignment = reduceRight(declarations, function (expr, decl) {
return t.assignmentExpression("=", decl.id, expr);
}, t.identifier("undefined"));
body.unshift(t.expressionStatement(statement));
var statement = t.expressionStatement(assignment);
statement._blockHoist = Infinity;
body.unshift(statement);
}

@@ -209,0 +211,0 @@

@@ -12,14 +12,6 @@ "use strict";

var buildBinaryExpression = function buildBinaryExpression(left, right, file) {
return t.binaryExpression("+", left, coerce(right, file));
var buildBinaryExpression = function buildBinaryExpression(left, right) {
return t.binaryExpression("+", left, right);
};
function coerce(node, file) {
if (file.isLoose("es7.templateLiterals") || t.isLiteral(node) && typeof node.value === "string") {
return node;
} else {
return t.callExpression(t.identifier("String"), [node]);
}
}
function check(node) {

@@ -72,6 +64,6 @@ return t.isTemplateLiteral(node) || t.isTaggedTemplateExpression(node);

var root = buildBinaryExpression(nodes.shift(), nodes.shift(), file);
var root = buildBinaryExpression(nodes.shift(), nodes.shift());
for (i = 0; i < nodes.length; i++) {
root = buildBinaryExpression(root, nodes[i], file);
root = buildBinaryExpression(root, nodes[i]);
}

@@ -78,0 +70,0 @@

@@ -6,4 +6,3 @@ "use strict";

var metadata = {
experimental: true,
optional: true
stage: 1
};

@@ -10,0 +9,0 @@

@@ -6,4 +6,3 @@ "use strict";

var metadata = {
experimental: true,
optional: true
stage: 0
};

@@ -10,0 +9,0 @@

@@ -19,4 +19,3 @@ "use strict";

var metadata = {
experimental: true,
optional: true
stage: 0
};

@@ -23,0 +22,0 @@

@@ -5,5 +5,5 @@ "use strict";

var metadata = {
experimental: true,
optional: true
optional: true,
stage: 1
};
exports.metadata = metadata;

@@ -11,4 +11,4 @@ "use strict";

var metadata = {
experimental: true,
optional: true
optional: true,
stage: 0
};

@@ -15,0 +15,0 @@

@@ -7,2 +7,3 @@ "use strict";

exports.__esModule = true;
// https://github.com/rwaldron/exponentiation-operator

@@ -14,2 +15,7 @@

var metadata = {
stage: 2
};
exports.metadata = metadata;
var MATH_POW = t.memberExpression(t.identifier("Math"), t.identifier("pow"));

@@ -16,0 +22,0 @@

@@ -13,4 +13,3 @@ "use strict";

var metadata = {
experimental: true,
optional: true
stage: 1
};

@@ -17,0 +16,0 @@

@@ -23,2 +23,4 @@ "use strict";

"optimisation.react.constantElements": require("./optimisation/react.constant-elements"),
"optimisation.react.inlineElements": require("./optimisation/react.inline-elements"),
reactCompat: require("./other/react-compat"),

@@ -41,2 +43,4 @@ react: require("./other/react"),

"es7.exponentiationOperator": require("./es7/exponentiation-operator"),
"es6.spec.templateLiterals": require("./es6/spec.template-literals"),
"es6.templateLiterals": require("./es6/template-literals"),

@@ -75,3 +79,3 @@

// needs to be after `es6.blockScoping` due to needing `letReferences` set on blocks
"es6.blockScopingTDZ": require("./es6/block-scoping-tdz"),
"es6.spec.blockScoping": require("./es6/spec.block-scoping"),

@@ -87,5 +91,7 @@ // needs to be after `es6.parameters.*` and `es6.blockScoping` due to needing pure

// needs to be before `es6.modules` due to dynamic imports
"es3.runtime": require("./es3/runtime"),
runtime: require("./other/runtime"),
// needs to be before `_blockHoist` due to function hoisting etc
"es7.exportExtensions": require("./es7/export-extensions"),
"es6.modules": require("./es6/modules"),

@@ -103,4 +109,5 @@

"es6.symbols": require("./es6/symbols"),
"es6.spec.symbols": require("./es6/spec.symbols"),
"spec.undefinedToVoid": require("./spec/undefined-to-void"),
"es1.ludicrous": require("./es1/ludicrous"),

@@ -107,0 +114,0 @@ _strict: require("./internal/strict"),

@@ -10,20 +10,15 @@ "use strict";

var t = _interopRequireWildcard(require("../../../types"));
var metadata = {
optional: true
};
var optional = true;
exports.metadata = metadata;
var immutabilityVisitor = {
enter: function enter(node, parent, scope, state) {
if (this.isJSXIdentifier() && react.isCompatTag(node.name)) {
return;
}
var _this = this;
if (this.isJSXIdentifier() || this.isIdentifier()) {
// direct references that we need to track to hoist this to the highest scope we can
if (this.isReferenced()) {
console.log(scope.block.type, node.name);
state.identifiers[node.name] = scope.getBindingIdentifier(node.name);
return;
}
}
var stop = function () {
state.isImmutable = false;
_this.stop();
};

@@ -35,62 +30,25 @@ if (this.isJSXClosingElement()) {

// ignore
if (this.isIdentifier() || this.isJSXMemberExpression()) {
if (this.isJSXIdentifier({ name: "ref" }) && this.parentPath.isJSXAttribute({ name: node })) {
return stop();
}
if (this.isJSXIdentifier() || this.isIdentifier() || this.isJSXMemberExpression()) {
return;
}
state.isImmutable = this.isImmutable();
if (!state.isImmutable) this.stop();
if (!this.isImmutable()) stop();
}
};
function scopeIsCompatible(scope, state) {
for (var name in state.identifiers) {
if (!scope.bindingIdentifierEquals(name, state.identifiers[name])) {
return false;
}
}
return true;
}
function getLastCompatibleScope(scope, state, lastCompatibleScope) {
if (scopeIsCompatible(scope, state)) {
if (scope.path.isProgram()) {
// we've reached the top, this is pretty pointless though since we can't use `getStatementParent`
// on this so let's just use the last scope
return lastCompatibleScope;
} else {
// up we go!
return getLastCompatibleScope(scope.parent, state, scope);
}
} else {
// this scope isn't compatible so just return the last good one
return lastCompatibleScope;
}
}
function JSXElement(node, parent, scope, file) {
// todo - check for `ref` attribute
if (node._ignoreConstant) return;
var state = {
identifiers: {},
isImmutable: true
};
var state = { isImmutable: true };
this.traverse(immutabilityVisitor, state);
this.skip();
if (!state.isImmutable) return;
var lastCompatibleScope = getLastCompatibleScope(scope, state);
console.log(state);
// same scope, can't hoist it up
if (lastCompatibleScope === scope) return;
var statementParent = lastCompatibleScope.path.getStatementParent();
var uid = scope.generateUidIdentifier("ref");
statementParent.insertBefore([t.variableDeclaration("var", [t.variableDeclarator(uid, node)])]);
return uid;
if (state.isImmutable) {
this.hoist();
node._ignoreConstant = true;
}
}
"use strict";
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; };
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
exports.manipulateOptions = manipulateOptions;
exports.Program = Program;
exports.pre = pre;
exports.Identifier = Identifier;
exports.__esModule = true;
var includes = _interopRequire(require("lodash/collection/includes"));
var util = _interopRequireWildcard(require("../../../util"));
var core = _interopRequire(require("core-js/library"));
var has = _interopRequire(require("lodash/object/has"));
var buildRuntimeTransformer = _interopRequire(require("../../helpers/build-runtime-transformer"));
var t = _interopRequireWildcard(require("../../../types"));
var isSymbolIterator = t.buildMatchMemberExpression("Symbol.iterator");
var coreHas = function coreHas(node) {
return node.name !== "_" && has(core, node.name);
};
var ALIASABLE_CONSTRUCTORS = ["Symbol", "Promise", "Map", "WeakMap", "Set", "WeakSet"];
var astVisitor = {
enter: function enter(node, parent, scope, file) {
var prop;
if (this.isMemberExpression() && this.isReferenced()) {
// Array.from -> _core.Array.from
var obj = node.object;
prop = node.property;
if (!t.isReferenced(obj, node)) return;
if (!node.computed && coreHas(obj) && has(core[obj.name], prop.name) && !scope.getBindingIdentifier(obj.name)) {
this.skip();
return t.prependToMemberExpression(node, file.get("coreIdentifier"));
}
} else if (this.isReferencedIdentifier() && !t.isMemberExpression(parent) && includes(ALIASABLE_CONSTRUCTORS, node.name) && !scope.getBindingIdentifier(node.name)) {
// Symbol() -> _core.Symbol(); new Promise -> new _core.Promise
return t.memberExpression(file.get("coreIdentifier"), node);
} else if (this.isCallExpression()) {
// arr[Symbol.iterator]() -> _core.$for.getIterator(arr)
var callee = node.callee;
if (node.arguments.length) return false;
if (!t.isMemberExpression(callee)) return false;
if (!callee.computed) return false;
prop = callee.property;
if (!isSymbolIterator(prop)) return false;
return util.template("corejs-iterator", {
CORE_ID: file.get("coreIdentifier"),
VALUE: callee.object
});
} else if (this.isBinaryExpression()) {
// Symbol.iterator in arr -> core.$for.isIterable(arr)
if (node.operator !== "in") return;
var left = node.left;
if (!isSymbolIterator(left)) return;
return util.template("corejs-is-iterator", {
CORE_ID: file.get("coreIdentifier"),
VALUE: node.right
});
}
}
};
var metadata = {
optional: true,
react: true
};
exports.metadata = metadata;
function manipulateOptions(opts) {
if (opts.whitelist) opts.whitelist.push("es6.modules");
}
function Program(node, parent, scope, file) {
this.traverse(astVisitor, file);
}
function pre(file) {
file.set("helperGenerator", function (name) {
return file.addImport("babel-runtime/helpers/" + name, name);
});
file.setDynamic("coreIdentifier", function () {
return file.addImport("babel-runtime/core-js", "core");
});
file.setDynamic("regeneratorIdentifier", function () {
return file.addImport("babel-runtime/regenerator", "regeneratorRuntime");
});
}
function Identifier(node, parent, scope, file) {
if (this.isReferencedIdentifier({ name: "regeneratorRuntime" })) {
return file.get("regeneratorIdentifier");
}
}
buildRuntimeTransformer(exports, core, "es5");

@@ -11,2 +11,4 @@ "use strict";

var PathHoister = _interopRequire(require("./hoister"));
var isBoolean = _interopRequire(require("lodash/lang/isBoolean"));

@@ -112,3 +114,5 @@

if (this.isPreviousType("Statement")) {
if (this.parentPath.isExpressionStatement()) {
return this.parentPath.insertBefore(nodes);
} else if (this.isPreviousType("Statement")) {
if (Array.isArray(this.container)) {

@@ -126,3 +130,3 @@ this._containerInsertBefore(nodes);

} else {
throw new Error("no idea what to do with this");
throw new Error("no idea what to do with this ");
}

@@ -159,3 +163,5 @@ };

if (this.isPreviousType("Statement")) {
if (this.parentPath.isExpressionStatement()) {
return this.parentPath.insertAfter(nodes);
} else if (this.isPreviousType("Statement")) {
if (Array.isArray(this.container)) {

@@ -275,2 +281,6 @@ this._containerInsertAfter(nodes);

TraversalPath.prototype._verifyNodeList = function _verifyNodeList(nodes) {
if (typeof nodes === "object") {
nodes = [nodes];
}
for (var i = 0; i < nodes.length; i++) {

@@ -280,2 +290,4 @@ var node = nodes[i];

}
return nodes;
};

@@ -618,6 +630,2 @@

TraversalPath.prototype.isScope = function isScope() {
return t.isScope(this.node, this.parent);
};
TraversalPath.prototype.isPreviousType = function isPreviousType(type) {

@@ -663,7 +671,18 @@ return t.isType(this.type, type);

return _traverseWrapper;
})(function (opts, state) {
traverse(this.node, opts, this.scope, state, this);
})(function (visitor, state) {
traverse(this.node, visitor, this.scope, state, this);
});
/**
* Description
*/
TraversalPath.prototype.hoist = function hoist() {
var scope = arguments[0] === undefined ? this.scope : arguments[0];
var hoister = new PathHoister(this, scope);
return hoister.run();
};
/**
* Match the current node if it matches the provided `pattern`.

@@ -670,0 +689,0 @@ *

@@ -80,3 +80,3 @@ "use strict";

state.registerDeclaration(this);
} else if (t.isScope(node, parent)) {
} else if (this.isScope()) {
this.skip();

@@ -97,6 +97,12 @@ }

if (parent && parent.block === path.node) {
return parent;
}
var cached = path.getData("scope");
if (cached) {
if (cached && cached.parent === parent) {
return cached;
} else {}
} else {
path.setData("scope", this);
}

@@ -281,3 +287,3 @@ this.parent = parent;

Scope.prototype.rename = function rename(oldName, newName) {
Scope.prototype.rename = function rename(oldName, newName, block) {
if (!newName) newName = this.generateUidIdentifier(oldName).name;

@@ -291,3 +297,3 @@

scope.traverse(scope.block, {
scope.traverse(block || scope.block, {
enter: function enter(node, parent, scope) {

@@ -301,3 +307,3 @@ if (t.isReferencedIdentifier(node, parent) && node.name === oldName) {

}
} else if (t.isScope(node, parent)) {
} else if (this.isScope()) {
if (!scope.bindingIdentifierEquals(oldName, binding)) {

@@ -310,6 +316,8 @@ this.skip();

scope.removeOwnBinding(oldName);
scope.bindings[newName] = info;
if (!block) {
scope.removeOwnBinding(oldName);
scope.bindings[newName] = info;
binding.name = newName;
binding.name = newName;
}
};

@@ -321,2 +329,14 @@

Scope.prototype.dump = function dump() {
var scope = this;
do {
console.log(scope.block.type, "Bindings:", Object.keys(scope.bindings));
} while (scope = scope.parent);
console.log("-------------");
};
/**
* Description
*/
Scope.prototype.toArray = function toArray(node, i) {

@@ -605,13 +625,16 @@ var file = this.file;

Scope.prototype.getAllBindingsOfKind = function getAllBindingsOfKind(kind) {
Scope.prototype.getAllBindingsOfKind = function getAllBindingsOfKind() {
var ids = object();
var scope = this;
do {
for (var name in scope.bindings) {
var binding = scope.bindings[name];
if (binding.kind === kind) ids[name] = binding;
}
scope = scope.parent;
} while (scope);
for (var i = 0; i < arguments.length; i++) {
var kind = arguments[i];
var scope = this;
do {
for (var name in scope.bindings) {
var binding = scope.bindings[name];
if (binding.kind === kind) ids[name] = binding;
}
scope = scope.parent;
} while (scope);
}

@@ -718,4 +741,2 @@ return ids;

module.exports = Scope;
//path.setData("scope", this);
module.exports = Scope;

@@ -17,7 +17,11 @@ {

"VariableDeclaration": ["Statement", "Declaration"],
"ExportAllDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
"ExportDefaultDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
"ExportNamedDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
"ImportDeclaration": ["Statement", "Declaration", "ModuleDeclaration"],
"ExportDefaultSpecifier": ["ModuleSpecifier"],
"ExportNamespaceSpecifier": ["ModuleSpecifier"],
"ExportDefaultFromSpecifier": ["ModuleSpecifier"],
"ExportAllDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
"ExportDefaultDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
"ExportNamedDeclaration": ["Statement", "Declaration", "ModuleDeclaration", "ExportDeclaration"],
"ImportDeclaration": ["Statement", "Declaration", "ModuleDeclaration"],
"ArrowFunctionExpression": ["Scopable", "Function", "Expression"],

@@ -102,5 +106,5 @@ "FunctionDeclaration": ["Scopable", "Function", "Statement", "Declaration"],

"ObjectTypeAnnotation": ["Flow"],
"ObjectTypeCallProperty": ["Flow"],
"ObjectTypeIndexer": ["Flow"],
"ObjectTypeProperty": ["Flow"],
"ObjectTypeCallProperty": ["Flow", "UserWhitespacable"],
"ObjectTypeIndexer": ["Flow", "UserWhitespacable"],
"ObjectTypeProperty": ["Flow", "UserWhitespacable"],
"QualifiedTypeIdentifier": ["Flow"],

@@ -107,0 +111,0 @@ "UnionTypeAnnotation": ["Flow"],

@@ -112,5 +112,5 @@ {

"value": null,
"kind": "method",
"computed": false,
"static": false,
"kind": null
"static": false
},

@@ -117,0 +117,0 @@

@@ -185,3 +185,3 @@ "use strict";

function isSpecifierDefault(specifier) {
return t.isImportDefaultSpecifier(specifier) || t.isIdentifier(specifier.imported || specifier.exported, { name: "default" });
return t.isImportDefaultSpecifier(specifier) || t.isExportDefaultSpecifier(specifier) || t.isIdentifier(specifier.imported || specifier.exported, { name: "default" });
}

@@ -191,7 +191,7 @@

if (t.isBlockStatement(node)) {
if (t.isLoop(parent.block, { body: node })) {
if (t.isLoop(parent, { body: node })) {
return false;
}
if (t.isFunction(parent.block, { body: node })) {
if (t.isFunction(parent, { body: node })) {
return false;

@@ -198,0 +198,0 @@ }

@@ -25,6 +25,2 @@ {

"EmptyStatement": [],
"ExportAllDeclaration": ["source"],
"ExportDefaultDeclaration": ["declaration"],
"ExportNamedDeclaration": ["declaration", "specifiers", "source"],
"ExportSpecifier": ["local", "exported"],
"ExpressionStatement": ["expression"],

@@ -76,2 +72,9 @@ "File": ["program"],

"ExportAllDeclaration": ["source", "exported"],
"ExportDefaultDeclaration": ["declaration"],
"ExportNamedDeclaration": ["declaration", "specifiers", "source"],
"ExportDefaultSpecifier": ["exported"],
"ExportNamespaceSpecifier": ["exported"],
"ExportSpecifier": ["local", "exported"],
"AnyTypeAnnotation": [],

@@ -103,3 +106,3 @@ "ArrayTypeAnnotation": ["elementType"],

"TypeParameterInstantiation": ["params"],
"ObjectTypeAnnotation": ["key", "value"],
"ObjectTypeAnnotation": ["properties", "indexers", "callProperties"],
"ObjectTypeCallProperty": ["value"],

@@ -106,0 +109,0 @@ "ObjectTypeIndexer": ["id", "key", "value"],

{
"name": "babel-core",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "5.0.0-beta3",
"version": "5.0.0-beta4",
"author": "Sebastian McKenzie <sebmck@gmail.com>",

@@ -30,3 +30,3 @@ "homepage": "https://babeljs.io/",

"convert-source-map": "^0.5.0",
"core-js": "^0.6.1",
"core-js": "^0.6.0",
"debug": "^2.1.1",

@@ -33,0 +33,0 @@ "detect-indent": "^3.0.0",

@@ -8,7 +8,7 @@ <p align="center">

<p align="center">
<strong>Babel</strong> is a transpiler for writing next generation JavaScript.
<strong>Babel</strong> is a compiler for writing next generation JavaScript.
</p>
<p align="center">
For questions and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> before creating an issue.
For questions and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> or <a href="stackoverflow.com">StackOverflow</a>. The Babel issue tracker is <strong>exclusively</strong> for bug reports and future requests.
</p>

@@ -15,0 +15,0 @@

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 too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc