Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,28 @@ pub struct StaticMemberExpression<'a> {
pub optional: bool, // for optional chaining
}

impl<'a> StaticMemberExpression<'a> {
pub fn get_first_object(&self) -> &Expression<'a> {
match &self.object {
Expression::StaticMemberExpression(member) => {
if let Expression::StaticMemberExpression(expr) = &member.object {
expr.get_first_object()
} else {
&self.object
}
}
Expression::ChainExpression(chain) => {
if let ChainElement::StaticMemberExpression(expr) = &chain.expression {
expr.get_first_object()
} else {
&self.object
}
}
_ => &self.object,
}
}
}

/// `MemberExpression[?Yield, ?Await] . PrivateIdentifier`
#[visited_node]
#[derive(Debug, Hash)]
Expand Down
18 changes: 17 additions & 1 deletion crates/oxc_transformer_dts/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use oxc_ast::ast::*;
use oxc_allocator::Box;
use oxc_span::{GetSpan, SPAN};

use crate::{diagnostics::computed_property_name, TransformerDts};
use crate::{
diagnostics::{computed_property_name, extends_clause_expression},
TransformerDts,
};

impl<'a> TransformerDts<'a> {
pub fn is_literal_key(&self, key: &PropertyKey<'a>) -> bool {
Expand Down Expand Up @@ -199,6 +202,19 @@ impl<'a> TransformerDts<'a> {
return None;
}

if let Some(super_class) = &decl.super_class {
let is_not_allowed = match super_class {
Expression::Identifier(_) => false,
Expression::StaticMemberExpression(expr) => {
!expr.get_first_object().is_identifier_reference()
}
_ => true,
};
if is_not_allowed {
self.ctx.error(extends_clause_expression(super_class.span()));
}
}

let mut elements = self.ctx.ast.new_vec();
let mut has_private_key = false;
for element in &decl.body.body {
Expand Down
6 changes: 1 addition & 5 deletions crates/oxc_transformer_dts/src/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,7 @@ impl<'a> TransformerDts<'a> {
let is_not_allowed = match key {
PropertyKey::StaticIdentifier(_) | PropertyKey::Identifier(_) => false,
PropertyKey::StaticMemberExpression(expr) => {
let mut object = &expr.object;
while let Expression::StaticMemberExpression(expr) = &object {
object = &expr.object;
}
!object.is_identifier_reference()
!expr.get_first_object().is_identifier_reference()
}
key => !self.is_literal_key(key),
};
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_transformer_dts/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ pub fn enum_member_initializers(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Enum member initializers must be computable without references to external symbols with --isolatedDeclarations.")
.with_label(span)
}

pub fn extends_clause_expression(span: Span) -> OxcDiagnostic {
OxcDiagnostic::error("Extends clause can't contain an expression with --isolatedDeclarations.")
.with_label(span)
}