From eae5332f1f2020be6dc097a65aa6e7e4e70c9e2e Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Mon, 2 Oct 2023 12:47:16 -0400 Subject: [PATCH] Allow newline before ...rest parameter Partial fix to #760 --- source/parser.hera | 2 +- test/function.civet | 64 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/source/parser.hera b/source/parser.hera index 2acbb27d..4dfc8239 100644 --- a/source/parser.hera +++ b/source/parser.hera @@ -1243,7 +1243,7 @@ NonEmptyParameters # https://262.ecma-international.org/#prod-FunctionRestParameter FunctionRestParameter - BindingRestElement:id TypeSuffix? ParameterElementDelimiter -> + __ BindingRestElement:id TypeSuffix? ParameterElementDelimiter -> return { type: "FunctionRestParameter", children: $0, diff --git a/test/function.civet b/test/function.civet index 1bc13526..70ec6ebc 100644 --- a/test/function.civet +++ b/test/function.civet @@ -836,6 +836,70 @@ describe "function", -> } """ + describe "indented parameters", -> + testCase """ + mixed + --- + ( + a, b + c, d + ) => null + --- + ( + a, b, + c, d + ) => null + """ + + testCase """ + ...rest + --- + foo := ( + x + ...rest + ) -> null + --- + function foo( + x, + ...rest + ) { return null } + """ + + testCase """ + rest... + --- + foo := ( + x + rest... + ) -> null + --- + function foo( + x, + ...rest + ) { return null } + """ + + // TODO: wrong indentation of }s + testCase """ + indented with types + --- + function f( + t: + item: T + u: + item: T + ) + --- + function f( + t: { + item: T + }, + u: { + item: T + } + ){} + """ + describe "implicit returns", -> testCase """ basic