Skip to content

Analyze ClassAccessorProperty to prevent the no-undef rule - #16884

Merged
JLHwung merged 3 commits into
babel:mainfrom
victorenator:patch-1
Oct 12, 2024
Merged

JLHwung merged 3 commits into
babel:mainfrom
victorenator:patch-1

Conversation

@victorenator

@victorenator victorenator commented Oct 6, 2024 •

Copy link
Copy Markdown
Contributor

a.js:

class A {
  accessor b;
}

Current and expected behavior:

npx eslint a.js
a.js
  2:11  error  'b' is not defined  no-undef

✖ 1 problem (1 error, 0 warnings)
Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

a.js:

```js
class A {
  accessor b;
}
```

Current and expected behavior:

```bash
npx eslint a.js
```

```
a.js
  2:11  error  'b' is not defined  no-undef

✖ 1 problem (1 error, 0 warnings)
```
@babel-bot

babel-bot commented Oct 6, 2024 •

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58079

@JLHwung

JLHwung commented Oct 6, 2024

Copy link
Copy Markdown
Contributor

Can you add some new tests to eslint/babel-eslint-tests/test/integration/eslint/verify.js? They would be similar to what we have for class field declarations:

describe("field declarations", () => {
it("should not be undefined", () => {
verifyAndAssertMessages(
`
class C {
d = 1;
}
`,
{ "no-undef": 1 },
);
});
it("should not be unused", () => {
verifyAndAssertMessages(
`
export class C {
d = 1;
}
`,
{ "no-unused-vars": 1 },
);
});
it("no-use-before-define allows referencing the class in a field", () => {
verifyAndAssertMessages(
`
class C {
d = C.name;
}
`,
{ "no-use-before-define": 1 },
);
});
});

);
});

it("no-use-before-define allows referencing the class in a accessor", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it("no-use-before-define allows referencing the class in a accessor", () => {
it("no-use-before-define allows referencing the class in an accessor", () => {

@JLHwung
JLHwung requested a review from liuxingbaoyu October 12, 2024 02:48

@liuxingbaoyu liuxingbaoyu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories area: eslint labels Oct 12, 2024
@JLHwung
JLHwung merged commit 33d705e into babel:main Oct 12, 2024
@victorenator
victorenator deleted the patch-1 branch October 22, 2024 19:01
@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 22, 2025
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jan 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: eslint outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants