diff --git a/lib/Parser.js b/lib/Parser.js index 1ccd7fb80..fe3cb7c63 100644 --- a/lib/Parser.js +++ b/lib/Parser.js @@ -1064,13 +1064,54 @@ class Parser extends Tapable { } prewalkVariableDeclaration(statement) { - if(statement.declarations) - this.prewalkVariableDeclarators(statement.declarations); + const hookMap = statement.kind === "const" ? this.hooks.varDeclarationConst : + statement.kind === "let" ? this.hooks.varDeclarationLet : + this.hooks.varDeclarationVar; + for(const declarator of statement.declarations) { + switch(declarator.type) { + case "VariableDeclarator": + { + this.enterPattern(declarator.id, (name, decl) => { + let hook = hookMap.get(name); + if(hook === undefined || !hook.call(decl)) { + hook = this.hooks.varDeclaration.get(name); + if(hook === undefined || !hook.call(decl)) { + this.scope.renames.set(name, null); + this.scope.definitions.add(name); + } + } + }); + break; + } + } + } } walkVariableDeclaration(statement) { - if(statement.declarations) - this.walkVariableDeclarators(statement.declarations); + for(const declarator of statement.declarations) { + switch(declarator.type) { + case "VariableDeclarator": + { + const renameIdentifier = declarator.init && this.getRenameIdentifier(declarator.init); + if(renameIdentifier && declarator.id.type === "Identifier") { + const hook = this.hooks.canRename.get(renameIdentifier); + if(hook !== undefined && hook.call(declarator.init)) { + // renaming with "var a = b;" + const hook = this.hooks.rename.get(renameIdentifier); + if(hook === undefined || !hook.call(declarator.init)) { + this.scope.renames.set(declarator.id.name, this.scope.renames.get(renameIdentifier) || renameIdentifier); + this.scope.definitions.delete(declarator.id.name); + } + break; + } + } + this.walkPattern(declarator.id); + if(declarator.init) + this.walkExpression(declarator.init); + break; + } + } + } } prewalkClassDeclaration(statement) { @@ -1109,57 +1150,6 @@ class Parser extends Tapable { }); } - prewalkVariableDeclarators(declarators) { - for(const declarator of declarators) { - switch(declarator.type) { - case "VariableDeclarator": - { - this.enterPattern(declarator.id, (name, decl) => { - const hookMap = declarator.kind === "const" ? this.hooks.varDeclarationConst : - declarator.kind === "let" ? this.hooks.varDeclarationLet : - this.hooks.varDeclarationVar; - const hook = hookMap.get(name); - if(hook === undefined || !hook.call(decl)) { - const hook = this.hooks.varDeclaration.get(name); - if(hook === undefined || !hook.call(decl)) { - this.scope.renames.set(name, null); - this.scope.definitions.add(name); - } - } - }); - break; - } - } - } - } - - walkVariableDeclarators(declarators) { - for(const declarator of declarators) { - switch(declarator.type) { - case "VariableDeclarator": - { - const renameIdentifier = declarator.init && this.getRenameIdentifier(declarator.init); - if(renameIdentifier && declarator.id.type === "Identifier") { - const hook = this.hooks.canRename.get(renameIdentifier); - if(hook !== undefined && hook.call(declarator.init)) { - // renaming with "var a = b;" - const hook = this.hooks.rename.get(renameIdentifier); - if(hook === undefined || !hook.call(declarator.init)) { - this.scope.renames.set(declarator.id.name, this.scope.renames.get(renameIdentifier) || renameIdentifier); - this.scope.definitions.delete(declarator.id.name); - } - break; - } - } - this.walkPattern(declarator.id); - if(declarator.init) - this.walkExpression(declarator.init); - break; - } - } - } - } - walkPattern(pattern) { switch(pattern.type) { case "ArrayPattern":