python2ts 0.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/README.md +148 -0
- package/dist/acorn-CDFV7HXL.js +3131 -0
- package/dist/acorn-CDFV7HXL.js.map +1 -0
- package/dist/angular-PCJAXZFD.js +3071 -0
- package/dist/angular-PCJAXZFD.js.map +1 -0
- package/dist/babel-O6RKFHDQ.js +7297 -0
- package/dist/babel-O6RKFHDQ.js.map +1 -0
- package/dist/chunk-DTI6R2GT.js +23942 -0
- package/dist/chunk-DTI6R2GT.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +117 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/estree-467CT4RF.js +4613 -0
- package/dist/estree-467CT4RF.js.map +1 -0
- package/dist/flow-FCFYGKSM.js +27547 -0
- package/dist/flow-FCFYGKSM.js.map +1 -0
- package/dist/glimmer-P46N72G3.js +2895 -0
- package/dist/glimmer-P46N72G3.js.map +1 -0
- package/dist/graphql-TFOZJU7B.js +1267 -0
- package/dist/graphql-TFOZJU7B.js.map +1 -0
- package/dist/html-KZKNLN3R.js +2934 -0
- package/dist/html-KZKNLN3R.js.map +1 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown-BS2B5AKD.js +3554 -0
- package/dist/markdown-BS2B5AKD.js.map +1 -0
- package/dist/meriyah-W6HUPGCY.js +2685 -0
- package/dist/meriyah-W6HUPGCY.js.map +1 -0
- package/dist/postcss-LMJBCD2Q.js +5081 -0
- package/dist/postcss-LMJBCD2Q.js.map +1 -0
- package/dist/typescript-Y5EPKFX5.js +13204 -0
- package/dist/typescript-Y5EPKFX5.js.map +1 -0
- package/dist/yaml-ZNP3H3BX.js +4225 -0
- package/dist/yaml-ZNP3H3BX.js.map +1 -0
- package/package.json +52 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Tree, SyntaxNode } from '@lezer/common';
|
|
2
|
+
export { py } from 'pythonlib';
|
|
3
|
+
|
|
4
|
+
interface ParseResult {
|
|
5
|
+
tree: Tree;
|
|
6
|
+
source: string;
|
|
7
|
+
}
|
|
8
|
+
interface NodeVisitor<T> {
|
|
9
|
+
visitNode(node: SyntaxNode, source: string): T;
|
|
10
|
+
}
|
|
11
|
+
declare const NodeTypes: {
|
|
12
|
+
readonly Script: "Script";
|
|
13
|
+
readonly ExpressionStatement: "ExpressionStatement";
|
|
14
|
+
readonly AssignStatement: "AssignStatement";
|
|
15
|
+
readonly AugmentedAssignStatement: "AugmentedAssignStatement";
|
|
16
|
+
readonly PrintStatement: "PrintStatement";
|
|
17
|
+
readonly PassStatement: "PassStatement";
|
|
18
|
+
readonly BreakStatement: "BreakStatement";
|
|
19
|
+
readonly ContinueStatement: "ContinueStatement";
|
|
20
|
+
readonly ReturnStatement: "ReturnStatement";
|
|
21
|
+
readonly IfStatement: "IfStatement";
|
|
22
|
+
readonly WhileStatement: "WhileStatement";
|
|
23
|
+
readonly ForStatement: "ForStatement";
|
|
24
|
+
readonly FunctionDefinition: "FunctionDefinition";
|
|
25
|
+
readonly ClassDefinition: "ClassDefinition";
|
|
26
|
+
readonly TryStatement: "TryStatement";
|
|
27
|
+
readonly RaiseStatement: "RaiseStatement";
|
|
28
|
+
readonly ImportStatement: "ImportStatement";
|
|
29
|
+
readonly FromImportStatement: "FromImportStatement";
|
|
30
|
+
readonly BinaryExpression: "BinaryExpression";
|
|
31
|
+
readonly UnaryExpression: "UnaryExpression";
|
|
32
|
+
readonly CompareOp: "CompareOp";
|
|
33
|
+
readonly ParenthesizedExpression: "ParenthesizedExpression";
|
|
34
|
+
readonly ConditionalExpression: "ConditionalExpression";
|
|
35
|
+
readonly CallExpression: "CallExpression";
|
|
36
|
+
readonly MemberExpression: "MemberExpression";
|
|
37
|
+
readonly SubscriptExpression: "SubscriptExpression";
|
|
38
|
+
readonly Slice: "Slice";
|
|
39
|
+
readonly Number: "Number";
|
|
40
|
+
readonly String: "String";
|
|
41
|
+
readonly FormatString: "FormatString";
|
|
42
|
+
readonly True: "True";
|
|
43
|
+
readonly False: "False";
|
|
44
|
+
readonly None: "None";
|
|
45
|
+
readonly VariableName: "VariableName";
|
|
46
|
+
readonly ArrayExpression: "ArrayExpression";
|
|
47
|
+
readonly DictionaryExpression: "DictionaryExpression";
|
|
48
|
+
readonly SetExpression: "SetExpression";
|
|
49
|
+
readonly TupleExpression: "TupleExpression";
|
|
50
|
+
readonly ListComprehension: "ListComprehension";
|
|
51
|
+
readonly DictionaryComprehension: "DictionaryComprehension";
|
|
52
|
+
readonly SetComprehension: "SetComprehension";
|
|
53
|
+
readonly GeneratorExpression: "GeneratorExpression";
|
|
54
|
+
readonly ArithOp: "ArithOp";
|
|
55
|
+
readonly CompareOp_: "CompareOp";
|
|
56
|
+
readonly AssignOp: "AssignOp";
|
|
57
|
+
readonly ArgList: "ArgList";
|
|
58
|
+
readonly ParamList: "ParamList";
|
|
59
|
+
readonly LambdaExpression: "LambdaExpression";
|
|
60
|
+
readonly Comment: "Comment";
|
|
61
|
+
readonly Keyword: "Keyword";
|
|
62
|
+
readonly Body: "Body";
|
|
63
|
+
};
|
|
64
|
+
type NodeType = (typeof NodeTypes)[keyof typeof NodeTypes];
|
|
65
|
+
|
|
66
|
+
declare function parse(source: string): ParseResult;
|
|
67
|
+
declare function getNodeText(node: SyntaxNode, source: string): string;
|
|
68
|
+
declare function getChildren(node: SyntaxNode): SyntaxNode[];
|
|
69
|
+
declare function getChildByType(node: SyntaxNode, type: string): SyntaxNode | null;
|
|
70
|
+
declare function getChildrenByType(node: SyntaxNode, type: string): SyntaxNode[];
|
|
71
|
+
declare function walkTree(tree: Tree, callback: (node: SyntaxNode) => void): void;
|
|
72
|
+
declare function debugTree(tree: Tree, source: string): string;
|
|
73
|
+
|
|
74
|
+
interface TransformContext {
|
|
75
|
+
source: string;
|
|
76
|
+
indentLevel: number;
|
|
77
|
+
usesRuntime: Set<string>;
|
|
78
|
+
/** Stack of scopes - each scope is a set of variable names declared in that scope */
|
|
79
|
+
scopeStack: Set<string>[];
|
|
80
|
+
/** Set of class names defined in this module (for adding 'new' on instantiation) */
|
|
81
|
+
definedClasses: Set<string>;
|
|
82
|
+
/** Whether currently processing an abstract class (ABC) */
|
|
83
|
+
isAbstractClass?: boolean;
|
|
84
|
+
}
|
|
85
|
+
interface TransformResult {
|
|
86
|
+
code: string;
|
|
87
|
+
usesRuntime: Set<string>;
|
|
88
|
+
}
|
|
89
|
+
declare function transform(input: string | ParseResult): TransformResult;
|
|
90
|
+
|
|
91
|
+
interface GeneratorOptions {
|
|
92
|
+
includeRuntime?: boolean;
|
|
93
|
+
runtimeImportPath?: string;
|
|
94
|
+
}
|
|
95
|
+
interface GeneratedCode {
|
|
96
|
+
code: string;
|
|
97
|
+
runtimeImport: string | null;
|
|
98
|
+
usedRuntimeFunctions: string[];
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generate TypeScript code from Python (sync, unformatted)
|
|
102
|
+
* For formatted output, use generateAsync()
|
|
103
|
+
*/
|
|
104
|
+
declare function generate(input: string | ParseResult, options?: GeneratorOptions): GeneratedCode;
|
|
105
|
+
/**
|
|
106
|
+
* Transpile Python to TypeScript (sync, unformatted)
|
|
107
|
+
* For formatted output, use transpileAsync()
|
|
108
|
+
*/
|
|
109
|
+
declare function transpile(python: string, options?: GeneratorOptions): string;
|
|
110
|
+
/**
|
|
111
|
+
* Format TypeScript code using Prettier
|
|
112
|
+
*/
|
|
113
|
+
declare function formatCode(code: string): Promise<string>;
|
|
114
|
+
/**
|
|
115
|
+
* Generate TypeScript code from Python (async, formatted with Prettier)
|
|
116
|
+
*/
|
|
117
|
+
declare function generateAsync(input: string | ParseResult, options?: GeneratorOptions): Promise<GeneratedCode>;
|
|
118
|
+
/**
|
|
119
|
+
* Transpile Python to TypeScript (async, formatted with Prettier)
|
|
120
|
+
*/
|
|
121
|
+
declare function transpileAsync(python: string, options?: GeneratorOptions): Promise<string>;
|
|
122
|
+
|
|
123
|
+
export { type GeneratedCode, type GeneratorOptions, type NodeType, type NodeVisitor, type ParseResult, type TransformContext, type TransformResult, debugTree, formatCode, generate, generateAsync, getChildByType, getChildren, getChildrenByType, getNodeText, parse, transform, transpile, transpileAsync, walkTree };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
debugTree,
|
|
3
|
+
formatCode,
|
|
4
|
+
generate,
|
|
5
|
+
generateAsync,
|
|
6
|
+
getChildByType,
|
|
7
|
+
getChildren,
|
|
8
|
+
getChildrenByType,
|
|
9
|
+
getNodeText,
|
|
10
|
+
parse,
|
|
11
|
+
transform,
|
|
12
|
+
transpile,
|
|
13
|
+
transpileAsync,
|
|
14
|
+
walkTree
|
|
15
|
+
} from "./chunk-DTI6R2GT.js";
|
|
16
|
+
import "./chunk-PZ5AY32C.js";
|
|
17
|
+
|
|
18
|
+
// src/index.ts
|
|
19
|
+
import { py } from "pythonlib";
|
|
20
|
+
export {
|
|
21
|
+
debugTree,
|
|
22
|
+
formatCode,
|
|
23
|
+
generate,
|
|
24
|
+
generateAsync,
|
|
25
|
+
getChildByType,
|
|
26
|
+
getChildren,
|
|
27
|
+
getChildrenByType,
|
|
28
|
+
getNodeText,
|
|
29
|
+
parse,
|
|
30
|
+
py,
|
|
31
|
+
transform,
|
|
32
|
+
transpile,
|
|
33
|
+
transpileAsync,
|
|
34
|
+
walkTree
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export {\n parse,\n debugTree,\n getNodeText,\n getChildren,\n getChildByType,\n getChildrenByType,\n walkTree\n} from \"./parser/index.js\"\nexport type { ParseResult, NodeVisitor, NodeType } from \"./parser/index.js\"\n\nexport { transform, type TransformResult, type TransformContext } from \"./transformer/index.js\"\n\nexport {\n generate,\n generateAsync,\n transpile,\n transpileAsync,\n formatCode,\n type GeneratorOptions,\n type GeneratedCode\n} from \"./generator/index.js\"\n\n// Re-export pythonlib runtime for convenience\nexport { py } from \"pythonlib\"\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,SAAS,UAAU;","names":[]}
|