|
3 | 3 | #include <string> |
4 | 4 | #include <map> |
5 | 5 | #include <queue> |
| 6 | +#include <stack> |
6 | 7 | #include <filesystem> |
7 | 8 | #include <optional> |
8 | 9 | #include <fstream> |
@@ -51,34 +52,42 @@ int main(int argc, char** argv) { |
51 | 52 | return 1; |
52 | 53 | } |
53 | 54 |
|
54 | | - const std::string config_file_relative_path = module_path.relative.parent_path().string(); |
| 55 | + std::filesystem::path relative_path = module_path.relative.parent_path(); |
55 | 56 |
|
56 | | - if (configs.find(config_file_relative_path) == configs.end()) { |
57 | | - Luau::Config config; |
| 57 | + if (configs.find(relative_path.string()) == configs.end()) { |
| 58 | + std::stack<std::pair<const std::string, std::optional<std::string>>> config_stack; |
| 59 | + |
| 60 | + while (true) { |
| 61 | + if ((configs.find(relative_path.string()) != configs.end())) { |
| 62 | + Luau::Config config = configs[relative_path.string()]; |
| 63 | + |
| 64 | + while (!config_stack.empty()) { |
| 65 | + const auto [path, config_file] = config_stack.top(); |
| 66 | + config_stack.pop(); |
| 67 | + |
| 68 | + if (config_file) { |
| 69 | + Luau::ConfigOptions config_option = {false, std::optional<Luau::ConfigOptions::AliasOptions>({path, true})}; |
| 70 | + std::optional<std::string> error = Luau::parseConfig(*config_file, config, config_option); |
| 71 | + |
| 72 | + if (error) throw std::runtime_error("Error parsing config: " + *error + "\n File: " + module_path.path.string()); |
| 73 | + } else { |
| 74 | + config = Luau::Config(config); |
| 75 | + } |
| 76 | + |
| 77 | + configs[path] = config; |
| 78 | + } |
58 | 79 |
|
59 | | - std::filesystem::path relative = module_path.relative.parent_path().parent_path(); |
60 | | - while (relative.string() != "/") { |
61 | | - const auto it = configs.find(relative.string()); |
62 | | - if (it != configs.end()) { |
63 | | - config = Luau::Config(it->second); |
64 | 80 | break; |
65 | | - } else { |
66 | | - relative = relative.parent_path(); |
67 | 81 | } |
68 | | - } |
69 | 82 |
|
70 | | - const std::filesystem::path config_file_path = module_path.path.parent_path() / Luau::kConfigName; |
71 | | - if (std::optional<std::string> config_file = readFile(config_file_path.string())) { |
72 | | - Luau::ConfigOptions config_option = {false, std::optional<Luau::ConfigOptions::AliasOptions>({config_file_relative_path, true})}; |
73 | | - std::optional<std::string> error = Luau::parseConfig(*config_file, config, config_option); |
| 83 | + config_stack.push({relative_path.string(), readFile((module_path.root / relative_path.relative_path() / Luau::kConfigName).string())}); |
74 | 84 |
|
75 | | - if (error) throw std::runtime_error("Error parsing config: " + *error + "\n File: " + module_path.path.string()); |
| 85 | + if (relative_path.string() == "/") configs["/"] = Luau::Config(); |
| 86 | + else relative_path = relative_path.parent_path(); |
76 | 87 | } |
77 | | - |
78 | | - configs[config_file_relative_path] = config; |
79 | 88 | } |
80 | 89 |
|
81 | | - const Luau::Config& config = configs[config_file_relative_path]; |
| 90 | + const Luau::Config& config = configs[module_path.relative.parent_path().string()]; |
82 | 91 |
|
83 | 92 | RequireFunctionLocalizerResult result = require_function_localizer(*file); |
84 | 93 | errors.insert(errors.end(), result.parse_errors.begin(), result.parse_errors.end()); |
|
0 commit comments