Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add await option for next-tick-style rule#2508

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
codiini wants to merge5 commits intovuejs:master
base:master
Choose a base branch
Loading
fromcodiini:await/next-tick-style

Conversation

codiini
Copy link

This PR addresses#2485

callbackBody =
args.type === 'ArrowFunctionExpression' ||
args.type === 'FunctionExpression'
? extractCallbackBody(args, sourceCode)
Copy link
Contributor

@fiskerfiskerJul 15, 2024
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We can't extract callback body directly, there might be variable conflicts.

exportdefault{asynccreated(){constfoo=1;nextTick(()=>{constfoo=2;doSomething(foo);})}}

if (callback.body.type === 'BlockStatement') {
return sourceCode
.getText(callback.body)
.slice(1, -1) // Remove curly braces
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe we can simply keep the block.


callbackBody =
args.type === 'ArrowFunctionExpression' ||
args.type === 'FunctionExpression'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
args.type==='FunctionExpression'
(args.type==='FunctionExpression'&&!args.geneator)

const sourceCode = context.getSourceCode()

// Handle callback to await conversion
if (callExpression.arguments.length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
if(callExpression.arguments.length>0){
if(callExpression.arguments.length===1){

)
return fixer.replaceText(
callExpression.parent,
`await ${nextTickCaller}();${callbackBody};`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We need make sure thenextTick call is an expression statement, otherwise this will cause sytax errors.

if (foo) nextTick(...)
(() => nextTick(...))();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@fisker How would you suggest the fix method handle these cases?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ignore or turn into a block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

"ignore" means no fix

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Okay, I've added a check.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Isn't it related to this one:#2508 (comment) ?
I removed the.slice() method which keeps the block

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry didn't see that change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No worries. Is everything good to go now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not a maintainer..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This seems not the correct fix.. It changes behavior

nextTick(()=>console.log(2))console.log(1)

Logs1 2

awaitnextTick();console.log(2)console.log(1)

Logs2 1

Maybe use suggestions instead?

function isAwaitedFunction(callExpression) {
return (
callExpression.parent.type === 'AwaitExpression' &&
callExpression.parent.parent.type !== 'MemberExpression'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why this.parent.parent check needed.

@codiinicodiini requested a review fromfiskerJuly 22, 2024 13:46
Comment on lines +100 to +102
if (callback.body.type === 'BlockStatement') {
return sourceCode.getText(callback.body).trim()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We can remove this branch.

args.type === 'ArrowFunctionExpression' ||
(args.type === 'FunctionExpression' && !args.generator)
? extractCallbackBody(args, sourceCode)
: `${sourceCode.getText(args)}()`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is also not safe

nextTick(foo||bar)
- await nextTick(); foo || bar()+ await nextTick(); (foo || bar)()

Iffoo is truly, it will not be called

return sourceCode.getText(callback.body).trim()
}

return sourceCode.getText(callback.body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The function body can't exact directly if it hasreturn

constfoo=async()=>{nextTick(()=>{return;})returnfalse}

returnsfalse

constfoo=async()=>{awaitnextTick();{return;}returnfalse}

returnsundefined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It will also broken if the callback has.id or usedarguments inside.

constfoo=async()=>{nextTick(functionfoo(){use(foo)use(arguments)})}

Copy link
Member

@FloEdelmannFloEdelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@codiini Could you please address@fisker's comments?

@FloEdelmannFloEdelmann linked an issueAug 29, 2024 that may beclosed by this pull request
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@fiskerfiskerfisker left review comments

@FloEdelmannFloEdelmannFloEdelmann requested changes

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

New option fornext-tick-style
3 participants
@codiini@fisker@FloEdelmann

[8]ページ先頭

©2009-2025 Movatter.jp