Skip to content

Commit 909ddba

Browse files
committed
fix(compiler-sfc): fix rewriteDefault problem when using @babel/parser@^7.20.0
1 parent fe77e2b commit 909ddba

File tree

9 files changed

+294
-76
lines changed

9 files changed

+294
-76
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"node": ">=16.11.0"
5454
},
5555
"devDependencies": {
56-
"@babel/types": "^7.12.0",
56+
"@babel/types": "^7.20.5",
5757
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
5858
"@microsoft/api-extractor": "~7.20.0",
5959
"@rollup/plugin-commonjs": "^23.0.2",

Diff for: packages/compiler-core/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme",
3434
"dependencies": {
3535
"@vue/shared": "3.2.45",
36-
"@babel/parser": "^7.16.4",
36+
"@babel/parser": "^7.20.5",
3737
"estree-walker": "^2.0.2",
3838
"source-map": "^0.6.1"
3939
},
4040
"devDependencies": {
41-
"@babel/types": "^7.16.0"
41+
"@babel/types": "^7.20.5"
4242
}
4343
}

Diff for: packages/compiler-sfc/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
3434
"dependencies": {
35-
"@babel/parser": "^7.16.4",
35+
"@babel/parser": "^7.20.5",
3636
"@vue/compiler-core": "3.2.45",
3737
"@vue/compiler-dom": "3.2.45",
3838
"@vue/compiler-ssr": "3.2.45",
@@ -45,7 +45,7 @@
4545
},
4646
"devDependencies": {
4747
"@types/estree": "^0.0.48",
48-
"@babel/types": "^7.16.0",
48+
"@babel/types": "^7.20.5",
4949
"@types/lru-cache": "^5.1.0",
5050
"pug": "^3.0.1",
5151
"sass": "^1.26.9",

Diff for: packages/compiler-sfc/src/compileScript.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export function compileScript(
363363
if (node.trailingComments && node.trailingComments.length > 0) {
364364
const lastCommentNode =
365365
node.trailingComments[node.trailingComments.length - 1]
366-
end = lastCommentNode.end + startOffset
366+
end = lastCommentNode.end! + startOffset
367367
}
368368
// locate the end of whitespace between this statement and the next
369369
while (end <= source.length) {
@@ -2018,14 +2018,18 @@ function extractEventNames(
20182018
) {
20192019
const typeNode = eventName.typeAnnotation.typeAnnotation
20202020
if (typeNode.type === 'TSLiteralType') {
2021-
if (typeNode.literal.type !== 'UnaryExpression') {
2021+
if (
2022+
typeNode.literal.type !== 'UnaryExpression' &&
2023+
typeNode.literal.type !== 'TemplateLiteral'
2024+
) {
20222025
emits.add(String(typeNode.literal.value))
20232026
}
20242027
} else if (typeNode.type === 'TSUnionType') {
20252028
for (const t of typeNode.types) {
20262029
if (
20272030
t.type === 'TSLiteralType' &&
2028-
t.literal.type !== 'UnaryExpression'
2031+
t.literal.type !== 'UnaryExpression' &&
2032+
t.literal.type !== 'TemplateLiteral'
20292033
) {
20302034
emits.add(String(t.literal.value))
20312035
}

Diff for: packages/compiler-sfc/src/rewriteDefault.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ 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+
const start =
47+
node.declaration.decorators?.[node.declaration.decorators?.length - 1]
48+
?.end ?? node.start
49+
s.overwrite(start!, node.declaration.id.start!, `class `)
4750
s.append(`\nconst ${as} = ${node.declaration.id.name}`)
4851
} else {
4952
s.overwrite(node.start!, node.declaration.start!, `const ${as} = `)
@@ -58,15 +61,19 @@ export function rewriteDefault(
5861
) {
5962
if (node.source) {
6063
if (specifier.local.name === 'default') {
61-
const end = specifierEnd(input, specifier.local.end!, node.end)
64+
const end = specifierEnd(input, specifier.local.end!, node.end!)
6265
s.prepend(
6366
`import { default as __VUE_DEFAULT__ } from '${node.source.value}'\n`
6467
)
6568
s.overwrite(specifier.start!, end, ``)
6669
s.append(`\nconst ${as} = __VUE_DEFAULT__`)
6770
continue
6871
} else {
69-
const end = specifierEnd(input, specifier.exported.end!, node.end)
72+
const end = specifierEnd(
73+
input,
74+
specifier.exported.end!,
75+
node.end!
76+
)
7077
s.prepend(
7178
`import { ${input.slice(
7279
specifier.local.start!,
@@ -78,7 +85,7 @@ export function rewriteDefault(
7885
continue
7986
}
8087
}
81-
const end = specifierEnd(input, specifier.end!, node.end)
88+
const end = specifierEnd(input, specifier.end!, node.end!)
8289
s.overwrite(specifier.start!, end, ``)
8390
s.append(`\nconst ${as} = ${specifier.local.name}`)
8491
}

Diff for: packages/reactivity-transform/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
},
2929
"homepage": "https://github.com/vuejs/core/tree/dev/packages/reactivity-transform#readme",
3030
"dependencies": {
31-
"@babel/parser": "^7.16.4",
31+
"@babel/parser": "^7.20.5",
3232
"@vue/compiler-core": "3.2.45",
3333
"@vue/shared": "3.2.45",
3434
"estree-walker": "^2.0.2",
3535
"magic-string": "^0.25.7"
3636
},
3737
"devDependencies": {
38-
"@babel/core": "^7.16.0",
39-
"@babel/types": "^7.16.0"
38+
"@babel/core": "^7.20.5",
39+
"@babel/types": "^7.20.5"
4040
}
4141
}

Diff for: packages/reactivity-transform/src/reactivityTransform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ export function transformAST(
395395
defaultValue = p.value.right
396396
}
397397
} else {
398-
key = p.computed ? p.key : (p.key as Identifier).name
398+
key = p.computed ? (p.key as Expression) : (p.key as Identifier).name
399399
if (p.value.type === 'Identifier') {
400400
// { foo: bar }
401401
nameId = p.value

Diff for: packages/vue-compat/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
"homepage": "https://github.com/vuejs/core/tree/main/packages/vue-compat#readme",
4040
"dependencies": {
41-
"@babel/parser": "^7.16.4",
41+
"@babel/parser": "^7.20.5",
4242
"estree-walker": "^2.0.2",
4343
"source-map": "^0.6.1"
4444
},

0 commit comments

Comments
 (0)