Replies: 1 comment 7 replies
-
FYI Marko's parser handles this but in a way that supports the vast majority of JS/TS expressions as attributes, mostly the only cases that our parser would not treat as an expression is when it conflicts with the html syntax, eg It works by maintaining a stack for enclosed sections (think string literals, brackets, regexps) and then outside of any enclosed thing using a regex that will match TS/JS binary and unary operators (https://github.com/marko-js/htmljs-parser/blob/main/src/states/EXPRESSION.ts#L214-L235) You can see the types of values that can be expressions in our test snapshot here: https://github.com/marko-js/htmljs-parser/blob/main/src/__tests__/fixtures/attr-operators-space-between/__snapshots__/attr-operators-space-between.expected.txt Just thought it might be interesting! |
Beta Was this translation helpful? Give feedback.
-
This feature would allow JSX to allow optional usage of curly braces when providing JS expressions for attributes.
Considered
The feature would only apply to the following expressions:
ArrayLiteral
Identifier
NullLiteral
BooleanLiteral
StringLiteral
NumericLiteral
RegularExpressionLiteral
TemplateLiteral
ParenthesizedExpression
Not considered
Most of the rejected expressions relates to allowing whitespace for tokens that do not have opening/closing symbols (which allows definition of token boundaries).
FunctionExpression
,AsyncFunctionExpression
,GeneratorExpression
,AsyncGeneratorExpression
,ClassExpression
- The syntax has no initial opening/closing tokens that would allow proper identification. Would require curly braces or parentheses to work (see ParenthesizedExpression)ArrowFunction
- allows optional whitespace, doesn't have initial opening/closing tokens for proper identification. Requires curly braces or parentheses.MemberExpression
,ImportMeta
,OptionalChain
- allows optional whitespace between chains, doesn't have initial opening/closing tokens for proper identification. Requires curly braces or parenthesesObjectLiteral
- conflict with curly braces.NewExpression
- requires whitespaceCallExpression
,ImportCall
- allows optional whitespace betweencallee
and the parameter list.UnaryExpression
,AssignmentExpression
,BinaryExpression
,TernaryExpression
- allows optional whitespaceBeta Was this translation helpful? Give feedback.
All reactions