rokucommunity / rokucommunity/brighterscript

?? operator transpiled code is needlessly verbose

Open
#306 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

BrighterScript enhancement
Dominant language
TypeScript
Stars
208
Forks
68
Avg merge
8h 39m
Merged PRs (30d)
39

Description

  endpoints = mc.getPath(task.output, "data.endpoints") ?? {}

transpiles to :

        endpoints = (function(mc, task)
                __bsConsequent = mc_getPath(task.output, "data.endpoints")
                if __bsConsequent <> invalid then
                    return __bsConsequent
                else
                    return {}
                end if
            end function)(mc, task)

in this case, where there is no dotted get, we could just have a function?
also, given that we know this is a statement, we could actually insert the if inline, which will use up just as much script ram storage as this code here.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how the ?? operator is transpiled, using the issue's example as the expected comparison. Check whether simple property access and statement assignments can use shorter output without changing semantics; done means equivalent transpiled code is less verbose and existing transpiler tests still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.