File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// https://prettier.io/docs/en/plugins.html#parsers
22import { YulBlock as SlangYulBlock } from '@nomicfoundation/slang/ast' ;
3- import { clearOffsets } from './slang-nodes/SlangNode.js' ;
43import { createParser } from './slang-utils/create-parser.js' ;
54import { YulBlock } from './slang-nodes/YulBlock.js' ;
65
76import 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
109export 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}
You can’t perform that action at this time.
0 commit comments