fix: TS errors on dependent projects with certain tsconfig settings (#6360) (#6361)

* fix: TS errors on dependent projects with certain tsconfig settings (#6360)

* Address PR comments
This commit is contained in:
ktbytechibong
2022-09-06 16:19:56 -04:00
committed by GitHub
parent 2bf1182534
commit e58cf77b7f
3 changed files with 25 additions and 33 deletions

View File

@@ -1371,7 +1371,7 @@ export class Block implements IASTNodeLocation, IDeletable {
* @returns Text of block.
*/
toString(opt_maxLength?: number, opt_emptyToken?: string): string {
let text = [];
const tokens = [];
const emptyFieldPlaceholder = opt_emptyToken || '?';
// Temporarily set flag to navigate to all fields.
@@ -1410,16 +1410,16 @@ export class Block implements IASTNodeLocation, IDeletable {
case ASTNode.types.INPUT: {
const connection = node.getLocation() as Connection;
if (!node.in()) {
text.push(emptyFieldPlaceholder);
tokens.push(emptyFieldPlaceholder);
} else if (shouldAddParentheses(connection)) {
text.push('(');
tokens.push('(');
}
break;
}
case ASTNode.types.FIELD: {
const field = node.getLocation() as Field;
if (field.name !== constants.COLLAPSED_FIELD_NAME) {
text.push(field.getText());
tokens.push(field.getText());
}
break;
}
@@ -1437,7 +1437,7 @@ export class Block implements IASTNodeLocation, IDeletable {
// If we hit an input on the way up, possibly close out parentheses.
if (node && node.getType() === ASTNode.types.INPUT &&
shouldAddParentheses(node.getLocation() as Connection)) {
text.push(')');
tokens.push(')');
}
}
if (node) {
@@ -1452,31 +1452,25 @@ export class Block implements IASTNodeLocation, IDeletable {
// Run through our text array and simplify expression to remove parentheses
// around single field blocks.
// E.g. ['repeat', '(', '10', ')', 'times', 'do', '?']
for (let i = 2; i < text.length; i++) {
if (text[i - 2] === '(' && text[i] === ')') {
text[i - 2] = text[i - 1];
text.splice(i - 1, 2);
for (let i = 2; i < tokens.length; i++) {
if (tokens[i - 2] === '(' && tokens[i] === ')') {
tokens[i - 2] = tokens[i - 1];
tokens.splice(i - 1, 2);
}
}
// Join the text array, removing spaces around added parentheses.
// AnyDuringMigration because: Type 'string' is not assignable to type
// 'any[]'.
text = text.reduce(function(acc, value) {
let text: string = tokens.reduce(function(acc, value) {
return acc + (acc.substr(-1) === '(' || value === ')' ? '' : ' ') + value;
}, '') as AnyDuringMigration;
// AnyDuringMigration because: Property 'trim' does not exist on type
// 'any[]'.
text = (text as AnyDuringMigration).trim() || '???';
}, '');
text = text.trim() || '???';
if (opt_maxLength) {
// TODO: Improve truncation so that text from this block is given
// priority. E.g. "1+2+3+4+5+6+7+8+9=0" should be "...6+7+8+9=0", not
// "1+2+3+4+5...". E.g. "1+2+3+4+5=6+7+8+9+0" should be "...4+5=6+7...".
if (text.length > opt_maxLength) {
// AnyDuringMigration because: Type 'string' is not assignable to type
// 'any[]'.
text = (text.substring(0, opt_maxLength - 3) + '...') as
AnyDuringMigration;
text = text.substring(0, opt_maxLength - 3) + '...';
}
}
return text;