-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Restructure ast to parse react attributes as object literal #11114
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
Restructure ast to parse react attributes as object literal #11114
Conversation
…utes to extend from. Create ObjectLiteralElementLike and make ObjectLiteralElement become union type of all possible type allow in PropertyDefinition
…ObjectLiteralExpression.
@@ -316,6 +316,7 @@ namespace ts { | |||
// Property assignments | |||
PropertyAssignment, | |||
ShorthandPropertyAssignment, | |||
SpreadObjectLiteralAssignment, |
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's already a SpreadElementExpression
used for array spread elements - is it possible we can use that?
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 thought about it. but i think it is may be more confused to do., @sandersn is putting up PR for spread operator, will see how he handle it over there
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 we still need this kind, but I think SpreadElement is a better name.
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.
Actually, I'll swap the name of the existing SpreadElementExpression with this in my PR, and you can just drop this change for now.
@@ -1048,10 +1057,16 @@ namespace ts { | |||
expression: Expression; | |||
} | |||
|
|||
// The reason we create this interface so that JSXAttributes and ObjectLiteralExpression interface can extend out of it. |
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.
JSDoc?
@@ -1048,10 +1057,16 @@ namespace ts { | |||
expression: Expression; | |||
} | |||
|
|||
// The reason we create this interface so that JSXAttributes and ObjectLiteralExpression interface can extend out of it. | |||
// JSXAttributes differs from normal ObjectLiteralExpression in that JSXAttributes can only take JSXAttribute or JSXSpreadAttribute |
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.
differs -> differ
Add an 's' to the end of ObjectLiteralExpression
, JSXAttribute
, JSXSpreadAttribute
, etc.
What do you mean by "take"?
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.
JSXAttributes
is like objectLiteralExpression
but its properties can only be JSXAttribute
or JSXSpreadAttribute
. I will clarify
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.
Looks mostly good but (1) I don't understand the new type ObjectLiteralElementLike
and (2) I need to think about Daniel's comment on SpreadElementExpression.
@@ -1048,10 +1057,19 @@ namespace ts { | |||
expression: Expression; | |||
} | |||
|
|||
/** | |||
* This interface is a base interface for ObjectLiteralExpression and JSXAttributes to extend from. JSXAttributes is similar to |
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 guess JSXAttributes
isn't in this change?
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.
Yep
* JSXAttribute or JSXSpreadAttribute. ObjectLiteralExpression, on the other hand, can only have properties of type | ||
* ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) | ||
**/ | ||
export interface ObjectLiteralExpressionBase<T extends ObjectLiteralElementLike> extends PrimaryExpression, Declaration { |
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.
this name seems weird when used with its type parameter: ObjectLiteralExpressionBase<ObjectLiteralElement>
. I would prefer a more generic name instead of the suffix Base
, maybe LiteralExpression
? LiteralExpression<ObjectLiteralElement>
and LiteralExpression<JSXAttribute | JSXSpreadAttribute>
looks more reasonable.
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.
As we talked off-line, the name LiteralExpression
can be confused with stringLiteral
or numericLiteral
. I will keep this name for now and if we decide to change, it can be done pretty easily
// @kind(SyntaxKind.SpreadObjectLiteralAssignment) | ||
export interface SpreadObjectLiteralAssignment extends ObjectLiteralElementLike, SpreadElementExpression { | ||
_spreadObjectLiteralAssignmentBrand: any; | ||
dotDotDotToken?: 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.
why is this optional?
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 though you will need in your spread-operator. I was wrong -> remove
_objectLiteralBrandBrand: any; | ||
name?: PropertyName; | ||
} | ||
|
||
export type ObjectLiteralElement = PropertyAssignment | ShorthandPropertyAssignment | SpreadObjectLiteralAssignment | MethodDeclaration | AccessorDeclaration; |
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 don't understand the addition of ObjectLiteralElementLike
plus this type. Why is it split now?
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.
From our in-person discussion, this is to capture JSX-based types later.
Also, we decided to swap the -Like/no-Like names.
@@ -316,6 +316,7 @@ namespace ts { | |||
// Property assignments | |||
PropertyAssignment, | |||
ShorthandPropertyAssignment, | |||
SpreadObjectLiteralAssignment, |
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 we still need this kind, but I think SpreadElement is a better name.
@@ -316,6 +316,7 @@ namespace ts { | |||
// Property assignments | |||
PropertyAssignment, | |||
ShorthandPropertyAssignment, | |||
SpreadObjectLiteralAssignment, |
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.
Actually, I'll swap the name of the existing SpreadElementExpression with this in my PR, and you can just drop this change for now.
…itearlElementLike as a type alias
@sandersn this is my restructure of the AST hierarchy to support spread in JSXAttributes essentially JsxAttributes will take the following form