-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6ac8ca
commit 9839544
Showing
2 changed files
with
28 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
use oxc_ast::ast::*; | ||
use oxc_ast::{ast::*, AstBuilder}; | ||
use oxc_span::GetSpan; | ||
|
||
use std::rc::Rc; | ||
|
||
/// ES2015: Shorthand Properties | ||
/// | ||
/// References: | ||
/// * <https://babel.dev/docs/babel-plugin-transform-shorthand-properties> | ||
/// * <https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-shorthand-properties> | ||
pub struct ShorthandProperties; | ||
pub struct ShorthandProperties<'a> { | ||
ast: Rc<AstBuilder<'a>>, | ||
} | ||
|
||
impl<'a> ShorthandProperties { | ||
pub fn new() -> Self { | ||
Self | ||
impl<'a> ShorthandProperties<'a> { | ||
pub fn new(ast: Rc<AstBuilder<'a>>) -> Self { | ||
Self { ast } | ||
} | ||
|
||
pub fn transform_object_property<'b>(&mut self, obj_prop: &'b mut ObjectProperty) { | ||
obj_prop.shorthand = false; | ||
pub fn transform_object_property<'b>(&mut self, obj_prop: &'b mut ObjectProperty<'a>) { | ||
if obj_prop.shorthand { | ||
obj_prop.shorthand = false; | ||
|
||
if obj_prop.key.is_specific_id("__proto__") { | ||
debug_assert!( | ||
!obj_prop.computed, | ||
"shorthand and computed cannot be true at the same time" | ||
); | ||
obj_prop.computed = true; | ||
|
||
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters