upgrade to babel 5

This commit is contained in:
Sebastian McKenzie 2015-04-28 14:55:28 +01:00
parent 2952d94e60
commit cfffaf6cdb
32 changed files with 54 additions and 54 deletions

View File

@ -1,6 +1,5 @@
{
"experimental": true,
"playground": true,
"loose": true,
"stage": 0,
"loose": ["all"],
"blacklist": ["es6.tailCall"]
}

View File

@ -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",

3
src/acorn/index.js Normal file
View File

@ -0,0 +1,3 @@
export * from "./src/index";
import "./plugins/flow";
import "./plugins/jsx";

View File

@ -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"

View File

@ -1,4 +1,4 @@
var acorn = require("..")
var acorn = require("../src/index")
var pp = acorn.Parser.prototype
var tt = acorn.tokTypes

View File

@ -1,4 +1,4 @@
var acorn = require("..")
var acorn = require("../src/index")
var tt = acorn.tokTypes;
var tc = acorn.tokContexts;

View File

@ -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

View File

@ -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);

View File

@ -77,7 +77,7 @@ export default class Buffer {
return;
}
removeLast ||= false;
removeLast = removeLast || false;
if (isNumber(i)) {
i = Math.min(2, i);

View File

@ -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 || [];

View File

@ -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;

View File

@ -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;
@ -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;

View File

@ -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;
}
@ -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) {
@ -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);
}
@ -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

View File

@ -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;
@ -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));
}

View File

@ -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);
}
}
};

View File

@ -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)

View File

@ -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;

View File

@ -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: []
};

View File

@ -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)

View File

@ -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) {

View File

@ -39,7 +39,7 @@ export default class Transformer {
//
this.handlers = this.normalize(transformer);
this.opts ||= {};
this.opts = this.opts || {};
this.key = transformerKey;
//

View File

@ -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");
}
}
@ -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");
}
}

View File

@ -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();
}
@ -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

View File

@ -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"));

View File

@ -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++) {

View File

@ -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() {

View File

@ -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");
}
};
@ -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)
]));

View File

@ -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"));

View File

@ -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;
}
}
}

View File

@ -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++) {
@ -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");
}

View File

@ -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);
@ -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;

View File

@ -17,7 +17,7 @@ function registerType(type: string, skipAliasCheck?: boolean) {
};
t[`assert${type}`] = function (node, opts) {
opts ||= {};
opts = opts || {};
if (!is(node, opts)) {
throw new Error(`Expected type ${JSON.stringify(type)} with option ${JSON.stringify(opts)}`);
}
@ -42,7 +42,7 @@ each(t.VISITOR_KEYS, function (keys, type) {
each(t.ALIAS_KEYS, function (aliases, type) {
each(aliases, function (alias) {
var types = t.FLIPPED_ALIAS_KEYS[alias] ||= [];
var types = t.FLIPPED_ALIAS_KEYS[alias] = t.FLIPPED_ALIAS_KEYS[alias] || [];
types.push(type);
});
});