@tsrx/vue 0.1.20 → 0.1.24

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Vue compiler built on @tsrx/core",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.1.20",
6
+ "version": "0.1.24",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -22,6 +22,10 @@
22
22
  "types": "./types/error-boundary.d.ts",
23
23
  "default": "./src/error-boundary.js"
24
24
  },
25
+ "./dynamic": {
26
+ "types": "./types/dynamic.d.ts",
27
+ "default": "./src/dynamic.js"
28
+ },
25
29
  "./interop": {
26
30
  "types": "./types/interop.d.ts",
27
31
  "default": "./src/interop.js"
@@ -35,7 +39,7 @@
35
39
  "esrap": "^2.2.8",
36
40
  "is-reference": "^3.0.3",
37
41
  "zimmerframe": "^1.1.2",
38
- "@tsrx/core": "0.1.20"
42
+ "@tsrx/core": "0.1.24"
39
43
  },
40
44
  "peerDependencies": {
41
45
  "vue": ">=3.5",
package/src/dynamic.js ADDED
@@ -0,0 +1,16 @@
1
+ import { exclude_prop_from_object } from '@tsrx/core/runtime/language-helpers';
2
+ import { createNodes, h } from 'vue-jsx-vapor';
3
+
4
+ /**
5
+ * @param {{ is?: any, [key: string]: any }} props
6
+ * @param {{ slots?: any }} [context]
7
+ * @returns {any}
8
+ */
9
+ export function Dynamic(props, context) {
10
+ return createNodes(() => {
11
+ const component = props?.is;
12
+ return component
13
+ ? h(component, exclude_prop_from_object(props, 'is'), context?.slots ?? props?.children)
14
+ : null;
15
+ });
16
+ }
package/src/index.js CHANGED
@@ -5,6 +5,7 @@ import { createVolarMappingsResult, dedupeMappings, parseModule } from '@tsrx/co
5
5
  import { transform } from './transform.js';
6
6
 
7
7
  export { isRefProp } from './ref.js';
8
+ export { Dynamic } from './dynamic.js';
8
9
 
9
10
  /**
10
11
  * Parse tsrx-vue source code to an ESTree AST.
package/src/transform.js CHANGED
@@ -33,13 +33,13 @@ const vue_platform = {
33
33
  name: 'Vue',
34
34
  imports: {
35
35
  suspense: 'vue',
36
+ dynamic: '@tsrx/vue/dynamic',
36
37
  errorBoundary: '@tsrx/vue/error-boundary',
37
38
  mergeRefs: '@tsrx/vue/ref',
38
39
  refProp: '@tsrx/vue/ref',
39
40
  },
40
41
  jsx: {
41
42
  rewriteClassAttr: false,
42
- acceptedTsxKinds: ['vue'],
43
43
  multiRefStrategy: 'merge-refs',
44
44
  hostSpreadRefStrategy: 'explicit-ref-attr',
45
45
  },
@@ -506,6 +506,10 @@ function create_define_vapor_component_call(fn_expression, generated_helpers, ge
506
506
  * @returns {any | null}
507
507
  */
508
508
  function render_for_of_as_vapor_for(node, loop_params, body_statements, transform_context) {
509
+ if (node.empty) {
510
+ return null;
511
+ }
512
+
509
513
  if (body_statements.length !== 1) {
510
514
  return null;
511
515
  }
@@ -0,0 +1,32 @@
1
+ import type { NativeElements } from 'vue-jsx-vapor';
2
+
3
+ type DynamicIntrinsicElements = NativeElements;
4
+
5
+ export type DynamicElementType =
6
+ | keyof DynamicIntrinsicElements
7
+ | ((props: any, ...args: any[]) => any)
8
+ | (new (...args: any[]) => { $props: any })
9
+ | (string & {});
10
+
11
+ type DynamicTarget<T> = Exclude<T, null | undefined | false>;
12
+ type DynamicComponentProps<T> = [T] extends [never]
13
+ ? Record<string, unknown>
14
+ : T extends new (...args: any[]) => { $props: infer P }
15
+ ? Omit<P, 'is'>
16
+ : T extends (props: infer P, ...args: any[]) => any
17
+ ? Omit<P, 'is'>
18
+ : T extends keyof DynamicIntrinsicElements
19
+ ? DynamicIntrinsicElements[T]
20
+ : Record<string, unknown>;
21
+
22
+ export type DynamicProps<T extends DynamicElementType> = DynamicComponentProps<
23
+ DynamicTarget<NoInfer<T>>
24
+ > & {
25
+ is: T | null | undefined | false;
26
+ };
27
+
28
+ export function Dynamic<T extends DynamicElementType>(
29
+ props: DynamicComponentProps<DynamicTarget<NoInfer<T>>> & {
30
+ is: T | null | undefined | false;
31
+ },
32
+ ): any;
package/types/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import type { CompileFn, ParseOptions, VolarCompileFn } from '@tsrx/core/types';
4
4
  export function parse(source: string, filename?: string, options?: ParseOptions): Program;
5
5
 
6
6
  export { isRefProp } from './ref.js';
7
+ export { Dynamic, type DynamicElementType, type DynamicProps } from './dynamic.js';
7
8
 
8
9
  export const compile: CompileFn;
9
10