Skip to content

Support for single-character escape sequences#160

Merged
Perryvw merged 5 commits intoTypeScriptToLua:masterfrom
Janne252:master
Jul 28, 2018
Merged

Support for single-character escape sequences#160
Perryvw merged 5 commits intoTypeScriptToLua:masterfrom
Janne252:master

Conversation

@Janne252
Copy link
Copy Markdown
Contributor

With this update single-character escape sequences will be preserved, e.g.

let escapedCharsInQuotes = '\\ \0 \b \t \n \v \f \" \' \`';

Is transpiled to

local escapedCharsInQuotes = "\\ \0 \b \t \n \v \f \" \' \`"

Previously you had to double escape them, for example "\n" would have resulted in an actual linebreak in the transpiled lua code.

Copy link
Copy Markdown
Member

@Perryvw Perryvw left a comment

Choose a reason for hiding this comment

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

You forgot transpileTemplateExpression, could you refactor the method as suggested and use it on the literal strings in transpileTemplateExpression too?

}
}

public transpileStringLiteralExpression(node: ts.Node): string {
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 would suggest refactoring to escapeString(str: string): string and just calling this wherever suitable.

return this.transpileIdentifier(node as ts.Identifier);
case ts.SyntaxKind.StringLiteral:
case ts.SyntaxKind.NoSubstitutionTemplateLiteral:
const text = (node as ts.StringLiteral).text;
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.

Then this would just be something like const text = this.escapeString((node as ts.StringLiteral).text);

@Janne252
Copy link
Copy Markdown
Contributor Author

I realized the missing support for template strings as well, wasn't quick enough to ninja-commit it though.

Support & tests added for template strings and requested changes applied.

@Perryvw Perryvw merged commit 5afaa2d into TypeScriptToLua:master Jul 28, 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.

2 participants