@tsrx/core 0.1.4 → 0.1.7

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/src/utils.js CHANGED
@@ -4,162 +4,9 @@
4
4
  */
5
5
 
6
6
  export { simple_hash, strong_hash } from './utils/hashing.js';
7
-
8
- const VOID_ELEMENT_NAMES = [
9
- 'area',
10
- 'base',
11
- 'br',
12
- 'col',
13
- 'command',
14
- 'embed',
15
- 'hr',
16
- 'img',
17
- 'input',
18
- 'keygen',
19
- 'link',
20
- 'meta',
21
- 'param',
22
- 'source',
23
- 'track',
24
- 'wbr',
25
- ];
26
-
27
- /**
28
- * Returns true if name is a void element
29
- * @param {string} name
30
- * @returns {boolean}
31
- */
32
- export function is_void_element(name) {
33
- return VOID_ELEMENT_NAMES.includes(name) || name.toLowerCase() === '!doctype';
34
- }
35
-
36
- const RESERVED_WORDS = [
37
- 'arguments',
38
- 'await',
39
- 'break',
40
- 'case',
41
- 'catch',
42
- 'class',
43
- 'const',
44
- 'continue',
45
- 'debugger',
46
- 'default',
47
- 'delete',
48
- 'do',
49
- 'else',
50
- 'enum',
51
- 'eval',
52
- 'export',
53
- 'extends',
54
- 'false',
55
- 'finally',
56
- 'for',
57
- 'function',
58
- 'if',
59
- 'implements',
60
- 'import',
61
- 'in',
62
- 'instanceof',
63
- 'interface',
64
- 'let',
65
- 'new',
66
- 'null',
67
- 'package',
68
- 'private',
69
- 'protected',
70
- 'public',
71
- 'return',
72
- 'static',
73
- 'super',
74
- 'switch',
75
- 'this',
76
- 'throw',
77
- 'true',
78
- 'try',
79
- 'typeof',
80
- 'var',
81
- 'void',
82
- 'while',
83
- 'with',
84
- 'yield',
85
- ];
86
-
87
- /**
88
- * Returns true if word is a reserved JS keyword
89
- * @param {string} word
90
- * @returns {boolean}
91
- */
92
- export function is_reserved(word) {
93
- return RESERVED_WORDS.includes(word);
94
- }
95
-
96
- /**
97
- * Attributes that are boolean, i.e. they are present or not present.
98
- */
99
- const DOM_BOOLEAN_ATTRIBUTES = [
100
- 'allowfullscreen',
101
- 'async',
102
- 'autofocus',
103
- 'autoplay',
104
- 'checked',
105
- 'controls',
106
- 'default',
107
- 'disabled',
108
- 'formnovalidate',
109
- 'hidden',
110
- 'indeterminate',
111
- 'inert',
112
- 'ismap',
113
- 'loop',
114
- 'multiple',
115
- 'muted',
116
- 'nomodule',
117
- 'novalidate',
118
- 'open',
119
- 'playsinline',
120
- 'readonly',
121
- 'required',
122
- 'reversed',
123
- 'seamless',
124
- 'selected',
125
- 'webkitdirectory',
126
- 'defer',
127
- 'disablepictureinpicture',
128
- 'disableremoteplayback',
129
- ];
130
-
131
- /**
132
- * Returns true if name is a boolean DOM attribute
133
- * @param {string} name
134
- * @returns {boolean}
135
- */
136
- export function is_boolean_attribute(name) {
137
- return DOM_BOOLEAN_ATTRIBUTES.includes(name);
138
- }
139
-
140
- const DOM_PROPERTIES = [
141
- ...DOM_BOOLEAN_ATTRIBUTES,
142
- 'formNoValidate',
143
- 'isMap',
144
- 'noModule',
145
- 'playsInline',
146
- 'readOnly',
147
- 'value',
148
- 'volume',
149
- 'defaultValue',
150
- 'defaultChecked',
151
- 'srcObject',
152
- 'noValidate',
153
- 'allowFullscreen',
154
- 'disablePictureInPicture',
155
- 'disableRemotePlayback',
156
- ];
157
-
158
- /**
159
- * Returns true if name is a DOM property
160
- * @param {string} name
161
- * @returns {boolean}
162
- */
163
- export function is_dom_property(name) {
164
- return DOM_PROPERTIES.includes(name);
165
- }
7
+ export {
8
+ is_boolean_attribute,
9
+ is_dom_property,
10
+ is_reserved,
11
+ is_void_element,
12
+ } from './utils/dom.js';
package/types/index.d.ts CHANGED
@@ -92,6 +92,7 @@ interface FunctionMetaData extends BaseNodeMetaData {
92
92
  is_component?: boolean;
93
93
  is_method?: boolean;
94
94
  tracked?: boolean;
95
+ has_lazy_descendants?: boolean;
95
96
  }
96
97
 
97
98
  // Strip parent, loc, and range from TSESTree nodes to match @sveltejs/acorn-typescript output
@@ -39,6 +39,8 @@ export interface JsxTransformContext {
39
39
  needs_ref_prop: boolean;
40
40
  needs_normalize_spread_props: boolean;
41
41
  needs_fragment: boolean;
42
+ needs_for_of_iterable: boolean;
43
+ needs_iteration_value_type: boolean;
42
44
  module_scoped_hook_components: boolean;
43
45
  helper_state: {
44
46
  base_name: string;
@@ -300,6 +302,16 @@ export interface JsxPlatform {
300
302
  * `prop={ref expr}` or normalizing host spreads containing named refs.
301
303
  */
302
304
  refProp?: string;
305
+ /**
306
+ * Module to import the `map_iterable` runtime helper (and the
307
+ * `IterationValue` type) from when compiling `for ... of` bodies whose
308
+ * source can be any `Iterable` — not just an array. React and Preact
309
+ * use target-owned paths like `'@tsrx/react/runtime/iterable'` and
310
+ * `'@tsrx/preact/runtime/iterable'`, which re-export from
311
+ * `'@tsrx/core/runtime/iterable'`. Solid and Vue lower for-of via their
312
+ * own iteration components and leave this unset.
313
+ */
314
+ forOfIterableHelper?: string;
303
315
  };
304
316
 
305
317
  jsx: {
@@ -0,0 +1,11 @@
1
+ export function event_name_from_capture(event_name: string): string;
2
+ export function get_attribute_event_name(
3
+ name: string,
4
+ handler: EventListener | { customName?: string },
5
+ ): string;
6
+ export function get_original_event_name(name: string): string;
7
+ export function is_capture_event(event_name: string): boolean;
8
+ export function is_event_attribute(attr: string): boolean;
9
+ export function is_non_delegated(event_name: string): boolean;
10
+ export function is_passive_event(name: string): boolean;
11
+ export function normalize_event_name(name: string): string;
@@ -0,0 +1,2 @@
1
+ export function simple_hash(str: string): string;
2
+ export function strong_hash(str: string): string;
@@ -0,0 +1,4 @@
1
+ export function escape<V>(value: V, is_attr?: boolean): string;
2
+ export function escape_script(str: string): string;
3
+ export function is_boolean_attribute(name: string): boolean;
4
+ export function normalize_css_property_name(str: string): string;
@@ -0,0 +1,13 @@
1
+ // Helper type for item in an array or iterable
2
+ // example: IterationValue<typeof something>
3
+ export type IterationValue<T> = T extends readonly unknown[]
4
+ ? T[number]
5
+ : T extends Iterable<infer U>
6
+ ? U
7
+ : never;
8
+
9
+ export function map_iterable<T, U>(
10
+ value: Iterable<T>,
11
+ fn: (item: T, index: number, is_last: boolean) => U,
12
+ tail?: () => U | U[],
13
+ ): U[];
@@ -0,0 +1,17 @@
1
+ export const get_descriptor: typeof Object.getOwnPropertyDescriptor;
2
+ export const get_descriptors: typeof Object.getOwnPropertyDescriptors;
3
+ export const array_from: typeof Array.from;
4
+ export const is_array: typeof Array.isArray;
5
+ export const define_property: typeof Object.defineProperty;
6
+ export const get_prototype_of: typeof Object.getPrototypeOf;
7
+ export const object_values: typeof Object.values;
8
+ export const object_entries: typeof Object.entries;
9
+ export const object_keys: typeof Object.keys;
10
+ export const get_own_property_symbols: typeof Object.getOwnPropertySymbols;
11
+ export const structured_clone: typeof structuredClone;
12
+ export const object_prototype: typeof Object.prototype;
13
+ export const array_prototype: typeof Array.prototype;
14
+ export const has_own_property: typeof Object.prototype.hasOwnProperty;
15
+
16
+ export function has_prototype_accessor(value: object, key: PropertyKey): boolean;
17
+ export function array_slice(array_like: ArrayLike<any>, ...args: number[]): any[];