Skip to content

Commit 2da2c61

Browse files
authored
feat: symbol restructure (#774)
1 parent 1182809 commit 2da2c61

287 files changed

Lines changed: 24874 additions & 23825 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/ddoc/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use deno_doc::html::HrefResolver;
1313
use deno_doc::html::UrlResolveKind;
1414
use deno_doc::html::UsageComposer;
1515
use deno_doc::html::UsageComposerEntry;
16-
use deno_doc::node::DocNodeDef;
16+
use deno_doc::node::DeclarationDef;
1717
use deno_graph::BuildOptions;
1818
use deno_graph::GraphKind;
1919
use deno_graph::ModuleGraph;
@@ -213,8 +213,9 @@ async fn run() -> anyhow::Result<()> {
213213
let mut doc_nodes =
214214
doc_nodes_by_url.into_values().flatten().collect::<Vec<_>>();
215215

216-
doc_nodes
217-
.retain(|doc_node| !matches!(doc_node.def, DocNodeDef::Import { .. }));
216+
doc_nodes.retain(|doc_node| {
217+
!matches!(doc_node.declarations[0].def, DeclarationDef::Import { .. })
218+
});
218219

219220
if let Some(filter) = filter {
220221
doc_nodes = find_nodes_by_name_recursively(doc_nodes, &filter);
@@ -378,7 +379,7 @@ fn generate_docs_directory(
378379
package_name: Option<String>,
379380
output_dir: PathBuf,
380381
main_entrypoint: Option<ModuleSpecifier>,
381-
doc_nodes_by_url: IndexMap<ModuleSpecifier, Vec<deno_doc::DocNode>>,
382+
doc_nodes_by_url: IndexMap<ModuleSpecifier, Vec<deno_doc::Symbol>>,
382383
) -> Result<(), anyhow::Error> {
383384
let cwd = current_dir().unwrap();
384385
let output_dir_resolved = cwd.join(output_dir);

js/test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ Deno.test({
1212
const entries = records["https://deno.land/std@0.104.0/fmt/colors.ts"];
1313
assertEquals(entries.length, 49);
1414
const fnStripColor = entries.find((n) =>
15-
n.kind === "function" && n.name === "stripColor"
15+
n.declarations.some((d) => d.kind === "function") &&
16+
n.name === "stripColor"
1617
);
1718
assert(fnStripColor, "unable to locate specific node");
18-
assert(fnStripColor.kind === "function");
19-
assert(fnStripColor.functionDef);
20-
assertEquals(fnStripColor.functionDef.params, [{
19+
const decl = fnStripColor.declarations[0];
20+
assert(decl.kind === "function");
21+
assert(decl.functionDef);
22+
assertEquals(decl.functionDef.params, [{
2123
kind: "identifier",
2224
name: "string",
2325
optional: false,
@@ -121,7 +123,7 @@ Deno.test({
121123
});
122124
const entries = Object.values(records)[0];
123125
assertEquals(entries.length, 1);
124-
assertEquals(entries[0].kind, "class");
126+
assertEquals(entries[0].declarations[0].kind, "class");
125127
assertEquals(entries[0].name, "B");
126128
},
127129
});

js/types.d.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
22

3-
export type DocNode =
4-
| DocNodeModuleDoc
5-
| DocNodeFunction
6-
| DocNodeVariable
7-
| DocNodeEnum
8-
| DocNodeClass
9-
| DocNodeTypeAlias
10-
| DocNodeNamespace
11-
| DocNodeInterface
12-
| DocNodeImport
13-
| DocNodeReference;
3+
export interface DocNode {
4+
name: string;
5+
isDefault?: true;
6+
declarations: Declaration[];
7+
}
148

159
/** Indicates how the documentation node was declared. `"private"` indicates
1610
* the node is un-exported. `"export"` indicates it is exported from the current
1711
* module. `"declare"` indicates that it is a type only declaration. */
1812
export type DeclarationKind = "private" | "export" | "declare";
1913

20-
interface DocNodeBase {
14+
export type Declaration =
15+
| DeclarationModuleDoc
16+
| DeclarationFunction
17+
| DeclarationVariable
18+
| DeclarationEnum
19+
| DeclarationClass
20+
| DeclarationTypeAlias
21+
| DeclarationNamespace
22+
| DeclarationInterface
23+
| DeclarationImport
24+
| DeclarationReference;
25+
26+
interface DeclarationBase {
2127
kind: DocNodeKind;
22-
name: string;
2328
location: Location;
2429
declarationKind: DeclarationKind;
2530
jsDoc?: JsDoc;
26-
isDefault?: true;
2731
}
2832

2933
export type DocNodeKind =
@@ -38,52 +42,52 @@ export type DocNodeKind =
3842
| "import"
3943
| "reference";
4044

41-
export interface DocNodeModuleDoc extends DocNodeBase {
45+
export interface DeclarationModuleDoc extends DeclarationBase {
4246
kind: "moduleDoc";
4347
jsDoc: JsDoc;
4448
}
4549

46-
export interface DocNodeFunction extends DocNodeBase {
50+
export interface DeclarationFunction extends DeclarationBase {
4751
kind: "function";
4852
functionDef: FunctionDef;
4953
}
5054

51-
export interface DocNodeVariable extends DocNodeBase {
55+
export interface DeclarationVariable extends DeclarationBase {
5256
kind: "variable";
5357
variableDef: VariableDef;
5458
}
5559

56-
export interface DocNodeEnum extends DocNodeBase {
60+
export interface DeclarationEnum extends DeclarationBase {
5761
kind: "enum";
5862
enumDef: EnumDef;
5963
}
6064

61-
export interface DocNodeClass extends DocNodeBase {
65+
export interface DeclarationClass extends DeclarationBase {
6266
kind: "class";
6367
classDef: ClassDef;
6468
}
6569

66-
export interface DocNodeTypeAlias extends DocNodeBase {
70+
export interface DeclarationTypeAlias extends DeclarationBase {
6771
kind: "typeAlias";
6872
typeAliasDef: TypeAliasDef;
6973
}
7074

71-
export interface DocNodeNamespace extends DocNodeBase {
75+
export interface DeclarationNamespace extends DeclarationBase {
7276
kind: "namespace";
7377
namespaceDef: NamespaceDef;
7478
}
7579

76-
export interface DocNodeInterface extends DocNodeBase {
80+
export interface DeclarationInterface extends DeclarationBase {
7781
kind: "interface";
7882
interfaceDef: InterfaceDef;
7983
}
8084

81-
export interface DocNodeImport extends DocNodeBase {
85+
export interface DeclarationImport extends DeclarationBase {
8286
kind: "import";
8387
importDef: ImportDef;
8488
}
8589

86-
export interface DocNodeReference extends DocNodeBase {
90+
export interface DeclarationReference extends DeclarationBase {
8791
kind: "reference";
8892
reference_def: ReferenceDef;
8993
}

lib/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ fn generate_html_inner(
566566
>(default_symbol_map)
567567
.map_err(|err| anyhow!("defaultSymbolMap: {}", err))?;
568568

569-
let doc_nodes_by_url: IndexMap<ModuleSpecifier, Vec<deno_doc::DocNode>> =
569+
let doc_nodes_by_url: IndexMap<ModuleSpecifier, Vec<deno_doc::Symbol>> =
570570
serde_wasm_bindgen::from_value(doc_nodes_by_url)
571571
.map_err(|err| anyhow!("docNodesByUrl: {}", err))?;
572572

src/class.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use deno_graph::symbols::EsModuleInfo;
55
use serde::Deserialize;
66
use serde::Serialize;
77

8-
use crate::DocNode;
98
use crate::Location;
109
use crate::ParamDef;
1110
use crate::decorators::DecoratorDef;
@@ -14,6 +13,7 @@ use crate::function::FunctionDef;
1413
use crate::function::function_to_function_def;
1514
use crate::js_doc::JsDoc;
1615
use crate::node::DeclarationKind;
16+
use crate::node::Symbol;
1717
use crate::params::assign_pat_to_param_def;
1818
use crate::params::ident_to_param_def;
1919
use crate::params::param_to_param_def;
@@ -124,9 +124,9 @@ pub struct ClassPropertyDef {
124124
pub location: Location,
125125
}
126126

127-
impl From<ClassPropertyDef> for DocNode {
128-
fn from(def: ClassPropertyDef) -> DocNode {
129-
DocNode::variable(
127+
impl From<ClassPropertyDef> for Symbol {
128+
fn from(def: ClassPropertyDef) -> Symbol {
129+
Symbol::variable(
130130
def.name,
131131
false,
132132
def.location,
@@ -178,9 +178,9 @@ pub struct ClassMethodDef {
178178
pub location: Location,
179179
}
180180

181-
impl From<ClassMethodDef> for DocNode {
182-
fn from(def: ClassMethodDef) -> DocNode {
183-
DocNode::function(
181+
impl From<ClassMethodDef> for Symbol {
182+
fn from(def: ClassMethodDef) -> Symbol {
183+
Symbol::function(
184184
def.name,
185185
false,
186186
def.location,
@@ -463,10 +463,6 @@ pub fn class_to_class_def(
463463
pub fn get_doc_for_class_decl(
464464
module_info: &EsModuleInfo,
465465
class_decl: &deno_ast::swc::ast::ClassDecl,
466-
) -> (String, ClassDef, JsDoc) {
467-
let class_name = class_decl.ident.sym.to_string();
468-
let (class_def, js_doc) =
469-
class_to_class_def(module_info, &class_decl.class, None);
470-
471-
(class_name, class_def, js_doc)
466+
) -> (ClassDef, JsDoc) {
467+
class_to_class_def(module_info, &class_decl.class, None)
472468
}

0 commit comments

Comments
 (0)