Files
protocol/src/lib/converter/nodes/module.ts
2016-10-11 13:51:29 -07:00

46 lines
1.5 KiB
TypeScript

import * as ts from "typescript";
import {Reflection, ReflectionKind, ReflectionFlag, ProjectReflection} from "../../models/index";
import {createDeclaration} from "../factories/index";
import {Context} from "../context";
import {Component, ConverterNodeComponent} from "../components";
@Component({name:'node:module'})
export class ModuleConverter extends ConverterNodeComponent<ts.ModuleDeclaration>
{
/**
* List of supported TypeScript syntax kinds.
*/
supports:ts.SyntaxKind[] = [
ts.SyntaxKind.ModuleDeclaration
];
/**
* Analyze the given module node and create a suitable reflection.
*
* @param context The context object describing the current state the converter is in.
* @param node The module node that should be analyzed.
* @return The resulting reflection or NULL.
*/
convert(context:Context, node:ts.ModuleDeclaration):Reflection {
var parent = context.scope;
var reflection = createDeclaration(context, node, ReflectionKind.Module);
context.withScope(reflection, () => {
var opt = context.getCompilerOptions();
if (parent instanceof ProjectReflection && !context.isDeclaration &&
(!module || module.valueOf() === ts.ModuleKind.None.valueOf())) {
reflection.setFlag(ReflectionFlag.Exported);
}
if (node.body) {
this.owner.convertNode(context, node.body);
}
});
return reflection;
}
}