mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-29 04:35:36 +08:00
Update react-docgen and ignore pages with no header
This commit is contained in:
36
website/react-docgen/lib/utils/__tests__/isExportsOrModuleAssignment-test.js
vendored
Normal file
36
website/react-docgen/lib/utils/__tests__/isExportsOrModuleAssignment-test.js
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
"use strict";
|
||||
|
||||
jest.autoMockOff();
|
||||
|
||||
describe('isExportsOrModuleAssignment', function() {
|
||||
var recast;
|
||||
var isExportsOrModuleAssignment;
|
||||
|
||||
function parse(src) {
|
||||
return new recast.types.NodePath(
|
||||
recast.parse(src).program.body[0]
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
isExportsOrModuleAssignment = require('../isExportsOrModuleAssignment');
|
||||
recast = require('recast');
|
||||
});
|
||||
|
||||
it('detects "module.exports = ...;"', function() {
|
||||
expect(isExportsOrModuleAssignment(parse('module.exports = foo;')))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it('detects "exports.foo = ..."', function() {
|
||||
expect(isExportsOrModuleAssignment(parse('exports.foo = foo;')))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it('does not accept "exports = foo;"', function() {
|
||||
// That doesn't actually export anything
|
||||
expect(isExportsOrModuleAssignment(parse('exports = foo;')))
|
||||
.toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
37
website/react-docgen/lib/utils/isExportsOrModuleAssignment.js
vendored
Normal file
37
website/react-docgen/lib/utils/isExportsOrModuleAssignment.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @flow
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
var expressionTo = require('./expressionTo');
|
||||
var types = require('recast').types.namedTypes;
|
||||
|
||||
/**
|
||||
* Returns true if the expression is of form `exports.foo = ...;` or
|
||||
* `modules.exports = ...;`.
|
||||
*/
|
||||
function isExportsOrModuleAssignment(path: NodePath): boolean {
|
||||
if (types.ExpressionStatement.check(path.node)) {
|
||||
path = path.get('expression');
|
||||
}
|
||||
if (!types.AssignmentExpression.check(path.node) ||
|
||||
!types.MemberExpression.check(path.node.left)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var exprArr = expressionTo.Array(path.get('left'));
|
||||
return (exprArr[0] === 'module' && exprArr[1] === 'exports') ||
|
||||
exprArr[0] == 'exports';
|
||||
}
|
||||
|
||||
module.exports = isExportsOrModuleAssignment;
|
||||
37
website/react-docgen/lib/utils/isReactCreateClassCall.js
vendored
Normal file
37
website/react-docgen/lib/utils/isReactCreateClassCall.js
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @flow
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
var isReactModuleName = require('./isReactModuleName');
|
||||
var match = require('./match');
|
||||
var resolveToModule = require('./resolveToModule');
|
||||
var types = require('recast').types.namedTypes;
|
||||
|
||||
/**
|
||||
* Returns true if the expression is a function call of the form
|
||||
* `React.createClass(...)`.
|
||||
*/
|
||||
function isReactCreateClassCall(path: NodePath): boolean {
|
||||
if (types.ExpressionStatement.check(path.node)) {
|
||||
path = path.get('expression');
|
||||
}
|
||||
|
||||
if (!match(path.node, {callee: {property: {name: 'createClass'}}})) {
|
||||
return false;
|
||||
}
|
||||
var module = resolveToModule(path.get('callee', 'object'));
|
||||
return module && isReactModuleName(module);
|
||||
}
|
||||
|
||||
module.exports = isReactCreateClassCall;
|
||||
Reference in New Issue
Block a user