rokucommunity / rokucommunity/brighterscript

Transpilation issue with complicated typecast

Open
#1,651 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I had this code:

sub someFunc()
    typecast m as { top as roSGNode, optional subscreen as SomeInterface, mainGroup as roSGNodeCustomComponent, config as roAssociativeArray } and SomeOtherInterface
    print m.top.title
end sub

and it would cause an exception:

Error when calling plugin BscPlugin.afterSerializeFile: TypeError: Cannot read properties of undefined (reading '$$$isSourceNode$$$')
PluginInterface.ts:90
    at SourceNode.add (/.../brighterscript/node_modules/source-map/lib/source-node.js:178:22)
PluginInterface.ts:90
    at SourceNode.<anonymous> (/.../brighterscript/node_modules/source-map/lib/source-node.js:176:14)
PluginInterface.ts:90
    at Array.forEach (<anonymous>)
PluginInterface.ts:90
    at SourceNode.add (/.../brighterscript/node_modules/source-map/lib/source-node.js:175:14)
PluginInterface.ts:90
    at new SourceNode (/.../brighterscript/node_modules/source-map/lib/source-node.js:44:31)
PluginInterface.ts:90
    at Util.sourceNodeFromTranspileResult (/.../brighterscript/src/util.ts:2173:16)
PluginInterface.ts:90
    at BrsFile.transpile (/.../brighterscript/src/files/BrsFile.ts:938:36)
PluginInterface.ts:90
    at BrsFile.serialize (/.../brighterscript/src/files/BrsFile.ts:904:33)

eg. this test should pass:

it.only('handles this complicated typecast', async () => {
    const file = program.setFile<BrsFile>('source/main.bs', `
        sub someFunc()
            typecast m as { top as roSGNode, optional subscreen as SomeInterface, mainGroup as roSGNodeCustomComponent, config as roAssociativeArray } and SomeOtherInterface
            print m.top.title
        end sub
    `);

    await testTranspile(file, `
        sub someFunc()
            ' typecast m as { top as roSGNode, optional subscreen as SomeInterface, mainGroup as roSGNodeCustomComponent, config as roAssociativeArray } and SomeOtherInterface
            print m.top.title
        end sub
    `, undefined, undefined, false);
});

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 with the supplied regression test, then inspect src/util.ts around sourceNodeFromTranspileResult and the BrsFile transpile/serialize entry points named in the stack trace. Run the test and verify that this complicated typecast no longer throws and produces the expected commented typecast output.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.