fix(es/lints): Fix const-assign in function expressions (#6294)

This commit is contained in:
Johan Holmerin 2022-10-30 13:34:57 +01:00 committed by GitHub
parent ff700d8252
commit a27392a251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 2 deletions

View File

@ -31,3 +31,8 @@ b &&= 10;
c ||= 10; c ||= 10;
d ??= 10; d ??= 10;
const fn = () => {
const e = 100;
e = 200;
};

View File

@ -518,3 +518,13 @@
: | : |
: `-- cannot reassign : `-- cannot reassign
`---- `----
x cannot reassign to a variable declared with `const`
,-[36:3]
36 | const e = 100;
: |
: `-- const variable was declared here
37 | e = 200;
: |
: `-- cannot reassign
`----

View File

@ -108,11 +108,13 @@ impl Visit for ConstAssign {
program.visit_children_with(self); program.visit_children_with(self);
} }
fn visit_var_decl(&mut self, var_decl: &VarDecl) { fn visit_var_declarator(&mut self, var_declarator: &VarDeclarator) {
let old_is_pat_decl = self.is_pat_decl; let old_is_pat_decl = self.is_pat_decl;
self.is_pat_decl = true; self.is_pat_decl = true;
var_decl.visit_children_with(self); var_declarator.name.visit_with(self);
self.is_pat_decl = old_is_pat_decl; self.is_pat_decl = old_is_pat_decl;
var_declarator.init.visit_with(self);
} }
} }