Skip to content

Commit a931cb9

Browse files
authored
Cleanup (#363)
- formatting fixes - removed redundant escapeString function - fixed return type of isIterationStatement - removed a comment
1 parent 6dbecdc commit a931cb9

File tree

3 files changed

+41
-48
lines changed

3 files changed

+41
-48
lines changed

src/CommandLineParser.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ export function parseCommandLine(args: string[]): ParsedCommandLine {
6464
const [tstlOptions, tstlDefaults] = getYargOptionsWithoutDefaults(optionDeclarations);
6565

6666
const parsedArgs = yargs
67-
.usage(
68-
"Syntax: tstl [options] [files...]\n\n" +
69-
"In addition to the options listed below you can also pass options" +
70-
"for the typescript compiler (For a list of options use tsc -h).\n" +
71-
"Some tsc options might have no effect.")
72-
.example("tstl path/to/file.ts [...]", "Compile files")
73-
.example("tstl -p path/to/tsconfig.json", "Compile project")
74-
.wrap(yargs.terminalWidth())
75-
.options(tstlOptions)
76-
.fail((msg, err) => {
77-
throw new CLIError(msg);
78-
})
79-
.parse(args);
67+
.usage(
68+
"Syntax: tstl [options] [files...]\n\n" +
69+
"In addition to the options listed below you can also pass options" +
70+
"for the typescript compiler (For a list of options use tsc -h).\n" +
71+
"Some tsc options might have no effect.")
72+
.example("tstl path/to/file.ts [...]", "Compile files")
73+
.example("tstl -p path/to/tsconfig.json", "Compile project")
74+
.wrap(yargs.terminalWidth())
75+
.options(tstlOptions)
76+
.fail((msg, err) => {
77+
throw new CLIError(msg);
78+
})
79+
.parse(args);
8080

8181
let commandLine = ts.parseCommandLine(args);
8282

src/LuaAST.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ export enum SyntaxKind {
6666
OrOperator,
6767
NotOperator, // Unary
6868
// Bitwise
69-
// Not sure we need those since we always used the lib functions bit.bor, bit.band ... irrc
7069
BitwiseAndOperator,
7170
BitwiseOrOperator,
7271
BitwiseExclusiveOrOperator,
@@ -201,7 +200,9 @@ export function createVariableDeclarationStatement(
201200
left: Identifier | Identifier[],
202201
right?: Expression | Expression[],
203202
parent?: Node,
204-
tsOriginal?: ts.Node): VariableDeclarationStatement {
203+
tsOriginal?: ts.Node
204+
): VariableDeclarationStatement
205+
{
205206
const statement = createNode(
206207
SyntaxKind.VariableDeclarationStatement,
207208
parent,
@@ -237,7 +238,9 @@ export function createAssignmentStatement(
237238
left: IdentifierOrTableIndexExpression | IdentifierOrTableIndexExpression[],
238239
right: Expression | Expression[],
239240
parent?: Node,
240-
tsOriginal?: ts.Node): AssignmentStatement {
241+
tsOriginal?: ts.Node
242+
): AssignmentStatement
243+
{
241244
const statement = createNode(SyntaxKind.AssignmentStatement, parent, tsOriginal) as AssignmentStatement;
242245
setParent(left, statement);
243246
if (Array.isArray(left)) {
@@ -287,7 +290,7 @@ export interface IterationStatement extends Statement {
287290
body: Block;
288291
}
289292

290-
export function isIterationStatement(node: Node): node is WhileStatement {
293+
export function isIterationStatement(node: Node): node is IterationStatement {
291294
return node.kind === SyntaxKind.WhileStatement || node.kind === SyntaxKind.RepeatStatement
292295
|| node.kind === SyntaxKind.ForStatement || node.kind === SyntaxKind.ForInStatement;
293296
}
@@ -360,7 +363,9 @@ export function createForStatement(
360363
limitExpression: Expression,
361364
stepExpression?: Expression,
362365
parent?: Node,
363-
tsOriginal?: ts.Node): ForStatement {
366+
tsOriginal?: ts.Node
367+
): ForStatement
368+
{
364369
const statement = createNode(SyntaxKind.ForStatement, parent, tsOriginal) as ForStatement;
365370
setParent(body, statement);
366371
statement.body = body;
@@ -386,7 +391,13 @@ export function isForInStatement(node: Node): node is ForInStatement {
386391
}
387392

388393
export function createForInStatement(
389-
body: Block, names: Identifier[], expressions: Expression[], parent?: Node, tsOriginal?: ts.Node): ForInStatement {
394+
body: Block,
395+
names: Identifier[],
396+
expressions: Expression[],
397+
parent?: Node,
398+
tsOriginal?: ts.Node
399+
): ForInStatement
400+
{
390401
const statement = createNode(SyntaxKind.ForInStatement, parent, tsOriginal) as ForInStatement;
391402
setParent(body, statement);
392403
statement.body = body;
@@ -804,7 +815,12 @@ export function isTableIndexExpression(node: Node): node is TableIndexExpression
804815
}
805816

806817
export function createTableIndexExpression(
807-
table: Expression, index: Expression, parent?: Node, tsOriginal?: ts.Node): TableIndexExpression {
818+
table: Expression,
819+
index: Expression,
820+
parent?: Node,
821+
tsOriginal?: ts.Node
822+
): TableIndexExpression
823+
{
808824
const expression = createNode(SyntaxKind.TableIndexExpression, parent, tsOriginal) as TableIndexExpression;
809825
setParent(table, expression);
810826
expression.table = table;

src/LuaTransformer.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ export class LuaTransformer {
251251
public transformClassDeclaration(
252252
statement: ts.ClassLikeDeclaration,
253253
nameOverride?: tstl.Identifier
254-
): tstl.Statement[] {
254+
): tstl.Statement[]
255+
{
255256
let className = statement.name ? this.transformIdentifier(statement.name) : nameOverride;
256257
if (!className) {
257258
throw TSTLErrors.MissingClassName(statement);
@@ -2946,15 +2947,15 @@ export class LuaTransformer {
29462947
}
29472948

29482949
public transformStringLiteral(literal: ts.StringLiteralLike): tstl.StringLiteral {
2949-
const text = this.escapeString(literal.text);
2950+
const text = tsHelper.escapeString(literal.text);
29502951
return tstl.createStringLiteral(text);
29512952
}
29522953

29532954
public transformTemplateExpression(expression: ts.TemplateExpression): tstl.BinaryExpression {
2954-
const parts: tstl.Expression[] = [tstl.createStringLiteral(this.escapeString(expression.head.text))];
2955+
const parts: tstl.Expression[] = [tstl.createStringLiteral(tsHelper.escapeString(expression.head.text))];
29552956
expression.templateSpans.forEach(span => {
29562957
const expr = this.transformExpression(span.expression);
2957-
const text = tstl.createStringLiteral(this.escapeString(span.literal.text));
2958+
const text = tstl.createStringLiteral(tsHelper.escapeString(span.literal.text));
29582959

29592960
// tostring(expr).."text"
29602961
parts.push(tstl.createBinaryExpression(
@@ -3038,30 +3039,6 @@ export class LuaTransformer {
30383039
tstl.createStringLiteral(identifier.text));
30393040
}
30403041

3041-
public escapeString(text: string): string {
3042-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
3043-
const escapeSequences: Array<[RegExp, string]> = [
3044-
[/[\\]/g, "\\\\"],
3045-
[/[\']/g, "\\\'"],
3046-
[/[\`]/g, "\\\`"],
3047-
[/[\"]/g, "\\\""],
3048-
[/[\n]/g, "\\n"],
3049-
[/[\r]/g, "\\r"],
3050-
[/[\v]/g, "\\v"],
3051-
[/[\t]/g, "\\t"],
3052-
[/[\b]/g, "\\b"],
3053-
[/[\f]/g, "\\f"],
3054-
[/[\0]/g, "\\0"],
3055-
];
3056-
3057-
if (text.length > 0) {
3058-
for (const [regex, replacement] of escapeSequences) {
3059-
text = text.replace(regex, replacement);
3060-
}
3061-
}
3062-
return text;
3063-
}
3064-
30653042
public transformLuaLibFunction(func: LuaLibFeature, ...params: tstl.Expression[]): tstl.CallExpression {
30663043
this.importLuaLibFeature(func);
30673044
const functionIdentifier = tstl.createIdentifier(`__TS__${func}`);

0 commit comments

Comments
 (0)