diff --git a/examples/basic/src/components/RandomButton/RandomButton.js b/examples/basic/src/components/RandomButton/RandomButton.js index 7abe4c193..65f7afbca 100644 --- a/examples/basic/src/components/RandomButton/RandomButton.js +++ b/examples/basic/src/components/RandomButton/RandomButton.js @@ -7,7 +7,8 @@ import './RandomButton.css'; /** * Button that changes label on every click. */ -export default class RandomButton extends Component { +// eslint-disable-next-line import/prefer-default-export +export class RandomButton extends Component { static propTypes = { /** * List of possible labels. diff --git a/examples/basic/src/components/RandomButton/Readme.md b/examples/basic/src/components/RandomButton/Readme.md index 53b99eb2d..f5502f381 100644 --- a/examples/basic/src/components/RandomButton/Readme.md +++ b/examples/basic/src/components/RandomButton/Readme.md @@ -2,5 +2,6 @@ You can `import` external files in your examples: ```jsx import { all } from 'dog-names' +import { RandomButton } from '../RandomButton' ; ``` diff --git a/examples/basic/src/components/RandomButton/index.js b/examples/basic/src/components/RandomButton/index.js index 081fd2ff2..7be7e3f6b 100644 --- a/examples/basic/src/components/RandomButton/index.js +++ b/examples/basic/src/components/RandomButton/index.js @@ -1 +1,2 @@ -export { default } from './RandomButton'; +// eslint-disable-next-line import/prefer-default-export +export { RandomButton } from './RandomButton'; diff --git a/src/loaders/__tests__/examples-loader.spec.js b/src/loaders/__tests__/examples-loader.spec.js index b98324d11..98c750fee 100644 --- a/src/loaders/__tests__/examples-loader.spec.js +++ b/src/loaders/__tests__/examples-loader.spec.js @@ -181,7 +181,7 @@ it('should prepend example code with React require()', () => { expect(result).toBeTruthy(); expect(() => new Function(result)).not.toThrowError(SyntaxError); expect(result).toMatch( - `const React$0 = require('react');\\nconst React = React$0.default || React$0;` + `const React$0 = require('react');\\nconst React = React$0['React'] || (React$0.default || React$0);` ); }); @@ -198,7 +198,7 @@ it('should prepend example code with component require()', () => { expect(result).toBeTruthy(); expect(() => new Function(result)).not.toThrowError(SyntaxError); expect(result).toMatch( - `const FooComponent$0 = require('../foo.js');\\nconst FooComponent = FooComponent$0.default || FooComponent$0;` + `const FooComponent$0 = require('../foo.js');\\nconst FooComponent = FooComponent$0['FooComponent'] || (FooComponent$0.default || FooComponent$0);` ); }); @@ -218,10 +218,10 @@ it('should allow explicit import of React and component module', () => { expect(result).toBeTruthy(); expect(() => new Function(result)).not.toThrowError(SyntaxError); expect(result).toMatch( - `const React$0 = require('react');\\nconst React = React$0.default || React$0;` + `const React$0 = require('react');\\nconst React = React$0['React'] || (React$0.default || React$0);` ); expect(result).toMatch( - `const FooComponent$0 = require('../foo.js');\\nconst FooComponent = FooComponent$0.default || FooComponent$0;` + `const FooComponent$0 = require('../foo.js');\\nconst FooComponent = FooComponent$0['FooComponent'] || (FooComponent$0.default || FooComponent$0);` ); }); @@ -241,7 +241,7 @@ it('should works for any Markdown file, without a current component', () => { expect(result).toBeTruthy(); expect(() => new Function(result)).not.toThrowError(SyntaxError); expect(result).toMatch( - `const React$0 = require('react');\\nconst React = React$0.default || React$0;` + `const React$0 = require('react');\\nconst React = React$0['React'] || (React$0.default || React$0);` ); expect(result).not.toMatch('undefined'); }); diff --git a/src/loaders/examples-loader.js b/src/loaders/examples-loader.js index 54331c1d5..36a1936ed 100644 --- a/src/loaders/examples-loader.js +++ b/src/loaders/examples-loader.js @@ -78,11 +78,19 @@ export default function examplesLoader(source) { b.variableDeclaration('const', [ b.variableDeclarator(b.identifier(`${name}$0`), requireIt(requireRequest).toAST()), ]), - // const name = name$0.default || name$0; + // const name = name$0[name] || name$0.default || name$0; b.variableDeclaration('const', [ b.variableDeclarator( b.identifier(name), - b.logicalExpression('||', b.identifier(`${name}$0.default`), b.identifier(`${name}$0`)) + b.logicalExpression( + '||', + b.identifier(`${name}$0['${name}']`), + b.logicalExpression( + '||', + b.identifier(`${name}$0.default`), + b.identifier(`${name}$0`) + ) + ) ), ]), ])