Skip to content

Commit eecb245

Browse files
committed
initial commit
1 parent a7181eb commit eecb245

27 files changed

+2591
-0
lines changed

.babelrc

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Babel has a bug which requires a workaround for `export * from '...'` found in `./src/BabylonDocs.js`.
3+
* See this issue: https://github.com/babel/babel/issues/2877
4+
* Solution applied is found here: https://github.com/babel/babel/issues/2877#issuecomment-280297439
5+
* `passPerPreset` is enabled to run `transform-runtime` then the standard presets.
6+
*/
7+
{
8+
"passPerPreset": true,
9+
10+
"presets":
11+
[
12+
{ "plugins": [ "transform-runtime" ] },
13+
{
14+
"passPerPreset": false,
15+
"presets": [ "latest", "stage-2" ]
16+
}
17+
],
18+
19+
"plugins":
20+
[
21+
"add-module-exports",
22+
["module-resolver", {
23+
"root": ["."],
24+
"alias":
25+
{
26+
"tjsdoc-docs-common/src": "tjsdoc-docs-common/dist"
27+
}
28+
}]
29+
],
30+
31+
"env":
32+
{
33+
"tjsdoc-dev":
34+
{
35+
"plugins":
36+
[
37+
"add-module-exports",
38+
["module-resolver", {
39+
"root": ["."],
40+
"cwd": "babelrc",
41+
"alias":
42+
{
43+
"tjsdoc-docs-common": "../tjsdoc-docs-common/src",
44+
"tjsdoc-docs-common/src": "../tjsdoc-docs-common/src"
45+
}
46+
}]
47+
]
48+
}
49+
}
50+
}

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[*]
2+
end_of_line = lf
3+
charset = utf-8
4+
insert_final_newline = true
5+
indent_style = space
6+
indent_size = 3
7+
trim_trailing_whitespace = true
8+
9+
[*.js]
10+
indent_size = 3

.eslintignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
coverage/
2+
dist/
3+
docs/
4+
node_modules/
5+
6+
tjsdoc-publisher-static-html/template

.eslintrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Loads https://github.com/typhonjs/typhonjs-config-eslint/blob/master/3.0/babel/es8/server/node/.eslintrc
3+
* NPM: https://www.npmjs.com/package/typhonjs-config-eslint
4+
*/
5+
{
6+
"extends": "./node_modules/typhonjs-config-eslint/3.0/babel/es8/server/node/.eslintrc"
7+
}

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.idea
2+
.DS_Store
3+
npm-debug.log
4+
coverage/
5+
dist/
6+
docs/
7+
node_modules/

.npmscriptrc.js

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
4+
/**
5+
* You can provide comments in `.npmscriptrc.js`
6+
*/
7+
var config =
8+
{
9+
"build":
10+
{
11+
"babel": { "source": "src", "destination": "dist" }
12+
},
13+
14+
"publish":
15+
{
16+
"prepublish": { "scripts": ["npm run eslint", "npm run test", "npm run build"] }
17+
},
18+
19+
"test":
20+
{
21+
// Provides a `coverage` handling command that is appended when running on Travis CI.
22+
"travis":
23+
{
24+
"istanbul": { "command": "cover", "options": ["--report lcovonly"] },
25+
"report": "./node_modules/.bin/codecov"
26+
},
27+
28+
"istanbul": { "command": "cover", "options": ["--include-all-sources --root src -x '**/template/**'"] },
29+
"mocha": { "source": "./node_modules/tjsdoc-tests-ecmascript/test/src", "options": ["--require tjsdoc-tests-ecmascript", "--compilers js:babel-register", "-t 120000 --recursive"] }
30+
},
31+
32+
// For local developer testing.
33+
"dev_test":
34+
{
35+
"istanbul": { "command": "cover", "options": ["--include-all-sources --root src -x '**/template/**'"] },
36+
"mocha": { "source": "./node_modules/tjsdoc-tests-ecmascript/test/src", "options": ["--require tjsdoc-tests-ecmascript", "--compilers js:babel-register", "-t 120000 --recursive"] }
37+
},
38+
39+
// Always tests with NPM module: tjsdoc-tests-ecmascript
40+
"dev_test_npm":
41+
{
42+
"mocha": { "source": "./node_modules/tjsdoc-tests-ecmascript/test/src", "options": ["--require tjsdoc-tests-ecmascript", "--compilers js:babel-register", "-t 120000 --recursive"] }
43+
}
44+
};
45+
46+
// Detect if running in development mode and if so attempt to locate local checked out tests. If found use the local
47+
// tests instead of the NPM module version automatically.
48+
if (process.env.BABEL_ENV === 'tjsdoc-dev')
49+
{
50+
try
51+
{
52+
var testPath = path.resolve('../tjsdoc-tests-ecmascript/package.json');
53+
54+
if (fs.existsSync(testPath))
55+
{
56+
var testPackage = require(testPath);
57+
58+
if (testPackage.name === 'tjsdoc-tests-ecmascript')
59+
{
60+
// Set to local tests.
61+
config.dev_test.mocha =
62+
{
63+
"source": "../tjsdoc-tests-ecmascript/test/src",
64+
"options": ["--compilers js:babel-register", "-t 120000 --recursive"]
65+
};
66+
}
67+
}
68+
}
69+
catch (err) { /* nop */ }
70+
}
71+
72+
// Out put a message indicating which testing environment is being used of developer tests are run.
73+
try
74+
{
75+
var npmArgv = JSON.parse(process.env['npm_config_argv']).cooked;
76+
var npmScript = npmArgv[1];
77+
78+
if (npmScript === 'dev-test' || npmScript === 'dev-test-coverage')
79+
{
80+
console.log('test location: ' + config.dev_test.mocha.source)
81+
}
82+
}
83+
catch (err) { /* nop */ }
84+
85+
module.exports = config;

.tjsdocrc

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Some comments! You can include comments in TJSDoc config files */
2+
{
3+
"source": "src",
4+
"destination": "docs",
5+
"builtinPluginVirtual": true,
6+
"emptyDestination": true,
7+
"unexportIdentifier": true,
8+
9+
"test":
10+
{
11+
"type": "mocha",
12+
"source":
13+
[
14+
"./node_modules/tjsdoc-tests-ecmascript/test/src/html",
15+
"./node_modules/tjsdoc-tests-ecmascript/test/src/html-doc"
16+
]
17+
}
18+
}

.tjsdocrc-local

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* Load local development modules directly. */
2+
{
3+
"extends": ".tjsdocrc",
4+
5+
"publisher": "../tjsdoc-publisher-static-html/src/publish.js",
6+
"runtime": "../tjsdoc-babylon/src/TJSDocBabylon.js"
7+
}

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- "5.8.0"
4+
script:
5+
- npm run test-coverage

AUTHORS.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
####Corporate Copyright Statements
2+
-----
3+
4+
Copyright (c) 2015-present TyphonRT Inc. [@typhonrt](https://github.com/typhonrt)
5+
6+
####Contributors
7+
-----
8+
9+
Michael Leahy [@typhonrt](https://github.com/typhonrt)

package.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "tjsdoc-docs-babylon",
3+
"version": "0.0.1",
4+
"description": "Provides Babylon doc tag generation for TJSDoc.",
5+
"author": "typhonrt",
6+
"homepage": "https://tjsdoc.typhonjs.io/",
7+
"license": "MPL-2.0",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/typhonjs-node-tjsdoc/tjsdoc-docs-babylon"
11+
},
12+
"scripts": {
13+
"build": "babel-node ./node_modules/typhonjs-npm-scripts-build-babel/scripts/build.js",
14+
"eslint": "eslint .",
15+
"dev-test": "BABEL_ENV=tjsdoc-dev babel-node ./node_modules/typhonjs-npm-scripts-test-mocha/scripts/mocha.js dev_test",
16+
"dev-test-coverage": "BABEL_ENV=tjsdoc-dev babel-node ./node_modules/typhonjs-npm-scripts-test-mocha/scripts/mocha-istanbul.js dev_test",
17+
"dev-test-npm": "BABEL_ENV=tjsdoc-dev babel-node ./node_modules/typhonjs-npm-scripts-test-mocha/scripts/mocha.js dev_test_npm",
18+
"dev-tjsdoc": "BABEL_ENV=tjsdoc-dev babel-node ../tjsdoc/src/TJSDocCLI.js -c .tjsdocrc-local",
19+
"prepublish": "babel-node ./node_modules/typhonjs-npm-scripts-publish/scripts/prepublish.js",
20+
"test": "babel-node ./node_modules/typhonjs-npm-scripts-test-mocha/scripts/mocha.js",
21+
"test-coverage": "babel-node ./node_modules/typhonjs-npm-scripts-test-mocha/scripts/mocha-istanbul.js"
22+
},
23+
"dependencies": {
24+
"babel-generator": "^6.0.0",
25+
"babel-runtime": "^6.0.0"
26+
},
27+
"devDependencies": {
28+
"tjsdoc-test-utils": "git+https://[email protected]/typhonjs-node-tjsdoc/tjsdoc-test-utils.git",
29+
"tjsdoc-tests-ecmascript": "git+https://[email protected]/typhonjs-node-tjsdoc/tjsdoc-tests-ecmascript.git",
30+
"typhonjs-config-eslint": "^0.5.0",
31+
"typhonjs-npm-build-test": "^0.6.0"
32+
},
33+
"keywords": [
34+
"typhonjs",
35+
"tjsdoc",
36+
"doc",
37+
"generation",
38+
"babylon"
39+
],
40+
"files": [
41+
"dist",
42+
"src",
43+
".tjsdocrc",
44+
"AUTHORS.md"
45+
],
46+
"main": "dist/",
47+
"bugs": {
48+
"url": "https://github.com/typhonjs-node-tjsdoc/tjsdoc/issues"
49+
}
50+
}

src/doc/AssignmentDoc.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import AbstractAssignmentDoc from 'tjsdoc-docs-common/src/doc/abstract/AbstractAssignmentDoc.js';
2+
3+
/**
4+
* Doc Class for Assignment AST node.
5+
*/
6+
export default class AssignmentDoc extends AbstractAssignmentDoc
7+
{
8+
/**
9+
* Take out self name from self node.
10+
*/
11+
_$name()
12+
{
13+
this._value.name = this._eventbus.triggerSync('tjsdoc:ast:flatten:member:expression',
14+
this._node.left).replace(/^this\./, '');
15+
}
16+
}
17+

src/doc/ClassDoc.js

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import AbstractClassDoc from 'tjsdoc-docs-common/src/doc/abstract/AbstractClassDoc.js';
2+
3+
/**
4+
* Doc Class from Class Declaration AST node.
5+
*/
6+
export default class ClassDoc extends AbstractClassDoc
7+
{
8+
/** Support for @extends and direct ES module inheritance. */
9+
_$extends()
10+
{
11+
const values = this._findAllTagValues(['@extends']);
12+
13+
if (values)
14+
{
15+
this._value.extends = [];
16+
17+
for (const value of values)
18+
{
19+
const { typeText } = this._eventbus.triggerSync('tjsdoc:parse:param:value', value,
20+
{ type: true, name: false, desc: false });
21+
22+
this._value.extends.push(typeText);
23+
}
24+
25+
return;
26+
}
27+
28+
if (this._node.superClass)
29+
{
30+
const node = this._node;
31+
const targets = [];
32+
33+
let longnames = [];
34+
35+
if (node.superClass.type === 'CallExpression')
36+
{
37+
targets.push(node.superClass.callee, ...node.superClass.arguments);
38+
}
39+
else
40+
{
41+
targets.push(node.superClass);
42+
}
43+
44+
for (const target of targets)
45+
{
46+
switch (target.type)
47+
{
48+
case 'Identifier':
49+
longnames.push(this._resolveLongname(target.name));
50+
break;
51+
52+
case 'MemberExpression':
53+
{
54+
const fullIdentifier = this._eventbus.triggerSync('tjsdoc:ast:flatten:member:expression', target);
55+
const rootIdentifier = fullIdentifier.split('.')[0];
56+
const rootLongname = this._resolveLongname(rootIdentifier);
57+
const filePath = rootLongname.replace(/~.*/, '');
58+
59+
longnames.push(`${filePath}~${fullIdentifier}`);
60+
break;
61+
}
62+
}
63+
}
64+
65+
if (node.superClass.type === 'CallExpression')
66+
{
67+
// expression extends may be a Class or a function, so filter by leading upper or lowercase.
68+
longnames = longnames.filter((v) => v.match(/^[a-zA-Z]|^[$_][a-zA-Z]/));
69+
70+
const filePath = this._pathResolver.absolutePath;
71+
const line = node.superClass.loc.start.line;
72+
const start = node.superClass.loc.start.column;
73+
const end = node.superClass.loc.end.column;
74+
75+
this._value.expressionExtends = this._readSelection(filePath, line, start, end);
76+
}
77+
78+
if (longnames.length) { this._value.extends = longnames; }
79+
}
80+
}
81+
82+
/** Take out self name from self node */
83+
_$name()
84+
{
85+
if (this._node.id)
86+
{
87+
this._value.name = this._node.id.name;
88+
}
89+
else
90+
{
91+
this._value.name = this._eventbus.triggerSync('tjsdoc:filepath:to:name', this._pathResolver.filePath);
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)