mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-05-02 00:07:23 +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,32 +1,45 @@
|
||||
import { canHaveDecorators, ClassDeclaration, factory, getDecorators as tsGetDecorators, SyntaxKind } from 'typescript';
|
||||
import {
|
||||
canHaveDecorators,
|
||||
ClassDeclaration,
|
||||
ClassElement,
|
||||
ConstructorDeclaration,
|
||||
factory,
|
||||
getDecorators as tsGetDecorators,
|
||||
MethodDeclaration,
|
||||
SyntaxKind,
|
||||
} from 'typescript';
|
||||
|
||||
import { transformMethod } from './methods';
|
||||
import { transformProperty } from './properties';
|
||||
|
||||
export function transformMembers(cls: ClassDeclaration) {
|
||||
export function transformMembers(cls: ClassDeclaration): ClassElement[] {
|
||||
const propertyIndices: number[] = [];
|
||||
|
||||
const members = cls.members.map((member: any, index: number) => {
|
||||
// only process decorated members
|
||||
const members = cls.members.map((member, index) => {
|
||||
const memberDecorators = canHaveDecorators(member) ? tsGetDecorators(member) : undefined;
|
||||
if (!memberDecorators || !memberDecorators.length) return member;
|
||||
|
||||
switch (member.kind) {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
return transformMethod(member);
|
||||
return transformMethod(member as MethodDeclaration) ?? member;
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
propertyIndices.push(index);
|
||||
return member;
|
||||
case SyntaxKind.Constructor:
|
||||
return factory.createConstructorDeclaration(undefined, member.parameters, member.body);
|
||||
case SyntaxKind.Constructor: {
|
||||
const ctor = member as ConstructorDeclaration;
|
||||
return factory.createConstructorDeclaration(undefined, ctor.parameters, ctor.body);
|
||||
}
|
||||
default:
|
||||
return member; // in case anything gets here by accident...
|
||||
return member;
|
||||
}
|
||||
});
|
||||
}) as ClassElement[];
|
||||
|
||||
propertyIndices.forEach((i: number) => {
|
||||
const [getter, setter] = transformProperty(members, i) as any;
|
||||
members.push(getter, setter);
|
||||
const result = transformProperty(members, i);
|
||||
if (Array.isArray(result)) {
|
||||
const [getter, setter] = result;
|
||||
members.push(getter, setter);
|
||||
}
|
||||
});
|
||||
|
||||
propertyIndices.reverse().forEach((i) => members.splice(i, 1));
|
||||
|
||||
Reference in New Issue
Block a user