@ts-graphviz/ast 0.0.0-pr956-20240225091623 → 0.0.0-pr956-20240225163634

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,12 +1,300 @@
1
1
  # @ts-graphviz/ast
2
2
 
3
- ## 0.0.0-pr956-20240225091623
3
+ ## 0.0.0-pr956-20240225163634
4
4
 
5
5
  ### Major Changes
6
6
 
7
- - [`6b2f0e8`](https://github.com/ts-graphviz/ts-graphviz/commit/6b2f0e8349605b4fe0dd950147ba3a8285b24b24) Thanks [@kamiazya](https://github.com/kamiazya)! - Release v2.0.0
7
+ - [`6b2f0e8`](https://github.com/ts-graphviz/ts-graphviz/commit/6b2f0e8349605b4fe0dd950147ba3a8285b24b24) Thanks [@kamiazya](https://github.com/kamiazya)! - # ts-graphviz v2
8
+
9
+ ## Why?
10
+
11
+ ### Dropping support for Node.js 14 & 16
12
+
13
+ We are introducing a major version upgrade to ts-graphviz to ensure better performance, security, and compatibility with the latest improvements in the JavaScript ecosystem. With this upgrade, we will no longer support Node.js 14 & 16, which has reached its End-of-Life (EOL), and set the new minimum guaranteed version to **Node.js 18**.
14
+
15
+ This major version upgrade is necessary due to the following reasons:
16
+
17
+ 1. **Breaking Change**: Dropping support for Node.js 14 & 16 is considered a breaking change, which requires a major version upgrade according to semantic versioning principles.
18
+
19
+ 2. **Improved Stability and Performance**: By focusing on LTS versions, we can provide a library that benefits from the stability, long-term support, and performance improvements provided by newer Node.js versions.
20
+
21
+ 3. **Security**: Ensuring that our library is compatible with the latest supported Node.js versions helps to minimize potential security vulnerabilities.
22
+
23
+ To help our users understand our approach to Node.js version support, we have established a clear [Node.js Version Support Policy](#nodejs-version-support-policy) for ts-graphviz.
24
+
25
+ We encourage our users to update their projects to the latest LTS version of Node.js to ensure the best performance, security, and compatibility with ts-graphviz.
26
+
27
+ ## Key Concepts
28
+
29
+ ts-graphviz is a TypeScript library designed to create, manipulate, and render Graphviz DOT language graphs.
30
+
31
+ It is built around several key concepts that make it modular, extensible, and easy to use:
32
+
33
+ 1. **TypeScript-First Design & Type Definitions**: ts-graphviz is designed with TypeScript as its primary language, providing strong typing and ensuring seamless integration with TypeScript projects. This enables users to leverage the full power of TypeScript's type system and tooling while working with Graphviz graphs. The library includes comprehensive type definitions for DOT language elements, making it easier to work with Graphviz elements in a type-safe manner.
34
+
35
+ 2. **Object-Oriented API**: ts-graphviz provides an object-oriented API for creating and manipulating graph elements like graphs, nodes, and edges. This enables users to work with complex graph structures intuitively and efficiently.
36
+
37
+ 3. **Modular Design[New in v2]**: The library is split into multiple packages, each serving a specific purpose. This modular design allows users to pick and choose the functionality they need, resulting in improved maintainability and flexibility.
38
+
39
+ 4. **AST Support**: ts-graphviz includes a module for processing DOT language at the Abstract Syntax Tree (AST) level. This feature allows users to parse and generate DOT language while preserving its structure, making it easier to manipulate and transform graphs programmatically.
40
+
41
+ 5. **Runtime Adapter**: The library provides adapter functions that enable users to execute Graphviz commands across different runtime environments, such as Node.js and Deno. These adapter functions serve as a wrapper, allowing for seamless integration with various platforms.
42
+
43
+ 6. **Extensibility**: ts-graphviz has been designed with extensibility in mind, allowing users to extend its functionality with custom implementations for specific use cases.
44
+
45
+ 7. **Multi-Paradigm Support**: ts-graphviz is designed to accommodate various programming paradigms, such as Object-Oriented Programming, Declarative Programming, and Functional Programming. This ensures that users can choose the programming style that best suits their needs and preferences, making it adaptable and versatile across different use cases and development approaches.
46
+
47
+ By combining these key concepts, ts-graphviz aims to provide a powerful and user-friendly tool for working with Graphviz DOT language in TypeScript projects.
48
+
49
+ # What's changed?
50
+
51
+ ## Package splitting and monorepo-ization
52
+
53
+ ### Purpose
54
+
55
+ The purpose of package splitting and monorepo-ization in the ts-graphviz v2 is to achieve the following objectives:
56
+
57
+ - **Improved modularity**: By separating functionality into distinct packages, the library becomes more modular. This allows users to install and use only the specific components they need, reducing unnecessary dependencies and improving overall performance.
58
+ - **Easier maintainability**: Splitting the library into smaller packages makes it easier for developers to maintain and update each package independently. This allows for faster bug fixes, feature enhancements, and more efficient development cycles.
59
+ - **Clearer dependencies**: Package splitting results in a more explicit dependency structure between components, making it easier for developers to understand and manage dependencies within the project.
60
+ - **Increased flexibility**: With a modular package structure, users can choose to use only the features they need, making it easier to integrate ts-graphviz into a broader range of projects and applications.
61
+ - **Simplified collaboration**: By breaking down the library into separate packages within a monorepo, contributors can focus on specific areas of interest without interfering with other parts of the library. This facilitates collaboration and encourages more developers to contribute to the project.
62
+ - **Centralized management**: Monorepo-ization allows for the centralized management of all the packages. This enables developers to track issues, manage pull requests, and maintain documentation in a single location, increasing efficiency and reducing overhead.
63
+ - **Consistent versioning and releases**: Monorepo-ization ensures that versioning and release processes are consistent across all packages, making it easier to maintain and update the library as a whole.
64
+
65
+ Overall, package splitting and monorepo-ization aim to create a more robust, maintainable, and user-friendly library that better serves the needs of the ts-graphviz community.
66
+
67
+ ### Packages
68
+
69
+ In v2 of ts-graphviz, the library functionality will be split into several packages. The packages to be split are as follows:
70
+
71
+ - **@ts-graphviz/common**: Contains type information related to DOT language attributes, attribute values, and models.
72
+ - **@ts-graphviz/ast**: Includes the module for processing DOT language at the AST (Abstract Syntax Tree) level.
73
+ - **@ts-graphviz/core**: Comprises the implementation of models and functions provided to users.
74
+ - **@ts-graphviz/adapter**: Handles runtime-dependent processing. For example, it provides I/O processing related to image generation in Graphviz on different runtimes, such as Node.js and Deno.
75
+
76
+ To ensure that existing users are not affected, the ts-graphviz package will remain available. This change will result in a clear division of functionality and will improve the scalability and maintainability of the project. However, users of previous versions and users who wish to use the library without extending it will be able to continue to use the ts-graphviz package as is.
77
+
78
+ - **ts-graphviz**: The main package that serves as the entry point for users. It provides a high-level API for creating, manipulating, and rendering Graphviz DOT language graphs. This package depends on the other packages to provide its functionality.
79
+
80
+ Please note that while we strive to maintain compatibility, there might be some minor differences or limitations in the compatibility package compared to the original ts-graphviz library. It is essential to review the documentation and update your code accordingly if needed, but only when you decide to migrate to the new package structure.
81
+
82
+ ### Dependency graph
83
+
84
+ | Package | Summary | Description |
85
+ | -------------------------------------------------------------------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
86
+ | [ts-graphviz](https://www.npmjs.com/package/ts-graphviz) | Graphviz library for TypeScript | The main package that serves as the entry point for users. It provides a high-level API for creating, manipulating, and rendering Graphviz DOT language graphs. |
87
+ | [@ts-graphviz/common](https://www.npmjs.com/package/@ts-graphviz/common) | Graphviz Types and Utilities | Contains type information related to DOT language attributes, attribute values, and models. |
88
+ | [@ts-graphviz/ast](https://www.npmjs.com/package/@ts-graphviz/ast) | Graphviz AST(Abstract Syntax Tree) Utilities | Includes the module for processing DOT language at the AST (Abstract Syntax Tree) level. |
89
+ | [@ts-graphviz/core](https://www.npmjs.com/package/@ts-graphviz/core) | Graphviz Models for Object-Oriented Programming | Comprises the implementation of models and functions provided to users. |
90
+ | [@ts-graphviz/adapter](https://www.npmjs.com/package/@ts-graphviz/adapter) | Graphviz Runtime adapters for Cross Platform | Handles runtime-dependent processing, such as input/output processing and Renderer implementations for different environments. |
91
+
92
+ ![dependency-graph](https://user-images.githubusercontent.com/35218186/236679412-ccef1f5d-14e8-46d1-808d-28bfe810ffda.svg)
93
+
94
+ ## Node.js Version Support Update
95
+
96
+ Starting with the upcoming release, ts-graphviz will no longer support Node.js 14 & 16, which has reached its End-of-Life (EOL). The new minimum guaranteed version will be **Node.js 18**. This decision allows us to focus on providing a secure and up-to-date library while minimizing the maintenance burden of supporting outdated versions.
97
+
98
+ To minimize disruption for our users, we have established a clear **Node.js Version Support Policy** for our library. This policy helps users understand our approach to Node.js version support and what to expect when using our library.
99
+
100
+ We encourage our users to update their projects to the latest LTS version of Node.js to ensure the best performance, security, and compatibility with ts-graphviz.
101
+
102
+ ### Node.js Version Support Policy
103
+
104
+ Our goal is to provide a stable and secure library for our users while keeping up with improvements in the JavaScript ecosystem. To achieve this, we have established the following Node.js version support policy for ts-graphviz:
105
+
106
+ 1. **Minimum Guaranteed Version**: We guarantee support for the latest Node.js version that has entered Long-Term Support (LTS) at the time of a major release of our library. This ensures that our library benefits from the stability and long-term support provided by LTS versions.
107
+
108
+ 2. **End-of-Life (EOL) Policy**: We will cease support for Node.js versions when they reach their EOL, as defined by the Node.js release schedule. This helps us focus on providing a secure and up-to-date library while minimizing the maintenance burden of supporting outdated versions.
109
+
110
+ 3. **Version Support Communication**: We will communicate our Node.js version support policy in our library's documentation and release notes. When a new major version is released or when a Node.js version enters EOL, we will inform our users through release notes, blog posts, or other relevant channels.
111
+
112
+ 4. **Migration Guides** : When introducing breaking changes due to Node.js version support updates, we will provide migration guides to help our users transition their projects to the new requirements smoothly.
113
+
114
+ ### Migration Guides
115
+
116
+ #### Update Node.js Version
117
+
118
+ To migrate to the new Node.js version support policy, follow these steps:
119
+
120
+ 1. **Check Node.js Version**: First, check the version of Node.js used in your project by running the following command in your terminal:
121
+ ```sh
122
+ node -v
123
+ ```
124
+ 2. **Update Node.js**: If your project is using Node.js 14 or 16, update it to the latest LTS version of Node.js (Node.js 18) by following the installation instructions provided on the official Node.js website or using a version manager like nvm or n.
125
+ 3. **Update Dependencies**: After updating Node.js, review your project's dependencies to ensure that they are compatible with the new Node.js version. Update any dependencies that require changes to work with the latest LTS version of Node.js.
126
+ 4. **Test and Verify**: Test your project with the updated Node.js version to ensure that it works as expected. Verify that all functionality is intact and that there are no compatibility issues with the new Node.js version.
127
+
128
+ By following these steps, you can migrate your project to the latest LTS version of Node.js and ensure compatibility with ts-graphviz.
129
+
130
+ #### Migrate `AttributeKeyDict` type to `Attribute.keys` type
131
+
132
+ `AttributeKeyDict` was deprecated in v1, so it was removed in v2.
133
+ Please modify to use `Attribute.keys`.
134
+
135
+ ```diff
136
+ - import { AttributeKeyDict } from 'ts-graphviz';
137
+ + import { Attribute } from '@ts-graphviz/common';
138
+
139
+ - const foo: AttributeKeyDict = ...;
140
+ + const foo: Attribute.keys = ...;
141
+ ```
142
+
143
+ #### Migrate `ts-graphviz/adapter` to `@ts-graphviz/adapter`
144
+
145
+ To migrate from the `ts-graphviz/adapter` module to the `@ts-graphviz/adapter` module, follow these steps:
146
+
147
+ 1. **Update Import Statements**: Update import statements in your code to use the new module name.
148
+
149
+ ```diff
150
+ - import { } from 'ts-graphviz/adapter';
151
+ + import { } from '@ts-graphviz/adapter';
152
+ ```
153
+
154
+ 2. **Update Package.json**: Update the `ts-graphviz` dependency in your `package.json` file to use the new version of the `@ts-graphviz/adapter` module.
155
+
156
+ ```diff
157
+ - "ts-graphviz": "^1.0.0",
158
+ + "ts-graphviz": "^2.0.0",
159
+ + "@ts-graphviz/adapter": "^2.0.0",
160
+ ```
161
+
162
+ 3. **Update Code References**: Search your codebase for any references to the `ts-graphviz/adapter` module and update them to use the new module name.
163
+
164
+ ```diff
165
+ - import { } from 'ts-graphviz/adapter';
166
+ + import { } from '@ts-graphviz/adapter';
167
+ ```
168
+
169
+ #### Migrate `ts-graphviz/ast` to `@ts-graphviz/ast`
170
+
171
+ To migrate from the `ts-graphviz/adapter` module to the `@ts-graphviz/adapter` module, follow these steps:
172
+
173
+ 1. **Update Import Statements**: Update import statements in your code to use the new module name.
174
+
175
+ ```diff
176
+ - import { } from 'ts-graphviz/ast';
177
+ + import { } from '@ts-graphviz/ast';
178
+ ```
179
+
180
+ 2. **Update Package.json**: Update the `ts-graphviz` dependency in your `package.json` file to use the new version of the `@ts-graphviz/ast` module.
181
+
182
+ ```diff
183
+ - "ts-graphviz": "^1.0.0",
184
+ + "ts-graphviz": "^2.0.0",
185
+ + "@ts-graphviz/ast": "^2.0.0",
186
+ ```
187
+
188
+ 3. **Update Code References**: Search your codebase for any references to the `ts-graphviz/ast` module and update them to use the new module name.
189
+
190
+ ```diff
191
+ - import { } from 'ts-graphviz/ast';
192
+ + import { } from '@ts-graphviz/ast';
193
+ ```
194
+
195
+ #### Migrate Extending the Type System
196
+
197
+ Common types moves to `@ts-graphviz/common` in v2.0.0.
198
+
199
+ If you have extended the type system, you need to update the import path.
200
+
201
+ ##### Use Case: Specifying Custom Graph Layout and Output Formats
202
+
203
+ ```diff
204
+ -import { $keywords } from 'ts-graphviz';
205
+ +import { $keywords } from '@ts-graphviz/common';
206
+ -import { toFile } from 'ts-graphviz/adapter';
207
+ +import { toFile } from '@ts-graphviz/adapter';
208
+
209
+ -// 1. Declare the 'ts-graphviz/adapter' module.
210
+ -declare module 'ts-graphviz/adapter' {
211
+ +// 1. Declare the '@ts-graphviz/adapter' module.
212
+ +declare module '@ts-graphviz/adapter' {
213
+ export namespace Layout {
214
+ // 2. Define the $values interface in the Layout namespace.
215
+ // 3. Inherit from $keywords<'my-custom-algorithm'> and specify the name of the new layout engine in <...>.
216
+ export interface $values extends $keywords<'my-custom-algorithm'> {}
217
+ }
218
+
219
+ export namespace Format {
220
+ // 4. Define the $values interface in the Format namespace.
221
+ // 5. Inherit from $keywords<'mp4'> and specify the name of the new output format in <...>.
222
+ export interface $values extends $keywords<'mp4'> {}
223
+ }
224
+ }
225
+
226
+ toFile('digraph { a -> b }', '/path/to/file', {
227
+ layout: 'my-custom-algorithm',
228
+ format: 'mp4',
229
+ });
230
+ ```
231
+
232
+ ##### Use Case: Adding Custom Attributes
233
+
234
+ ```diff
235
+ - import { digraph, toDot, attribute as _, $keywords } from 'ts-graphviz';
236
+ + import { $keywords } from '@ts-graphviz'/common;
237
+ + import { digraph, toDot, attribute as _ } from 'ts-graphviz';
238
+
239
+ -// 1. Declare the 'ts-graphviz' module.
240
+ -declare module 'ts-graphviz' {
241
+ +// 1. Declare the '@ts-graphviz/common' module.
242
+ +declare module '@ts-graphviz/common' {
243
+ export namespace GraphAttributeKey {
244
+ // 2. Define the $values interface in the GraphAttributeKey namespace.
245
+ // 3. Inherit from $keywords<'hoge'> and specify the name of the new attribute in <...>.
246
+ export interface $values extends $keywords<'hoge'> {}
247
+ }
248
+
249
+ export namespace Attribute {
250
+ // 4. Define the $keys interface in the Attribute namespace.
251
+ // 5. Inherit from $keywords<'hoge'> and specify the name of the new attribute in <...>.
252
+ export interface $keys extends $keywords<'hoge'> {}
253
+
254
+ // 6. Define the $types interface in the Attribute namespace.
255
+ // 7. Specify the new attribute in the key and define its corresponding value in the value.
256
+ export interface $types {
257
+ hoge: string;
258
+ }
259
+ }
260
+ }
261
+
262
+ console.log(
263
+ toDot(
264
+ digraph((g) => {
265
+ g.set(_.hoge, 'fuga');
266
+ }),
267
+ ),
268
+ );
269
+ ```
270
+
271
+ ## Development
272
+
273
+ ### Package manager
274
+
275
+ Migration from yarn v1 to pnpm has been done for package management.
276
+
277
+ ### Build tool and Test suite
278
+
279
+ To enhance the development experience, the build tool has been changed from rollup to vite, and the test suite from jest to vitest. This was done because jest lacked standard support for monorepo integration and TypeScript, requiring the installation of additional plugins. However, vite and vitest handle these challenges more elegantly, providing a smoother and more efficient development workflow.
280
+
281
+ ### Release flow
282
+
283
+ The release flow has been updated to use the changeset tool to manage changes and releases.
284
+
285
+ This tool allows for a more streamlined and automated release process, making it easier to manage versioning and changelogs across multiple packages within the monorepo.
286
+
287
+ ### Linter an Formatter
288
+
289
+ The linter and formatter have been updated to use biome, respectively.
290
+
291
+ This change was made to ensure consistent code style and formatting across the entire codebase, making it easier to maintain and contribute to the project.
292
+
293
+ ## API Changes
294
+
295
+ - The status of the ModelContext API and other APIs that were provided in beta and alpha have been removed. This is a temporary measure to ensure compliance with the `@microsoft/api-extractor` specification used internally in the d.ts file rollup.
8
296
 
9
297
  ### Patch Changes
10
298
 
11
299
  - Updated dependencies [[`6b2f0e8`](https://github.com/ts-graphviz/ts-graphviz/commit/6b2f0e8349605b4fe0dd950147ba3a8285b24b24)]:
12
- - @ts-graphviz/common@0.0.0-pr956-20240225091623
300
+ - @ts-graphviz/common@0.0.0-pr956-20240225163634
package/lib/ast.cjs CHANGED
@@ -1,24 +1,4 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
- var __publicField = (obj, key, value) => {
5
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
- return value;
7
- };
8
- var __accessCheck = (obj, member, msg) => {
9
- if (!member.has(obj))
10
- throw TypeError("Cannot " + msg);
11
- };
12
- var __privateGet = (obj, member, getter) => {
13
- __accessCheck(obj, member, "read from private field");
14
- return getter ? getter.call(obj) : member.get(obj);
15
- };
16
- var __privateAdd = (obj, member, value) => {
17
- if (member.has(obj))
18
- throw TypeError("Cannot add the same private member more than once");
19
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
20
- };
21
- var _plugins, _plugins2;
22
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
23
3
  const common = require("@ts-graphviz/common");
24
4
  class Builder {
@@ -34,8 +14,7 @@ class Builder {
34
14
  * @internal
35
15
  */
36
16
  getLocation() {
37
- var _a, _b;
38
- return ((_b = (_a = this.options) == null ? void 0 : _a.locationFunction) == null ? void 0 : _b.call(_a)) ?? null;
17
+ return this.options?.locationFunction?.() ?? null;
39
18
  }
40
19
  /**
41
20
  * Create an {@link ASTNode} of the specified type
@@ -297,17 +276,17 @@ class Printer {
297
276
  * @param options Options to be used when generating the DOT string.
298
277
  */
299
278
  constructor(options = {}) {
300
- /** @internal */
301
- __privateAdd(this, _plugins, [...defaultPlugins$2]);
302
279
  this.options = options;
303
280
  }
281
+ /** @internal */
282
+ #plugins = [...defaultPlugins$2];
304
283
  /**
305
284
  * Generates a DOT string from an ASTNode.
306
285
  * @param ast The ASTNode to be converted into a DOT string.
307
286
  * @returns The DOT string generated from the ASTNode.
308
287
  */
309
288
  print(ast) {
310
- const plugins = [...__privateGet(this, _plugins)];
289
+ const plugins = [...this.#plugins];
311
290
  const {
312
291
  indentSize = 2,
313
292
  indentStyle = "space",
@@ -330,7 +309,6 @@ class Printer {
330
309
  return context.print(ast);
331
310
  }
332
311
  }
333
- _plugins = new WeakMap();
334
312
  function stringify(ast, options) {
335
313
  const result = new Printer(options).print(ast);
336
314
  if (!result) {
@@ -3301,10 +3279,7 @@ const peggyParser = (
3301
3279
  const str = value.trim();
3302
3280
  const matches = str.match(/\n([\t ]+|(?!\s).)/g);
3303
3281
  if (matches) {
3304
- const indentLengths = matches.map((match) => {
3305
- var _a;
3306
- return ((_a = match.match(/[\t ]/g)) == null ? void 0 : _a.length) ?? 0;
3307
- });
3282
+ const indentLengths = matches.map((match) => match.match(/[\t ]/g)?.length ?? 0);
3308
3283
  const pattern = new RegExp(`
3309
3284
  [ ]{${Math.min(...indentLengths)}}`, "g");
3310
3285
  return str.replace(pattern, "\n");
@@ -3659,10 +3634,10 @@ const defaultPlugins$1 = [
3659
3634
  ];
3660
3635
  class FromModelConverter {
3661
3636
  constructor(options = {}) {
3662
- /** @hidden */
3663
- __privateAdd(this, _plugins2, [...defaultPlugins$1]);
3664
3637
  this.options = options;
3665
3638
  }
3639
+ /** @hidden */
3640
+ #plugins = [...defaultPlugins$1];
3666
3641
  /**
3667
3642
  * Converts a DotObjectModel into an AST.
3668
3643
  *
@@ -3670,7 +3645,7 @@ class FromModelConverter {
3670
3645
  * @returns The AST generated from the model.
3671
3646
  */
3672
3647
  convert(model) {
3673
- const plugins = [...__privateGet(this, _plugins2)];
3648
+ const plugins = [...this.#plugins];
3674
3649
  const { commentKind = "Slash" } = this.options;
3675
3650
  const context = {
3676
3651
  commentKind,
@@ -3686,14 +3661,11 @@ class FromModelConverter {
3686
3661
  return context.convert(model);
3687
3662
  }
3688
3663
  }
3689
- _plugins2 = new WeakMap();
3690
3664
  function fromModel(model, options) {
3691
3665
  return new FromModelConverter(options).convert(model);
3692
3666
  }
3693
3667
  class CommentHolder {
3694
- constructor() {
3695
- __publicField(this, "comment", null);
3696
- }
3668
+ comment = null;
3697
3669
  set(comment) {
3698
3670
  this.comment = comment;
3699
3671
  }
@@ -3701,9 +3673,8 @@ class CommentHolder {
3701
3673
  this.comment = null;
3702
3674
  }
3703
3675
  apply(model, location) {
3704
- var _a, _b, _c;
3705
- if (location && ((_a = this.comment) == null ? void 0 : _a.location)) {
3706
- if (((_b = this.comment) == null ? void 0 : _b.kind) === "Block") {
3676
+ if (location && this.comment?.location) {
3677
+ if (this.comment?.kind === "Block") {
3707
3678
  if (this.comment.location.end.line === location.start.line - 1) {
3708
3679
  model.comment = this.comment.value;
3709
3680
  }
@@ -3713,7 +3684,7 @@ class CommentHolder {
3713
3684
  }
3714
3685
  }
3715
3686
  } else {
3716
- model.comment = (_c = this.comment) == null ? void 0 : _c.value;
3687
+ model.comment = this.comment?.value;
3717
3688
  }
3718
3689
  this.reset();
3719
3690
  }
@@ -3741,23 +3712,19 @@ const DotPlugin = {
3741
3712
  };
3742
3713
  function convertToEdgeTargetTuple(edge) {
3743
3714
  return edge.targets.map((t) => {
3744
- var _a, _b;
3745
3715
  switch (t.type) {
3746
3716
  case "NodeRef":
3747
3717
  return {
3748
3718
  id: t.id.value,
3749
- port: (_a = t.port) == null ? void 0 : _a.value,
3750
- compass: (_b = t.compass) == null ? void 0 : _b.value
3719
+ port: t.port?.value,
3720
+ compass: t.compass?.value
3751
3721
  };
3752
3722
  case "NodeRefGroup":
3753
- return t.children.map((t2) => {
3754
- var _a2, _b2;
3755
- return {
3756
- id: t2.id.value,
3757
- port: (_a2 = t2.port) == null ? void 0 : _a2.value,
3758
- compass: (_b2 = t2.compass) == null ? void 0 : _b2.value
3759
- };
3760
- });
3723
+ return t.children.map((t2) => ({
3724
+ id: t2.id.value,
3725
+ port: t2.port?.value,
3726
+ compass: t2.compass?.value
3727
+ }));
3761
3728
  }
3762
3729
  });
3763
3730
  }
@@ -3863,9 +3830,8 @@ const GraphPlugin = {
3863
3830
  return ast.type === "Graph";
3864
3831
  },
3865
3832
  convert(context, ast) {
3866
- var _a;
3867
3833
  const G = ast.directed ? context.models.Digraph : context.models.Graph;
3868
- const graph = new G((_a = ast.id) == null ? void 0 : _a.value, ast.strict);
3834
+ const graph = new G(ast.id?.value, ast.strict);
3869
3835
  applyStatements(graph, ast.children);
3870
3836
  return graph;
3871
3837
  }
@@ -3895,8 +3861,7 @@ const SubgraphPlugin = {
3895
3861
  return ast.type === "Subgraph";
3896
3862
  },
3897
3863
  convert(context, ast) {
3898
- var _a;
3899
- const subgraph = new context.models.Subgraph((_a = ast.id) == null ? void 0 : _a.value);
3864
+ const subgraph = new context.models.Subgraph(ast.id?.value);
3900
3865
  applyStatements(subgraph, ast.children);
3901
3866
  return subgraph;
3902
3867
  }
@@ -3910,12 +3875,12 @@ const defaultPlugins = [
3910
3875
  ];
3911
3876
  class ToModelConverter {
3912
3877
  constructor(options = {}) {
3913
- /** @hidden */
3914
- __publicField(this, "plugins", [
3915
- ...defaultPlugins
3916
- ]);
3917
3878
  this.options = options;
3918
3879
  }
3880
+ /** @hidden */
3881
+ plugins = [
3882
+ ...defaultPlugins
3883
+ ];
3919
3884
  /**
3920
3885
  * Convert AST to Model.
3921
3886
  *
package/lib/ast.js CHANGED
@@ -1,23 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
- var __accessCheck = (obj, member, msg) => {
8
- if (!member.has(obj))
9
- throw TypeError("Cannot " + msg);
10
- };
11
- var __privateGet = (obj, member, getter) => {
12
- __accessCheck(obj, member, "read from private field");
13
- return getter ? getter.call(obj) : member.get(obj);
14
- };
15
- var __privateAdd = (obj, member, value) => {
16
- if (member.has(obj))
17
- throw TypeError("Cannot add the same private member more than once");
18
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
19
- };
20
- var _plugins, _plugins2;
21
1
  import { pipe, map, isNodeModel, isForwardRefNode, createModelsContext } from "@ts-graphviz/common";
22
2
  class Builder {
23
3
  /**
@@ -32,8 +12,7 @@ class Builder {
32
12
  * @internal
33
13
  */
34
14
  getLocation() {
35
- var _a, _b;
36
- return ((_b = (_a = this.options) == null ? void 0 : _a.locationFunction) == null ? void 0 : _b.call(_a)) ?? null;
15
+ return this.options?.locationFunction?.() ?? null;
37
16
  }
38
17
  /**
39
18
  * Create an {@link ASTNode} of the specified type
@@ -295,17 +274,17 @@ class Printer {
295
274
  * @param options Options to be used when generating the DOT string.
296
275
  */
297
276
  constructor(options = {}) {
298
- /** @internal */
299
- __privateAdd(this, _plugins, [...defaultPlugins$2]);
300
277
  this.options = options;
301
278
  }
279
+ /** @internal */
280
+ #plugins = [...defaultPlugins$2];
302
281
  /**
303
282
  * Generates a DOT string from an ASTNode.
304
283
  * @param ast The ASTNode to be converted into a DOT string.
305
284
  * @returns The DOT string generated from the ASTNode.
306
285
  */
307
286
  print(ast) {
308
- const plugins = [...__privateGet(this, _plugins)];
287
+ const plugins = [...this.#plugins];
309
288
  const {
310
289
  indentSize = 2,
311
290
  indentStyle = "space",
@@ -328,7 +307,6 @@ class Printer {
328
307
  return context.print(ast);
329
308
  }
330
309
  }
331
- _plugins = new WeakMap();
332
310
  function stringify(ast, options) {
333
311
  const result = new Printer(options).print(ast);
334
312
  if (!result) {
@@ -3299,10 +3277,7 @@ const peggyParser = (
3299
3277
  const str = value.trim();
3300
3278
  const matches = str.match(/\n([\t ]+|(?!\s).)/g);
3301
3279
  if (matches) {
3302
- const indentLengths = matches.map((match) => {
3303
- var _a;
3304
- return ((_a = match.match(/[\t ]/g)) == null ? void 0 : _a.length) ?? 0;
3305
- });
3280
+ const indentLengths = matches.map((match) => match.match(/[\t ]/g)?.length ?? 0);
3306
3281
  const pattern = new RegExp(`
3307
3282
  [ ]{${Math.min(...indentLengths)}}`, "g");
3308
3283
  return str.replace(pattern, "\n");
@@ -3657,10 +3632,10 @@ const defaultPlugins$1 = [
3657
3632
  ];
3658
3633
  class FromModelConverter {
3659
3634
  constructor(options = {}) {
3660
- /** @hidden */
3661
- __privateAdd(this, _plugins2, [...defaultPlugins$1]);
3662
3635
  this.options = options;
3663
3636
  }
3637
+ /** @hidden */
3638
+ #plugins = [...defaultPlugins$1];
3664
3639
  /**
3665
3640
  * Converts a DotObjectModel into an AST.
3666
3641
  *
@@ -3668,7 +3643,7 @@ class FromModelConverter {
3668
3643
  * @returns The AST generated from the model.
3669
3644
  */
3670
3645
  convert(model) {
3671
- const plugins = [...__privateGet(this, _plugins2)];
3646
+ const plugins = [...this.#plugins];
3672
3647
  const { commentKind = "Slash" } = this.options;
3673
3648
  const context = {
3674
3649
  commentKind,
@@ -3684,14 +3659,11 @@ class FromModelConverter {
3684
3659
  return context.convert(model);
3685
3660
  }
3686
3661
  }
3687
- _plugins2 = new WeakMap();
3688
3662
  function fromModel(model, options) {
3689
3663
  return new FromModelConverter(options).convert(model);
3690
3664
  }
3691
3665
  class CommentHolder {
3692
- constructor() {
3693
- __publicField(this, "comment", null);
3694
- }
3666
+ comment = null;
3695
3667
  set(comment) {
3696
3668
  this.comment = comment;
3697
3669
  }
@@ -3699,9 +3671,8 @@ class CommentHolder {
3699
3671
  this.comment = null;
3700
3672
  }
3701
3673
  apply(model, location) {
3702
- var _a, _b, _c;
3703
- if (location && ((_a = this.comment) == null ? void 0 : _a.location)) {
3704
- if (((_b = this.comment) == null ? void 0 : _b.kind) === "Block") {
3674
+ if (location && this.comment?.location) {
3675
+ if (this.comment?.kind === "Block") {
3705
3676
  if (this.comment.location.end.line === location.start.line - 1) {
3706
3677
  model.comment = this.comment.value;
3707
3678
  }
@@ -3711,7 +3682,7 @@ class CommentHolder {
3711
3682
  }
3712
3683
  }
3713
3684
  } else {
3714
- model.comment = (_c = this.comment) == null ? void 0 : _c.value;
3685
+ model.comment = this.comment?.value;
3715
3686
  }
3716
3687
  this.reset();
3717
3688
  }
@@ -3739,23 +3710,19 @@ const DotPlugin = {
3739
3710
  };
3740
3711
  function convertToEdgeTargetTuple(edge) {
3741
3712
  return edge.targets.map((t) => {
3742
- var _a, _b;
3743
3713
  switch (t.type) {
3744
3714
  case "NodeRef":
3745
3715
  return {
3746
3716
  id: t.id.value,
3747
- port: (_a = t.port) == null ? void 0 : _a.value,
3748
- compass: (_b = t.compass) == null ? void 0 : _b.value
3717
+ port: t.port?.value,
3718
+ compass: t.compass?.value
3749
3719
  };
3750
3720
  case "NodeRefGroup":
3751
- return t.children.map((t2) => {
3752
- var _a2, _b2;
3753
- return {
3754
- id: t2.id.value,
3755
- port: (_a2 = t2.port) == null ? void 0 : _a2.value,
3756
- compass: (_b2 = t2.compass) == null ? void 0 : _b2.value
3757
- };
3758
- });
3721
+ return t.children.map((t2) => ({
3722
+ id: t2.id.value,
3723
+ port: t2.port?.value,
3724
+ compass: t2.compass?.value
3725
+ }));
3759
3726
  }
3760
3727
  });
3761
3728
  }
@@ -3861,9 +3828,8 @@ const GraphPlugin = {
3861
3828
  return ast.type === "Graph";
3862
3829
  },
3863
3830
  convert(context, ast) {
3864
- var _a;
3865
3831
  const G = ast.directed ? context.models.Digraph : context.models.Graph;
3866
- const graph = new G((_a = ast.id) == null ? void 0 : _a.value, ast.strict);
3832
+ const graph = new G(ast.id?.value, ast.strict);
3867
3833
  applyStatements(graph, ast.children);
3868
3834
  return graph;
3869
3835
  }
@@ -3893,8 +3859,7 @@ const SubgraphPlugin = {
3893
3859
  return ast.type === "Subgraph";
3894
3860
  },
3895
3861
  convert(context, ast) {
3896
- var _a;
3897
- const subgraph = new context.models.Subgraph((_a = ast.id) == null ? void 0 : _a.value);
3862
+ const subgraph = new context.models.Subgraph(ast.id?.value);
3898
3863
  applyStatements(subgraph, ast.children);
3899
3864
  return subgraph;
3900
3865
  }
@@ -3908,12 +3873,12 @@ const defaultPlugins = [
3908
3873
  ];
3909
3874
  class ToModelConverter {
3910
3875
  constructor(options = {}) {
3911
- /** @hidden */
3912
- __publicField(this, "plugins", [
3913
- ...defaultPlugins
3914
- ]);
3915
3876
  this.options = options;
3916
3877
  }
3878
+ /** @hidden */
3879
+ plugins = [
3880
+ ...defaultPlugins
3881
+ ];
3917
3882
  /**
3918
3883
  * Convert AST to Model.
3919
3884
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ts-graphviz/ast",
3
- "version": "0.0.0-pr956-20240225091623",
4
- "description": "",
3
+ "version": "0.0.0-pr956-20240225163634",
4
+ "description": "Graphviz AST(Abstract Syntax Tree) Utilities",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/ts-graphviz/ts-graphviz#readme",
7
7
  "bugs": {
@@ -41,14 +41,8 @@
41
41
  "main": "lib/ast.cjs",
42
42
  "module": "lib/ast.js",
43
43
  "types": "lib/ast.d.ts",
44
- "files": [
45
- "lib",
46
- "README.md",
47
- "CHANGELOG.md",
48
- "LICENSE"
49
- ],
50
44
  "dependencies": {
51
- "@ts-graphviz/common": "^0.0.0-pr956-20240225091623"
45
+ "@ts-graphviz/common": "^0.0.0-pr956-20240225163634"
52
46
  },
53
47
  "devDependencies": {
54
48
  "peggy": "^3.0.2",