Skip to content

Fix jsdoc comment parsing initial state #36661

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

Merged
merged 3 commits into from
Feb 7, 2020

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Feb 6, 2020

Jsdoc comment parsing can be invoked in two modes:

  1. top-level parsing, for comments not inside a tag.
  2. tag parsing, for comments that occur after the semantic parts of a tag.

Top-level parsing skips an initial * because it assumes that it is starting at the very beginning of a JSDoc comment. Tag parsing does not.

The two modes are distinguished by an optional second parameter named margin. When margin is provided, it provides an initial indent used for comment alignment.

Previously, the check for margin was a truthy check if (margin).
This check incorrectly treats margin="" the same as margin=undefined.

This PR changes the check to if (margin !== undefined), which correctly treats margin="" the same as margin=" ". Since the start state would now be SaveComments much more often, it also changes the start state of comment parsing to SawAsterisk, so that initial whitespace is ignored. SavingComments retains all text, which is a breaking change (though perhaps a desirable one, but I'm not going to fix it here.)

Fixes #21402

Jsdoc comment parsing can be invoked in two modes:

1. top-level parsing, for comments not inside a tag.
2. tag parsing, for comment that occur after the semantic parts of a
tag.

Top-level parsing skips an initial * because it assumes that it is starting
at the very beginning of a JSDoc comment. Tag parsing does not.

The two modes are distinguished by an optional second parameter named
`margin`. When `margin` is provided, it provides an initial indent used
for comment alignment.

Previously, the check for `margin` was a truthy check `if (margin)`.
This check incorrectly treats `margin=""` the same as
`margin=undefined`.

This PR changes the check to `if (margin !== undefined)`, which
correctly treats `margin=""` the same as `margin="    "`.
1. Use SawAsterisk start state.
2. @template needs to skip asterisk in addition to whitespace while
parsing type parameter names.
@sandersn sandersn merged commit 1e48cbe into master Feb 7, 2020
@sandersn sandersn deleted the fix-comment-parsing-initial-state branch February 7, 2020 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSDoc tag comment parsing skips initial asterisk
3 participants