Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.1 KB
Raw Blame
/**
 * Babel plugin that replaces `import.meta.hot` with `undefined`.
 *
 * `babel-plugin-transform-import-meta` handles standard properties (url,
 * filename, dirname, resolve) but does NOT handle the Vite-specific `hot`
 * property.  Jest runs in CommonJS/Node where `import.meta` is unavailable,
 * so any reference to `import.meta.hot` causes a SyntaxError.
 *
 * Replacing it with `undefined` makes the HMR guard blocks dead-code:
 *   import.meta.hot?.data  →  undefined?.data  →  undefined
 *   if (import.meta.hot)   →  if (undefined)   →  skipped
 */
module.exports = function transformImportMetaHot() {
  return {
    name: 'transform-import-meta-hot',
    visitor: {
      MemberExpression(path) {
        const { node } = path;
        if (
          node.object.type === 'MetaProperty' &&
          node.object.meta.name === 'import' &&
          node.object.property.name === 'meta' &&
          node.property.type === 'Identifier' &&
          node.property.name === 'hot'
        ) {
          path.replaceWith({ type: 'Identifier', name: 'undefined' });
        }
      },
    },
  };
};