{"version":3,"file":"member.mjs","names":[],"sources":["../../../../../src/modules/preprocessor/preprocess/transform/member.ts"],"sourcesContent":["import type { Argument, MemberExpression, ObjectExpression } from \"oxc-parser\";\n\nimport type { CompilerContext } from \"#/contexts/compiler\";\n\nimport { cloneDeep } from \"es-toolkit\";\n\nimport { ARGS, FN, ID, SIGNATURE, VA } from \"#/consts\";\nimport { CompileError } from \"#/errors/compile\";\nimport { createObjectKeyValue } from \"#/modules/preprocessor/preprocess/transform/helper/kv\";\nimport { createId } from \"./helper/id\";\n\ntype TransformMemberExprOptions = {\n    context: CompilerContext;\n    va: string;\n    member: MemberExpression;\n    arguments: Argument[];\n};\n\ntype TransformMemberExprResult = {\n    object: ObjectExpression;\n};\n\nconst transformMemberExpr = (\n    options: TransformMemberExprOptions,\n): TransformMemberExprResult => {\n    const ctx: CompilerContext = options.context;\n\n    const member: MemberExpression = cloneDeep(options.member);\n\n    const object: ObjectExpression = {\n        type: \"ObjectExpression\",\n        start: member.start,\n        end: member.end,\n        properties: [],\n    };\n\n    const { property: signature } = createObjectKeyValue({\n        key: SIGNATURE,\n        value: true,\n    });\n\n    object.properties.push(signature);\n\n    const { property: id } = createObjectKeyValue({\n        key: ID,\n        value: createId({\n            context: ctx,\n            va: options.va,\n            arguments: options.arguments,\n        }),\n    });\n\n    object.properties.push(id);\n\n    const { property: va } = createObjectKeyValue({\n        key: VA,\n        value: options.va,\n    });\n\n    object.properties.push(va);\n\n    let fnName: string = \"\";\n\n    // const abc = x.y({ ... });\n    if (member.property.type === \"Identifier\") {\n        fnName = member.property.name;\n    }\n\n    // const abc = x[\"y\"]({ ... });\n    else if (member.property.type === \"Literal\") {\n        if (member.property.value === \"\" || member.property.value === null) {\n            throw new CompileError({\n                context: options.context,\n                span: {\n                    start: member.property.start,\n                    end: member.property.end,\n                },\n                message: `Unsupported member property value: null`,\n            });\n        }\n\n        fnName = member.property.value.toString();\n    } else {\n        throw new CompileError({\n            context: options.context,\n            span: {\n                start: member.property.start,\n                end: member.property.end,\n            },\n            message: `Unsupported member expression property type: ${member.property.type}`,\n        });\n    }\n\n    const { property: fn } = createObjectKeyValue({\n        key: FN,\n        value: fnName,\n    });\n\n    object.properties.push(fn);\n\n    const { property: args } = createObjectKeyValue({\n        key: ARGS,\n        value: options.arguments,\n    });\n\n    object.properties.push(args);\n\n    return {\n        object,\n    };\n};\n\nexport type { TransformMemberExprOptions, TransformMemberExprResult };\nexport { transformMemberExpr };\n"],"mappings":";;;;;;AAsBA,MAAM,uBACF,YAC4B;CAC5B,MAAM,MAAuB,QAAQ;CAErC,MAAM,SAA2B,UAAU,QAAQ,MAAM;CAEzD,MAAM,SAA2B;EAC7B,MAAM;EACN,OAAO,OAAO;EACd,KAAK,OAAO;EACZ,YAAY,CAAC;CACjB;CAEA,MAAM,EAAE,UAAU,cAAc,qBAAqB;EACjD,KAAK;EACL,OAAO;CACX,CAAC;CAED,OAAO,WAAW,KAAK,SAAS;CAEhC,MAAM,EAAE,UAAU,OAAO,qBAAqB;EAC1C;EACA,OAAO,SAAS;GACZ,SAAS;GACT,IAAI,QAAQ;GACZ,WAAW,QAAQ;EACvB,CAAC;CACL,CAAC;CAED,OAAO,WAAW,KAAK,EAAE;CAEzB,MAAM,EAAE,UAAU,OAAO,qBAAqB;EAC1C,KAAK;EACL,OAAO,QAAQ;CACnB,CAAC;CAED,OAAO,WAAW,KAAK,EAAE;CAEzB,IAAI,SAAiB;CAGrB,IAAI,OAAO,SAAS,SAAS,cACzB,SAAS,OAAO,SAAS;MAIxB,IAAI,OAAO,SAAS,SAAS,WAAW;EACzC,IAAI,OAAO,SAAS,UAAU,MAAM,OAAO,SAAS,UAAU,MAC1D,MAAM,IAAI,aAAa;GACnB,SAAS,QAAQ;GACjB,MAAM;IACF,OAAO,OAAO,SAAS;IACvB,KAAK,OAAO,SAAS;GACzB;GACA,SAAS;EACb,CAAC;EAGL,SAAS,OAAO,SAAS,MAAM,SAAS;CAC5C,OACI,MAAM,IAAI,aAAa;EACnB,SAAS,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