Skip to content

Commit 42aff5f

Browse files
committed
fix(compiler-sfc): fix rewriteDefault problem when using @babel/parser^7.20.0
1 parent 2e57061 commit 42aff5f

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"csstype": "^3.1.0"
8888
},
8989
"devDependencies": {
90-
"@babel/parser": "^7.18.4",
90+
"@babel/parser": "^7.20.5",
9191
"@microsoft/api-extractor": "^7.25.0",
9292
"@rollup/plugin-alias": "^3.1.9",
9393
"@rollup/plugin-commonjs": "^22.0.0",

packages/compiler-sfc/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"dist"
99
],
1010
"dependencies": {
11-
"@babel/parser": "^7.18.4",
11+
"@babel/parser": "^7.20.5",
1212
"postcss": "^8.4.14",
1313
"source-map": "^0.6.1"
1414
},
1515
"devDependencies": {
16-
"@babel/types": "^7.19.4",
16+
"@babel/types": "^7.20.5",
1717
"@types/estree": "^0.0.48",
1818
"@types/hash-sum": "^1.0.0",
1919
"@types/lru-cache": "^5.1.1",

packages/compiler-sfc/src/rewriteDefault.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ export function rewriteDefault(
4343
ast.forEach(node => {
4444
if (node.type === 'ExportDefaultDeclaration') {
4545
if (node.declaration.type === 'ClassDeclaration') {
46-
s.overwrite(node.start!, node.declaration.id.start!, `class `)
46+
if (node.declaration.decorators) {
47+
s.overwrite(
48+
node.declaration.decorators[node.declaration.decorators.length - 1]
49+
.end!,
50+
node.declaration.id.start!,
51+
`class `
52+
)
53+
} else {
54+
s.overwrite(node.start!, node.declaration.start!, ``)
55+
}
4756
s.append(`\nconst ${as} = ${node.declaration.id.name}`)
4857
} else {
4958
s.overwrite(node.start!, node.declaration.start!, `const ${as} = `)

pnpm-lock.yaml

+21-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)