@rightcapital/phpdoc-parser 0.3.52--.370.1.0 → 0.3.52--.372.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/phpdoc-parser/transpiler/helpers.d.ts +10 -50
- package/dist/phpdoc-parser/transpiler/helpers.js +35 -89
- package/package.json +1 -1
- package/dist/phpdoc-parser/transpiler/base-type-transpiler.d.ts +0 -17
- package/dist/phpdoc-parser/transpiler/base-type-transpiler.js +0 -15
package/dist/index.d.ts
CHANGED
|
@@ -73,3 +73,4 @@ export { ReturnTagValueNode } from './phpdoc-parser/ast/php-doc/return-tag-value
|
|
|
73
73
|
export { Printer } from './phpdoc-parser/printer/printer';
|
|
74
74
|
export { PhpDocTypeNodeToTypescriptTypeNodeTranspiler } from './phpdoc-parser/transpiler/php-doc-to-typescript-type-transpiler';
|
|
75
75
|
export * from './phpdoc-parser/ast/php-doc/helpers';
|
|
76
|
+
export * from './phpdoc-parser/transpiler/helpers';
|
package/dist/index.js
CHANGED
|
@@ -162,3 +162,4 @@ Object.defineProperty(exports, "Printer", { enumerable: true, get: function () {
|
|
|
162
162
|
var php_doc_to_typescript_type_transpiler_1 = require("./phpdoc-parser/transpiler/php-doc-to-typescript-type-transpiler");
|
|
163
163
|
Object.defineProperty(exports, "PhpDocTypeNodeToTypescriptTypeNodeTranspiler", { enumerable: true, get: function () { return php_doc_to_typescript_type_transpiler_1.PhpDocTypeNodeToTypescriptTypeNodeTranspiler; } });
|
|
164
164
|
__exportStar(require("./phpdoc-parser/ast/php-doc/helpers"), exports);
|
|
165
|
+
__exportStar(require("./phpdoc-parser/transpiler/helpers"), exports);
|
|
@@ -1,50 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function createSourceFileRoot(fileName: string, sourceText?: string, scriptTarget?:
|
|
3
|
-
export declare function addStatementsToNode(sourceFile:
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
|
|
11
|
-
nodeType: string;
|
|
12
|
-
children: PhpDocTagNode[];
|
|
13
|
-
};
|
|
14
|
-
type PhpDocTagNode = {
|
|
15
|
-
nodeType: string;
|
|
16
|
-
name: string;
|
|
17
|
-
value: PropertyTagValueNode;
|
|
18
|
-
};
|
|
19
|
-
type PropertyTagValueNode = {
|
|
20
|
-
nodeType: string;
|
|
21
|
-
type: UnionTypeNode | ArrayShapeNode;
|
|
22
|
-
propertyName: string;
|
|
23
|
-
description: string;
|
|
24
|
-
};
|
|
25
|
-
type UnionTypeNode = {
|
|
26
|
-
nodeType: string;
|
|
27
|
-
types: IdentifierTypeNode[];
|
|
28
|
-
};
|
|
29
|
-
type IdentifierTypeNode = {
|
|
30
|
-
nodeType: string;
|
|
31
|
-
name: string;
|
|
32
|
-
};
|
|
33
|
-
type ArrayShapeNode = {
|
|
34
|
-
nodeType: string;
|
|
35
|
-
items: ArrayShapeItemNode[];
|
|
36
|
-
sealed: boolean;
|
|
37
|
-
kind: string;
|
|
38
|
-
};
|
|
39
|
-
type ArrayShapeItemNode = {
|
|
40
|
-
nodeType: string;
|
|
41
|
-
keyName: IdentifierTypeNode;
|
|
42
|
-
optional: boolean;
|
|
43
|
-
valueType: IdentifierTypeNode;
|
|
44
|
-
};
|
|
45
|
-
type TsProperty = {
|
|
46
|
-
propertyName: string;
|
|
47
|
-
type: string;
|
|
48
|
-
};
|
|
49
|
-
export declare function transformPhpDocToTypeScriptObject(phpDocNode: PhpDocNode): TsProperty[];
|
|
50
|
-
export {};
|
|
1
|
+
import { type ImportDeclaration, type ExportDeclaration, type TypeElement, type TypeParameterDeclaration, type HeritageClause, type InterfaceDeclaration, ScriptTarget, type SourceFile, ScriptKind, type Statement, type EnumDeclaration, type ModifierSyntaxKind, type Node } from 'typescript';
|
|
2
|
+
export declare function createSourceFileRoot(fileName: string, sourceText?: string, scriptTarget?: ScriptTarget, scriptKind?: ScriptKind): SourceFile;
|
|
3
|
+
export declare function addStatementsToNode(sourceFile: SourceFile, newStatements: Statement[]): SourceFile;
|
|
4
|
+
export declare function createImportDeclarationNode(symbols: string[], filePath: string): ImportDeclaration;
|
|
5
|
+
export declare function createExportDeclarationNode(symbols: string[], moduleSpecifierString?: string): ExportDeclaration;
|
|
6
|
+
export declare function createInterfaceNode(interfaceName: string, members?: TypeElement[], typeParameters?: TypeParameterDeclaration[], heritageClauses?: HeritageClause[]): InterfaceDeclaration;
|
|
7
|
+
export declare function createCommentNode(commentText: string, isMultiLine?: boolean, hasTrailingNewLine?: boolean): Statement;
|
|
8
|
+
export declare function createEnumNode(enumName: string, members: [string, number | string][], modifiers: ModifierSyntaxKind[]): EnumDeclaration;
|
|
9
|
+
export declare function renderTsNodeToString(tsNode: Node): string;
|
|
10
|
+
export declare function renderTsSourceFileToString(sourceFile: SourceFile): string;
|
|
@@ -1,51 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const sourceFile = ts.createSourceFile(fileName, sourceText, scriptTarget, true, scriptKind);
|
|
3
|
+
exports.renderTsSourceFileToString = exports.renderTsNodeToString = exports.createEnumNode = exports.createCommentNode = exports.createInterfaceNode = exports.createExportDeclarationNode = exports.createImportDeclarationNode = exports.addStatementsToNode = exports.createSourceFileRoot = void 0;
|
|
4
|
+
const typescript_1 = require("typescript");
|
|
5
|
+
function createSourceFileRoot(fileName, sourceText = '', scriptTarget = typescript_1.ScriptTarget.Latest, scriptKind = typescript_1.ScriptKind.TS) {
|
|
6
|
+
const sourceFile = (0, typescript_1.createSourceFile)(fileName, sourceText, scriptTarget, true, scriptKind);
|
|
8
7
|
return sourceFile;
|
|
9
8
|
}
|
|
10
9
|
exports.createSourceFileRoot = createSourceFileRoot;
|
|
11
10
|
function addStatementsToNode(sourceFile, newStatements) {
|
|
12
|
-
const updatedStatements =
|
|
11
|
+
const updatedStatements = typescript_1.factory.createNodeArray([
|
|
13
12
|
...sourceFile.statements,
|
|
14
13
|
...newStatements,
|
|
15
14
|
]);
|
|
16
|
-
return
|
|
15
|
+
return typescript_1.factory.updateSourceFile(sourceFile, updatedStatements);
|
|
17
16
|
}
|
|
18
17
|
exports.addStatementsToNode = addStatementsToNode;
|
|
19
|
-
function
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
exports.renderTsNodeToString = renderTsNodeToString;
|
|
25
|
-
function createImportDeclarationNode(symbols, fileName) {
|
|
26
|
-
const importClause = ts.factory.createImportClause(false, undefined, ts.factory.createNamedImports(symbols.map((symbol) => ts.factory.createImportSpecifier(false, undefined, ts.factory.createIdentifier(symbol)))));
|
|
27
|
-
const moduleSpecifier = ts.factory.createStringLiteral(fileName);
|
|
28
|
-
const importDeclaration = ts.factory.createImportDeclaration(undefined, importClause, moduleSpecifier);
|
|
18
|
+
function createImportDeclarationNode(symbols, filePath) {
|
|
19
|
+
const importClause = typescript_1.factory.createImportClause(true, undefined, typescript_1.factory.createNamedImports(symbols.map((symbol) => typescript_1.factory.createImportSpecifier(false, undefined, typescript_1.factory.createIdentifier(symbol)))));
|
|
20
|
+
const moduleSpecifier = typescript_1.factory.createStringLiteral(filePath);
|
|
21
|
+
const importDeclaration = typescript_1.factory.createImportDeclaration(undefined, importClause, moduleSpecifier);
|
|
29
22
|
return importDeclaration;
|
|
30
23
|
}
|
|
31
24
|
exports.createImportDeclarationNode = createImportDeclarationNode;
|
|
32
25
|
function createExportDeclarationNode(symbols, moduleSpecifierString) {
|
|
33
|
-
const exportSpecifiers = symbols.map((symbol) =>
|
|
34
|
-
const namedExports =
|
|
26
|
+
const exportSpecifiers = symbols.map((symbol) => typescript_1.factory.createExportSpecifier(false, undefined, typescript_1.factory.createIdentifier(symbol)));
|
|
27
|
+
const namedExports = typescript_1.factory.createNamedExports(exportSpecifiers);
|
|
35
28
|
const moduleSpecifier = moduleSpecifierString
|
|
36
|
-
?
|
|
29
|
+
? typescript_1.factory.createStringLiteral(moduleSpecifierString)
|
|
37
30
|
: undefined;
|
|
38
|
-
const exportDeclaration =
|
|
31
|
+
const exportDeclaration = typescript_1.factory.createExportDeclaration(undefined, false, namedExports, moduleSpecifier);
|
|
39
32
|
return exportDeclaration;
|
|
40
33
|
}
|
|
41
34
|
exports.createExportDeclarationNode = createExportDeclarationNode;
|
|
42
|
-
function createInterfaceNode(interfaceName, members = [], typeParameters = []) {
|
|
43
|
-
const interfaceDeclaration =
|
|
35
|
+
function createInterfaceNode(interfaceName, members = [], typeParameters = [], heritageClauses = []) {
|
|
36
|
+
const interfaceDeclaration = typescript_1.factory.createInterfaceDeclaration([typescript_1.factory.createModifier(typescript_1.SyntaxKind.ExportKeyword)], typescript_1.factory.createIdentifier(interfaceName), typeParameters, heritageClauses, members);
|
|
44
37
|
return interfaceDeclaration;
|
|
45
38
|
}
|
|
46
39
|
exports.createInterfaceNode = createInterfaceNode;
|
|
47
40
|
function createCommentNode(commentText, isMultiLine = true, hasTrailingNewLine = true) {
|
|
48
|
-
const emptyStatement =
|
|
41
|
+
const emptyStatement = typescript_1.factory.createEmptyStatement();
|
|
49
42
|
let formattedCommentText;
|
|
50
43
|
if (isMultiLine) {
|
|
51
44
|
formattedCommentText = `*\n * ${commentText.split('\n').join('\n * ')}\n `;
|
|
@@ -53,76 +46,29 @@ function createCommentNode(commentText, isMultiLine = true, hasTrailingNewLine =
|
|
|
53
46
|
else {
|
|
54
47
|
formattedCommentText = commentText;
|
|
55
48
|
}
|
|
56
|
-
const emptyStatementWithComment =
|
|
57
|
-
?
|
|
58
|
-
:
|
|
49
|
+
const emptyStatementWithComment = (0, typescript_1.addSyntheticLeadingComment)(emptyStatement, isMultiLine
|
|
50
|
+
? typescript_1.SyntaxKind.MultiLineCommentTrivia
|
|
51
|
+
: typescript_1.SyntaxKind.SingleLineCommentTrivia, formattedCommentText, hasTrailingNewLine);
|
|
59
52
|
return emptyStatementWithComment;
|
|
60
53
|
}
|
|
61
54
|
exports.createCommentNode = createCommentNode;
|
|
62
|
-
function createEnumNode(enumName, members,
|
|
63
|
-
const memberNodes = members.map(([key, value]) =>
|
|
64
|
-
?
|
|
65
|
-
:
|
|
66
|
-
const enumDeclaration =
|
|
67
|
-
? [
|
|
68
|
-
ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
|
|
69
|
-
ts.factory.createModifier(ts.SyntaxKind.ConstKeyword),
|
|
70
|
-
]
|
|
71
|
-
: [ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createIdentifier(enumName), memberNodes);
|
|
55
|
+
function createEnumNode(enumName, members, modifiers) {
|
|
56
|
+
const memberNodes = members.map(([key, value]) => typescript_1.factory.createEnumMember(key, typeof value === 'number'
|
|
57
|
+
? typescript_1.factory.createNumericLiteral(value)
|
|
58
|
+
: typescript_1.factory.createStringLiteral(value)));
|
|
59
|
+
const enumDeclaration = typescript_1.factory.createEnumDeclaration(modifiers.map((modifier) => typescript_1.factory.createToken(modifier)), typescript_1.factory.createIdentifier(enumName), memberNodes);
|
|
72
60
|
return enumDeclaration;
|
|
73
61
|
}
|
|
74
62
|
exports.createEnumNode = createEnumNode;
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const propertyName = _.camelCase(tag.value.propertyName.replace(/^\$/, ''));
|
|
80
|
-
const type = transformTypeNodeToTypeScript(tag.value.type);
|
|
81
|
-
return { propertyName, type };
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
exports.transformPhpDocToTypeScriptObject = transformPhpDocToTypeScriptObject;
|
|
85
|
-
function transformTypeNodeToTypeScript(typeNode) {
|
|
86
|
-
if (typeNode.nodeType === 'UnionTypeNode') {
|
|
87
|
-
return typeNode.types
|
|
88
|
-
.map((t) => transformIdentifierTypeNodeToTypeScript(t))
|
|
89
|
-
.join(' | ');
|
|
90
|
-
}
|
|
91
|
-
if (typeNode.nodeType === 'ArrayShapeNode') {
|
|
92
|
-
const entries = typeNode.items
|
|
93
|
-
.map((item) => `${_.camelCase(item.keyName.name)}${item.optional ? '?' : ''}: ${transformIdentifierTypeNodeToTypeScript(item.valueType)}`)
|
|
94
|
-
.join('; ');
|
|
95
|
-
return `{ ${entries} }`;
|
|
96
|
-
}
|
|
97
|
-
return 'any';
|
|
63
|
+
function renderTsNodeToString(tsNode) {
|
|
64
|
+
const printer = (0, typescript_1.createPrinter)({ newLine: typescript_1.NewLineKind.LineFeed });
|
|
65
|
+
const resultFile = createSourceFileRoot('temp.ts');
|
|
66
|
+
return printer.printNode(typescript_1.EmitHint.Unspecified, tsNode, resultFile);
|
|
98
67
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return identifierTypeNode.name;
|
|
105
|
-
case 'float':
|
|
106
|
-
return 'number';
|
|
107
|
-
case 'boolean':
|
|
108
|
-
case 'bool':
|
|
109
|
-
return 'boolean';
|
|
110
|
-
case 'date':
|
|
111
|
-
case 'datetime':
|
|
112
|
-
case 'immutable_date':
|
|
113
|
-
case 'immutable_datetime':
|
|
114
|
-
case 'CarbonInterface':
|
|
115
|
-
case '\\Carbon\\CarbonInterface':
|
|
116
|
-
case '\\Carbon\\Carbon':
|
|
117
|
-
case '\\Carbon\\CarbonImmutable':
|
|
118
|
-
return 'string';
|
|
119
|
-
case 'array':
|
|
120
|
-
return 'any';
|
|
121
|
-
case 'Collection':
|
|
122
|
-
return 'any[]';
|
|
123
|
-
case 'mixed':
|
|
124
|
-
return 'any';
|
|
125
|
-
default:
|
|
126
|
-
return 'any';
|
|
127
|
-
}
|
|
68
|
+
exports.renderTsNodeToString = renderTsNodeToString;
|
|
69
|
+
function renderTsSourceFileToString(sourceFile) {
|
|
70
|
+
const printer = (0, typescript_1.createPrinter)({ newLine: typescript_1.NewLineKind.LineFeed });
|
|
71
|
+
const sourceFileContent = printer.printFile(sourceFile);
|
|
72
|
+
return sourceFileContent;
|
|
128
73
|
}
|
|
74
|
+
exports.renderTsSourceFileToString = renderTsSourceFileToString;
|
package/package.json
CHANGED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ImportDeclaration, TypeNode } from 'typescript';
|
|
2
|
-
export declare abstract class BaseTypeTranspiler<SourceTypeNode> {
|
|
3
|
-
nameNodePathResolver: (nodeParts: string[]) => {
|
|
4
|
-
path: string;
|
|
5
|
-
name: string;
|
|
6
|
-
isTypeOnly: boolean;
|
|
7
|
-
};
|
|
8
|
-
constructor(nameNodePathResolver: (nodeParts: string[]) => {
|
|
9
|
-
path: string;
|
|
10
|
-
name: string;
|
|
11
|
-
isTypeOnly: boolean;
|
|
12
|
-
});
|
|
13
|
-
abstract transpile(typeNode: SourceTypeNode): TypeNode;
|
|
14
|
-
beforeTranspile(): void;
|
|
15
|
-
getImportDeclarations(): ImportDeclaration[];
|
|
16
|
-
protected importDeclarations: ImportDeclaration[];
|
|
17
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseTypeTranspiler = void 0;
|
|
4
|
-
class BaseTypeTranspiler {
|
|
5
|
-
constructor(nameNodePathResolver) {
|
|
6
|
-
this.nameNodePathResolver = nameNodePathResolver;
|
|
7
|
-
}
|
|
8
|
-
beforeTranspile() {
|
|
9
|
-
this.importDeclarations = [];
|
|
10
|
-
}
|
|
11
|
-
getImportDeclarations() {
|
|
12
|
-
return this.importDeclarations;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.BaseTypeTranspiler = BaseTypeTranspiler;
|