Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-sfc): fix rewriteDefault problem when using @babel/parser@^7.20.0 #7373

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"node": ">=16.11.0"
},
"devDependencies": {
"@babel/types": "^7.12.0",
"@babel/types": "^7.20.5",
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
"@microsoft/api-extractor": "~7.20.0",
"@rollup/plugin-commonjs": "^23.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-core#readme",
"dependencies": {
"@vue/shared": "3.2.45",
"@babel/parser": "^7.16.4",
"@babel/parser": "^7.20.5",
"estree-walker": "^2.0.2",
"source-map": "^0.6.1"
},
"devDependencies": {
"@babel/types": "^7.16.0"
"@babel/types": "^7.20.5"
}
}
4 changes: 2 additions & 2 deletions packages/compiler-sfc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
"dependencies": {
"@babel/parser": "^7.16.4",
"@babel/parser": "^7.20.5",
"@vue/compiler-core": "3.2.45",
"@vue/compiler-dom": "3.2.45",
"@vue/compiler-ssr": "3.2.45",
Expand All @@ -45,7 +45,7 @@
},
"devDependencies": {
"@types/estree": "^0.0.48",
"@babel/types": "^7.16.0",
"@babel/types": "^7.20.5",
"@types/lru-cache": "^5.1.0",
"pug": "^3.0.1",
"sass": "^1.26.9",
Expand Down
10 changes: 7 additions & 3 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export function compileScript(
if (node.trailingComments && node.trailingComments.length > 0) {
const lastCommentNode =
node.trailingComments[node.trailingComments.length - 1]
end = lastCommentNode.end + startOffset
end = lastCommentNode.end! + startOffset
}
// locate the end of whitespace between this statement and the next
while (end <= source.length) {
Expand Down Expand Up @@ -2018,14 +2018,18 @@ function extractEventNames(
) {
const typeNode = eventName.typeAnnotation.typeAnnotation
if (typeNode.type === 'TSLiteralType') {
if (typeNode.literal.type !== 'UnaryExpression') {
if (
typeNode.literal.type !== 'UnaryExpression' &&
typeNode.literal.type !== 'TemplateLiteral'
) {
emits.add(String(typeNode.literal.value))
}
} else if (typeNode.type === 'TSUnionType') {
for (const t of typeNode.types) {
if (
t.type === 'TSLiteralType' &&
t.literal.type !== 'UnaryExpression'
t.literal.type !== 'UnaryExpression' &&
t.literal.type !== 'TemplateLiteral'
) {
emits.add(String(t.literal.value))
}
Expand Down
21 changes: 17 additions & 4 deletions 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 All @@ -58,15 +67,19 @@ export function rewriteDefault(
) {
if (node.source) {
if (specifier.local.name === 'default') {
const end = specifierEnd(input, specifier.local.end!, node.end)
const end = specifierEnd(input, specifier.local.end!, node.end!)
s.prepend(
`import { default as __VUE_DEFAULT__ } from '${node.source.value}'\n`
)
s.overwrite(specifier.start!, end, ``)
s.append(`\nconst ${as} = __VUE_DEFAULT__`)
continue
} else {
const end = specifierEnd(input, specifier.exported.end!, node.end)
const end = specifierEnd(
input,
specifier.exported.end!,
node.end!
)
s.prepend(
`import { ${input.slice(
specifier.local.start!,
Expand All @@ -78,7 +91,7 @@ export function rewriteDefault(
continue
}
}
const end = specifierEnd(input, specifier.end!, node.end)
const end = specifierEnd(input, specifier.end!, node.end!)
s.overwrite(specifier.start!, end, ``)
s.append(`\nconst ${as} = ${specifier.local.name}`)
}
Expand Down
6 changes: 3 additions & 3 deletions packages/reactivity-transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
},
"homepage": "https://github.com/vuejs/core/tree/dev/packages/reactivity-transform#readme",
"dependencies": {
"@babel/parser": "^7.16.4",
"@babel/parser": "^7.20.5",
"@vue/compiler-core": "3.2.45",
"@vue/shared": "3.2.45",
"estree-walker": "^2.0.2",
"magic-string": "^0.25.7"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/types": "^7.16.0"
"@babel/core": "^7.20.5",
"@babel/types": "^7.20.5"
}
}
2 changes: 1 addition & 1 deletion packages/reactivity-transform/src/reactivityTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export function transformAST(
defaultValue = p.value.right
}
} else {
key = p.computed ? p.key : (p.key as Identifier).name
key = p.computed ? (p.key as Expression) : (p.key as Identifier).name
if (p.value.type === 'Identifier') {
// { foo: bar }
nameId = p.value
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"homepage": "https://github.com/vuejs/core/tree/main/packages/vue-compat#readme",
"dependencies": {
"@babel/parser": "^7.16.4",
"@babel/parser": "^7.20.5",
"estree-walker": "^2.0.2",
"source-map": "^0.6.1"
},
Expand Down
Loading