diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7194/actual.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7194/actual.js new file mode 100644 index 0000000000..bd37aa462a --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7194/actual.js @@ -0,0 +1,13 @@ +function f() { + g(async function() { + c(() => this); + }); +} + +(async function () { + console.log('async wrapper:', this === 'foo') + + ;(() => { + console.log('nested arrow:', this === 'foo') + })() +}).call('foo') diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7194/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7194/expected.js new file mode 100644 index 0000000000..158a9d5eb8 --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7194/expected.js @@ -0,0 +1,17 @@ +function f() { + g(babelHelpers.asyncToGenerator(function* () { + var _this = this; + + c(function () { + return _this; + }); + })); +} + +babelHelpers.asyncToGenerator(function* () { + var _this2 = this; + + console.log('async wrapper:', this === 'foo');(function () { + console.log('nested arrow:', _this2 === 'foo'); + })(); +}).call('foo'); diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7194/options.json b/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7194/options.json new file mode 100644 index 0000000000..ca83e712a9 --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7194/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "transform-es2015-arrow-functions", + "transform-async-to-generator", + "external-helpers" + ] +} diff --git a/packages/babel-traverse/src/scope/index.js b/packages/babel-traverse/src/scope/index.js index a093ad3d50..7e8176637c 100644 --- a/packages/babel-traverse/src/scope/index.js +++ b/packages/babel-traverse/src/scope/index.js @@ -23,17 +23,17 @@ let _crawlCallsCount = 0; * node itself containing all scopes it has been associated with. */ -function getCache(node, parentScope, self) { - let scopes: Array = scopeCache.get(node) || []; +function getCache(path, parentScope, self) { + let scopes: Array = scopeCache.get(path.node) || []; for (let scope of scopes) { - if (scope.parent === parentScope) return scope; + if (scope.parent === parentScope && scope.path === path) return scope; } scopes.push(self); - if (!scopeCache.has(node)) { - scopeCache.set(node, scopes); + if (!scopeCache.has(path.node)) { + scopeCache.set(path.node, scopes); } } @@ -150,7 +150,7 @@ export default class Scope { return parentScope; } - let cached = getCache(path.node, parentScope, this); + let cached = getCache(path, parentScope, this); if (cached) return cached; this.uid = uid++;