Skip to content

Commit d3ebb8a

Browse files
authored
refactor: upgrade to deno_ast 0.15 (#252)
1 parent d02b9e0 commit d3ebb8a

File tree

15 files changed

+222
-128
lines changed

15 files changed

+222
-128
lines changed

.clippy.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Prefer using `SourcePos` from deno_ast because it abstracts
2+
# away swc's non-zero-indexed based positioning
3+
disallowed-methods = [
4+
"swc_common::Spanned::span",
5+
]
6+
disallowed-types = [
7+
"swc_common::BytePos",
8+
"swc_common::Span",
9+
"swc_common::Spanned",
10+
]

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "deno_doc"
3-
version = "0.34.0"
3+
version = "0.35.0"
44
edition = "2021"
55
description = "doc generation for deno"
66
authors = ["the Deno authors"]
@@ -16,8 +16,8 @@ name = "ddoc"
1616
[dependencies]
1717
anyhow = { version = "1.0.43", optional = true }
1818
cfg-if = "1.0.0"
19-
deno_ast = "0.14.0"
20-
deno_graph = "0.26.0"
19+
deno_ast = "0.15.0"
20+
deno_graph = "0.27.0"
2121
futures = "0.3.17"
2222
js-sys = { version = "0.3.55", optional = true }
2323
lazy_static = "1.4.0"

examples/ddoc/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use futures::executor::block_on;
1616
use futures::future;
1717
use std::env::current_dir;
1818
use std::fs::read_to_string;
19-
use std::sync::Arc;
2019

2120
struct SourceFileLoader {}
2221

@@ -33,7 +32,7 @@ impl Loader for SourceFileLoader {
3332
Some(LoadResponse::Module {
3433
specifier: specifier.clone(),
3534
maybe_headers: None,
36-
content: Arc::new(content),
35+
content: content.into(),
3736
})
3837
})
3938
.map_err(|err| err.into())

src/class.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright 2020-2022 the Deno authors. All rights reserved. MIT license.
22

3-
use deno_ast::swc::common::Spanned;
43
use deno_ast::ParsedSource;
4+
use deno_ast::SourceRangedForSpanned;
55
use serde::Deserialize;
66
use serde::Serialize;
77

@@ -17,7 +17,7 @@ use crate::params::param_to_param_def;
1717
use crate::params::prop_name_to_string;
1818
use crate::params::ts_fn_param_to_param_def;
1919
use crate::swc_util::get_location;
20-
use crate::swc_util::js_doc_for_span;
20+
use crate::swc_util::js_doc_for_range;
2121
use crate::ts_type::infer_ts_type_from_expr;
2222
use crate::ts_type::maybe_type_param_instantiation_to_type_defs;
2323
use crate::ts_type::ts_type_ann_to_def;
@@ -247,7 +247,7 @@ pub fn class_to_class_def(
247247

248248
match member {
249249
Constructor(ctor) => {
250-
let ctor_js_doc = js_doc_for_span(parsed_source, &ctor.span());
250+
let ctor_js_doc = js_doc_for_range(parsed_source, &ctor.range());
251251
let constructor_name =
252252
prop_name_to_string(Some(parsed_source), &ctor.key);
253253

@@ -279,13 +279,13 @@ pub fn class_to_class_def(
279279
accessibility: ctor.accessibility,
280280
name: constructor_name,
281281
params,
282-
location: get_location(parsed_source, ctor.span.lo()),
282+
location: get_location(parsed_source, ctor.start()),
283283
};
284284
constructors.push(constructor_def);
285285
}
286286
Method(class_method) => {
287287
let method_js_doc =
288-
js_doc_for_span(parsed_source, &class_method.span());
288+
js_doc_for_range(parsed_source, &class_method.range());
289289
let method_name =
290290
prop_name_to_string(Some(parsed_source), &class_method.key);
291291
let fn_def =
@@ -299,12 +299,12 @@ pub fn class_to_class_def(
299299
name: method_name,
300300
kind: class_method.kind,
301301
function_def: fn_def,
302-
location: get_location(parsed_source, class_method.span.lo()),
302+
location: get_location(parsed_source, class_method.start()),
303303
};
304304
methods.push(method_def);
305305
}
306306
ClassProp(class_prop) => {
307-
let prop_js_doc = js_doc_for_span(parsed_source, &class_prop.span());
307+
let prop_js_doc = js_doc_for_range(parsed_source, &class_prop.range());
308308

309309
let ts_type = if let Some(type_ann) = &class_prop.type_ann {
310310
// if the property has a type annotation, use it
@@ -333,7 +333,7 @@ pub fn class_to_class_def(
333333
accessibility: class_prop.accessibility,
334334
name: prop_name,
335335
decorators,
336-
location: get_location(parsed_source, class_prop.span.lo()),
336+
location: get_location(parsed_source, class_prop.start()),
337337
};
338338
properties.push(prop_def);
339339
}
@@ -376,7 +376,7 @@ pub fn class_to_class_def(
376376
// JSDoc associated with the class may actually be a leading comment on a
377377
// decorator, and so we should parse out the JSDoc for the first decorator
378378
let js_doc = if !class.decorators.is_empty() {
379-
js_doc_for_span(parsed_source, &class.decorators[0].span)
379+
js_doc_for_range(parsed_source, &class.decorators[0].range())
380380
} else {
381381
JsDoc::default()
382382
};

0 commit comments

Comments
 (0)