import { IPlugin } from "./i-plugin" ; import BasePlugin from "./base-plugin" ; import { CssType } from "../type/css-type" ; import { AppletType } from "../type/applet-type" ; import { cssTransform } from "../css/css-transform" ; author CaMnter
  class CssPlugin extends BasePlugin { private _targetCss ? : CssType ; private _expectCss ? : CssType ; constructor ( target , expect ) { super ( target , expect ) ; } run ( code ) { if ( ! code || '' === code ) { throw new Error ( `CssPlugin # constructor #「code」error: ${ code }` ) ; } this . checkAppletType ( '_target' , '_targetCss' , this . _target ) ; this . checkAppletType ( '_expect' , '_expectCss' , this . _expect ) ; if ( ! this . _targetCss || ! this . _expectCss ) { throw new Error ( `CssPlugin # run # missing CssType「this.targetCss」: ${ this . _targetCss }「this.expectCss」: ${ this . _expectCss }` ) ; } this . _result = cssTransform ( code , this . _targetCss , this . _expectCss ) ; return this . _result ; } checkAppletType ( name , targetCssName , target ) { const _this = this as any ; switch ( target ) { case AppletType . wx : _this [ `${ targetCssName }` ] = CssType . wxss ; break ; case AppletType . my : _this [ `${ targetCssName }` ] = CssType . acss ; break ; default : throw new Error ( `CssPlugin # checkAppletType # atypical applet type「${ name }」: ${ this . _target }` ) ; break ; } } get targetCss ( ) : CssType | undefined { return this . _targetCss ; } get expectCss ( ) : CssType | undefined { return this . _expectCss ; } } export default CssPlugin ;