-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add minimal support for the components prop
This defines the `_components` variable in `_createMdxContent`. This variable contains all components injected through the `components` prop, a reference to `props`, and all local variables. All MDX JSX tags are prefixed with `_components.` in the virtual code. As a result, components declared in the `components` prop are allowed. Components from both the `components` prop and local variables are displayed in the autocomplete. A downside of this approach is that documentation is lost for local components. To mitigate this, only unknown JSX tags are prefixed. Only MDX JSX tags are handled yet. JSX from estree not yet. Refs #260
- Loading branch information
1 parent
dca9433
commit 5c860df
Showing
5 changed files
with
460 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Check if a name belongs to a JSX component that can be injected. | ||
* | ||
* These are components whose name start with an upper case character. They may | ||
* also not be defined in the scope. | ||
* | ||
* @param {string | null} name | ||
* The name of the component to check. | ||
* @param {string[]} scope | ||
* The variable names available in the scope. | ||
* @returns {boolean} | ||
* Whether or not the given name is that of an injectable JSX component. | ||
*/ | ||
export function isInjectableComponent(name, scope) { | ||
if (!name) { | ||
return false | ||
} | ||
|
||
const char = name.charAt(0) | ||
if (char !== char.toUpperCase()) { | ||
return false | ||
} | ||
|
||
return !scope.includes(name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.