| 1 |
diff --git a/node_modules/wp-pot/src/parsers/php-parser.js b/node_modules/wp-pot/src/parsers/php-parser.js |
| 2 |
index c8f411d..319a5da 100644 |
| 3 |
--- a/node_modules/wp-pot/src/parsers/php-parser.js |
| 4 |
+++ b/node_modules/wp-pot/src/parsers/php-parser.js |
| 5 |
@@ -220,6 +220,32 @@ class PHPParser { |
| 6 |
return comment; |
| 7 |
} |
| 8 |
|
| 9 |
+ /** |
| 10 |
+ * Get method name from property lookup, going as deep as necessary. |
| 11 |
+ * Example: $this->plugin->text_domain->translate |
| 12 |
+ * |
| 13 |
+ * @param {object} what |
| 14 |
+ * @return {string} |
| 15 |
+ * @private |
| 16 |
+ */ |
| 17 |
+ _getMethodNameFromPropertyLookup(what) { |
| 18 |
+ let methodName = []; |
| 19 |
+ |
| 20 |
+ while(what) { |
| 21 |
+ if (what.kind === 'propertylookup') { |
| 22 |
+ methodName.push(what.offset.name); |
| 23 |
+ what = what.what; |
| 24 |
+ } else if (what.kind === 'variable') { |
| 25 |
+ methodName.push(what.name); |
| 26 |
+ what = null; |
| 27 |
+ } else { |
| 28 |
+ what = null; |
| 29 |
+ } |
| 30 |
+ } |
| 31 |
+ |
| 32 |
+ return `\$${methodName.reverse().join('->')}`; |
| 33 |
+ } |
| 34 |
+ |
| 35 |
/** |
| 36 |
* Check if ast is a valid function call |
| 37 |
* |
| 38 |
@@ -231,8 +257,8 @@ class PHPParser { |
| 39 |
if (ast.kind === 'call') { |
| 40 |
let methodName = ast.what.name; |
| 41 |
|
| 42 |
- if (ast.what.kind === 'propertylookup' && ast.what.what.kind === 'variable') { |
| 43 |
- methodName = ['$', ast.what.what.name, '->', ast.what.offset.name].join(''); |
| 44 |
+ if (ast.what.kind === 'propertylookup') { |
| 45 |
+ methodName = this._getMethodNameFromPropertyLookup(ast.what); |
| 46 |
} else if (ast.what.kind === 'name' && ast.what.resolution === 'fqn') { |
| 47 |
methodName = ast.what.name.replace(/^\\/, ''); |
| 48 |
} |
| 49 |
|