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

Replace espree with babel. #21853

Merged
merged 7 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 4 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/docgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ This command will generate a file named `entry-point-api.md` containing all the
* **--use-token** `(String)`: This options allows you to customize the string between the tokens. For example, `--use-token my-api` will look up for the start token <code>&lt;!-- START TOKEN(my-api) --&gt;</code> and the end token <code>&lt;!-- END TOKEN(my-api) --&gt;</code>. Depends on `--to-token`.
* **--debug**: Run in debug mode, which outputs some intermediate files useful for debugging.

### Babel Configuration

`@wordpress/docgen` follows the default [project-wide configuration of Babel](https://babeljs.io/docs/en/next/config-files#project-wide-configuration). Like Babel, it will automatically search for a `babel.config.json` file, or an equivalent one using the [supported extensions](https://babeljs.io/docs/en/next/config-files#supported-file-extensions), in the project root directory.

Without it, `@wordpress/docgen` runs with the default option. In other words, it cannot parse JSX or other advanced syntaxes.

## Examples

### Default export
Expand Down
2 changes: 1 addition & 1 deletion packages/docgen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"docgen": "./bin/cli.js"
},
"dependencies": {
"@babel/core": "^7.9.0",
"doctrine": "^2.1.0",
"espree": "^4.0.0",
"lodash": "^4.17.15",
"mdast-util-inject": "1.1.0",
"optionator": "0.8.2",
Expand Down
15 changes: 4 additions & 11 deletions packages/docgen/src/engine.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
/**
* External dependencies.
*/
const espree = require( 'espree' );
const babel = require( '@babel/core' );
const { flatten } = require( 'lodash' );

/**
* Internal dependencies.
*/
const getIntermediateRepresentation = require( './get-intermediate-representation' );

const getAST = ( source ) =>
espree.parse( source, {
attachComment: true,
loc: true,
ecmaVersion: 2018,
ecmaFeatures: {
jsx: true,
},
sourceType: 'module',
} );
const getAST = ( source ) => {
return babel.parse( source || '' ).program;
};

const getExportTokens = ( ast ) =>
ast.body.filter( ( node ) =>
Expand Down