jsxpression 0.1.28 → 0.1.29
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 +155 -188
- package/lib/analyze/analysis-report.d.ts +2 -2
- package/lib/analyze/analysis-report.d.ts.map +1 -1
- package/lib/analyze/analysis-report.js +4 -0
- package/lib/analyze/analysis-report.js.map +1 -1
- package/lib/analyze/data/data-access.d.ts.map +1 -1
- package/lib/analyze/data/data-access.js +45 -82
- package/lib/analyze/data/data-access.js.map +1 -1
- package/lib/analyze/data/method-calls.d.ts.map +1 -1
- package/lib/analyze/data/method-calls.js +4 -3
- package/lib/analyze/data/method-calls.js.map +1 -1
- package/lib/analyze/data/utils.d.ts +2 -3
- package/lib/analyze/data/utils.d.ts.map +1 -1
- package/lib/analyze/data/utils.js +10 -36
- package/lib/analyze/data/utils.js.map +1 -1
- package/lib/analyze/jsx/element-attributes.d.ts +1 -1
- package/lib/analyze/jsx/element-attributes.d.ts.map +1 -1
- package/lib/analyze/jsx/element-attributes.js +13 -3
- package/lib/analyze/jsx/element-attributes.js.map +1 -1
- package/lib/analyze/jsx/element-children.d.ts +1 -1
- package/lib/analyze/jsx/element-children.d.ts.map +1 -1
- package/lib/analyze/jsx/element-children.js +16 -5
- package/lib/analyze/jsx/element-children.js.map +1 -1
- package/lib/analyze/jsx/element-tags.d.ts +1 -1
- package/lib/analyze/jsx/element-tags.d.ts.map +1 -1
- package/lib/analyze/jsx/element-tags.js +12 -2
- package/lib/analyze/jsx/element-tags.js.map +1 -1
- package/lib/analyze/security/analyze.d.ts.map +1 -1
- package/lib/analyze/security/analyze.js +2 -4
- package/lib/analyze/security/analyze.js.map +1 -1
- package/lib/analyze/security/call-expressions.d.ts +2 -2
- package/lib/analyze/security/call-expressions.d.ts.map +1 -1
- package/lib/analyze/security/call-expressions.js +21 -5
- package/lib/analyze/security/call-expressions.js.map +1 -1
- package/lib/analyze/security/declarations.d.ts +1 -1
- package/lib/analyze/security/declarations.d.ts.map +1 -1
- package/lib/analyze/security/declarations.js +22 -2
- package/lib/analyze/security/declarations.js.map +1 -1
- package/lib/analyze/security/expressions.d.ts.map +1 -1
- package/lib/analyze/security/expressions.js +10 -2
- package/lib/analyze/security/expressions.js.map +1 -1
- package/lib/analyze/security/identifiers.d.ts +2 -2
- package/lib/analyze/security/identifiers.d.ts.map +1 -1
- package/lib/analyze/security/identifiers.js +159 -19
- package/lib/analyze/security/identifiers.js.map +1 -1
- package/lib/builtins.d.ts.map +1 -1
- package/lib/builtins.js +5 -0
- package/lib/builtins.js.map +1 -1
- package/lib/compile/compile.d.ts.map +1 -1
- package/lib/compile/compile.js +131 -61
- package/lib/compile/compile.js.map +1 -1
- package/lib/evaluate/evaluate.d.ts +3 -3
- package/lib/evaluate/evaluate.d.ts.map +1 -1
- package/lib/evaluate/evaluate.js +28 -7
- package/lib/evaluate/evaluate.js.map +1 -1
- package/lib/jsx.d.ts +2 -19
- package/lib/jsx.d.ts.map +1 -1
- package/lib/jsx.js +0 -6
- package/lib/jsx.js.map +1 -1
- package/lib/parse/parse.d.ts.map +1 -1
- package/lib/parse/parse.js +4 -3
- package/lib/parse/parse.js.map +1 -1
- package/lib/render.d.ts +4 -4
- package/lib/render.d.ts.map +1 -1
- package/lib/render.js +7 -9
- package/lib/render.js.map +1 -1
- package/lib/schema.d.ts +2 -7
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +0 -43
- package/lib/schema.js.map +1 -1
- package/lib/traverse.d.ts +4 -4
- package/lib/traverse.d.ts.map +1 -1
- package/lib/traverse.js +118 -40
- package/lib/traverse.js.map +1 -1
- package/lib/validate.d.ts +1 -1
- package/lib/validate.js +1 -1
- package/package.json +4 -3
- package/src/analyze/analysis-report.ts +6 -2
- package/src/analyze/analyze.test.ts +108 -69
- package/src/analyze/data/data-access.ts +45 -90
- package/src/analyze/data/method-calls.ts +4 -3
- package/src/analyze/data/utils.ts +11 -40
- package/src/analyze/jsx/element-attributes.ts +24 -9
- package/src/analyze/jsx/element-children.ts +20 -6
- package/src/analyze/jsx/element-tags.ts +15 -3
- package/src/analyze/security/analyze.ts +1 -3
- package/src/analyze/security/call-expressions.ts +37 -17
- package/src/analyze/security/declarations.ts +35 -9
- package/src/analyze/security/expressions.ts +17 -3
- package/src/analyze/security/identifiers.ts +172 -28
- package/src/builtins.ts +6 -0
- package/src/codegen/generate-typescript-definitions.test.ts +16 -23
- package/src/compile/compile.test.ts +153 -30
- package/src/compile/compile.ts +163 -73
- package/src/evaluate/evaluate.test.ts +276 -14
- package/src/evaluate/evaluate.ts +34 -10
- package/src/jsx.ts +2 -31
- package/src/parse/parse.test.ts +4 -4
- package/src/parse/parse.ts +4 -3
- package/src/render.test.ts +476 -27
- package/src/render.ts +7 -14
- package/src/schema.ts +1 -55
- package/src/traverse.ts +135 -49
- package/src/validate.ts +1 -1
- package/LICENSE +0 -21
- package/lib/analyze/analyze.test.d.ts +0 -2
- package/lib/analyze/analyze.test.d.ts.map +0 -1
- package/lib/analyze/analyze.test.js +0 -763
- package/lib/analyze/analyze.test.js.map +0 -1
- package/lib/analyze/security/member-access.d.ts +0 -6
- package/lib/codegen/generate-typescript-definitions.test.d.ts +0 -2
- package/lib/codegen/generate-typescript-definitions.test.d.ts.map +0 -1
- package/lib/codegen/generate-typescript-definitions.test.js +0 -649
- package/lib/codegen/generate-typescript-definitions.test.js.map +0 -1
- package/lib/compile/compile.test.d.ts +0 -2
- package/lib/compile/compile.test.d.ts.map +0 -1
- package/lib/compile/compile.test.js +0 -146
- package/lib/compile/compile.test.js.map +0 -1
- package/lib/evaluate/evaluate.test.d.ts +0 -2
- package/lib/evaluate/evaluate.test.d.ts.map +0 -1
- package/lib/evaluate/evaluate.test.js +0 -260
- package/lib/evaluate/evaluate.test.js.map +0 -1
- package/lib/parse/parse.test.d.ts +0 -2
- package/lib/parse/parse.test.d.ts.map +0 -1
- package/lib/parse/parse.test.js +0 -80
- package/lib/parse/parse.test.js.map +0 -1
- package/lib/render.test.d.ts +0 -2
- package/lib/render.test.d.ts.map +0 -1
- package/lib/render.test.js +0 -301
- package/lib/render.test.js.map +0 -1
- package/lib/traverse.test.d.ts +0 -2
- package/lib/traverse.test.d.ts.map +0 -1
- package/lib/traverse.test.js +0 -84
- package/lib/traverse.test.js.map +0 -1
- package/lib/types.d.ts +0 -12
- package/src/analyze/security/member-access.ts +0 -35
- package/src/types.ts +0 -17
package/src/schema.ts
CHANGED
|
@@ -126,10 +126,6 @@ export function getAllElements(schema: Schema): string[] {
|
|
|
126
126
|
return schema.elements ? Object.keys(schema.elements) : [];
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
export function getElementConfig(schema: Schema, tagName: string): ElementSchema | undefined {
|
|
130
|
-
return getElementSchema(schema, tagName);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
129
|
export function getAttributeSchema(schema: Schema, tagName: string, attributeName: string): PropertySchema | undefined {
|
|
134
130
|
const elementSchema = getElementSchema(schema, tagName);
|
|
135
131
|
return elementSchema?.props?.[attributeName];
|
|
@@ -151,57 +147,7 @@ export function getRequiredAttributes(schema: Schema, tagName: string): string[]
|
|
|
151
147
|
return required;
|
|
152
148
|
}
|
|
153
149
|
|
|
154
|
-
|
|
155
|
-
const allAttributes = getAllowedAttributes(schema, tagName);
|
|
156
|
-
const requiredAttributes = getRequiredAttributes(schema, tagName);
|
|
157
|
-
return allAttributes.filter((attr) => !requiredAttributes.includes(attr));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function isAttributeRequired(schema: Schema, tagName: string, attributeName: string): boolean {
|
|
161
|
-
const requiredAttributes = getRequiredAttributes(schema, tagName);
|
|
162
|
-
return requiredAttributes.includes(attributeName);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export function getDataSchema(schema: Schema): Record<string, PropertySchema> | undefined {
|
|
166
|
-
return schema.data;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function getPropertyAtPath(schema: Schema, path: string[]): PropertySchema | undefined {
|
|
170
|
-
if (!schema.data || path.length === 0) {
|
|
171
|
-
return undefined;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
let current: PropertySchema | undefined = path[0] !== undefined ? schema.data[path[0]] : undefined;
|
|
175
|
-
|
|
176
|
-
for (let i = 1; i < path.length && current; i++) {
|
|
177
|
-
if (current.type === "object" && current.shape) {
|
|
178
|
-
current = current.shape[path[i]!];
|
|
179
|
-
} else {
|
|
180
|
-
return undefined;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return current;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function getAvailablePropertiesAtPath(schema: Schema, path: string[]): string[] {
|
|
188
|
-
if (!schema.data) {
|
|
189
|
-
return [];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (path.length === 0) {
|
|
193
|
-
return Object.keys(schema.data);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const parentProperty = getPropertyAtPath(schema, path);
|
|
197
|
-
if (parentProperty?.type === "object" && parentProperty.shape) {
|
|
198
|
-
return Object.keys(parentProperty.shape);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return [];
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export type PropertyEnumValue = string | number | boolean;
|
|
150
|
+
type PropertyEnumValue = string | number | boolean;
|
|
205
151
|
|
|
206
152
|
export function getEnumValues(property: PropertySchema): readonly PropertyEnumValue[] | undefined {
|
|
207
153
|
switch (property.type) {
|
package/src/traverse.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { Program } from "acorn";
|
|
2
|
-
import {
|
|
1
|
+
import type { Program } from "acorn";
|
|
2
|
+
import { base, type RecursiveVisitors, type SimpleVisitors, simple } from "acorn-walk";
|
|
3
3
|
import {
|
|
4
|
-
JSXAttribute,
|
|
5
|
-
JSXElement,
|
|
6
|
-
JSXExpressionContainer,
|
|
7
|
-
JSXFragment,
|
|
8
|
-
JSXOpeningElement,
|
|
9
|
-
JSXSpreadAttribute,
|
|
10
|
-
isJsxText,
|
|
11
4
|
isJsxEmptyExpression,
|
|
5
|
+
isJsxText,
|
|
6
|
+
type JSXAttribute,
|
|
7
|
+
type JSXElement,
|
|
8
|
+
type JSXExpressionContainer,
|
|
9
|
+
type JSXFragment,
|
|
10
|
+
type JSXOpeningElement,
|
|
11
|
+
type JSXSpreadAttribute,
|
|
12
12
|
} from "./jsx.js";
|
|
13
13
|
|
|
14
14
|
type Visit = (node: unknown, state: unknown) => void;
|
|
@@ -33,46 +33,132 @@ type ExtendedSimpleVisitors = SimpleVisitors<unknown> & {
|
|
|
33
33
|
JSXSpreadAttribute?: SimpleVisitor<JSXSpreadAttribute>;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
36
|
+
const tsNodeTypes = [
|
|
37
|
+
"TSInterfaceDeclaration",
|
|
38
|
+
"TSInterfaceBody",
|
|
39
|
+
"TSTypeAliasDeclaration",
|
|
40
|
+
"TSTypeAnnotation",
|
|
41
|
+
"TSTypeReference",
|
|
42
|
+
"TSTypeParameterDeclaration",
|
|
43
|
+
"TSTypeParameterInstantiation",
|
|
44
|
+
"TSTypeParameter",
|
|
45
|
+
"TSAsExpression",
|
|
46
|
+
"TSSatisfiesExpression",
|
|
47
|
+
"TSNonNullExpression",
|
|
48
|
+
"TSTypeAssertion",
|
|
49
|
+
"TSEnumDeclaration",
|
|
50
|
+
"TSEnumMember",
|
|
51
|
+
"TSModuleDeclaration",
|
|
52
|
+
"TSModuleBlock",
|
|
53
|
+
"TSImportEqualsDeclaration",
|
|
54
|
+
"TSExportAssignment",
|
|
55
|
+
"TSNamespaceExportDeclaration",
|
|
56
|
+
"TSDeclareFunction",
|
|
57
|
+
"TSDeclareMethod",
|
|
58
|
+
"TSExternalModuleReference",
|
|
59
|
+
"TSInstantiationExpression",
|
|
60
|
+
"TSTypeCastExpression",
|
|
61
|
+
"TSParameterProperty",
|
|
62
|
+
"TSIndexSignature",
|
|
63
|
+
"TSCallSignatureDeclaration",
|
|
64
|
+
"TSConstructSignatureDeclaration",
|
|
65
|
+
"TSPropertySignature",
|
|
66
|
+
"TSMethodSignature",
|
|
67
|
+
"TSTypePredicate",
|
|
68
|
+
"TSTypeQuery",
|
|
69
|
+
"TSTypeLiteral",
|
|
70
|
+
"TSTypeOperator",
|
|
71
|
+
"TSMappedType",
|
|
72
|
+
"TSConditionalType",
|
|
73
|
+
"TSInferType",
|
|
74
|
+
"TSImportType",
|
|
75
|
+
"TSExpressionWithTypeArguments",
|
|
76
|
+
"TSQualifiedName",
|
|
77
|
+
"TSFunctionType",
|
|
78
|
+
"TSConstructorType",
|
|
79
|
+
"TSUnionType",
|
|
80
|
+
"TSIntersectionType",
|
|
81
|
+
"TSTupleType",
|
|
82
|
+
"TSNamedTupleMember",
|
|
83
|
+
"TSArrayType",
|
|
84
|
+
"TSOptionalType",
|
|
85
|
+
"TSRestType",
|
|
86
|
+
"TSLiteralType",
|
|
87
|
+
"TSIndexedAccessType",
|
|
88
|
+
"TSParenthesizedType",
|
|
89
|
+
"TSAnyKeyword",
|
|
90
|
+
"TSBooleanKeyword",
|
|
91
|
+
"TSBigIntKeyword",
|
|
92
|
+
"TSNeverKeyword",
|
|
93
|
+
"TSNullKeyword",
|
|
94
|
+
"TSNumberKeyword",
|
|
95
|
+
"TSObjectKeyword",
|
|
96
|
+
"TSStringKeyword",
|
|
97
|
+
"TSSymbolKeyword",
|
|
98
|
+
"TSUndefinedKeyword",
|
|
99
|
+
"TSUnknownKeyword",
|
|
100
|
+
"TSVoidKeyword",
|
|
101
|
+
"TSThisType",
|
|
102
|
+
] as const;
|
|
103
|
+
|
|
104
|
+
const tsWalkers: Record<string, (node: any, state: any, c: any) => void> = {};
|
|
105
|
+
for (const nodeType of tsNodeTypes) {
|
|
106
|
+
tsWalkers[nodeType] = () => {};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const jsxWalkers: ExtendedRecursiveVisitors = {
|
|
110
|
+
JSXElement(node, state, visit) {
|
|
111
|
+
const element = node as JSXElement;
|
|
112
|
+
visit(element.openingElement, state);
|
|
113
|
+
for (const child of element.children) {
|
|
114
|
+
if (isJsxText(child) || isJsxEmptyExpression(child)) {
|
|
115
|
+
continue;
|
|
67
116
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
117
|
+
visit(child as any, state);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
JSXFragment(node, state, visit) {
|
|
122
|
+
const fragment = node as JSXFragment;
|
|
123
|
+
for (const child of fragment.children) {
|
|
124
|
+
if (isJsxText(child) || isJsxEmptyExpression(child)) {
|
|
125
|
+
continue;
|
|
72
126
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
127
|
+
visit(child as any, state);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
JSXOpeningElement(node, state, visit) {
|
|
132
|
+
const opening = node as JSXOpeningElement;
|
|
133
|
+
for (const attr of opening.attributes) {
|
|
134
|
+
visit(attr as any, state);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
JSXAttribute(node, state, visit) {
|
|
139
|
+
const attr = node as JSXAttribute;
|
|
140
|
+
if (attr.value) {
|
|
141
|
+
visit(attr.value as any, state);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
JSXSpreadAttribute(node, state, visit) {
|
|
146
|
+
const spread = node as JSXSpreadAttribute;
|
|
147
|
+
visit(spread.argument as any, state);
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
JSXExpressionContainer(node, state, visit) {
|
|
151
|
+
const container = node as JSXExpressionContainer;
|
|
152
|
+
if (!isJsxEmptyExpression(container.expression)) {
|
|
153
|
+
visit(container.expression as any, state);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export function traverse(ast: Program, visitors: ExtendedSimpleVisitors): void {
|
|
159
|
+
simple(ast, visitors as SimpleVisitors<unknown>, {
|
|
160
|
+
...base,
|
|
161
|
+
...jsxWalkers,
|
|
162
|
+
...tsWalkers,
|
|
163
|
+
});
|
|
78
164
|
}
|
package/src/validate.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface ValidateOptions {
|
|
|
25
25
|
*
|
|
26
26
|
* @example
|
|
27
27
|
* ```typescript
|
|
28
|
-
* const result = validate("<Text>{
|
|
28
|
+
* const result = validate("<Text>{user.name}</Text>", schema);
|
|
29
29
|
* if (result.ok) {
|
|
30
30
|
* console.log("JSX is valid!");
|
|
31
31
|
* } else {
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Divid AB
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyze.test.d.ts","sourceRoot":"","sources":["../../src/analyze/analyze.test.ts"],"names":[],"mappings":""}
|