Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/babel-8-core-upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"weapp-tailwindcss": major
"@weapp-tailwindcss/babel": major
---

升级核心 Babel 解析与遍历依赖到 8.x,并适配 Babel 8 的 ESM-only 与同步 transform API 变化;同时将相关包的 Node.js 支持范围调整为 Babel 8 要求的 `^22.18.0 || >=24.11.0`。
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"gulp-plugin"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
"node": "^22.18.0 || >=24.11.0"
},
"scripts": {
"build": "cross-env WEAPP_TW_SKIP_INTERACTIVE_TARO_BUILD=1 WEAPP_TW_SKIP_INTERACTIVE_UNI_BUILD=1 turbo run build",
Expand Down Expand Up @@ -215,8 +215,8 @@
},
"devDependencies": {
"@ampproject/remapping": "^2.3.0",
"@babel/core": "catalog:babelCore7285",
"@babel/generator": "~7.29.7",
"@babel/core": "catalog:babelCore8",
"@babel/generator": "^8.0.0",
"@changesets/changelog-github": "^0.7.0",
"@changesets/cli": "^2.31.0",
"@commitlint/cli": "^21.0.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dist"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
"node": "^22.18.0 || >=24.11.0"
},
"scripts": {
"dev": "tsdown --watch --sourcemap",
Expand All @@ -34,9 +34,9 @@
"lint:fix": "eslint . --fix"
},
"dependencies": {
"@babel/parser": "~7.29.7",
"@babel/traverse": "~7.29.7",
"@babel/types": "~7.29.7"
"@babel/parser": "^8.0.0",
"@babel/traverse": "^8.0.0",
"@babel/types": "^8.0.0"
},
"publishConfig": {
"exports": {
Expand Down
9 changes: 5 additions & 4 deletions packages/babel/test/evaluate.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import babel from '@babel/core'
import type { PluginItem } from '@babel/core'
import { transformSync } from '@babel/core'
import fs from 'fs-extra'
import path from 'pathe'

function getCase(name: string) {
return fs.readFileSync(path.resolve(import.meta.dirname, './fixtures/evaluate', name), 'utf8')
}

const plugin: babel.PluginItem = {
const plugin: PluginItem = {
visitor: {
BinaryExpression(path) {
// 尝试计算二元表达式的常量值
Expand Down Expand Up @@ -68,7 +69,7 @@ const plugin: babel.PluginItem = {
}
describe('evaluate', () => {
it('0.js', () => {
const res = babel.transform(
const res = transformSync(
getCase('0.js'),
{
plugins: [
Expand All @@ -82,7 +83,7 @@ describe('evaluate', () => {
})

it('1.js', () => {
const res = babel.transform(
const res = transformSync(
getCase('1.js'),
{
plugins: [
Expand Down
5 changes: 2 additions & 3 deletions packages/minify-preserve/test/bundler-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { PluginObj, PluginPass } from '@babel/core'
import { transformAsync } from '@babel/core'
import type { Configuration, Stats } from 'webpack'
import { mkdtemp, readdir, readFile, rm, writeFile } from 'node:fs/promises'
import { createRequire } from 'node:module'
Expand Down Expand Up @@ -235,8 +236,6 @@ async function bundleWithSwc(keepFnNames: boolean) {
return result.code.trim()
}

const babel = require('@babel/core') as typeof import('@babel/core')

interface ManglePluginOptions {
keepNames?: boolean
}
Expand Down Expand Up @@ -265,7 +264,7 @@ function babelManglePlugin(): PluginObj<BabelManglePluginState> {
}

async function bundleWithBabel(keepFnNames: boolean) {
const result = await babel.transformAsync(BABEL_SOURCE, {
const result = await transformAsync(BABEL_SOURCE, {
configFile: false,
babelrc: false,
sourceType: 'module',
Expand Down
8 changes: 4 additions & 4 deletions packages/weapp-tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"with-layer.css"
],
"engines": {
"node": "^20.19.0 || >=22.12.0"
"node": "^22.18.0 || >=24.11.0"
},
"scripts": {
"dev": "tsdown --watch --sourcemap",
Expand Down Expand Up @@ -202,9 +202,9 @@
},
"dependencies": {
"@ast-core/escape": "~1.0.1",
"@babel/parser": "~7.29.7",
"@babel/traverse": "~7.29.7",
"@babel/types": "~7.29.7",
"@babel/parser": "^8.0.0",
"@babel/traverse": "^8.0.0",
"@babel/types": "^8.0.0",
"@vue/compiler-dom": "catalog:vue3",
"@weapp-core/escape": "~8.0.0",
"@weapp-tailwindcss/logger": "workspace:*",
Expand Down
13 changes: 2 additions & 11 deletions packages/weapp-tailwindcss/test/js/babel-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { NodePath } from '@babel/traverse'
import type { CallExpression } from '@babel/types'
import * as parser from '@babel/parser'
import { MappingChars2String } from '@weapp-core/escape'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { afterEach, describe, expect, it } from 'vitest'
import { parse, traverse } from '@/babel'
import * as babel from '@/js/babel'

Expand All @@ -14,13 +13,12 @@ describe('babel helpers additional coverage', () => {

it('memoises parsed ASTs when parser caching is enabled', () => {
const code = 'const value = 1'
const spy = vi.spyOn(parser, 'parse')
const parserOptions = { sourceType: 'module' as const, cache: true }
const first = babel.babelParse(code, parserOptions)
const second = babel.babelParse(code, parserOptions)

expect(spy).toHaveBeenCalledTimes(1)
expect(second).toBe(first)
expect(babel.parseCache.size).toBe(1)
})

it('uses hashed parser cache keys instead of retaining source text in keys', () => {
Expand All @@ -33,7 +31,6 @@ describe('babel helpers additional coverage', () => {

it('skips parser caching for sources over the configured source length limit', () => {
const code = 'const value = "text-red-500"'
const spy = vi.spyOn(parser, 'parse')
const first = babel.babelParse(code, {
sourceType: 'module' as const,
cache: true,
Expand All @@ -45,14 +42,11 @@ describe('babel helpers additional coverage', () => {
cacheMaxSourceLength: code.length - 1,
})

expect(spy).toHaveBeenCalledTimes(2)
expect(second).not.toBe(first)
expect(babel.parseCache.size).toBe(0)
})

it('trims parser cache entries to the configured entry limit', () => {
const spy = vi.spyOn(parser, 'parse')

const first = babel.babelParse('const first = 1', {
sourceType: 'module' as const,
cache: true,
Expand All @@ -69,19 +63,16 @@ describe('babel helpers additional coverage', () => {
cacheMaxEntries: 1,
})

expect(spy).toHaveBeenCalledTimes(3)
expect(second).not.toBe(first)
expect(third).not.toBe(first)
expect(babel.parseCache.size).toBe(1)
})

it('does not retain parsed ASTs when parser caching is disabled', () => {
const code = 'const value = 1'
const spy = vi.spyOn(parser, 'parse')
const first = babel.babelParse(code, { sourceType: 'module' as const, cache: false })
const second = babel.babelParse(code, { sourceType: 'module' as const, cache: false })

expect(spy).toHaveBeenCalledTimes(2)
expect(second).not.toBe(first)
expect(babel.parseCache.size).toBe(0)
})
Expand Down
Loading
Loading