[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With toJS and modular, it makes import { ... } from './data-contracts' disappeared #979

Open
leezu2020 opened this issue Nov 6, 2024 · 0 comments

Comments

@leezu2020
Copy link
leezu2020 commented Nov 6, 2024

Hi, there.

Using with toJS and modular, import { ... } from './data-contracts' is disappeared.
Without toJS, it seems to be going well.

I don't know why it's fine, doing like below.

// src/translators/javascript.ts
...
export class JavascriptTranslator extends Translator {
  ...
  translate = async (input) => {
    const compiled = this.compileTSCode(input);

    const jsFileName = `${input.fileName}${typescript.Extension.Js}`;
    const dtsFileName = `${input.fileName}${typescript.Extension.Dts}`;
    const sourceContent = compiled[jsFileName];
    const tsImportRows = input.fileContent
      .split("\n")
      .filter((line) => line.startsWith("import "));
    const declarationContent = compiled[dtsFileName]
      .split("\n")
      .map((line) => {
        // I commented out this lines.
        // if (line.startsWith("import ")) {
        //  return tsImportRows.shift();
        // }
        return line;
      })
      .join("\n");

    return [
      {
        fileName: input.fileName,
        fileExtension: typescript.Extension.Js,
        fileContent: await this.codeFormatter.formatCode(sourceContent),
      },
      {
        fileName: input.fileName,
        fileExtension: typescript.Extension.Dts,
        fileContent: await this.codeFormatter.formatCode(declarationContent),
      },
    ];
  };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant