@@ -27,20 +27,18 @@ export default declare(({
2727 SVG_DEFAULT_PROPS_CODE ,
2828 } ) => {
2929 const namedTemplate = `
30- var SVG_NAME = function SVG_NAME(props) { React.PureComponent.call(this, props); };
31- SVG_NAME.prototype = Object.create(React.PureComponent.prototype);
32- SVG_NAME.prototype.constructor = SVG_NAME;
33- SVG_NAME.prototype.render = function render() { var props = this.props; return SVG_CODE; };
34- ${ SVG_DEFAULT_PROPS_CODE ? 'SVG_NAME.defaultProps = SVG_DEFAULT_PROPS_CODE;' : '' }
30+ var SVG_NAME = createReactClass({
31+ render: function() { var props = this.props; return SVG_CODE; },
32+ ${ SVG_DEFAULT_PROPS_CODE ? 'getDefaultProps: function() { return SVG_DEFAULT_PROPS_CODE; }' : '' }
33+ });
3534 ${ IS_EXPORT ? 'export { SVG_NAME };' : '' }
3635 ` ;
3736 const anonymousTemplate = `
38- var Component = function (props) { React.PureComponent.call(this, props); };
39- Component.prototype = Object.create(React.PureComponent.prototype);
40- Component.prototype.constructor = Component;
41- Component.prototype.render = function render() { var props = this.props; return SVG_CODE; };
42- ${ SVG_DEFAULT_PROPS_CODE ? 'Component.defaultProps = SVG_DEFAULT_PROPS_CODE;' : '' }
43- Component.displayName = 'EXPORT_FILENAME';
37+ var Component = createReactClass({
38+ displayName: EXPORT_FILENAME,
39+ render: function() { var props = this.props; return SVG_CODE; },
40+ ${ SVG_DEFAULT_PROPS_CODE ? 'getDefaultProps: function() { return SVG_DEFAULT_PROPS_CODE; }' : '' }
41+ });
4442 export default Component;
4543 ` ;
4644
@@ -130,6 +128,8 @@ export default declare(({
130128
131129 file . get ( 'ensureReact' ) ( ) ;
132130 file . set ( 'ensureReact' , ( ) => { } ) ;
131+ file . get ( 'ensureCreateReactClass' ) ( ) ;
132+ file . set ( 'ensureCreateReactClass' , ( ) => { } ) ;
133133 }
134134 return newPath ;
135135 }
@@ -144,6 +144,20 @@ export default declare(({
144144 if ( typeof filename === 'undefined' && typeof opts . filename !== 'string' ) {
145145 throw new TypeError ( 'the "filename" option is required when transforming code' ) ;
146146 }
147+
148+ if ( ! path . scope . hasBinding ( 'create-react-class' ) ) {
149+ const assignDeclaration = t . importDeclaration ( [
150+ t . importDefaultSpecifier ( t . identifier ( 'createReactClass' ) ) ,
151+ ] , t . stringLiteral ( 'create-react-class' ) ) ;
152+
153+ file . set ( 'ensureCreateReactClass' , ( ) => {
154+ const [ newPath ] = path . unshiftContainer ( 'body' , assignDeclaration ) ;
155+ newPath . get ( 'specifiers' ) . forEach ( ( specifier ) => { path . scope . registerBinding ( 'module' , specifier ) ; } ) ;
156+ } ) ;
157+ } else {
158+ file . set ( 'ensureCreateReactClass' , ( ) => { } ) ;
159+ }
160+
147161 if ( ! path . scope . hasBinding ( 'React' ) ) {
148162 const reactImportDeclaration = t . importDeclaration ( [
149163 t . importDefaultSpecifier ( t . identifier ( 'React' ) ) ,
0 commit comments