Skip to content

Commit

Permalink
[TS] Fix relative paths for exports
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Truman Mulholland authored and trumully committed Feb 3, 2025
1 parent 0312061 commit c533489
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/idl_gen_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ 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,
if (it.second.ns->components.size() > 0)
std::copy(it.second.ns->components.begin() + it.second.ns->components.size() - 1,
it.second.ns->components.end(),
std::back_inserter(rel_components));
else
Expand Down
7 changes: 7 additions & 0 deletions tests/long_namespace.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace com.company.test;

table Person {
name:string;
age:short;
}
root_type Person;
7 changes: 7 additions & 0 deletions tests/longer_namespace.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace longer_namespace.a.b.c;

table Person {
name:string;
age:short;
}
root_type Person;
8 changes: 8 additions & 0 deletions tests/ts/TypeScriptTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ def esbuild(input, output):
schema="../union_underlying_type_test.fbs"
)

flatc(options=["--ts"], schema="../long_namespace.fbs")
esbuild("./long-namespace/com/company.ts", "./long-namespace/long_namespace_generated.cjs")

flatc(options=["--ts"], schema="../longer_namespace.fbs")
esbuild(
"./longer-namespace/a/b/c.ts", "./longer-namespace/longer_namespace_generated.cjs"
)

print("Running TypeScript Compiler...")
check_call(["tsc"])
print("Running TypeScript Compiler in old node resolution mode for no_import_ext...")
Expand Down
4 changes: 3 additions & 1 deletion tests/ts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"namespace_test/**/*.ts",
"union_vector/**/*.ts",
"arrays_test_complex/**/*.ts",
"union_underlying_type_test.ts"
"union_underlying_type_test.ts",
"long-namespace/**/*.ts",
"longer-namespace/**/*.ts"
]
}

0 comments on commit c533489

Please sign in to comment.