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

Make JSDoc Parsing Configurable using the transpileModule method #56625

Closed
6 tasks done
mpodwysocki opened this issue Nov 30, 2023 · 3 comments Β· Fixed by #56627
Closed
6 tasks done

Make JSDoc Parsing Configurable using the transpileModule method #56625

mpodwysocki opened this issue Nov 30, 2023 · 3 comments Β· Fixed by #56627

Comments

@mpodwysocki
Copy link
Member

πŸ” Search Terms

transpileModule jsDocParsingMode

βœ… Viability Checklist

⭐ Suggestion

In #55739 there was an addition to ts. createSourceFile which allowed to opt into parsing JSDocs, which until then had been opt-in by default. This API, however, was not added to the ts.transpileModule where the Azure SDK for JavaScript currently uses to create samples.

πŸ“ƒ Motivating Example

We currently use the TypeScript compiler to parse our TypeScript files to convert them to JavaScript such as the following:

  const output = ts.transpileModule(processedSrcText, {
    compilerOptions: {
      ...compilerOptions,
      ...extraCompilerOptions,
      removeComments: false,
    },
    ...transpileOptions,
  });

Upgrading to 5.3 from 5.2 caused us to lose our JSDoc comments as opting into JSDoc parsing is hard coded in this case to not include them. The ideal solution would be to do the following to add the jsDocParsingMode to the TranspileOptions such as the tollowing:

transpileOptions.jsDocParsingMode = ts.JSDocParsingMode.ParseAll;

πŸ’» Use Cases

  1. What do you want to use this for? This is used as part of our workflow convert our existing samples from TypeScript to JavaScript and retain all of our JSDocs from TypeScript to apply to JavaScript.
  2. What shortcomings exist with current approaches? With 5.3, we no longer have the ability to read these comments through the ts.transpileModule method as it is hard coded to ts.JSDocParsingMode.ParseNone
  3. What workarounds are you using in the meantime? None as we cannot upgrade to TypeScript 5.3 unless this option is introduced.
@andrewbranch
Copy link
Member

Note to maintainers: the thing that makes this relevant to ts.tranpileModule is the fact that custom transformers can be passed in, which see the parse tree. It was probably omitted from this API because the basic usage is just text in, text out.

@jakebailey
Copy link
Member

jakebailey commented Dec 1, 2023

Reading the above implies that the JSDoc was actually removed from the output JS code; my intention was that it was safe to pass ParseNone here because that would mean that we skipped actually parsing the nodes themselves and they'd just be regular comments that were output like non-jsdoc comments. Is that not the case? Or are you actually using transformers somehow in the above? (You didn't say one way or the other.)

@andrewbranch
Copy link
Member

andrewbranch commented Dec 1, 2023

The issue isn't about emit at all; Azure is doing some fancy stuff with reading JSDoc nodes in transformers. (This issue was filed at my request after offline discussion)

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

Successfully merging a pull request may close this issue.

3 participants