File tree Expand file tree Collapse file tree 4 files changed +78
-1
lines changed
src/slang-comments/handlers Expand file tree Collapse file tree 4 files changed +78
-1
lines changed Original file line number Diff line number Diff line change 1+ import { NonterminalKind } from '@nomicfoundation/slang/cst' ;
2+ import { util } from 'prettier' ;
3+ import { locEnd } from '../../slang-utils/loc.js' ;
4+ import addCollectionNodeFirstComment from './add-collection-node-first-comment.js' ;
5+ import addCollectionNodeLastComment from './add-collection-node-last-comment.js' ;
6+
7+ import type { HandlerParams } from './types.d.ts' ;
8+
9+ export default function handleStructComments ( {
10+ text,
11+ precedingNode,
12+ enclosingNode,
13+ followingNode,
14+ comment
15+ } : HandlerParams ) : boolean {
16+ if ( enclosingNode ?. kind !== NonterminalKind . StructDefinition ) {
17+ return false ;
18+ }
19+
20+ const nextCharacter = util . getNextNonSpaceNonCommentCharacter (
21+ text ,
22+ locEnd ( comment )
23+ ) ;
24+
25+ if (
26+ precedingNode ?. kind === NonterminalKind . StructMembers &&
27+ nextCharacter === '}'
28+ ) {
29+ addCollectionNodeLastComment ( precedingNode , comment ) ;
30+ return true ;
31+ }
32+
33+ if ( followingNode ?. kind === NonterminalKind . StructMembers ) {
34+ addCollectionNodeFirstComment ( followingNode , comment ) ;
35+ return true ;
36+ }
37+
38+ return false ;
39+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import handleModifierInvocationComments from './handle-modifier-invocation-comme
99import handleParametersDeclarationComments from './handle-parameters-declaration-comments.js' ;
1010import handlePositionalArgumentsDeclarationComments from './handle-positional-arguments-declaration-comments.js' ;
1111import handleStorageLayoutSpecifierComments from './handle-storage-layout-specifier-comments.js' ;
12+ import handleStructComments from './handle-struct-comments.js' ;
1213import handleWhileStatementComments from './handle-while-statement-comments.js' ;
1314import handleYulBlockComments from './handle-yul-block-comments.js' ;
1415
@@ -24,6 +25,7 @@ export default [
2425 handleParametersDeclarationComments ,
2526 handlePositionalArgumentsDeclarationComments ,
2627 handleStorageLayoutSpecifierComments ,
28+ handleStructComments ,
2729 handleWhileStatementComments ,
2830 handleYulBlockComments
2931] ;
Original file line number Diff line number Diff line change @@ -165,4 +165,17 @@ contract Comments13 {
165165 ) // comment 13
166166 {
167167 }
168+ }
169+
170+
171+
172+ contract Comments14 {
173+ struct AssetStore // use 0 for non-EVM chains
174+ {
175+ uint chainId;
176+ uint assetStoreIndex;
177+ string assetStoreAddress; // we assume all addresses are strings and the front-end will cast correctly
178+ //string shortName; // usually an asset shortName `eth:` or `st:` for a stealth address
179+ }
180+
168181}
Original file line number Diff line number Diff line change 1- // Jest Snapshot v1, https://goo.gl/fbAQLP
1+ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22
33exports [` Comments.sol format 1` ] = `
44====================================options=====================================
@@ -174,6 +174,19 @@ contract Comments13 {
174174 {
175175 }
176176}
177+
178+
179+
180+ contract Comments14 {
181+ struct AssetStore // use 0 for non-EVM chains
182+ {
183+ uint chainId;
184+ uint assetStoreIndex;
185+ string assetStoreAddress; // we assume all addresses are strings and the front-end will cast correctly
186+ // string shortName; // usually an asset shortName \`eth:\` or \`st:\` for a stealth address
187+ }
188+
189+ }
177190=====================================output=====================================
178191contract Comments1 {
179192 /* solhint-disable var-name-mixedcase */
@@ -378,5 +391,15 @@ contract Comments13 {
378391 {}
379392}
380393
394+ contract Comments14 {
395+ struct AssetStore {
396+ // use 0 for non-EVM chains
397+ uint chainId;
398+ uint assetStoreIndex;
399+ string assetStoreAddress; // we assume all addresses are strings and the front-end will cast correctly
400+ // string shortName; // usually an asset shortName \`eth:\` or \`st:\` for a stealth address
401+ }
402+ }
403+
381404================================================================================
382405` ;
You can’t perform that action at this time.
0 commit comments