Begin transition of Babel to a more scalable architecture, async flow to allow for RPC and better build system for multiple packages

This commit is contained in:
Sebastian McKenzie
2015-07-11 12:39:54 +01:00
parent 04a29f8344
commit 423d8c510d
33 changed files with 66106 additions and 2805 deletions

7
test/_browser.js Normal file
View File

@@ -0,0 +1,7 @@
if (process.browser) {
require("./tests");
require("./tests-jsx");
require("./tests-harmony");
require("./tests-flow");
require("./tests-babel");
}

87
test/driver.js Executable file
View File

@@ -0,0 +1,87 @@
var parse = require("../lib").parse;
exports.test = function(code, ast, options) {
buildTest({code: code, ast: ast, options: options});
};
exports.testFail = function(code, message, options) {
buildTest({code: code, error: message, options: options});
};
exports.testAssert = function(code, assert, options) {
buildTest({code: code, assert: assert, options: options});
};
function buildTest(config) {
test(config.code, function () {
return runTest(config);
});
}
function runTest(test) {
if (test.filter && !test.filter(test)) return;
var testOpts = test.options || {locations: true};
var expected = {};
if (expected.onComment = testOpts.onComment)
testOpts.onComment = []
if (expected.onToken = testOpts.onToken)
testOpts.onToken = [];
return parse(test.code, testOpts).then(function (ast) {
if (test.error) {
throw new Error("Expected error message: " + test.error + ". But parsing succeeded.");
} else if (test.assert) {
var error = test.assert(ast);
if (error) throw new Error("Assertion failed: " + error);
} else {
var mis = misMatch(test.ast, ast);
for (var name in expected) {
if (mis) break;
if (expected[name]) {
mis = misMatch(expected[name], testOpts[name]);
testOpts[name] = expected[name];
}
}
if (mis) throw new Error(mis);
}
}, function (err) {
if (test.error) {
if (err.message === test.error) {
return;
} else {
throw new Error("Expected error message: " + test.error + ". Got error message: " + err.message);
}
}
throw err;
});
};
function ppJSON(v) { return v instanceof RegExp ? v.toString() : JSON.stringify(v, null, 2); }
function addPath(str, pt) {
if (str.charAt(str.length-1) == ")")
return str.slice(0, str.length-1) + "/" + pt + ")";
return str + " (" + pt + ")";
}
var misMatch = exports.misMatch = function(exp, act) {
if (!exp || !act || (typeof exp != "object") || (typeof act != "object")) {
if (exp !== act && typeof exp != "function")
return ppJSON(exp) + " !== " + ppJSON(act);
} else if (exp instanceof RegExp || act instanceof RegExp) {
var left = ppJSON(exp), right = ppJSON(act);
if (left !== right) return left + " !== " + right;
} else if (exp.splice) {
if (!act.slice) return ppJSON(exp) + " != " + ppJSON(act);
if (act.length != exp.length) return "array length mismatch " + exp.length + " != " + act.length;
for (var i = 0; i < act.length; ++i) {
var mis = misMatch(exp[i], act[i]);
if (mis) return addPath(mis, i);
}
} else {
for (var prop in exp) {
var mis = misMatch(exp[prop], act[prop]);
if (mis) return addPath(mis, prop);
}
}
};

2
test/mocha.opts Normal file
View File

@@ -0,0 +1,2 @@
--reporter dot
--ui tdd

3433
test/tests-babel.js Normal file

File diff suppressed because it is too large Load Diff

11245
test/tests-flow.js Normal file

File diff suppressed because it is too large Load Diff

15331
test/tests-harmony.js Executable file

File diff suppressed because it is too large Load Diff

3654
test/tests-jsx.js Normal file

File diff suppressed because it is too large Load Diff

28853
test/tests.js Executable file

File diff suppressed because it is too large Load Diff