You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by endel <gi...@git.apache.org> on 2016/06/10 14:48:22 UTC

[GitHub] thrift issue #488: THRIFT-3143

Github user endel commented on the issue:

    https://github.com/apache/thrift/pull/488
  
    Thanks for your work @wilfrem. I think this pull-request should be reviewed and maybe accepted, since JavaScript is evolving so fast - which makes the current JavaScript/Node generators unusable in modern build tools for the browser, for example. Having a TypeScript generator could solve this problem.
    
    I did some changes in the `import` section, which seems to be broken in the current version. Here's the patch to import the actual references needed:
    
    ```patch
    diff --git a/compiler/cpp/src/generate/t_ts_generator.cc b/compiler/cpp/src/generate/t_ts_generator.cc
    index 2100f7f..44fbeb5 100644
    --- a/compiler/cpp/src/generate/t_ts_generator.cc
    +++ b/compiler/cpp/src/generate/t_ts_generator.cc
    @@ -343,9 +341,36 @@ string t_ts_generator::render_includes() {
       if (gen_node_) {
         const vector<t_program*>& includes = program_->get_includes();
         for (size_t i = 0; i < includes.size(); ++i) {
    -      result += "import " + includes[i]->get_name() + "_ttypes = require('./" + includes[i]->get_name()
    -                + "_types')\n";
    +
    +      // Import all exposed enums/structs/types from defined module
    +      std::vector<std::string> imports;
    +
    +      const std::vector<t_typedef*>& typedefs = includes[i]->get_typedefs();
    +      for (size_t j = 0; j < typedefs.size(); ++j) {
    +        imports.push_back(typedefs[j]->get_type()->get_name());
    +      }
    +
    +      const std::vector<t_enum*>& enums = includes[i]->get_enums();
    +      for (size_t j = 0; j < enums.size(); ++j) {
    +        imports.push_back(enums[j]->get_name());
    +      }
    +
    +      const std::vector<t_struct*>& structs = includes[i]->get_structs();
    +      for (size_t j = 0; j < structs.size(); ++j) {
    +        imports.push_back(structs[j]->get_name());
    +      }
    +
    +      std::stringstream modules;
    +      for(size_t j = 0; j < imports.size(); ++j)
    +      {
    +        if(j != 0)
    +          modules << ", ";
    +        modules << imports[j];
    +      }
    +
    +      result += "import { " + modules.str() + " } from './" + includes[i]->get_name() + ".ts'\n";
         }
    +
         if (includes.size() > 0) {
           result += "\n";
         }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---