Skip to content

Commit 7b03001

Browse files
committed
removing ExperimentalFeature from the AST tree
1 parent 61bbca4 commit 7b03001

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/slang-nodes/ExperimentalFeature.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import {
22
NonterminalKind,
33
TerminalNode as SlangTerminalNode
44
} from '@nomicfoundation/slang/cst';
5-
import { PolymorphicNode } from './PolymorphicNode.js';
5+
import { SlangNode } from './SlangNode.js';
66
import { StringLiteral } from './StringLiteral.js';
77
import { TerminalNode } from './TerminalNode.js';
88

99
import type * as ast from '@nomicfoundation/slang/ast';
1010
import type { ParserOptions } from 'prettier';
1111
import type { AstNode } from './types.d.ts';
1212

13-
export class ExperimentalFeature extends PolymorphicNode {
13+
export class ExperimentalFeature extends SlangNode {
1414
readonly kind = NonterminalKind.ExperimentalFeature;
1515

1616
variant: StringLiteral | TerminalNode;
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NonterminalKind } from '@nomicfoundation/slang/cst';
2-
import { printVariant } from '../slang-printers/print-variant.js';
2+
import { extractVariant } from '../slang-utils/extract-variant.js';
33
import { SlangNode } from './SlangNode.js';
44
import { ExperimentalFeature } from './ExperimentalFeature.js';
55

@@ -11,17 +11,19 @@ import type { AstNode } from './types.d.ts';
1111
export class ExperimentalPragma extends SlangNode {
1212
readonly kind = NonterminalKind.ExperimentalPragma;
1313

14-
feature: ExperimentalFeature;
14+
feature: ExperimentalFeature['variant'];
1515

1616
constructor(ast: ast.ExperimentalPragma, options: ParserOptions<AstNode>) {
1717
super(ast);
1818

19-
this.feature = new ExperimentalFeature(ast.feature, options);
19+
this.feature = extractVariant(
20+
new ExperimentalFeature(ast.feature, options)
21+
);
2022

2123
this.updateMetadata(this.feature);
2224
}
2325

2426
print(path: AstPath<ExperimentalPragma>, print: PrintFunction): Doc {
25-
return ['experimental ', path.call(printVariant(print), 'feature')];
27+
return ['experimental ', path.call(print, 'feature')];
2628
}
2729
}

src/slangPrinter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type { Statement } from './slang-nodes/Statement.js';
1919
import type { YulStatement } from './slang-nodes/YulStatement.js';
2020
import type { ContractSpecifier } from './slang-nodes/ContractSpecifier.js';
2121
import type { ElementaryType } from './slang-nodes/ElementaryType.js';
22+
import type { ExperimentalFeature } from './slang-nodes/ExperimentalFeature.js';
2223

2324
function hasNodeIgnoreComment({ comments }: StrictAstNode): boolean {
2425
// Prettier sets SourceUnit's comments to undefined after assigning comments
@@ -86,6 +87,7 @@ function genericPrint(
8687
| YulStatement
8788
| ContractSpecifier
8889
| ElementaryType
90+
| ExperimentalFeature
8991
>
9092
>,
9193
options: ParserOptions<AstNode>,

0 commit comments

Comments
 (0)