Skip to content

Commit

Permalink
Fix namespace-relative transpile bug for standalone file (#1324)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron authored Oct 11, 2024
1 parent 3abcdaf commit 024e9a4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/files/BrsFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,38 @@ describe('BrsFile', () => {
`);
});

it('transpiles namespace calls from within an array', () => {
testTranspile(`
namespace Vertibrates.Birds
function GetAllBirds()
return [
GetDuck(),
GetGoose()
]
end function
function GetDuck()
end function
function GetGoose()
end function
end namespace
`, `
function Vertibrates_Birds_GetAllBirds()
return [
Vertibrates_Birds_GetDuck()
Vertibrates_Birds_GetGoose()
]
end function
function Vertibrates_Birds_GetDuck()
end function
function Vertibrates_Birds_GetGoose()
end function
`, undefined, 'components/NobodyImportsMe.bs', false);
});

it('properly transpiles inferred namespace function for assignment', () => {
testTranspile(`
namespace NameA.NameB
Expand Down
11 changes: 10 additions & 1 deletion src/files/BrsFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CancellationTokenSource } from 'vscode-languageserver';
import { CompletionItemKind, TextEdit } from 'vscode-languageserver';
import chalk from 'chalk';
import * as path from 'path';
import type { Scope } from '../Scope';
import { Scope } from '../Scope';
import { DiagnosticCodeMap, diagnosticCodes, DiagnosticMessages } from '../DiagnosticMessages';
import { FunctionScope } from '../FunctionScope';
import type { Callable, CallableArg, CallableParam, CommentFlag, FunctionCall, BsDiagnostic, FileReference, FileLink, BscFile } from '../interfaces';
Expand Down Expand Up @@ -1243,6 +1243,15 @@ export class BrsFile {
let lowerCalleeName = callee?.name?.text?.toLowerCase();
if (lowerCalleeName) {
let scopes = this.program.getScopesForFile(this);

//if this file does not belong to any scopes, make a temporary one to answer the question
if (scopes.length === 0) {
const scope = new Scope(`temporary-for-${this.pkgPath}`, this.program);
scope.getAllFiles = () => [this];
scope.getOwnFiles = scope.getAllFiles;
scopes.push(scope);
}

for (let scope of scopes) {
let namespace = scope.namespaceLookup.get(namespaceName.toLowerCase());
if (namespace?.functionStatements[lowerCalleeName]) {
Expand Down

0 comments on commit 024e9a4

Please sign in to comment.