Skip to content

Commit

Permalink
Make destructured parameters more flexible (Fixes #270) (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindberg authored Mar 18, 2021
1 parent 942228a commit 2513f0f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2759,4 +2759,54 @@ export {};
),
)
}

test("function isNotTestHost([, sectionItem]: ConfigurationSectionEntry): boolean;") {
val content = "declare function isNotTestHost([, sectionItem]: ConfigurationSectionEntry): boolean"
shouldParseAs(content, TsParser.tsDeclFunction)(
TsDeclFunction(
NoComments,
true,
TsIdentSimple("isNotTestHost"),
TsFunSig(
NoComments,
IArray(),
IArray(
TsFunParam(
NoComments,
TsIdentSimple("hasSectionItem"),
Some(TsTypeRef(NoComments, TsQIdent(IArray(TsIdentSimple("ConfigurationSectionEntry"))), IArray())),
),
),
Some(TsTypeRef.boolean),
),
Zero,
CodePath.NoPath,
),
)
}

test("function foo({ 'com.foo': _, ...entitlementsPlist }: Plist): Plist") {
val content = "declare function foo({ 'com.foo': _, ...entitlementsPlist }: Plist): Plist"
shouldParseAs(content, TsParser.tsDeclFunction)(
TsDeclFunction(
NoComments,
true,
TsIdentSimple("foo"),
TsFunSig(
NoComments,
IArray(),
IArray(
TsFunParam(
NoComments,
TsIdentSimple("hasCom.apple.developer.contacts.notesEntitlementsPlist"),
Some(TsTypeRef(NoComments, TsQIdent(IArray(TsIdentSimple("Plist"))), IArray())),
),
),
Some(TsTypeRef(NoComments, TsQIdent(IArray(TsIdentSimple("Plist"))), IArray())),
),
Zero,
CodePath.NoPath,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,12 @@ class TsParser(path: Option[(os.Path, Int)]) extends StdTokenParsers with Parser

/** Represent in tree? **/
lazy val destructuredObj: Parser[TsIdentSimple] =
"{" ~>! rep((tsIdent | ("..." ~> tsIdent)) <~ (":" <~ (tsIdent | destructured)).? <~ ",".?) <~ "}" ^^ (
"{" ~>! rep((tsIdentLiberal | ("..." ~> tsIdent)) <~ (":" <~ (tsIdent | destructured)).? <~ ",".?) <~ "}" ^^ (
ids =>
TsIdent("has" + ids.map(_.value.capitalize).mkString("")),
)
lazy val destructuredArray: Parser[TsIdentSimple] =
"[" ~>! repsep(tsIdent <~ (":" <~ (tsIdent | destructured)).?, ",") <~ "]" ^^ (
"[" ~>! ",".? ~> repsep(tsIdent <~ (":" <~ (tsIdent | destructured)).?, ",") <~ "]" ^^ (
ids =>
TsIdent("has" + ids.map(_.value.capitalize).mkString("")),
)
Expand Down

0 comments on commit 2513f0f

Please sign in to comment.