diff --git a/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js b/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js index 4eb08783f2..572b9bb379 100644 --- a/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js +++ b/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js @@ -49,21 +49,25 @@ function remap(path, key) { let currentFunction; let passedShadowFunction = false; - let fnPath = path.findParent(function (path) { - if (path.isProgram() || path.isFunction()) { + let fnPath = path.find(function (innerPath) { + if (innerPath.parentPath && innerPath.parentPath.isClassProperty() && innerPath.key === "value") { + return true; + } + if (path === innerPath) return false; + if (innerPath.isProgram() || innerPath.isFunction()) { // catch current function in case this is the shadowed one and we can ignore it - currentFunction = currentFunction || path; + currentFunction = currentFunction || innerPath; } - if (path.isProgram()) { + if (innerPath.isProgram()) { passedShadowFunction = true; return true; - } else if (path.isFunction() && !path.isArrowFunctionExpression()) { + } else if (innerPath.isFunction() && !innerPath.isArrowFunctionExpression()) { if (shadowFunction) { - if (path === shadowFunction || path.node === shadowFunction.node) return true; + if (innerPath === shadowFunction || innerPath.node === shadowFunction.node) return true; } else { - if (!path.is("shadow")) return true; + if (!innerPath.is("shadow")) return true; } passedShadowFunction = true; diff --git a/packages/babel-core/test/fixtures/transformation/misc/class-property-initializer-blocks-shadow/actual.js b/packages/babel-core/test/fixtures/transformation/misc/class-property-initializer-blocks-shadow/actual.js new file mode 100644 index 0000000000..0a1fda2178 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/misc/class-property-initializer-blocks-shadow/actual.js @@ -0,0 +1,10 @@ +class A { + prop1 = () => this; + static prop2 = () => this; + prop3 = () => arguments; + static prop4 = () => arguments; + prop5 = this; + static prop6 = this; + prop7 = arguments; + static prop8 = arguments; +} diff --git a/packages/babel-core/test/fixtures/transformation/misc/class-property-initializer-blocks-shadow/expected.js b/packages/babel-core/test/fixtures/transformation/misc/class-property-initializer-blocks-shadow/expected.js new file mode 100644 index 0000000000..0a1fda2178 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/misc/class-property-initializer-blocks-shadow/expected.js @@ -0,0 +1,10 @@ +class A { + prop1 = () => this; + static prop2 = () => this; + prop3 = () => arguments; + static prop4 = () => arguments; + prop5 = this; + static prop6 = this; + prop7 = arguments; + static prop8 = arguments; +} diff --git a/packages/babel-core/test/fixtures/transformation/misc/class-property-initializer-blocks-shadow/options.json b/packages/babel-core/test/fixtures/transformation/misc/class-property-initializer-blocks-shadow/options.json new file mode 100644 index 0000000000..7b4b869750 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/misc/class-property-initializer-blocks-shadow/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["syntax-class-properties"] +}