Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): consider namespace function transpiled names #685

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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