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

refactor: convert utils.transform to async function #4333

Merged
merged 2 commits into from Jan 4, 2022

Conversation

dnalborczyk
Copy link
Contributor

@dnalborczyk dnalborczyk commented Dec 30, 2021

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

Typescript found another potential bug during the conversion:

[!] (plugin typescript) Error: @rollup/plugin-typescript TS2454: Variable 'curPlugin' is used before being assigned.
src/utils/transform.ts (156:25)

156   throwPluginError(err, curPlugin.name, { hook: 'transform', id });

which makes sense, since the assignment is not guaranteed in the try block, if the code throws anywhere prior.

@codecov
Copy link

codecov bot commented Dec 30, 2021

Codecov Report

Merging #4333 (8856823) into master (7f55571) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #4333   +/-   ##
=======================================
  Coverage   98.44%   98.44%           
=======================================
  Files         205      205           
  Lines        7314     7316    +2     
  Branches     2084     2084           
=======================================
+ Hits         7200     7202    +2     
  Misses         55       55           
  Partials       59       59           
Impacted Files Coverage Δ
src/utils/transform.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7f55571...8856823. Read the comment docs.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

which makes sense, since the assignment is not guaranteed in the try block, if the code throws anywhere prior.

Actually it is guaranteed to be assigned because it is assigned before the first plugin hook is executed. There is nothing that can throw before this point. Which is why it is impossible to write a test to cover your change.
Maybe there is another way to make TypeScript happy than to add unnecessary optionals.

@dnalborczyk
Copy link
Contributor Author

Actually it is guaranteed to be assigned because it is assigned before the first plugin hook is executed. There is nothing that can throw before this point. Which is why it is impossible to write a test to cover your change. Maybe there is another way to make TypeScript happy than to add unnecessary optionals.

I know what you mean, I imagine it's not easy to track what's going on in the try block (what is guaranteed and what not).

let foo
try {
    foo = { name: 'name'}
} catch (err) {
    console.log(foo.name) // Object is possibly 'undefined'.(2532)
}

also lifting the callback out of the try/catch block didn't help:

let foo
function bar() {
    foo = { name: 'name'}
}
bar()
console.log(foo.name) // Object is possibly 'undefined'.(2532)

anyhow, I initialized the plugin name variable.

@lukastaegert lukastaegert merged commit 3943111 into rollup:master Jan 4, 2022
@dnalborczyk dnalborczyk deleted the transform-async branch January 11, 2022 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants