( modifiers: readonly modifierKeys[] | readonly ts.Modifier[] | undefined, name: string, question: boolean, type: ts.TypeNode )
| 33 | } |
| 34 | |
| 35 | export function propertySignature( |
| 36 | modifiers: readonly modifierKeys[] | readonly ts.Modifier[] | undefined, |
| 37 | name: string, |
| 38 | question: boolean, |
| 39 | type: ts.TypeNode |
| 40 | ): ts.PropertySignature { |
| 41 | |
| 42 | var id: Identifier | StringLiteral = identifier(name); |
| 43 | |
| 44 | // Property names can be quoted if they are not valid identifiers. |
| 45 | // This is things like hyphens, numbers first, etc. |
| 46 | // TODO: If this regex exists in the typescript compiler, use that instead. |
| 47 | if(!(/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name))) { |
| 48 | id = ts.factory.createStringLiteral(name); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | return ts.factory.createPropertySignature( |
| 53 | modifiers?.map((m) => modifier(m)), |
| 54 | id, |
| 55 | question ? questionToken() : undefined, |
| 56 | type |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | export function questionToken(): ts.QuestionToken { |
| 61 | return ts.factory.createToken(ts.SyntaxKind.QuestionToken); |
no test coverage detected
searching dependent graphs…