diff --git a/packages/babel-plugin-apply-mdx-type-props/index.js b/packages/babel-plugin-apply-mdx-type-props/index.js deleted file mode 100644 index 9a3c256ba..000000000 --- a/packages/babel-plugin-apply-mdx-type-props/index.js +++ /dev/null @@ -1,57 +0,0 @@ -const {declare} = require('@babel/helper-plugin-utils') - -const startsWithCapitalLetter = str => /^[A-Z]/.test(str) - -class BabelPluginApplyMdxTypeProp { - constructor() { - const names = [] - this.state = {names} - - this.plugin = declare(api => { - api.assertVersion(7) - const {types: t} = api - - return { - visitor: { - JSXOpeningElement(path) { - const jsxName = path.node.name.name - - let parentPath = path.parentPath.parentPath - let parentName - - while (parentPath) { - if (parentPath.node.type === 'JSXElement') { - parentName = parentPath.node.openingElement.name.name - break - } - - parentPath = parentPath.parentPath - } - - if (typeof parentName === 'string' && parentName !== 'MDXLayout') { - path.node.attributes.push( - t.jSXAttribute( - t.jSXIdentifier(`parentName`), - t.stringLiteral(parentName) - ) - ) - } - - if (startsWithCapitalLetter(jsxName)) { - names.push(jsxName) - - path.node.attributes.push( - t.jSXAttribute( - t.jSXIdentifier(`mdxType`), - t.stringLiteral(jsxName) - ) - ) - } - } - } - } - }) - } -} - -module.exports = BabelPluginApplyMdxTypeProp diff --git a/packages/babel-plugin-apply-mdx-type-props/package.json b/packages/babel-plugin-apply-mdx-type-props/package.json index 660a132ed..8bf7c2f44 100644 --- a/packages/babel-plugin-apply-mdx-type-props/package.json +++ b/packages/babel-plugin-apply-mdx-type-props/package.json @@ -1,37 +1,4 @@ { - "name": "babel-plugin-apply-mdx-type-prop", - "version": "2.0.0-next.8", - "description": "Apply the MDX type prop used in the MDX pragma", - "repository": "mdx-js/mdx", - "homepage": "https://mdxjs.com", - "bugs": "https://github.com/mdx-js/mdx/issues", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/unified" - }, - "author": "John Otander (http://johnotander.com)", - "contributors": [ - "JounQin (https://www.1stg.me)" - ], - "license": "MIT", - "files": [ - "index.js" - ], - "keywords": [ - "mdx", - "markdown", - "react", - "jsx", - "remark", - "babel" - ], - "dependencies": { - "@babel/helper-plugin-utils": "^7.10.4" - }, - "scripts": { - "test-api": "jest test", - "test-coverage": "jest test --coverage", - "test": "yarn test-coverage" - }, - "gitHead": "bf7deab69996449cb99c2217dff75e65855eb2c1" + "private": true, + "name": "babel-plugin-apply-mdx-type-prop" } diff --git a/packages/babel-plugin-apply-mdx-type-props/readme.md b/packages/babel-plugin-apply-mdx-type-props/readme.md index a60e7dbb1..b0c3651a6 100644 --- a/packages/babel-plugin-apply-mdx-type-props/readme.md +++ b/packages/babel-plugin-apply-mdx-type-props/readme.md @@ -1,117 +1,8 @@ # babel-plugin-apply-mdx-type-prop -[![Build][build-badge]][build] -[![Downloads][downloads-badge]][downloads] -[![Sponsors][sponsors-badge]][opencollective] -[![Backers][backers-badge]][opencollective] -[![Chat][chat-badge]][chat] +Deprecated! -Create a Babel plugin to both add `mdxType` props to components and extract all -those found named. -Used by [MDX][]. +Created for but no longer used in [MDX](https://mdxjs.com). -## Install - -[npm][]: - -```sh -npm install babel-plugin-apply-mdx-type-prop -``` - -[yarn][]: - -```sh -yarn add babel-plugin-apply-mdx-type-prop -``` - -## Use - -Say we have the following code in `input.jsx`: - -```jsx -export const Foo = () => ( -
-
-) - -export default () => ( - <> -

Hello!

- - -) -``` - -And our script, `example.js`: - -```js -const fs = require('fs') -const babel = require('@babel/core') -const BabelPluginApplyMdxTypeProp = require('babel-plugin-apply-mdx-type-prop') - -// Construct one for every file you’re processing. -const applyMdxTypeProp = new BabelPluginApplyMdxTypeProp() - -const result = babel.transformSync(fs.readFileSync('./input.jsx'), { - configFile: false, - plugins: ['@babel/plugin-syntax-jsx', applyMdxTypeProp.plugin] -}) - -console.log(result.code) -console.log(applyMdxTypeProp.state.names) -``` - -Now, running `node example` yields: - -```jsx -export const Foo = () => ( -
-
-) - -export default () => ( - <> -

Hello!

- - -) -``` - -```js -['Button', 'TomatoBox'] -``` - -## API - -### `BabelPluginApplyMdxTypeProp()` - -Constructor for an instance to transform and capture MDX types. - -Note that this isn’t a Babel plugin but _creates_ one. - -###### Returns - -Instance with: - -* `plugin` — Plugin for Babel -* `state` — Object with a `names` field listing all (including duplicates) - found types - -## License - -MIT - -[build-badge]: https://github.com/mdx-js/mdx/workflows/CI/badge.svg -[build]: https://github.com/mdx-js/mdx/actions -[downloads-badge]: https://img.shields.io/npm/dm/babel-plugin-apply-mdx-type-prop.svg -[downloads]: https://www.npmjs.com/package/babel-plugin-apply-mdx-type-prop -[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg -[backers-badge]: https://opencollective.com/unified/backers/badge.svg -[opencollective]: https://opencollective.com/unified -[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg -[chat]: https://github.com/mdx-js/mdx/discussions -[mdx]: https://mdxjs.com -[npm]: https://docs.npmjs.com/cli/install -[yarn]: https://yarnpkg.com/cli/add +This used to add `mdxType`, `parentName` props to JSX elements, +and track which components were used. diff --git a/packages/babel-plugin-apply-mdx-type-props/test/index.test.js b/packages/babel-plugin-apply-mdx-type-props/test/index.test.js deleted file mode 100644 index 9c6202b6b..000000000 --- a/packages/babel-plugin-apply-mdx-type-props/test/index.test.js +++ /dev/null @@ -1,56 +0,0 @@ -const babel = require('@babel/core') - -const BabelPluginApplyMdxTypeProp = require('..') - -const transform = value => { - const plugin = new BabelPluginApplyMdxTypeProp() - - const result = babel.transformSync(value, { - configFile: false, - plugins: [require('@babel/plugin-syntax-jsx'), plugin.plugin] - }) - - return { - ...result, - state: plugin.state - } -} - -describe('babel-plugin-add-mdx-type-prop', () => { - test('should add `mdxType` to components', () => { - expect(transform('var d =
').code).toEqual( - 'var d =
;' - ) - }) - - test('should support (as in, ignore) fragments', () => { - expect(transform('var d = <>