@flamework-experimental/transformer 2.0.0-alpha.0 → 2.0.0-alpha.1

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.
@@ -308,15 +308,17 @@ function updateLinks(state, node, properties) {
308
308
  for (var _e = __values(getDeclaredChildren(state, node, instanceType)), _f = _e.next(); !_f.done; _f = _e.next()) {
309
309
  var _g = __read(_f.value, 2), property = _g[0], declaredType = _g[1];
310
310
  var targetType = state.typeChecker.getNonNullableType(declaredType);
311
- var optional = isOptionalMember(state, property, declaredType);
311
+ // Whether it names a component or a plain instance: a child that may be missing is a
312
+ // child `this.instance` cannot be indexed for, so the tree does not describe one.
313
+ if (isOptionalMember(state, property, declaredType)) {
314
+ assertChildIsRequired(node, property, property.name);
315
+ }
312
316
  if (getComponentInstanceType(state, targetType, node)) {
313
317
  // A child's own guard is part of the component's instance guard, so the link only
314
318
  // has to name the component that must exist on it.
315
- links.push(createLink(state, node, "child", property.name, optional, targetType));
319
+ links.push(createLink(state, node, "child", property.name, false, targetType));
316
320
  }
317
321
  else if ((0, buildGuardFromType_1.isInstanceType)(targetType)) {
318
- if (optional)
319
- assertChildIsRequired(node, property, property.name);
320
322
  assertInstanceTree(state, node, targetType, property.name);
321
323
  }
322
324
  }
@@ -346,22 +348,15 @@ function getPropertyNode(node, property) {
346
348
  return factory_1.f.is.namedDeclaration(declaration) ? declaration.name : declaration;
347
349
  }
348
350
  /**
349
- * A child of the instance tree cannot be optional. `this.instance.Head` is an index into the
350
- * instance itself, and Roblox raises on a child that is not there rather than handing back nothing,
351
- * so the optional type would promise a read that is not safe to make.
352
- *
353
- * A child typed as a *component* is the exception, and is let through above: it is a link, so its
354
- * presence is watched and `childComponents.Head` -- an ordinary table read -- is what says whether
355
- * the child is there.
351
+ * A child of the instance tree cannot be optional, whether it names a component or a plain
352
+ * instance. `this.instance.Head` is an index into the instance itself, and Roblox raises on a
353
+ * child that is not there rather than handing back nothing, so the optional type would promise a
354
+ * read that is not safe to make. A component that may or may not be there is reached through an
355
+ * optional link attribute, or looked up with `getComponent`.
356
356
  */
357
357
  function assertChildIsRequired(node, property, path) {
358
358
  var component = node.name ? " of '".concat(node.name.text, "'") : "";
359
- // Naming a component is only an option for a direct child; one deeper in the tree cannot be
360
- // linked at all, so it is not offered as a way out there.
361
- var link = path.includes(".")
362
- ? ""
363
- : " type it as a component so that Flamework watches it and 'childComponents' says whether it is there, or";
364
- diagnostics_1.Diagnostics.error(getPropertyNode(node, property), "Child '".concat(path, "' of the instance tree").concat(component, " is optional, which Flamework does not allow: Roblox raises when a child that does not exist is indexed, so 'this.instance.").concat(path, "' would error rather than be undefined."), "Require the child,".concat(link, " leave it out of the tree and reach for it with FindFirstChild."));
359
+ diagnostics_1.Diagnostics.error(getPropertyNode(node, property), "Child '".concat(path, "' of the instance tree").concat(component, " is optional, which Flamework does not allow: Roblox raises when a child that does not exist is indexed, so 'this.instance.").concat(path, "' would error rather than be undefined."), "Require the child, or leave it out of the tree and reach for it with FindFirstChild; a component that may be missing can be named by an optional link attribute, or looked up with getComponent.");
365
360
  }
366
361
  /**
367
362
  * Checks the children declared below a direct child of the instance tree.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flamework-experimental/transformer",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.1",
4
4
  "description": "An opinionated game framework for Roblox.",
5
5
  "main": "out/index.js",
6
6
  "scripts": {