Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createFunctionCall(meta: OutputMeta) {
const newValueInitializer = ts.createBinary(
ts.createIdentifier(data),
ts.createToken(ts.SyntaxKind.BarBarToken),
ts.createPropertyAccess(ts.createThis(), meta.propDeclarationName)
)
// TODO use referenceKeyName
const emit = createEmitCall(meta, [
ts.createShorthandPropertyAssignment(meta.referenceKeyName),
ts.createPropertyAssignment(meta.propDeclarationName, newValueInitializer)
])
return ts.createCall(
ts.createPropertyAccess(
ts.createCall(ts.createPropertyAccess(ts.createThis(), meta.functionName), undefined, [
ts.createObjectLiteral([
ts.createPropertyAssignment(meta.functionPropertyName, ts.createIdentifier(newValue)),
ts.createPropertyAssignment(
meta.functionReferenceIdKeyName,
function getMethodBlock(method: ts.MethodDeclaration, decoratorName: string, decoratorArgs: any): ts.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()
),
method.body
)]);
default:
return ts.createCall(ts.createIdentifier(decoratorMethod), undefined, [
ts.createThis(),
ts.createLiteral((method.name as any).text),
convertValueToLiteral(decoratorArgs),
ts.createIdentifier('arguments')
]);
}
}
function connectBinary(op: BinaryOperator, nodes: Expression[]): Expression {
if (nodes.length === 0) {
return createIdentifier('undefined')
}
if (nodes.length === 1) {
return nodes[0]
}
return createBinary(nodes[0], op, connectBinary(op, nodes.slice(1)))
}
ts.createIdentifier('T'),
ts.createTypeOperatorNode(
ts.createTypeReferenceNode(
ts.createIdentifier('A'),
undefined
)
),
undefined
)
],
[
ts.createParameter(
undefined,
undefined,
undefined,
ts.createIdentifier('type'),
undefined,
ts.createTypeReferenceNode(
ts.createIdentifier('T'),
undefined
),
undefined
),
ts.createParameter(
undefined,
undefined,
undefined,
ts.createIdentifier('payload'),
ts.createToken(ts.SyntaxKind.QuestionToken),
ts.createIndexedAccessTypeNode(
ts.createTypeReferenceNode(
ts.createIdentifier('A'),
.map(([key, value]) => {
if (typeof value === 'string') {
return ts.createPropertyAssignment(
ts.createIdentifier(key),
parseURI(value),
)
} else {
return ts.createPropertyAssignment(
ts.createIdentifier(key),
parseTree(value),
)
}
})
)
)
);
visitorContext.typeMapperStack.push(mapper);
for (const property of properties) {
conditions.push(visitPropertySymbol(property, accessor, visitorContext));
}
const stringIndexType = visitorContext.checker.getIndexTypeOfType(type, ts.IndexKind.String);
if (stringIndexType) {
const keyIdentifier = ts.createIdentifier('key');
const itemAccessor = ts.createElementAccess(accessor, keyIdentifier);
conditions.push(
ts.createCall(
ts.createPropertyAccess(
ts.createCall(
ts.createPropertyAccess(ts.createIdentifier('Object'), ts.createIdentifier('keys')),
undefined,
[accessor]
),
ts.createIdentifier('every')
),
undefined,
[
ts.createArrowFunction(
undefined,
undefined,
[
ts.createParameter(
undefined,
undefined,
undefined,
keyIdentifier
function createEventListener(meta: InputMeta) {
const referenceIdIdentifier = ts.createIdentifier('event.detail.referenceId')
const propAccessIdentifier = ts.createPropertyAccess(ts.createThis(), meta.propertyReferenceIdName)
return ts.createMethod(
[
ts.createDecorator(
ts.createCall(ts.createIdentifier(Decorators.Listen), undefined, [ts.createLiteral(`body:${meta.eventName}`)])
)
],
undefined,
undefined,
`${meta.propertyReferenceIdName}Changed`,
undefined,
undefined,
[ts.createParameter(undefined, undefined, undefined, ts.createIdentifier('event'), undefined, undefined)],
undefined,
ts.createBlock(
[
ts.createIdentifier(param),
undefined,
type,
undefined,
),
],
undefined,
ts.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
ts.createTemplateExpression(
ts.createTemplateHead(
'/' + uri.slice(0, matches.index),
'/' + uri.slice(0, matches.index),
),
[
ts.createTemplateSpan(
ts.createIdentifier(param),
ts.createTemplateTail(
uri.slice(matches.index + matches[0].length),
uri.slice(matches.index + matches[0].length),
),
),
],
),
)
}
return ts.createArrowFunction(
undefined,
undefined,
[],
undefined,
ts.createToken(ts.SyntaxKind.EqualsGreaterThanToken),
function createDisjunctionExpression(validationReport: DisjunctionValidationReport, reportError: boolean): ts.Expression {
const conditions = validationReport.reports.map((report) => createExpression(report, reportError));
if (reportError) {
const errorsIdentifier = ts.createIdentifier('errors');
const errorIdentifier = ts.createIdentifier('error');
const prevIdentifier = ts.createIdentifier('prev');
const nextIdentifier = ts.createIdentifier('next');
return ts.createArrowFunction(
undefined,
undefined,
[],
undefined,
undefined,
ts.createBlock([
ts.createVariableStatement(
[ts.createModifier(ts.SyntaxKind.ConstKeyword)],
[ts.createVariableDeclaration(
errorsIdentifier,
undefined,
ts.createCall(
ts.createPropertyAccess(
ts.createArrayLiteral(conditions),
ts.createPropertyAssignment(
"params",
ts.createObjectLiteral(
[...endpoint.queryParams].map(queryParam =>
ts.createPropertyAssignment(
ts.createStringLiteral(queryParam.name),
ts.createIdentifier(queryParam.name)
)
)
)
),
...(includeRequest
? [
ts.createPropertyAssignment(
"data",
ts.createIdentifier(REQUEST_PARAMETER)
)
]
: []),
ts.createPropertyAssignment(
"validateStatus",
ts.createArrowFunction(
/*modifiers*/ undefined,
/*typeParameters*/ undefined,
[],
/*type*/ undefined,
/*equalsGreaterThanToken*/ undefined,
ts.createLiteral(true)
)
)
],
/*multiLine*/ true