Skip to content

Commit

Permalink
feat: report class evaluation TDZ errors in no-use-before-define (#15134
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mdjermanovic committed Nov 5, 2021
1 parent 4fd7a6c commit c9fefd2
Show file tree
Hide file tree
Showing 3 changed files with 734 additions and 78 deletions.
75 changes: 71 additions & 4 deletions docs/rules/no-use-before-define.md
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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:
Expand All @@ -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.