Skip to content

Commit

Permalink
chore: early return for "__proto__"() {}
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Oct 6, 2023
1 parent c426566 commit cf7fe6f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions crates/oxc_transformer/src/es2015/shorthand_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,23 @@ impl<'a> ShorthandProperties<'a> {
return;
}

if !obj_prop.key.is_specific_id("__proto__")
&& !obj_prop.key.is_specific_string_literal("__proto__")
{
let is_proto_id = obj_prop.key.is_specific_id("__proto__");
let is_proto_string = obj_prop.key.is_specific_string_literal("__proto__");

if !is_proto_id && !is_proto_string {
return;
}

obj_prop.computed = true;

if is_proto_string {
// input:
// "__proto__"() {}
// output:
// ["__proto__"]: function() {}
return;
}

let proto = StringLiteral { span: obj_prop.key.span(), value: "__proto__".into() };
let expr = self.ast.literal_string_expression(proto);
obj_prop.key = PropertyKey::Expression(expr);
Expand Down

0 comments on commit cf7fe6f

Please sign in to comment.