Skip to content

Commit cbe36ad

Browse files
committed
using the new collection of metadata
1 parent 08d0a84 commit cbe36ad

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/slangYulParser.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// https://prettier.io/docs/en/plugins.html#parsers
22
import { YulBlock as SlangYulBlock } from '@nomicfoundation/slang/ast';
3-
import { clearOffsets } from './slang-nodes/SlangNode.js';
43
import { createParser } from './slang-utils/create-parser.js';
54
import { YulBlock } from './slang-nodes/YulBlock.js';
65

76
import type { ParserOptions } from 'prettier';
8-
import type { AstNode } from './slang-nodes/types.d.ts';
7+
import type { AstNode, Comment } from './slang-nodes/types.d.ts';
98

109
export default function parse(
1110
text: string,
@@ -15,10 +14,15 @@ export default function parse(
1514

1615
// We update the compiler version by the inferred one.
1716
options.compiler = parser.languageVersion;
17+
const comments: Comment[] = [];
1818
const parsed = new YulBlock(
1919
new SlangYulBlock(parseOutput.tree.asNonterminalNode()),
20+
{ offsets: new Map<number, number>(), comments },
2021
options
2122
);
22-
clearOffsets();
23+
24+
// Because of comments being extracted like a Russian doll, the order needs
25+
// to be fixed at the end.
26+
parsed.comments = comments.sort((a, b) => a.loc.start - b.loc.start);
2327
return parsed;
2428
}

0 commit comments

Comments
 (0)