mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-04-13 00:00:10 +08:00
62956e429c
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.
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import {
|
|
ClassElement,
|
|
factory,
|
|
GetAccessorDeclaration,
|
|
Identifier,
|
|
PropertyDeclaration,
|
|
SetAccessorDeclaration,
|
|
} from 'typescript';
|
|
|
|
import { getDecorator, getDecoratorName } from '../helpers';
|
|
|
|
export function transformProperty(
|
|
members: ClassElement[],
|
|
index: number
|
|
): [GetAccessorDeclaration, SetAccessorDeclaration] | PropertyDeclaration {
|
|
const property = members[index] as PropertyDeclaration,
|
|
decorator = getDecorator(property),
|
|
decoratorName = decorator ? getDecoratorName(decorator) : undefined;
|
|
|
|
let type: 'cordova' | 'instance';
|
|
|
|
switch (decoratorName) {
|
|
case 'CordovaProperty':
|
|
type = 'cordova';
|
|
break;
|
|
|
|
case 'InstanceProperty':
|
|
type = 'instance';
|
|
break;
|
|
|
|
default:
|
|
return property;
|
|
}
|
|
|
|
const propertyName = (property.name as Identifier).text;
|
|
|
|
const getter = factory.createGetAccessorDeclaration(
|
|
undefined,
|
|
property.name,
|
|
[],
|
|
property.type,
|
|
factory.createBlock([
|
|
factory.createReturnStatement(
|
|
factory.createCallExpression(factory.createIdentifier(type + 'PropertyGet'), undefined, [
|
|
factory.createThis(),
|
|
factory.createStringLiteral(propertyName),
|
|
])
|
|
),
|
|
])
|
|
);
|
|
|
|
const setter = factory.createSetAccessorDeclaration(
|
|
undefined,
|
|
property.name,
|
|
[factory.createParameterDeclaration(undefined, undefined, 'value', undefined, property.type)],
|
|
factory.createBlock([
|
|
factory.createExpressionStatement(
|
|
factory.createCallExpression(factory.createIdentifier(type + 'PropertySet'), undefined, [
|
|
factory.createThis(),
|
|
factory.createStringLiteral(propertyName),
|
|
factory.createIdentifier('value'),
|
|
])
|
|
),
|
|
])
|
|
);
|
|
|
|
return [getter, setter];
|
|
}
|