z icon indicating copy to clipboard operation
z copied to clipboard

Matching doesn't work on strings

Open cirokd opened this issue 6 years ago • 5 comments

Hello!

First of all, great library, thank you!

I just introduced z (version 1.0.8) to a project and I cannot seem to get it to work with strings. I created a sandbox in which I recreated the issue I faced. It also includes two tests from the test suite that don't work as expected. I'm not familiar with the source code but anyways let me know if I can be of help fixing this issue.

Here is the sandbox: https://codesandbox.io/s/w6kql5km47 Thank you in advance for your time looking into this!

cirokd avatar Sep 27 '18 14:09 cirokd

Hi @cirokd , your sandbox at codesandbox.io is using babel which transpile your code, so z isn't receiving your actual code but a transpiled one (which doesn't suit very well for z).

I don't know codesandbox.io much, but I tried going on configuration files, added .babelrc then I cleaned up the preset and then your code ran as expected 😁 , the .babelrc file looked like this:

{
  "plugins": [
    [
      "transform-runtime",
      {
        "polyfill": false,
        "regenerator": true
      }
    ],
    "transform-object-rest-spread"
  ]
}

If you want to use z with babel is possible, just select a stage which is compatible with functions with default parameters, you can see more here: https://babeljs.io/docs/en/next/presets#stage-x-experimental-presets

leonardiwagner avatar Sep 27 '18 15:09 leonardiwagner

Thank you @leonardiwagner for your quick response!

I found this page on MDN about default parameters. Can you please tell me if I need "Basic support" only, or is "Destructured parameter with default value assignment" necessary as well? What is required for z to work?

cirokd avatar Sep 28 '18 09:09 cirokd

@cirokd actually I don't even think z itself use default parameters at all! The requirement to use the basic support of default parameters in your case is because you are using default parameters on z and this shouldn't be transpiled, so you can go with "basic support".

That means if later you want to use object matches in z, then will be required "destructured parameters" support once the objects matches are written using destructured parameters!

tl;dr; it will depend on what you want to write on z, not z itself , "basic support" is fine in your case :smile:

leonardiwagner avatar Sep 28 '18 19:09 leonardiwagner

Thank you for your time!

cirokd avatar Oct 03 '18 09:10 cirokd

so z isn't receiving your actual code but a transpiled one (which doesn't suit very well for z)

Would you accept a PR to warn about this at the top of the README? This is a very major caveat and users deserve to know up front about it.

jedwards1211 avatar Jun 06 '20 08:06 jedwards1211