-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: supprort recursively replacing
declare global
modules (#50)
* refactor: split generate.ts * feat: scan declare global block * refactor: change ReplacementTarget interface to support declare global blocks * feat: generate declare global replacement
- Loading branch information
Showing
4 changed files
with
298 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import ts from "typescript"; | ||
|
||
export function getStatementDeclName( | ||
statement: ts.Statement, | ||
): string | undefined { | ||
if (ts.isVariableStatement(statement)) { | ||
for (const dec of statement.declarationList.declarations) { | ||
if (ts.isIdentifier(dec.name)) { | ||
return dec.name.text; | ||
} | ||
} | ||
} else if ( | ||
ts.isFunctionDeclaration(statement) || | ||
ts.isInterfaceDeclaration(statement) || | ||
ts.isTypeAliasDeclaration(statement) || | ||
ts.isModuleDeclaration(statement) | ||
) { | ||
return statement.name?.text; | ||
} else if (ts.isInterfaceDeclaration(statement)) { | ||
return statement.name.text; | ||
} | ||
return undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.