-
Notifications
You must be signed in to change notification settings - Fork 7
/
enumModule.ts
65 lines (54 loc) · 1.87 KB
/
enumModule.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { CommonjsModule } from './commonjsModule';
import { ModuleRegistry } from './moduleRegistry';
import { IEnumModule, LogObj, NsMap } from '../../types';
export class EnumModule extends CommonjsModule implements IEnumModule {
public readonly isDerived: boolean = true;
public constructor(
className: string,
sourceFileName: string,
targetFileName: string,
_namespaces: NsMap,
serverFilesRoot: string,
builtinsPath: string,
log: LogObj,
originalIdentName?: string,
ancestorModule?: CommonjsModule
) {
super(className + 'Enum', sourceFileName, targetFileName, _namespaces, serverFilesRoot, builtinsPath, log, originalIdentName, ancestorModule);
}
// For removing dupes during second pass of codegen
public clearStatements() {
this._constructorStatements = [];
this._hoistedContent = new Set();
this._specialVars = {};
}
public registerSpecialVar() { /* Makes no sense: override, do nothing */ }
public checkSpecialVarIdentifier(): boolean {
/* Makes no sense: override, do nothing */
return false;
}
public addMethod() {
/* Makes no sense: override, do nothing */
}
public addProperty() {
/* Makes no sense: override, do nothing */
}
public addStaticConst(identifier: string, value: string, inferredType: string) {
const doc = `/**
* @var ${inferredType} ${identifier}
*/`;
this._hoistedContent.add(`${doc ? doc + '\n' : ''}const ${identifier} = ${value};`);
}
public generateContent() {
const fullyQualifiedNamespace = ModuleRegistry.pathToNamespace(this.targetFileName);
return `<?php
/* NOTICE: autogenerated file; Do not edit by hand */
namespace ${fullyQualifiedNamespace};
use ${this._namespaces.builtins}\\CJSModule;
class ${this.className} extends CJSModule {
${Array.from(this._hoistedContent.values()).join('\n')}
private function __construct() {}
}
`;
}
}