Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly transform __proto__ properties #12664

Merged
merged 2 commits into from Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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));
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved
} 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 () {}
};