-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
docgen: remove doctrine #18045
Comments
Some notes:
The plan would be to update the |
Relevant to this is the research I did at the time on doctrine alternatives (see comment on Feb 22): #13329 (comment) |
I started exploring this, initially aiming to use This is about as far as I got with the implementation, but while it technically passes the unit tests, it fails in creating identical documentation for many of the packages for the above reason: (Click to expand
|
Relevant documentation: https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API Notable here is to feed a source string into var ts = require( 'typescript' );
ts.createSourceFile( '', '/**\n * Function description.\n *\n * @param {string} myVariable My variable description.\n */', ts.ScriptTarget.ES2015 ); ASTExplorer also has a TypeScript mode for exploring the AST: https://astexplorer.net/#/gist/34e05c635ea8a8904a4d557afc9dccc8/04f2263c5748d52b7a523809ace596e7f6e31e5e It's includes full parsing of the JSDoc, including types. |
Noting: While the TypeScript parser does parse the complex types, we will need to make sure we can print those in a meaningful way. Rolling something custom here could become very hairy very quickly, given the full scope of supported types. VSCode actually evaluates this very nicely: Ideally we can reuse this for our own documented output. I've found a little bit of a lead in the TypeScript Compiler API documentation, though the documentation is far from exhaustive. Specifically, we may be able to use parts of the "Using the Type Checker" section: https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API#using-the-type-checker let program = ts.createProgram(fileNames, options);
// ...
let checker = program.getTypeChecker();
// ...
checker.typeToString( checker.getTypeOfSymbolAtLocation( /* ... */ ) ); |
Even without a complete substitution of Doctrine, we probably need to find a way to address some of the current problems with the types printing sooner than later. Specifically, we are seeing many instances that For example, see also: #19520 |
Interim fix proposed at #19571 |
One other possible advantage of using the TypeScript compiler is more in how we already use a different parser (Espree) than that which runs over our own code (Babel). This hasn't been much of an issue thus far, but I just encountered my first issue where a particularly new syntax that we we support through Babel (ES2019 optional catch binding) will throw an error when running export function isURL( url ) {
try {
new URL( url );
return true;
} catch {
return false;
}
}
Using TypeScript doesn't really address the underlying issue that we have different parsers being used, but we could perhaps assume the TypeScript would be more up-to-date. Alternatively (and as an interim solution), it might just be a matter of keeping the |
This is unfortunately not as simple as it might seem, since one of the breaking changes introduced in One thing I noted in the process of this is that we configure the ECMAScript version here: gutenberg/packages/docgen/src/engine.js Line 15 in 1fb3c38
This is particularly relevant for my previous comment where I mention being unable to use ES2019 features. It's pretty clear by this code why this wouldn't be expected to work 😄 I haven't tested yet, but it's possible that Espree versions prior to the breaking 5.0 version might have support for newer versions of ECMAScript, so that we could still use those language features without bumping to the latest Espree version. |
I'm working on this with #19952. |
doctrine
is the JSDoc parser we use indocgen
to get structured information out of the JSDoc comments. It was created and maintained by the ESLint people, although it's no longer actively developed. We should migrate out ofdoctrine
for that reason.The suggested replacement (eslint-plugin-jsoc) uses a different JSDoc parser with support for many other syntaxes (typescript, etc). We should look into trying
jsdoctypeparser
or any other that's actively developed.The text was updated successfully, but these errors were encountered: