File tree 3 files changed +38
-4
lines changed 3 files changed +38
-4
lines changed Original file line number Diff line number Diff line change
1
+ import { GetterDeclaration , SetterDeclaration } from '../declarations/AccessorDeclaration' ;
1
2
import { Declaration } from '../declarations/Declaration' ;
2
3
import { MethodDeclaration } from '../declarations/MethodDeclaration' ;
3
4
import { ParameterDeclaration } from '../declarations/ParameterDeclaration' ;
@@ -11,6 +12,7 @@ import { NamedImport } from '../imports/NamedImport';
11
12
import { NamespaceImport } from '../imports/NamespaceImport' ;
12
13
import { StringImport } from '../imports/StringImport' ;
13
14
import { SymbolSpecifier } from '../SymbolSpecifier' ;
15
+ import { generateAccessorDeclaration } from './typescript-generators/accessorDeclaration' ;
14
16
import { generateExternalModuleImport } from './typescript-generators/externalModuleImport' ;
15
17
import { generateMethodDeclaration } from './typescript-generators/methodDeclaration' ;
16
18
import { generateNamedImport } from './typescript-generators/namedImport' ;
@@ -46,6 +48,8 @@ export const GENERATORS: Generators = {
46
48
[ NamedImport . name ] : generateNamedImport ,
47
49
[ NamespaceImport . name ] : generateNamespaceImport ,
48
50
[ StringImport . name ] : generateStringImport ,
51
+ [ SetterDeclaration . name ] : generateAccessorDeclaration ,
52
+ [ GetterDeclaration . name ] : generateAccessorDeclaration ,
49
53
} ;
50
54
51
55
/**
Original file line number Diff line number Diff line change
1
+ import { AccessorDeclaration , SetterDeclaration } from '../../declarations/AccessorDeclaration' ;
2
+ import { getVisibilityText } from '../../declarations/DeclarationVisibility' ;
3
+ import { TypescriptGenerationOptions } from '../TypescriptGenerationOptions' ;
4
+
5
+ /**
6
+ * Generates typescript code for a class property accessor.
7
+ *
8
+ * @export
9
+ * @param {AccessorDeclaration } accessor
10
+ * @param {TypescriptGenerationOptions } { tabSize }
11
+ * @returns {string }
12
+ */
13
+ export function generateAccessorDeclaration (
14
+ accessor : AccessorDeclaration ,
15
+ { tabSize } : TypescriptGenerationOptions ,
16
+ ) : string {
17
+ const tabs = Array ( tabSize + 1 ) . join ( ' ' ) ;
18
+ let definitionLine : string ;
19
+ if ( accessor instanceof SetterDeclaration ) {
20
+ definitionLine = `${ tabs } ${ accessor . visibility !== undefined ? getVisibilityText ( accessor . visibility ) + ' ' : '' } ` +
21
+ `set ${ accessor . name } (value${ accessor . type ? `: ${ accessor . type } ` : '' } ) {` ;
22
+ } else {
23
+ definitionLine = `${ tabs } ${ accessor . visibility !== undefined ? getVisibilityText ( accessor . visibility ) + ' ' : '' } ` +
24
+ `get ${ accessor . name } ()${ accessor . type ? `: ${ accessor . type } ` : '' } {` ;
25
+ }
26
+
27
+ return `${ definitionLine }
28
+ ${ tabs } ${ tabs } throw new Error('Not implemented yet.');
29
+ ${ tabs } }\n`;
30
+ }
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ import { generateParameterDeclaration } from './parameterDeclaration';
5
5
6
6
/**
7
7
* Generates typescript code for a method declaration.
8
- *
8
+ *
9
9
* @export
10
- * @param {MethodDeclaration } method
11
- * @param {TypescriptGenerationOptions } { tabSize }
12
- * @returns {string }
10
+ * @param {MethodDeclaration } method
11
+ * @param {TypescriptGenerationOptions } { tabSize }
12
+ * @returns {string }
13
13
*/
14
14
export function generateMethodDeclaration ( method : MethodDeclaration , { tabSize } : TypescriptGenerationOptions ) : string {
15
15
const intend = Array ( tabSize + 1 ) . join ( ' ' ) ;
You can’t perform that action at this time.
0 commit comments