You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brian Terlson (@bterlson), who found this bug, suggests just skipping asterisks everywhere in the type parser which might work if we really never think that types will have asterisks in them.
The symptom may be the same, but the cause is different #23517 is failure to skip asterisks inside (unrecognised) tag text, whereas this bug is a failure to skip asterisks inside a type. The fix will be different since (1) whitespace is still important in the text case (2) the jsdoc lexer and parser are used for the text case. Neither is true for the type parser.
See also #26067. As mentioned there, it seems like it would be easier to group the asterisk together with the newline/whitespace trivia while scanning (and set a scanner flag about the linebreak).
It feels like this could be implemented with a relatively minor change - if it were possible to differentiate between scanning a comment and scanning code:
diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts
index 61ce8330bf..71541f356c 100644
--- a/src/compiler/scanner.ts+++ b/src/compiler/scanner.ts@@ -1447,6 +1447,10 @@ namespace ts {
return pos += 2, token = SyntaxKind.AsteriskAsteriskToken;
}
pos++;
+ if (skipTrivia && (tokenFlags & TokenFlags.PrecedingLineBreak)) {+ // decoration at the start of a JSDoc comment line+ continue;+ }
return token = SyntaxKind.AsteriskToken;
case CharacterCodes.plus:
if (text.charCodeAt(pos + 1) === CharacterCodes.plus) {
This change fixes comment parsing but breaks code parsing (generator methods and any other multiline expression where the line starts with a *). It may also break the indent handling when parsing comments.
So far I don't see an easy way to skip * after newline only while parsing JSDoc types - it feels like there are too many branches of the type parsing to cover.
Nathan Shively-Sanders (@sandersn) - any thoughts on how to provide the scanner with more context (similar to skipTrivia)? Or any other ideas?
In case the "provide the scanner with more context" idea sounds like a good one, I've pushed up a branch that makes things work with multi-line JSDoc types in #26528.
Activity
sandersn commentedon Apr 24, 2018
Brian Terlson (@bterlson), who found this bug, suggests just skipping asterisks everywhere in the type parser which might work if we really never think that types will have asterisks in them.
mhegazy commentedon Apr 25, 2018
looks like a duplicate of #23517
sandersn commentedon Apr 26, 2018
The symptom may be the same, but the cause is different #23517 is failure to skip asterisks inside (unrecognised) tag text, whereas this bug is a failure to skip asterisks inside a type. The fix will be different since (1) whitespace is still important in the text case (2) the jsdoc lexer and parser are used for the text case. Neither is true for the type parser.
tschaub commentedon Aug 6, 2018
See also #26067. As mentioned there, it seems like it would be easier to group the asterisk together with the newline/whitespace trivia while scanning (and set a scanner flag about the linebreak).
tschaub commentedon Aug 18, 2018
It feels like this could be implemented with a relatively minor change - if it were possible to differentiate between scanning a comment and scanning code:
This change fixes comment parsing but breaks code parsing (generator methods and any other multiline expression where the line starts with a
*). It may also break the indent handling when parsing comments.So far I don't see an easy way to skip
*after newline only while parsing JSDoc types - it feels like there are too many branches of the type parsing to cover.Nathan Shively-Sanders (@sandersn) - any thoughts on how to provide the scanner with more context (similar to
skipTrivia)? Or any other ideas?tschaub commentedon Aug 18, 2018
In case the "provide the scanner with more context" idea sounds like a good one, I've pushed up a branch that makes things work with multi-line JSDoc types in #26528.
tschaub commentedon Sep 2, 2018
All tests are now passing on #26528. I've also added cases to demonstrate that #26846 is fixed by the same.