ripple 0.2.96 → 0.2.98

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": "Ripple is an elegant TypeScript UI framework",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.2.96",
6
+ "version": "0.2.98",
7
7
  "type": "module",
8
8
  "module": "src/runtime/index-client.js",
9
9
  "main": "src/runtime/index-client.js",
@@ -1,3 +1,5 @@
1
+ /** @import {Expression, FunctionExpression} from 'estree' */
2
+
1
3
  import { walk } from 'zimmerframe';
2
4
  import path from 'node:path';
3
5
  import { print } from 'esrap';
@@ -195,6 +197,9 @@ const visitors = {
195
197
  },
196
198
 
197
199
  CallExpression(node, context) {
200
+ if (!context.state.to_ts) {
201
+ delete node.typeArguments;
202
+ }
198
203
  const callee = node.callee;
199
204
  const parent = context.path.at(-1);
200
205
 
@@ -407,29 +412,13 @@ const visitors = {
407
412
  },
408
413
 
409
414
  VariableDeclaration(node, context) {
410
- const declarations = [];
411
-
412
415
  for (const declarator of node.declarations) {
413
- const metadata = declarator.metadata;
414
-
415
- if (declarator.id.type === 'Identifier') {
416
- const binding = context.state.scope.get(declarator.id.name);
417
-
418
- if (!context.state.to_ts) {
419
- delete declarator.id.typeAnnotation;
420
- }
421
-
422
- declarations.push(context.visit(declarator));
423
- } else {
424
- if (!context.state.to_ts) {
425
- delete declarator.id.typeAnnotation;
426
- }
427
-
428
- declarations.push(context.visit(declarator));
416
+ if (!context.state.to_ts) {
417
+ delete declarator.id.typeAnnotation;
429
418
  }
430
419
  }
431
420
 
432
- return { ...node, declarations };
421
+ return context.next();
433
422
  },
434
423
 
435
424
  FunctionDeclaration(node, context) {
@@ -106,6 +106,45 @@ const visitors = {
106
106
  );
107
107
  },
108
108
 
109
+ CallExpression(node, context) {
110
+ if (!context.state.to_ts) {
111
+ delete node.typeArguments;
112
+ }
113
+ return context.next();
114
+ },
115
+
116
+ PropertyDefinition(node, context) {
117
+ if (!context.state.to_ts) {
118
+ delete node.typeAnnotation;
119
+ }
120
+ return context.next();
121
+ },
122
+
123
+ TSAsExpression(node, context) {
124
+ if (!context.state.to_ts) {
125
+ return context.visit(node.expression);
126
+ }
127
+ return context.next();
128
+ },
129
+
130
+ ExportNamedDeclaration(node, context) {
131
+ if (!context.state.to_ts && node.exportKind === 'type') {
132
+ return b.empty;
133
+ }
134
+
135
+ return context.next();
136
+ },
137
+
138
+ VariableDeclaration(node, context) {
139
+ for (const declarator of node.declarations) {
140
+ if (!context.state.to_ts) {
141
+ delete declarator.id.typeAnnotation;
142
+ }
143
+ }
144
+
145
+ return context.next();
146
+ },
147
+
109
148
  Element(node, context) {
110
149
  const { state, visit } = context;
111
150
 
@@ -40,7 +40,7 @@ export function mount(component, options) {
40
40
  };
41
41
  }
42
42
 
43
- export { create_context as createContext } from './internal/client/context.js';
43
+ export { Context } from './internal/client/context.js';
44
44
 
45
45
  export {
46
46
  flush_sync as flushSync,
@@ -4,7 +4,7 @@ import { DERIVED, TRACKED, UNINITIALIZED } from './internal/client/constants.js'
4
4
  import { is_tracked_object } from './internal/client/utils.js';
5
5
  import { active_component } from './internal/server/index.js';
6
6
 
7
- export { create_context as createContext } from './internal/server/context.js';
7
+ export { Context } from './internal/server/context.js';
8
8
 
9
9
  export function effect() {
10
10
  // NO-OP
@@ -44,4 +44,3 @@ export function track(v, get, set) {
44
44
  v,
45
45
  };
46
46
  }
47
-
@@ -58,12 +58,3 @@ export class Context {
58
58
  current_context.set(context, value);
59
59
  }
60
60
  }
61
-
62
- /**
63
- * @template T
64
- * @param {T} initial_value
65
- * @returns {Context<T>}
66
- */
67
- export function create_context(initial_value) {
68
- return new Context(initial_value);
69
- }
@@ -58,12 +58,3 @@ export class Context {
58
58
  current_context.set(context, value);
59
59
  }
60
60
  }
61
-
62
- /**
63
- * @template T
64
- * @param {T} initial_value
65
- * @returns {Context<T>}
66
- */
67
- export function create_context(initial_value) {
68
- return new Context(initial_value);
69
- }
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2
- import { mount, createContext, flushSync, track } from 'ripple';
2
+ import { mount, Context, flushSync, track } from 'ripple';
3
3
 
4
4
  describe('context', () => {
5
5
  let container;
@@ -20,7 +20,7 @@ describe('context', () => {
20
20
  });
21
21
 
22
22
  it('creates a reactive ref with initial value', () => {
23
- const MyContext = createContext(null);
23
+ const MyContext = new Context(null);
24
24
 
25
25
  component Child() {
26
26
  const value = MyContext.get();
@@ -42,8 +42,8 @@ describe('context', () => {
42
42
  });
43
43
 
44
44
  it('handles context captured inside a computed tracked', () => {
45
-
46
- const MyContext = createContext(null)
45
+
46
+ const MyContext = new Context(null)
47
47
 
48
48
  const doubleContext = () => {
49
49
  const value = MyContext.get()
@@ -52,7 +52,7 @@ describe('context', () => {
52
52
 
53
53
  component App() {
54
54
  MyContext.set(4)
55
-
55
+
56
56
  <h3>{MyContext.get()}</h3>
57
57
 
58
58
  <h4>{'2x:'} {doubleContext()}</h4>
package/types/index.d.ts CHANGED
@@ -24,12 +24,12 @@ export interface TrackedArray<T> extends Array<T> { }
24
24
 
25
25
  export declare const TrackedArray: TrackedArrayConstructor;
26
26
 
27
- export type Context<T> = {
28
- get(): T;
29
- set(value: T): void;
30
- };
31
-
32
- export declare function createContext<T>(initialValue: T): Context<T>;
27
+ export declare class Context<T> {
28
+ constructor(initial_value: T);
29
+ get(): T;
30
+ set(value: T): void;
31
+ #private;
32
+ }
33
33
 
34
34
  export declare class TrackedSet<T> extends Set<T> {
35
35
  isDisjointFrom(other: TrackedSet<T> | Set<T>): boolean;