fix(es/resolver): Ensure that a parameter type is resolved to parent (#4645)

This commit is contained in:
David Sherret 2022-05-13 02:31:52 -04:00 committed by GitHub
parent d9d3585732
commit 2745cb7949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 3 deletions

View File

@ -440,7 +440,9 @@ macro_rules! typed_ref {
($name:ident, $T:ty) => {
fn $name(&mut self, node: &mut $T) {
if self.config.handle_types {
let ident_type = self.ident_type;
node.visit_mut_children_with(self);
self.ident_type = ident_type;
}
}
};
@ -451,9 +453,11 @@ macro_rules! typed_ref_init {
fn $name(&mut self, node: &mut $T) {
if self.config.handle_types {
let in_type = self.in_type;
let ident_type = self.ident_type;
self.ident_type = IdentType::Ref;
self.in_type = true;
node.visit_mut_children_with(self);
self.ident_type = ident_type;
self.in_type = in_type;
}
}
@ -1058,6 +1062,21 @@ impl<'a> VisitMut for Resolver<'a> {
p.visit_mut_children_with(self);
}
fn visit_mut_assign_pat(&mut self, node: &mut AssignPat) {
// visit the type first so that it doesn't resolve any
// identifiers from the others
node.type_ann.visit_mut_with(self);
node.left.visit_mut_with(self);
node.right.visit_mut_with(self);
}
fn visit_mut_rest_pat(&mut self, node: &mut RestPat) {
// visit the type first so that it doesn't resolve any
// identifiers from the arg
node.type_ann.visit_mut_with(self);
node.arg.visit_mut_with(self);
}
fn visit_mut_private_method(&mut self, m: &mut PrivateMethod) {
m.key.visit_mut_with(self);

View File

@ -0,0 +1,6 @@
var k, v;
var map = new Map([["", true]]);
for ([k, ...[v]] of map) {
k;
v;
}

View File

@ -0,0 +1,11 @@
var k__1, v__1;
var map__1 = new Map([
[
"",
true
]
]);
for ([k__1, ...[v__1]] of map__1){
k__1;
v__1;
}

View File

@ -1,6 +1,9 @@
import type { Foo } from "./foo.ts";
// ^^^ <---- (a)
function _bar(...Foo: Foo) {
// ^^^ <---- (b)
console.log(Foo);
}
function _bar2(Foo: Foo, other = Foo) {
Foo;
}

View File

@ -1,4 +1,7 @@
import { Foo__1 } from "./foo.ts";
function _bar__1(...Foo__2: Foo__2) {
function _bar__1(...Foo__2: Foo__1) {
console.log(Foo__2);
}
function _bar2__1(Foo__4: Foo__1, other__4 = Foo__4) {
Foo__4;
}