@@ -16,6 +16,9 @@ import {
1616
1717export interface PluginConfig {
1818 fileType : string ;
19+
20+ /** prefer using class property to define utils */
21+ preferClassProperty ?: boolean ;
1922}
2023
2124const pluginFactory : BuilderComponentPluginFactory < PluginConfig > = ( config ?) => {
@@ -57,13 +60,25 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
5760 linkAfter : [ COMMON_CHUNK_NAME . ExternalDepsImport ] ,
5861 } ) ;
5962
60- next . chunks . push ( {
61- type : ChunkType . STRING ,
62- fileType : cfg . fileType ,
63- name : CLASS_DEFINE_CHUNK_NAME . ConstructorContent ,
64- content : 'this.utils = utils;' ,
65- linkAfter : [ CLASS_DEFINE_CHUNK_NAME . ConstructorStart ] ,
66- } ) ;
63+ if ( cfg . preferClassProperty ) {
64+ // mode: class property
65+ next . chunks . push ( {
66+ type : ChunkType . STRING ,
67+ fileType : cfg . fileType ,
68+ name : CLASS_DEFINE_CHUNK_NAME . InsVar ,
69+ content : 'utils = utils;' ,
70+ linkAfter : [ ...DEFAULT_LINK_AFTER [ CLASS_DEFINE_CHUNK_NAME . InsVar ] ] ,
71+ } ) ;
72+ } else {
73+ // mode: assign in constructor
74+ next . chunks . push ( {
75+ type : ChunkType . STRING ,
76+ fileType : cfg . fileType ,
77+ name : CLASS_DEFINE_CHUNK_NAME . ConstructorContent ,
78+ content : 'this.utils = utils;' ,
79+ linkAfter : [ CLASS_DEFINE_CHUNK_NAME . ConstructorStart ] ,
80+ } ) ;
81+ }
6782
6883 if ( useRef ) {
6984 next . chunks . push ( {
0 commit comments