parent
d761d765bd
commit
2297e2d764
4
packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/actual.js
vendored
Normal file
4
packages/babel-plugin-transform-computed-properties/test/fixtures/regression/7144/actual.js
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export default {
|
||||||
|
[a]: b,
|
||||||
|
[c]: d
|
||||||
|
};
|
||||||
@ -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);
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["external-helpers", "transform-computed-properties"]
|
||||||
|
}
|
||||||
@ -17,7 +17,8 @@ export function insertBefore(nodes) {
|
|||||||
if (
|
if (
|
||||||
this.parentPath.isExpressionStatement() ||
|
this.parentPath.isExpressionStatement() ||
|
||||||
this.parentPath.isLabeledStatement() ||
|
this.parentPath.isLabeledStatement() ||
|
||||||
this.parentPath.isExportDeclaration()
|
this.parentPath.isExportNamedDeclaration() ||
|
||||||
|
(this.parentPath.isExportDefaultDeclaration() && this.isDeclaration())
|
||||||
) {
|
) {
|
||||||
return this.parentPath.insertBefore(nodes);
|
return this.parentPath.insertBefore(nodes);
|
||||||
} else if (
|
} else if (
|
||||||
@ -98,7 +99,8 @@ export function insertAfter(nodes) {
|
|||||||
if (
|
if (
|
||||||
this.parentPath.isExpressionStatement() ||
|
this.parentPath.isExpressionStatement() ||
|
||||||
this.parentPath.isLabeledStatement() ||
|
this.parentPath.isLabeledStatement() ||
|
||||||
this.parentPath.isExportDeclaration()
|
this.parentPath.isExportNamedDeclaration() ||
|
||||||
|
(this.parentPath.isExportDefaultDeclaration() && this.isDeclaration())
|
||||||
) {
|
) {
|
||||||
return this.parentPath.insertAfter(nodes);
|
return this.parentPath.insertAfter(nodes);
|
||||||
} else if (
|
} else if (
|
||||||
|
|||||||
@ -143,14 +143,13 @@ describe("modification", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("the exported expression", function() {
|
it("the exported expression", function() {
|
||||||
const bodyPath = getPath("export default 2;", {
|
const declPath = getPath("export default 2;", {
|
||||||
sourceType: "module",
|
sourceType: "module",
|
||||||
}).parentPath;
|
});
|
||||||
const path = bodyPath.get("body.0.declaration");
|
const path = declPath.get("declaration");
|
||||||
path.insertBefore(t.identifier("x"));
|
path.insertBefore(t.identifier("x"));
|
||||||
|
|
||||||
assert.equal(bodyPath.get("body").length, 2);
|
assert.equal(generateCode(declPath), "export default (x, 2);");
|
||||||
assert.deepEqual(bodyPath.get("body.0").node, t.identifier("x"));
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -236,8 +235,10 @@ describe("modification", function() {
|
|||||||
const path = bodyPath.get("body.0.declaration");
|
const path = bodyPath.get("body.0.declaration");
|
||||||
path.insertAfter(t.identifier("x"));
|
path.insertAfter(t.identifier("x"));
|
||||||
|
|
||||||
assert.equal(bodyPath.get("body").length, 2);
|
assert.equal(
|
||||||
assert.deepEqual(bodyPath.get("body.1").node, t.identifier("x"));
|
generateCode({ parentPath: bodyPath }),
|
||||||
|
"var _temp;\n\nexport default (_temp = 2, x, _temp);",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user