Skip to content

Commit

Permalink
feat(transformer): drop this parameter from typescript functions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen authored Oct 20, 2023
1 parent ee134f0 commit d31a667
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
10 changes: 10 additions & 0 deletions crates/oxc_transformer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,14 @@ impl<'a> VisitMut<'a> for Transformer<'a> {
self.visit_class_element(class_element);
});
}

fn visit_formal_parameters(&mut self, params: &mut FormalParameters<'a>) {
self.typescript.as_mut().map(|t| t.transform_formal_parameters(params));
for param in params.items.iter_mut() {
self.visit_formal_parameter(param);
}
if let Some(rest) = &mut params.rest {
self.visit_rest_element(rest);
}
}
}
8 changes: 8 additions & 0 deletions crates/oxc_transformer/src/typescript/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use oxc_ast::ast::*;
use oxc_ast::AstBuilder;

use std::rc::Rc;
Expand All @@ -15,4 +16,11 @@ impl<'a> TypeScript<'a> {
pub fn new(_ast: Rc<AstBuilder<'a>>) -> Self {
Self { _ast }
}

#[allow(clippy::unused_self)]
pub fn transform_formal_parameters(&self, params: &mut FormalParameters<'a>) {
if params.items.get(0).is_some_and(|param| matches!(&param.pattern.kind, BindingPatternKind::BindingIdentifier(ident) if ident.name =="this")) {
params.items.remove(0);
}
}
}
6 changes: 2 additions & 4 deletions tasks/transform_conformance/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Passed: 160/1087
Passed: 162/1087

# All Passed:
* babel-plugin-transform-numeric-separator
Expand Down Expand Up @@ -714,7 +714,7 @@ Passed: 160/1087
* unicode-regex/negated-set/input.js
* unicode-regex/slash/input.js

# babel-plugin-transform-typescript (71/181)
# babel-plugin-transform-typescript (73/181)
* class/abstract-class-decorated/input.ts
* class/abstract-class-decorated-method/input.ts
* class/abstract-class-decorated-parameter/input.ts
Expand Down Expand Up @@ -749,7 +749,6 @@ Passed: 160/1087
* enum/string-value-template/input.ts
* enum/string-values-computed/input.ts
* enum/ts5.0-const-foldable/input.ts
* exports/declare-shadowed/input.ts
* exports/declared-types/input.ts
* exports/export-const-enums/input.ts
* exports/export-type/input.ts
Expand All @@ -763,7 +762,6 @@ Passed: 160/1087
* exports/type-only-export-specifier-2/input.ts
* exports/type-only-export-specifier-3/input.ts
* function/overloads-exports/input.mjs
* function/this-parameter/input.ts
* imports/elide-injected/input.ts
* imports/elide-preact/input.ts
* imports/elide-react/input.ts
Expand Down

0 comments on commit d31a667

Please sign in to comment.