From f2fea017c6fc7e66bb331e935b9ae403792e5626 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Tue, 1 Mar 2016 08:14:14 -0800 Subject: [PATCH] Ensure that the found context is active before pushing it. --- .../test/fixtures/regression/T7165/actual.js | 6 ++++ .../fixtures/regression/T7165/expected.js | 31 +++++++++++++++++++ .../fixtures/regression/T7165/options.json | 6 ++++ .../babel-traverse/src/path/modification.js | 6 +++- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/actual.js create mode 100644 packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/expected.js create mode 100644 packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/options.json diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/actual.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/actual.js new file mode 100644 index 0000000000..680ffbcd79 --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/actual.js @@ -0,0 +1,6 @@ +import foo from 'foo'; +import { something } from 'bar'; + +const anything = {}; + +export * from 'bar'; diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/expected.js b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/expected.js new file mode 100644 index 0000000000..705591f7eb --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/expected.js @@ -0,0 +1,31 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _bar = require('bar'); + +var _loop = function (_key2) { + if (_key2 === "default") return 'continue'; + Object.defineProperty(exports, _key2, { + enumerable: true, + get: function () { + return _bar[_key2]; + } + }); +}; + +for (var _key2 in _bar) { + var _ret = _loop(_key2); + + if (_ret === 'continue') continue; +} + +var _foo = require('foo'); + +var _foo2 = _interopRequireDefault(_foo); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var anything = {}; diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/options.json b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/options.json new file mode 100644 index 0000000000..c96d00e02b --- /dev/null +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/test/fixtures/regression/T7165/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "transform-es2015-block-scoping", + "transform-es2015-modules-commonjs" + ] +} diff --git a/packages/babel-traverse/src/path/modification.js b/packages/babel-traverse/src/path/modification.js index 5811a19514..b2827613a3 100644 --- a/packages/babel-traverse/src/path/modification.js +++ b/packages/babel-traverse/src/path/modification.js @@ -47,7 +47,11 @@ export function _containerInsert(from, nodes) { if (this.context) { let path = this.context.create(this.parent, this.container, to, this.listKey); - path.pushContext(this.context); + + // While this path may have a context, there is currently no guarantee that the context + // will be the active context, because `popContext` may leave a final context in place. + // We should remove this `if` and always push once T7171 has been resolved. + if (this.context.queue) path.pushContext(this.context); paths.push(path); } else { paths.push(NodePath.get({