From 254e6ea4bf14a602ea74200b3c539212e4110fe2 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Fri, 8 Jul 2016 14:23:04 -0400 Subject: [PATCH] Create a variable for class properties in scope instead of deleting the key (#336) --- babylon-to-espree/toAST.js | 5 ----- index.js | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/babylon-to-espree/toAST.js b/babylon-to-espree/toAST.js index 5dce899a..cc680e99 100644 --- a/babylon-to-espree/toAST.js +++ b/babylon-to-espree/toAST.js @@ -206,11 +206,6 @@ var astTransformVisitor = { } } - // remove class property keys (or patch in escope) - if (path.isClassProperty()) { - delete node.key; - } - // async function as generator if (path.isFunction()) { if (node.async) node.generator = true; diff --git a/index.js b/index.js index 004f3a76..9cbfb51a 100644 --- a/index.js +++ b/index.js @@ -229,6 +229,13 @@ function monkeypatch() { // visit decorators that are in: ClassDeclaration / ClassExpression var visitClass = referencer.prototype.visitClass; referencer.prototype.visitClass = function(node) { + var classBody = node.body.body; + for (var a = 0; a < classBody.length; a++) { + if (classBody[a].type === "ClassProperty") { + createScopeVariable.call(this, classBody[a], classBody[a].key); + } + } + visitDecorators.call(this, node); var typeParamScope; if (node.typeParameters) {