Skip to content

Casting ambiguous syntax - #181

Merged
Perryvw merged 5 commits into
TypeScriptToLua:masterfrom
andreiradu:casting_ambiguous_syntax
Sep 4, 2018
Merged

Casting ambiguous syntax#181
Perryvw merged 5 commits into
TypeScriptToLua:masterfrom
andreiradu:casting_ambiguous_syntax

Conversation

@andreiradu

@andreiradu andreiradu commented Aug 23, 2018

Copy link
Copy Markdown
Contributor

using extra paranthesis in ts causes code like dostuff() (self.member):method(); calls, which can be ambiguous depending on context. I've added ; at the end of statements to help disambiguate.

Closes #191

Comment thread src/Transpiler.ts Outdated
if (node.initializer) {
const value = this.transpileExpression(node.initializer);
return `local ${identifierName} = ${value}\n`;
return `local ${identifierName} = ${value};\n`;

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.

You pushed these too far down, I suggest adding the ';' in the transpileNode function, like you did for ExpressionStatement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That was my first approach, but transpileVariableDeclaration returns a newline, so the transpiled code would look like

      local a = 0
;
      foo()

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.

I think that's a bug, if removing the \n from transpileVariableDeclaration does not break any (non-whitespace) tests I am fine with you removing it there.

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.

That new line after variable declaration is definitely unintentional and should be removed.

@Perryvw Perryvw left a comment

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.

Looks good! If you merge master into your branch this can be merged as far as I'm considered. You could also add the suggested ;, or we could leave it for a future update.

Comment thread src/Transpiler.ts
let result = "";
for (const variableDeclaration of (node.initializer as ts.VariableDeclarationList).declarations) {
result += this.indent + this.transpileVariableDeclaration(variableDeclaration);
result += this.indent + this.transpileVariableDeclaration(variableDeclaration) + "\n";

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.

Should there also be a ; here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not really, you know a while will always follow, so there's no ambiguity. I've tried not to add ; where they weren't needed.

…yntax

# Conflicts:
#	test/unit/objectLiteral.spec.ts
@andreiradu

Copy link
Copy Markdown
Contributor Author

Merged master and fixed tests

@Perryvw
Perryvw merged commit 5eeecbd into TypeScriptToLua:master Sep 4, 2018
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.

3 participants