Store comment at end of class in Nop statement

Fixed #509.
This commit is contained in:
Nikita Popov 2018-07-07 12:45:32 +02:00
parent df64d86cf4
commit 8b1c9c0409
7 changed files with 1776 additions and 1716 deletions

View File

@ -1,7 +1,16 @@
Version 4.0.3-dev
-----------------
### Fixed
* Fixed possible undefined offset notice in formatting-preserving printer. (#513)
### Added
* Improved error recovery inside arrays.
* Preserve trailing comment inside classes. **Note:** This change is possibly BC breaking if your
code validates that classes can only contain certain statement types. After this change, classes
can also contain Nop statements, while this was not previously possible. (#509)
Version 4.0.2 (2018-06-03)
--------------------------

View File

@ -454,11 +454,17 @@ static_var:
| plain_variable '=' static_scalar { $$ = Stmt\StaticVar[$1, $3]; }
;
class_statement_list:
class_statement_list class_statement { push($1, $2); }
class_statement_list_ex:
class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } }
| /* empty */ { init(); }
;
class_statement_list:
class_statement_list_ex
{ makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
if ($nop !== null) { $1[] = $nop; } $$ = $1; }
;
class_statement:
variable_modifiers property_declaration_list ';'
{ $$ = Stmt\Property[$1, $2]; $this->checkProperty($$, #1); }

View File

@ -522,11 +522,17 @@ static_var:
| plain_variable '=' expr { $$ = Stmt\StaticVar[$1, $3]; }
;
class_statement_list:
class_statement_list class_statement { if ($2 !== null) { push($1, $2); } }
class_statement_list_ex:
class_statement_list_ex class_statement { if ($2 !== null) { push($1, $2); } }
| /* empty */ { init(); }
;
class_statement_list:
class_statement_list_ex
{ makeNop($nop, $this->lookaheadStartAttributes, $this->endAttributes);
if ($nop !== null) { $1[] = $nop; } $$ = $1; }
;
class_statement:
variable_modifiers property_declaration_list ';'
{ $$ = Stmt\Property[$1, $2]; $this->checkProperty($$, #1); }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
Comment at end of class (#509)
-----
<?php
class MyClass {
protected $a;
// my comment
}
-----
array(
0: Stmt_Class(
flags: 0
name: Identifier(
name: MyClass
)
extends: null
implements: array(
)
stmts: array(
0: Stmt_Property(
flags: MODIFIER_PROTECTED (2)
props: array(
0: Stmt_PropertyProperty(
name: VarLikeIdentifier(
name: a
)
default: null
)
)
)
1: Stmt_Nop(
comments: array(
0: // my comment
)
)
)
)
)

View File

@ -222,6 +222,11 @@ array(
)
)
)
8: Stmt_Nop(
comments: array(
0: // __halt_compiler does not work
)
)
)
)
1: Stmt_Expression(