Skip to content

Commit 8aad3ca

Browse files
committed
Remove TS prefix from 4-underscore-prefixed identifiers
1 parent 6d78e35 commit 8aad3ca

File tree

2 files changed

+61
-61
lines changed

2 files changed

+61
-61
lines changed

src/LuaTransformer.ts

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ export class LuaTransformer {
887887
tstl.createStringLiteral("__index")
888888
);
889889
if (tsHelper.hasGetAccessorInClassOrAncestor(statement, false, this.checker)) {
890-
// localClassName.prototype.__index = __TS_Index(localClassName.prototype)
890+
// localClassName.prototype.__index = __TS__Index(localClassName.prototype)
891891
const assignClassPrototypeIndex = tstl.createAssignmentStatement(
892892
classPrototypeIndex,
893893
this.transformLuaLibFunction(LuaLibFeature.Index, undefined, createClassPrototype()),
@@ -919,7 +919,7 @@ export class LuaTransformer {
919919
}
920920

921921
if (tsHelper.hasSetAccessorInClassOrAncestor(statement, false, this.checker)) {
922-
// localClassName.prototype.__newindex = __TS_NewIndex(localClassName.prototype)
922+
// localClassName.prototype.__newindex = __TS__NewIndex(localClassName.prototype)
923923
const classPrototypeNewIndex = tstl.createTableIndexExpression(
924924
createClassPrototype(),
925925
tstl.createStringLiteral("__newindex")
@@ -1388,11 +1388,11 @@ export class LuaTransformer {
13881388
continue;
13891389
}
13901390

1391-
// Binding patterns become ____TS_bindingPattern0, ____TS_bindingPattern1, etc as function parameters
1391+
// Binding patterns become ____bindingPattern0, ____bindingPattern1, etc as function parameters
13921392
// See transformFunctionBody for how these values are destructured
13931393
const paramName =
13941394
ts.isObjectBindingPattern(param.name) || ts.isArrayBindingPattern(param.name)
1395-
? tstl.createIdentifier(`____TS_bindingPattern${identifierIndex++}`)
1395+
? tstl.createIdentifier(`____bindingPattern${identifierIndex++}`)
13961396
: this.transformIdentifier(param.name as ts.Identifier);
13971397

13981398
// This parameter is a spread parameter (...param)
@@ -1441,7 +1441,7 @@ export class LuaTransformer {
14411441
let bindPatternIndex = 0;
14421442
for (const declaration of parameters) {
14431443
if (ts.isObjectBindingPattern(declaration.name) || ts.isArrayBindingPattern(declaration.name)) {
1444-
const identifier = tstl.createIdentifier(`____TS_bindingPattern${bindPatternIndex++}`);
1444+
const identifier = tstl.createIdentifier(`____bindingPattern${bindPatternIndex++}`);
14451445
if (declaration.initializer !== undefined) {
14461446
// Default binding parameter
14471447
headerStatements.push(
@@ -2336,14 +2336,14 @@ export class LuaTransformer {
23362336
// Declaration of new variable
23372337
const variables = statement.initializer.declarations[0].name;
23382338
if (ts.isArrayBindingPattern(variables) || ts.isObjectBindingPattern(variables)) {
2339-
valueVariable = tstl.createIdentifier("____TS_values");
2339+
valueVariable = tstl.createIdentifier("____values");
23402340
block.statements.unshift(this.transformForOfInitializer(statement.initializer, valueVariable));
23412341
} else {
23422342
valueVariable = this.transformIdentifier(variables);
23432343
}
23442344
} else {
23452345
// Assignment to existing variable
2346-
valueVariable = tstl.createIdentifier("____TS_value");
2346+
valueVariable = tstl.createIdentifier("____value");
23472347
block.statements.unshift(this.transformForOfInitializer(statement.initializer, valueVariable));
23482348
}
23492349

@@ -2387,11 +2387,11 @@ export class LuaTransformer {
23872387
}
23882388
} else {
23892389
// Variables NOT declared in for loop - catch iterator values in temps and assign
2390-
// for ____TS_value0 in ${iterable} do
2391-
// ${initializer} = ____TS_value0
2390+
// for ____value0 in ${iterable} do
2391+
// ${initializer} = ____value0
23922392
if (ts.isArrayLiteralExpression(statement.initializer)) {
23932393
const tmps = statement.initializer.elements.map((_, i) =>
2394-
tstl.createIdentifier(`____TS_value${i}`)
2394+
tstl.createIdentifier(`____value${i}`)
23952395
);
23962396
const assign = tstl.createAssignmentStatement(
23972397
statement.initializer.elements.map(
@@ -2421,9 +2421,9 @@ export class LuaTransformer {
24212421
);
24222422
} else {
24232423
// Destructuring or variable NOT declared in for loop
2424-
// for ____TS_value in ${iterator} do
2425-
// local ${initializer} = unpack(____TS_value)
2426-
const valueVariable = tstl.createIdentifier("____TS_value");
2424+
// for ____value in ${iterator} do
2425+
// local ${initializer} = unpack(____value)
2426+
const valueVariable = tstl.createIdentifier("____value");
24272427
const initializer = this.transformForOfInitializer(statement.initializer, valueVariable);
24282428
block.statements.splice(0, 0, initializer);
24292429
return tstl.createForInStatement(block, [valueVariable], [luaIterator]);
@@ -2446,9 +2446,9 @@ export class LuaTransformer {
24462446
);
24472447
} else {
24482448
// Destructuring or variable NOT declared in for loop
2449-
// for ____TS_value in __TS__iterator(${iterator}) do
2450-
// local ${initializer} = ____TS_value
2451-
const valueVariable = tstl.createIdentifier("____TS_value");
2449+
// for ____value in __TS__iterator(${iterator}) do
2450+
// local ${initializer} = ____value
2451+
const valueVariable = tstl.createIdentifier("____value");
24522452
const initializer = this.transformForOfInitializer(statement.initializer, valueVariable);
24532453
block.statements.splice(0, 0, initializer);
24542454
return tstl.createForInStatement(
@@ -2556,7 +2556,7 @@ export class LuaTransformer {
25562556
if (scope === undefined) {
25572557
throw TSTLErrors.UndefinedScope();
25582558
}
2559-
const switchName = `____TS_switch${scope.id}`;
2559+
const switchName = `____switch${scope.id}`;
25602560

25612561
const expression = this.transformExpression(statement.expression);
25622562
const switchVariable = tstl.createIdentifier(switchName);
@@ -2612,7 +2612,7 @@ export class LuaTransformer {
26122612
}
26132613

26142614
if (breakableScope.type === ScopeType.Switch) {
2615-
return tstl.createGotoStatement(`____TS_switch${breakableScope.id}_end`);
2615+
return tstl.createGotoStatement(`____switch${breakableScope.id}_end`);
26162616
} else {
26172617
return tstl.createBreakStatement(breakStatement);
26182618
}
@@ -2628,8 +2628,8 @@ export class LuaTransformer {
26282628
public transformTryStatement(statement: ts.TryStatement): StatementVisitResult {
26292629
const [tryBlock, tryScope] = this.transformScopeBlock(statement.tryBlock, ScopeType.Try);
26302630

2631-
const tryResultIdentfier = tstl.createIdentifier("____TS_try");
2632-
const returnValueIdentifier = tstl.createIdentifier("____TS_returnValue");
2631+
const tryResultIdentifier = tstl.createIdentifier("____try");
2632+
const returnValueIdentifier = tstl.createIdentifier("____returnValue");
26332633

26342634
const result: tstl.Statement[] = [];
26352635

@@ -2643,18 +2643,18 @@ export class LuaTransformer {
26432643
// try with catch
26442644
let [catchBlock, catchScope] = this.transformScopeBlock(statement.catchClause.block, ScopeType.Catch);
26452645
if (statement.catchClause.variableDeclaration) {
2646-
// Replace ____TS_returned with catch variable
2646+
// Replace ____returned with catch variable
26472647
returnedIdentifier = this.transformIdentifier(statement.catchClause.variableDeclaration
26482648
.name as ts.Identifier);
26492649
} else if (tryScope.functionReturned || catchScope.functionReturned) {
2650-
returnedIdentifier = tstl.createIdentifier("____TS_returned");
2650+
returnedIdentifier = tstl.createIdentifier("____returned");
26512651
}
26522652

2653-
const tryReturnIdentifiers = [tryResultIdentfier]; // ____TS_try
2653+
const tryReturnIdentifiers = [tryResultIdentifier]; // ____try
26542654
if (returnedIdentifier) {
2655-
tryReturnIdentifiers.push(returnedIdentifier); // ____TS_returned or catch variable
2655+
tryReturnIdentifiers.push(returnedIdentifier); // ____returned or catch variable
26562656
if (tryScope.functionReturned || catchScope.functionReturned) {
2657-
tryReturnIdentifiers.push(returnValueIdentifier); // ____TS_returnValue
2657+
tryReturnIdentifiers.push(returnValueIdentifier); // ____returnValue
26582658
returnCondition = tstl.cloneIdentifier(returnedIdentifier);
26592659
}
26602660
}
@@ -2672,19 +2672,19 @@ export class LuaTransformer {
26722672
catchBlock = tstl.createBlock([catchAssign]);
26732673
}
26742674
const notTryCondition = tstl.createUnaryExpression(
2675-
tstl.createParenthesizedExpression(tryResultIdentfier),
2675+
tstl.createParenthesizedExpression(tryResultIdentifier),
26762676
tstl.SyntaxKind.NotOperator
26772677
);
26782678
result.push(tstl.createIfStatement(notTryCondition, catchBlock));
26792679
} else if (tryScope.functionReturned) {
26802680
// try with return, but no catch
2681-
returnedIdentifier = tstl.createIdentifier("____TS_returned");
2682-
const returnedVariables = [tryResultIdentfier, returnedIdentifier, returnValueIdentifier];
2681+
returnedIdentifier = tstl.createIdentifier("____returned");
2682+
const returnedVariables = [tryResultIdentifier, returnedIdentifier, returnValueIdentifier];
26832683
result.push(tstl.createVariableDeclarationStatement(returnedVariables, tryCall));
26842684

2685-
// change return condition from '____TS_returned' to '____TS_try and ____TS_returned'
2685+
// change return condition from '____returned' to '____try and ____returned'
26862686
returnCondition = tstl.createBinaryExpression(
2687-
tstl.cloneIdentifier(tryResultIdentfier),
2687+
tstl.cloneIdentifier(tryResultIdentifier),
26882688
returnedIdentifier,
26892689
tstl.SyntaxKind.AndOperator
26902690
);
@@ -2699,9 +2699,9 @@ export class LuaTransformer {
26992699

27002700
if (returnCondition && returnedIdentifier) {
27012701
// With catch clause:
2702-
// if ____TS_returned then return ____TS_returnValue end
2702+
// if ____returned then return ____returnValue end
27032703
// No catch clause:
2704-
// if ____TS_try and ____TS_returned then return ____TS_returnValue end
2704+
// if ____try and ____returned then return ____returnValue end
27052705
const returnValues: tstl.Expression[] = [];
27062706
const parentTryCatch = this.findScope(ScopeType.Function | ScopeType.Try | ScopeType.Catch);
27072707
if (parentTryCatch && parentTryCatch.type !== ScopeType.Function) {
@@ -3083,7 +3083,7 @@ export class LuaTransformer {
30833083
} else {
30843084
right = [this.createUnpackCall(this.transformExpression(expression.right), expression.right)];
30853085
}
3086-
const tmps = left.map((_, i) => tstl.createIdentifier(`____TS_tmp${i}`));
3086+
const tmps = left.map((_, i) => tstl.createIdentifier(`____tmp${i}`));
30873087
const statements: tstl.Statement[] = [
30883088
tstl.createVariableDeclarationStatement(tmps, right),
30893089
tstl.createAssignmentStatement(left as tstl.AssignmentLeftHandSideExpression[], tmps),
@@ -3153,28 +3153,28 @@ export class LuaTransformer {
31533153
);
31543154
if (hasEffects && objExpression && indexExpression) {
31553155
// Complex property/element accesses need to cache object/index expressions to avoid repeating side-effects
3156-
// local __TS_obj, __TS_index = ${objExpression}, ${indexExpression};
3157-
const obj = tstl.createIdentifier("____TS_obj");
3158-
const index = tstl.createIdentifier("____TS_index");
3156+
// local __obj, __index = ${objExpression}, ${indexExpression};
3157+
const obj = tstl.createIdentifier("____obj");
3158+
const index = tstl.createIdentifier("____index");
31593159
const objAndIndexDeclaration = tstl.createVariableDeclarationStatement(
31603160
[obj, index],
31613161
[this.transformExpression(objExpression), this.transformExpression(indexExpression)]
31623162
);
31633163
const accessExpression = tstl.createTableIndexExpression(obj, index);
31643164

3165-
const tmp = tstl.createIdentifier("____TS_tmp");
3165+
const tmp = tstl.createIdentifier("____tmp");
31663166
right = tstl.createParenthesizedExpression(right);
31673167
let tmpDeclaration: tstl.VariableDeclarationStatement;
31683168
let assignStatement: tstl.AssignmentStatement;
31693169
if (isPostfix) {
3170-
// local ____TS_tmp = ____TS_obj[____TS_index];
3171-
// ____TS_obj[____TS_index] = ____TS_tmp ${replacementOperator} ${right};
3170+
// local ____tmp = ____obj[____index];
3171+
// ____obj[____index] = ____tmp ${replacementOperator} ${right};
31723172
tmpDeclaration = tstl.createVariableDeclarationStatement(tmp, accessExpression);
31733173
const operatorExpression = this.transformBinaryOperation(tmp, right, replacementOperator, expression);
31743174
assignStatement = tstl.createAssignmentStatement(accessExpression, operatorExpression);
31753175
} else {
3176-
// local ____TS_tmp = ____TS_obj[____TS_index] ${replacementOperator} ${right};
3177-
// ____TS_obj[____TS_index] = ____TS_tmp;
3176+
// local ____tmp = ____obj[____index] ${replacementOperator} ${right};
3177+
// ____obj[____index] = ____tmp;
31783178
const operatorExpression = this.transformBinaryOperation(
31793179
accessExpression,
31803180
right,
@@ -3184,18 +3184,18 @@ export class LuaTransformer {
31843184
tmpDeclaration = tstl.createVariableDeclarationStatement(tmp, operatorExpression);
31853185
assignStatement = tstl.createAssignmentStatement(accessExpression, tmp);
31863186
}
3187-
// return ____TS_tmp
3187+
// return ____tmp
31883188
return this.createImmediatelyInvokedFunctionExpression(
31893189
[objAndIndexDeclaration, tmpDeclaration, assignStatement],
31903190
tmp,
31913191
expression
31923192
);
31933193
} else if (isPostfix) {
31943194
// Postfix expressions need to cache original value in temp
3195-
// local ____TS_tmp = ${left};
3196-
// ${left} = ____TS_tmp ${replacementOperator} ${right};
3197-
// return ____TS_tmp
3198-
const tmpIdentifier = tstl.createIdentifier("____TS_tmp");
3195+
// local ____tmp = ${left};
3196+
// ${left} = ____tmp ${replacementOperator} ${right};
3197+
// return ____tmp
3198+
const tmpIdentifier = tstl.createIdentifier("____tmp");
31993199
const tmpDeclaration = tstl.createVariableDeclarationStatement(tmpIdentifier, left);
32003200
const operatorExpression = this.transformBinaryOperation(
32013201
tmpIdentifier,
@@ -3211,10 +3211,10 @@ export class LuaTransformer {
32113211
);
32123212
} else if (ts.isPropertyAccessExpression(lhs) || ts.isElementAccessExpression(lhs)) {
32133213
// Simple property/element access expressions need to cache in temp to avoid double-evaluation
3214-
// local ____TS_tmp = ${left} ${replacementOperator} ${right};
3215-
// ${left} = ____TS_tmp;
3216-
// return ____TS_tmp
3217-
const tmpIdentifier = tstl.createIdentifier("____TS_tmp");
3214+
// local ____tmp = ${left} ${replacementOperator} ${right};
3215+
// ${left} = ____tmp;
3216+
// return ____tmp
3217+
const tmpIdentifier = tstl.createIdentifier("____tmp");
32183218
const operatorExpression = this.transformBinaryOperation(left, right, replacementOperator, expression);
32193219
const tmpDeclaration = tstl.createVariableDeclarationStatement(tmpIdentifier, operatorExpression);
32203220
const assignStatement = this.transformAssignment(lhs, tmpIdentifier);
@@ -3321,10 +3321,10 @@ export class LuaTransformer {
33213321
);
33223322
if (hasEffects && objExpression && indexExpression) {
33233323
// Complex property/element accesses need to cache object/index expressions to avoid repeating side-effects
3324-
// local __TS_obj, __TS_index = ${objExpression}, ${indexExpression};
3325-
// ____TS_obj[____TS_index] = ____TS_obj[____TS_index] ${replacementOperator} ${right};
3326-
const obj = tstl.createIdentifier("____TS_obj");
3327-
const index = tstl.createIdentifier("____TS_index");
3324+
// local __obj, __index = ${objExpression}, ${indexExpression};
3325+
// ____obj[____index] = ____obj[____index] ${replacementOperator} ${right};
3326+
const obj = tstl.createIdentifier("____obj");
3327+
const index = tstl.createIdentifier("____index");
33283328
const objAndIndexDeclaration = tstl.createVariableDeclarationStatement(
33293329
[obj, index],
33303330
[this.transformExpression(objExpression), this.transformExpression(indexExpression)]
@@ -3991,14 +3991,14 @@ export class LuaTransformer {
39913991
const context = this.transformExpression(left.expression);
39923992
if (tsHelper.isExpressionWithEvaluationEffect(left.expression)) {
39933993
// Inject context parameter
3994-
transformedArguments.unshift(tstl.createIdentifier("____TS_self"));
3994+
transformedArguments.unshift(tstl.createIdentifier("____self"));
39953995

39963996
// Cache left-side if it has effects
3997-
//(function() local ____TS_self = context; return ____TS_self[argument](parameters); end)()
3997+
//(function() local ____self = context; return ____self[argument](parameters); end)()
39983998
const argument = ts.isElementAccessExpression(left)
39993999
? this.transformElementAccessArgument(left)
40004000
: tstl.createStringLiteral(left.name.text);
4001-
const selfIdentifier = tstl.createIdentifier("____TS_self");
4001+
const selfIdentifier = tstl.createIdentifier("____self");
40024002
const selfAssignment = tstl.createVariableDeclarationStatement(selfIdentifier, context);
40034003
const index = tstl.createTableIndexExpression(selfIdentifier, argument);
40044004
const callExpression = tstl.createCallExpression(index, transformedArguments);

test/translation/__snapshots__/transformation.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,25 +562,25 @@ f = function(____, x) return ({x = x}) end"
562562

563563
exports[`Transformation (tryCatch) 1`] = `
564564
"do
565-
local ____TS_try, er = pcall(
565+
local ____try, er = pcall(
566566
function()
567567
local a = 42
568568
end
569569
)
570-
if not ____TS_try then
570+
if not ____try then
571571
local b = \\"fail\\"
572572
end
573573
end"
574574
`;
575575

576576
exports[`Transformation (tryCatchFinally) 1`] = `
577577
"do
578-
local ____TS_try, er = pcall(
578+
local ____try, er = pcall(
579579
function()
580580
local a = 42
581581
end
582582
)
583-
if not ____TS_try then
583+
if not ____try then
584584
local b = \\"fail\\"
585585
end
586586
do

0 commit comments

Comments
 (0)