cddl2ts 0.9.1 → 0.10.0

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/build/index.js CHANGED
@@ -586,7 +586,8 @@ function parseUnionType(t, options) {
586
586
  else if (isNativeTypeWithOperator(t) && NATIVE_TYPES[t.Type.Type]) {
587
587
  return NATIVE_TYPES[t.Type.Type];
588
588
  }
589
- else if (isPropertyReference(t) && t.Value === 'null') {
589
+ else if (isPropertyReference(t) && t.Value === 'null' && !isLiteralWithValue(t)) {
590
+ // a bare `null` reference is the null type; a quoted "null" is a string literal
590
591
  return b.tsNullKeyword();
591
592
  }
592
593
  else if (isGroup(t)) {
@@ -635,7 +635,7 @@ export interface ScriptUndefinedValue {
635
635
  }
636
636
 
637
637
  export interface ScriptNullValue {
638
- type: null;
638
+ type: "null";
639
639
  }
640
640
 
641
641
  export interface ScriptStringValue {
@@ -968,7 +968,7 @@ export interface ScriptUndefinedValue {
968
968
  }
969
969
 
970
970
  export interface ScriptNullValue {
971
- type: null;
971
+ type: "null";
972
972
  }
973
973
 
974
974
  export interface ScriptStringValue {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cddl2ts",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "A Node.js package that can generate a TypeScript definition based on a CDDL file",
5
5
  "author": "Christian Bromann <mail@bromann.dev>",
6
6
  "license": "MIT",
@@ -25,14 +25,14 @@
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/yargs": "^17.0.35",
28
- "@types/node": "^25.5.0"
28
+ "@types/node": "^26.0.1"
29
29
  },
30
30
  "dependencies": {
31
31
  "@babel/parser": "^7.29.0",
32
32
  "camelcase": "^9.0.0",
33
33
  "recast": "^0.23.11",
34
34
  "yargs": "^18.0.0",
35
- "cddl": "0.20.1"
35
+ "cddl": "0.21.0"
36
36
  },
37
37
  "scripts": {
38
38
  "release": "release-it --config .release-it.ts --VV",
package/src/index.ts CHANGED
@@ -680,7 +680,8 @@ function parseUnionType (t: PropertyType | Assignment, options: TransformSetting
680
680
  return NATIVE_TYPES[(t as any).Type]
681
681
  } else if (isNativeTypeWithOperator(t) && NATIVE_TYPES[(t.Type as any).Type]) {
682
682
  return NATIVE_TYPES[(t.Type as any).Type]
683
- } else if (isPropertyReference(t) && t.Value === 'null') {
683
+ } else if (isPropertyReference(t) && t.Value === 'null' && !isLiteralWithValue(t)) {
684
+ // a bare `null` reference is the null type; a quoted "null" is a string literal
684
685
  return b.tsNullKeyword()
685
686
  } else if (isGroup(t)) {
686
687
  /**
@@ -24,7 +24,7 @@ export interface UndefinedValue {
24
24
  }
25
25
 
26
26
  export interface NullValue {
27
- type: null;
27
+ type: "null";
28
28
  }
29
29
 
30
30
  export interface StringValue {
@@ -638,7 +638,7 @@ export interface ScriptUndefinedValue {
638
638
  }
639
639
 
640
640
  export interface ScriptNullValue {
641
- type: null;
641
+ type: "null";
642
642
  }
643
643
 
644
644
  export interface ScriptStringValue {
@@ -971,7 +971,7 @@ export interface ScriptUndefinedValue {
971
971
  }
972
972
 
973
973
  export interface ScriptNullValue {
974
- type: null;
974
+ type: "null";
975
975
  }
976
976
 
977
977
  export interface ScriptStringValue {
@@ -285,7 +285,8 @@ describe('transform edge cases', () => {
285
285
  Operator: { Type: 'default', Value: literal('mouse') }
286
286
  }),
287
287
  variable('bool-literal', literal(true)),
288
- variable('null-literal', literal(null))
288
+ variable('null-literal', literal(null)),
289
+ variable('null-string-literal', literal('null'))
289
290
  ])
290
291
 
291
292
  expect(output).toContain('export type TupleType = [number, string];')
@@ -297,6 +298,8 @@ describe('transform edge cases', () => {
297
298
  expect(output).toContain('export type PointerType = PointerValue;')
298
299
  expect(output).toContain('export type BoolLiteral = true;')
299
300
  expect(output).toContain('export type NullLiteral = null;')
301
+ // a quoted "null" is a string literal, not the null type
302
+ expect(output).toContain('export type NullStringLiteral = "null";')
300
303
  })
301
304
 
302
305
  it('should include optional properties and default tags in object docs', () => {