8000 Start to attempt to rework how references to imported types work. · reddaly/protobuf-javascript@a90de85 · GitHub
[go: up one dir, main page]

Skip to content

Commit a90de85

Browse files
committed
Start to attempt to rework how references to imported types work.
1 parent e7e3a45 commit a90de85

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

generator/js_generator.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ std::string ModuleAlias(const std::string& filename) {
152152
// file descriptor's package.
153153
std::string GetNamespace(const GeneratorOptions& options,
154154
const FileDescriptor* file) {
155+
if (options.import_style == GeneratorOptions::kImportEs6) {
156+
std::string dotSeparated = "proto." + file->package();
157+
// Use $ because it's not valid in proto package names
158+
// (https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#identifiers).
159+
// If we used _, "foo.a_b" would be equivalent to "foo.a.b".
160+
ReplaceCharacters(&dotSeparated, ".", '$');
161+
return dotSeparated;
162+
}
163+
155164
if (!options.namespace_prefix.empty()) {
156165
return options.namespace_prefix;
157166
} else if (!file->package().empty()) {
@@ -3839,10 +3848,13 @@ void Generator::GenerateFile(const GeneratorOptions& options,
38393848

38403849
// Generate "require" statements.
38413850
if (options.import_style == GeneratorOptions::kImportEs6) {
3851+
printer->Print("import jspb from \"google-protobuf\";\n");
3852+
38423853
for (int i = 0; i < file->dependency_count(); i++) {
38433854
const std::string& name = file->dependency(i)->name();
38443855
printer->Print(
3845-
"// TODO: import {used types here} from \"$file$\";\n",
3856+
"import * as $alias$ from \"$file$\";\n",
3857+
"alias", ModuleAlias(name),
38463858
"file", GetRootPath(file->name(), name) + GetJSFilename(options, name));
38473859
}
38483860

0 commit comments

Comments
 (0)
0