-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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-core): No access this
through function declaration in <script setup>
#6827
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add unit tests of the issue?
Case added. Thanks. |
if ( | ||
parent && | ||
parent.type === 'CallExpression' && | ||
(type === BindingTypes.SETUP_LET || type === BindingTypes.SETUP_CONST) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why check BindingTypes
here? Consider this example, the problem is still existing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I had to make sure it's a function identifier with
parents.type
. Then use.bind()
to change the scope toundefined
. - Considered with the smallest dimension of the issue, including the following situations when
type
isBindingTypes.SETUP_CONST
orBindingTypes.SETUP_LET
:
// BindingTypes.SETUP_LET
let foo = () => {}
let foo = function() {}
// BindingTypes.SETUP_CONST
const foo = () => {}
const foo = function {}
function foo() {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many kinds of BindingTypes
. For generality, I don't think it's necessary to check BindingTypes
here.
Or if you have a better solution to fix the example I provided, it's also all right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated! The previous judgment was poor, and the following conditions are also met.
const foo = ref(function(a, b) {
console.log(this)
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, but CI is failed. You can push an empty commit git commit --allow-empty -m "Empty-Commit"
to re-run CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It's actually the other way around, it should fail in dev (like it does in prod): vitejs/vite#3872 (comment)
@posva This PR is true to fix - it will fail in both dev and prod mode. |
You are right, I was a bit too fast on reading that |
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-dom
@vue/runtime-core
@vue/shared
@vue/server-renderer
@vue/compat
vue
commit: |
Size ReportBundles
Usages
|
fix #6822