Skip to content

Commit

Permalink
Support TS -readonly / -? syntax in mapped object types
Browse files Browse the repository at this point in the history
FIX: Add support for `{-readonly [K in T]-?: U}` TypeScript syntax.

Closes #36
  • Loading branch information
marijnh committed Jun 11, 2024
1 parent b3775dc commit 0f89f5b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/javascript.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,14 @@ AwaitExpression[@dynamicPrecedence=1] {

UnaryExpression {
!prefix (kw<"void"> | kw<"typeof"> | kw<"delete"> |
LogicOp<"!"> | BitOp<"~"> | incdec | incdecPrefix | ArithOp<"+" | "-">)
LogicOp<"!"> | BitOp<"~"> | incdec | incdecPrefix | plusMin)
expressionNoComma
}

BinaryExpression {
expressionNoComma !exp ArithOp<"**"> expressionNoComma |
expressionNoComma !times (divide | ArithOp<"%"> | ArithOp<"*">) expressionNoComma |
expressionNoComma !plus ArithOp<"+" | "-"> expressionNoComma |
expressionNoComma !plus plusMin expressionNoComma |
expressionNoComma !shift BitOp<">>" ">"? | "<<"> expressionNoComma |
expressionNoComma !rel (LessThan | CompareOp<"<=" | ">" "="?> | kw<"instanceof">) expressionNoComma |
expressionNoComma !satisfies tskw<"satisfies"> type |
Expand Down Expand Up @@ -410,7 +410,7 @@ typeofExpression {
type[@isGroup=Type] {
ThisType { kw<"this"> } |
LiteralType {
ArithOp<"+" | "-">? Number |
plusMin? Number |
boolean |
String
} |
Expand Down Expand Up @@ -459,7 +459,10 @@ ObjectType {
}

IndexSignature {
tsPkwMod<"readonly">? "[" PropertyDefinition { identifier } (TypeAnnotation | ~tsIn kw<"in"> type) "]" TypeAnnotation
(plusMin? tsPkwMod<"readonly">)?
"[" PropertyDefinition { identifier } (TypeAnnotation | ~tsIn kw<"in"> type) "]"
(plusMin? Optional)?
TypeAnnotation
}

MethodType {
Expand All @@ -470,9 +473,9 @@ MethodType {
}

PropertyType {
(ArithOp<"+" | "-">? tsPkwMod<"readonly">)?
(plusMin? tsPkwMod<"readonly">)?
PropertyDefinition
(ArithOp<"+" | "-">? Optional)?
(plusMin? Optional)?
TypeAnnotation
}

Expand Down Expand Up @@ -596,6 +599,8 @@ questionOp[@name=LogicOp] { "?" }

unionOp[@name=LogicOp] { "|" }

plusMin { ArithOp<"+" | "-"> }

intersectionOp[@name=LogicOp] { "&" }

@skip { spaces | newline | LineComment | BlockComment }
Expand Down

0 comments on commit 0f89f5b

Please sign in to comment.