From 611cd158987efa7cdcc13df91c34afdb811b4185 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Wed, 22 Jan 2025 11:58:29 -0500 Subject: [PATCH 1/3] Allow binary operators after nested object literals and bulleted arrays Fixes #1687 --- source/parser.hera | 32 +++++++++++++++++++------------- test/array.civet | 41 +++++++++++++++++++++++++++++++++++++++++ test/object.civet | 16 +++++++++++++++- 3 files changed, 75 insertions(+), 14 deletions(-) diff --git a/source/parser.hera b/source/parser.hera index 33750dba..f5463f89 100644 --- a/source/parser.hera +++ b/source/parser.hera @@ -606,6 +606,8 @@ IsLike # Whitespace followed by RHS WRHS + NestedBulletedArray -> [undefined, $1] + NestedImplicitObjectLiteral -> [undefined, $1] PushIndent ( ( Nested _? ) RHS )?:wrhs PopIndent -> if (!wrhs) return $skip return wrhs @@ -710,12 +712,13 @@ NWTypePostfix # https://262.ecma-international.org/#prod-UpdateExpression UpdateExpression - # NOTE: Not allowing whitespace betwen prefix and postfix increment operators and operand - UpdateExpressionSymbol UnaryWithoutParenthesizedAssignment -> + # NOTE: Not allowing whitespace between prefix and postfix increment operators and operand + # This is especially important for ++ to work as binary concat operator + UpdateExpressionSymbol:symbol !Whitespace UnaryWithoutParenthesizedAssignment:assigned -> return { type: "UpdateExpression", - assigned: $2, - children: $0, + assigned, + children: [symbol, assigned], } LeftHandSideExpression ( UpdateExpressionSymbol /(?!\p{ID_Start}|[_$0-9(\[{])/ )? -> if (!$2) return $1 @@ -5639,18 +5642,20 @@ Debugger return { $loc, token: $1 } MaybeNestedNonPipelineExpression - NestedBulletedArray - NestedImplicitObjectLiteral - PushIndent ( Nested NonPipelineExpression )?:expression PopIndent AllowedTrailingCallExpressions?:trailing -> + # Leave NestedBulletedArray and NestedImplicitObjectLiteral for + # the second case, where they get checked by PrimaryExpression, + # which then allows for trailing binary operators etc. + !NestedBulletedArray !NestedImplicitObjectLiteral PushIndent ( Nested NonPipelineExpression )?:expression PopIndent AllowedTrailingCallExpressions?:trailing -> if (!expression) return $skip if (!trailing) return expression return [ expression, trailing ] NonPipelineExpression MaybeNestedPostfixedExpression - NestedBulletedArray - NestedImplicitObjectLiteral - PushIndent ( Nested PostfixedExpression )?:expression PopIndent AllowedTrailingCallExpressions?:trailing -> + # Leave NestedBulletedArray and NestedImplicitObjectLiteral for + # the second case, where they get checked by PrimaryExpression, + # which then allows for trailing binary operators etc. + !NestedBulletedArray !NestedImplicitObjectLiteral PushIndent ( Nested PostfixedExpression )?:expression PopIndent AllowedTrailingCallExpressions?:trailing -> if (!expression) return $skip if (!trailing) return expression return [ expression, trailing ] @@ -5664,9 +5669,10 @@ NestedPostfixedExpressionNoTrailing return expression MaybeNestedExpression - NestedBulletedArray - NestedImplicitObjectLiteral - PushIndent ( Nested Expression )?:expression PopIndent AllowedTrailingCallExpressions?:trailing -> + # Leave NestedBulletedArray and NestedImplicitObjectLiteral for + # the second case, where they get checked by PrimaryExpression, + # which then allows for trailing binary operators etc. + !NestedBulletedArray !NestedImplicitObjectLiteral PushIndent ( Nested Expression )?:expression PopIndent AllowedTrailingCallExpressions?:trailing -> if (!expression) return $skip if (!trailing) return expression return [ expression, trailing ] diff --git a/test/array.civet b/test/array.civet index ab877c7a..e9bc6152 100644 --- a/test/array.civet +++ b/test/array.civet @@ -841,6 +841,47 @@ describe "array", -> .toString()) """ + testCase """ + with trailing type cast + --- + x = + . a + . b + as const + --- + x = [ + a, + b] as const + """ + + testCase """ + with trailing binary operator + --- + x = + . a + . b + ++ rest + --- + x = [ + a, + b] + .concat(rest) + """ + + testCase """ + with preceding and trailing binary operator + --- + x = front ++ + . a + . b + ++ rest + --- + x = front.concat( [ + a, + b]) + .concat(rest) + """ + describe "[] followed by elements", -> testCase """ indented diff --git a/test/object.civet b/test/object.civet index 7b3695c3..c6d20a65 100644 --- a/test/object.civet +++ b/test/object.civet @@ -772,7 +772,21 @@ describe "object", -> return ({a:(hasA? 1:void 0), b:(hasB? 2:void 0)}) } - """; // TODO: thinks next triple quote is a call expression + """ + + testCase """ + braceless object with trailing type cast + --- + x = + a: 1 + b: 2 + as const + --- + x = { + a: 1, + b: 2, + } as const + """ """ async From f64d96f6ad9b32933899bb3312bc04f20b857e56 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Wed, 22 Jan 2025 12:15:33 -0500 Subject: [PATCH 2/3] Update upload-artifact to fix CI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index db7f5b82..c36697e5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: yarn build yarn test - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: browser.js path: dist/browser.js From 8c32b1c44b5986208c0c2af1788c2d96fc60a13a Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Wed, 22 Jan 2025 12:33:52 -0500 Subject: [PATCH 3/3] Attempt to fix API_TOKEN in CI --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c36697e5..8411c949 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,8 +72,10 @@ jobs: cache: yarn node-version: 20 - - name: Install and Test + - name: Install and Build # `yarn docs:build` includes `yarn build` run: | yarn yarn docs:build + env: + API_TOKEN: ${{ secrets.GITHUB_TOKEN }}