fix: correctly transform __proto__ properties (#12664)
* fix: correctly transform `__proto__` properties * fixup! fix: correctly transform `__proto__` properties
This commit is contained in:
parent
2811b535d6
commit
f1314a1683
@ -90,8 +90,6 @@ export default declare((api, options) => {
|
|||||||
|
|
||||||
if (prop.kind === "get" || prop.kind === "set") {
|
if (prop.kind === "get" || prop.kind === "set") {
|
||||||
pushMutatorDefine(info, prop);
|
pushMutatorDefine(info, prop);
|
||||||
} else if (t.isStringLiteral(key, { value: "__proto__" })) {
|
|
||||||
pushAssign(objId, prop, body);
|
|
||||||
} else {
|
} else {
|
||||||
if (computedProps.length === 1) {
|
if (computedProps.length === 1) {
|
||||||
return t.callExpression(state.addHelper("defineProperty"), [
|
return t.callExpression(state.addHelper("defineProperty"), [
|
||||||
|
|||||||
11
packages/babel-plugin-transform-computed-properties/test/fixtures/spec/proto-shorthand/input.js
vendored
Normal file
11
packages/babel-plugin-transform-computed-properties/test/fixtures/spec/proto-shorthand/input.js
vendored
Normal file
@ -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 () {});
|
||||||
3
packages/babel-plugin-transform-computed-properties/test/fixtures/spec/proto/input.js
vendored
Normal file
3
packages/babel-plugin-transform-computed-properties/test/fixtures/spec/proto/input.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
var obj = {
|
||||||
|
['__proto__']: 123
|
||||||
|
};
|
||||||
1
packages/babel-plugin-transform-computed-properties/test/fixtures/spec/proto/output.js
vendored
Normal file
1
packages/babel-plugin-transform-computed-properties/test/fixtures/spec/proto/output.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var obj = babelHelpers.defineProperty({}, '__proto__', 123);
|
||||||
@ -20,14 +20,25 @@ export default declare(api => {
|
|||||||
);
|
);
|
||||||
func.returnType = node.returnType;
|
func.returnType = node.returnType;
|
||||||
|
|
||||||
|
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));
|
path.replaceWith(t.objectProperty(node.key, func, node.computed));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
ObjectProperty({ node }) {
|
ObjectProperty(path) {
|
||||||
|
const { node } = path;
|
||||||
if (node.shorthand) {
|
if (node.shorthand) {
|
||||||
|
const computedKey = t.toComputedKey(node);
|
||||||
|
if (t.isStringLiteral(computedKey, { value: "__proto__" })) {
|
||||||
|
path.replaceWith(t.objectProperty(computedKey, node.value, true));
|
||||||
|
} else {
|
||||||
node.shorthand = false;
|
node.shorthand = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
var shorthand = {
|
||||||
|
__proto__,
|
||||||
|
}
|
||||||
|
|
||||||
|
var method = {
|
||||||
|
__proto__() {}
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
var shorthand = {
|
||||||
|
["__proto__"]: __proto__
|
||||||
|
};
|
||||||
|
var method = {
|
||||||
|
["__proto__"]: function () {}
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user