nitrogen 0.30.1 → 0.30.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.
@@ -129,8 +129,15 @@ export function createType(language, type, isOptional) {
129
129
  }
130
130
  else if (type.isNumber() || type.isNumberLiteral()) {
131
131
  if (type.isEnumLiteral()) {
132
- // enum literals are technically just numbers - but we treat them differently in C++.
133
- return createType(language, type.getBaseTypeOfLiteralType(), isOptional);
132
+ // An enum is just a number, that's why it's a number literal.
133
+ // Get the base of the literal, which would be our enum's definition.
134
+ const baseType = type.getBaseTypeOfLiteralType();
135
+ if (!baseType.isEnum()) {
136
+ // The base of the literal is not the enum definition, we need to throw.
137
+ throw new Error(`The enum "${type.getLiteralValue()}" (${type.getText()}) is either a single-value-enum, or an enum-literal. Use a separately defined enum with at least 2 cases instead!`);
138
+ }
139
+ // Call createType(...) now with the enum type.
140
+ return createType(language, baseType, isOptional);
134
141
  }
135
142
  return new NumberType();
136
143
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nitrogen",
3
- "version": "0.30.1",
3
+ "version": "0.30.2",
4
4
  "description": "The code-generator for react-native-nitro-modules.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index.d.ts",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "chalk": "^5.3.0",
39
- "react-native-nitro-modules": "^0.30.1",
39
+ "react-native-nitro-modules": "^0.30.2",
40
40
  "ts-morph": "^27.0.0",
41
41
  "yargs": "^18.0.0",
42
42
  "zod": "^4.0.5"
@@ -189,8 +189,17 @@ export function createType(
189
189
  return new BooleanType()
190
190
  } else if (type.isNumber() || type.isNumberLiteral()) {
191
191
  if (type.isEnumLiteral()) {
192
- // enum literals are technically just numbers - but we treat them differently in C++.
193
- return createType(language, type.getBaseTypeOfLiteralType(), isOptional)
192
+ // An enum is just a number, that's why it's a number literal.
193
+ // Get the base of the literal, which would be our enum's definition.
194
+ const baseType = type.getBaseTypeOfLiteralType()
195
+ if (!baseType.isEnum()) {
196
+ // The base of the literal is not the enum definition, we need to throw.
197
+ throw new Error(
198
+ `The enum "${type.getLiteralValue()}" (${type.getText()}) is either a single-value-enum, or an enum-literal. Use a separately defined enum with at least 2 cases instead!`
199
+ )
200
+ }
201
+ // Call createType(...) now with the enum type.
202
+ return createType(language, baseType, isOptional)
194
203
  }
195
204
  return new NumberType()
196
205
  } else if (type.isString()) {