branch: externals/phps-mode
commit 30e9fa14ff3666106d0c7b2c42495e16ac539348
Author: Christian Johansson <[email protected]>
Commit: Christian Johansson <[email protected]>
Added a failing bookkeeping test
---
phps-mode-ast-bookkeeping.el | 20 +++++++++++++++++++-
test/phps-mode-test-ast.el | 7 ++++++-
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/phps-mode-ast-bookkeeping.el b/phps-mode-ast-bookkeeping.el
index e0b7ec01b7..7f314eb05a 100644
--- a/phps-mode-ast-bookkeeping.el
+++ b/phps-mode-ast-bookkeeping.el
@@ -862,7 +862,25 @@
(cond
((equal member-type 'simple-variable)
- (let ((sub-scope (cdr scope)))
+ ;; When current scope is arrow function
+ ;; we should go up in scope until we get out of
+ ;; arrow functions scope
+ (let ((sub-scope scope)
+ (head-scope)
+ (is-arrow-function-scope t))
+ (while (and
+ sub-scope
+ is-arrow-function-scope)
+ (setq
+ head-scope
+ (car sub-scope))
+ (setq
+ sub-scope
+ (cdr sub-scope))
+ (unless (equal
+ (plist-get head-scope 'type)
+ 'arrow-function)
+ (setq is-arrow-function-scope nil)))
(push '(type static) sub-scope)
(let ((predefined)
(variable-ids
diff --git a/test/phps-mode-test-ast.el b/test/phps-mode-test-ast.el
index 1f223b9484..c46ebc41c4 100644
--- a/test/phps-mode-test-ast.el
+++ b/test/phps-mode-test-ast.el
@@ -404,12 +404,17 @@
"Bookkeeping of $this not available inside static method"
'(((68 73) 0) (" class MyClass function there id $this" 1) ((153 158) 1)))
- ;; TODO Make this test pass
(phps-mode-test-ast--should-bookkeep
"<?php\n\nclass myClass\n{\n private $test = 'abc';\n public function
test($d)\n {\n return fn($e) => $this->test . $d . $e;\n
}\n}\n\n$a = new myClass();\necho $a->test('def')('ghi');"
"Bookkeeping of $this reference inside arrow function inside of method"
'((" class myClass id $test" 1) ((36 41) 1) (" class myClass function test
id $this" 1) (" class myClass function test id $d" 1) ((76 78) 1) (" class
myClass function test arrow function 1 id $e" 1) ((104 106) 1) ((111 116) 1)
((118 122) 1) ((125 127) 1) ((130 132) 1) (" id $a" 1) ((143 145) 1)))
+ ;; TODO Make this test pass
+ (phps-mode-test-ast--should-bookkeep
+ "<?php class myClass { static $var = '123'; static function myMethod($a) {
return fn($b) => self::$var . $a . $b; }} echo myClass::myMethod('4')('5');"
+ "Bookkeeping of self reference inside arrow function inside of static
method"
+ '((" class myClass id $var" 1) ((30 34) 1) (" class myClass function
myMethod id $a" 1) ((69 71) 1) (" class myClass function myMethod arrow
function 1 id $b" 1) ((85 87) 1) ((98 102) 1) ((105 107) 1) ((110 112) 1)))
+
(message "\n-- Ran tests for bookkeeping generation. --"))
(defun phps-mode-test-ast ()