Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into release-0.66.0
  • Loading branch information
TwitchBronBron committed Jun 9, 2023
2 parents 5f96c43 + e433516 commit f6343a6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 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



## [0.65.1](https://github.com/rokucommunity/brighterscript/compare/v0.65.0...v0.65.1) - 2023-06-09
### Fixed
- injection of duplicate super calls into classes ([#823](https://github.com/rokucommunity/brighterscript/pull/823))



## [0.65.0](https://github.com/rokucommunity/brighterscript/compare/v0.64.4...v0.65.0) - 2023-05-17
### Changed
- npm audit fixes. upgrade to coveralls-next ([43756d8](https://github.com/rokucommunity/brighterscript/commit/43756d8))
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brighterscript",
"version": "0.65.0",
"version": "0.65.1",
"description": "A superset of Roku's BrightScript language.",
"scripts": {
"preversion": "npm run build && npm run lint && npm run test",
Expand Down
39 changes: 39 additions & 0 deletions src/files/BrsFile.Class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,45 @@ describe('BrsFile BrighterScript classes', () => {
`);
});

it('does not inject a call to super if one exists', () => {
testTranspile(`
class Animal
end class
class Duck extends Animal
sub new()
print "I am a statement which does not use m"
super()
end sub
end class
`, `
function __Animal_builder()
instance = {}
instance.new = sub()
end sub
return instance
end function
function Animal()
instance = __Animal_builder()
instance.new()
return instance
end function
function __Duck_builder()
instance = __Animal_builder()
instance.super0_new = instance.new
instance.new = sub()
print "I am a statement which does not use m"
m.super0_new()
end sub
return instance
end function
function Duck()
instance = __Duck_builder()
instance.new()
return instance
end function
`);
});

it('handles class inheritance inferred constructor calls', () => {
testTranspile(`
class Animal
Expand Down
18 changes: 10 additions & 8 deletions src/parser/Statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2184,19 +2184,21 @@ export class MethodStatement extends FunctionStatement {
return;
}

//find the first non-comment statement
let firstStatement = this.func.body.statements.find(x => !isCommentStatement(x));
//if the first statement is a call to super, quit here
if (
//check whether any calls to super exist
let containsSuperCall =
this.func.body.statements.findIndex((x) => {
//is a call statement
isExpressionStatement(firstStatement) && isCallExpression(firstStatement.expression) &&
return isExpressionStatement(x) && isCallExpression(x.expression) &&
//is a call to super
util.findBeginningVariableExpression(firstStatement?.expression.callee as any).name.text.toLowerCase() === 'super'
) {
util.findBeginningVariableExpression(x.expression.callee as any).name.text.toLowerCase() === 'super';
}) !== -1;

//if a call to super exists, quit here
if (containsSuperCall) {
return;
}

//this is a child class, and the first statement isn't a call to super. Inject one
//this is a child class, and the constructor doesn't contain a call to super. Inject one
const superCall = new ExpressionStatement(
new CallExpression(
new VariableExpression(
Expand Down

0 comments on commit f6343a6

Please sign in to comment.