Replace the deprecated esprima-fb parser with flow-parser, on the RN website

Summary:
(I changed a ton from when I previously submitted this PR so please take another look if you already did.)

PROBLEM: the no-longer-maintained `esprima-fb` parser does not support class properties, leading our website docgen to die if we use class properties, which we're gonna do real soon now
SOLUTION: use `flow-parser` instead, which the flow team is maintaining including all the fancy-pants ES? stuff that FB uses internally.

This removes the `esprima-fb` parser from jsdocs and replaces it with `flow-parser`. It's almost the same, I checked by diffing all the parser json output and it only had a few irrelevant differences. I had to add a file of constants so that we could remove esprima-fb altogether, too.

This also adds a couple unit tests, so that we can test that jsDocs works programmatically. They don't run if you run the regular RN tests, you have to run `npm test` from the `/website/` subdirectory.
Closes https://github.com/facebook/react-native/pull/9890

Differential Revision: D3865629

Pulled By: bestander

fbshipit-source-id: 8f561b78ca4a02f3f7b45e55904ec2fa911e3bb6
This commit is contained in:
Kevin Lacker
2016-09-14 14:16:35 -07:00
committed by Facebook Github Bot 5
parent 3182b608fc
commit 857bae4ea3
13 changed files with 199 additions and 30 deletions

View File

@@ -10,9 +10,9 @@
/*jslint node: true */
'use strict';
var esprima = require('esprima-fb');
var flowParser = require('flow-parser');
var fs = require('fs');
var Syntax = esprima.Syntax;
var Syntax = require('./syntax');
var findExportDefinition = require('./findExportDefinition');
var genericTransform = require('./generic-function-visitor');
@@ -76,7 +76,7 @@ function stripStaticUpstreamWarning(docblock) {
if (!docblock) {
return docblock;
}
// Esprima strips out the starting and ending tokens, so add them back
// The parser strips out the starting and ending tokens, so add them back
docblock = '/*' + docblock + '*/\n';
return docblock;
}
@@ -196,8 +196,8 @@ function getModuleName(commentsForFile) {
}
/**
* Esprima includes the leading colon (and possibly spaces) as part of the
* typehint, so we have to strip those out.
* The parser includes the leading colon (and possibly spaces) as part of
* the typehint, so we have to strip those out.
*/
function sanitizeTypehint(string) {
for (var i = 0; i < string.length; i++) {
@@ -229,7 +229,7 @@ function getFunctionData(
var typechecks = commentsForFile.typechecks;
var typehintsFromBlock = null;
if (typechecks) {
// esprima has trouble with some params so ignore them (e.g. $__0)
// The parser has trouble with some params so ignore them (e.g. $__0)
if (!node.params.some(function(param) { return !param.name; })) {
try {
typehintsFromBlock = genericTransform.getTypeHintsFromDocBlock(
@@ -497,7 +497,7 @@ function getRequireData(node) {
*/
function parseSource(source) {
var lines = source.split('\n');
var ast = esprima.parse(source, {
var ast = flowParser.parse(source, {
loc: true,
comment: true,
range: true,