mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
fix(transformer/decorators): missing check private function (#2607)
This commit is contained in:
parent
35ce3ccdc0
commit
7a12514151
2 changed files with 61 additions and 59 deletions
|
|
@ -3,7 +3,7 @@ use std::{borrow::Cow, collections::HashMap, rc::Rc};
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
use oxc_allocator::{Box, Vec};
|
use oxc_allocator::{Box, Vec};
|
||||||
use oxc_ast::{ast::*, AstBuilder};
|
use oxc_ast::{ast::*, AstBuilder};
|
||||||
use oxc_span::{CompactString, SPAN};
|
use oxc_span::{Atom, CompactString, SPAN};
|
||||||
use oxc_syntax::operator::{AssignmentOperator, LogicalOperator};
|
use oxc_syntax::operator::{AssignmentOperator, LogicalOperator};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
|
@ -456,62 +456,12 @@ impl<'a> Decorators<'a> {
|
||||||
|
|
||||||
if def.key.is_private_identifier() {
|
if def.key.is_private_identifier() {
|
||||||
{
|
{
|
||||||
if !flag.is_static() && private_in_expression.is_none() {
|
if !flag.is_static() {
|
||||||
// _ => #a in _;
|
// _ => #a in _;
|
||||||
private_in_expression = Some(
|
private_in_expression =
|
||||||
self.ast.arrow_function_expression(
|
Some(self.get_is_private_function(
|
||||||
SPAN,
|
def.key.private_name().unwrap(),
|
||||||
true,
|
));
|
||||||
false,
|
|
||||||
self.ast.formal_parameters(
|
|
||||||
SPAN,
|
|
||||||
FormalParameterKind::ArrowFormalParameters,
|
|
||||||
self.ast.new_vec_single(self.ast.formal_parameter(
|
|
||||||
SPAN,
|
|
||||||
self.ast.binding_pattern(
|
|
||||||
self.ast.binding_pattern_identifier(
|
|
||||||
BindingIdentifier::new(
|
|
||||||
SPAN,
|
|
||||||
self.ast.new_atom("_"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
self.ast.new_vec(),
|
|
||||||
)),
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
self.ast.function_body(
|
|
||||||
SPAN,
|
|
||||||
self.ast.new_vec(),
|
|
||||||
self.ast.new_vec_single(
|
|
||||||
self.ast.expression_statement(
|
|
||||||
SPAN,
|
|
||||||
self.ast.private_in_expression(
|
|
||||||
SPAN,
|
|
||||||
PrivateIdentifier::new(
|
|
||||||
SPAN,
|
|
||||||
def.key.private_name().unwrap(),
|
|
||||||
),
|
|
||||||
self.ast
|
|
||||||
.identifier_reference_expression(
|
|
||||||
IdentifierReference::new(
|
|
||||||
SPAN,
|
|
||||||
self.ast.new_atom("_"),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -595,6 +545,13 @@ impl<'a> Decorators<'a> {
|
||||||
DecoratorFlags::Field
|
DecoratorFlags::Field
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if def.key.is_private_identifier() && !flag.is_static() {
|
||||||
|
private_in_expression =
|
||||||
|
Some(self.get_is_private_function(
|
||||||
|
def.key.private_name().unwrap().clone(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
name = self.get_unique_name(&if def.computed {
|
name = self.get_unique_name(&if def.computed {
|
||||||
Cow::Borrowed("init_computedKey")
|
Cow::Borrowed("init_computedKey")
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1010,4 +967,50 @@ impl<'a> Decorators<'a> {
|
||||||
}
|
}
|
||||||
self.ast.array_expression(SPAN, decorator_elements, None)
|
self.ast.array_expression(SPAN, decorator_elements, None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// _ => #a in _;
|
||||||
|
fn get_is_private_function(&self, name: Atom<'a>) -> Expression<'a> {
|
||||||
|
self.ast.arrow_function_expression(
|
||||||
|
SPAN,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
self.ast.formal_parameters(
|
||||||
|
SPAN,
|
||||||
|
FormalParameterKind::ArrowFormalParameters,
|
||||||
|
self.ast.new_vec_single(self.ast.formal_parameter(
|
||||||
|
SPAN,
|
||||||
|
self.ast.binding_pattern(
|
||||||
|
self.ast.binding_pattern_identifier(BindingIdentifier::new(
|
||||||
|
SPAN,
|
||||||
|
self.ast.new_atom("_"),
|
||||||
|
)),
|
||||||
|
None,
|
||||||
|
false,
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
self.ast.new_vec(),
|
||||||
|
)),
|
||||||
|
None,
|
||||||
|
),
|
||||||
|
self.ast.function_body(
|
||||||
|
SPAN,
|
||||||
|
self.ast.new_vec(),
|
||||||
|
self.ast.new_vec_single(self.ast.expression_statement(
|
||||||
|
SPAN,
|
||||||
|
self.ast.private_in_expression(
|
||||||
|
SPAN,
|
||||||
|
PrivateIdentifier::new(SPAN, name),
|
||||||
|
self.ast.identifier_reference_expression(IdentifierReference::new(
|
||||||
|
SPAN,
|
||||||
|
self.ast.new_atom("_"),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
Passed: 351/1369
|
Passed: 352/1369
|
||||||
|
|
||||||
# All Passed:
|
# All Passed:
|
||||||
* babel-plugin-transform-numeric-separator
|
* babel-plugin-transform-numeric-separator
|
||||||
|
|
@ -907,7 +907,7 @@ Passed: 351/1369
|
||||||
* spread-transform/transform-to-babel-extend/input.js
|
* spread-transform/transform-to-babel-extend/input.js
|
||||||
* spread-transform/transform-to-object-assign/input.js
|
* spread-transform/transform-to-object-assign/input.js
|
||||||
|
|
||||||
# babel-plugin-proposal-decorators (23/190)
|
# babel-plugin-proposal-decorators (24/190)
|
||||||
* 2018-09-transformation/async-generator-method/input.js
|
* 2018-09-transformation/async-generator-method/input.js
|
||||||
* 2018-09-transformation/class-decorators-yield-await/input.js
|
* 2018-09-transformation/class-decorators-yield-await/input.js
|
||||||
* 2021-12-accessors/context-name/input.js
|
* 2021-12-accessors/context-name/input.js
|
||||||
|
|
@ -1016,7 +1016,6 @@ Passed: 351/1369
|
||||||
* 2023-05-exported/default-named/input.mjs
|
* 2023-05-exported/default-named/input.mjs
|
||||||
* 2023-05-exported/member-decorator/input.mjs
|
* 2023-05-exported/member-decorator/input.mjs
|
||||||
* 2023-05-fields/context-name/input.js
|
* 2023-05-fields/context-name/input.js
|
||||||
* 2023-05-fields/private/input.js
|
|
||||||
* 2023-05-fields--to-es2015/context-name/input.js
|
* 2023-05-fields--to-es2015/context-name/input.js
|
||||||
* 2023-05-fields--to-es2015/private/input.js
|
* 2023-05-fields--to-es2015/private/input.js
|
||||||
* 2023-05-fields--to-es2015/public/input.js
|
* 2023-05-fields--to-es2015/public/input.js
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue