Skip to content
Merged
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
16 changes: 8 additions & 8 deletions crates/oxc_transformer/src/jsx/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,20 @@ enum RefreshIdentifierResolver<'a> {
impl<'a> RefreshIdentifierResolver<'a> {
/// Parses a string into a RefreshIdentifierResolver
pub fn parse(input: &str, ast: AstBuilder<'a>) -> Self {
if !input.contains('.') {
// Handle simple identifier reference
return Self::Identifier(ast.identifier_reference(SPAN, input));
}

let mut parts = input.split('.');

let first_part = parts.next().unwrap();
let Some(second_part) = parts.next() else {
// Handle simple identifier reference
return Self::Identifier(ast.identifier_reference(SPAN, input));
};
Comment on lines 35 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is there a way to get the second part first?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Split is an iterator, so you have to consume it in order. first_part is just a slice of input so it's not costly to generate.

I would also hope that compiler knows that Split always yields at least 1 item (even "".split('.') yields a single item ""), so it should be able to remove the .unwrap() in let first_part = parts.next().unwrap();. I don't know that for sure, though.


if first_part == "import" {
// Handle import.meta.$RefreshReg$ expression
// Handle `import.meta.$RefreshReg$` expression
let mut expr = ast.expression_meta_property(
SPAN,
ast.identifier_name(SPAN, "import"),
ast.identifier_name(SPAN, parts.next().unwrap()),
ast.identifier_name(SPAN, second_part),
);
if let Some(property) = parts.next() {
expr = Expression::from(ast.member_expression_static(
Expand All @@ -60,7 +60,7 @@ impl<'a> RefreshIdentifierResolver<'a> {

// Handle `window.$RefreshReg$` member expression
let object = ast.identifier_reference(SPAN, first_part);
let property = ast.identifier_name(SPAN, parts.next().unwrap());
let property = ast.identifier_name(SPAN, second_part);
Self::Member((object, property))
}

Expand Down
Loading