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

Commit

Permalink
fix(rome_js_analyze): noInvalidConstructorSuper recognize extends mod…
Browse files Browse the repository at this point in the history
….Member (#4501)
  • Loading branch information
Conaclos authored May 17, 2023
1 parent 55f062d commit 99d41a2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#### Other changes

- `noInnerDeclarations`: allow function declarations in nested block inside an _ES module_ [#4492](https://github.com/rome/tools/compare/main...Conaclos:noInnerDeclarations/4492?expand=1).
- `noInvalidConstructorSuper`: recognize `extends` clauses that use static member access such as `extends mod.C` [#4499](https://github.com/rome/tools/issues/4499)

## Parser
## VSCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ impl NoInvalidConstructorSuperState {
}
}
}

fn detail(&self) -> Option<(&TextRange, MarkupBuf)> {
match self {
NoInvalidConstructorSuperState::BadExtends { extends_range, .. } => Some((
Expand Down Expand Up @@ -150,7 +151,7 @@ impl Rule for NoInvalidConstructorSuper {
}

fn is_valid_constructor(expression: AnyJsExpression) -> Option<bool> {
match expression {
match expression.omit_parentheses() {
AnyJsExpression::JsThisExpression(_)
| AnyJsExpression::JsFunctionExpression(_)
| AnyJsExpression::JsCallExpression(_)
Expand All @@ -159,6 +160,7 @@ fn is_valid_constructor(expression: AnyJsExpression) -> Option<bool> {
| AnyJsExpression::JsYieldExpression(_)
| AnyJsExpression::JsNewExpression(_)
| AnyJsExpression::JsNewTargetExpression(_)
| AnyJsExpression::JsStaticMemberExpression(_)
| AnyJsExpression::JsClassExpression(_) => Some(true),
AnyJsExpression::JsIdentifierExpression(identifier) => {
let name = identifier.name().ok()?;
Expand All @@ -176,16 +178,13 @@ fn is_valid_constructor(expression: AnyJsExpression) -> Option<bool> {
) {
return is_valid_constructor(assignment.right().ok()?);
}

Some(false)
}

AnyJsExpression::JsLogicalExpression(expression) => {
let operator = expression.operator().ok()?;
if matches!(operator, JsLogicalOperator::LogicalAnd) {
return is_valid_constructor(expression.right().ok()?);
}

is_valid_constructor(expression.left().ok()?)
.or_else(|| is_valid_constructor(expression.right().ok()?))
}
Expand All @@ -196,9 +195,6 @@ fn is_valid_constructor(expression: AnyJsExpression) -> Option<bool> {
AnyJsExpression::JsSequenceExpression(sequence_expression) => {
is_valid_constructor(sequence_expression.right().ok()?)
}
AnyJsExpression::JsParenthesizedExpression(expression) => {
is_valid_constructor(expression.expression().ok()?)
}
_ => Some(false),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ export default class A extends B {
super();
}
}

export class A extends mod.B {
constructor() {
super();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
assertion_line: 96
expression: valid.js
---
# Input
Expand Down Expand Up @@ -42,6 +43,12 @@ export default class A extends B {
}
}

export class A extends mod.B {
constructor() {
super();
}
}

```


0 comments on commit 99d41a2

Please sign in to comment.