Skip to content

Commit fd88d24

Browse files
committed
Fix lint
1 parent 3889930 commit fd88d24

File tree

3 files changed

+42
-101
lines changed

3 files changed

+42
-101
lines changed

libs/extractor/src/css_utils.rs

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -32,62 +32,10 @@ impl From<CssToStyleResult> for ExtractStyleValue {
3232
}
3333
}
3434

35-
pub fn rm_last_semi_colon<'a>(code: &'a str) -> &'a str {
35+
pub fn rm_last_semi_colon(code: &str) -> &str {
3636
code.trim_end_matches(';')
3737
}
3838

39-
/// Normalize whitespace while preserving string literals
40-
fn normalize_whitespace_preserving_strings(input: &str) -> String {
41-
let mut result = String::with_capacity(input.len());
42-
let mut chars = input.chars().peekable();
43-
let mut string_placeholders = Vec::new();
44-
let mut placeholder_counter = 0;
45-
46-
while let Some(ch) = chars.next() {
47-
if ch == '"' || ch == '\'' || ch == '`' {
48-
// Found start of string literal
49-
let quote = ch;
50-
let mut string_content = String::from(quote);
51-
let mut escaped = false;
52-
53-
while let Some(&next_ch) = chars.peek() {
54-
chars.next();
55-
string_content.push(next_ch);
56-
57-
if escaped {
58-
escaped = false;
59-
} else if next_ch == '\\' {
60-
escaped = true;
61-
} else if next_ch == quote {
62-
// End of string literal
63-
break;
64-
}
65-
}
66-
67-
// Replace string literal with placeholder
68-
let placeholder = format!("__STRING_{}__", placeholder_counter);
69-
placeholder_counter += 1;
70-
string_placeholders.push((placeholder.clone(), string_content));
71-
result.push_str(&placeholder);
72-
} else {
73-
result.push(ch);
74-
}
75-
}
76-
77-
// Normalize whitespace (newlines, tabs, multiple spaces)
78-
result = result.replace(['\n', '\t'], " ");
79-
while result.contains(" ") {
80-
result = result.replace(" ", " ");
81-
}
82-
result = result.trim().to_string();
83-
84-
// Restore string literals
85-
for (placeholder, original_string) in string_placeholders.iter().rev() {
86-
result = result.replace(placeholder, original_string);
87-
}
88-
89-
result
90-
}
9139
pub fn css_to_style_literal<'a>(
9240
css: &TemplateLiteral<'a>,
9341
level: u8,
@@ -214,7 +162,7 @@ pub fn css_to_style_literal<'a>(
214162
styles.push(CssToStyleResult::Dynamic(ExtractDynamicStyle::new(
215163
style.property(),
216164
style.level(),
217-
&identifier,
165+
identifier,
218166
style.selector().cloned(),
219167
)));
220168
} else {

libs/extractor/src/extractor/extract_style_from_styled.rs

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,14 @@ fn create_styled_component<'a>(
165165
SPAN,
166166
FormalParameterKind::ArrowFormalParameters,
167167
oxc_allocator::Vec::from_iter_in(
168-
vec![
169-
ast_builder.formal_parameter(
170-
SPAN,
171-
oxc_allocator::Vec::from_iter_in(vec![], ast_builder.allocator),
172-
ast_builder.binding_pattern(
173-
ast_builder.binding_pattern_kind_object_pattern(
174-
SPAN,
175-
oxc_allocator::Vec::from_iter_in(
176-
vec![
168+
vec![ast_builder.formal_parameter(
169+
SPAN,
170+
oxc_allocator::Vec::from_iter_in(vec![], ast_builder.allocator),
171+
ast_builder.binding_pattern(
172+
ast_builder.binding_pattern_kind_object_pattern(
173+
SPAN,
174+
oxc_allocator::Vec::from_iter_in(
175+
vec![
177176
ast_builder.binding_property(
178177
SPAN,
179178
ast_builder.property_key_static_identifier(SPAN, "style"),
@@ -211,28 +210,27 @@ fn create_styled_component<'a>(
211210
false,
212211
),
213212
],
214-
ast_builder.allocator,
215-
),
216-
Some(ast_builder.binding_rest_element(
217-
SPAN,
218-
ast_builder.binding_pattern(
219-
ast_builder.binding_pattern_kind_binding_identifier(
220-
SPAN,
221-
ast_builder.atom("rest"),
222-
),
223-
None::<oxc_allocator::Box<oxc_ast::ast::TSTypeAnnotation<'a>>>,
224-
false,
225-
),
226-
)),
213+
ast_builder.allocator,
227214
),
228-
None::<oxc_allocator::Box<oxc_ast::ast::TSTypeAnnotation<'a>>>,
229-
false,
215+
Some(ast_builder.binding_rest_element(
216+
SPAN,
217+
ast_builder.binding_pattern(
218+
ast_builder.binding_pattern_kind_binding_identifier(
219+
SPAN,
220+
ast_builder.atom("rest"),
221+
),
222+
None::<oxc_allocator::Box<oxc_ast::ast::TSTypeAnnotation<'a>>>,
223+
false,
224+
),
225+
)),
230226
),
231-
None,
232-
false,
227+
None::<oxc_allocator::Box<oxc_ast::ast::TSTypeAnnotation<'a>>>,
233228
false,
234229
),
235-
],
230+
None,
231+
false,
232+
false,
233+
)],
236234
ast_builder.allocator,
237235
),
238236
None::<oxc_allocator::Box<oxc_ast::ast::BindingRestElement<'a>>>,
@@ -241,20 +239,16 @@ fn create_styled_component<'a>(
241239
SPAN,
242240
oxc_allocator::Vec::from_iter_in(vec![], ast_builder.allocator),
243241
oxc_allocator::Vec::from_iter_in(
244-
vec![
245-
ast_builder.statement_expression(
242+
vec![ast_builder.statement_expression(
243+
SPAN,
244+
ast_builder.expression_jsx_element(
246245
SPAN,
247-
ast_builder.expression_jsx_element(
246+
ast_builder.alloc_jsx_opening_element(
248247
SPAN,
249-
ast_builder.alloc_jsx_opening_element(
250-
SPAN,
251-
ast_builder
252-
.jsx_element_name_identifier(SPAN, ast_builder.atom(tag_name)),
253-
None::<
254-
oxc_allocator::Box<oxc_ast::ast::TSTypeParameterInstantiation<'a>>,
255-
>,
256-
oxc_allocator::Vec::from_iter_in(
257-
vec![
248+
ast_builder.jsx_element_name_identifier(SPAN, ast_builder.atom(tag_name)),
249+
None::<oxc_allocator::Box<oxc_ast::ast::TSTypeParameterInstantiation<'a>>>,
250+
oxc_allocator::Vec::from_iter_in(
251+
vec![
258252
ast_builder.jsx_attribute_item_spread_attribute(
259253
SPAN,
260254
ast_builder
@@ -333,14 +327,13 @@ fn create_styled_component<'a>(
333327
),
334328
),
335329
],
336-
ast_builder.allocator,
337-
),
330+
ast_builder.allocator,
338331
),
339-
oxc_allocator::Vec::from_iter_in(vec![], ast_builder.allocator),
340-
None::<oxc_allocator::Box<oxc_ast::ast::JSXClosingElement<'a>>>,
341332
),
333+
oxc_allocator::Vec::from_iter_in(vec![], ast_builder.allocator),
334+
None::<oxc_allocator::Box<oxc_ast::ast::JSXClosingElement<'a>>>,
342335
),
343-
],
336+
)],
344337
ast_builder.allocator,
345338
),
346339
);

libs/extractor/src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ pub(super) fn expression_to_code(expression: &Expression) -> String {
2626
.alloc_expression_statement(SPAN, expression.clone_in(&allocator)),
2727
),
2828
);
29-
let code = Codegen::new()
29+
30+
Codegen::new()
3031
.with_options(CodegenOptions {
3132
minify: true,
3233
..Default::default()
3334
})
3435
.build(&parsed.program)
35-
.code;
36-
code
36+
.code
3737
}
3838

3939
pub(super) fn is_same_expression<'a>(a: &Expression<'a>, b: &Expression<'a>) -> bool {

0 commit comments

Comments
 (0)