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

Support ECMAScript imports in examples #1074

Closed
sapegin opened this issue Aug 7, 2018 · 0 comments
Closed

Support ECMAScript imports in examples #1074

sapegin opened this issue Aug 7, 2018 · 0 comments
Assignees

Comments

@sapegin
Copy link
Member

sapegin commented Aug 7, 2018

It shouldn't be hard to support the most common import variations in the examples:

import Pizza from 'pizza';
import { Pizza as Falafel, Coffee } from 'lunch';
import Lunch, { Pizza as Falafel, Coffee } from 'lunch';

There are two places where we need to add this:

  1. In styleguide-loader:

const requiresFromExamples = getRequires(codeFromAllExamples);

We may want to use something like detect-import-require instead of a custom RegExp.

  1. On the frontend:

compileCode(code) {
try {
const wrappedCode = code.trim().match(/^</) ? wrapCodeInFragment(code) : code;
return compileCode(wrappedCode, this.props.compilerConfig);
} catch (err) {
if (this.props.onError) {
this.props.onError(err);
}
}
return false;
}

rewrite-imports may be a good start, but it doesn't support multiline statements.

@sapegin sapegin added this to the 8.0.0: New editor milestone Aug 7, 2018
@sapegin sapegin self-assigned this Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant