mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-09-01 08:17:07 +00:00
Improve typings
Remove `DEV` blocks
This commit is contained in:
@@ -26,11 +26,7 @@ for (const sourceFile of project.getSourceFiles()) {
|
||||
const posixFilePath = toPosixPath(filePath);
|
||||
|
||||
if (!posixFilePath.startsWith(posixSrc)) continue;
|
||||
if (
|
||||
posixFilePath.includes("/_test/") ||
|
||||
posixFilePath.endsWith(".spec.ts") ||
|
||||
posixFilePath.endsWith(".test.ts")
|
||||
) {
|
||||
if (posixFilePath.includes("/_test/") || posixFilePath.endsWith(".spec.ts") || posixFilePath.endsWith(".test.ts")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ for (const sourceFile of project.getSourceFiles()) {
|
||||
const posixFilePath = toPosixPath(filePath);
|
||||
|
||||
if (!posixFilePath.startsWith(posixSrc)) continue;
|
||||
if (posixFilePath.includes("/_test/") || posixFilePath.endsWith(".spec.ts") || posixFilePath.endsWith(".test.ts")) continue;
|
||||
if (posixFilePath.includes("/_test/") || posixFilePath.endsWith(".spec.ts") || posixFilePath.endsWith(".test.ts"))
|
||||
continue;
|
||||
|
||||
// Find AsExpression (expr as Type) and TypeAssertion (<Type>expr)
|
||||
const asExpressions = sourceFile.getDescendantsOfKind(SyntaxKind.AsExpression);
|
||||
|
||||
@@ -69,7 +69,7 @@ for (const sourceFile of project.getSourceFiles()) {
|
||||
|
||||
for (const impDecl of importDeclarations) {
|
||||
const specifier = impDecl.getModuleSpecifierValue();
|
||||
|
||||
|
||||
// Check if it's a Node.js built-in module we want to redirect
|
||||
let exportedName = "";
|
||||
if (specifier === "fs/promises" || specifier === "node:fs/promises") {
|
||||
@@ -92,11 +92,11 @@ for (const sourceFile of project.getSourceFiles()) {
|
||||
|
||||
if (targetImports.length > 0) {
|
||||
console.log(`File: ${posixFilePath.slice(posixProjectRoot.length + 1)}`);
|
||||
|
||||
|
||||
for (const { impDecl, exportedName, localName } of targetImports) {
|
||||
const { line } = sourceFile.getLineAndColumnAtPos(impDecl.getStart());
|
||||
console.log(` Line ${line}: Redirecting "${impDecl.getText()}"`);
|
||||
|
||||
|
||||
if (exportedName === localName) {
|
||||
namedImportsToAdd.push(exportedName);
|
||||
} else {
|
||||
|
||||
@@ -38,7 +38,8 @@ for (const sourceFile of project.getSourceFiles()) {
|
||||
const posixFilePath = toPosixPath(filePath);
|
||||
|
||||
if (!posixFilePath.startsWith(posixSrc)) continue;
|
||||
if (posixFilePath.includes("/_test/") || posixFilePath.endsWith(".spec.ts") || posixFilePath.endsWith(".test.ts")) continue;
|
||||
if (posixFilePath.includes("/_test/") || posixFilePath.endsWith(".spec.ts") || posixFilePath.endsWith(".test.ts"))
|
||||
continue;
|
||||
|
||||
let fileModified = false;
|
||||
|
||||
@@ -51,10 +52,11 @@ for (const sourceFile of project.getSourceFiles()) {
|
||||
if (varDec) {
|
||||
const varName = varDec.getName();
|
||||
// Count references within the catch clause itself
|
||||
const count = catchClause.getDescendantsOfKind(SyntaxKind.Identifier)
|
||||
.filter((id) => id.getText() === varName)
|
||||
.length;
|
||||
if (count === 1) { // Only the declaration itself
|
||||
const count = catchClause
|
||||
.getDescendantsOfKind(SyntaxKind.Identifier)
|
||||
.filter((id) => id.getText() === varName).length;
|
||||
if (count === 1) {
|
||||
// Only the declaration itself
|
||||
catchVarsToRemove.push(varDec);
|
||||
}
|
||||
}
|
||||
@@ -86,10 +88,11 @@ for (const sourceFile of project.getSourceFiles()) {
|
||||
for (const namedImport of namedImports) {
|
||||
const importName = namedImport.getAliasNode()?.getText() ?? namedImport.getName();
|
||||
// Count references in the entire file
|
||||
const count = sourceFile.getDescendantsOfKind(SyntaxKind.Identifier)
|
||||
.filter((id) => id.getText() === importName)
|
||||
.length;
|
||||
if (count === 1) { // Only the import specifier itself
|
||||
const count = sourceFile
|
||||
.getDescendantsOfKind(SyntaxKind.Identifier)
|
||||
.filter((id) => id.getText() === importName).length;
|
||||
if (count === 1) {
|
||||
// Only the import specifier itself
|
||||
importsToRemove.push({ namedImport, impDecl });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user