Add what a file declares. The first declaration of a name stands.
(file: string, source: string, aliases: Map<string, string>)
| 26 | |
| 27 | /** Add what a file declares. The first declaration of a name stands. */ |
| 28 | function addNamespaceAliases(file: string, source: string, aliases: Map<string, string>): void { |
| 29 | // (Few files declare one, and this looks for it without looking at every line.) |
| 30 | if (!CPP_NS_ALIAS_FILE.test(file) || !/\bnamespace[ \t]+\w+[ \t]*=/.test(source)) return; |
| 31 | for (const m of source.matchAll(/^[ \t]*namespace[ \t]+([A-Za-z_]\w*)[ \t]*=[ \t]*(?:::)?([A-Za-z_][\w:]*)[ \t]*;/gm)) { |
| 32 | if (!aliases.has(m[1]!)) aliases.set(m[1]!, m[2]!); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** The project's namespace aliases: `namespace py = pybind11;`. */ |
| 37 | export function cppNamespaceAliases(context: ResolutionContext): Map<string, string> { |
no test coverage detected