From 9dccd01438c461dfd8ba7e6877f1f411c6bb07e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Sat, 13 Jan 2024 02:52:35 +0800 Subject: [PATCH] fix(plugin-jsx): interop default --- package.json | 1 + packages/babel-plugin-jsx/src/index.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e92deb4..7817acf 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "vue-jsx-monorepo", "private": true, "packageManager": "pnpm@8.14.1", + "type": "module", "scripts": { "build": "pnpm run -r build", "test": "vitest", diff --git a/packages/babel-plugin-jsx/src/index.ts b/packages/babel-plugin-jsx/src/index.ts index 1821479..4389d77 100644 --- a/packages/babel-plugin-jsx/src/index.ts +++ b/packages/babel-plugin-jsx/src/index.ts @@ -1,8 +1,8 @@ import * as t from '@babel/types'; import type * as BabelCore from '@babel/core'; -import template from '@babel/template'; +import _template from '@babel/template'; // @ts-expect-error -import syntaxJsx from '@babel/plugin-syntax-jsx'; +import _syntaxJsx from '@babel/plugin-syntax-jsx'; // @ts-expect-error import { addNamed, addNamespace, isModule } from '@babel/helper-module-imports'; import { type NodePath } from '@babel/traverse'; @@ -31,9 +31,17 @@ const hasJSX = (parentPath: NodePath) => { const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/; +/* #__NO_SIDE_EFFECTS__ */ +function interopDefault(m: any) { + return m.default || m; +} + +const syntaxJsx = /*#__PURE__*/ interopDefault(_syntaxJsx); +const template = /*#__PURE__*/ interopDefault(_template); + export default ({ types }: typeof BabelCore): BabelCore.PluginObj => ({ name: 'babel-plugin-jsx', - inherits: syntaxJsx, + inherits: /*#__PURE__*/ interopDefault(syntaxJsx), visitor: { ...transformVueJSX, ...sugarFragment,