1.1.0 • Published 6 months ago

ts-loader-forcesupertransformer v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

ts-loader-forcesupertransformer: typescript 'super' enforcer

Add a @forceSuperCall tag in a method's JSDoc, and all overrides must call super or an error will be thrown during compilation.

Installation

npm install --save-dev ts-loader-forcesupertransformer

In your webpack config file, include the following code:

const forceSuperTransformer = require("ts-loader-forcesupertransformer");

module.exports = {
  // ...
  module: {
    rules: [
      {
        test: /\.ts$/,
        loader: "ts-loader",
        options: {
          getCustomTransformers: (program) => ({
            before: [forceSuperTransformer(program)],
          }),
        },
      },
    ],
  },
};

To renew the transformer after every build, call the exported function with null (necessary if using 'watch'):

module.exports = {
  // ...
  plugins: [
    {
      apply: (compiler) => {
        compiler.hooks.done.tap("AfterBuildPlugin", (compilation) => {
          forceSuperTransformer(null);
        });
      },
    },
  ],
};

Usage

Add the following jsdoc tag

/**
*
* @forceSuperTransformer_forceSuperCall
*/
public fooBar():boolean
{
    //important code
}

public override fooBar():boolean
{
    super.fooBar(); // compilation error if missing
}

Configuration

A custom JSDoc tag name can be provided:

const transformer = forceSuperTransformer(program, "customAttributeName");

If not provided, the name defaults to forceSuperTransformer_forceSuperCall.

Disclaimer

Not heavily tested. Contributions welcome.

1.1.0

6 months ago

1.0.9

7 months ago

1.0.8

7 months ago

1.0.7

8 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago