Skip to content

Commit 4cdb852

Browse files
committed
Fix tag/function.js crazy formatting
1 parent da979fd commit 4cdb852

File tree

1 file changed

+106
-106
lines changed

1 file changed

+106
-106
lines changed

tags/function.js

Lines changed: 106 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,119 @@
1-
var getParent = require("bit-docs-process-tags/get-parent"),
2-
tnd = require("bit-docs-type-annotate").typeNameDescription;
3-
4-
//(~)? is just a stupid way of making sure there are the right number of parts
5-
6-
// key: function() or key= function(){}
7-
keyFunction = /(?:([\w\.\$]+)|(["'][^"']+["']))\s*[:=].*function\s?\(([^\)]*)/,
8-
namedFunction = /\s*function\s+([\w\.\$]+)\s*(~)?\(([^\)]*)/;
9-
1+
var updateNameWithScope = require("../lib/updateNameAndParentWithScope");
2+
var getParent = require("bit-docs-process-tags/get-parent");
3+
var tnd = require("bit-docs-type-annotate").typeNameDescription;
4+
5+
// key: function() or key= function(){}
6+
//(~)? is just a stupid way of making sure there are the right number of parts
7+
keyFunction = /(?:([\w\.\$]+)|(["'][^"']+["']))\s*[:=].*function\s?\(([^\)]*)/;
8+
namedFunction = /\s*function\s+([\w\.\$]+)\s*(~)?\(([^\)]*)/;
9+
10+
/**
11+
* @module {Object} bit-docs-js/tags/function @function
12+
* @parent bit-docs-js/tags
13+
*
14+
* @description Specifies the comment is for a function. Use
15+
* [bit-docs-js/tags/param] to specify the parameters of a function.
16+
*
17+
* @signature `@function [NAME] [TITLE]`
18+
*
19+
* @codestart javascript
20+
* /**
21+
* * @function lib.Component.prototype.update update
22+
* * @parent lib.Component
23+
* *|
24+
* C.p.update = function(){
25+
*
26+
* }
27+
* @codeend
28+
*
29+
* @param {String} [NAME] The name of the function. It should be supplied
30+
* if it cannot be determined from the code block following the comment.
31+
*
32+
* @param {String} [TITLE] The title to be used for display purposes.
33+
*
34+
* @body
35+
*
36+
* ## Code Matching
37+
*
38+
* The `@function` type can be inferred from code like the following:
39+
*
40+
* @codestart javascript
41+
* /**
42+
* * The foo function exists
43+
* *|
44+
* foo: function(){}
45+
*
46+
* /**
47+
* * The bar function exists
48+
* *|
49+
* bar = function(){}
50+
* @codeend
51+
*/
52+
module.exports = {
53+
codeMatch: /function(\s+[\w\.\$]+)?\s*\([^\)]*\)/,
54+
code: function (code, scope, docMap) {
55+
var parts = code.match(keyFunction);
56+
57+
if (!parts) {
58+
parts = code.match(namedFunction);
59+
}
1060

61+
var data = {
62+
type: "function"
63+
};
1164

12-
var updateNameWithScope = require("../lib/updateNameAndParentWithScope");
65+
if (!parts) {
66+
return;
67+
}
1368

14-
/**
15-
* @module {Object} bit-docs-js/tags/function @function
16-
* @parent bit-docs-js/tags
17-
*
18-
* @description Specifies the comment is for a function. Use
19-
* [bit-docs-js/tags/param] to specify the parameters of a function.
20-
*
21-
* @signature `@function [NAME] [TITLE]`
22-
*
23-
* @codestart javascript
24-
* /**
25-
* * @function lib.Component.prototype.update update
26-
* * @parent lib.Component
27-
* *|
28-
* C.p.update = function(){
29-
*
30-
* }
31-
* @codeend
32-
*
33-
* @param {String} [NAME] The name of the function. It should be supplied
34-
* if it cannot be determined from the code block following the comment.
35-
*
36-
* @param {String} [TITLE] The title to be used for display purposes.
37-
*
38-
* @body
39-
*
40-
* ## Code Matching
41-
*
42-
* The `@function` type can be inferred from code like the following:
43-
*
44-
* @codestart javascript
45-
* /**
46-
* * The foo function exists
47-
* *|
48-
* foo: function(){}
49-
*
50-
* /**
51-
* * The bar function exists
52-
* *|
53-
* bar = function(){}
54-
* @codeend
55-
*/
56-
module.exports = {
57-
codeMatch: /function(\s+[\w\.\$]+)?\s*\([^\)]*\)/,
58-
code: function( code, scope, docMap ) {
69+
data.name = parts[1] ? parts[1].replace(/^this\./, "")
70+
.replace(/^exports\./, "")
71+
.replace(/^\$./, "jQuery.") : parts[2];
5972

60-
var parts = code.match(keyFunction);
73+
data.params = [];
74+
var params = parts[3].match(/\w+/g);
6175

62-
if (!parts ) {
63-
parts = code.match(namedFunction);
64-
}
65-
var data = {
66-
type: "function"
67-
};
68-
if (!parts ) {
69-
return;
76+
if (params) {
77+
for (var i = 0; i < params.length; i++) {
78+
data.params.push({
79+
name: params[i],
80+
types: [{ type: "*" }]
81+
});
7082
}
71-
data.name = parts[1] ? parts[1].replace(/^this\./, "")
72-
.replace(/^exports\./, "")
73-
.replace(/^\$./, "jQuery.") : parts[2];
74-
75-
76-
data.params = [];
77-
var params = parts[3].match(/\w+/g);
78-
79-
if ( params ) {
83+
}
8084

81-
for ( var i = 0; i < params.length; i++ ) {
82-
data.params.push({
83-
name: params[i],
84-
types: [{type: "*"}]
85-
});
86-
}
85+
// assign name and parent
86+
if (scope && docMap) {
87+
var parentAndName = getParent.andName({
88+
parents: "*",
89+
useName: ["constructor", "static", "prototype", "add", "module"],
90+
scope: scope,
91+
docMap: docMap,
92+
name: data.name
93+
});
94+
95+
data.parent = parentAndName.parent;
96+
data.name = parentAndName.name;
97+
}
8798

88-
}
99+
return data;
100+
},
101+
add: function (line, curData, scope, docMap) {
102+
var data = tnd(line);
103+
this.title = data.description;
89104

90-
// assign name and parent
91-
if(scope && docMap){
92-
var parentAndName = getParent.andName({
93-
parents: "*",
94-
useName: ["constructor","static","prototype","add","module"],
95-
scope: scope,
96-
docMap: docMap,
97-
name: data.name
98-
});
105+
if (data.name) {
106+
this.name = data.name;
107+
}
99108

100-
data.parent = parentAndName.parent;
101-
data.name = parentAndName.name;
102-
}
109+
updateNameWithScope(this, scope, docMap);
103110

104-
return data;
105-
},
106-
add: function(line, curData, scope, docMap){
107-
var data = tnd(line);
108-
this.title = data.description;
109-
if(data.name) {
110-
this.name = data.name;
111-
}
112-
updateNameWithScope(this, scope, docMap);
113-
if(this.name)
111+
if (this.name) {
114112
this.type = "function";
115-
if(!data.params){
116-
data.params = [];
117-
}
118113
}
119-
};
114+
115+
if (!data.params) {
116+
data.params = [];
117+
}
118+
}
119+
};

0 commit comments

Comments
 (0)