Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
viewFile: SourceFile,
propsName: string
): boolean {
const hoc = `AppStyle.withTheme`
const identifier = viewVar.getFirstChild(
c =>
c.getKind() === SyntaxKind.CallExpression && c.getText().startsWith(hoc)
)
let callExp: CallExpression
if (identifier) {
if (identifier.getText().startsWith(hoc)) {
return false
}
callExp = identifier.getFirstChildByKind(SyntaxKind.CallExpression)
}
if (!callExp) {
const arrowFn = viewVar.getInitializer() as ArrowFunction // viewVar.getFirstDescendantByKind(SyntaxKind.ArrowFunction)
if (arrowFn.getParameters) {
ReactUtils.setFunctionPropsParams(arrowFn, propsName)
}
viewVar.replaceWithText(
`${viewVar.getName()} = ${hoc}(${arrowFn.getText()})`
)
this.updateImports(viewFile, propsName)
return true
}
return false
this.sourceFile,
this.name,
props.name
)
const identifier = viewVar.getFirstChild(
c =>
c.getKind() === SyntaxKind.CallExpression && c.getText().startsWith(key)
)
let callExp: CallExpression
if (identifier) {
// if (identifier.getText().startsWith(hoc)) {
// return false
// }
callExp = identifier.getFirstChildByKind(SyntaxKind.CallExpression)
}
if (!callExp) {
const fn = viewVar.getInitializer() as ArrowFunction
if (fn.getParameters) {
react.setFunctionPropsParams(fn, props.name)
}
viewVar.replaceWithText(
`${viewVar.getName()} = ${statement}(${fn.getText()})`
)
} else {
if (force) {
callExp.replaceWithText(statement)
} else {
return false
}
c =>
c.getKind() === SyntaxKind.CallExpression && c.getText().startsWith(hoc)
)
static setAppStoreHoc(
viewVar: VariableDeclaration,
propsName: string,
typeArgs: string[],
statesMap: NameValue[],
actionsMap: NameValue[]
) {
let callExp: CallExpression
const identifier = viewVar.getChildAtIndex(2)
if (
identifier &&
identifier.getKind() === SyntaxKind.CallExpression &&
identifier.getText().startsWith('AppStore.withStore')
) {
callExp = identifier.getFirstChildByKind(SyntaxKind.CallExpression)
}
let connectionArgs: string[]
;({ connectionArgs, typeArgs } = ReduxUtils.resolveConnectionArgs(
callExp,
statesMap,
actionsMap,
typeArgs
))
const connectionArgsStr = `AppStore.withStore<${typeArgs.join(
','
)}>(${connectionArgs.join(',')})`
if (callExp) {
callExp.replaceWithText(connectionArgsStr)
.map(s => {
const ce = s.getFirstDescendantByKind(SyntaxKind.CallExpression)
if (ce && ce.getText().startsWith('useState(')) {
return ce
}
return undefined
})
.filter(ce => !!ce)
static setAppStoreHoc(
viewVar: VariableDeclaration,
propsName: string,
typeArgs: string[],
statesMap: NameValue[],
actionsMap: NameValue[]
) {
let callExp: CallExpression
const identifier = viewVar.getChildAtIndex(2)
if (
identifier &&
identifier.getKind() === SyntaxKind.CallExpression &&
identifier.getText().startsWith('AppStore.withStore')
) {
callExp = identifier.getFirstChildByKind(SyntaxKind.CallExpression)
}
let connectionArgs: string[]
;({ connectionArgs, typeArgs } = ReduxUtils.resolveConnectionArgs(
callExp,
statesMap,
actionsMap,
typeArgs
))
const connectionArgsStr = `AppStore.withStore<${typeArgs.join(
','
)}>(${connectionArgs.join(',')})`
.map( ( node: Node ) => node.getFirstAncestorByKind( SyntaxKind.CallExpression ) )
.filter( ( node ): node is CallExpression => !!node );
private attachToArrowFunction(name: string, screenFile: SourceFile): boolean {
const vd = screenFile.getVariableDeclaration(name)
if (!vd) {
return false
}
let arrowFn = vd.getInitializerIfKind(SyntaxKind.ArrowFunction)
if (!arrowFn) {
const callExp = vd.getInitializerIfKind(SyntaxKind.CallExpression)
if (!callExp) {
return false
}
arrowFn = callExp.getFirstChildByKind(SyntaxKind.ArrowFunction)
}
if (!arrowFn) {
return false
}
this.setFunctionBody(arrowFn)
return true
}
getFunction() {
let fn = this.sourceFile.getFunction(this.name)
if (!fn) {
const varDec = this.sourceFile.getVariableDeclaration(this.name)
if (!varDec) {
return undefined
}
const initializer = varDec.getInitializerIfKind(SyntaxKind.CallExpression)
if (!initializer) {
return undefined
}
const args = initializer.getArguments()
if (!args.length) {
return undefined
}
fn = this.sourceFile.getFunction(args[0].getText())
}
return fn
}