jsxpression 0.1.28 → 0.1.31

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.
Files changed (141) hide show
  1. package/README.md +155 -188
  2. package/lib/analyze/analysis-report.d.ts +2 -2
  3. package/lib/analyze/analysis-report.d.ts.map +1 -1
  4. package/lib/analyze/analysis-report.js +4 -0
  5. package/lib/analyze/analysis-report.js.map +1 -1
  6. package/lib/analyze/data/data-access.d.ts.map +1 -1
  7. package/lib/analyze/data/data-access.js +45 -82
  8. package/lib/analyze/data/data-access.js.map +1 -1
  9. package/lib/analyze/data/method-calls.d.ts.map +1 -1
  10. package/lib/analyze/data/method-calls.js +4 -3
  11. package/lib/analyze/data/method-calls.js.map +1 -1
  12. package/lib/analyze/data/utils.d.ts +2 -3
  13. package/lib/analyze/data/utils.d.ts.map +1 -1
  14. package/lib/analyze/data/utils.js +10 -36
  15. package/lib/analyze/data/utils.js.map +1 -1
  16. package/lib/analyze/jsx/element-attributes.d.ts +1 -1
  17. package/lib/analyze/jsx/element-attributes.d.ts.map +1 -1
  18. package/lib/analyze/jsx/element-attributes.js +13 -3
  19. package/lib/analyze/jsx/element-attributes.js.map +1 -1
  20. package/lib/analyze/jsx/element-children.d.ts +1 -1
  21. package/lib/analyze/jsx/element-children.d.ts.map +1 -1
  22. package/lib/analyze/jsx/element-children.js +16 -5
  23. package/lib/analyze/jsx/element-children.js.map +1 -1
  24. package/lib/analyze/jsx/element-tags.d.ts +1 -1
  25. package/lib/analyze/jsx/element-tags.d.ts.map +1 -1
  26. package/lib/analyze/jsx/element-tags.js +12 -2
  27. package/lib/analyze/jsx/element-tags.js.map +1 -1
  28. package/lib/analyze/security/analyze.d.ts.map +1 -1
  29. package/lib/analyze/security/analyze.js +2 -4
  30. package/lib/analyze/security/analyze.js.map +1 -1
  31. package/lib/analyze/security/call-expressions.d.ts +2 -2
  32. package/lib/analyze/security/call-expressions.d.ts.map +1 -1
  33. package/lib/analyze/security/call-expressions.js +21 -5
  34. package/lib/analyze/security/call-expressions.js.map +1 -1
  35. package/lib/analyze/security/declarations.d.ts +1 -1
  36. package/lib/analyze/security/declarations.d.ts.map +1 -1
  37. package/lib/analyze/security/declarations.js +22 -2
  38. package/lib/analyze/security/declarations.js.map +1 -1
  39. package/lib/analyze/security/expressions.d.ts.map +1 -1
  40. package/lib/analyze/security/expressions.js +10 -2
  41. package/lib/analyze/security/expressions.js.map +1 -1
  42. package/lib/analyze/security/identifiers.d.ts +2 -2
  43. package/lib/analyze/security/identifiers.d.ts.map +1 -1
  44. package/lib/analyze/security/identifiers.js +159 -19
  45. package/lib/analyze/security/identifiers.js.map +1 -1
  46. package/lib/builtins.d.ts.map +1 -1
  47. package/lib/builtins.js +5 -0
  48. package/lib/builtins.js.map +1 -1
  49. package/lib/codegen/builtins/builtin-types.d.ts.map +1 -1
  50. package/lib/codegen/builtins/builtin-types.js +7 -1
  51. package/lib/codegen/builtins/builtin-types.js.map +1 -1
  52. package/lib/compile/compile.d.ts.map +1 -1
  53. package/lib/compile/compile.js +131 -61
  54. package/lib/compile/compile.js.map +1 -1
  55. package/lib/evaluate/evaluate.d.ts +3 -3
  56. package/lib/evaluate/evaluate.d.ts.map +1 -1
  57. package/lib/evaluate/evaluate.js +28 -7
  58. package/lib/evaluate/evaluate.js.map +1 -1
  59. package/lib/jsx.d.ts +2 -19
  60. package/lib/jsx.d.ts.map +1 -1
  61. package/lib/jsx.js +0 -6
  62. package/lib/jsx.js.map +1 -1
  63. package/lib/parse/parse.d.ts.map +1 -1
  64. package/lib/parse/parse.js +4 -3
  65. package/lib/parse/parse.js.map +1 -1
  66. package/lib/render.d.ts +4 -4
  67. package/lib/render.d.ts.map +1 -1
  68. package/lib/render.js +7 -9
  69. package/lib/render.js.map +1 -1
  70. package/lib/schema.d.ts +2 -7
  71. package/lib/schema.d.ts.map +1 -1
  72. package/lib/schema.js +0 -43
  73. package/lib/schema.js.map +1 -1
  74. package/lib/traverse.d.ts +4 -4
  75. package/lib/traverse.d.ts.map +1 -1
  76. package/lib/traverse.js +118 -40
  77. package/lib/traverse.js.map +1 -1
  78. package/lib/validate.d.ts +1 -1
  79. package/lib/validate.js +1 -1
  80. package/package.json +4 -3
  81. package/src/analyze/analysis-report.ts +6 -2
  82. package/src/analyze/analyze.test.ts +108 -69
  83. package/src/analyze/data/data-access.ts +45 -90
  84. package/src/analyze/data/method-calls.ts +4 -3
  85. package/src/analyze/data/utils.ts +11 -40
  86. package/src/analyze/jsx/element-attributes.ts +24 -9
  87. package/src/analyze/jsx/element-children.ts +20 -6
  88. package/src/analyze/jsx/element-tags.ts +15 -3
  89. package/src/analyze/security/analyze.ts +1 -3
  90. package/src/analyze/security/call-expressions.ts +37 -17
  91. package/src/analyze/security/declarations.ts +35 -9
  92. package/src/analyze/security/expressions.ts +17 -3
  93. package/src/analyze/security/identifiers.ts +172 -28
  94. package/src/builtins.ts +6 -0
  95. package/src/codegen/builtins/builtin-types.ts +7 -1
  96. package/src/codegen/generate-typescript-definitions.test.ts +16 -23
  97. package/src/compile/compile.test.ts +153 -30
  98. package/src/compile/compile.ts +163 -73
  99. package/src/evaluate/evaluate.test.ts +276 -14
  100. package/src/evaluate/evaluate.ts +34 -10
  101. package/src/jsx.ts +2 -31
  102. package/src/parse/parse.test.ts +4 -4
  103. package/src/parse/parse.ts +4 -3
  104. package/src/render.test.ts +476 -27
  105. package/src/render.ts +7 -14
  106. package/src/schema.ts +1 -55
  107. package/src/traverse.ts +135 -49
  108. package/src/validate.ts +1 -1
  109. package/LICENSE +0 -21
  110. package/lib/analyze/analyze.test.d.ts +0 -2
  111. package/lib/analyze/analyze.test.d.ts.map +0 -1
  112. package/lib/analyze/analyze.test.js +0 -763
  113. package/lib/analyze/analyze.test.js.map +0 -1
  114. package/lib/analyze/security/member-access.d.ts +0 -6
  115. package/lib/codegen/generate-typescript-definitions.test.d.ts +0 -2
  116. package/lib/codegen/generate-typescript-definitions.test.d.ts.map +0 -1
  117. package/lib/codegen/generate-typescript-definitions.test.js +0 -649
  118. package/lib/codegen/generate-typescript-definitions.test.js.map +0 -1
  119. package/lib/compile/compile.test.d.ts +0 -2
  120. package/lib/compile/compile.test.d.ts.map +0 -1
  121. package/lib/compile/compile.test.js +0 -146
  122. package/lib/compile/compile.test.js.map +0 -1
  123. package/lib/evaluate/evaluate.test.d.ts +0 -2
  124. package/lib/evaluate/evaluate.test.d.ts.map +0 -1
  125. package/lib/evaluate/evaluate.test.js +0 -260
  126. package/lib/evaluate/evaluate.test.js.map +0 -1
  127. package/lib/parse/parse.test.d.ts +0 -2
  128. package/lib/parse/parse.test.d.ts.map +0 -1
  129. package/lib/parse/parse.test.js +0 -80
  130. package/lib/parse/parse.test.js.map +0 -1
  131. package/lib/render.test.d.ts +0 -2
  132. package/lib/render.test.d.ts.map +0 -1
  133. package/lib/render.test.js +0 -301
  134. package/lib/render.test.js.map +0 -1
  135. package/lib/traverse.test.d.ts +0 -2
  136. package/lib/traverse.test.d.ts.map +0 -1
  137. package/lib/traverse.test.js +0 -84
  138. package/lib/traverse.test.js.map +0 -1
  139. package/lib/types.d.ts +0 -12
  140. package/src/analyze/security/member-access.ts +0 -35
  141. 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
- export function getOptionalAttributes(schema: Schema, tagName: string): string[] {
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 { simple, base, SimpleVisitors, RecursiveVisitors } from "acorn-walk";
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
- export function traverse(ast: Program, visitors: Partial<ExtendedSimpleVisitors>): void {
37
- simple(ast, visitors, {
38
- ...base,
39
- JSXAttribute(node, state, visit) {
40
- if (node.value) {
41
- visit(node.value, state);
42
- }
43
- },
44
- JSXElement(node, state, visit) {
45
- const { openingElement } = node;
46
- if (openingElement && Array.isArray(openingElement.attributes)) {
47
- for (const attribute of openingElement.attributes) {
48
- visit(attribute, state);
49
- }
50
- }
51
- for (const child of node.children) {
52
- if (!isJsxText(child)) {
53
- visit(child, state);
54
- }
55
- }
56
- },
57
- JSXExpressionContainer(node, state, visit) {
58
- if (!isJsxEmptyExpression(node.expression)) {
59
- visit(node.expression, state);
60
- }
61
- },
62
- JSXFragment(node, state, visit) {
63
- for (const child of node.children) {
64
- if (!isJsxText(child)) {
65
- visit(child, state);
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
- JSXOpeningElement(node, state, visit) {
70
- for (const attribute of node.attributes) {
71
- visit(attribute, state);
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
- JSXSpreadAttribute(node, state, visit) {
75
- visit(node.argument, state);
76
- },
77
- } as ExtendedRecursiveVisitors);
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>{data.user.name}</Text>", schema);
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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=analyze.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"analyze.test.d.ts","sourceRoot":"","sources":["../../src/analyze/analyze.test.ts"],"names":[],"mappings":""}