Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(es/ast): Remove unused fields of TsPropertySignature #8955

Merged
merged 3 commits into from
Jun 14, 2024
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.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 0 additions & 9 deletions bindings/binding_core_wasm/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2376,37 +2376,28 @@ export interface TsPropertySignature extends Node, HasSpan {
computed: boolean;
optional: boolean;

init?: Expression;
params: TsFnParameter[];

typeAnnotation?: TsTypeAnnotation;
typeParams?: TsTypeParameterDeclaration;
}

export interface TsGetterSignature extends Node, HasSpan {
type: "TsGetterSignature";

readonly: boolean;
key: Expression;
computed: boolean;
optional: boolean;
typeAnnotation?: TsTypeAnnotation;
}

export interface TsSetterSignature extends Node, HasSpan {
type: "TsSetterSignature";

readonly: boolean;
key: Expression;
computed: boolean;
optional: boolean;
param: TsFnParameter;
}

export interface TsMethodSignature extends Node, HasSpan {
type: "TsMethodSignature";

readonly: boolean;
key: Expression;
computed: boolean;
optional: boolean;
Expand Down
10 changes: 0 additions & 10 deletions crates/swc_ecma_ast/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,17 @@ pub struct TsPropertySignature {
pub key: Box<Expr>,
pub computed: bool,
pub optional: bool,
#[cfg_attr(feature = "serde-impl", serde(default))]
pub init: Option<Box<Expr>>,
pub params: Vec<TsFnParam>,
#[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))]
pub type_ann: Option<Box<TsTypeAnn>>,
#[cfg_attr(feature = "serde-impl", serde(default))]
pub type_params: Option<Box<TsTypeParamDecl>>,
}

#[ast_node("TsGetterSignature")]
#[derive(Eq, Hash, EqIgnoreSpan)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct TsGetterSignature {
pub span: Span,
pub readonly: bool,
pub key: Box<Expr>,
pub computed: bool,
pub optional: bool,
#[cfg_attr(feature = "serde-impl", serde(default, rename = "typeAnnotation"))]
pub type_ann: Option<Box<TsTypeAnn>>,
}
Expand All @@ -212,10 +205,8 @@ pub struct TsGetterSignature {
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct TsSetterSignature {
pub span: Span,
pub readonly: bool,
pub key: Box<Expr>,
pub computed: bool,
pub optional: bool,
pub param: TsFnParam,
}

Expand All @@ -224,7 +215,6 @@ pub struct TsSetterSignature {
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct TsMethodSignature {
pub span: Span,
pub readonly: bool,
pub key: Box<Expr>,
pub computed: bool,
pub optional: bool,
Expand Down
13 changes: 0 additions & 13 deletions crates/swc_ecma_codegen/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,6 @@ where
fn emit_ts_method_signature(&mut self, n: &TsMethodSignature) -> Result {
self.emit_leading_comments_of_span(n.span(), false)?;

if n.readonly {
keyword!("readonly");
}

if n.computed {
punct!("[");
emit!(n.key);
Expand Down Expand Up @@ -751,8 +747,6 @@ where
punct!("?");
}

emit!(n.type_params);

// punct!("(");
// self.emit_list(n.span, Some(&n.params), ListFormat::Parameters)?;
// punct!(")");
Expand All @@ -762,13 +756,6 @@ where
formatting_space!();
emit!(type_ann);
}

if let Some(init) = &n.init {
formatting_space!();
punct!("=");
formatting_space!();
emit!(init);
}
}

#[emitter]
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_ecma_parser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub enum SyntaxError {
ArrowNotAllowed,
ExportNotAllowed,
GetterSetterCannotBeReadonly,
GetterSetterCannotBeOptional,
GetterParam,
SetterParam,

Expand Down Expand Up @@ -563,6 +564,9 @@ impl SyntaxError {
SyntaxError::GetterSetterCannotBeReadonly => {
"A getter or a setter cannot be readonly".into()
}
SyntaxError::GetterSetterCannotBeOptional => {
"A getter or a setter cannot be optional".into()
}
SyntaxError::GetterParam => "A `get` accessor cannot have parameters".into(),
SyntaxError::SetterParam => "A `set` accessor must have exactly one parameter".into(),
SyntaxError::RestPatInSetter => "Rest pattern is not allowed in setter".into(),
Expand Down
20 changes: 8 additions & 12 deletions crates/swc_ecma_parser/src/parser/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,11 @@ impl<I: Tokens> Parser<I> {

let optional = eat!(self, '?');

if !readonly && is_one_of!(self, '(', '<') {
if is_one_of!(self, '(', '<') {
if readonly {
syntax_error!(self, SyntaxError::ReadOnlyMethod)
}

let type_params = self.try_parse_ts_type_params(false, true)?;
expect!(self, '(');
let params = self.parse_ts_binding_list_for_signature()?;
Expand All @@ -1432,7 +1436,6 @@ impl<I: Tokens> Parser<I> {
Ok(Either::Right(TsMethodSignature {
span: span!(self, start),
computed,
readonly,
key,
optional,
type_params,
Expand All @@ -1449,9 +1452,6 @@ impl<I: Tokens> Parser<I> {
readonly,
key,
optional,
init: None,
type_params: None,
params: vec![],
type_ann,
}))
}
Expand Down Expand Up @@ -1491,7 +1491,9 @@ impl<I: Tokens> Parser<I> {
if let Some(v) = self.try_parse_ts(|p| {
let start = p.input.cur_pos();

let readonly = p.parse_ts_modifier(&["readonly"], false)?.is_some();
if readonly {
syntax_error!(p, SyntaxError::GetterSetterCannotBeReadonly)
}

let is_get = if eat!(p, "get") {
true
Expand All @@ -1502,8 +1504,6 @@ impl<I: Tokens> Parser<I> {

let (computed, key) = p.parse_ts_property_name()?;

let optional = eat!(p, '?');

if is_get {
expect!(p, '(');
expect!(p, ')');
Expand All @@ -1513,10 +1513,8 @@ impl<I: Tokens> Parser<I> {

Ok(Some(TsTypeElement::TsGetterSignature(TsGetterSignature {
span: span!(p, start),
readonly,
key,
computed,
optional,
type_ann,
})))
} else {
Expand All @@ -1531,10 +1529,8 @@ impl<I: Tokens> Parser<I> {

Ok(Some(TsTypeElement::TsSetterSignature(TsSetterSignature {
span: span!(p, start),
readonly,
key,
computed,
optional,
param,
})))
}
Expand Down