Repository: rokucommunity/brighterscript (ts)

Issue:
Enum usage in namespaces transpiling broken in v1.0.0-alpha.30
Here's a unit test showing the issue.

```typescript
it.only('enum stuff works', async () => {
    program.setFile('components/Colors.bs', `
        namespace Colors
            enum Primary
                red = "#FF0000"
            end enum
        end namespace
    `);

    program.setFile('components/Button.xml', `
        <component name="Button" extends="Group">
            <script type="text/brightscript" uri="pkg:/components/Button.bs" />
        </component>
    `);
    const file = program.setFile('components/Button.bs', `
        import "Colors.bs"

        namespace alpha
            sub testIt()
                print Colors.Primary.red
                aa = {
                    value: Colors.Primary.red
                }
            end sub
        end namespace
    `);
    program.validate();
    expectZeroDiagnostics(program);
    await testTranspile(file, `put expected code here, but it should transpile enums and it doesnt right now`);
});
```

Pull request description:
Fixes Transpile issue with enums in namespaces
Fixes #1215 


Patch:
diff --git a/src/bscPlugin/BscPlugin.ts b/src/bscPlugin/BscPlugin.ts
index 1fce1b38..2487db63 100644
--- a/src/bscPlugin/BscPlugin.ts
+++ b/src/bscPlugin/BscPlugin.ts
@@ -20,7 +20,7 @@ import { BslibManager } from './serialize/BslibManager';
 import { FileSerializer } from './serialize/FileSerializer';
 import { BrsFilePreTranspileProcessor } from './transpile/BrsFileTranspileProcessor';
 import { XmlFilePreTranspileProcessor } from './transpile/XmlFilePreTranspileProcessor';
-import { BrsFileAfterValidator } from './validation/BrsFileAfterValidatior';
+import { BrsFileAfterValidator } from './validation/BrsFileAfterValidator';
 
 export class BscPlugin implements CompilerPlugin {
     public name = 'BscPlugin';
diff --git a/src/bscPlugin/transpile/BrsFileTranspileProcessor.ts b/src/bscPlugin/transpile/BrsFileTranspileProcessor.ts
index bfd061be..a21679c0 100644
--- a/src/bscPlugin/transpile/BrsFileTranspileProcessor.ts
+++ b/src/bscPlugin/transpile/BrsFileTranspileProcessor.ts
@@ -71,10 +71,8 @@ export class BrsFilePreTranspileProcessor {
         //assume we've been given the enum.member syntax, so pop the member and try again
         const parts = name.toLowerCase().split('.');
         const memberName = parts.pop();
-        if (containingNamespace && parts[0] !== containingNamespace.toLowerCase()) {
-            parts.unshift(containingNamespace.toLowerCase());
-        }
-        result = scope?.getEnumFileLink(parts.join('.'));
+
+        result = scope?.getEnumFileLink(parts.join('.'), containingNamespace);
         if (result) {
             const value = result.item.getMemberValue(memberName);
             return {


Test patch:
diff --git a/src/bscPlugin/validation/BrsFileAfterValidatior.ts b/src/bscPlugin/validation/BrsFileAfterValidator.ts
similarity index 100%
rename from src/bscPlugin/validation/BrsFileAfterValidatior.ts
rename to src/bscPlugin/validation/BrsFileAfterValidator.ts
diff --git a/src/parser/tests/statement/Enum.spec.ts b/src/parser/tests/statement/Enum.spec.ts
index db5bb9b6..ca93ea99 100644
--- a/src/parser/tests/statement/Enum.spec.ts
+++ b/src/parser/tests/statement/Enum.spec.ts
@@ -808,5 +808,53 @@ describe('EnumStatement', () => {
                 end sub
             `);
         });
+
+        it('works when enum is in a namespace', async () => {
+            program.setFile('components/Colors.bs', `
+                namespace Colors
+                    enum Primary
+                        red = "#FF0000"
+                    end enum
+                end namespace
+            `);
+
+            program.setFile('components/Button.xml', `
+                <component name="Button" extends="Group">
+                    <script type="text/brightscript" uri="pkg:/components/Button.bs" />
+                </component>
+            `);
+            const file = program.setFile('components/Button.bs', `
+                import "Colors.bs"
+
+                namespace alpha
+                    sub testIt()
+                        print Colors.Primary.red
+                        aa = {
+                            value: Colors.Primary.red
+                        }
+                    end sub
+                end namespace
+
+                namespace Colors
+                    sub testIt()
+                        print Primary.red
+                    end sub
+                end namespace
+            `);
+            program.validate();
+            expectZeroDiagnostics(program);
+            await testTranspile(file, `
+                'import "Colors.bs"
+                sub alpha_testIt()
+                    print "#FF0000"
+                    aa = {
+                        value: "#FF0000"
+                    }
+                end sub
+                sub Colors_testIt()
+                    print "#FF0000"
+                end sub
+            `);
+        });
     });
 });