Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion transforms/magic-redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { recursiveParent } from '../utils/recursiveParent'

const unifiedMagicString = (path: ASTPath<CallExpression>, projectRequestName: string) => {
const pathArguments = path.value.arguments
if (pathArguments.length === 1 && pathArguments[0].type === 'StringLiteral' && pathArguments[0].value === 'back') {

if (pathArguments.length === 1 && pathArguments[0]?.type === 'StringLiteral' && pathArguments[0].value === 'back') {
path.value.arguments = [
logicalExpression(
'||',
Expand All @@ -39,6 +40,7 @@ export default function transformer(file: FileInfo, _api: API) {
},
})
.map((path) => unifiedMagicString(path, recursiveParent(path.parentPath) || 'req'))

parsedFile
.find(CallExpression, {
callee: {
Expand Down
4 changes: 2 additions & 2 deletions utils/recursiveParent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const recursiveParent = (
paramIndex = 0,
parentExpressionType = defaultParentExpressionType,
): string | null => {
if (parentExpressionType.some((type) => parent.value.type === type)) {
if (parentExpressionType.some((type) => parent.value?.type === type)) {
const foundNode = parent.value as unknown as ArrowFunctionExpression | FunctionExpression
if (foundNode.params[paramIndex].type === 'Identifier') {
if (foundNode.params[paramIndex]?.type === 'Identifier') {
return foundNode.params[paramIndex].name
}
return null
Expand Down
Loading