js_generator.h

#include <google/protobuf/compiler/js/js_generator.h>
namespace google::protobuf::compiler::js

Generates JavaScript code for a given .proto file.

Classes in this file

CodeGenerator implementation which generates a JavaScript source file and header.

struct GeneratorOptions

#include <google/protobuf/compiler/js/js_generator.h>
namespace google::protobuf::compiler::js

Members

enum
ImportStyle
What style of imports should be used. more...
enum
OutputMode
string
output_dir
Output path.
string
namespace_prefix
Namespace prefix.
bool
binary
Enable binary-format support?
enum google::protobuf::compiler::js::GeneratorOptions::ImportStyle
import_style
bool
add_require_for_enums
Add a goog.requires() call for each enum type used. more...
bool
testonly
Set this as a test-only module via goog.setTestOnly();.
string
library
Create a library with name <name>_lib.js rather than a separate .js file per type?
bool
error_on_name_conflict
Error if there are two types that would generate the same output file?
string
extension
The extension to use for output file names.
bool
one_output_file_per_input_file
Create a separate output file for each input file?
GeneratorOptions()
bool
ParseFromOptions(const std::vector< std::pair< string, string > > & options, string * error)
string
GetFileNameExtension() const
Returns the file name extension to use for generated code.
OutputMode
output_mode() const
Indicates how to output the generated code based on the provided options.

enum GeneratorOptions::ImportStyle {
  kImportClosure,
  kImportCommonJs,
  kImportBrowser,
  kImportEs6
}

What style of imports should be used.

kImportClosuregoog.require()
kImportCommonJsrequire()
kImportBrowserno import statements
kImportEs6import { member } from ''

enum GeneratorOptions::OutputMode {
  kOneOutputFilePerInputFile,
  kOneOutputFilePerType,
  kEverythingInOneFile
}

kOneOutputFilePerInputFileCreate an output file for each input .proto file.
kOneOutputFilePerTypeCreate an output file for each type.
kEverythingInOneFilePut everything in a single file named by the library option.

boolGeneratorOptions::add_require_for_enums

Add a goog.requires() call for each enum type used.

If not set, a forward declaration with goog.forwardDeclare is produced instead.

class Generator: public CodeGenerator

#include <google/protobuf/compiler/js/js_generator.h>
namespace google::protobuf::compiler::js

CodeGenerator implementation which generates a JavaScript source file and header.

If you create your own protocol compiler binary and you want it to support JavaScript output, you can do so by registering an instance of this CodeGenerator with the CommandLineInterface in your main() function.

Members

Generator()
virtual
~Generator()
virtual bool
Generate(const FileDescriptor * file, const string & parameter, GeneratorContext * generator_context, string * error) const
Generates code for the given proto file, generating one or more files in the given output directory. more...
virtual bool
HasGenerateAll() const
This is no longer used, but this class is part of the opensource protobuf library, so it has to remain to keep vtables the same for the current version of the library. more...
virtual bool
GenerateAll(const std::vector< const FileDescriptor * > & files, const string & parameter, GeneratorContext * generator_context, string * error) const
Generates code for all given proto files. more...

virtual bool Generator::Generate(
        const FileDescriptor * file,
        const string & parameter,
        GeneratorContext * generator_context,
        string * error) const

Generates code for the given proto file, generating one or more files in the given output directory.

A parameter to be passed to the generator can be specified on the command line. This is intended to be used to pass generator specific parameters. It is empty if no parameter was given. ParseGeneratorParameter (below), can be used to accept multiple parameters within the single parameter command line flag.

Returns true if successful. Otherwise, sets *error to a description of the problem (e.g. "invalid parameter") and returns false.


virtual bool Generator::HasGenerateAll() const

This is no longer used, but this class is part of the opensource protobuf library, so it has to remain to keep vtables the same for the current version of the library.

When protobufs does a api breaking change, the method can be removed.


virtual bool Generator::GenerateAll(
        const std::vector< const FileDescriptor * > & files,
        const string & parameter,
        GeneratorContext * generator_context,
        string * error) const

Generates code for all given proto files.

WARNING: The canonical code generator design produces one or two output files per input .proto file, and we do not wish to encourage alternate designs.

A parameter is given as passed on the command line, as in |Generate()| above.

Returns true if successful. Otherwise, sets *error to a description of the problem (e.g. "invalid parameter") and returns false.