Fix a regression introduced in #7040 (#7116)

This commit is contained in:
Nicolò Ribaudo 2017-12-28 22:15:53 +01:00 committed by GitHub
parent d761d765bd
commit 2297e2d764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 9 deletions

View File

@ -0,0 +1,4 @@
export default {
[a]: b,
[c]: d
};

View File

@ -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);

View File

@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-computed-properties"]
}

View File

@ -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 (

View File

@ -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);",
);
});
});
});