Estree compatibility as plugin (#277)
* Initial estree support for ClassMethod * Handle literals for estree * Fix regex * correct output of regexp and regenerate test * Add tests for validation stuff with estree plugin * Parse Properties correctly This also refactors how babylon parses obj properties in general so that this logic can be more easily extended. * Run all throws-tests a second time with estree plugin * Fix all throw tests * Remove rebase conflict * Correctly set kind This ensures state.inMethod gets propagated correctly * Add computed: false to methods with ident async * Implement directive field on Directives * Test invalid directives * more tests
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
var test = require("ava");
|
||||
var getFixtures = require("babel-helper-fixtures").multiple;
|
||||
|
||||
module.exports = function runFixtureTests(fixturesPath, parseFunction) {
|
||||
exports.runFixtureTests = function runFixtureTests(fixturesPath, parseFunction) {
|
||||
var fixtures = getFixtures(fixturesPath);
|
||||
|
||||
Object.keys(fixtures).forEach(function (name) {
|
||||
fixtures[name].forEach(function (testSuite) {
|
||||
testSuite.tests.forEach(function (task) {
|
||||
var testFn = task.disabled ? test.skip : test;
|
||||
var testFn = task.disabled ? test.skip : task.options.only ? test.only : test;
|
||||
|
||||
testFn(name + "/" + testSuite.title + "/" + task.title, function () {
|
||||
try {
|
||||
@@ -22,10 +22,41 @@ module.exports = function runFixtureTests(fixturesPath, parseFunction) {
|
||||
});
|
||||
};
|
||||
|
||||
exports.runThrowTestsWithEstree = function runThrowTestsWithEstree(fixturesPath, parseFunction) {
|
||||
var fixtures = getFixtures(fixturesPath);
|
||||
|
||||
Object.keys(fixtures).forEach(function (name) {
|
||||
fixtures[name].forEach(function (testSuite) {
|
||||
testSuite.tests.forEach(function (task) {
|
||||
if (!task.options.throws) return;
|
||||
|
||||
task.options.plugins = task.options.plugins || [];
|
||||
task.options.plugins.push("estree");
|
||||
|
||||
var testFn = task.disabled ? test.skip : task.options.only ? test.only : test;
|
||||
|
||||
testFn(name + "/" + testSuite.title + "/" + task.title, function () {
|
||||
try {
|
||||
return runTest(task, parseFunction);
|
||||
} catch (err) {
|
||||
err.message = task.actual.loc + ": " + err.message;
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function save(test, ast) {
|
||||
delete ast.tokens;
|
||||
if (ast.comments && !ast.comments.length) delete ast.comments;
|
||||
|
||||
// Ensure that RegExp are serialized as strings
|
||||
const toJSON = RegExp.prototype.toJSON;
|
||||
RegExp.prototype.toJSON = RegExp.prototype.toString;
|
||||
require("fs").writeFileSync(test.expect.loc, JSON.stringify(ast, null, " "));
|
||||
RegExp.prototype.toJSON = toJSON;
|
||||
}
|
||||
|
||||
function runTest(test, parseFunction) {
|
||||
@@ -69,7 +100,8 @@ function runTest(test, parseFunction) {
|
||||
}
|
||||
|
||||
function ppJSON(v) {
|
||||
return v instanceof RegExp ? v.toString() : JSON.stringify(v, null, 2);
|
||||
v = v instanceof RegExp ? v.toString() : v;
|
||||
return JSON.stringify(v, null, 2);
|
||||
}
|
||||
|
||||
function addPath(str, pt) {
|
||||
@@ -81,20 +113,20 @@ function addPath(str, pt) {
|
||||
}
|
||||
|
||||
function misMatch(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) {
|
||||
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);
|
||||
} else if (Array.isArray(exp)) {
|
||||
if (!Array.isArray(act)) 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 {
|
||||
} else if (!exp || !act || (typeof exp != "object") || (typeof act != "object")) {
|
||||
if (exp !== act && typeof exp != "function")
|
||||
return ppJSON(exp) + " !== " + ppJSON(act);
|
||||
} else {
|
||||
for (var prop in exp) {
|
||||
var mis = misMatch(exp[prop], act[prop]);
|
||||
if (mis) return addPath(mis, prop);
|
||||
|
||||
Reference in New Issue
Block a user