Skip to content

Commit cd72e9a

Browse files
authored
Simplify Node creation (#311)
1 parent 61b2aee commit cd72e9a

29 files changed

+78
-139
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default tseslint.config(
1616
"simple-import-sort": eslintPluginSimpleImportSort,
1717
},
1818
rules: {
19+
"object-shorthand": "error",
1920
"@typescript-eslint/no-namespace": "off",
2021
"@typescript-eslint/no-non-null-assertion": "off",
2122
"@typescript-eslint/no-explicit-any": "off",

src/factories/alias.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { type Alias, type Content, type Position } from "../types.js";
2-
import { createCommentAttachable } from "./comment-attachable.js";
3-
import { createNode } from "./node.js";
42

53
export function createAlias(
64
position: Position,
75
content: Content,
86
value: string,
97
): Alias {
108
return {
11-
...createNode("alias", position),
12-
...createCommentAttachable(),
9+
type: "alias",
10+
position,
11+
leadingComments: [],
12+
trailingComment: null,
1313
...content,
1414
value,
1515
};

src/factories/anchor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { type Anchor, type Position } from "../types.js";
2-
import { createNode } from "./node.js";
32

43
export function createAnchor(position: Position, value: string): Anchor {
54
return {
6-
...createNode("anchor", position),
5+
type: "anchor",
6+
position,
77
value,
88
};
99
}

src/factories/block-value.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import {
44
type Content,
55
type Position,
66
} from "../types.ts";
7-
import { createLeadingCommentAttachable } from "./leading-comment-attachable.ts";
8-
import { createNode } from "./node.ts";
97

108
export function createBlockValue(
119
position: Position,
@@ -16,8 +14,9 @@ export function createBlockValue(
1614
indicatorComment: null | Comment,
1715
): BlockValue {
1816
return {
19-
...createNode("blockValue", position),
20-
...createLeadingCommentAttachable(),
17+
type: "blockValue",
18+
position,
19+
leadingComments: [],
2120
...content,
2221
chomping,
2322
indent,

src/factories/comment-attachable.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/factories/comment.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/factories/directive.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { type Directive, type Position } from "../types.ts";
2-
import { createCommentAttachable } from "./comment-attachable.ts";
3-
import { createNode } from "./node.ts";
42

53
export function createDirective(
64
position: Position,
75
name: string,
86
parameters: string[],
97
): Directive {
108
return {
11-
...createNode("directive", position),
12-
...createCommentAttachable(),
9+
type: "directive",
10+
position,
11+
leadingComments: [],
12+
trailingComment: null,
1313
name,
1414
parameters,
1515
};

src/factories/document-body.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ import {
44
type DocumentBody,
55
type Position,
66
} from "../types.ts";
7-
import { createEndCommentAttachable } from "./end-comment-attachable.ts";
8-
import { createNode } from "./node.ts";
97

108
export function createDocumentBody(
119
position: Position,
1210
content: null | ContentNode,
1311
endComments: Comment[],
1412
): DocumentBody {
1513
return {
16-
...createNode("documentBody", position),
17-
...createEndCommentAttachable(endComments),
14+
type: "documentBody",
15+
position,
16+
endComments,
1817
children: !content ? [] : [content],
1918
};
2019
}

src/factories/document-head.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import {
44
type DocumentHead,
55
type Position,
66
} from "../types.ts";
7-
import { createEndCommentAttachable } from "./end-comment-attachable.ts";
8-
import { createNode } from "./node.ts";
9-
import { createTrailingCommentAttachable } from "./trailing-comment-attachable.ts";
107

118
export function createDocumentHead(
129
position: Position,
@@ -15,9 +12,10 @@ export function createDocumentHead(
1512
trailingComment: null | Comment,
1613
): DocumentHead {
1714
return {
18-
...createNode("documentHead", position),
19-
...createEndCommentAttachable(endComments),
20-
...createTrailingCommentAttachable(trailingComment),
15+
type: "documentHead",
16+
position,
17+
endComments,
18+
trailingComment,
2119
children,
2220
};
2321
}

src/factories/document.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {
55
type DocumentHead,
66
type Position,
77
} from "../types.ts";
8-
import { createNode } from "./node.ts";
9-
import { createTrailingCommentAttachable } from "./trailing-comment-attachable.ts";
108

119
export function createDocument(
1210
position: Position,
@@ -17,8 +15,9 @@ export function createDocument(
1715
trailingComment: null | Comment,
1816
): Document {
1917
return {
20-
...createNode("document", position),
21-
...createTrailingCommentAttachable(trailingComment),
18+
type: "document",
19+
position,
20+
trailingComment,
2221
directivesEndMarker,
2322
documentEndMarker,
2423
children: [head, body],

0 commit comments

Comments
 (0)