Skip to content
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

Make destructured parameters more flexible (Fixes #270) #277

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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