Skip to content

Commit 5f40d53

Browse files
committed
fix: build
1 parent 74a83f9 commit 5f40d53

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"@typescript-eslint/parser": "^6.13.2",
7474
"@vitest/coverage-istanbul": "^1.0.4",
7575
"@vue/consolidate": "0.17.3",
76+
"ast-kit": "^0.11.2",
7677
"conventional-changelog-cli": "^4.1.0",
7778
"enquirer": "^2.4.1",
7879
"esbuild": "^0.19.5",

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
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)