chore: bump eslint and its plugins (#13412)

This commit is contained in:
Huáng Jùnliàng 2021-06-03 23:42:32 -04:00 committed by GitHub
parent 8720919665
commit 4eda1c8605
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 906 additions and 724 deletions

View File

@ -30,13 +30,13 @@
"eslint": ">=7.5.0"
},
"dependencies": {
"eslint-scope": "^5.1.0",
"eslint-scope": "^5.1.1",
"eslint-visitor-keys": "^2.1.0",
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
},
"devDependencies": {
"@babel/core": "workspace:*",
"dedent": "^0.7.0",
"eslint": "^7.5.0"
"eslint": "^7.27.0"
}
}

View File

@ -20,6 +20,6 @@
"eslint": ">=7.5.0"
},
"devDependencies": {
"eslint": "^7.5.0"
"eslint": "^7.27.0"
}
}

View File

@ -31,6 +31,6 @@
},
"homepage": "https://babel.dev/",
"devDependencies": {
"eslint": "^7.5.0"
"eslint": "^7.27.0"
}
}

View File

@ -41,6 +41,6 @@
},
"devDependencies": {
"clone-deep": "^4.0.1",
"eslint": "^7.5.0"
"eslint": "^7.27.0"
}
}

View File

@ -15,6 +15,6 @@
"@babel/preset-env": "workspace:^7.12.13",
"@babel/preset-flow": "workspace:^7.12.13",
"@babel/preset-react": "workspace:^7.12.13",
"eslint": "^7.5.0"
"eslint": "^7.27.0"
}
}

View File

@ -8,8 +8,8 @@
"@babel/eslint-parser": "workspace:^7.14.4",
"@babel/preset-react": "workspace:^7.13.13",
"dedent": "^0.7.0",
"eslint": "^7.5.0",
"eslint-plugin-import": "^2.22.0",
"eslint": "^7.27.0",
"eslint-plugin-import": "^2.23.4",
"npm-babel-parser": "npm:@babel/parser@^7.14.0"
}
}

View File

@ -33,10 +33,12 @@ const baseEslintOpts = {
* @param object opts
* @param function done
*/
function lint(opts, done) {
function lint(opts) {
return new Promise((resolve, reject) => {
readFixture(opts.fixture, (err, src) => {
if (err) return done(err);
done(null, eslint.linter.verify(src, opts.eslint));
if (err) return reject(err);
resolve(eslint.linter.verify(src, opts.eslint));
});
});
}
@ -66,18 +68,14 @@ function strictSuite() {
eslintOpts.rules[ruleId] = [errorLevel, "never"];
["global-with", "function-with"].forEach(fixture => {
it(`should error on ${fixture.match(/^[^-]+/)[0]} directive`, done => {
lint(
{
it(`should error on ${
fixture.match(/^[^-]+/)[0]
} directive`, async () => {
const report = await lint({
fixture: ["strict", fixture],
eslint: eslintOpts,
},
(err, report) => {
if (err) return done(err);
});
expect(report[0].ruleId).toBe(ruleId);
done();
},
);
});
});
});
@ -88,65 +86,41 @@ function strictSuite() {
});
eslintOpts.rules[ruleId] = [errorLevel, "global"];
it("shouldn't error on single global directive", done => {
lint(
{
it("shouldn't error on single global directive", async () => {
const report = await lint({
fixture: ["strict", "global-with"],
eslint: eslintOpts,
},
(err, report) => {
if (err) return done(err);
});
expect(report.length).toBe(0);
done();
},
);
});
it("should error twice on global directive: no and function directive: yes", done => {
lint(
{
it("should error twice on global directive: no and function directive: yes", async () => {
const report = await lint({
fixture: ["strict", "function-with"],
eslint: eslintOpts,
},
(err, report) => {
if (err) return done(err);
});
expect(report[0].ruleId).toBe(ruleId);
done();
},
);
});
it("should error on function directive", done => {
lint(
{
it("should error on function directive", async () => {
const report = await lint({
fixture: ["strict", "global-with-function-with"],
eslint: eslintOpts,
},
(err, report) => {
if (err) return done(err);
});
expect(report[0].ruleId).toBe(ruleId);
// This is to make sure the test fails prior to adapting Babel AST
// directive representation to ESLint format. Otherwise it reports an
// error for missing global directive that masquerades as the expected
// result of the previous assertion.
expect(report[0].nodeType).not.toBe("Program");
done();
},
);
});
it("should error on no directive", done => {
lint(
{
it("should error on no directive", async () => {
const report = await lint({
fixture: ["strict", "none"],
eslint: eslintOpts,
},
(err, report) => {
if (err) return done(err);
});
expect(report[0].ruleId).toBe(ruleId);
done();
},
);
});
});
@ -156,63 +130,39 @@ function strictSuite() {
});
eslintOpts.rules[ruleId] = [errorLevel, "function"];
it("shouldn't error on single function directive", done => {
lint(
{
fixture: ["strict", "function-with"],
it("shouldn't error on single function directive", async () => {
const report = await lint({
fixture: ["strict", "none"],
eslint: eslintOpts,
},
(err, report) => {
if (err) return done(err);
});
expect(report.length).toBe(0);
done();
},
);
});
it("should error twice on function directive: no and global directive: yes", done => {
lint(
{
it("should error twice on function directive: no and global directive: yes", async () => {
const report = await lint({
fixture: ["strict", "global-with-function-without"],
eslint: eslintOpts,
},
(err, report) => {
if (err) return done(err);
});
[0, 1].forEach(i => {
expect(report[i].ruleId).toBe(ruleId);
});
done();
},
);
});
it("should error on only global directive", done => {
lint(
{
it("should error on only global directive", async () => {
const report = await lint({
fixture: ["strict", "global-with"],
eslint: eslintOpts,
},
(err, report) => {
if (err) return done(err);
});
expect(report[0].ruleId).toBe(ruleId);
done();
},
);
});
it("should error on extraneous global directive", done => {
lint(
{
it("should error on extraneous global directive", async () => {
const report = await lint({
fixture: ["strict", "global-with-function-with"],
eslint: eslintOpts,
},
(err, report) => {
if (err) return done(err);
});
expect(report[0].ruleId).toBe(ruleId);
expect(report[0].nodeType.indexOf("Function")).toBe(-1);
done();
},
);
});
});
}

View File

@ -43,12 +43,12 @@
"babel-plugin-transform-charcodes": "^0.2.0",
"chalk": "^2.4.2",
"charcodes": "^0.2.0",
"eslint": "^7.5.0",
"eslint-import-resolver-node": "^0.3.3",
"eslint-plugin-flowtype": "^4.6.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^23.8.2",
"eslint-plugin-prettier": "^3.1.2",
"eslint": "^7.27.0",
"eslint-import-resolver-node": "^0.3.4",
"eslint-plugin-flowtype": "^5.7.2",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-prettier": "^3.4.0",
"fancy-log": "^1.3.3",
"flow-bin": "^0.123.0",
"gulp": "^4.0.2",

View File

@ -273,7 +273,7 @@ fs.readdirSync(fixtureLoc).forEach(function (binName) {
// copy .babelignore file to tmp directory
opts.inFiles[".babelignore"] = helper.readFile(babelIgnoreLoc);
}
// eslint-disable-next-line jest/valid-title
it(testName, buildTest(binName, testName, opts), 20000);
});
});

View File

@ -33,6 +33,13 @@ function transformFile(filename, opts, cb) {
function transformFileSync(filename, opts) {
return babel.transformFileSync(filename, { cwd, configFile: false, ...opts });
}
function transformFileAsync(filename, opts) {
return babel.transformFileAsync(filename, {
cwd,
configFile: false,
...opts,
});
}
function transformAsync(code, opts) {
return babel.transformAsync(code, { cwd, configFile: false, ...opts });
@ -147,20 +154,40 @@ describe("api", function () {
expect(babel.tokTypes).toBeDefined();
});
it("transformFile", function (done) {
it("transformFile", function () {
const options = {
babelrc: false,
};
Object.freeze(options);
transformFile(cwd + "/fixtures/api/file.js", options, function (err, res) {
if (err) return done(err);
return new Promise((resolve, reject) => {
transformFile(
cwd + "/fixtures/api/file.js",
options,
function (err, res) {
if (err) return reject(err);
expect(res.code).toBe("foo();");
// keep user options untouched
expect(options).toEqual({ babelrc: false });
done();
resolve();
},
);
});
});
it("transformFileAsync", async function () {
const options = {
babelrc: false,
};
Object.freeze(options);
const res = await transformFileAsync(
cwd + "/fixtures/api/file.js",
options,
);
expect(res.code).toBe("foo();");
// keep user options untouched
expect(options).toEqual({ babelrc: false });
});
it("transformFileSync", function () {
const options = {
babelrc: false,
@ -759,7 +786,8 @@ describe("api", function () {
babelrc: false,
};
it("only syntax plugin available", function (done) {
it("only syntax plugin available", function () {
return new Promise(resolve => {
transformFile(
cwd + "/fixtures/api/parsing-errors/only-syntax/file.js",
options,
@ -771,12 +799,14 @@ describe("api", function () {
"Add @babel/plugin-proposal-pipeline-operator (https://git.io/vb4SU) to the " +
"'plugins' section of your Babel config to enable transformation.",
);
done();
resolve();
},
);
});
});
it("both syntax and transform plugin available", function (done) {
it("both syntax and transform plugin available", function () {
return new Promise(resolve => {
transformFile(
cwd + "/fixtures/api/parsing-errors/syntax-and-transform/file.js",
options,
@ -788,11 +818,12 @@ describe("api", function () {
"Add @babel/plugin-proposal-do-expressions (https://git.io/vb4S3) to the " +
"'plugins' section of your Babel config to enable transformation.",
);
done();
resolve();
},
);
});
});
});
describe("missing helpers", function () {
it("should always throw", function () {

View File

@ -188,26 +188,21 @@ describe("@babel/core config loading", () => {
const options2 = loadConfig(opts).options;
expect(options2.plugins.length).toBe(options1.plugins.length);
for (let i = 0; i < options1.plugins.length; i++) {
if (i === 0) {
expect(options2.plugins[i]).not.toBe(options1.plugins[i]);
} else {
expect(options2.plugins[0]).not.toBe(options1.plugins[0]);
for (let i = 1; i < options1.plugins.length; i++) {
expect(options2.plugins[i]).toBe(options1.plugins[i]);
}
}
process.env.INVALIDATE_PLUGIN3 = true;
const options3 = loadConfig(opts).options;
expect(options3.plugins.length).toBe(options1.plugins.length);
for (let i = 0; i < options1.plugins.length; i++) {
if (i === 0 || i === 5) {
expect(options3.plugins[i]).not.toBe(options1.plugins[i]);
} else {
expect(options3.plugins.length).toBe(6);
expect(options3.plugins[0]).not.toBe(options1.plugins[0]);
expect(options3.plugins[5]).not.toBe(options1.plugins[5]);
for (let i = 1; i < 5; i++) {
expect(options3.plugins[i]).toBe(options1.plugins[i]);
}
}
});
it("should invalidate config file presets and their children", () => {
@ -219,27 +214,22 @@ describe("@babel/core config loading", () => {
const options2 = loadConfig(opts).options;
expect(options2.plugins.length).toBe(options1.plugins.length);
for (let i = 0; i < options1.plugins.length; i++) {
if (i === 5) {
expect(options2.plugins[i]).not.toBe(options1.plugins[i]);
} else {
expect(options2.plugins.length).toBe(6);
expect(options2.plugins[5]).not.toBe(options1.plugins[5]);
for (let i = 0; i < 5; i++) {
expect(options2.plugins[i]).toBe(options1.plugins[i]);
}
}
process.env.INVALIDATE_PRESET2 = true;
const options3 = loadConfig(opts).options;
expect(options3.plugins.length).toBe(options1.plugins.length);
for (let i = 0; i < options1.plugins.length; i++) {
if (i === 4 || i === 5) {
expect(options3.plugins[i]).not.toBe(options1.plugins[i]);
} else {
expect(options3.plugins.length).toBe(6);
expect(options3.plugins[4]).not.toBe(options1.plugins[4]);
expect(options3.plugins[5]).not.toBe(options1.plugins[5]);
for (let i = 0; i < 4; i++) {
expect(options3.plugins[i]).toBe(options1.plugins[i]);
}
}
});
it("should invalidate the config file and its plugins/presets", () => {
@ -251,14 +241,14 @@ describe("@babel/core config loading", () => {
const options2 = loadConfig(opts).options;
expect(options2.plugins.length).toBe(options1.plugins.length);
expect(options2.plugins.length).toBe(6);
expect(options2.plugins[0]).not.toBe(options1.plugins[0]);
expect(options2.plugins[1]).not.toBe(options1.plugins[1]);
expect(options2.plugins[4]).not.toBe(options1.plugins[4]);
expect(options2.plugins[5]).not.toBe(options1.plugins[5]);
for (let i = 0; i < options1.plugins.length; i++) {
if (i === 0 || i === 1 || i === 4 || i === 5 || i === 6) {
expect(options2.plugins[i]).not.toBe(options1.plugins[i]);
} else {
expect(options2.plugins[i]).toBe(options1.plugins[i]);
}
}
expect(options2.plugins[2]).toBe(options1.plugins[2]);
expect(options2.plugins[3]).toBe(options1.plugins[3]);
});
});
@ -318,14 +308,15 @@ describe("@babel/core config loading", () => {
plugins: opts.plugins.map(([plg, opt]) => [plg, { ...opt }]),
}).options;
expect(options2.plugins.length).toBe(options1.plugins.length);
expect(options2.plugins.length).toBe(6);
for (let i = 0; i < options2.plugins.length; i++) {
if (i === 2) {
expect(options2.plugins[i]).not.toBe(options1.plugins[i]);
} else {
expect(options2.plugins[i]).toBe(options1.plugins[i]);
}
}
expect(options2.plugins[2]).not.toBe(options1.plugins[2]);
expect(options2.plugins[0]).toBe(options1.plugins[0]);
expect(options2.plugins[1]).toBe(options1.plugins[1]);
expect(options2.plugins[3]).toBe(options1.plugins[3]);
expect(options2.plugins[4]).toBe(options1.plugins[4]);
expect(options2.plugins[5]).toBe(options1.plugins[5]);
});
it("should invalidate the presets when given a fresh options", () => {
@ -338,14 +329,15 @@ describe("@babel/core config loading", () => {
presets: opts.presets.map(([plg, opt]) => [plg, { ...opt }]),
}).options;
expect(options2.plugins.length).toBe(options1.plugins.length);
expect(options2.plugins.length).toBe(6);
for (let i = 0; i < options2.plugins.length; i++) {
if (i === 3) {
expect(options2.plugins[i]).not.toBe(options1.plugins[i]);
} else {
expect(options2.plugins[i]).toBe(options1.plugins[i]);
}
}
expect(options2.plugins[3]).not.toBe(options1.plugins[3]);
expect(options2.plugins[0]).toBe(options1.plugins[0]);
expect(options2.plugins[1]).toBe(options1.plugins[1]);
expect(options2.plugins[2]).toBe(options1.plugins[2]);
expect(options2.plugins[4]).toBe(options1.plugins[4]);
expect(options2.plugins[5]).toBe(options1.plugins[5]);
});
it("should invalidate the programmatic plugins", () => {
@ -357,14 +349,15 @@ describe("@babel/core config loading", () => {
const options2 = loadConfig(opts).options;
expect(options2.plugins.length).toBe(options1.plugins.length);
expect(options2.plugins.length).toBe(6);
for (let i = 0; i < options1.plugins.length; i++) {
if (i === 2) {
expect(options2.plugins[i]).not.toBe(options1.plugins[i]);
} else {
expect(options2.plugins[i]).toBe(options1.plugins[i]);
}
}
expect(options2.plugins[2]).not.toBe(options1.plugins[2]);
expect(options2.plugins[0]).toBe(options1.plugins[0]);
expect(options2.plugins[1]).toBe(options1.plugins[1]);
expect(options2.plugins[3]).toBe(options1.plugins[3]);
expect(options2.plugins[4]).toBe(options1.plugins[4]);
expect(options2.plugins[5]).toBe(options1.plugins[5]);
});
it("should invalidate the programmatic presets and their children", () => {
@ -376,14 +369,15 @@ describe("@babel/core config loading", () => {
const options2 = loadConfig(opts).options;
expect(options2.plugins.length).toBe(options1.plugins.length);
expect(options2.plugins.length).toBe(6);
for (let i = 0; i < options1.plugins.length; i++) {
if (i === 3) {
expect(options2.plugins[i]).not.toBe(options1.plugins[i]);
} else {
expect(options2.plugins[i]).toBe(options1.plugins[i]);
}
}
expect(options2.plugins[3]).not.toBe(options1.plugins[3]);
expect(options2.plugins[0]).toBe(options1.plugins[0]);
expect(options2.plugins[1]).toBe(options1.plugins[1]);
expect(options2.plugins[2]).toBe(options1.plugins[2]);
expect(options2.plugins[4]).toBe(options1.plugins[4]);
expect(options2.plugins[5]).toBe(options1.plugins[5]);
});
it("should thrown when plugin is not valid", () => {

View File

@ -229,8 +229,12 @@ describe("option-manager", () => {
});
describe("presets", function () {
function presetTest(name) {
it(name, function () {
it.each([
"es5_function",
"es5_object",
"es2015_default_function",
"es2015_default_object",
])("%p should work", name => {
const options = loadOptions({
presets: [path.join(cwd, "fixtures/option-manager/presets", name)],
});
@ -239,28 +243,17 @@ describe("option-manager", () => {
expect(options.plugins).toHaveLength(1);
expect(options.presets).toHaveLength(0);
});
}
function presetThrowsTest(name, msg) {
it(name, function () {
it.each([
["es2015_named", /Must export a default export when using ES6 modules/],
["es2015_invalid", /Unsupported format: string/],
["es5_invalid", /Unsupported format: string/],
])("%p should throw %p", (name, msg) => {
expect(() =>
loadOptions({
presets: [path.join(cwd, "fixtures/option-manager/presets", name)],
}),
).toThrow(msg);
});
}
presetTest("es5_function");
presetTest("es5_object");
presetTest("es2015_default_function");
presetTest("es2015_default_object");
presetThrowsTest(
"es2015_named",
/Must export a default export when using ES6 modules/,
);
presetThrowsTest("es2015_invalid", /Unsupported format: string/);
presetThrowsTest("es5_invalid", /Unsupported format: string/);
});
});

View File

@ -740,15 +740,19 @@ describe("programmatic generation", function () {
expect(output).toBe(`"\\u8868\\u683C_\\u526F\\u672C"`);
});
if (process.env.BABEL_8_BREAKING) {
it("default", () => {
const output = generate(string).code;
if (process.env.BABEL_8_BREAKING) {
expect(output).toBe(`"表格_副本"`);
} else {
expect(output).toBe(`"\\u8868\\u683C_\\u526F\\u672C"`);
}
});
} else {
it("default in Babel 7", () => {
const output = generate(string).code;
expect(output).toBe(`"\\u8868\\u683C_\\u526F\\u672C"`);
});
}
});
describe("typescript interface declaration", () => {

View File

@ -205,6 +205,7 @@ describe("bin/babel-node", function () {
opts.inFiles[".babelrc"] = helper.readFile(babelrcLoc);
}
// eslint-disable-next-line jest/valid-title
it(testName, buildTest(testName, opts), 20000);
});
});

View File

@ -53,17 +53,17 @@ describe("'decoratorsBeforeExport' option", function () {
run(AFTER, false, false);
function run(code, before, throws) {
const name =
(before === undefined ? "default" : before) +
" - decorators " +
(code === BEFORE ? "before" : "after") +
"export";
test(name, function () {
const expectTheParser = expect(
const codeTitle = code === BEFORE ? "before" : "after";
if (throws) {
test(`${before} - decorators ${codeTitle} export should throw`, function () {
expect(makeParser(code, { decoratorsBeforeExport: before })).toThrow();
});
} else {
test(`${before} - decorators ${codeTitle} export should not throw`, function () {
expect(
makeParser(code, { decoratorsBeforeExport: before }),
);
throws ? expectTheParser.toThrow() : expectTheParser.not.toThrow();
).not.toThrow();
});
}
}
});

View File

@ -4,21 +4,22 @@ import vm from "vm";
import { fileURLToPath } from "url";
describe("browserify", function () {
it("@babel/register may be used without breaking browserify", function (done) {
it("@babel/register may be used without breaking browserify", function () {
const bundler = browserify(
path.join(
path.dirname(fileURLToPath(import.meta.url)),
"fixtures/browserify/register.js",
),
);
return new Promise((resolve, reject) => {
bundler.bundle(function (err, bundle) {
if (err) return done(err);
if (err) return reject(err);
expect(bundle.length).toBeTruthy();
// ensure that the code runs without throwing an exception
vm.runInNewContext("var global = this;\n" + bundle, {});
done();
resolve();
});
});
});
});

View File

@ -93,14 +93,15 @@ describe("@babel/register - caching", () => {
expect(get()).toEqual({});
});
it("should create the cache after dirty", cb => {
it("should create the cache after dirty", () => {
load();
setDirty();
return new Promise(resolve => {
process.nextTick(() => {
expect(fs.existsSync(testCacheFilename)).toBe(true);
expect(get()).toEqual({});
cb();
resolve();
});
});
});
@ -117,20 +118,22 @@ describe("@babel/register - caching", () => {
});
}
it("should be disabled when CACHE_PATH is not allowed to write", cb => {
it("should be disabled when CACHE_PATH is not allowed to write", () => {
writeCache({ foo: "bar" }, 0o466);
load();
setDirty();
expect(get()).toEqual({ foo: "bar" });
return new Promise(resolve => {
process.nextTick(() => {
load();
expect(get()).toEqual({});
expect(consoleWarnSpy.mock.calls[0][0]).toContain(
"Babel could not write cache to file",
);
cb();
resolve();
});
});
});
});

View File

@ -145,7 +145,7 @@ describe("@babel/register", function () {
expect(sourceMapSupport).toBe(false);
});
it("returns concatenatable sourceRoot and sources", callback => {
it("returns concatenatable sourceRoot and sources", async () => {
// The Source Maps R3 standard https://sourcemaps.info/spec.html states
// that `sourceRoot` is “prepended to the individual entries in the
// source field.” If `sources` contains file names, and `sourceRoot`
@ -156,21 +156,15 @@ describe("@babel/register", function () {
// requires() another with @babel/register active, and I couldnt get
// that working inside a test, possibly because of jests mocking
// hooks, so we spawn a separate process.
spawnNode(["-r", registerFile, sourceMapTestFile], output => {
let err;
try {
const output = await spawnNodeAsync([
"-r",
registerFile,
sourceMapTestFile,
]);
const sourceMap = JSON.parse(output);
expect(sourceMap.map.sourceRoot + sourceMap.map.sources[0]).toBe(
sourceMapNestedTestFile,
);
} catch (e) {
err = e;
}
callback(err);
});
});
test("hook transpiles with config", () => {
@ -196,29 +190,21 @@ describe("@babel/register", function () {
expect(result).toBe('"use strict";\n\nrequire("assert");');
});
test("transforms modules used within register", callback => {
test("transforms modules used within register", async () => {
// Need a clean environment without `convert-source-map`
// already in the require cache, so we spawn a separate process
spawnNode([internalModulesTestFile], output => {
let err;
try {
const output = await spawnNodeAsync([internalModulesTestFile]);
const { convertSourceMap } = JSON.parse(output);
expect(convertSourceMap).toMatch("/* transformed */");
} catch (e) {
err = e;
}
callback(err);
});
});
});
function spawnNode(args, callback) {
function spawnNodeAsync(args) {
const spawn = child.spawn(process.execPath, args, { cwd: __dirname });
let output = "";
let callback;
for (const stream of [spawn.stderr, spawn.stdout]) {
stream.on("data", chunk => {
@ -229,4 +215,8 @@ function spawnNode(args, callback) {
spawn.on("close", function () {
callback(output);
});
return new Promise(resolve => {
callback = resolve;
});
}

View File

@ -4,40 +4,40 @@ exports[`scope duplicate bindings catch const 1`] = `"Duplicate declaration \\"e
exports[`scope duplicate bindings catch let 1`] = `"Duplicate declaration \\"e\\""`;
exports[`scope duplicate bindings global class/class 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global class/class should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global class/const 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global class/const should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global class/function 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global class/function should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global class/let 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global class/let should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global class/var 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global class/var should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global const/class 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global const/class should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global const/const 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global const/const should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global const/function 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global const/function should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global const/let 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global const/let should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global const/var 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global const/var should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global function/class 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global function/class should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global function/let 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global function/let should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global let/class 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global let/class should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global let/const 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global let/const should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global let/function 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global let/function should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global let/let 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global let/let should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global let/var 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global let/var should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global var/class 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global var/class should fail 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global var/let 1`] = `"Duplicate declaration \\"foo\\""`;
exports[`scope duplicate bindings global var/let should fail 1`] = `"Duplicate declaration \\"foo\\""`;

View File

@ -34,13 +34,13 @@ function addDeoptTest(code, type, expectedType) {
describe("evaluation", function () {
describe("evaluateTruthy", function () {
it("it should work with null", function () {
it("should work with null", function () {
expect(
getPath("false || a.length === 0;").get("body")[0].evaluateTruthy(),
).toBeUndefined();
});
it("it should not mistake lack of confidence for falsy", function () {
it("should not mistake lack of confidence for falsy", function () {
expect(
getPath("foo || 'bar'").get("body")[0].evaluate().value,
).toBeUndefined();
@ -117,7 +117,7 @@ describe("evaluation", function () {
expect(eval_invalid_call.confident).toBe(false);
});
it("it should not deopt vars in different scope", function () {
it("should not deopt vars in different scope", function () {
const input =
"var a = 5; function x() { var a = 5; var b = a + 1; } var b = a + 2";
expect(
@ -129,7 +129,7 @@ describe("evaluation", function () {
).toBe(7);
});
it("it should not deopt let/const inside blocks", function () {
it("should not deopt let/const inside blocks", function () {
expect(
getPath("let x = 5; { let x = 1; } let y = x + 5")
.get("body.2.declarations.0.init")

View File

@ -16,7 +16,7 @@ function getPath(code) {
describe("inference", function () {
describe("baseTypeStrictlyMatches", function () {
it("it should work with null", function () {
it("should work with null", function () {
const path = getPath("var x = null; x === null")
.get("body")[1]
.get("expression");
@ -27,7 +27,7 @@ describe("inference", function () {
expect(strictMatch).toBeTruthy();
});
it("it should work with numbers", function () {
it("should work with numbers", function () {
const path = getPath("var x = 1; x === 2")
.get("body")[1]
.get("expression");
@ -38,7 +38,7 @@ describe("inference", function () {
expect(strictMatch).toBeTruthy();
});
it("it should bail when type changes", function () {
it("should bail when type changes", function () {
const path = getPath("var x = 1; if (foo) x = null;else x = 3; x === 2")
.get("body")[2]
.get("expression");
@ -50,7 +50,7 @@ describe("inference", function () {
expect(strictMatch).toBeFalsy();
});
it("it should differentiate between null and undefined", function () {
it("should differentiate between null and undefined", function () {
const path = getPath("var x; x === null")
.get("body")[1]
.get("expression");

View File

@ -578,12 +578,16 @@ describe("scope", () => {
),
);
};
["let", "const"].forEach(name => {
it(name, () => {
const ast = createTryCatch(name);
it("let", () => {
const ast = createTryCatch("let");
expect(() => getPath(ast)).toThrowErrorMatchingSnapshot();
});
it("const", () => {
const ast = createTryCatch("const");
expect(() => getPath(ast)).toThrowErrorMatchingSnapshot();
});
it("var", () => {
@ -666,32 +670,36 @@ describe("scope", () => {
};
for (const [kind1, kind2, success] of cases) {
it(`${kind1}/${kind2}`, () => {
const ast = createAST(kind1, kind2);
if (success) {
it(`${kind1}/${kind2} should succeed`, () => {
const ast = createAST(kind1, kind2);
expect(() => getPath(ast)).not.toThrow();
} else {
expect(() => getPath(ast)).toThrowErrorMatchingSnapshot();
}
});
} else {
it(`${kind1}/${kind2} should fail`, () => {
const ast = createAST(kind1, kind2);
expect(() => getPath(ast)).toThrowErrorMatchingSnapshot();
});
}
if (kind1 !== kind2) {
// todo: remove the if allowed
if (kind1 === "const" && (kind2 === "function" || kind2 === "var")) {
continue;
}
it(`${kind2}/${kind1}`, () => {
const ast = createAST(kind2, kind1);
if (success) {
it(`${kind2}/${kind1} should succeed`, () => {
const ast = createAST(kind2, kind1);
expect(() => getPath(ast)).not.toThrow();
});
} else {
it(`${kind2}/${kind1} should fail`, () => {
const ast = createAST(kind2, kind1);
expect(() => getPath(ast)).toThrowErrorMatchingSnapshot();
}
});
}
}
}
});
});
});

View File

@ -15,7 +15,7 @@ describe("asserts", () => {
if (k.startsWith("assert") && k !== "assertNode") {
const nodeType = k.replace("assert", "");
it(nodeType, () => {
it(`${nodeType} on unknown AST type should throw`, () => {
expect(() => {
t[k]({ type: "FlavorTownDeclaration" }, {});
}).toThrow(

View File

@ -1,12 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`builders flow createTypeAnnotationBasedOnTypeof bigint 1`] = `
exports[`builders flow createTypeAnnotationBasedOnTypeof bigint is valid 1`] = `
Object {
"type": "AnyTypeAnnotation",
}
`;
exports[`builders flow createTypeAnnotationBasedOnTypeof function 1`] = `
exports[`builders flow createTypeAnnotationBasedOnTypeof function is valid 1`] = `
Object {
"id": Object {
"name": "Function",
@ -17,13 +17,13 @@ Object {
}
`;
exports[`builders flow createTypeAnnotationBasedOnTypeof number 1`] = `
exports[`builders flow createTypeAnnotationBasedOnTypeof number is valid 1`] = `
Object {
"type": "NumberTypeAnnotation",
}
`;
exports[`builders flow createTypeAnnotationBasedOnTypeof object 1`] = `
exports[`builders flow createTypeAnnotationBasedOnTypeof object is valid 1`] = `
Object {
"id": Object {
"name": "Object",
@ -34,13 +34,13 @@ Object {
}
`;
exports[`builders flow createTypeAnnotationBasedOnTypeof string 1`] = `
exports[`builders flow createTypeAnnotationBasedOnTypeof string is valid 1`] = `
Object {
"type": "StringTypeAnnotation",
}
`;
exports[`builders flow createTypeAnnotationBasedOnTypeof symbol 1`] = `
exports[`builders flow createTypeAnnotationBasedOnTypeof symbol is valid 1`] = `
Object {
"id": Object {
"name": "Symbol",
@ -51,13 +51,13 @@ Object {
}
`;
exports[`builders flow createTypeAnnotationBasedOnTypeof true 1`] = `
exports[`builders flow createTypeAnnotationBasedOnTypeof true is valid 1`] = `
Object {
"type": "BooleanTypeAnnotation",
}
`;
exports[`builders flow createTypeAnnotationBasedOnTypeof undefined 1`] = `
exports[`builders flow createTypeAnnotationBasedOnTypeof undefined is valid 1`] = `
Object {
"type": "VoidTypeAnnotation",
}

View File

@ -22,7 +22,7 @@ describe("builders", function () {
for (const name in values) {
const value = values[name];
it(name, function () {
it(`${name} is valid`, function () {
const result = createTypeAnnotationBasedOnTypeof(value);
expect(result).toMatchSnapshot();
});

865
yarn.lock

File diff suppressed because it is too large Load Diff