Skip to content

Transpilation issue with complicated typecast #1651

@markwpearce

Description

@markwpearce

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);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions