(expr, context)
| 22370 | } |
| 22371 | |
| 22372 | target(expr, context) { |
| 22373 | const ast = this.ast; |
| 22374 | let current = expr; |
| 22375 | let path = []; |
| 22376 | for (;;) { |
| 22377 | if (current instanceof ast.Attribute) { |
| 22378 | path.push(current.attr); |
| 22379 | current = current.value; |
| 22380 | } else if (current instanceof ast.Name && current.id !== 'self' && current.id !== 'CONSTANTS') { |
| 22381 | path.push(current.id); |
| 22382 | break; |
| 22383 | } else { |
| 22384 | path = null; |
| 22385 | break; |
| 22386 | } |
| 22387 | } |
| 22388 | if (path) { |
| 22389 | let target = null; |
| 22390 | for (let i = path.length - 1; i >= 0; i--) { |
| 22391 | const name = path[i]; |
| 22392 | if (target) { |
| 22393 | target = target.__getattr__ ? target.__getattr__(name) : target[name]; |
| 22394 | } else { |
| 22395 | target = context.get(name); |
| 22396 | } |
| 22397 | if (!target) { |
| 22398 | break; |
| 22399 | } |
| 22400 | } |
| 22401 | if (!target) { |
| 22402 | path.reverse(); |
| 22403 | const name = path.join('.'); |
| 22404 | const file = `${path.join('/')}.py`; |
| 22405 | if (this._sources.has(file)) { |
| 22406 | target = this.import(name); |
| 22407 | } else { |
| 22408 | target = this.resolve(name); |
| 22409 | } |
| 22410 | } |
| 22411 | return target; |
| 22412 | } |
| 22413 | return this.expression(expr, context); |
| 22414 | } |
| 22415 | |
| 22416 | add(name, source) { |
| 22417 | this._sources.set(name, source); |
no test coverage detected