File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -379,7 +379,7 @@ function parseReturn(s: ITokenStream): Ast.Return {
379
379
* StatementWithAttr = *Attr Statement
380
380
* ```
381
381
*/
382
- function parseStatementWithAttr ( s : ITokenStream ) : Ast . Definition {
382
+ export function parseStatementWithAttr ( s : ITokenStream ) : Ast . Definition {
383
383
const attrs : Ast . Attribute [ ] = [ ] ;
384
384
while ( s . is ( TokenKind . OpenSharpBracket ) ) {
385
385
attrs . push ( parseAttr ( s ) as Ast . Attribute ) ;
Original file line number Diff line number Diff line change 1
1
import { NODE } from '../utils.js' ;
2
2
import { TokenKind } from '../token.js' ;
3
3
import { AiScriptSyntaxError , AiScriptUnexpectedEOFError } from '../../error.js' ;
4
- import { parseDefStatement , parseStatement } from './statements.js' ;
4
+ import { parseDefStatement , parseStatement , parseStatementWithAttr } from './statements.js' ;
5
5
import { parseExpr } from './expressions.js' ;
6
6
7
7
import type * as Ast from '../../node.js' ;
@@ -91,6 +91,10 @@ export function parseNamespace(s: ITokenStream): Ast.Namespace {
91
91
members . push ( parseNamespace ( s ) ) ;
92
92
break ;
93
93
}
94
+ case TokenKind . OpenSharpBracket : {
95
+ members . push ( parseStatementWithAttr ( s ) ) ;
96
+ break ;
97
+ }
94
98
}
95
99
96
100
// terminator
Original file line number Diff line number Diff line change @@ -929,6 +929,25 @@ describe('Attribute', () => {
929
929
if ( attr . value . type !== 'bool' ) assert . fail ( ) ;
930
930
assert . equal ( attr . value . value , true ) ;
931
931
} ) ;
932
+
933
+ test . concurrent ( 'attribute with statement under namespace' , async ( ) => {
934
+ const parser = new Parser ( ) ;
935
+ const nodes = parser . parse ( `
936
+ :: Tests {
937
+ #[test]
938
+ @assert_success() {
939
+ <: "Hello, world!"
940
+ }
941
+ }
942
+ ` ) ;
943
+ assert . equal ( nodes . length , 1 ) ;
944
+ const ns = nodes [ 0 ] ;
945
+ assert . ok ( ns . type === 'ns' ) ;
946
+ const member = ns . members [ 0 ] ;
947
+ assert . ok ( member . type === 'def' ) ;
948
+ const attr = member . attr [ 0 ] ;
949
+ assert . equal ( attr . name , 'test' ) ;
950
+ } ) ;
932
951
} ) ;
933
952
934
953
describe ( 'Location' , ( ) => {
Original file line number Diff line number Diff line change
1
+ - 名前空間下の変数定義に属性を付与できるようになりました。
You can’t perform that action at this time.
0 commit comments