ts-budgie
Version:
Converts TypeScript code to Budgie.
82 lines • 3.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var visitorsBag_1 = require("./visitorsBag");
/**
* Routes visitors for node types.
*/
var NodeVisitRouter = /** @class */ (function () {
/**
* Initializes a new instance of the NodeVisitRouter.
*
* @param dependencies Dependencies to be used for initialization.
*/
function NodeVisitRouter(dependencies) {
this.dependencies = dependencies;
this.visitorsBag = new visitorsBag_1.VisitorsBag({
aliaser: dependencies.aliaser,
casing: dependencies.casing,
nameSplitter: dependencies.nameSplitter,
router: this,
sourceFile: dependencies.sourceFile,
typeChecker: dependencies.typeChecker,
variableUsage: dependencies.variableUsage,
visitorContext: dependencies.visitorContext,
});
}
/**
* Retrieves the output transformations for a node.
*
* @param node Node to retrieve transformations for.
* @returns Output transformations for the node.
*/
NodeVisitRouter.prototype.recurseIntoNode = function (node) {
var creator = this.dependencies.visitorCreatorsBag.getCreator(node.kind);
if (creator === undefined) {
return this.recurseIntoNodes(node.getChildren());
}
return this.visitorsBag.createVisitor(creator).visit(node);
};
/**
* Retrieves the Budgie output for a set of nodes.
*
* @param node Node to transform.
* @param parent Common parent of the nodes.
* @returns Transformed Budgie output for the nodes.
*/
NodeVisitRouter.prototype.recurseIntoNodes = function (nodes) {
var transformations = [];
for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
var node = nodes_1[_i];
transformations.push.apply(transformations, this.recurseIntoNode(node));
}
return transformations;
};
/**
* Retrieves the Budgie output for an inline value.
*
* @param node Node to transform.
* @returns Transformed Budgie output for the inline value.
*/
NodeVisitRouter.prototype.recurseIntoValue = function (node) {
var subTransformations = this.recurseIntoNode(node);
var sourceFile = this.dependencies.sourceFile;
return this.dependencies.printer.printTransformations(sourceFile.getText(sourceFile), subTransformations)[0];
};
/**
* Retrieves the Budgie output for a set of inline values.
*
* @param nodes Nodes to transform.
* @returns Transformed Budgie output for the inline values.
*/
NodeVisitRouter.prototype.recurseIntoValues = function (nodes) {
var values = [];
for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
var node = nodes_2[_i];
values.push(this.recurseIntoValue(node));
}
return values;
};
return NodeVisitRouter;
}());
exports.NodeVisitRouter = NodeVisitRouter;
//# sourceMappingURL=router.js.map