Skip to content
Permalink
Browse files
feat: report class evaluation TDZ errors in no-use-before-define (#15134
)
  • Loading branch information
mdjermanovic committed Nov 5, 2021
1 parent 4fd7a6c commit c9fefd2e40348b3e02b855597707a557dc4991d5
Show file tree
Hide file tree
Showing 3 changed files with 734 additions and 78 deletions.
@@ -12,7 +12,6 @@ Examples of **incorrect** code for this rule:

```js
/*eslint no-use-before-define: "error"*/
/*eslint-env es6*/
alert(a);
var a = 10;
@@ -29,13 +28,29 @@ var b = 1;
alert(c);
let c = 1;
}
{
class C extends C {}
}
{
class C {
static x = "foo";
[C.x]() {}
}
}
{
const C = class {
static x = C;
}
}
```

Examples of **correct** code for this rule:

```js
/*eslint no-use-before-define: "error"*/
/*eslint-env es6*/
var a;
a = 10;
@@ -53,6 +68,24 @@ function g() {
let c;
c++;
}
{
class C {
static x = C;
}
}
{
const C = class C {
static x = C;
}
}
{
const C = class {
x = C;
}
}
```

## Options
@@ -103,18 +136,32 @@ Examples of **incorrect** code for the `{ "classes": false }` option:

```js
/*eslint no-use-before-define: ["error", { "classes": false }]*/
/*eslint-env es6*/
new A();
class A {
}
{
class C extends C {}
}
{
class C extends D {}
class D {}
}
{
class C {
static x = "foo";
[C.x]() {}
}
}
```

Examples of **correct** code for the `{ "classes": false }` option:

```js
/*eslint no-use-before-define: ["error", { "classes": false }]*/
/*eslint-env es6*/
function foo() {
return new A();
@@ -139,6 +186,19 @@ const f = () => {};
g();
const g = function() {};
{
const C = class {
static x = C;
}
}
{
const C = class {
static x = foo;
}
const foo = 1;
}
```

Examples of **correct** code for the `{ "variables": false }` option:
@@ -158,4 +218,11 @@ const f = () => {};
const e = function() { return g(); }
const g = function() {}
{
const C = class {
x = foo;
}
const foo = 1;
}
```

0 comments on commit c9fefd2

Please sign in to comment.