Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix named export for example components #1380

Merged
merged 5 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/loaders/__tests__/examples-loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);`
);
});

Expand All @@ -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);`
);
});

Expand All @@ -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);`
);
});

Expand All @@ -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');
});
7 changes: 5 additions & 2 deletions src/loaders/examples-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ export default function examplesLoader(source) {
b.variableDeclaration('const', [
b.variableDeclarator(
b.identifier(name),
b.logicalExpression('||', b.identifier(`${name}$0.default`), b.identifier(`${name}$0`))
),
b.logicalExpression('||',
sapegin marked this conversation as resolved.
Show resolved Hide resolved
b.identifier(`${name}$0['${name}']`),
b.logicalExpression('||', b.identifier(`${name}$0.default`), b.identifier(`${name}$0`)),
),
)
]),
])
)
Expand Down