|
1 | 1 | import * as ts from "typescript"; |
2 | 2 | import * as lua from "../../../../LuaAST"; |
3 | | -import { createSelfIdentifier } from "../../../utils/lua-ast"; |
4 | | -import { transformParameters, transformFunctionBodyStatements, transformFunctionBodyHeader } from "../../function"; |
5 | 3 | import { TransformationContext } from "../../../context"; |
| 4 | +import { createSelfIdentifier } from "../../../utils/lua-ast"; |
| 5 | +import { popScope, pushScope, ScopeType } from "../../../utils/scope"; |
| 6 | +import { transformFunctionBodyHeader, transformFunctionBodyStatements, transformParameters } from "../../function"; |
6 | 7 | import { transformIdentifier } from "../../identifier"; |
7 | 8 | import { transformClassInstanceFields } from "./fields"; |
8 | | -import { pushScope, ScopeType, popScope } from "../../../utils/scope"; |
9 | 9 |
|
10 | 10 | export function createConstructorName(className: lua.Identifier): lua.TableIndexExpression { |
11 | 11 | return lua.createTableIndexExpression( |
@@ -66,13 +66,15 @@ export function transformConstructorDeclaration( |
66 | 66 |
|
67 | 67 | // Add in instance field declarations |
68 | 68 | for (const declaration of constructorFieldsDeclarations) { |
69 | | - const declarationName = transformIdentifier(context, declaration.name as ts.Identifier); |
70 | | - // self.declarationName = declarationName |
71 | | - const assignment = lua.createAssignmentStatement( |
72 | | - lua.createTableIndexExpression(createSelfIdentifier(), lua.createStringLiteral(declarationName.text)), |
73 | | - declarationName |
74 | | - ); |
75 | | - bodyWithFieldInitializers.push(assignment); |
| 69 | + if (ts.isIdentifier(declaration.name)) { |
| 70 | + // self.declarationName = declarationName |
| 71 | + const assignment = lua.createAssignmentStatement( |
| 72 | + lua.createTableIndexExpression(createSelfIdentifier(), lua.createStringLiteral(declaration.name.text)), |
| 73 | + transformIdentifier(context, declaration.name) |
| 74 | + ); |
| 75 | + bodyWithFieldInitializers.push(assignment); |
| 76 | + } |
| 77 | + // else { TypeScript error: A parameter property may not be declared using a binding pattern } |
76 | 78 | } |
77 | 79 |
|
78 | 80 | bodyWithFieldInitializers.push(...classInstanceFields); |
|
0 commit comments