UNPKG

@ui5/ts-interface-generator

Version:

Generator for TypeScript type definitions for custom UI5 controls implemented in TypeScript

18 lines 1.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const typescript_1 = __importDefault(require("typescript")); function astToString(ast) { const file = typescript_1.default.createSourceFile("_.d.ts", "", typescript_1.default.ScriptTarget.Latest, false, typescript_1.default.ScriptKind.TS); // @ts-ignore this assignment works file.statements = typescript_1.default.factory.createNodeArray(ast); // using a *printer* for simplicity; TODO: the TypeScript formatter API would be more appropriate const printer = typescript_1.default.createPrinter({ newLine: typescript_1.default.NewLineKind.LineFeed }); let result = printer.printNode(typescript_1.default.EmitHint.Unspecified, file, undefined); result = result.replace(/\s*\/\/\n/g, "\n"); // replace dummy comments with just a linebreak return result; } exports.default = astToString; //# sourceMappingURL=astToString.js.map