Skip to content

Commit

Permalink
Fix class finding bug during validation
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Oct 12, 2020
1 parent f075612 commit bdba4e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/files/BrsFile.Class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,30 @@ describe('BrsFile BrighterScript classes', () => {
expect(duckClass.memberMap['move']).to.exist;
});

it('supports various namespace configurations', async () => {
await program.addOrReplaceFile<BrsFile>({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
class Animal
sub new()
bigBird = new Birds.Bird()
donald = new Birds.Duck()
end sub
end class
namespace Birds
class Bird
sub new()
dog = new Animal()
donald = new Duck()
end sub
end class
class Duck
end class
end namespace
`);
await program.validate();
expect(program.getDiagnostics()[0]?.message).not.to.exist;
});

describe('transpile', () => {
it('follows correct sequence for property initializers', async () => {
await testTranspile(`
Expand Down
7 changes: 6 additions & 1 deletion src/validators/ClassValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ export class BsClassValidator {
*/
private getClassByName(className: string, namespaceName?: string) {
let fullName = util.getFulllyQualifiedClassName(className, namespaceName);
return this.classes[fullName.toLowerCase()];
let cls = this.classes[fullName.toLowerCase()];
//if we couldn't find the class by its full namespaced name, look for a global class with that name
if (!cls) {
cls = this.classes[className.toLowerCase()];
}
return cls;
}

/**
Expand Down

0 comments on commit bdba4e2

Please sign in to comment.