Skip to content

Commit a1da3f4

Browse files
committed
fix: build
1 parent b444158 commit a1da3f4

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"@typescript-eslint/parser": "^6.7.2",
7070
"@vitest/coverage-istanbul": "^0.34.4",
7171
"@vue/consolidate": "0.17.3",
72+
"ast-kit": "^0.11.2",
7273
"chalk": "^4.1.0",
7374
"conventional-changelog-cli": "^4.1.0",
7475
"enquirer": "^2.4.1",

pnpm-lock.yaml

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/const-enum.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { parse } from '@babel/parser'
2626
import path from 'node:path'
2727
import MagicString from 'magic-string'
28+
import { locateTrailingComma } from 'ast-kit'
2829

2930
const ENUM_CACHE_PATH = 'temp/enum.json'
3031

@@ -227,15 +228,22 @@ export function constEnum() {
227228
enumData.ids.includes(spec.local.name)
228229
) {
229230
const next = node.specifiers[i + 1]
230-
if (next) {
231-
// @ts-ignore
232-
s.remove(spec.start, next.start)
233-
} else {
234-
// last one
235-
const prev = node.specifiers[i - 1]
236-
// @ts-ignore
237-
s.remove(prev ? prev.end : spec.start, spec.end)
238-
}
231+
const trailingComma = locateTrailingComma(
232+
code,
233+
// @ts-expect-error
234+
spec.end,
235+
next
236+
? next.start
237+
: node.source
238+
? node.source.start
239+
: node.end,
240+
)
241+
242+
s.remove(
243+
// @ts-expect-error
244+
spec.start,
245+
trailingComma !== -1 ? trailingComma + 1 : spec.end,
246+
)
239247
}
240248
}
241249
}

0 commit comments

Comments
 (0)