Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
Breaking: Upgraded Babel to 7.0.0-beta.51 (#642)
Browse files Browse the repository at this point in the history
* Upgraded Babel to 7.0.0-beta.51, with changes to decorators

* Removed support for Node 4 and added it for Node 10

* nit: fix typo [skip ci]
  • Loading branch information
rubennorte authored and existentialism committed Jun 29, 2018
1 parent e865104 commit 15e8d6f
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,9 +1,9 @@
sudo: false
language: node_js
node_js:
- "10"
- "8"
- "6"
- "4"

matrix:
fast_finish: true
Expand Down
11 changes: 7 additions & 4 deletions lib/parse.js
@@ -1,12 +1,15 @@
"use strict";

var babylonToEspree = require("./babylon-to-espree");
var parse = require("babylon").parse;
var tt = require("babylon").tokTypes;
var parse = require("@babel/parser").parse;
var tt = require("@babel/parser").tokTypes;
var traverse = require("@babel/traverse").default;
var codeFrameColumns = require("@babel/code-frame").codeFrameColumns;

module.exports = function(code, options) {
const legacyDecorators =
options.ecmaFeatures && options.ecmaFeatures.legacyDecorators;

var opts = {
codeFrame: options.hasOwnProperty("codeFrame") ? options.codeFrame : true,
sourceType: options.sourceType,
Expand All @@ -16,14 +19,14 @@ module.exports = function(code, options) {
ranges: true,
tokens: true,
plugins: [
"flow",
["flow", { all: true }],
"jsx",
"estree",
"asyncFunctions",
"asyncGenerators",
"classConstructorCall",
"classProperties",
"decorators",
legacyDecorators ? "decorators-legacy" : "decorators",
"doExpressions",
"exponentiationOperator",
"exportDefaultFrom",
Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -11,10 +11,10 @@
"url": "https://github.com/babel/babel-eslint.git"
},
"dependencies": {
"@babel/code-frame": "7.0.0-beta.44",
"@babel/traverse": "7.0.0-beta.44",
"@babel/types": "7.0.0-beta.44",
"babylon": "7.0.0-beta.44",
"@babel/code-frame": "7.0.0-beta.51",
"@babel/parser": "7.0.0-beta.51",
"@babel/traverse": "7.0.0-beta.51",
"@babel/types": "7.0.0-beta.51",
"eslint-scope": "~3.7.1",
"eslint-visitor-keys": "^1.0.0"
},
Expand All @@ -30,7 +30,7 @@
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"license": "MIT",
"engines": {
"node": ">=4"
"node": ">=6"
},
"bugs": {
"url": "https://github.com/babel/babel-eslint/issues"
Expand Down
112 changes: 100 additions & 12 deletions test/non-regression.js
Expand Up @@ -476,7 +476,7 @@ describe("verify", () => {
);
});

it("polymorphpic types #109", () => {
it("polymorphic types #109", () => {
verifyAndAssertMessages(
"export default function groupByEveryN<T>(array: Array<T>, n: number): Array<Array<?T>> { n; }",
{ "no-unused-vars": 1, "no-undef": 1 }
Expand All @@ -494,7 +494,7 @@ describe("verify", () => {
);
});

it("polymorphpic/generic types for class #123", () => {
it("polymorphic/generic types for class #123", () => {
verifyAndAssertMessages(
`
class Box<T> {
Expand All @@ -507,7 +507,7 @@ describe("verify", () => {
);
});

it("polymorphpic/generic types for function #123", () => {
it("polymorphic/generic types for function #123", () => {
verifyAndAssertMessages(
`
export function identity<T>(value) {
Expand All @@ -518,7 +518,7 @@ describe("verify", () => {
);
});

it("polymorphpic/generic types for type alias #123", () => {
it("polymorphic/generic types for type alias #123", () => {
verifyAndAssertMessages(
`
import Bar from './Bar';
Expand All @@ -528,7 +528,7 @@ describe("verify", () => {
);
});

it("polymorphpic/generic types - outside of fn scope #123", () => {
it("polymorphic/generic types - outside of fn scope #123", () => {
verifyAndAssertMessages(
`
export function foo<T>(value) { value; };
Expand All @@ -542,7 +542,7 @@ describe("verify", () => {
);
});

it("polymorphpic/generic types - extending unknown #123", () => {
it("polymorphic/generic types - extending unknown #123", () => {
verifyAndAssertMessages(
`
import Bar from 'bar';
Expand All @@ -553,6 +553,16 @@ describe("verify", () => {
);
});

it("polymorphic/generic types - function calls", () => {
verifyAndAssertMessages(
`
function f<T>(): T {}
f<T>();
`,
{ "no-unused-vars": 1, "no-undef": 1 }
);
});

it("support declarations #132", () => {
verifyAndAssertMessages(
`
Expand Down Expand Up @@ -1124,9 +1134,32 @@ describe("verify", () => {
);
});

describe("decorators #72", () => {
describe("decorators #72 (legacy)", () => {
function verifyDecoratorsLegacyAndAssertMessages(
code,
rules,
expectedMessages,
sourceType
) {
const overrideConfig = {
parserOptions: {
ecmaFeatures: {
legacyDecorators: true,
},
sourceType,
},
};
return verifyAndAssertMessages(
code,
rules,
expectedMessages,
sourceType,
overrideConfig
);
}

it("class declaration", () => {
verifyAndAssertMessages(
verifyDecoratorsLegacyAndAssertMessages(
`
import classDeclaration from 'decorator';
import decoratorParameter from 'decorator';
Expand All @@ -1140,7 +1173,7 @@ describe("verify", () => {
});

it("method definition", () => {
verifyAndAssertMessages(
verifyDecoratorsLegacyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
Expand All @@ -1158,7 +1191,7 @@ describe("verify", () => {
});

it("method definition get/set", () => {
verifyAndAssertMessages(
verifyDecoratorsLegacyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
Expand All @@ -1178,7 +1211,7 @@ describe("verify", () => {
});

it("object property", () => {
verifyAndAssertMessages(
verifyDecoratorsLegacyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
Expand All @@ -1197,7 +1230,7 @@ describe("verify", () => {
});

it("object property get/set", () => {
verifyAndAssertMessages(
verifyDecoratorsLegacyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
Expand All @@ -1218,6 +1251,61 @@ describe("verify", () => {
});
});

describe("decorators #72", () => {
it("class declaration", () => {
verifyAndAssertMessages(
`
import classDeclaration from 'decorator';
import decoratorParameter from 'decorator';
export
@classDeclaration((parameter) => parameter)
@classDeclaration(decoratorParameter)
@classDeclaration
class TextareaAutosize {}
`,
{ "no-unused-vars": 1 }
);
});

it("method definition", () => {
verifyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
export class TextareaAutosize {
@classMethodDeclarationA((parameter) => parameter)
@classMethodDeclarationA(decoratorParameter)
@classMethodDeclarationA
methodDeclaration(e) {
e();
}
}
`,
{ "no-unused-vars": 1 }
);
});

it("method definition get/set", () => {
verifyAndAssertMessages(
`
import classMethodDeclarationA from 'decorator';
import decoratorParameter from 'decorator';
export class TextareaAutosize {
@classMethodDeclarationA((parameter) => parameter)
@classMethodDeclarationA(decoratorParameter)
@classMethodDeclarationA
get bar() { }
@classMethodDeclarationA((parameter) => parameter)
@classMethodDeclarationA(decoratorParameter)
@classMethodDeclarationA
set bar(val) { val; }
}
`,
{ "no-unused-vars": 1 }
);
});
});

it("detects minimal no-unused-vars case #120", () => {
verifyAndAssertMessages("var unused;", { "no-unused-vars": 1 }, [
"1:5 'unused' is defined but never used. no-unused-vars",
Expand Down

0 comments on commit 15e8d6f

Please sign in to comment.