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

refactor(ecmascript): remove HasProto which is not part of the spec #6470

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__"))
}
Loading