From 56335409d324083a384e96aed8f12bf8be430272 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sat, 4 Apr 2015 14:01:26 +1100 Subject: [PATCH] stop constructor verification traversal on FunctionDeclaration/FunctionExpression - fixes #1155 --- src/babel/transformation/transformers/es6/classes.js | 12 ++++++++++++ test/core/fixtures/transformation/misc/options.json | 3 +++ .../transformation/misc/regression-1155/actual.js | 9 +++++++++ .../transformation/misc/regression-1155/expected.js | 11 +++++++++++ 4 files changed, 35 insertions(+) create mode 100644 test/core/fixtures/transformation/misc/options.json create mode 100644 test/core/fixtures/transformation/misc/regression-1155/actual.js create mode 100644 test/core/fixtures/transformation/misc/regression-1155/expected.js diff --git a/src/babel/transformation/transformers/es6/classes.js b/src/babel/transformation/transformers/es6/classes.js index bde532ea03..db62df61e4 100644 --- a/src/babel/transformation/transformers/es6/classes.js +++ b/src/babel/transformation/transformers/es6/classes.js @@ -62,6 +62,18 @@ var verifyConstructorVisitor = traverse.explode({ } }, + FunctionDeclaration: { + enter() { + this.skip(); + } + }, + + FunctionExpression: { + enter() { + this.skip(); + } + }, + ThisExpression: { enter(node, parent, scope, state) { if (state.hasSuper && !state.hasBareSuper) { diff --git a/test/core/fixtures/transformation/misc/options.json b/test/core/fixtures/transformation/misc/options.json new file mode 100644 index 0000000000..7d6e6cda1c --- /dev/null +++ b/test/core/fixtures/transformation/misc/options.json @@ -0,0 +1,3 @@ +{ + "externalHelpers": true +} diff --git a/test/core/fixtures/transformation/misc/regression-1155/actual.js b/test/core/fixtures/transformation/misc/regression-1155/actual.js new file mode 100644 index 0000000000..f94a7f5899 --- /dev/null +++ b/test/core/fixtures/transformation/misc/regression-1155/actual.js @@ -0,0 +1,9 @@ +class Foo { + constructor (options) { + let parentOptions = {}; + parentOptions.init = function () { + this; + }; + super(parentOptions); + } +} diff --git a/test/core/fixtures/transformation/misc/regression-1155/expected.js b/test/core/fixtures/transformation/misc/regression-1155/expected.js new file mode 100644 index 0000000000..e9efbee824 --- /dev/null +++ b/test/core/fixtures/transformation/misc/regression-1155/expected.js @@ -0,0 +1,11 @@ +"use strict"; + +var Foo = function Foo(options) { + babelHelpers.classCallCheck(this, Foo); + + var parentOptions = {}; + parentOptions.init = function () { + this; + }; + babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this, parentOptions); +};