Skip to content

Commit

Permalink
upgrade to babel 5
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmck committed Apr 28, 2015
1 parent 2952d94 commit cfffaf6
Show file tree
Hide file tree
Showing 32 changed files with 54 additions and 54 deletions.
5 changes: 2 additions & 3 deletions .babelrc
@@ -1,6 +1,5 @@
{
"experimental": true,
"playground": true,
"loose": true,
"stage": 0,
"loose": ["all"],
"blacklist": ["es6.tailCall"]
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -59,7 +59,7 @@
"user-home": "^1.1.1"
},
"devDependencies": {
"babel": "4.7.13",
"babel": "5.1.13",
"browserify": "^9.0.8",
"chai": "^2.2.0",
"eslint": "^0.18.0",
Expand Down
3 changes: 3 additions & 0 deletions src/acorn/index.js
@@ -0,0 +1,3 @@
export * from "./src/index";
import "./plugins/flow";
import "./plugins/jsx";
2 changes: 1 addition & 1 deletion src/acorn/package.json
Expand Up @@ -2,7 +2,7 @@
"name": "acorn",
"description": "ECMAScript parser",
"homepage": "https://github.com/marijnh/acorn",
"main": "src/index.js",
"main": "index.js",
"version": "1.0.0",
"engines": {
"node": ">=0.4.0"
Expand Down
2 changes: 1 addition & 1 deletion src/acorn/plugins/flow.js
@@ -1,4 +1,4 @@
var acorn = require("..")
var acorn = require("../src/index")

var pp = acorn.Parser.prototype
var tt = acorn.tokTypes
Expand Down
2 changes: 1 addition & 1 deletion src/acorn/plugins/jsx.js
@@ -1,4 +1,4 @@
var acorn = require("..")
var acorn = require("../src/index")

var tt = acorn.tokTypes;
var tc = acorn.tokContexts;
Expand Down
3 changes: 0 additions & 3 deletions src/acorn/src/index.js
Expand Up @@ -38,9 +38,6 @@ export {isIdentifierChar, isIdentifierStart} from "./identifier"
export {Token} from "./tokenize"
export {isNewLine, lineBreak, lineBreakG} from "./whitespace"

import "../plugins/flow";
import "../plugins/jsx";

export const version = "1.0.0"

// The main exported interface (under `self.acorn` when in the
Expand Down
2 changes: 1 addition & 1 deletion src/babel/api/browser.js
Expand Up @@ -11,7 +11,7 @@ transform.run = function (code, opts = {}) {
};

transform.load = function (url, callback, opts = {}, hold) {
opts.filename ||= url;
opts.filename = opts.filename || url;

var xhr = global.ActiveXObject ? new global.ActiveXObject("Microsoft.XMLHTTP") : new global.XMLHttpRequest();
xhr.open("GET", url, true);
Expand Down
2 changes: 1 addition & 1 deletion src/babel/generation/buffer.js
Expand Up @@ -77,7 +77,7 @@ export default class Buffer {
return;
}

removeLast ||= false;
removeLast = removeLast || false;

if (isNumber(i)) {
i = Math.min(2, i);
Expand Down
2 changes: 1 addition & 1 deletion src/babel/generation/index.js
Expand Up @@ -12,7 +12,7 @@ import * as t from "../types";

class CodeGenerator {
constructor(ast, opts, code) {
opts ||= {};
opts = opts || {};

this.comments = ast.comments || [];
this.tokens = ast.tokens || [];
Expand Down
2 changes: 1 addition & 1 deletion src/babel/generation/node/whitespace.js
Expand Up @@ -16,7 +16,7 @@ function crawl(node, state = {}) {
} else if (t.isFunction(node)) {
state.hasFunction = true;
} else if (t.isIdentifier(node)) {
state.hasHelper ||= isHelper(node.callee);
state.hasHelper = state.hasHelper || isHelper(node.callee);
}

return state;
Expand Down
4 changes: 2 additions & 2 deletions src/babel/tools/resolve-rc.js
Expand Up @@ -33,7 +33,7 @@ export default function (loc, opts = {}) {
var json;

try {
json = jsons[content] ||= JSON.parse(stripJsonComments(content));
json = jsons[content] = jsons[content] || JSON.parse(stripJsonComments(content));
} catch (err) {
err.message = `${file}: ${err.message}`;
throw err;
Expand All @@ -47,7 +47,7 @@ export default function (loc, opts = {}) {
var c = a.slice(0);
for (var v of b) {
if (a.indexOf(v) < 0) {
c.push(v);
c.push(v);
}
}
return c;
Expand Down
8 changes: 4 additions & 4 deletions src/babel/transformation/file/index.js
Expand Up @@ -134,7 +134,7 @@ export default class File {
if (optionParser) val = optionParser(key, val);

if (option.alias) {
opts[option.alias] ||= val;
opts[option.alias] = opts[option.alias] || val;
} else {
opts[key] = val;
}
Expand Down Expand Up @@ -349,7 +349,7 @@ export default class File {
}

addImport(source: string, name?: string, type?: string): Object {
name ||= source;
name = name || source;
var id = this.dynamicImportIds[name];

if (!id) {
Expand All @@ -361,7 +361,7 @@ export default class File {
declar._blockHoist = 3;

if (type) {
var modules = this.dynamicImportTypes[type] ||= [];
var modules = this.dynamicImportTypes[type] = this.dynamicImportTypes[type] || [];
modules.push(declar);
}

Expand All @@ -379,7 +379,7 @@ export default class File {
attachAuxiliaryComment(node: Object): Object {
var comment = this.opts.auxiliaryComment;
if (comment) {
node.leadingComments ||= [];
node.leadingComments = node.leadingComments || [];
node.leadingComments.push({
type: "Line",
value: " " + comment
Expand Down
4 changes: 2 additions & 2 deletions src/babel/transformation/helpers/define-map.js
Expand Up @@ -15,7 +15,7 @@ export function push(mutatorMap, node, kind, file) {

//

map._inherits ||= [];
map._inherits = map._inherits || [];
map._inherits.push(node);

map._key = node.key;
Expand All @@ -25,7 +25,7 @@ export function push(mutatorMap, node, kind, file) {
}

if (node.decorators) {
var decorators = map.decorators ||= t.arrayExpression([]);
var decorators = map.decorators = map.decorators || t.arrayExpression([]);
decorators.elements = decorators.elements.concat(node.decorators.map(dec => dec.expression));
}

Expand Down
Expand Up @@ -20,7 +20,7 @@ var referenceVisitor = {
enter(node, parent, scope, state) {
var name = state.id.name;
if (t.isReferencedIdentifier(node, parent, { name: name }) && scope.bindingIdentifierEquals(name, state.id)) {
return state.ref ||= scope.generateUidIdentifier(name);
return state.ref = state.ref || scope.generateUidIdentifier(name);
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/babel/transformation/helpers/replace-supers.js
Expand Up @@ -218,7 +218,7 @@ export default class ReplaceSupers {
return this.setSuperProperty(node.left.property, node.right, node.left.computed, getThisReference());
} else {
// super.age += 2; -> var _ref = super.age; super.age = _ref + 2;
ref ||= path.scope.generateUidIdentifier("ref");
ref = ref || path.scope.generateUidIdentifier("ref");
return [
t.variableDeclaration("var", [
t.variableDeclarator(ref, node.left)
Expand Down
2 changes: 1 addition & 1 deletion src/babel/transformation/index.js
Expand Up @@ -60,7 +60,7 @@ import rawTransformers from "./transformers";
each(rawTransformers, function (transformer, key) {
var namespace = key.split(".")[0];

transform.namespaces[namespace] ||= [];
transform.namespaces[namespace] = transform.namespaces[namespace] || [];
transform.namespaces[namespace].push(key);
transform.transformerNamespaces[key] = namespace;

Expand Down
2 changes: 1 addition & 1 deletion src/babel/transformation/modules/_default.js
Expand Up @@ -166,7 +166,7 @@ export default class DefaultFormatter {
}

_addExport(name, exported) {
var info = this.localExports[name] ||= {
var info = this.localExports[name] = this.localExports[name] || {
binding: this.scope.getBindingIdentifier(name),
exported: []
};
Expand Down
2 changes: 1 addition & 1 deletion src/babel/transformation/modules/common.js
Expand Up @@ -114,7 +114,7 @@ export default class CommonJSFormatter extends DefaultFormatter {
uid = this.scope.generateUidBasedOnNode(node, "import");
}

uid ||= node.specifiers[0].local;
uid = uid || node.specifiers[0].local;

var declar = t.variableDeclaration("var", [
t.variableDeclarator(uid, call)
Expand Down
4 changes: 2 additions & 2 deletions src/babel/transformation/modules/system.js
Expand Up @@ -77,11 +77,11 @@ var runnerSettersVisitor = {

export default class SystemFormatter extends AMDFormatter {
constructor(file) {
super(file);

this.exportIdentifier = file.scope.generateUidIdentifier("export");
this.noInteropRequireExport = true;
this.noInteropRequireImport = true;

DefaultFormatter.apply(this, arguments);
}

_addImportSource(node, exportNode) {
Expand Down
2 changes: 1 addition & 1 deletion src/babel/transformation/transformer.js
Expand Up @@ -39,7 +39,7 @@ export default class Transformer {
//

this.handlers = this.normalize(transformer);
this.opts ||= {};
this.opts = this.opts || {};
this.key = transformerKey;

//
Expand Down
4 changes: 2 additions & 2 deletions src/babel/transformation/transformers/es6/block-scoping.js
Expand Up @@ -14,7 +14,7 @@ function isLet(node, parent) {
if (isLetInitable(node, parent)) {
for (var i = 0; i < node.declarations.length; i++) {
var declar = node.declarations[i];
declar.init ||= t.identifier("undefined");
declar.init = declar.init || t.identifier("undefined");
}
}

Expand Down Expand Up @@ -611,7 +611,7 @@ class BlockScoping {
for (var i = 0; i < cases.length; i++) {
var caseConsequent = cases[i].consequent[0];
if (t.isBreakStatement(caseConsequent) && !caseConsequent.label) {
caseConsequent.label = this.loopLabel ||= this.file.scope.generateUidIdentifier("loop");
caseConsequent.label = this.loopLabel = this.loopLabel || this.file.scope.generateUidIdentifier("loop");
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/babel/transformation/transformers/es6/classes.js
Expand Up @@ -558,11 +558,11 @@ class ClassTransformer {
var body;
var target;
if (node.static) {
initializers = this.staticInitializersId ||= this.scope.generateUidIdentifier("staticInitializers");
initializers = this.staticInitializersId = this.staticInitializersId || this.scope.generateUidIdentifier("staticInitializers");
body = this.staticPropBody;
target = this.classRef;
} else {
initializers = this.instanceInitializersId ||= this.scope.generateUidIdentifier("instanceInitializers");
initializers = this.instanceInitializersId = this.instanceInitializersId || this.scope.generateUidIdentifier("instanceInitializers");
body = this.instancePropBody;
target = t.thisExpression();
}
Expand All @@ -575,7 +575,7 @@ class ClassTransformer {
])
));
} else {
node.value ||= t.identifier("undefined");
node.value = node.value || t.identifier("undefined");

if (node.static) {
// can just be added to the static map
Expand Down
2 changes: 1 addition & 1 deletion src/babel/transformation/transformers/es6/destructuring.js
Expand Up @@ -200,7 +200,7 @@ export function VariableDeclaration(node, parent, scope, file) {

for (i = 0; i < nodes.length; i++) {
node = nodes[i];
declar ||= t.variableDeclaration(node.kind, []);
declar = declar || t.variableDeclaration(node.kind, []);

if (!t.isVariableDeclaration(node) && declar.kind !== node.kind) {
throw file.errorWithNode(node, messages.get("invalidParentForThisNode"));
Expand Down
2 changes: 1 addition & 1 deletion src/babel/transformation/transformers/es6/object-super.js
Expand Up @@ -32,7 +32,7 @@ function Property(path, node, scope, getObjectRef, file) {

export function ObjectExpression(node, parent, scope, file) {
var objectRef;
var getObjectRef = () => objectRef ||= scope.generateUidIdentifier("obj");
var getObjectRef = () => objectRef = objectRef || scope.generateUidIdentifier("obj");

var propPaths = this.get("properties");
for (var i = 0; i < node.properties.length; i++) {
Expand Down
10 changes: 5 additions & 5 deletions src/babel/transformation/transformers/es6/tail-call.js
Expand Up @@ -101,23 +101,23 @@ class TailCallTransformer {
}

getArgumentsId() {
return this.argumentsId ||= this.scope.generateUidIdentifier("arguments");
return this.argumentsId = this.argumentsId || this.scope.generateUidIdentifier("arguments");
}

getThisId() {
return this.thisId ||= this.scope.generateUidIdentifier("this");
return this.thisId = this.thisId || this.scope.generateUidIdentifier("this");
}

getLeftId() {
return this.leftId ||= this.scope.generateUidIdentifier("left");
return this.leftId = this.leftId || this.scope.generateUidIdentifier("left");
}

getFunctionId() {
return this.functionId ||= this.scope.generateUidIdentifier("function");
return this.functionId = this.functionId || this.scope.generateUidIdentifier("function");
}

getAgainId() {
return this.againId ||= this.scope.generateUidIdentifier("again");
return this.againId = this.againId || this.scope.generateUidIdentifier("again");
}

getParams() {
Expand Down
Expand Up @@ -52,11 +52,11 @@ function aliasFunction(getBody, path, scope) {

var state = {
getArgumentsId() {
return argumentsId ||= scope.generateUidIdentifier("arguments");
return argumentsId = argumentsId || scope.generateUidIdentifier("arguments");
},

getThisId() {
return thisId ||= scope.generateUidIdentifier("this");
return thisId = thisId || scope.generateUidIdentifier("this");
}
};

Expand All @@ -67,7 +67,7 @@ function aliasFunction(getBody, path, scope) {
var body;

var pushDeclaration = function (id, init) {
body ||= getBody();
body = body || getBody();
body.unshift(t.variableDeclaration("var", [
t.variableDeclarator(id, init)
]));
Expand Down
Expand Up @@ -21,7 +21,7 @@ export function MethodDefinition(node) {
var isConstructor = !node.computed && t.isIdentifier(node.key, { name: "constructor" });

// get ["constructor"]() {}
isConstructor ||= t.isLiteral(node.key, { value: "constructor" });
isConstructor = isConstructor || t.isLiteral(node.key, { value: "constructor" });

if (isConstructor) {
throw this.errorWithNode(messages.get("classesIllegalConstructorKind"));
Expand Down
3 changes: 2 additions & 1 deletion src/babel/traversal/index.js
Expand Up @@ -122,7 +122,8 @@ traverse.explode = function (obj) {
var aliases = t.FLIPPED_ALIAS_KEYS[type];
if (aliases) {
for (var i = 0; i < aliases.length; i++) {
obj[aliases[i]] ||= fns;
var alias = aliases[i];
obj[alias] = obj[alias] || fns;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/babel/traversal/path/index.js
Expand Up @@ -47,7 +47,7 @@ export default class TraversalPath {

static get(parentPath: TraversalPath, context?: TraversalContext, parent, container, key, file?: File) {
var targetNode = container[key];
var paths = container._paths ||= [];
var paths = container._paths = container._paths || [];
var path;

for (var i = 0; i < paths.length; i++) {
Expand Down Expand Up @@ -613,7 +613,7 @@ export default class TraversalPath {
var match = prop.isnt("computed") && key.isIdentifier({ name: targetName });

// { "foo": "obj" } or { ["foo"]: "obj" }
match ||= key.isLiteral({ value: targetName });
match = match || key.isLiteral({ value: targetName });

if (match) return prop.get("value");
}
Expand Down
6 changes: 3 additions & 3 deletions src/babel/traversal/scope.js
Expand Up @@ -242,8 +242,8 @@ export default class Scope {
if (kind === "hoisted" && local.kind === "let") return;

var duplicate = false;
duplicate ||= kind === "let" || kind === "const" || local.kind === "let" || local.kind === "const" || local.kind === "module";
duplicate ||= local.kind === "param" && (kind === "let" || kind === "const");
if (!duplicate) duplicate = kind === "let" || kind === "const" || local.kind === "let" || local.kind === "const" || local.kind === "module";
if (!duplicate) duplicate = local.kind === "param" && (kind === "let" || kind === "const");

if (duplicate) {
throw this.file.errorWithNode(id, messages.get("scopeDuplicateDeclaration", name), TypeError);
Expand All @@ -255,7 +255,7 @@ export default class Scope {
*/

rename(oldName: string, newName: string, block?) {
newName ||= this.generateUidIdentifier(oldName).name;
newName = newName || this.generateUidIdentifier(oldName).name;

var info = this.getBinding(oldName);
if (!info) return;
Expand Down

0 comments on commit cfffaf6

Please sign in to comment.