Skip to content

Commit

Permalink
fix(parser): consider namespace function transpiled names (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturocuya committed Sep 7, 2022
1 parent 82620e0 commit 58e1325
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
29 changes: 29 additions & 0 deletions src/Scope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,35 @@ describe('Scope', () => {
]);
});

it('accepts namespace names in their transpiled form on .brs files', () => {
program.setFile('source/ns.bs', `
namespace MyNamespace
sub foo()
end sub
end namespace
namespace A.B.C
sub ga()
end sub
end namespace
`);
program.setFile('source/main.brs', `
sub main()
MyNamespace_foo()
A_B_C_ga()
end sub
`);
program.setFile('source/main.xml', `
<?xml version="1.0" encoding="UTF-8"?>
<component name="MyComponent" extends="Group">
<script type="text/brightscript" uri="main.brs"/>
<script type="text/brightscript" uri="ns.bs"/>
</component>
`);
program.validate();
expectZeroDiagnostics(program);
});

it('Validates NOT too deep nested files', () => {
program.setFile('source/folder2/folder3/folder4/folder5/folder6/folder7/main.brs', ``);
program.setFile('source/folder2/folder3/folder4/folder5/folder6/folder7/main2.bs', ``);
Expand Down
20 changes: 17 additions & 3 deletions src/parser/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ import type {
PrintSeparatorTab,
Statement
} from './Statement';
import {
ConstStatement
} from './Statement';
import {
AssignmentStatement,
Block,
Body,
CatchStatement,
ClassStatement,
ConstStatement,
CommentStatement,
DimStatement,
DottedSetStatement,
Expand Down Expand Up @@ -972,6 +970,22 @@ export class Parser {
let result = new FunctionStatement(name, func, this.currentNamespaceName);
func.functionStatement = result;
this._references.functionStatements.push(result);

// Add the transpiled name for namespace functions
// to consider an edge case when defining namespaces in .bs files
// and using them in .brs files.
if (func.namespaceName) {
const transpiledNamespaceFunctionName = result.getName(ParseMode.BrightScript);
const funcType = func.getFunctionType();
funcType.setName(transpiledNamespaceFunctionName);

this.symbolTable.addSymbol(
transpiledNamespaceFunctionName,
name.range,
funcType
);
}

return result;
}
} finally {
Expand Down

0 comments on commit 58e1325

Please sign in to comment.