forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 facebook#9890 Differential Revision: D3865629 Pulled By: bestander fbshipit-source-id: 8f561b78ca4a02f3f7b45e55904ec2fa911e3bb6
- Loading branch information
Showing
13 changed files
with
199 additions
and
30 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
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,39 @@ | ||
/** | ||
* Copyright (c) 2016-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const jsDocs = require('../jsdocs'); | ||
const libs = __dirname + '/../../../Libraries/'; | ||
|
||
function checkWeCanParse(library) { | ||
let path = libs + library; | ||
let code = fs.readFileSync(path).toString(); | ||
let json = jsDocs(code); | ||
expect(json).toBeTruthy(); | ||
} | ||
|
||
describe('parseSource', () => { | ||
it('should parse Vibration.js', () => { | ||
checkWeCanParse('Vibration/Vibration.js'); | ||
}); | ||
|
||
it('should parse AsyncStorage.js', () => { | ||
checkWeCanParse('Storage/AsyncStorage.js'); | ||
}); | ||
|
||
it('should not parse invalid code', () => { | ||
let code = ` | ||
for x in range(10): | ||
print 'oops this isnt python' | ||
`; | ||
expect(jsDocs('fakepath', code)).toBeFalsy(); | ||
}); | ||
}); |
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
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
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,121 @@ | ||
/** | ||
* Copyright (c) 2016-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
// This Syntax object defines a number of constants that flow-parser uses. | ||
|
||
module.exports = { | ||
AnyTypeAnnotation: 'AnyTypeAnnotation', | ||
ArrayExpression: 'ArrayExpression', | ||
ArrayPattern: 'ArrayPattern', | ||
ArrayTypeAnnotation: 'ArrayTypeAnnotation', | ||
ArrowFunctionExpression: 'ArrowFunctionExpression', | ||
AssignmentExpression: 'AssignmentExpression', | ||
BinaryExpression: 'BinaryExpression', | ||
BlockStatement: 'BlockStatement', | ||
BooleanTypeAnnotation: 'BooleanTypeAnnotation', | ||
BreakStatement: 'BreakStatement', | ||
CallExpression: 'CallExpression', | ||
CatchClause: 'CatchClause', | ||
ClassBody: 'ClassBody', | ||
ClassDeclaration: 'ClassDeclaration', | ||
ClassExpression: 'ClassExpression', | ||
ClassImplements: 'ClassImplements', | ||
ClassProperty: 'ClassProperty', | ||
ComprehensionBlock: 'ComprehensionBlock', | ||
ComprehensionExpression: 'ComprehensionExpression', | ||
ConditionalExpression: 'ConditionalExpression', | ||
ContinueStatement: 'ContinueStatement', | ||
DebuggerStatement: 'DebuggerStatement', | ||
DeclareClass: 'DeclareClass', | ||
DeclareFunction: 'DeclareFunction', | ||
DeclareModule: 'DeclareModule', | ||
DeclareVariable: 'DeclareVariable', | ||
DoWhileStatement: 'DoWhileStatement', | ||
EmptyStatement: 'EmptyStatement', | ||
ExportDeclaration: 'ExportDeclaration', | ||
ExportBatchSpecifier: 'ExportBatchSpecifier', | ||
ExportSpecifier: 'ExportSpecifier', | ||
ExpressionStatement: 'ExpressionStatement', | ||
ForInStatement: 'ForInStatement', | ||
ForOfStatement: 'ForOfStatement', | ||
ForStatement: 'ForStatement', | ||
FunctionDeclaration: 'FunctionDeclaration', | ||
FunctionExpression: 'FunctionExpression', | ||
FunctionTypeAnnotation: 'FunctionTypeAnnotation', | ||
FunctionTypeParam: 'FunctionTypeParam', | ||
GenericTypeAnnotation: 'GenericTypeAnnotation', | ||
Identifier: 'Identifier', | ||
IfStatement: 'IfStatement', | ||
ImportDeclaration: 'ImportDeclaration', | ||
ImportDefaultSpecifier: 'ImportDefaultSpecifier', | ||
ImportNamespaceSpecifier: 'ImportNamespaceSpecifier', | ||
ImportSpecifier: 'ImportSpecifier', | ||
InterfaceDeclaration: 'InterfaceDeclaration', | ||
InterfaceExtends: 'InterfaceExtends', | ||
IntersectionTypeAnnotation: 'IntersectionTypeAnnotation', | ||
LabeledStatement: 'LabeledStatement', | ||
Literal: 'Literal', | ||
LogicalExpression: 'LogicalExpression', | ||
MemberExpression: 'MemberExpression', | ||
MethodDefinition: 'MethodDefinition', | ||
NewExpression: 'NewExpression', | ||
NullableTypeAnnotation: 'NullableTypeAnnotation', | ||
NumberTypeAnnotation: 'NumberTypeAnnotation', | ||
ObjectExpression: 'ObjectExpression', | ||
ObjectPattern: 'ObjectPattern', | ||
ObjectTypeAnnotation: 'ObjectTypeAnnotation', | ||
ObjectTypeCallProperty: 'ObjectTypeCallProperty', | ||
ObjectTypeIndexer: 'ObjectTypeIndexer', | ||
ObjectTypeProperty: 'ObjectTypeProperty', | ||
Program: 'Program', | ||
Property: 'Property', | ||
QualifiedTypeIdentifier: 'QualifiedTypeIdentifier', | ||
ReturnStatement: 'ReturnStatement', | ||
SequenceExpression: 'SequenceExpression', | ||
SpreadElement: 'SpreadElement', | ||
SpreadProperty: 'SpreadProperty', | ||
StringLiteralTypeAnnotation: 'StringLiteralTypeAnnotation', | ||
StringTypeAnnotation: 'StringTypeAnnotation', | ||
SwitchCase: 'SwitchCase', | ||
SwitchStatement: 'SwitchStatement', | ||
TaggedTemplateExpression: 'TaggedTemplateExpression', | ||
TemplateElement: 'TemplateElement', | ||
TemplateLiteral: 'TemplateLiteral', | ||
ThisExpression: 'ThisExpression', | ||
ThrowStatement: 'ThrowStatement', | ||
TupleTypeAnnotation: 'TupleTypeAnnotation', | ||
TryStatement: 'TryStatement', | ||
TypeAlias: 'TypeAlias', | ||
TypeAnnotation: 'TypeAnnotation', | ||
TypeCastExpression: 'TypeCastExpression', | ||
TypeofTypeAnnotation: 'TypeofTypeAnnotation', | ||
TypeParameterDeclaration: 'TypeParameterDeclaration', | ||
TypeParameterInstantiation: 'TypeParameterInstantiation', | ||
UnaryExpression: 'UnaryExpression', | ||
UnionTypeAnnotation: 'UnionTypeAnnotation', | ||
UpdateExpression: 'UpdateExpression', | ||
VariableDeclaration: 'VariableDeclaration', | ||
VariableDeclarator: 'VariableDeclarator', | ||
VoidTypeAnnotation: 'VoidTypeAnnotation', | ||
WhileStatement: 'WhileStatement', | ||
WithStatement: 'WithStatement', | ||
JSXIdentifier: 'JSXIdentifier', | ||
JSXNamespacedName: 'JSXNamespacedName', | ||
JSXMemberExpression: 'JSXMemberExpression', | ||
JSXEmptyExpression: 'JSXEmptyExpression', | ||
JSXExpressionContainer: 'JSXExpressionContainer', | ||
JSXElement: 'JSXElement', | ||
JSXClosingElement: 'JSXClosingElement', | ||
JSXOpeningElement: 'JSXOpeningElement', | ||
JSXAttribute: 'JSXAttribute', | ||
JSXSpreadAttribute: 'JSXSpreadAttribute', | ||
JSXText: 'JSXText', | ||
YieldExpression: 'YieldExpression', | ||
AwaitExpression: 'AwaitExpression' | ||
} |
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
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 |
---|---|---|
@@ -1,29 +1,33 @@ | ||
{ | ||
"scripts": { | ||
"start": "RN_VERSION=next node server/server.js", | ||
"test": "jest", | ||
"gh-pages": "node publish-gh-pages.js" | ||
}, | ||
"dependencies": { | ||
"babel-core": "^6.6.4", | ||
"babel-plugin-external-helpers": "^6.5.0", | ||
"babel-polyfill": "^6.6.1", | ||
"babel-preset-react-native": "~1.6.0", | ||
"babel-register": "^6.6.0", | ||
"babel-types": "^6.6.4", | ||
"bluebird": "^2.9.21", | ||
"connect": "2.8.3", | ||
"esprima-fb": "15001.1001.0-dev-harmony-fb", | ||
"deep-assign": "^2.0.0", | ||
"flow-parser": "^0.32.0", | ||
"fs.extra": "1.3.2", | ||
"glob": "6.0.4", | ||
"jsdoc-api": "^1.1.0", | ||
"jstransform": "11.0.3", | ||
"mkdirp": "^0.5.1", | ||
"optimist": "0.6.0", | ||
"react": "~0.13.0", | ||
"react-docgen": "^2.9.0", | ||
"react-page-middleware": "git://github.com/facebook/react-page-middleware.git", | ||
"request": "^2.69.0", | ||
"semver-compare": "^1.0.0", | ||
"babel-core": "^6.6.4", | ||
"babel-plugin-external-helpers": "^6.5.0", | ||
"babel-polyfill": "^6.6.1", | ||
"babel-preset-react-native": "~1.6.0", | ||
"babel-register": "^6.6.0", | ||
"babel-types": "^6.6.4", | ||
"jsdoc-api": "^1.1.0", | ||
"deep-assign": "^2.0.0" | ||
"semver-compare": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"jest": "^15.1.1" | ||
} | ||
} |
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