Skip to content

Commit

Permalink
transpile namespaced function var assignments
Browse files Browse the repository at this point in the history
Fixes #91
  • Loading branch information
TwitchBronBron committed May 28, 2020
1 parent 48e8838 commit b21c38e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0



## [Unreleased]
### Fixed
- bug where assigning a namespaced function to a variable wasn't properly transpiling the dots to underscores (fixes [#91](https://github.com/rokucommunity/brighterscript/issues/91))



## [0.10.3] - 2020-05-27
### Changed
- tokenizing a string with no closing quote will now include all of the text until the end of the line.
Expand Down
24 changes: 24 additions & 0 deletions src/files/BrsFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,30 @@ describe('BrsFile', () => {
});

describe('transpile', () => {
describe('namespaces', () => {
it('properly transpiles namespace functions for assignments', async () => {
await testTranspile(`
namespace NameA.NameB
sub Speak()
end sub
end namespace
sub main()
sayHello = NameA.NameB.Speak
sayHello()
someOtherObject = some.other.object
end sub
`, `
sub NameA_NameB_Speak()
end sub
sub main()
sayHello = NameA_NameB_Speak
sayHello()
someOtherObject = some.other.object
end sub
`);
});
});
it('includes all text to end of line for a non-terminated string', async () => {
await testTranspile(`
sub main()
Expand Down
24 changes: 12 additions & 12 deletions src/parser/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ export class CallExpression implements Expression {
transpile(state: TranspileState) {
let result = [];

//if the callee starts with a namespace name, transpile the name
if (state.file.calleeStartsWithNamespace(this.callee)) {
result.push(
...new NamespacedVariableNameExpression(this.callee as DottedGetExpression | VariableExpression).transpile(state)
);
//if the callee is the name of a known namespace function
} else if (state.file.calleeIsKnownNamespaceFunction(this.callee, this.namespaceName?.getName(ParseMode.BrighterScript))) {
//if the callee is the name of a known namespace function
if (state.file.calleeIsKnownNamespaceFunction(this.callee, this.namespaceName?.getName(ParseMode.BrighterScript))) {
result.push(
new SourceNode(
this.callee.range.start.line + 1,
Expand Down Expand Up @@ -243,11 +238,16 @@ export class DottedGetExpression implements Expression {
public readonly range: Range;

transpile(state: TranspileState) {
return [
...this.obj.transpile(state),
'.',
new SourceNode(this.name.range.start.line + 1, this.name.range.start.character, state.pathAbsolute, this.name.text)
];
//if the callee starts with a namespace name, transpile the name
if (state.file.calleeStartsWithNamespace(this)) {
return new NamespacedVariableNameExpression(this as DottedGetExpression | VariableExpression).transpile(state);
} else {
return [
...this.obj.transpile(state),
'.',
new SourceNode(this.name.range.start.line + 1, this.name.range.start.character, state.pathAbsolute, this.name.text)
];
}
}
}

Expand Down

0 comments on commit b21c38e

Please sign in to comment.