@openwebf/webf 0.23.0 → 0.23.2

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.
@@ -0,0 +1,30 @@
1
+ import { generateReactComponent } from '../src/react';
2
+ import { IDLBlob } from '../src/IDLBlob';
3
+ import { ConstObject, EnumObject, EnumMemberObject } from '../src/declaration';
4
+
5
+ describe('React generator - declare const support', () => {
6
+ it('emits export declare const for constants from typings', () => {
7
+ const blob = new IDLBlob('/test/source', '/test/target', 'ConstOnly', 'test', '');
8
+ const constObj = new ConstObject();
9
+ constObj.name = 'WEBF_CUPERTINO_SYMBOL';
10
+ constObj.type = 'unique symbol';
11
+
12
+ blob.objects = [constObj as any];
13
+
14
+ const output = generateReactComponent(blob);
15
+ expect(output).toContain('export declare const WEBF_CUPERTINO_SYMBOL: unique symbol;');
16
+ });
17
+
18
+ it('emits export declare enum for enums from typings', () => {
19
+ const blob = new IDLBlob('/test/source', '/test/target', 'EnumOnly', 'test', '');
20
+ const eo = new EnumObject();
21
+ eo.name = 'CupertinoColors';
22
+ const m1 = new EnumMemberObject(); m1.name = "'red'"; m1.initializer = '0x0f';
23
+ const m2 = new EnumMemberObject(); m2.name = "'bbb'"; m2.initializer = '0x00';
24
+ eo.members = [m1, m2];
25
+ blob.objects = [eo as any];
26
+
27
+ const output = generateReactComponent(blob);
28
+ expect(output).toContain("export declare enum CupertinoColors { 'red' = 0x0f, 'bbb' = 0x00 }");
29
+ });
30
+ });
package/test/vue.test.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { generateVueTypings } from '../src/vue';
2
2
  import { IDLBlob } from '../src/IDLBlob';
3
- import { ClassObject, ClassObjectKind, PropsDeclaration } from '../src/declaration';
3
+ import { ClassObject, ClassObjectKind, PropsDeclaration, ConstObject } from '../src/declaration';
4
4
 
5
5
  describe('Vue Generator', () => {
6
6
  describe('generateVueTypings', () => {
@@ -153,5 +153,37 @@ describe('Vue Generator', () => {
153
153
  expect(result).toContain("'class'?: string;");
154
154
  expect(result).toContain("'style'?: string | Record<string, any>;");
155
155
  });
156
+
157
+ it('should include declare const variables as exported declarations', () => {
158
+ const blob = new IDLBlob('/test/source', '/test/target', 'ConstOnly', 'test', '');
159
+
160
+ const constObj = new ConstObject();
161
+ constObj.name = 'WEBF_UNIQUE';
162
+ constObj.type = 'unique symbol';
163
+
164
+ blob.objects = [constObj as any];
165
+
166
+ const result = generateVueTypings([blob]);
167
+
168
+ expect(result).toContain('export declare const WEBF_UNIQUE: unique symbol;');
169
+ });
170
+
171
+ it('should include declare enum as exported declaration', () => {
172
+ const blob = new IDLBlob('/test/source', '/test/target', 'EnumOnly', 'test', '');
173
+ // Build a minimal faux EnumObject via analyzer by simulating ast is heavy; create a shape
174
+ // We'll reuse analyzer classes by importing EnumObject is cumbersome in test; instead
175
+ // craft an object literal compatible with instanceof check by constructing real class.
176
+ const { EnumObject, EnumMemberObject } = require('../src/declaration');
177
+ const e = new EnumObject();
178
+ e.name = 'CupertinoColors';
179
+ const m1 = new EnumMemberObject(); m1.name = "'red'"; m1.initializer = '0x0f';
180
+ const m2 = new EnumMemberObject(); m2.name = "'bbb'"; m2.initializer = '0x00';
181
+ e.members = [m1, m2];
182
+
183
+ blob.objects = [e as any];
184
+
185
+ const result = generateVueTypings([blob]);
186
+ expect(result).toContain("export declare enum CupertinoColors { 'red' = 0x0f, 'bbb' = 0x00 }");
187
+ });
156
188
  });
157
- });
189
+ });