Skip to content

Commit 83ab3d4

Browse files
committed
Remove use of escapedText and __String
1 parent e144a53 commit 83ab3d4

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

src/LuaAST.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ export function isStringLiteral(node: Node): node is StringLiteral {
614614
return node.kind === SyntaxKind.StringLiteral;
615615
}
616616

617-
export function createStringLiteral(value: string | ts.__String, tsOriginal?: ts.Node, parent?: Node): StringLiteral {
617+
export function createStringLiteral(value: string, tsOriginal?: ts.Node, parent?: Node): StringLiteral {
618618
const expression = createNode(SyntaxKind.StringLiteral, tsOriginal, parent) as StringLiteral;
619619
expression.value = value as string;
620620
return expression;
@@ -839,14 +839,14 @@ export function isIdentifier(node: Node): node is Identifier {
839839
}
840840

841841
export function createIdentifier(
842-
text: string | ts.__String,
842+
text: string,
843843
tsOriginal?: ts.Node,
844844
symbolId?: SymbolId,
845845
originalName?: string,
846846
parent?: Node
847847
): Identifier {
848848
const expression = createNode(SyntaxKind.Identifier, tsOriginal, parent) as Identifier;
849-
expression.text = text as string;
849+
expression.text = text;
850850
expression.symbolId = symbolId;
851851
expression.originalName = originalName;
852852
return expression;

src/LuaTransformer.ts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,7 +3878,7 @@ export class LuaTransformer {
38783878
// if ownerType inherits from an array, use array calls where appropriate
38793879
if (
38803880
tsHelper.isArrayType(ownerType, this.checker, this.program) &&
3881-
tsHelper.isDefaultArrayCallMethodName(node.expression.name.escapedText as string)
3881+
tsHelper.isDefaultArrayCallMethodName(node.expression.name.text)
38823882
) {
38833883
return this.transformArrayCallExpression(node);
38843884
}
@@ -3894,7 +3894,7 @@ export class LuaTransformer {
38943894
return tstl.createCallExpression(this.transformExpression(node.expression), parameters);
38953895
} else {
38963896
// Replace last . with : here
3897-
const name = node.expression.name.escapedText;
3897+
const name = node.expression.name.text;
38983898
if (name === "toString") {
38993899
const toStringIdentifier = tstl.createIdentifier("tostring");
39003900
return tstl.createCallExpression(
@@ -4096,7 +4096,7 @@ export class LuaTransformer {
40964096

40974097
// Transpile a Math._ property
40984098
protected transformMathExpression(identifier: ts.Identifier): tstl.Expression {
4099-
const name = identifier.escapedText as string;
4099+
const name = identifier.text;
41004100
switch (name) {
41014101
case "PI":
41024102
const property = tstl.createStringLiteral("pi");
@@ -4122,7 +4122,7 @@ export class LuaTransformer {
41224122
const expression = node.expression as ts.PropertyAccessExpression;
41234123
const signature = this.checker.getResolvedSignature(node);
41244124
const params = this.transformArguments(node.arguments, signature);
4125-
const expressionName = expression.name.escapedText as string;
4125+
const expressionName = expression.name.text;
41264126
switch (expressionName) {
41274127
// math.tan(x / y)
41284128
case "atan2": {
@@ -4192,21 +4192,21 @@ export class LuaTransformer {
41924192

41934193
// Transpile access of string properties, only supported properties are allowed
41944194
protected transformStringProperty(node: ts.PropertyAccessExpression): tstl.UnaryExpression {
4195-
switch (node.name.escapedText) {
4195+
switch (node.name.text) {
41964196
case "length":
41974197
let expression = this.transformExpression(node.expression);
41984198
if (ts.isTemplateExpression(node.expression)) {
41994199
expression = tstl.createParenthesizedExpression(expression);
42004200
}
42014201
return tstl.createUnaryExpression(expression, tstl.SyntaxKind.LengthOperator, node);
42024202
default:
4203-
throw TSTLErrors.UnsupportedProperty("string", node.name.escapedText as string, node);
4203+
throw TSTLErrors.UnsupportedProperty("string", node.name.text, node);
42044204
}
42054205
}
42064206

42074207
// Transpile access of array properties, only supported properties are allowed
42084208
protected transformArrayProperty(node: ts.PropertyAccessExpression): tstl.UnaryExpression | undefined {
4209-
switch (node.name.escapedText) {
4209+
switch (node.name.text) {
42104210
case "length":
42114211
let expression = this.transformExpression(node.expression);
42124212
if (tstl.isTableExpression(expression)) {
@@ -4219,12 +4219,12 @@ export class LuaTransformer {
42194219
}
42204220

42214221
protected transformLuaTableProperty(node: ts.PropertyAccessExpression): tstl.UnaryExpression {
4222-
switch (node.name.escapedText) {
4222+
switch (node.name.text) {
42234223
case "length":
42244224
const propertyAccessExpression = this.transformExpression(node.expression);
42254225
return tstl.createUnaryExpression(propertyAccessExpression, tstl.SyntaxKind.LengthOperator, node);
42264226
default:
4227-
throw TSTLErrors.UnsupportedProperty("LuaTable", node.name.escapedText as string, node);
4227+
throw TSTLErrors.UnsupportedProperty("LuaTable", node.name.text, node);
42284228
}
42294229
}
42304230

@@ -4281,7 +4281,7 @@ export class LuaTransformer {
42814281
const params = this.transformArguments(node.arguments, signature);
42824282
const caller = this.transformExpression(expression.expression);
42834283

4284-
const expressionName = expression.name.escapedText as string;
4284+
const expressionName = expression.name.text;
42854285
switch (expressionName) {
42864286
case "replace":
42874287
return this.transformLuaLibFunction(LuaLibFeature.StringReplace, node, caller, ...params);
@@ -4424,7 +4424,7 @@ export class LuaTransformer {
44244424

44254425
// Transpile a String._ property
44264426
protected transformStringExpression(identifier: ts.Identifier): ExpressionVisitResult {
4427-
const identifierString = identifier.escapedText as string;
4427+
const identifierString = identifier.text;
44284428

44294429
switch (identifierString) {
44304430
case "fromCharCode":
@@ -4445,7 +4445,7 @@ export class LuaTransformer {
44454445
protected transformObjectCallExpression(expression: ts.CallExpression): ExpressionVisitResult {
44464446
const method = expression.expression as ts.PropertyAccessExpression;
44474447
const parameters = this.transformArguments(expression.arguments);
4448-
const methodName = method.name.escapedText;
4448+
const methodName = method.name.text;
44494449

44504450
switch (methodName) {
44514451
case "assign":
@@ -4465,7 +4465,7 @@ export class LuaTransformer {
44654465

44664466
protected transformConsoleCallExpression(expression: ts.CallExpression): ExpressionVisitResult {
44674467
const method = expression.expression as ts.PropertyAccessExpression;
4468-
const methodName = method.name.escapedText;
4468+
const methodName = method.name.text;
44694469
const signature = this.checker.getResolvedSignature(expression);
44704470

44714471
switch (methodName) {
@@ -4543,7 +4543,7 @@ export class LuaTransformer {
45434543
const method = expression.expression as ts.PropertyAccessExpression;
45444544
const signature = this.checker.getResolvedSignature(expression);
45454545
const parameters = this.transformArguments(expression.arguments, signature);
4546-
const methodName = method.name.escapedText;
4546+
const methodName = method.name.text;
45474547

45484548
switch (methodName) {
45494549
case "for":
@@ -4561,7 +4561,7 @@ export class LuaTransformer {
45614561
protected transformNumberCallExpression(expression: ts.CallExpression): tstl.CallExpression {
45624562
const method = expression.expression as ts.PropertyAccessExpression;
45634563
const parameters = this.transformArguments(expression.arguments);
4564-
const methodName = method.name.escapedText;
4564+
const methodName = method.name.text;
45654565

45664566
switch (methodName) {
45674567
case "isNaN":
@@ -4577,7 +4577,7 @@ export class LuaTransformer {
45774577
expression: ts.CallExpression & { expression: ts.PropertyAccessExpression },
45784578
isWithinExpressionStatement: boolean
45794579
): void {
4580-
const methodName = expression.expression.name.escapedText;
4580+
const methodName = expression.expression.name.text;
45814581
if (expression.arguments.some(argument => ts.isSpreadElement(argument))) {
45824582
throw TSTLErrors.ForbiddenLuaTableUseException("Arguments cannot be spread.", expression);
45834583
}
@@ -4607,9 +4607,9 @@ export class LuaTransformer {
46074607
expression: { expression: ts.PropertyAccessExpression };
46084608
}
46094609
): tstl.VariableDeclarationStatement | tstl.AssignmentStatement {
4610-
const methodName = node.expression.expression.name.escapedText;
4610+
const methodName = node.expression.expression.name.text;
46114611
const signature = this.checker.getResolvedSignature(node.expression);
4612-
const tableName = (node.expression.expression.expression as ts.Identifier).escapedText;
4612+
const tableName = (node.expression.expression.expression as ts.Identifier).text;
46134613
const luaTable = tstl.createIdentifier(tableName);
46144614
const params = this.transformArguments((node.expression as ts.CallExpression).arguments, signature);
46154615

@@ -4635,9 +4635,9 @@ export class LuaTransformer {
46354635
expression: ts.CallExpression & { expression: ts.PropertyAccessExpression }
46364636
): tstl.Expression {
46374637
const method = expression.expression;
4638-
const methodName = method.name.escapedText;
4638+
const methodName = method.name.text;
46394639
const signature = this.checker.getResolvedSignature(expression);
4640-
const tableName = (method.expression as ts.Identifier).escapedText;
4640+
const tableName = (method.expression as ts.Identifier).text;
46414641
const luaTable = tstl.createIdentifier(tableName);
46424642
const params = this.transformArguments(expression.arguments, signature);
46434643

@@ -4654,7 +4654,7 @@ export class LuaTransformer {
46544654
const signature = this.checker.getResolvedSignature(node);
46554655
const params = this.transformArguments(node.arguments, signature);
46564656
const caller = this.transformExpression(expression.expression);
4657-
const expressionName = expression.name.escapedText;
4657+
const expressionName = expression.name.text;
46584658
switch (expressionName) {
46594659
case "concat":
46604660
return this.transformLuaLibFunction(LuaLibFeature.ArrayConcat, node, caller, ...params);
@@ -4708,7 +4708,7 @@ export class LuaTransformer {
47084708
case "flatMap":
47094709
return this.transformLuaLibFunction(LuaLibFeature.ArrayFlatMap, node, caller, ...params);
47104710
default:
4711-
throw TSTLErrors.UnsupportedProperty("array", expressionName as string, node);
4711+
throw TSTLErrors.UnsupportedProperty("array", expressionName, node);
47124712
}
47134713
}
47144714

@@ -4721,7 +4721,7 @@ export class LuaTransformer {
47214721
const signature = this.checker.getResolvedSignature(node);
47224722
const params = this.transformArguments(node.arguments, signature);
47234723
const caller = this.transformExpression(expression.expression);
4724-
const expressionName = expression.name.escapedText;
4724+
const expressionName = expression.name.text;
47254725
switch (expressionName) {
47264726
case "apply":
47274727
return this.transformLuaLibFunction(LuaLibFeature.FunctionApply, node, caller, ...params);
@@ -4730,7 +4730,7 @@ export class LuaTransformer {
47304730
case "call":
47314731
return this.transformLuaLibFunction(LuaLibFeature.FunctionCall, node, caller, ...params);
47324732
default:
4733-
throw TSTLErrors.UnsupportedProperty("function", expressionName as string, node);
4733+
throw TSTLErrors.UnsupportedProperty("function", expressionName, node);
47344734
}
47354735
}
47364736

@@ -4827,9 +4827,7 @@ export class LuaTransformer {
48274827
strings.map(partialString => tstl.createTableFieldExpression(tstl.createStringLiteral(partialString)))
48284828
);
48294829
const rawStringArray = tstl.createTableExpression(
4830-
rawStrings.map(stringLiteral =>
4831-
tstl.createTableFieldExpression(tstl.createStringLiteral(stringLiteral))
4832-
)
4830+
rawStrings.map(stringLiteral => tstl.createTableFieldExpression(tstl.createStringLiteral(stringLiteral)))
48334831
);
48344832
stringTableLiteral.fields.push(
48354833
tstl.createTableFieldExpression(rawStringArray, tstl.createStringLiteral("raw"))
@@ -5352,7 +5350,7 @@ export class LuaTransformer {
53525350
const leftType = this.checker.getTypeAtLocation(node.left.expression);
53535351
const decorators = tsHelper.getCustomDecorators(leftType, this.checker);
53545352
if (decorators.has(DecoratorKind.LuaTable)) {
5355-
switch (node.left.name.escapedText as string) {
5353+
switch (node.left.name.text) {
53565354
case "length":
53575355
throw TSTLErrors.ForbiddenLuaTableUseException(
53585356
`A LuaTable object's length cannot be re-assigned.`,

0 commit comments

Comments
 (0)