Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #106 from rafeca/add-reactpurecomponent
Browse files Browse the repository at this point in the history
Add React.PureComponent to the list of default super classes
  • Loading branch information
gaearon authored Sep 12, 2017
2 parents df23cf0 + 4e321a5 commit ccd6dc1
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export default function({ types: t, template }) {
normalizeOptions(options) {
return {
factoryMethods: options.factoryMethods || ['React.createClass'],
superClasses: options.superClasses || ['React.Component', 'Component'],
superClasses: options.superClasses || ['React.Component', 'React.PureComponent', 'Component', 'PureComponent'],
transforms: options.transforms.map(opts => {
return {
transform: opts.transform,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"plugins": [
["../../../src", {
"transforms": [{
"transform": "transform-lib"
}]
}]
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import React, { PureComponent } from 'react';
class Foo extends PureComponent {
render() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import _transformLib from 'transform-lib';
const _components = {
Foo: {
displayName: 'Foo'
}
};

const _transformLib2 = _transformLib({
filename: '%FIXTURE_PATH%',
components: _components,
locals: [],
imports: []
});

function _wrapComponent(id) {
return function (Component) {
return _transformLib2(Component, id);
};
}

import React, { PureComponent } from 'react';

const Foo = _wrapComponent('Foo')(class Foo extends PureComponent {
render() {}
});
6 changes: 2 additions & 4 deletions test/fixtures/code-exports/actual.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export default class Foo extends React.Component {}
export default class extends React.Component {}
export class Foo extends React.Component {}
export default React.createClass({});
export class Bar extends React.Component {}
export const bar = React.createClass({});
export default class Baz { render() {} }
export default class { render() {} }
export class Baz { render() {} }
export class Boo { render() {} }
8 changes: 2 additions & 6 deletions test/fixtures/code-exports/expected.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
export default class Foo extends React.Component {}
export default class extends React.Component {}
export class Foo extends React.Component {}
export default React.createClass({});
export class Bar extends React.Component {}
export const bar = React.createClass({});
export default class Baz {
render() {}
}
export default class {
export class Baz {
render() {}
}
export class Boo {
Expand Down

0 comments on commit ccd6dc1

Please sign in to comment.