Skip to content

refactor: remove optional in ReplacementMap #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion build/logic/ReplacementMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export type ReplacementTarget = (
statement: ts.Statement;
}
) & {
optional: boolean;
sourceFile: ts.SourceFile;
};

Expand Down
10 changes: 2 additions & 8 deletions build/logic/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,8 @@ function generateStatements(
}

let lineInserted = false;
for (const target of replacementTargets.values()) {
for (const statement of target) {
if (statement.optional) {
// Since target from aliases may not be present in the original file,
// aliases that have not been consumed are skipped.
continue;
}

for (const [name, targets] of replacementTargets.entries()) {
for (const statement of targets) {
if (!lineInserted) {
result += "// --------------------\n";
lineInserted = true;
Expand Down
16 changes: 4 additions & 12 deletions build/logic/scanBetterFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,19 @@ export function loadAliasFile(
const name = getStatementDeclName(statement) ?? "";
const aliases = alias.get(name);
if (!aliases) {
console.warn(`Warning: No alias found for ${name}`);
return [statement];
}
return aliases.map((aliasDetails) => {
return aliases.flatMap((aliasDetails) => {
if (aliasDetails.file !== targetFileName) {
return statement;
return [];
}
return replaceAliases(statement, aliasDetails.replacement);
return [replaceAliases(statement, aliasDetails.replacement)];
});
});

// Scan the target file
const replacementMap = scanStatements(printer, statements, aliasFile);
// mark everything as optional
for (const targets of replacementMap.values()) {
for (const target of targets) {
target.optional = true;
}
}

return {
replacementMap,
Expand Down Expand Up @@ -122,7 +117,6 @@ function scanStatements(
type: "interface",
members,
originalStatement: transformedStatement,
optional: false,
sourceFile: sourceFile,
});
return targets;
Expand All @@ -146,7 +140,6 @@ function scanStatements(
sourceFile,
)
: new Map(),
optional: false,
sourceFile: sourceFile,
});
return targets;
Expand All @@ -156,7 +149,6 @@ function scanStatements(
statements.push({
type: "non-interface",
statement: transformedStatement,
optional: false,
sourceFile: sourceFile,
});
return statements;
Expand Down
1 change: 0 additions & 1 deletion build/util/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const es5TypedArrays = [
"Uint32Array",
"Float32Array",
"Float64Array",
"Float16Array",
];

const es2020TypedBigIntArrays = ["BigInt64Array", "BigUint64Array"];
Expand Down