mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-12 07:50:59 +00:00
[TS] Fix relative paths for exports (#8517)
Fixes an issue where exports were using incorrect relative paths for >=3 namespace levels. This is fixed by making the starting range of the namespace components relative to the amount of components. Co-authored-by: Björn Harrtell <bjornharrtell@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
b8db3a9a6a
commit
00eec2445b
@@ -263,14 +263,9 @@ class TsGenerator : public BaseGenerator {
|
||||
for (const auto &def : it.second.definitions) {
|
||||
std::vector<std::string> rel_components;
|
||||
// build path for root level vs child level
|
||||
if (it.second.ns->components.size() > 1)
|
||||
std::copy(it.second.ns->components.begin() + 1,
|
||||
it.second.ns->components.end(),
|
||||
std::back_inserter(rel_components));
|
||||
else
|
||||
std::copy(it.second.ns->components.begin(),
|
||||
it.second.ns->components.end(),
|
||||
std::back_inserter(rel_components));
|
||||
if (it.second.ns->components.size() > 0) {
|
||||
rel_components.push_back(it.second.ns->components.back());
|
||||
}
|
||||
auto base_file_name =
|
||||
namer_.File(*(def.second), SkipFile::SuffixAndExtension);
|
||||
auto base_name =
|
||||
@@ -303,8 +298,12 @@ class TsGenerator : public BaseGenerator {
|
||||
if (it2.second.ns->components.size() != child_ns_level) continue;
|
||||
auto ts_file_path = it2.second.path + ".ts";
|
||||
code += "export * as " + it2.second.symbolic_name + " from './";
|
||||
std::string rel_path = it2.second.path;
|
||||
code += rel_path + ".js';\n";
|
||||
int count = it2.second.ns->components.size() > 1 ? 2 : 1;
|
||||
std::vector<std::string> rel_path;
|
||||
std::copy(it2.second.ns->components.end() - count,
|
||||
it2.second.ns->components.end(),
|
||||
std::back_inserter(rel_path));
|
||||
code += namer_.Directories(rel_path, SkipDir::OutputPathAndTrailingPathSeparator) + ".js';\n";
|
||||
export_counter++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user