babel-plugin-tester icon indicating copy to clipboard operation
babel-plugin-tester copied to clipboard

How to specify the ordering of the tested plugin

Open cibernox opened this issue 5 years ago • 0 comments

Hi.

I'm trying to write a babel plugin that transforms one decorator into a different one. For instance transform

class MyClass {
  @injectIfEnabled('FEATURE') router
}

into

class MyClass {
  @inject router
}

when that feature is enabled or into

class MyClass {
  @inject router
}

when it's not.

I'm running these:

  • babel-plugin-tester 9.2.0:
  • node 14:
  • npm (or yarn) version: 6.14

The problem I'm facing is that since my plugin looks for class properties with a decorator named injectIfEnabled, I need the plugin to run before @babel/plugin-proposal-decorators has transpiled decorators.

I can't seem to find a way of specifying that the plugin under testing must run in a specific order:

pluginTester({
    plugin: myPlugin,
    pluginName: 'my-plugin',
    babelOptions: {
        plugins: [
          ['@babel/plugin-syntax-decorators', { legacy: true }],
          // myPlugin should run here
          ['@babel/plugin-proposal-class-properties', { loose: true }]
        ]
    },
})

Am I missing something or this is really not possible right now?

cibernox avatar Aug 19 '20 18:08 cibernox