Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions generate-types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const toIdentifier = (str) => {
.replace(IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX, "_");
};

/** @param {string[]} list */
const joinIdentifer = (list) => {
const str = list.join("_");
return str.replace(/([^_])_+(.|$)/g, (m, a, b) =>
Expand Down Expand Up @@ -1693,13 +1694,15 @@ const printError = (diagnostic) => {
const { nameMapping } = options;

const nameToQueueEntry = new Map();
/** @param symbolName {SymbolName} */
const findName = (symbolName, requeueOnConflict = false) => {
const key = symbolName.join(" ");
for (const wishedName of Object.keys(nameMapping)) {
if (nameMapping[wishedName].test(key)) {
symbolName = [wishedName, ...symbolName];
}
}
/** @type {string} */
let name;
for (let i = 1; i <= symbolName.length; i++) {
name = joinIdentifer(symbolName.slice(0, i));
Expand All @@ -1726,6 +1729,7 @@ const printError = (diagnostic) => {
return `${name}_${i}`;
};

/** @type {Map<ts.Type, string>} */
const typeToVariable = new Map();
for (const entry of needName) {
const [type, item] = entry;
Expand Down Expand Up @@ -1761,6 +1765,12 @@ const printError = (diagnostic) => {
declarationKeys.set(text, key);
};

/**
* @param {ts.Type} type
* @param {string} variable
* @param {() => string} fn
* @returns {void}
*/
const queueDeclaration = (type, variable, fn) => {
if (!variable) {
throw new Error(
Expand Down