Mark ThisExpression and Super as Purish (#12251)
* Mark `ThisExpression` as `Purish` The other purish types are functions and literals, so I guess it means "it doesn't have side effects" * Super & tests * Fix tests
This commit is contained in:
parent
87a30524f6
commit
df908fc63b
@ -232,6 +232,19 @@ describe("scope", () => {
|
||||
expect(
|
||||
getPath("String.raw`foo`").get("body")[0].get("expression").isPure(),
|
||||
).toBeTruthy();
|
||||
expect(getPath("this").get("body.0.expression").isPure()).toBeTruthy();
|
||||
expect(getPath("this.foo").get("body.0.expression").isPure()).toBeFalsy();
|
||||
expect(
|
||||
getPath("({ m() { super.foo } })")
|
||||
.get("body.0.expression.properties.0.body.body.0.expression")
|
||||
.isPure(),
|
||||
).toBeFalsy();
|
||||
expect(
|
||||
// This only tests "super", not "super.foo"
|
||||
getPath("({ m() { super.foo } })")
|
||||
.get("body.0.expression.properties.0.body.body.0.expression.object")
|
||||
.isPure(),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
test("label", function () {
|
||||
|
||||
@ -980,7 +980,7 @@ defineType("SwitchStatement", {
|
||||
});
|
||||
|
||||
defineType("ThisExpression", {
|
||||
aliases: ["Expression"],
|
||||
aliases: ["Expression", "Pureish"],
|
||||
});
|
||||
|
||||
defineType("ThrowStatement", {
|
||||
@ -1785,7 +1785,7 @@ defineType("SpreadElement", {
|
||||
});
|
||||
|
||||
defineType("Super", {
|
||||
aliases: ["Expression"],
|
||||
aliases: ["Expression", "Pureish"],
|
||||
});
|
||||
|
||||
defineType("TaggedTemplateExpression", {
|
||||
|
||||
@ -3965,7 +3965,9 @@ export function isPureish(node: ?Object, opts?: Object): boolean {
|
||||
"NullLiteral" === nodeType ||
|
||||
"BooleanLiteral" === nodeType ||
|
||||
"RegExpLiteral" === nodeType ||
|
||||
"ThisExpression" === nodeType ||
|
||||
"ArrowFunctionExpression" === nodeType ||
|
||||
"Super" === nodeType ||
|
||||
"BigIntLiteral" === nodeType ||
|
||||
"DecimalLiteral" === nodeType ||
|
||||
(nodeType === "Placeholder" && "StringLiteral" === node.expectedNode)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user