mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(ecmascript): remove HasProto which is not part of the spec (#6470)
This commit is contained in:
parent
455dab4900
commit
1ba2a247e1
3 changed files with 8 additions and 19 deletions
|
|
@ -1,14 +0,0 @@
|
|||
use oxc_ast::ast::ObjectExpression;
|
||||
|
||||
use crate::PropName;
|
||||
|
||||
pub trait HasProto {
|
||||
/// Returns `true` if this object has a property named `__proto__`
|
||||
fn has_proto(&self) -> bool;
|
||||
}
|
||||
|
||||
impl<'a> HasProto for ObjectExpression<'a> {
|
||||
fn has_proto(&self) -> bool {
|
||||
self.properties.iter().any(|p| p.prop_name().is_some_and(|name| name.0 == "__proto__"))
|
||||
}
|
||||
}
|
||||
|
|
@ -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,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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},
|
||||
|
|
@ -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.
|
||||
|
|
@ -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) });
|
||||
}
|
||||
|
|
@ -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…
Reference in a new issue