diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/actual.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/actual.js new file mode 100644 index 0000000000..988e22c813 --- /dev/null +++ b/packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/actual.js @@ -0,0 +1,4 @@ +export default { + [a]: b, + [c]: d +}; \ No newline at end of file diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/expected.js b/packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/expected.js new file mode 100644 index 0000000000..ba3cebe17f --- /dev/null +++ b/packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/expected.js @@ -0,0 +1,3 @@ +var _a$c; + +export default (_a$c = {}, babelHelpers.defineProperty(_a$c, a, b), babelHelpers.defineProperty(_a$c, c, d), _a$c); diff --git a/packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/options.json b/packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/options.json new file mode 100644 index 0000000000..1f70f9c5c9 --- /dev/null +++ b/packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["external-helpers", "transform-computed-properties"] +} diff --git a/packages/babel-traverse/src/path/modification.js b/packages/babel-traverse/src/path/modification.js index 4eaf93543e..77cb382160 100644 --- a/packages/babel-traverse/src/path/modification.js +++ b/packages/babel-traverse/src/path/modification.js @@ -17,7 +17,8 @@ export function insertBefore(nodes) { if ( this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement() || - this.parentPath.isExportDeclaration() + this.parentPath.isExportNamedDeclaration() || + (this.parentPath.isExportDefaultDeclaration() && this.isDeclaration()) ) { return this.parentPath.insertBefore(nodes); } else if ( @@ -98,7 +99,8 @@ export function insertAfter(nodes) { if ( this.parentPath.isExpressionStatement() || this.parentPath.isLabeledStatement() || - this.parentPath.isExportDeclaration() + this.parentPath.isExportNamedDeclaration() || + (this.parentPath.isExportDefaultDeclaration() && this.isDeclaration()) ) { return this.parentPath.insertAfter(nodes); } else if ( diff --git a/packages/babel-traverse/test/modification.js b/packages/babel-traverse/test/modification.js index e526b4d6b4..3691608249 100644 --- a/packages/babel-traverse/test/modification.js +++ b/packages/babel-traverse/test/modification.js @@ -143,14 +143,13 @@ describe("modification", function() { }); it("the exported expression", function() { - const bodyPath = getPath("export default 2;", { + const declPath = getPath("export default 2;", { sourceType: "module", - }).parentPath; - const path = bodyPath.get("body.0.declaration"); + }); + const path = declPath.get("declaration"); path.insertBefore(t.identifier("x")); - assert.equal(bodyPath.get("body").length, 2); - assert.deepEqual(bodyPath.get("body.0").node, t.identifier("x")); + assert.equal(generateCode(declPath), "export default (x, 2);"); }); }); }); @@ -236,8 +235,10 @@ describe("modification", function() { const path = bodyPath.get("body.0.declaration"); path.insertAfter(t.identifier("x")); - assert.equal(bodyPath.get("body").length, 2); - assert.deepEqual(bodyPath.get("body.1").node, t.identifier("x")); + assert.equal( + generateCode({ parentPath: bodyPath }), + "var _temp;\n\nexport default (_temp = 2, x, _temp);", + ); }); }); });