@snowtop/ent 0.1.0-alpha34 → 0.1.0-alpha35

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowtop/ent",
3
- "version": "0.1.0-alpha34",
3
+ "version": "0.1.0-alpha35",
4
4
  "description": "snowtop ent framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -91,7 +91,7 @@ function getTransformClassInfo(fileContents, sourceFile, node, transformSchema)
91
91
  }
92
92
  // intentionally doesn't parse decorators since we don't need it
93
93
  function getClassElementInfo(fileContents, member, sourceFile) {
94
- if (isFieldElement(member, sourceFile)) {
94
+ if (isFieldElement(fileContents, member, sourceFile)) {
95
95
  return getFieldElementInfo(fileContents, member, sourceFile);
96
96
  }
97
97
  if (member.kind === typescript_1.default.SyntaxKind.Constructor) {
@@ -201,7 +201,7 @@ function getConstructorElementInfo(fileContents, member, sourceFile) {
201
201
  comment: "",
202
202
  };
203
203
  }
204
- function isFieldElement(member, sourceFile) {
204
+ function isFieldElement(fileContents, member, sourceFile) {
205
205
  if (member.kind !== typescript_1.default.SyntaxKind.PropertyDeclaration) {
206
206
  return false;
207
207
  }
@@ -215,16 +215,31 @@ function isFieldElement(member, sourceFile) {
215
215
  return false;
216
216
  }
217
217
  if (property.initializer?.kind !== typescript_1.default.SyntaxKind.ArrayLiteralExpression) {
218
- console.error("invalid array type");
218
+ throwErr(fileContents, member, "invalid array type");
219
219
  return false;
220
220
  }
221
221
  return true;
222
222
  }
223
+ // if there's an error transforming any of the schemas, we should stop...
224
+ function throwErr(fileContents, node, error) {
225
+ console.error(error);
226
+ throw new Error(`error transforming this field ${fileContents.substring(node.getFullStart(), node.getEnd())}`);
227
+ }
223
228
  function parseFieldElement(element, sourceFile, fileContents, nested) {
224
- if (element.kind !== typescript_1.default.SyntaxKind.CallExpression) {
225
- console.error("skipped non-call expression");
229
+ if (element.kind !== typescript_1.default.SyntaxKind.CallExpression &&
230
+ element.kind !== typescript_1.default.SyntaxKind.PropertyAccessExpression) {
231
+ throwErr(fileContents, element, `skipped unknown (non-call|non-property) expression ${element.kind}`);
226
232
  return null;
227
233
  }
234
+ if (element.kind === typescript_1.default.SyntaxKind.PropertyAccessExpression) {
235
+ const ret = parseFieldElement(element.expression, sourceFile, fileContents, true);
236
+ if (ret !== null) {
237
+ if (!nested) {
238
+ ret.suffix = fileContents.substring(ret.callEx.getEnd(), element.getEnd());
239
+ }
240
+ return ret;
241
+ }
242
+ }
228
243
  let callEx = element;
229
244
  if (callEx.arguments.length !== 1) {
230
245
  // have a situation like: StringType({ name: "canonicalName" }).trim().toLowerCase(),
@@ -238,12 +253,22 @@ function parseFieldElement(element, sourceFile, fileContents, nested) {
238
253
  return ret;
239
254
  }
240
255
  }
241
- console.error("callExpression with arguments not of length 1");
242
- return null;
256
+ throwErr(fileContents, element, "callExpression with arguments not of length 1");
243
257
  }
244
258
  let arg = callEx.arguments[0];
245
259
  if (arg.kind !== typescript_1.default.SyntaxKind.ObjectLiteralExpression) {
246
- console.error("not objectLiteralExpression");
260
+ // this and the check above for PropertyAccessExpression are to handle things like
261
+ // FooType({
262
+ /// ...
263
+ // }).function(blah)
264
+ const ret = parseFieldElement(callEx.expression, sourceFile, fileContents, true);
265
+ if (ret !== null) {
266
+ if (!nested) {
267
+ ret.suffix = fileContents.substring(ret.callEx.getEnd(), callEx.getEnd());
268
+ }
269
+ return ret;
270
+ }
271
+ throwErr(fileContents, element, `not objectLiteralExpression. kind ${arg.kind}`);
247
272
  return null;
248
273
  }
249
274
  let expr = arg;
@@ -263,7 +288,7 @@ function parseFieldElement(element, sourceFile, fileContents, nested) {
263
288
  }
264
289
  }
265
290
  if (!name) {
266
- console.error(`couldn't find name property`);
291
+ throwErr(fileContents, element, `couldn't find name property`);
267
292
  return null;
268
293
  }
269
294
  // remove quotes