Skip to content

Constants not properly transpiling across files #1618

@Miller162

Description

@Miller162

Hey all.  I am running into a weird issue where a const is not transpiled properly
lets say I have 2 files:
helper.bs and map.bs

map.bs looks as follows

namespace name.space 
     enum someEnum 
         one = "val1"
         two = "val2"
         three = "val3"
     end enum 

     const map = { 
         "key1": someEnum.one, 
         "key2": someEnum.two, 
         "key3": someEnum.three
     }
end namespace

helper.bs and looks as follows

import "map.bs"
namespace name.space
     class someClass 
         public function someFunc(key as dynamic) as object 
              return name.space.map[key]
         end function 
     end class
end namespace 

when the code is transpiled to .brs, someFunc() in helper.brs looks as follows

function __name_space_someClass_method_someFunc(key as dynamic) as object 
      return ({ 
         "key1": someEnum.one, 
         "key2": someEnum.two, 
         "key3": someEnum.three
     })[key]
end function

where the someEnum values are not being properly replaced.  This results in a crash when the code is running as we are attempting to use a dot operator on an invalid/uninitialized object.

If i move the contents of the map.bs file to helper.bs, it transpiles properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions