Skip to content

Commit

Permalink
Linting and formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
zorkow committed May 19, 2022
1 parent b6b394f commit ba19057
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 34 deletions.
5 changes: 3 additions & 2 deletions ts/common/dom_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,16 +318,17 @@ export function tagName(node: Element): string {
* Deep clone of an Element, depending on the environment.
*
* @param node The element to be cloned.
* @return The deep clone.
* @returns The deep clone.
*/
export function cloneNode(node: Element): Element {
return node.cloneNode(true) as Element;
}

/**
* Serializes and XML element.
*
* @param node The node to serialize.
* @return The serialized expression.
* @returns The serialized expression.
*/
export function serializeXml(node: Element): string {
const xmls = new SystemExternal.xmldom.XMLSerializer();
Expand Down
6 changes: 4 additions & 2 deletions ts/common/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export class Variables {
*/
public static ensureLocale(loc: string, def: string): string {
if (!Variables.LOCALES.get(loc)) {
console.error(`Locale ${loc} does not exist! Using`
+ ` ${Variables.LOCALES.get(def)} instead.`);
console.error(
`Locale ${loc} does not exist! Using` +
` ${Variables.LOCALES.get(def)} instead.`
);
return def;
}
return loc;
Expand Down
1 change: 0 additions & 1 deletion ts/common/xpath_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,3 @@ export function updateEvaluator(node: Element) {
xpath.currentDocument = node.ownerDocument;
}
}

2 changes: 1 addition & 1 deletion ts/l10n/numbers/numbers_da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function hundredsToWords_(num: number, ordinal = false): string {
* Translates a number of up to twelve digits into a string representation.
*
* @param num The number to translate.
* @param ordinal Are we computing an ordinal?
* @param ordinal Are we computing an ordinal?
* @returns The string representation of that number.
*/
function numberToWords(num: number, ordinal = false): string {
Expand Down
7 changes: 3 additions & 4 deletions ts/rule_engine/speech_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,22 +497,21 @@ export class Precondition {
* Retrieves a preset priority if one is defined. Note that this priority will
* supersede the heuristically computed priorities!
*
* @return The priority number.
* @returns The priority number.
*/
private presetPriority(): [boolean, number] {
if (!this.constraints.length) {
return [false, 0];
}
const last = this.constraints[this.constraints.length - 1].
match(/^priority=(.*$)/);
const last =
this.constraints[this.constraints.length - 1].match(/^priority=(.*$)/);
if (!last) {
return [false, 0];
}
this.constraints.pop();
const numb = parseFloat(last[1]);
return [true, isNaN(numb) ? 0 : numb];
}

}

/**
Expand Down
10 changes: 5 additions & 5 deletions ts/semantic_tree/semantic_skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,20 +384,21 @@ export class SemanticSkeleton {

/**
* Checks if a node is a root of a subtree.
*
* @param id The id number to check.
* @returns True if the id is the root of the skeleton.
*/
public isRoot(id: number): boolean {
const level = this.levelsMap[id];
return id === level[0];
}


public directChildren(id: number): number[] {
if (!this.isRoot(id)) {
return [];
}
const level = this.levelsMap[id];
return level.slice(1).map(child => {
return level.slice(1).map((child) => {
if (SemanticSkeleton.simpleCollapseStructure(child)) {
return child;
}
Expand All @@ -417,16 +418,15 @@ export class SemanticSkeleton {
nodes.push(tree as number);
return;
}
tree = (tree as Sexp[]);
tree = tree as Sexp[];
if (SemanticSkeleton.contentCollapseStructure(tree)) {
tree = tree.slice(1);
}
tree.forEach(x => subtreeNodes_(x, nodes));
tree.forEach((x) => subtreeNodes_(x, nodes));
};
const level = this.levelsMap[id];
const subtree: number[] = [];
subtreeNodes_(level.slice(1), subtree);
return subtree;
}

}
37 changes: 21 additions & 16 deletions ts/walker/abstract_walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,11 @@ export abstract class AbstractWalker<T> implements Walker {
this.skeleton.populate();
this.focus_ = this.singletonFocus(this.rootId);
this.levels = this.initLevels();
SpeechGeneratorUtil.connectMactions(this.node, this.getXml(), this.rebuilt_.xml);
SpeechGeneratorUtil.connectMactions(
this.node,
this.getXml(),
this.rebuilt_.xml
);
}

/**
Expand Down Expand Up @@ -594,23 +598,24 @@ export abstract class AbstractWalker<T> implements Walker {

/**
* Retrieves all root nodes of the visual subtrees.
*
* @param id The id of the root node.
* @return The list of ids.
* @returns The list of ids.
*/
private retrieveVisuals(id: string): string[] {
if (!this.skeleton) {
return [id];
}
let num = parseInt(id, 10);
let semStree = this.skeleton.subtreeNodes(num);
const num = parseInt(id, 10);
const semStree = this.skeleton.subtreeNodes(num);
if (!semStree.length) {
return [id];
}
semStree.unshift(num);
const mmlStree: {[num: number]: boolean} = {};
const mmlStree: { [num: number]: boolean } = {};
const result = [];
XpathUtil.updateEvaluator(this.getXml());
for (let child of semStree) {
for (const child of semStree) {
if (mmlStree[child]) {
continue;
}
Expand All @@ -624,17 +629,17 @@ export abstract class AbstractWalker<T> implements Walker {
/**
* Find all ids in the subtree spanned at a node and register them.
*
* @param {number} id The root id of the subtree.
* @param {{[num: number]: boolean}} nodes The accumulator collecting the
* nodes.
* @param id The root id of the subtree.
* @param nodes The accumulator collecting the nodes.
*/
private subtreeIds(id: number, nodes: {[num: number]: boolean}) {
let xmlRoot = XpathUtil.evalXPath(
`//*[@data-semantic-id="${id}"]`, this.getXml());
let xpath = XpathUtil.evalXPath('*//@data-semantic-id', xmlRoot[0]);
xpath.forEach(x => nodes[parseInt(x.textContent, 10)] = true);
};

private subtreeIds(id: number, nodes: { [num: number]: boolean }) {
const xmlRoot = XpathUtil.evalXPath(
`//*[@data-semantic-id="${id}"]`,
this.getXml()
);
const xpath = XpathUtil.evalXPath('*//@data-semantic-id', xmlRoot[0]);
xpath.forEach((x) => (nodes[parseInt(x.textContent, 10)] = true));
}

/**
* Makes a focus for a primary node and a node list, all given by their ids.
Expand Down
3 changes: 0 additions & 3 deletions ts/walker/syntax_walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,4 @@ export class SyntaxWalker extends AbstractWalker<string> {
public focusSemanticNodes() {
return [this.getFocus().getSemanticPrimary()];
}



}

0 comments on commit ba19057

Please sign in to comment.