@@ -152,6 +152,15 @@ std::string ModuleAlias(const std::string& filename) {
152
152
// file descriptor's package.
153
153
std::string GetNamespace (const GeneratorOptions& options,
154
154
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
+
155
164
if (!options.namespace_prefix .empty ()) {
156
165
return options.namespace_prefix ;
157
166
} else if (!file->package ().empty ()) {
@@ -3839,10 +3848,13 @@ void Generator::GenerateFile(const GeneratorOptions& options,
3839
3848
3840
3849
// Generate "require" statements.
3841
3850
if (options.import_style == GeneratorOptions::kImportEs6 ) {
3851
+ printer->Print (" import jspb from \" google-protobuf\" ;\n " );
3852
+
3842
3853
for (int i = 0 ; i < file->dependency_count (); i++) {
3843
3854
const std::string& name = file->dependency (i)->name ();
3844
3855
printer->Print (
3845
- " // TODO: import {used types here} from \" $file$\" ;\n " ,
3856
+ " import * as $alias$ from \" $file$\" ;\n " ,
3857
+ " alias" , ModuleAlias (name),
3846
3858
" file" , GetRootPath (file->name (), name) + GetJSFilename (options, name));
3847
3859
}
3848
3860
0 commit comments