Skip to content

Commit

Permalink
refactor(ecmascript): remove HasProto which is not part of the spec
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Oct 12, 2024
1 parent 455dab4 commit d2c66d3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
14 changes: 0 additions & 14 deletions crates/oxc_ecmascript/src/has_proto.rs

This file was deleted.

3 changes: 1 addition & 2 deletions crates/oxc_ecmascript/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
//! Methods defined in the [ECMAScript Language Specification](https://tc39.es/ecma262).
mod bound_names;
mod has_proto;
mod is_simple_parameter_list;
mod private_bound_identifiers;
mod prop_name;

pub use self::{
bound_names::BoundNames, has_proto::HasProto, is_simple_parameter_list::IsSimpleParameterList,
bound_names::BoundNames, is_simple_parameter_list::IsSimpleParameterList,
private_bound_identifiers::PrivateBoundIdentifiers, prop_name::PropName,
};
10 changes: 7 additions & 3 deletions crates/oxc_transformer/src/react/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
use oxc_allocator::Vec;
use oxc_ast::{ast::*, AstBuilder, NONE};
use oxc_ecmascript::HasProto;
use oxc_ecmascript::PropName;
use oxc_span::{Atom, GetSpan, Span, SPAN};
use oxc_syntax::{
identifier::{is_irregular_whitespace, is_line_terminator},
Expand Down Expand Up @@ -545,7 +545,7 @@ impl<'a, 'ctx> ReactJsx<'a, 'ctx> {
JSXAttributeItem::SpreadAttribute(spread) => {
if is_classic && attributes.len() == 1 {
// deopt if spreading an object with `__proto__` key
if !matches!(&spread.argument, Expression::ObjectExpression(o) if o.has_proto())
if !matches!(&spread.argument, Expression::ObjectExpression(o) if has_proto(o))
{
arguments.push(Argument::from({
// SAFETY: `ast.copy` is unsound! We need to fix.
Expand All @@ -557,7 +557,7 @@ impl<'a, 'ctx> ReactJsx<'a, 'ctx> {

// Add attribute to prop object
match &spread.argument {
Expression::ObjectExpression(expr) if !expr.has_proto() => {
Expression::ObjectExpression(expr) if !has_proto(expr) => {
// SAFETY: `ast.copy` is unsound! We need to fix.
properties.extend(unsafe { ctx.ast.copy(&expr.properties) });
}
Expand Down Expand Up @@ -1047,3 +1047,7 @@ fn create_static_member_expression<'a>(
let property = ctx.ast.identifier_name(SPAN, property_name);
ctx.ast.member_expression_static(SPAN, object, property, false).into()
}

fn has_proto(e: &ObjectExpression<'_>) -> bool {
e.properties.iter().any(|p| p.prop_name().is_some_and(|name| name.0 == "__proto__"))
}

0 comments on commit d2c66d3

Please sign in to comment.