rokucommunity / rokucommunity/brighterscript

Inline bslib functions to eliminate need for bslib.brs

Open
#1,524 0 comments 1 reaction 1 assignee View on GitHub

Nobody has claimed this yet.

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

Description

Add the ability to inline the bslib functions in the current file to eliminate the need for bslib.brs.

Motivation

While the current bslib.brs pattern works for app developers, it introduces friction for library consumers who must remember to add bslib.brs imports. This proposal aims to make library adoption easier and reduce manual steps.

Example:

function main()
        message = `Hello ${m.top.name}`
end function

Used to transpile to:

function main()
                         'bslib_toString somehow imported from `pkg:/source/bslib.brs`
    message = ("Hello " + bslib_toString(m.top.name))
end function

But now will transpile to the following code (enabling that file to be completely self-sufficient):

function main()
    message = ("Hello " + bslib_toString_1234567890abcdef(m.top.name))
end function

function bslib_toString_1234567890abcdef(value)
    '...the contents of bslib_toString
end function

Requirements:

1. Add a new configuration option
  • Extend the configuration system to support a bslibHandling object as shown below. (final name up for discussion):
{
  "bslibHandling": {
    "mode": "shared" | "unique-per-file",
    "uniqueStrategy": "md5" | "guid" // for unique-per-file
  }
}
  • Add a mode property with options: "shared" (default) and "unique-per-file"
  • Add a uniqueStrategy property for "unique-per-file" which supports "md5" (default) and "guid". This decides how to generate the suffix for file-inlined functions.
2. Implement the two behaviors
shared (default):
  • Current behavior: output all bslib helpers to a single shared file (e.g., bslib.brs).
unique-per-file:

When this mode is enabled, generate unique bslib functions for each file

  • the unique identifier should be either
    • md5(file.srcPath) (default)
    • or a GUID.
  • Inline all bslib helpers directly into each file that needs them; do not generate a shared file.
  • change all bslib calls to use that suffixed file. (i.e. bslib_ternary => bslib_ternary_1234567890abcdef)
  • prevent injecting the bslib.brs imports into xml files that currently happens
3. Documentation
  • Update documentation to explain the new configuration options and their effects.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.