mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-04-13 00:00:10 +08:00
fix: add strict types to build scripts and remove all any usage
Replace all implicit and explicit any types in build scripts with proper TypeScript Compiler API types (Decorator, ClassDeclaration, MethodDeclaration, Identifier, SourceFile, etc.). Add PackageJson and InjectableClassEntry interfaces. Fix return types, null checks, and type assertions throughout all transformer scripts.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Expression, factory, MethodDeclaration, SyntaxKind } from 'typescript';
|
||||
import { Expression, factory, Identifier, MethodDeclaration, SyntaxKind } from 'typescript';
|
||||
|
||||
import { Logger } from '../../logger';
|
||||
import {
|
||||
@@ -12,9 +12,11 @@ import {
|
||||
export function transformMethod(method: MethodDeclaration) {
|
||||
if (!method) return;
|
||||
|
||||
const decorator = getDecorator(method),
|
||||
decoratorName = getDecoratorName(decorator),
|
||||
decoratorArgs = getDecoratorArgs(decorator);
|
||||
const decorator = getDecorator(method);
|
||||
if (!decorator) return;
|
||||
|
||||
const decoratorName = getDecoratorName(decorator);
|
||||
const decoratorArgs = getDecoratorArgs(decorator);
|
||||
|
||||
try {
|
||||
return factory.createMethodDeclaration(
|
||||
@@ -27,13 +29,17 @@ export function transformMethod(method: MethodDeclaration) {
|
||||
method.type,
|
||||
factory.createBlock([factory.createReturnStatement(getMethodBlock(method, decoratorName, decoratorArgs))])
|
||||
);
|
||||
} catch (e) {
|
||||
Logger.error('Error transforming method: ' + (method.name as any).text);
|
||||
Logger.error(e.message);
|
||||
} catch (e: unknown) {
|
||||
Logger.error('Error transforming method: ' + (method.name as Identifier).text);
|
||||
Logger.error(e instanceof Error ? e.message : String(e));
|
||||
}
|
||||
}
|
||||
|
||||
function getMethodBlock(method: MethodDeclaration, decoratorName: string, decoratorArgs: any): Expression {
|
||||
function getMethodBlock(
|
||||
method: MethodDeclaration,
|
||||
decoratorName: string,
|
||||
decoratorArgs: Record<string, string | number | boolean | string[]>
|
||||
): Expression {
|
||||
const decoratorMethod = getMethodsForDecorator(decoratorName)[0];
|
||||
|
||||
switch (decoratorName) {
|
||||
@@ -46,14 +52,14 @@ function getMethodBlock(method: MethodDeclaration, decoratorName: string, decora
|
||||
SyntaxKind.EqualsEqualsEqualsToken,
|
||||
factory.createTrue()
|
||||
),
|
||||
method.body
|
||||
method.body!
|
||||
),
|
||||
]);
|
||||
|
||||
default:
|
||||
return factory.createCallExpression(factory.createIdentifier(decoratorMethod), undefined, [
|
||||
factory.createThis(),
|
||||
factory.createStringLiteral(decoratorArgs?.methodName || (method.name as any).text),
|
||||
factory.createStringLiteral((decoratorArgs?.methodName as string) || (method.name as Identifier).text),
|
||||
convertValueToLiteral(decoratorArgs),
|
||||
factory.createIdentifier('arguments'),
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user