Skip to content

Commit 6af78d3

Browse files
committed
replacing all AstNode references for the more accurate PrintableNode
1 parent 2341fe4 commit 6af78d3

176 files changed

Lines changed: 393 additions & 404 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.

src/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
RequiredOptions,
1717
SupportLanguage
1818
} from 'prettier';
19-
import type { AstNode } from './slang-nodes/types.d.ts';
19+
import type { PrintableNode } from './slang-nodes/types.d.ts';
2020

2121
const slangParserId = 'slang';
2222
const antlrParserId = 'antlr';
@@ -39,7 +39,7 @@ const languages: SupportLanguage[] = [
3939

4040
// https://prettier.io/docs/en/plugins.html#parsers
4141
const antlrParser = { astFormat: antlrAstId, parse: antlrParse, ...loc };
42-
const slangParser: Parser<AstNode> = {
42+
const slangParser: Parser<PrintableNode> = {
4343
astFormat: slangAstId,
4444
parse: slangParse,
4545
locStart,
@@ -53,8 +53,7 @@ const parsers = {
5353

5454
const antlrCanAttachComment = ({ type }: { type: string }): boolean =>
5555
typeof type === 'string' && type !== 'BlockComment' && type !== 'LineComment';
56-
const canAttachComment = (node: AstNode): boolean =>
57-
typeof node !== 'string' &&
56+
const canAttachComment = (node: PrintableNode | undefined): boolean =>
5857
node !== undefined &&
5958
node.kind && // Make sure it's not Location
6059
!isComment(node);
@@ -72,7 +71,7 @@ const antlrPrinter = {
7271
print: antlrPrint,
7372
printComment: comments.printComment
7473
};
75-
const slangPrinter: Printer<AstNode> = {
74+
const slangPrinter: Printer<PrintableNode | undefined> = {
7675
canAttachComment,
7776
handleComments,
7877
isBlockComment,

src/slang-comments/handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import type { Comment } from '../slang-nodes/types.d.ts';
55
function handler(
66
comment: Comment,
77
text: string
8-
// options: ParserOptions<AstNode>,
9-
// ast: AstNode,
8+
// options: ParserOptions<PrintableNode>,
9+
// ast: PrintableNode,
1010
// isLastComment: boolean
1111
): boolean {
1212
const { precedingNode, enclosingNode, followingNode } = comment;

src/slang-comments/printer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { isComment } from '../slang-utils/is-comment.js';
22

33
import type { AstPath, Doc } from 'prettier';
4-
import type { AstNode } from '../slang-nodes/types.d.ts';
4+
import type { PrintableNode } from '../slang-nodes/types.d.ts';
55

6-
export function printComment({ node: comment }: AstPath<AstNode>): Doc {
6+
export function printComment({
7+
node: comment
8+
}: AstPath<PrintableNode | undefined>): Doc {
79
if (isComment(comment)) {
810
return comment.print();
911
}

src/slang-nodes/AdditiveExpression.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Expression } from './Expression.js';
99
import type * as ast from '@nomicfoundation/slang/ast';
1010
import type { AstPath, Doc, ParserOptions } from 'prettier';
1111
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
12-
import type { AstNode } from './types.d.ts';
12+
import type { PrintableNode } from './types.d.ts';
1313

1414
const tryToHug = createHugFunction(['%']);
1515

@@ -38,7 +38,7 @@ export class AdditiveExpression extends SlangNode {
3838
constructor(
3939
ast: ast.AdditiveExpression,
4040
collected: CollectedMetadata,
41-
options: ParserOptions<AstNode>
41+
options: ParserOptions<PrintableNode>
4242
) {
4343
super(ast, collected);
4444

@@ -59,7 +59,7 @@ export class AdditiveExpression extends SlangNode {
5959
print(
6060
path: AstPath<AdditiveExpression>,
6161
print: PrintFunction,
62-
options: ParserOptions<AstNode>
62+
options: ParserOptions<PrintableNode>
6363
): Doc {
6464
return printAdditiveExpression(this, path, print, options);
6565
}

src/slang-nodes/AndExpression.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Expression } from './Expression.js';
77
import type * as ast from '@nomicfoundation/slang/ast';
88
import type { AstPath, Doc, ParserOptions } from 'prettier';
99
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
10-
import type { AstNode } from './types.d.ts';
10+
import type { PrintableNode } from './types.d.ts';
1111

1212
export class AndExpression extends SlangNode {
1313
readonly kind = NonterminalKind.AndExpression;
@@ -21,7 +21,7 @@ export class AndExpression extends SlangNode {
2121
constructor(
2222
ast: ast.AndExpression,
2323
collected: CollectedMetadata,
24-
options: ParserOptions<AstNode>
24+
options: ParserOptions<PrintableNode>
2525
) {
2626
super(ast, collected);
2727

@@ -39,7 +39,7 @@ export class AndExpression extends SlangNode {
3939
print(
4040
path: AstPath<AndExpression>,
4141
print: PrintFunction,
42-
options: ParserOptions<AstNode>
42+
options: ParserOptions<PrintableNode>
4343
): Doc {
4444
return printLogicalOperation(this, path, print, options);
4545
}

src/slang-nodes/ArgumentsDeclaration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { NamedArgumentsDeclaration } from './NamedArgumentsDeclaration.js';
77

88
import type { ParserOptions } from 'prettier';
99
import type { CollectedMetadata } from '../types.d.ts';
10-
import type { AstNode } from './types.d.ts';
10+
import type { PrintableNode } from './types.d.ts';
1111

1212
const createNonterminalVariant = createNonterminalVariantSimpleCreator<
1313
ast.ArgumentsDeclaration,
@@ -25,7 +25,7 @@ export class ArgumentsDeclaration extends SlangNode {
2525
constructor(
2626
ast: ast.ArgumentsDeclaration,
2727
collected: CollectedMetadata,
28-
options: ParserOptions<AstNode>
28+
options: ParserOptions<PrintableNode>
2929
) {
3030
super(ast, collected);
3131

src/slang-nodes/ArrayExpression.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ArrayValues } from './ArrayValues.js';
55
import type * as ast from '@nomicfoundation/slang/ast';
66
import type { AstPath, Doc, ParserOptions } from 'prettier';
77
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
8-
import type { AstNode } from './types.d.ts';
8+
import type { PrintableNode } from './types.d.ts';
99

1010
export class ArrayExpression extends SlangNode {
1111
readonly kind = NonterminalKind.ArrayExpression;
@@ -15,7 +15,7 @@ export class ArrayExpression extends SlangNode {
1515
constructor(
1616
ast: ast.ArrayExpression,
1717
collected: CollectedMetadata,
18-
options: ParserOptions<AstNode>
18+
options: ParserOptions<PrintableNode>
1919
) {
2020
super(ast, collected);
2121

src/slang-nodes/ArrayTypeName.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Expression } from './Expression.js';
77
import type * as ast from '@nomicfoundation/slang/ast';
88
import type { AstPath, Doc, ParserOptions } from 'prettier';
99
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
10-
import type { AstNode } from './types.d.ts';
10+
import type { PrintableNode } from './types.d.ts';
1111

1212
export class ArrayTypeName extends SlangNode {
1313
readonly kind = NonterminalKind.ArrayTypeName;
@@ -19,7 +19,7 @@ export class ArrayTypeName extends SlangNode {
1919
constructor(
2020
ast: ast.ArrayTypeName,
2121
collected: CollectedMetadata,
22-
options: ParserOptions<AstNode>
22+
options: ParserOptions<PrintableNode>
2323
) {
2424
super(ast, collected);
2525

src/slang-nodes/ArrayValues.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Expression } from './Expression.js';
77
import type * as ast from '@nomicfoundation/slang/ast';
88
import type { AstPath, Doc, ParserOptions } from 'prettier';
99
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
10-
import type { AstNode } from './types.d.ts';
10+
import type { PrintableNode } from './types.d.ts';
1111

1212
export class ArrayValues extends SlangNode {
1313
readonly kind = NonterminalKind.ArrayValues;
@@ -17,7 +17,7 @@ export class ArrayValues extends SlangNode {
1717
constructor(
1818
ast: ast.ArrayValues,
1919
collected: CollectedMetadata,
20-
options: ParserOptions<AstNode>
20+
options: ParserOptions<PrintableNode>
2121
) {
2222
super(ast, collected, true);
2323

src/slang-nodes/AssemblyFlags.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { StringLiteral } from './StringLiteral.js';
66
import type * as ast from '@nomicfoundation/slang/ast';
77
import type { AstPath, Doc, ParserOptions } from 'prettier';
88
import type { CollectedMetadata, PrintFunction } from '../types.d.ts';
9-
import type { AstNode } from './types.d.ts';
9+
import type { PrintableNode } from './types.d.ts';
1010

1111
export class AssemblyFlags extends SlangNode {
1212
readonly kind = NonterminalKind.AssemblyFlags;
@@ -16,7 +16,7 @@ export class AssemblyFlags extends SlangNode {
1616
constructor(
1717
ast: ast.AssemblyFlags,
1818
collected: CollectedMetadata,
19-
options: ParserOptions<AstNode>
19+
options: ParserOptions<PrintableNode>
2020
) {
2121
super(ast, collected, true);
2222

0 commit comments

Comments
 (0)