-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
fix: Types containing comments generate invalid code #14762
fix: Types containing comments generate invalid code #14762
Conversation
|
||
if (node.returnType) { | ||
if (node.type === "ArrowFunctionExpression") { | ||
this._noLineTerminator = true; | ||
this.print(node.returnType, node); | ||
this._noLineTerminator = false; | ||
} else { | ||
this.print(node.returnType, node); | ||
} | ||
} | ||
this.print(node.returnType, node); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted here #14758.
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/52517/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be enough to disallow a line terminator in the following positions:
- After the
returnType
of anArrowFunctionExpression
- After the
typeName
of aTSTypeReference
withparams
- After the
elementType
of aTSArrayType
- After the
objectType
of aTSIndexedAccessType
Also, could you add these generator tests with retainLines: true
?
type T = U.
/* 1 */
C /* 2 */ [
/* 3 */
0];
type T = U.
/* 1 */
C /* 2 */ [
/* 3 */
];
type T = U.
/* 1 */
C /* 2 */ <
/* 3 */
0>;
let f = (x)
/* 1 */
:
/* 2 */
void /* 3 */ => 1
There seem to be two ways, one is like #14758 and the other is using |
I prefer the #14758 approach, since it lets us get a "better" output where we can print newlines. The flow rules are the same, except that the AST nodes are |
|
||
type T2 = U. | ||
/* 1 */ | ||
C /* 2 */[]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a bug here.
update: maybe not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the /* 3 */
comment should be printed somewhere. It's a bug that we already have regardless of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
TypeAnnotation
with comments generates incorrect code
This PR also contains some very minor performance optimizations.