Skip to content

feat: add plugin options for customization #19

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

Merged
merged 4 commits into from
Oct 8, 2021
Merged

Conversation

twada
Copy link
Member

@twada twada commented Oct 8, 2021

Provide options for pattern customization.

fixes #6
refs: unassert-js/unassert#22

Example

for given config,

{
  "presets": [
    ...
  ],
  "plugins": [
    ["babel-plugin-unassert", {
      "variables": [
        "assert",
        "invariant",
        "nassert",
        "uassert"
      ],
      "modules": [
        "assert",
        "node:assert",
        "invariant",
        "nanoassert",
        "uvu/assert"
      ]
    }]
  ]
}

input:

'use strict';

var invariant = require('invariant');
const nassert = require('nanoassert');
import * as uassert from 'uvu/assert';


function add (a, b) {
    nassert(!isNaN(a));

    uassert.is(Math.sqrt(4), 2);
    uassert.is(Math.sqrt(144), 12);
    uassert.is(Math.sqrt(2), Math.SQRT2);

    invariant(someTruthyVal, 'This will not throw');
    invariant(someFalseyVal, 'This will throw an error with this message');

    return a + b;
}

output:

'use strict';

function add(a, b) {
  return a + b;
}

@twada twada merged commit b631029 into master Oct 8, 2021
@twada twada deleted the customization-options branch October 8, 2021 16:30
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.

Doesn't work with different local variable name
1 participant