Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
3d792ec
Update TypeScript to 3.8.3
sainthkh Mar 29, 2020
fd0a4a6
Extract getExportTokens and rename it to getExportStatements
sainthkh Mar 17, 2020
e0165e0
Add script: dump-ast.
sainthkh Mar 17, 2020
c87aaff
Refactor getExportEntries.
sainthkh Mar 18, 2020
eb4b14b
hasExportKeyword -> hasExportModifier, hasDefaultKeyword -> hasDefaul…
sainthkh Mar 18, 2020
47b0f41
Remove doctrine and unnecessary files/code. Edit comment.
sainthkh Mar 19, 2020
22b8388
Refactor getJsdocFromToken
sainthkh Mar 19, 2020
d546688
getJsdocFromToken -> getJsdocFromStatement.
sainthkh Mar 19, 2020
ad2aea1
Handle the case when there is no tag.
sainthkh Mar 19, 2020
9372027
Refactor getIntermediateRepresentation.
sainthkh Mar 20, 2020
3528e37
Fix index.js
sainthkh Mar 22, 2020
6966050
Remove getIRFromStatement from public API.
sainthkh Mar 22, 2020
69a6fa5
Fix the case for `import 'x'`.
sainthkh Mar 22, 2020
84671d4
Remove unnecessary comment.
sainthkh Mar 22, 2020
528fa02
TypeScript compiles @wordpress as a tag. Fixed it.
sainthkh Mar 22, 2020
5b7aec9
Fix fileName.
sainthkh Mar 22, 2020
05eea4c
Add test for generating types.
sainthkh Mar 22, 2020
b22acb8
Add types to test.
sainthkh Mar 23, 2020
5c52fe8
Removed unnecessary files and espree
sainthkh Mar 25, 2020
d98bb09
Remove type checker.
sainthkh Mar 23, 2020
7e18aad
Add primitive types.
sainthkh Mar 23, 2020
b1d1d21
Add more type generations.
sainthkh Mar 24, 2020
34ea53b
Add function and object.
sainthkh Mar 24, 2020
7b3224b
Add more types.
sainthkh Mar 25, 2020
2b2e52c
Add explanation comment for __WORDPRESS_IMPORT__
sainthkh Mar 25, 2020
7ebc964
import -> require
sainthkh Mar 25, 2020
c83fc7e
Handle @typedef.
sainthkh Mar 25, 2020
67012d7
Uncomment tests.
sainthkh Mar 25, 2020
535efa5
type field for typedef.
sainthkh Mar 25, 2020
6a47250
Format typedef.
sainthkh Mar 26, 2020
296c61e
Show default value.
sainthkh Mar 26, 2020
5f90185
When a doc has no description but has tags, it's documented.
sainthkh Mar 26, 2020
dd14b0f
Replace __WORDPRESS_IMPORT__
sainthkh Mar 26, 2020
294d4cd
Remove arg name and dot.
sainthkh Mar 26, 2020
c3c4137
Format jsdoc object param definition
sainthkh Mar 26, 2020
c89e1a1
escapedText adds one more _. So, changed them to text.
sainthkh Mar 26, 2020
097cc9c
Fix lone qualified name.
sainthkh Mar 26, 2020
89ca742
Restore @wordpress in description.
sainthkh Mar 26, 2020
859fecc
Handle generics.
sainthkh Mar 27, 2020
673fa13
Handle <caption>ES(5|Next)</caption> tags.
sainthkh Mar 27, 2020
4e522b5
escapedText -> text.
sainthkh Mar 27, 2020
4ac2228
Remove unnecessary script.
sainthkh Mar 27, 2020
6b0b0f6
Remove unnecessary exports.json.
sainthkh Mar 27, 2020
86fc6b9
Fix when the type of jsdoc type literal has a type option like {?object}
sainthkh Mar 27, 2020
2f8076e
Remove unnecessary code.
sainthkh Mar 27, 2020
fa1d12d
Add known issues.
sainthkh Mar 29, 2020
843d4b6
Respect WP coding style.
sainthkh Mar 29, 2020
4029682
Add jsdoc comments.
sainthkh Mar 29, 2020
9811795
Add cases to help understand code.
sainthkh Mar 29, 2020
f92fd7f
Use optional chaining + optional catch binding!
sainthkh Mar 29, 2020
b879fb0
Show type error.
sainthkh Mar 29, 2020
8654f4e
Fix package.json lint error.
sainthkh Mar 29, 2020
7f026d5
Fix test failures.
sainthkh Mar 29, 2020
ada4448
Remove unnecessary script in package.json.
sainthkh Mar 31, 2020
f114bda
Remove ES2020 or rename it to ESNext.
sainthkh Mar 31, 2020
62014e8
Add comment when __WORDPRESS_IMPORT__ is restored.
sainthkh Mar 31, 2020
28172ef
Replace @wordpress in type names.
sainthkh Mar 31, 2020
c621be2
Remove getLocalName().
sainthkh Mar 31, 2020
1f8a54f
Add more sample cases in the comment to getExportStatements.
sainthkh Mar 31, 2020
d869e45
Remove unnecessary code.
sainthkh Mar 31, 2020
d5f9b22
Fix curly.
sainthkh Mar 31, 2020
c6c9c99
Handle when there is no "export" in the file.
sainthkh Mar 31, 2020
ad088d8
Comment where I got the list of types.
sainthkh Apr 1, 2020
8586be6
Remove invalid test case.
sainthkh Apr 1, 2020
c5f7b88
Update docs
sainthkh Apr 1, 2020
e4c60f3
sF -> internalSourceFile.
sainthkh Apr 3, 2020
d150875
console.log -> process.stdout.write
sainthkh Apr 3, 2020
2f20e58
Parse new syntaxes correctly.
sainthkh Apr 3, 2020
209271a
Revert "Use optional chaining + optional catch binding!"
sainthkh Apr 3, 2020
0ec03a5
Revert "Update docs"
sainthkh Apr 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove getIRFromStatement from public API.
  • Loading branch information
sainthkh committed Apr 3, 2020
commit 6966050e1d3a9f567c73429e6745d827e5aceb87
11 changes: 4 additions & 7 deletions packages/docgen/src/get-intermediate-representation.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,7 @@ const getDependencyIR = ( sourceFile ) => ( statement ) => {
*
* @return {Array<IREntry>} Intermediate Representation in JSON.
*/
export const getIRFromStatement = (
path,
statement,
typeChecker,
sourceFile
) => {
const getIRFromStatement = ( path, statement, typeChecker, sourceFile ) => {
const exportEntries = getExportEntries( statement );
const ir = [];
exportEntries.forEach( ( entry ) => {
Expand Down Expand Up @@ -266,7 +261,7 @@ export const getIRFromStatement = (
*
* @return {Array<IREntry>} Intermediate Representation in JSON.
*/
export const getIntermediateRepresentation = (
const getIntermediateRepresentation = (
path,
exportStatements,
typeChecker,
Expand All @@ -278,3 +273,5 @@ export const getIntermediateRepresentation = (
)
);
};

module.exports = getIntermediateRepresentation;
132 changes: 60 additions & 72 deletions packages/docgen/src/test/get-intermediate-representation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const path = require( 'path' );
* Internal dependencies.
*/
const compile = require( '../compile' );
const { getIRFromStatement } = require( '../get-intermediate-representation' );
const getIntermediateRepresentation = require( '../get-intermediate-representation' );

describe( 'Intermediate Representation From Statement', function() {
const prepare = ( dir ) => {
Expand All @@ -27,9 +27,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements, sourceFile } = prepare(
'default-undocumented-nocomments'
);
const ir = getIRFromStatement(
const ir = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand All @@ -46,9 +46,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements, sourceFile } = prepare(
'default-undocumented-oneliner'
);
const irOneliner = getIRFromStatement(
const irOneliner = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand All @@ -65,9 +65,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements } = prepare(
'tags-ts-definition'
);
const ir = getIRFromStatement(
const ir = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker
);
expect( ir ).toHaveLength( 1 );
Expand All @@ -93,9 +93,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements } = prepare(
'default-class-anonymous'
);
const irClassAnonymous = getIRFromStatement(
const irClassAnonymous = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker
);
expect( irClassAnonymous ).toHaveLength( 1 );
Expand All @@ -111,9 +111,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements } = prepare(
'default-class-named'
);
const irClassNamed = getIRFromStatement(
const irClassNamed = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker
);
expect( irClassNamed ).toHaveLength( 1 );
Expand All @@ -129,9 +129,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements } = prepare(
'default-function-anonymous'
);
const irFnAnonymous = getIRFromStatement(
const irFnAnonymous = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker
);
expect( irFnAnonymous ).toHaveLength( 1 );
Expand All @@ -147,9 +147,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements } = prepare(
'default-function-named'
);
const irFnNamed = getIRFromStatement(
const irFnNamed = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker
);
expect( irFnNamed[ 0 ] ).toEqual( {
Expand All @@ -164,9 +164,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements } = prepare(
'default-variable'
);
const irVar = getIRFromStatement(
const irVar = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker
);
expect( irVar[ 0 ] ).toEqual( {
Expand All @@ -183,9 +183,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements } = prepare(
'named-class'
);
const irNamedClass = getIRFromStatement(
const irNamedClass = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker
);
expect( irNamedClass ).toHaveLength( 1 );
Expand All @@ -201,9 +201,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements } = prepare(
'named-function'
);
const irNamedFn = getIRFromStatement(
const irNamedFn = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker
);
expect( irNamedFn ).toHaveLength( 1 );
Expand All @@ -219,9 +219,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements } = prepare(
'named-variable'
);
const irNamedVar = getIRFromStatement(
const irNamedVar = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker
);
expect( irNamedVar ).toHaveLength( 1 );
Expand All @@ -237,9 +237,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { typeChecker, exportStatements } = prepare(
'named-variables'
);
const irNamedVars = getIRFromStatement(
const irNamedVars = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker
);
expect( irNamedVars ).toHaveLength( 2 );
Expand All @@ -265,9 +265,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'default-identifier'
);
const irDefaultId = getIRFromStatement(
const irDefaultId = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand All @@ -284,26 +284,20 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'default-named-export'
);
const irDefaultNamed0 = getIRFromStatement(
const irDefaultNamed = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
expect( irDefaultNamed0 ).toHaveLength( 1 );
expect( irDefaultNamed0[ 0 ] ).toEqual( {
expect( irDefaultNamed ).toHaveLength( 2 );
expect( irDefaultNamed[ 0 ] ).toEqual( {
path: null,
name: 'functionDeclaration',
description: 'Function declaration example.',
tags: [],
} );
const irDefaultNamed1 = getIRFromStatement(
null,
exportStatements[ 1 ],
typeChecker,
sourceFile
);
expect( irDefaultNamed1[ 0 ] ).toEqual( {
expect( irDefaultNamed[ 1 ] ).toEqual( {
path: null,
name: 'default',
description: 'Function declaration example.',
Expand All @@ -317,9 +311,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'named-identifier'
);
const irNamedId = getIRFromStatement(
const irNamedId = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand All @@ -336,9 +330,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'named-identifier-destructuring'
);
const irNamedIdDestructuring = getIRFromStatement(
const irNamedIdDestructuring = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand All @@ -355,9 +349,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'named-identifiers'
);
const irIds = getIRFromStatement(
const irIds = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand Down Expand Up @@ -386,32 +380,26 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'named-identifiers-and-inline'
);
const irIdInline0 = getIRFromStatement(
const irIdInline = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
expect( irIdInline0 ).toHaveLength( 2 );
expect( irIdInline0[ 0 ] ).toEqual( {
expect( irIdInline ).toHaveLength( 3 );
expect( irIdInline[ 0 ] ).toEqual( {
path: null,
name: 'functionDeclaration',
description: 'Function declaration example.',
tags: [],
} );
expect( irIdInline0[ 1 ] ).toEqual( {
expect( irIdInline[ 1 ] ).toEqual( {
path: null,
name: 'ClassDeclaration',
description: 'Class declaration example.',
tags: [],
} );
const irIdInline1 = getIRFromStatement(
null,
exportStatements[ 1 ],
typeChecker,
sourceFile
);
expect( irIdInline1[ 0 ] ).toEqual( {
expect( irIdInline[ 2 ] ).toEqual( {
path: null,
name: 'variableDeclaration',
description: 'Variable declaration example.',
Expand All @@ -426,9 +414,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'named-import-named'
);
const ir = getIRFromStatement(
const ir = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand Down Expand Up @@ -458,9 +446,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'named-default'
);
const irNamedDefault = getIRFromStatement(
const irNamedDefault = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand All @@ -477,9 +465,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'named-default-exported'
);
const irNamedDefaultExported = getIRFromStatement(
const irNamedDefaultExported = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand All @@ -498,9 +486,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'namespace'
);
const irNamespace = getIRFromStatement(
const irNamespace = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand Down Expand Up @@ -529,9 +517,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'namespace-commented'
);
const irNamespaceCommented = getIRFromStatement(
const irNamespaceCommented = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand Down Expand Up @@ -564,9 +552,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'default-import-default'
);
const irDefault = getIRFromStatement(
const irDefault = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand All @@ -583,9 +571,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'default-import-named'
);
const irNamed = getIRFromStatement(
const irNamed = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand All @@ -603,9 +591,9 @@ describe( 'Intermediate Representation From Statement', function() {
const { sourceFile, typeChecker, exportStatements } = prepare(
'named-import-namespace'
);
const ir = getIRFromStatement(
const ir = getIntermediateRepresentation(
null,
exportStatements[ 0 ],
exportStatements,
typeChecker,
sourceFile
);
Expand Down