Skip to content

Commit b94dcab

Browse files
committed
refactor(ast): rename TemplateLiteral::quasi to TemplateLiteral::single_quasi
1 parent 6fc8f4f commit b94dcab

File tree

20 files changed

+40
-34
lines changed

20 files changed

+40
-34
lines changed

crates/oxc_ast/src/ast_impl/js.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,7 @@ impl<'a> PropertyKey<'a> {
459459
Self::NumericLiteral(lit) => Some(Cow::Owned(lit.value.to_string())),
460460
Self::BigIntLiteral(lit) => Some(Cow::Borrowed(lit.value.as_str())),
461461
Self::NullLiteral(_) => Some(Cow::Borrowed("null")),
462-
Self::TemplateLiteral(lit) => {
463-
lit.expressions.is_empty().then(|| lit.quasi()).flatten().map(Into::into)
464-
}
462+
Self::TemplateLiteral(lit) => lit.single_quasi().map(Into::into),
465463
_ => None,
466464
}
467465
}
@@ -548,7 +546,7 @@ impl<'a> TemplateLiteral<'a> {
548546
}
549547

550548
/// Get single quasi from `template`
551-
pub fn quasi(&self) -> Option<Atom<'a>> {
549+
pub fn single_quasi(&self) -> Option<Atom<'a>> {
552550
if self.is_no_substitution_template() { self.quasis[0].value.cooked } else { None }
553551
}
554552
}

crates/oxc_ast/src/ast_impl/ts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl<'a> TSEnumMemberName<'a> {
1919
Self::Identifier(ident) => ident.name,
2020
Self::String(lit) | Self::ComputedString(lit) => lit.value,
2121
Self::ComputedTemplateString(template) => template
22-
.quasi()
22+
.single_quasi()
2323
.expect("`TSEnumMemberName::TemplateString` should have no substitution and at least one quasi"),
2424
}
2525
}

crates/oxc_ast/src/ast_kind_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl AstKind<'_> {
251251
Self::RegExpLiteral(r) => format!("RegExpLiteral({})", r.regex).into(),
252252
Self::TemplateLiteral(t) => format!(
253253
"TemplateLiteral({})",
254-
t.quasi().map_or_else(|| "None".into(), |q| format!("Some({q})"))
254+
t.single_quasi().map_or_else(|| "None".into(), |q| format!("Some({q})"))
255255
)
256256
.into(),
257257
Self::TemplateElement(_) => "TemplateElement".into(),

crates/oxc_ecmascript/src/side_effects/may_have_side_effects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<'a> MayHaveSideEffects<'a> for ComputedMemberExpression<'a> {
417417
Expression::StringLiteral(s) => {
418418
property_access_may_have_side_effects(&self.object, &s.value, ctx)
419419
}
420-
Expression::TemplateLiteral(t) => t.quasi().is_some_and(|quasi| {
420+
Expression::TemplateLiteral(t) => t.single_quasi().is_some_and(|quasi| {
421421
property_access_may_have_side_effects(&self.object, &quasi, ctx)
422422
}),
423423
Expression::NumericLiteral(n) => !n.value.to_integer_index().is_some_and(|n| {

crates/oxc_ecmascript/src/to_primitive.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ pub fn maybe_object_with_to_primitive_related_properties_overridden(
9292
PropertyKey::StringLiteral(str) => {
9393
matches!(str.value.as_str(), "toString" | "valueOf")
9494
}
95-
PropertyKey::TemplateLiteral(temp) => {
96-
temp.quasi().is_some_and(|val| matches!(val.as_str(), "toString" | "valueOf"))
97-
}
95+
PropertyKey::TemplateLiteral(temp) => temp
96+
.single_quasi()
97+
.is_some_and(|val| matches!(val.as_str(), "toString" | "valueOf")),
9898
_ => true,
9999
},
100100
ObjectPropertyKind::SpreadProperty(e) => match &e.argument {

crates/oxc_linter/src/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ pub fn extract_regex_flags<'a>(
308308
}
309309
let flag_arg = match &args[1] {
310310
Argument::StringLiteral(flag_arg) => flag_arg.value,
311-
Argument::TemplateLiteral(template) => template.quasi()?,
311+
Argument::TemplateLiteral(template) => template.single_quasi()?,
312312
_ => return None,
313313
};
314314
let mut flags = RegExpFlags::empty();

crates/oxc_linter/src/rules/eslint/valid_typeof.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,15 @@ impl Rule for ValidTypeof {
124124
}
125125

126126
if let Expression::TemplateLiteral(template) = sibling {
127-
if template.quasi().is_some_and(|value| !VALID_TYPES.contains(&value.as_str())) {
128-
ctx.diagnostic(invalid_value(None, sibling.span()));
127+
if template.expressions.is_empty() {
128+
if template
129+
.single_quasi()
130+
.is_some_and(|value| !VALID_TYPES.contains(&value.as_str()))
131+
{
132+
ctx.diagnostic(invalid_value(None, sibling.span()));
133+
}
134+
return;
129135
}
130-
return;
131136
}
132137

133138
if let Expression::Identifier(ident) = sibling {

crates/oxc_linter/src/rules/jest/no_identical_title.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ fn filter_and_process_jest_result<'a>(
149149
Some(Argument::StringLiteral(string_lit)) => {
150150
Some((string_lit.span, &string_lit.value, kind, parent_id))
151151
}
152-
Some(Argument::TemplateLiteral(template_lit)) => {
153-
template_lit.quasi().map(|quasi| (template_lit.span, quasi.as_str(), kind, parent_id))
154-
}
152+
Some(Argument::TemplateLiteral(template_lit)) => template_lit
153+
.single_quasi()
154+
.map(|quasi| (template_lit.span, quasi.as_str(), kind, parent_id)),
155155
_ => None,
156156
}
157157
}

crates/oxc_linter/src/rules/jest/prefer_lowercase_title/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl Rule for PreferLowercaseTitle {
238238
if let Argument::StringLiteral(string_expr) = arg {
239239
self.lint_string(ctx, string_expr.value.as_str(), string_expr.span);
240240
} else if let Argument::TemplateLiteral(template_expr) = arg {
241-
let Some(template_string) = template_expr.quasi() else {
241+
let Some(template_string) = template_expr.single_quasi() else {
242242
return;
243243
};
244244
self.lint_string(ctx, template_string.as_str(), template_expr.span);

crates/oxc_linter/src/rules/jest/valid_title.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl ValidTitle {
180180
);
181181
}
182182
Argument::TemplateLiteral(template_literal) => {
183-
if let Some(quasi) = template_literal.quasi() {
183+
if let Some(quasi) = template_literal.single_quasi() {
184184
validate_title(
185185
quasi.as_str(),
186186
template_literal.span,

0 commit comments

Comments
 (0)