fix(linter/no-unused-vars): mark the class/function in the new expression as used (#5306)

Fix: #5274
This commit is contained in:
magic-akari 2024-08-29 01:38:16 +08:00 committed by GitHub
parent 08dc0adeab
commit 318479ec4d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -42,6 +42,9 @@ impl<'s, 'a> Symbol<'s, 'a> {
// e.g. var foo = function bar() { }
// we don't want to check for violations on `bar`, just `foo`
| AstKind::VariableDeclarator(_)
// new (class CustomRenderer{})
// new (function() {})
| AstKind::NewExpression(_)
=> {
return true;
}

View file

@ -13,6 +13,12 @@ fn test_vars_simple() {
("let a = 1; if (true) { console.log(a) }", None),
("let _a = 1", Some(json!([{ "varsIgnorePattern": "^_" }]))),
("const { foo: _foo, baz } = obj; f(baz);", Some(json!([{ "varsIgnorePattern": "^_" }]))),
(
r"export const rendered = marked(markdown, {
renderer: new (class CustomRenderer extends Renderer {})(),
});",
None,
),
];
let fail = vec![
("let a = 1", None),