Skip to content

Commit 4e2a327

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

File tree

4 files changed

+37
-22
lines changed

4 files changed

+37
-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

+13-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,19 @@ 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 (
47+
node.declaration.decorators &&
48+
node.start === node.declaration.start
49+
) {
50+
s.overwrite(
51+
node.declaration.decorators[node.declaration.decorators.length - 1]
52+
.end! + 1,
53+
node.declaration.id.start!,
54+
`class `
55+
)
56+
} else {
57+
s.overwrite(node.start!, node.declaration.start!, ``)
58+
}
4759
s.append(`\nconst ${as} = ${node.declaration.id.name}`)
4860
} else {
4961
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)