[ 
https://issues.apache.org/jira/browse/THRIFT-3143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15324557#comment-15324557
 ] 

ASF GitHub Bot commented on 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";
         }
    ```


> add typescript directory support
> --------------------------------
>
>                 Key: THRIFT-3143
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3143
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Node.js - Compiler
>            Reporter: Kazuki Yasufuku
>
> Current typescript support is only work for browser, and generated d.ts uses 
> internal module.
> So, it's hard to use for typescript in node.js.
> To solve probrem, I make a pull request that generate typescript code 
> directory.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to