mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-04-13 00:00:10 +08:00
refactor(build): use typescript es6 imports
This commit is contained in:
@@ -1,4 +1,20 @@
|
||||
import * as ts from 'typescript';
|
||||
import {
|
||||
createBinary,
|
||||
createBlock,
|
||||
createCall,
|
||||
createIdentifier,
|
||||
createIf,
|
||||
createImmediatelyInvokedArrowFunction,
|
||||
createLiteral,
|
||||
createMethod,
|
||||
createReturn,
|
||||
createThis,
|
||||
createTrue,
|
||||
Expression,
|
||||
MethodDeclaration,
|
||||
SyntaxKind,
|
||||
} from 'typescript';
|
||||
|
||||
import { Logger } from '../../logger';
|
||||
import {
|
||||
convertValueToLiteral,
|
||||
@@ -8,7 +24,7 @@ import {
|
||||
getMethodsForDecorator,
|
||||
} from '../helpers';
|
||||
|
||||
export function transformMethod(method: ts.MethodDeclaration) {
|
||||
export function transformMethod(method: MethodDeclaration) {
|
||||
if (!method) return;
|
||||
|
||||
const decorator = getDecorator(method),
|
||||
@@ -16,7 +32,7 @@ export function transformMethod(method: ts.MethodDeclaration) {
|
||||
decoratorArgs = getDecoratorArgs(decorator);
|
||||
|
||||
try {
|
||||
return ts.createMethod(
|
||||
return createMethod(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
@@ -25,7 +41,7 @@ export function transformMethod(method: ts.MethodDeclaration) {
|
||||
method.typeParameters,
|
||||
method.parameters,
|
||||
method.type,
|
||||
ts.createBlock([ts.createReturn(getMethodBlock(method, decoratorName, decoratorArgs))])
|
||||
createBlock([createReturn(getMethodBlock(method, decoratorName, decoratorArgs))])
|
||||
);
|
||||
} catch (e) {
|
||||
Logger.error('Error transforming method: ' + (method.name as any).text);
|
||||
@@ -33,30 +49,30 @@ export function transformMethod(method: ts.MethodDeclaration) {
|
||||
}
|
||||
}
|
||||
|
||||
function getMethodBlock(method: ts.MethodDeclaration, decoratorName: string, decoratorArgs: any): ts.Expression {
|
||||
function getMethodBlock(method: MethodDeclaration, decoratorName: string, decoratorArgs: any): Expression {
|
||||
const decoratorMethod = getMethodsForDecorator(decoratorName)[0];
|
||||
|
||||
switch (decoratorName) {
|
||||
case 'CordovaCheck':
|
||||
case 'InstanceCheck':
|
||||
// TODO remove function wrapper
|
||||
return ts.createImmediatelyInvokedArrowFunction([
|
||||
ts.createIf(
|
||||
ts.createBinary(
|
||||
ts.createCall(ts.createIdentifier(decoratorMethod), undefined, [ts.createThis()]),
|
||||
ts.SyntaxKind.EqualsEqualsEqualsToken,
|
||||
ts.createTrue()
|
||||
return createImmediatelyInvokedArrowFunction([
|
||||
createIf(
|
||||
createBinary(
|
||||
createCall(createIdentifier(decoratorMethod), undefined, [createThis()]),
|
||||
SyntaxKind.EqualsEqualsEqualsToken,
|
||||
createTrue()
|
||||
),
|
||||
method.body
|
||||
),
|
||||
]);
|
||||
|
||||
default:
|
||||
return ts.createCall(ts.createIdentifier(decoratorMethod), undefined, [
|
||||
ts.createThis(),
|
||||
ts.createLiteral(decoratorArgs?.methodName || (method.name as any).text),
|
||||
return createCall(createIdentifier(decoratorMethod), undefined, [
|
||||
createThis(),
|
||||
createLiteral(decoratorArgs?.methodName || (method.name as any).text),
|
||||
convertValueToLiteral(decoratorArgs),
|
||||
ts.createIdentifier('arguments'),
|
||||
createIdentifier('arguments'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user