Skip to content

Commit

Permalink
fix: correctly聽transform __proto__聽properties (#12664)
Browse files Browse the repository at this point in the history
* fix: correctly聽transform `__proto__`聽properties

* fixup! fix: correctly聽transform `__proto__`聽properties
  • Loading branch information
ExE-Boss committed Jan 22, 2021
1 parent 2811b53 commit f1314a1
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 5 deletions.
Expand Up @@ -90,8 +90,6 @@ export default declare((api, options) => {

if (prop.kind === "get" || prop.kind === "set") {
pushMutatorDefine(info, prop);
} else if (t.isStringLiteral(key, { value: "__proto__" })) {
pushAssign(objId, prop, body);
} else {
if (computedProps.length === 1) {
return t.callExpression(state.addHelper("defineProperty"), [
Expand Down
@@ -0,0 +1,11 @@
var shorthand = {
__proto__,
}

var method = {
__proto__() {}
}

var methodComputed = {
["__proto__"]() {}
}
@@ -0,0 +1,7 @@
{
"plugins": [
"external-helpers",
"transform-computed-properties",
"transform-shorthand-properties"
]
}
@@ -0,0 +1,3 @@
var shorthand = babelHelpers.defineProperty({}, "__proto__", __proto__);
var method = babelHelpers.defineProperty({}, "__proto__", function () {});
var methodComputed = babelHelpers.defineProperty({}, "__proto__", function () {});
@@ -0,0 +1,3 @@
var obj = {
['__proto__']: 123
};
@@ -0,0 +1 @@
var obj = babelHelpers.defineProperty({}, '__proto__', 123);
17 changes: 14 additions & 3 deletions packages/babel-plugin-transform-shorthand-properties/src/index.js
Expand Up @@ -20,13 +20,24 @@ export default declare(api => {
);
func.returnType = node.returnType;

path.replaceWith(t.objectProperty(node.key, func, node.computed));
const computedKey = t.toComputedKey(node);
if (t.isStringLiteral(computedKey, { value: "__proto__" })) {
path.replaceWith(t.objectProperty(computedKey, func, true));
} else {
path.replaceWith(t.objectProperty(node.key, func, node.computed));
}
}
},

ObjectProperty({ node }) {
ObjectProperty(path) {
const { node } = path;
if (node.shorthand) {
node.shorthand = false;
const computedKey = t.toComputedKey(node);
if (t.isStringLiteral(computedKey, { value: "__proto__" })) {
path.replaceWith(t.objectProperty(computedKey, node.value, true));
} else {
node.shorthand = false;
}
}
},
},
Expand Down
@@ -0,0 +1,7 @@
var shorthand = {
__proto__,
}

var method = {
__proto__() {}
}
@@ -0,0 +1,6 @@
var shorthand = {
["__proto__"]: __proto__
};
var method = {
["__proto__"]: function () {}
};

0 comments on commit f1314a1

Please sign in to comment.