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,EAAgB,WAAa,EAAW,KAAK,GAAM,EAAE,QAGzD,EAAgB,OAAS,EAAO,KAChC,EAAgB,oBAAsB,EAAoB,KAC1D,EAAgB,eAAiB,EAAe,KAIhD,MAAM,EAAqB,EAAM,eAC7B,EAAM,iBACF,EAAM,WAAW,UACjB,EAAM,WAAW,eAErB,CAAC,EAAiB,EAAM,cAAc,EAAU,UAI9C,EAAa,EAAM,mBACrB,EAAM,WAAW,GACjB,GAIE,EAAiB,EAAM,oBAAoB,QAAS,CAAC,IAK3D,GAAI,iCAAiC,GAAO,CACxC,MAAM,EAA8B,EAAM,yBACtC,EAAM,WAAW,IAGrB,EAAK,YAAY,GACjB,EAAK,WAAW,YAAY,EAChC,MAGI,EAAK,YAAY,EACrB,GAGX","file":"/npm/@tilework/babel-plugin-mosaic-middleware-decorator@0.0.19/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@tilework/babel-plugin-mosaic-middleware-decorator@0.0.19/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const path = require(\"path\");\nconst {\n    getParentThemePaths\n} = require(\"@tilework/mosaic-dev-utils/parent-theme\");\nconst { getMosaicConfig } = require(\"@tilework/mosaic-dev-utils/mosaic-config\");\nconst extensions = require(\"@tilework/mosaic-dev-utils/extensions\");\n\nconst { sourceDirectories = [] } = getMosaicConfig(process.cwd());\n\nconst allowedPaths = [\n    ...getParentThemePaths(),\n    process.cwd(),\n    ...extensions.map(({ packageName }) => {\n        const isWin =\n            process &&\n            (process.platform === \"win32\" ||\n                /^(msys|cygwin)$/.test(process.env.OSTYPE));\n\n        if (!isWin) {\n            return packageName;\n        }\n\n        return packageName.replace(\"/\", \"\\\\\");\n    }),\n    ...extensions.map(({ packagePath }) => packagePath)\n].reduce(\n    (acc, pathname) => [\n        ...acc,\n        ...sourceDirectories.map((directory) => path.join(pathname, directory))\n    ],\n    []\n);\n\nconst namespaceExtractor = /@namespace +(?<namespace>[^ ]+)/;\n\nconst extractNamespaceFromComments = (comments = []) =>\n    comments.reduce((acquired, testable) => {\n        if (acquired) {\n            return acquired;\n        }\n        const { groups: { namespace } = {} } =\n            testable.value.trim().match(namespaceExtractor) || {};\n        return namespace;\n    }, \"\");\n\nconst isParentExportDefaultDeclaration = (path) => {\n    const {\n        parent: { type }\n    } = path;\n\n    return type === \"ExportDefaultDeclaration\";\n};\n\nconst isParentExportNamedDeclaration = (path) => {\n    const {\n        parent: { type }\n    } = path;\n\n    return type === \"ExportNamedDeclaration\";\n};\n\n/**\n * Gets leading comments directly from the path.node\n * Or from the parent, if path.parent is exdf or named exp.\n */\nconst getLeadingCommentsPath = (path) => {\n    if (path.node.leadingComments) {\n        return path;\n    }\n    if (\n        isParentExportNamedDeclaration(path) ||\n        isParentExportDefaultDeclaration(path)\n    ) {\n        return path.parentPath;\n    }\n\n    return path;\n};\n\nconst getLeadingComments = (path) => {\n    const {\n        node: { leadingComments }\n    } = getLeadingCommentsPath(path);\n\n    return leadingComments;\n};\n\nconst getNamespaceFromPath = (path) => {\n    const leadingComments = getLeadingComments(path);\n    if (!leadingComments) {\n        return null;\n    }\n\n    return extractNamespaceFromComments(leadingComments);\n};\n\n/**\n * This removes the defined namespace from the comments belonging to the path\n * Or to the path's parents, if it's exdf or named exp.\n */\nconst removeNamespaceFromPath = (path, namespace) => {\n    const leadingCommentsPath = getLeadingCommentsPath(path);\n\n    leadingCommentsPath.node.leadingComments.forEach((comment) => {\n        comment.value = comment.value.replace(\n            new RegExp(`@namespace +${namespace}`),\n            `#namespace ${namespace}`\n        );\n    });\n};\n\n/**\n * If a constructor exists for the class {path}\n * This adds a super() call on top of it\n */\nconst addSuperToConstructor = (path, types) => {\n    const constructor = path\n        .get(\"body\")\n        .get(\"body\")\n        .find((member) => {\n            // Search for a constructor\n            const isConstructor = member.get(\"key\").node.name === \"constructor\";\n            if (!isConstructor) {\n                return false;\n            }\n\n            // Handle TS overloads: ensure that the retrieved thing indeed is a method\n            const isMethod = member.get(\"type\").node === \"ClassMethod\";\n            if (!isMethod) {\n                return false;\n            }\n\n            return true;\n        });\n\n    if (!constructor) {\n        return;\n    }\n\n    const superCall = types.expressionStatement(\n        types.callExpression(types.super(), [])\n    );\n\n    try {\n        constructor.get(\"body\").unshiftContainer(\"body\", superCall);\n    } catch {\n        console.log(constructor);\n        process.exit(0);\n    }\n};\n\n/**\n * Checks the filename in order to verify that it belongs to an extension\n */\nconst isMustProcessNamespace = (state) => {\n    const { filename } = state.file.opts;\n\n    for (let i = 0; i < allowedPaths.length; i++) {\n        const allowedPath = allowedPaths[i];\n\n        if (filename.includes(allowedPath)) {\n            return true;\n        }\n    }\n\n    return false;\n};\n\nmodule.exports = (options) => {\n    const { types } = options;\n\n    return {\n        name: \"middleware-decorators\",\n        visitor: {\n            // Transform leading comments of anonymous arrow functions\n            ArrowFunctionExpression: (path, state) => {\n                if (!isMustProcessNamespace(state)) {\n                    return;\n                }\n\n                const namespace = getNamespaceFromPath(path);\n\n                if (!namespace) {\n                    return;\n                }\n\n                removeNamespaceFromPath(path, namespace);\n\n                path.replaceWith(\n                    types.callExpression(\n                        types.memberExpression(\n                            types.identifier(\"Mosaic\"),\n                            types.identifier(\"middleware\")\n                        ),\n                        [path.node, types.stringLiteral(namespace)]\n                    )\n                );\n            },\n\n            VariableDeclaration: (path, state) => {\n                if (!isMustProcessNamespace(state)) {\n                    return;\n                }\n\n                const namespace = getNamespaceFromPath(path);\n                if (!namespace) {\n                    return;\n                }\n\n                removeNamespaceFromPath(path, namespace);\n\n                const declarator = path.get(\"declarations\")[0];\n                const init = declarator.get(\"init\");\n\n                init.replaceWith(\n                    types.callExpression(\n                        types.memberExpression(\n                            types.identifier(\"Mosaic\"),\n                            types.identifier(\"middleware\")\n                        ),\n                        [init.node, types.stringLiteral(namespace)]\n                    )\n                );\n            },\n\n            FunctionDeclaration: (path, state) => {\n                if (!isMustProcessNamespace(state)) {\n                    return;\n                }\n\n                const namespace = getNamespaceFromPath(path);\n                if (!namespace) {\n                    return;\n                }\n\n                removeNamespaceFromPath(path, namespace);\n\n                const {\n                    node: {\n                        id: { name },\n                        params,\n                        body\n                    }\n                } = path;\n\n                const functionExpression = types.functionExpression(\n                    types.identifier(name),\n                    params,\n                    body\n                );\n\n                const middlewaredFunctionExpression = types.callExpression(\n                    types.memberExpression(\n                        types.identifier(\"Mosaic\"),\n                        types.identifier(\"middleware\")\n                    ),\n                    [functionExpression, types.stringLiteral(namespace)]\n                );\n\n                const declarator = types.variableDeclarator(\n                    types.identifier(name),\n                    middlewaredFunctionExpression\n                );\n\n                const declaration = types.variableDeclaration(\"let\", [declarator]);\n\n                const isDefaultExport = isParentExportDefaultDeclaration(path);\n\n                // Handle regular case\n                if (!isDefaultExport) {\n                    path.replaceWith(declaration);\n                    return;\n                }\n\n                // Handle default export\n                const { parentPath } = path;\n\n                const exportDefaultDeclaration = types.exportDefaultDeclaration(\n                    types.identifier(name)\n                );\n\n                parentPath.insertAfter(exportDefaultDeclaration);\n                parentPath.replaceWith(declaration);\n            },\n\n            // TODO make this work with class expressions ?\n            ClassDeclaration: (path, state) => {\n                if (!isMustProcessNamespace(state)) {\n                    return;\n                }\n\n                const namespace = getNamespaceFromPath(path);\n                if (!namespace) {\n                    return;\n                }\n\n                // Consume the used namespace: prevent middleware(middleware(...))\n                removeNamespaceFromPath(path, namespace);\n\n                // Extract all the contents of a class\n                const superClass = path.get(\"superClass\");\n                const id = path.get(\"id\");\n                const body = path.get(\"body\");\n                const decorators = path.get(\"decorators\");\n                const initialImplements = path.get(\"implements\");\n                const mixins = path.get(\"mixins\");\n                const superTypeParameters = path.get(\"superTypeParameters\");\n                const typeParameters = path.get(\"typeParameters\");\n\n                // Mosaic.Extensible(SuperClass || undefined)\n                const superExpression = types.callExpression(\n                    types.memberExpression(\n                        types.identifier(\"Mosaic\"),\n                        types.identifier(\"Extensible\")\n                    ),\n                    [(superClass && superClass.node) || types.identifier(\"\")]\n                );\n\n                // If the middlewarable class did not have a base class before\n                // We should add a super() call to its constructor\n                if (!superClass.node) {\n                    addSuperToConstructor(path, types);\n                }\n\n                // Set the new base class\n                superClass.replaceWith(superExpression);\n\n                const {\n                    node: { name }\n                } = path.get(\"id\");\n\n                // Generate the middlewarable class as an expression,\n                // To be able to operate with it as with a variable, not as with a declaration\n                // ClassExpression != ClassDeclaration\n                // This class deliberately does not have a name in the moment of declaration\n                // Having a name there will cause calls to the class from within itself not respect middleware\n                const classExpression = types.classExpression(\n                    types.identifier(`${id.node.name}_`),\n                    superClass.node,\n                    body.node,\n                    decorators.node\n                );\n\n                // Return all the stuff that's been on the initial class\n                if (Array.isArray(initialImplements)) {\n                    classExpression.implements = initialImplements.map((x) => x.node);\n                }\n\n                if (Array.isArray(decorators)) {\n                    classExpression.decorators = decorators.map((x) => x.node);\n                }\n\n                classExpression.mixins = mixins.node;\n                classExpression.superTypeParameters = superTypeParameters.node;\n                classExpression.typeParameters = typeParameters.node;\n\n                // Generate the final middleware expression\n                // Mosaic.middleware(class {}, 'namespace')\n                const wrappedInMiddeware = types.callExpression(\n                    types.memberExpression(\n                        types.identifier(\"Mosaic\"),\n                        types.identifier(\"middleware\")\n                    ),\n                    [classExpression, types.stringLiteral(namespace.trim())]\n                );\n\n                // SomeClass = Mosaic...<generated above thing>\n                const declarator = types.variableDeclarator(\n                    types.identifier(name),\n                    wrappedInMiddeware\n                );\n\n                // const SomeClass = ...\n                const newDeclaration = types.variableDeclaration(\"const\", [declarator]);\n\n                // If the class was export default'ed initially\n                // We need to remove the initial exdf, because `export default const x = ...` is not valid\n                // And generate a new exdf with just the class' name\n                if (isParentExportDefaultDeclaration(path)) {\n                    const newExportDefaultDeclaration = types.exportDefaultDeclaration(\n                        types.identifier(name)\n                    );\n\n                    path.insertAfter(newExportDefaultDeclaration);\n                    path.parentPath.replaceWith(newDeclaration);\n                } else {\n                    // In all the other cases - just replace the generated thing\n                    // With a new declaration\n                    path.replaceWith(newDeclaration);\n                }\n            }\n        }\n    };\n};\n"]}