@azure-tools/typespec-apiview
Version:
Library for emitting APIView token files from TypeSpec
40 lines • 1.21 kB
JavaScript
export function reviewLineText(line, indent) {
const indentString = " ".repeat(indent);
let tokenText = "";
for (const token of line.Tokens) {
tokenText += reviewTokenText(token, tokenText);
}
const childrenText = line.Children.map(c => reviewLineText(c, indent + 2)).join("\n");
if (childrenText !== "") {
return `${indentString}${tokenText}\n${childrenText}`;
}
else {
return `${indentString}${tokenText}`;
}
}
function reviewTokenText(token, preview) {
const previewEndsInSpace = preview.endsWith(" ");
const hasSuffixSpace = token.HasSuffixSpace !== undefined ? token.HasSuffixSpace : true;
const suffixSpace = hasSuffixSpace ? " " : "";
const prefixSpace = (token.HasPrefixSpace && !previewEndsInSpace) ? " " : "";
const value = token.Value;
return `${prefixSpace}${value}${suffixSpace}`;
}
export class NamespaceStack {
constructor() {
this.stack = new Array();
}
push(val) {
this.stack.push(val);
}
pop() {
return this.stack.pop();
}
value() {
return this.stack.join(".");
}
reset() {
this.stack = Array();
}
}
//# sourceMappingURL=util.js.map