|
1 | 1 | import type { PHPRegistree } from "../registree/index.ts"; |
2 | 2 | import { type PHPFile, type PHPNode, SymbolNode } from "../registree/types.ts"; |
3 | 3 | import type { PHPImports } from "./types.ts"; |
4 | | -import { |
5 | | - PHP_INCLUDE_QUERY, |
6 | | - PHP_USE_DETECTION_QUERY, |
7 | | - PHP_USE_QUERY, |
8 | | -} from "./queries.ts"; |
| 4 | +import { PHP_INCLUDE_QUERY, PHP_USE_DETECTION_QUERY } from "./queries.ts"; |
9 | 5 | import type Parser from "tree-sitter"; |
10 | | -import { dirname } from "@std/path"; |
| 6 | +import { dirname, join } from "@std/path"; |
11 | 7 |
|
12 | 8 | export class PHPIncluseResolver { |
13 | 9 | registree: PHPRegistree; |
@@ -57,19 +53,17 @@ export class PHPIncluseResolver { |
57 | 53 | }, |
58 | 54 | }; |
59 | 55 | for (const use of useDirectives) { |
60 | | - const useClause = PHP_USE_QUERY.captures(use.node); |
61 | | - if (!useClause) continue; |
62 | 56 | let name: string | undefined = undefined; |
63 | 57 | let node: PHPNode | undefined = undefined; |
64 | | - for (const clause of useClause) { |
65 | | - if (clause.name === "alias") { |
66 | | - name = clause.node.text; |
| 58 | + for (const clause of use.node.namedChildren) { |
| 59 | + if (clause.type === "namespace_aliasing_clause") { |
| 60 | + name = clause.text; |
67 | 61 | } else { |
68 | | - node = this.registree.tree.findNode(clause.node.text); |
| 62 | + node = this.registree.tree.findNode(clause.text); |
69 | 63 | if (node && !name) { |
70 | 64 | name = node.name; |
71 | 65 | } else if (!node && !name) { |
72 | | - name = clause.node.text; |
| 66 | + name = clause.text; |
73 | 67 | } |
74 | 68 | } |
75 | 69 | } |
@@ -136,11 +130,11 @@ export class PHPIncluseResolver { |
136 | 130 | imports.unresolved.paths.push(path); |
137 | 131 | } |
138 | 132 | } else if (include.name === "includebin") { |
139 | | - const filepath = this.#splitBinary(include.node) |
| 133 | + const fileparts = this.#splitBinary(include.node) |
140 | 134 | .map((n) => n.text === "__DIR__" ? dirname(file.path) : n.text) |
141 | 135 | .filter((n) => n !== "") |
142 | | - .map((n) => n.replace(/['"]/g, "")) |
143 | | - .join("/"); |
| 136 | + .map((n) => n.replace(/['"]/g, "")); |
| 137 | + const filepath = join(fileparts[0], ...fileparts.slice(1)); |
144 | 138 | const importedfile = this.registree.registry.getFile( |
145 | 139 | filepath, |
146 | 140 | file.path, |
|
0 commit comments