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

Parcel 2 doesn't know precedence of await or logical or assignment #6765

Closed
danieltroger opened this issue Aug 25, 2021 · 1 comment · Fixed by #6848
Closed

Parcel 2 doesn't know precedence of await or logical or assignment #6765

danieltroger opened this issue Aug 25, 2021 · 1 comment · Fixed by #6848

Comments

@danieltroger
Copy link
Contributor

🐛 bug report

Parcel (I think it's SWC because babel seems to do it correctly) doesn't do precedence correctly when using await and logical OR assignment.

🎛 Configuration (.babelrc, package.json, cli command)

{
  "dependencies": {
    "parcel": "nightly"
  },
  "targets": {
    "modern": {
      "engines": {
        "browsers": "firefox 77"
      }
    }
  }
}

🤔 Expected Behavior

Output code: !async function(){let o;const s=await (o||(o=Promise.resolve("this is a string")));console.log(s.toString())}();

Eval result: this is a string

😯 Current Behavior

Output code: !async function(){let o;const s=await o||(o=Promise.resolve("this is a string"));console.log(s.toString())}();

Eval result: [object Promise]

💁 Possible Solution

Don't remove parentheses where that changes the code

🔦 Context

I happily deployed my code to production and it broke. After an hour of debugging and hating yarn berry or whatever gave me this issue when I tried to upgrade parcel:

🚨 Build failed.

@parcel/core: Failed to resolve 'src/test/temp-12545.tsx'

@parcel/resolver-default: The "path" argument must be of type string. Received undefined

  TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
  at new NodeError (node:internal/errors:371:5)
  at validateString (node:internal/validators:119:11)
  at Object.isAbsolute (node:path:1157:5)
  at NodeResolver.resolveModule
  ([project_dir]/.yarn/cache/@parcel-node-resolver-core-npm-2.0.0-nightly.2418-a46b40c4e1-9a61779ada.zip/node_modules/@parcel/node-resolver-core/lib/NodeResolver.js:224:25)
  at async NodeResolver.resolve
  ([project_dir]/.yarn/cache/@parcel-node-resolver-core-npm-2.0.0-nightly.2418-a46b40c4e1-9a61779ada.zip/node_modules/@parcel/node-resolver-core/lib/NodeResolver.js:137:20)
  at async ResolverRunner.resolve
  ([project_dir]/.yarn/cache/@parcel-core-npm-2.0.0-nightly.809-cffd5f51ab-eda7e37cd3.zip/node_modules/@parcel/core/lib/requests/PathRequest.js:207:22)
  at async Object.run ([project_dir]/.yarn/cache/@parcel-core-npm-2.0.0-nightly.809-cffd5f51ab-eda7e37cd3.zip/node_modules/@parcel/core/lib/requests/PathRequest.js:104:16)
  at async RequestTracker.runRequest ([project_dir]/.yarn/cache/@parcel-core-npm-2.0.0-nightly.809-cffd5f51ab-eda7e37cd3.zip/node_modules/@parcel/core/lib/RequestTracker.js:711:20)
  at async AssetGraphBuilder.runPathRequest
  ([project_dir]/.yarn/cache/@parcel-core-npm-2.0.0-nightly.809-cffd5f51ab-eda7e37cd3.zip/node_modules/@parcel/core/lib/requests/AssetGraphRequest.js:722:18)
  at async PromiseQueue._runFn ([project_dir]/.yarn/cache/@parcel-utils-npm-2.0.0-nightly.811-05dc7f2595-6b3d9e3e8a.zip/node_modules/@parcel/utils/lib/PromiseQueue.js:88:7)

I have finally produced this issue report.
Similar issue: #5759

💻 Code Sample

main();

async function main() {
  let promise: Promise<string>;

  const awaited_promise = await (promise ||= Promise.resolve("this is a string"));
  console.log(awaited_promise.toString());
}

🌍 Your Environment

Software Version(s)
Parcel 2.0.0-nightly.809+95f5648d
Node v16.7.0
npm/Yarn yarn 3.0.1
Operating System macOS 10.15.7 (19H1323)
@danieltroger
Copy link
Contributor Author

@mischnic https://github.com/swc-project/swc/releases/tag/v1.2.83 was just released, I think you can upgrade. Thanks for the quick report :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants