Skip to content

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

Merged
merged 5 commits into from
Sep 26, 2016

Conversation

yuit
Copy link
Contributor

@yuit yuit commented Sep 23, 2016

@sandersn this is my restructure of the AST hierarchy to support spread in JSXAttributes essentially JsxAttributes will take the following form

export interface JsxAttributes extends ObjectLiteralExpressionBase<JsxAttributeLike> {
        _jsxAttributesBrand: any;
}

Kanchalai Tanglertsampan added 2 commits September 23, 2016 15:50
…utes to extend from.

Create ObjectLiteralElementLike and make ObjectLiteralElement become union type of all possible type allow in PropertyDefinition
@@ -316,6 +316,7 @@ namespace ts {
// Property assignments
PropertyAssignment,
ShorthandPropertyAssignment,
SpreadObjectLiteralAssignment,
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Member

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.
Copy link
Member

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
Copy link
Member

@DanielRosenwasser DanielRosenwasser Sep 24, 2016

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"?

Copy link
Contributor Author

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

Copy link
Member

@sandersn sandersn left a 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
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this optional?

Copy link
Contributor Author

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;
Copy link
Member

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?

Copy link
Member

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,
Copy link
Member

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,
Copy link
Member

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.

@yuit yuit merged commit 3d92117 into master Sep 26, 2016
@yuit yuit deleted the restructureASTToParseReactAttributesAsObjectLiteral branch September 26, 2016 22:12
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants