Skip to content

Replaced numerical fors with while loops - #87

Merged
lolleko merged 4 commits into
masterfrom
for-loop-fix
Apr 1, 2018
Merged

Replaced numerical fors with while loops#87
lolleko merged 4 commits into
masterfrom
for-loop-fix

Conversation

@lolleko

@lolleko lolleko commented Mar 31, 2018

Copy link
Copy Markdown
Member

Fixes #85

@lolleko
lolleko requested a review from Perryvw March 31, 2018 16:33
Comment thread src/TSHelper.ts
}

public static hasCustomDecorator(type: ts.Type, checker: ts.TypeChecker, decorator: string): boolean {
if (type.symbol) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was here for a reason, you will get null pointers without.

Comment thread src/Transpiler.ts Outdated
// Add header
let result = this.indent + `for ${identifier.escapedText}=${start},${end},${step} do\n`;
let result = `--for(${variable.trim()}; ${condition}; ${incrementor};)\n`;
result += this.indent + variable;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well just add all declarations instead of just the first.

Comment thread test/unit/loops.spec.ts
@TestCase([0, 1, 2, 3], [0, 2, 2, 4], "let i = arrTest.length - 1; i <= 0; i -= 2")
// @TestCase([0, 1, 2, 3], [1, 2, 3, 4], "let i = arrTest.length - 1; i <= 0; i--")
// @TestCase([0, 1, 2, 3], [0, 2, 2, 4], "let i = arrTest.length - 1; i <= 0; i -= 2")
@TestCase([0, 1, 2, 3], [0, 2, 2, 4], "let i = arrTest.length - 1; i >= 0; i -= 2")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this one with i-- since that's the standard way to loop over an array backwards.

@lolleko
lolleko merged commit e3f5d46 into master Apr 1, 2018
@lolleko
lolleko deleted the for-loop-fix branch April 1, 2018 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants