File tree Expand file tree Collapse file tree 3 files changed +96
-1
lines changed Expand file tree Collapse file tree 3 files changed +96
-1
lines changed Original file line number Diff line number Diff line change @@ -358,7 +358,7 @@ module.exports = {
358358 this . next ( ) ;
359359 }
360360
361- if ( this . peek ( ) === "=" ) {
361+ if ( this . peekSkipComments ( ) === "=" ) {
362362 return [ false , null ] ;
363363 }
364364
@@ -386,6 +386,21 @@ module.exports = {
386386 return [ nullable , type ] ;
387387 } ,
388388
389+ peekSkipComments : function ( ) {
390+ const lexerState = this . lexer . getState ( ) ;
391+ let nextToken ;
392+
393+ do {
394+ nextToken = this . lexer . lex ( ) ;
395+ } while (
396+ nextToken === this . tok . T_COMMENT ||
397+ nextToken === this . tok . T_WHITESPACE
398+ ) ;
399+
400+ this . lexer . setState ( lexerState ) ;
401+ return nextToken ;
402+ } ,
403+
389404 /*
390405 * reading an interface
391406 * ```ebnf
Original file line number Diff line number Diff line change @@ -49,6 +49,71 @@ Program {
4949}
5050` ;
5151
52+ exports [` classconstant multiline declaration with comment 1` ] = `
53+ Program {
54+ " children" : [
55+ Class {
56+ " attrGroups" : [],
57+ " body" : [
58+ ClassConstant {
59+ " attrGroups" : [],
60+ " constants" : [
61+ Constant {
62+ " kind" : " constant" ,
63+ " name" : Identifier {
64+ " kind" : " identifier" ,
65+ " name" : " CONSTANT" ,
66+ },
67+ " value" : String {
68+ " isDoubleQuote" : false ,
69+ " kind" : " string" ,
70+ " leadingComments" : [
71+ CommentLine {
72+ " kind" : " commentline" ,
73+ " offset" : 75 ,
74+ " value" : " // Comment
75+ " ,
76+ },
77+ ],
78+ " raw" : " 'string'" ,
79+ " unicode" : false ,
80+ " value" : " string" ,
81+ },
82+ },
83+ ],
84+ " final" : false ,
85+ " kind" : " classconstant" ,
86+ " nullable" : false ,
87+ " type" : null ,
88+ " visibility" : " public" ,
89+ },
90+ ],
91+ " extends" : null ,
92+ " implements" : null ,
93+ " isAbstract" : false ,
94+ " isAnonymous" : false ,
95+ " isFinal" : false ,
96+ " isReadonly" : false ,
97+ " kind" : " class" ,
98+ " name" : Identifier {
99+ " kind" : " identifier" ,
100+ " name" : " Foo" ,
101+ },
102+ },
103+ ],
104+ " comments" : [
105+ CommentLine {
106+ " kind" : " commentline" ,
107+ " offset" : 75 ,
108+ " value" : " // Comment
109+ " ,
110+ },
111+ ],
112+ " errors" : [],
113+ " kind" : " program" ,
114+ }
115+ ` ;
116+
52117exports [` classconstant multiple 1` ] = `
53118Program {
54119 " children" : [
Original file line number Diff line number Diff line change @@ -75,4 +75,19 @@ describe("classconstant", () => {
7575 ) ,
7676 ) . toThrowErrorMatchingSnapshot ( ) ;
7777 } ) ;
78+ it ( "multiline declaration with comment" , ( ) => {
79+ expect (
80+ parser . parseEval (
81+ `class Foo {
82+ public
83+ const
84+ CONSTANT
85+ // Comment
86+ =
87+ 'string';
88+ }` ,
89+ { parser : { version : 803 , extractDoc : true } } ,
90+ ) ,
91+ ) . toMatchSnapshot ( ) ;
92+ } ) ;
7893} ) ;
You canβt perform that action at this time.
0 commit comments