Skip to content

Commit 29892c0

Browse files
authored
feat: deno_ast 0.52 (#1467)
1 parent 5a71063 commit 29892c0

20 files changed

+87
-76
lines changed

Cargo.lock

Lines changed: 39 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ test = true
2323
default = []
2424

2525
[dependencies]
26-
deno_ast = { version = "0.51.0", features = ["scopes", "transforms", "utils", "visit", "view", "react"] }
26+
deno_ast = { version = "0.52.0", features = ["scopes", "transforms", "utils", "visit", "view", "react"] }
2727
log = "0.4.20"
2828
serde = { version = "1.0.195", features = ["derive"] }
2929
serde_json = "1.0.111"

src/rules/adjacent_overload_signatures.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ impl ExtractMethod for ast_view::TsTypeElement<'_> {
185185
ref key, ..
186186
}) => match key {
187187
Expr::Ident(ident) => Some(Method::Method(ident.sym().to_string())),
188-
Expr::Lit(Lit::Str(s)) => Some(Method::Method(s.value().to_string())),
188+
Expr::Lit(Lit::Str(s)) => {
189+
Some(Method::Method(s.value().to_string_lossy().into_owned()))
190+
}
189191
_ => None,
190192
},
191193
TsTypeElement::TsCallSignatureDecl(_) => Some(Method::CallSignature),

src/rules/camelcase.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,11 @@ impl Handler for CamelcaseHandler {
607607
local,
608608
IdentToCheck::named_import(
609609
local.inner,
610-
Some(match imported {
611-
ast_view::ModuleExportName::Ident(ident) => ident.sym(),
612-
ast_view::ModuleExportName::Str(str) => str.value(),
610+
Some(&match imported {
611+
ast_view::ModuleExportName::Ident(ident) => ident.sym().to_string(),
612+
ast_view::ModuleExportName::Str(str) => {
613+
str.value().to_string_lossy().into_owned()
614+
}
613615
}),
614616
),
615617
);

src/rules/jsx_button_has_type.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,9 @@ impl Handler for HasButtonTypeHandler {
100100
if let Some(attr_value) = attr.value {
101101
let kind = DiagnosticKind::WrongValue;
102102
match attr_value {
103-
JSXAttrValue::Lit(lit) => {
104-
if let Lit::Str(lit_str) = lit {
105-
let value = lit_str.value();
106-
if !is_valid_value(value) {
107-
ctx.add_diagnostic_with_hint(
108-
attr_value.range(),
109-
CODE,
110-
kind.message(),
111-
kind.hint(),
112-
);
113-
}
114-
} else {
103+
JSXAttrValue::Str(lit_str) => {
104+
let value = lit_str.value().to_string_lossy();
105+
if !is_valid_value(&value) {
115106
ctx.add_diagnostic_with_hint(
116107
attr_value.range(),
117108
CODE,
@@ -227,8 +218,8 @@ fn check_literal_value(ctx: &mut Context, lit: &Lit) {
227218

228219
match lit {
229220
Lit::Str(lit_str) => {
230-
let value = lit_str.value();
231-
if !is_valid_value(value) {
221+
let value = lit_str.value().to_string_lossy();
222+
if !is_valid_value(&value) {
232223
ctx.add_diagnostic_with_hint(
233224
lit.range(),
234225
CODE,

src/rules/jsx_curly_braces.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Handler for JSXCurlyBracesHandler {
8686
if let JSXElementChild::JSXExprContainer(child_expr) = child {
8787
if let JSXExpr::Expr(Expr::Lit(Lit::Str(lit_str))) = child_expr.expr {
8888
// Ignore entities which would require escaping.
89-
if IGNORE_CHARS.is_match(lit_str.inner.value.as_str()) {
89+
if IGNORE_CHARS.is_match(&lit_str.inner.value.to_string_lossy()) {
9090
continue;
9191
}
9292

@@ -111,7 +111,7 @@ impl Handler for JSXCurlyBracesHandler {
111111
vec![LintFix {
112112
description: "Remove curly braces around JSX child".into(),
113113
changes: vec![LintFixChange {
114-
new_text: lit_str.value().to_string().into(),
114+
new_text: lit_str.value().to_string_lossy().into_owned().into(),
115115
range: child.range(),
116116
}],
117117
}],
@@ -135,7 +135,11 @@ impl Handler for JSXCurlyBracesHandler {
135135
description: "Remove curly braces around JSX attribute value"
136136
.into(),
137137
changes: vec![LintFixChange {
138-
new_text: format!("\"{}\"", lit_str.value()).into(),
138+
new_text: format!(
139+
"\"{}\"",
140+
lit_str.value().to_string_lossy()
141+
)
142+
.into(),
139143
range: value.range(),
140144
}],
141145
}],

src/rules/no_deprecated_deno_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn extract_symbol<'a>(
4646
MemberProp::Ident(ident) => Some(ident.sym()),
4747
MemberProp::PrivateName(ident) => Some(ident.name()),
4848
MemberProp::Computed(prop) => match &prop.expr {
49-
Expr::Lit(Lit::Str(s)) => Some(s.value()),
49+
Expr::Lit(Lit::Str(s)) => s.value().as_str(),
5050
Expr::Ident(ident) => Some(ident.sym()),
5151
Expr::Tpl(Tpl { exprs, quasis, .. })
5252
if exprs.is_empty() && quasis.len() == 1 =>

src/rules/no_dupe_class_members.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,15 @@ impl Visit for ClassVisitor<'_, '_, '_> {
143143
fn normalize_prop_name(name: &PropName) -> Option<String> {
144144
let normalized = match *name {
145145
PropName::Ident(IdentName { ref sym, .. }) => sym.to_string(),
146-
PropName::Str(Str { ref value, .. }) => value.to_string(),
146+
PropName::Str(Str { ref value, .. }) => {
147+
value.to_string_lossy().into_owned()
148+
}
147149
PropName::Num(Number { ref value, .. }) => value.to_string(),
148150
PropName::BigInt(BigInt { ref value, .. }) => value.to_string(),
149151
PropName::Computed(ComputedPropName { ref expr, .. }) => match &**expr {
150-
Expr::Lit(Lit::Str(Str { ref value, .. })) => value.to_string(),
152+
Expr::Lit(Lit::Str(Str { ref value, .. })) => {
153+
value.to_string_lossy().into_owned()
154+
}
151155
Expr::Lit(Lit::Bool(Bool { ref value, .. })) => value.to_string(),
152156
Expr::Lit(Lit::Null(Null { .. })) => "null".to_string(),
153157
Expr::Lit(Lit::Num(Number { ref value, .. })) => value.to_string(),

src/rules/no_external_imports.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ struct NoExternalImportHandler;
5050

5151
impl NoExternalImportHandler {
5252
fn check_import_path(&self, decl: &ImportDecl, ctx: &mut Context) {
53-
let parsed_src = ModuleSpecifier::parse(decl.src.value());
53+
let parsed_src =
54+
ModuleSpecifier::parse(&decl.src.value().to_string_lossy());
5455
let maybe_file_path = ctx.specifier().to_file_path().ok();
5556
let file_stem = maybe_file_path
5657
.as_ref()

src/rules/no_import_assertions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Handler for NoImportAssertionsHandler {
8484
}
8585
},
8686
ast_view::PropName::Str(str) => {
87-
if str.value().as_ref() == "assert" {
87+
if str.value().as_str() == Some("assert") {
8888
ctx.add_diagnostic_with_hint(
8989
str.range(),
9090
CODE,

0 commit comments

Comments
 (0)