Skip to content

Commit e44ba30

Browse files
committed
Fix VariableDeclaration visitors
1 parent 6922a5e commit e44ba30

File tree

1 file changed

+44
-54
lines changed

1 file changed

+44
-54
lines changed

lib/Parser.js

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,63 +1063,17 @@ class Parser extends Tapable {
10631063
}
10641064

10651065
prewalkVariableDeclaration(statement) {
1066-
if(statement.declarations)
1067-
this.prewalkVariableDeclarators(statement.declarations);
1068-
}
1069-
1070-
walkVariableDeclaration(statement) {
1071-
if(statement.declarations)
1072-
this.walkVariableDeclarators(statement.declarations);
1073-
}
1074-
1075-
prewalkClassDeclaration(statement) {
1076-
if(statement.id) {
1077-
this.scope.renames.set(statement.id.name, null);
1078-
this.scope.definitions.add(statement.id.name);
1079-
}
1080-
}
1081-
1082-
walkClassDeclaration(statement) {
1083-
this.walkClass(statement);
1084-
}
1085-
1086-
prewalkSwitchCases(switchCases) {
1087-
for(let index = 0, len = switchCases.length; index < len; index++) {
1088-
const switchCase = switchCases[index];
1089-
this.prewalkStatements(switchCase.consequent);
1090-
}
1091-
}
1092-
1093-
walkSwitchCases(switchCases) {
1094-
for(let index = 0, len = switchCases.length; index < len; index++) {
1095-
const switchCase = switchCases[index];
1096-
1097-
if(switchCase.test) {
1098-
this.walkExpression(switchCase.test);
1099-
}
1100-
this.walkStatements(switchCase.consequent);
1101-
}
1102-
}
1103-
1104-
walkCatchClause(catchClause) {
1105-
this.inScope([catchClause.param], () => {
1106-
this.prewalkStatement(catchClause.body);
1107-
this.walkStatement(catchClause.body);
1108-
});
1109-
}
1110-
1111-
prewalkVariableDeclarators(declarators) {
1112-
for(const declarator of declarators) {
1066+
const hookMap = statement.kind === "const" ? this.hooks.varDeclarationConst :
1067+
statement.kind === "let" ? this.hooks.varDeclarationLet :
1068+
this.hooks.varDeclarationVar;
1069+
for(const declarator of statement.declarations) {
11131070
switch(declarator.type) {
11141071
case "VariableDeclarator":
11151072
{
11161073
this.enterPattern(declarator.id, (name, decl) => {
1117-
const hookMap = declarator.kind === "const" ? this.hooks.varDeclarationConst :
1118-
declarator.kind === "let" ? this.hooks.varDeclarationLet :
1119-
this.hooks.varDeclarationVar;
1120-
const hook = hookMap.get(name);
1074+
let hook = hookMap.get(name);
11211075
if(hook === undefined || !hook.call(decl)) {
1122-
const hook = this.hooks.varDeclaration.get(name);
1076+
hook = this.hooks.varDeclaration.get(name);
11231077
if(hook === undefined || !hook.call(decl)) {
11241078
this.scope.renames.set(name, null);
11251079
this.scope.definitions.add(name);
@@ -1132,8 +1086,8 @@ class Parser extends Tapable {
11321086
}
11331087
}
11341088

1135-
walkVariableDeclarators(declarators) {
1136-
for(const declarator of declarators) {
1089+
walkVariableDeclaration(statement) {
1090+
for(const declarator of statement.declarations) {
11371091
switch(declarator.type) {
11381092
case "VariableDeclarator":
11391093
{
@@ -1159,6 +1113,42 @@ class Parser extends Tapable {
11591113
}
11601114
}
11611115

1116+
prewalkClassDeclaration(statement) {
1117+
if(statement.id) {
1118+
this.scope.renames.set(statement.id.name, null);
1119+
this.scope.definitions.add(statement.id.name);
1120+
}
1121+
}
1122+
1123+
walkClassDeclaration(statement) {
1124+
this.walkClass(statement);
1125+
}
1126+
1127+
prewalkSwitchCases(switchCases) {
1128+
for(let index = 0, len = switchCases.length; index < len; index++) {
1129+
const switchCase = switchCases[index];
1130+
this.prewalkStatements(switchCase.consequent);
1131+
}
1132+
}
1133+
1134+
walkSwitchCases(switchCases) {
1135+
for(let index = 0, len = switchCases.length; index < len; index++) {
1136+
const switchCase = switchCases[index];
1137+
1138+
if(switchCase.test) {
1139+
this.walkExpression(switchCase.test);
1140+
}
1141+
this.walkStatements(switchCase.consequent);
1142+
}
1143+
}
1144+
1145+
walkCatchClause(catchClause) {
1146+
this.inScope([catchClause.param], () => {
1147+
this.prewalkStatement(catchClause.body);
1148+
this.walkStatement(catchClause.body);
1149+
});
1150+
}
1151+
11621152
walkPattern(pattern) {
11631153
switch(pattern.type) {
11641154
case "ArrayPattern":

0 commit comments

Comments
 (0)