Skip to content

Commit

Permalink
fix(compiler-sfc): fix rewriteDefault problem when using @babel/parse…
Browse files Browse the repository at this point in the history
…r^7.20.0
  • Loading branch information
linshuohao committed Dec 29, 2022
1 parent 2e57061 commit 42aff5f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"csstype": "^3.1.0"
},
"devDependencies": {
"@babel/parser": "^7.18.4",
"@babel/parser": "^7.20.5",
"@microsoft/api-extractor": "^7.25.0",
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^22.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-sfc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"dist"
],
"dependencies": {
"@babel/parser": "^7.18.4",
"@babel/parser": "^7.20.5",
"postcss": "^8.4.14",
"source-map": "^0.6.1"
},
"devDependencies": {
"@babel/types": "^7.19.4",
"@babel/types": "^7.20.5",
"@types/estree": "^0.0.48",
"@types/hash-sum": "^1.0.0",
"@types/lru-cache": "^5.1.1",
Expand Down
11 changes: 10 additions & 1 deletion packages/compiler-sfc/src/rewriteDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ export function rewriteDefault(
ast.forEach(node => {
if (node.type === 'ExportDefaultDeclaration') {
if (node.declaration.type === 'ClassDeclaration') {
s.overwrite(node.start!, node.declaration.id.start!, `class `)
if (node.declaration.decorators) {
s.overwrite(
node.declaration.decorators[node.declaration.decorators.length - 1]
.end!,
node.declaration.id.start!,
`class `
)
} else {
s.overwrite(node.start!, node.declaration.start!, ``)
}
s.append(`\nconst ${as} = ${node.declaration.id.name}`)
} else {
s.overwrite(node.start!, node.declaration.start!, `const ${as} = `)
Expand Down
39 changes: 21 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 42aff5f

Please sign in to comment.