Skip to content

Commit

Permalink
fix(es): Fix for the type checker (#1381)
Browse files Browse the repository at this point in the history
swc_ecma_codegen:
 - Fix codegen of `TsCallSignatureDecl`.

swc_ecma_transforms_base:
 - Handle `TsCallSignatureDecl`.
  • Loading branch information
kdy1 authored Feb 7, 2021
1 parent 7a93594 commit 686c981
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ecmascript/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include = ["Cargo.toml", "src/**/*.rs"]
license = "Apache-2.0/MIT"
name = "swc_ecma_codegen"
repository = "https://github.com/swc-project/swc.git"
version = "0.43.7"
version = "0.43.8"

[dependencies]
bitflags = "1"
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/codegen/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a> Emitter<'a> {

if let Some(type_ann) = &n.type_ann {
space!();
punct!("=>");
punct!(":");
space!();

emit!(type_ann);
Expand Down
2 changes: 1 addition & 1 deletion ecmascript/transforms/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2018"
license = "Apache-2.0/MIT"
name = "swc_ecma_transforms_base"
repository = "https://github.com/swc-project/swc.git"
version = "0.2.8"
version = "0.2.9"

[dependencies]
fxhash = "0.2.1"
Expand Down
23 changes: 22 additions & 1 deletion ecmascript/transforms/base/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,6 @@ macro_rules! noop {
impl<'a> VisitMut for Resolver<'a> {
noop!(visit_mut_accessibility, Accessibility);
noop!(visit_mut_true_plus_minus, TruePlusMinus);
noop!(visit_mut_ts_call_signature_decl, TsCallSignatureDecl);
noop!(visit_mut_ts_keyword_type, TsKeywordType);
noop!(visit_mut_ts_keyword_type_kind, TsKeywordTypeKind);
noop!(visit_mut_ts_type_operator_op, TsTypeOperatorOp);
Expand Down Expand Up @@ -538,6 +537,28 @@ impl<'a> VisitMut for Resolver<'a> {
ty.type_ann.visit_mut_with(&mut child);
}

fn visit_mut_ts_call_signature_decl(&mut self, n: &mut TsCallSignatureDecl) {
if !self.handle_types {
return;
}

self.in_type = true;
let child_mark = Mark::fresh(self.mark);

// Child folder
let mut child = Resolver::new(
child_mark,
Scope::new(ScopeKind::Fn, Some(&self.current)),
None,
self.handle_types,
);
child.in_type = true;

n.type_params.visit_mut_with(&mut child);
n.params.visit_mut_with(&mut child);
n.type_ann.visit_mut_with(&mut child);
}

fn visit_mut_ts_method_signature(&mut self, n: &mut TsMethodSignature) {
if !self.handle_types {
return;
Expand Down
23 changes: 23 additions & 0 deletions ecmascript/transforms/base/src/resolver/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2100,3 +2100,26 @@ to_ts!(
}
"
);

to_ts!(
generated_contextual_typing_01,
"
class Base { private p; }
var x338 = (n: { (): Base[]; }) => n;
x338(function named() { return [d1, d2] });
",
"
class Base {
private p__0;
}
var x338 = (n__2: {
(): Base[];
})=>n__2;
x338(function named() {
return [
d1,
d2
];
});
"
);

0 comments on commit 686c981

Please sign in to comment.