Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 8ef598e

Browse files
committed
fix: esm compactiblity
1 parent 17b45ff commit 8ef598e

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/core/identifiers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrivateName, Expression, Statement, SpreadElement, Node, TSType } from '@babel/types'
1+
import type { PrivateName, Expression, Statement, SpreadElement, Node, TSType } from '@babel/types'
22

33
export function getIdentifierDeclarations(nodes: Statement[], identifiers = new Set<string>()) {
44
for (let node of nodes) {

src/core/macros.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// modified from https://github.com/vuejs/vue-next/blob/main/packages/compiler-sfc/src/compileScript.ts
22

3-
import {
3+
import type {
44
Node,
55
ObjectExpression,
66
TSType,
@@ -11,8 +11,11 @@ import {
1111
CallExpression,
1212
TSInterfaceBody,
1313
} from '@babel/types'
14-
import { types as t } from '@babel/core'
15-
import { parseExpression } from '@babel/parser'
14+
import * as babelCore from '@babel/core'
15+
import * as babelParser from '@babel/parser'
16+
17+
const { types: t } = babelCore
18+
const { parseExpression } = babelParser
1619

1720
// Special compiler macros
1821
const DEFINE_PROPS = 'defineProps'

src/core/transformScriptSetup.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { types as t } from '@babel/core'
1+
import * as babelCore from '@babel/core'
22
import { camelize, capitalize } from '@vue/shared'
3-
import { Node, Statement } from '@babel/types'
3+
import type { Node, ObjectExpression, Statement } from '@babel/types'
44
import generate from '@babel/generator'
55
import { partition } from '@antfu/utils'
66
import { ParsedSFC, ScriptSetupTransformOptions } from '../types'
77
import { applyMacros } from './macros'
88
import { getIdentifierDeclarations } from './identifiers'
99

10+
const { types: t } = babelCore
11+
1012
function isAsyncImport(node: any) {
1113
if (node.type === 'VariableDeclaration') {
1214
const declaration = node.declarations[0]
@@ -38,7 +40,7 @@ export function transformScriptSetup(sfc: ParsedSFC, options?: ScriptSetupTransf
3840
getIdentifierDeclarations(setupBody, declarations)
3941

4042
// filter out identifiers that are used in `<template>`
41-
const returns: t.ObjectExpression['properties'] = Array.from(declarations)
43+
const returns: ObjectExpression['properties'] = Array.from(declarations)
4244
.filter(Boolean)
4345
.filter(i => template.identifiers.has(i))
4446
.map((i) => {

0 commit comments

Comments
 (0)