@atscript/core 0.1.76 → 0.1.78

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/dist/index.cjs CHANGED
@@ -1029,15 +1029,30 @@ var AnnotationSpec = class {
1029
1029
  message: `${mainToken.text} at argument #${i + 1} ("${argSpec.name}") must be one of [${values.join(", ")}]`,
1030
1030
  range: token.range
1031
1031
  });
1032
- if (this.config.defType?.length) {
1033
- const parentNode = mainToken.parentNode;
1034
- const idToken = isRef(parentNode) ? parentNode.token("identifier") : undefined;
1035
- const isAnnotateEntry = !!idToken && !!doc.annotateBlockAt(idToken.range.start.line, idToken.range.start.character);
1036
- if (!isAnnotateEntry) {
1037
- let def = parentNode.getDefinition();
1038
- if (isRef(def)) def = doc.unwindType(def.id, def.chain)?.def || def;
1039
- messages.push(...this.validateTargetType(def, mainToken.range) || []);
1040
- }
1032
+ }
1033
+ return messages.length > 0 ? messages : undefined;
1034
+ }
1035
+ /**
1036
+ * Cross-file-dependent validation, deferred to diagnostic time
1037
+ * (`AtscriptDoc.getDiagMessages`) where imported target types finally resolve.
1038
+ *
1039
+ * Runs the `defType` target-type guard for inline props and the
1040
+ * plugin-provided `validate` hook. Both introspect the field's resolved type
1041
+ * via `doc.unwindType`, so running them at parse time — before cross-file
1042
+ * dependencies are wired — yielded unresolved imports and spurious
1043
+ * diagnostics. Annotate-block entries' `defType` guard is handled separately
1044
+ * by `getDiagMessages` (the `referred` loop) and is skipped here.
1045
+ */ validateDeferred(mainToken, args, doc) {
1046
+ if (!mainToken.parentNode) return undefined;
1047
+ const messages = [];
1048
+ if (this.config.defType?.length) {
1049
+ const parentNode = mainToken.parentNode;
1050
+ const idToken = isRef(parentNode) ? parentNode.token("identifier") : undefined;
1051
+ const isAnnotateEntry = !!idToken && !!doc.annotateBlockAt(idToken.range.start.line, idToken.range.start.character);
1052
+ if (!isAnnotateEntry) {
1053
+ let def = parentNode.getDefinition();
1054
+ if (isRef(def)) def = doc.unwindType(def.id, def.chain)?.def || def;
1055
+ messages.push(...this.validateTargetType(def, mainToken.range) || []);
1041
1056
  }
1042
1057
  }
1043
1058
  if (this.config.validate) messages.push(...this.config.validate(mainToken, args, doc) || []);
@@ -4119,6 +4134,10 @@ else group$1.nested.push({
4119
4134
  }
4120
4135
  }
4121
4136
  }
4137
+ for (const a of this.annotations) {
4138
+ const spec = this.resolveAnnotation(a.name);
4139
+ if (spec) this._allMessages.push(...spec.validateDeferred(a.token, a.args, this) || []);
4140
+ }
4122
4141
  }
4123
4142
  return this._allMessages;
4124
4143
  }
package/dist/index.d.ts CHANGED
@@ -889,6 +889,18 @@ declare class AnnotationSpec {
889
889
  private validateType;
890
890
  modify(mainToken: Token, args: Token[], doc: AtscriptDoc): void;
891
891
  validate(mainToken: Token, args: Token[], doc: AtscriptDoc): TMessages | undefined;
892
+ /**
893
+ * Cross-file-dependent validation, deferred to diagnostic time
894
+ * (`AtscriptDoc.getDiagMessages`) where imported target types finally resolve.
895
+ *
896
+ * Runs the `defType` target-type guard for inline props and the
897
+ * plugin-provided `validate` hook. Both introspect the field's resolved type
898
+ * via `doc.unwindType`, so running them at parse time — before cross-file
899
+ * dependencies are wired — yielded unresolved imports and spurious
900
+ * diagnostics. Annotate-block entries' `defType` guard is handled separately
901
+ * by `getDiagMessages` (the `referred` loop) and is skipped here.
902
+ */
903
+ validateDeferred(mainToken: Token, args: Token[], doc: AtscriptDoc): TMessages | undefined;
892
904
  /**
893
905
  * Checks an already-resolved target node against this annotation's `defType`
894
906
  * guard (e.g. `@expect.minLength` requires `string | array`). Returns a
package/dist/index.mjs CHANGED
@@ -1005,15 +1005,30 @@ var AnnotationSpec = class {
1005
1005
  message: `${mainToken.text} at argument #${i + 1} ("${argSpec.name}") must be one of [${values.join(", ")}]`,
1006
1006
  range: token.range
1007
1007
  });
1008
- if (this.config.defType?.length) {
1009
- const parentNode = mainToken.parentNode;
1010
- const idToken = isRef(parentNode) ? parentNode.token("identifier") : undefined;
1011
- const isAnnotateEntry = !!idToken && !!doc.annotateBlockAt(idToken.range.start.line, idToken.range.start.character);
1012
- if (!isAnnotateEntry) {
1013
- let def = parentNode.getDefinition();
1014
- if (isRef(def)) def = doc.unwindType(def.id, def.chain)?.def || def;
1015
- messages.push(...this.validateTargetType(def, mainToken.range) || []);
1016
- }
1008
+ }
1009
+ return messages.length > 0 ? messages : undefined;
1010
+ }
1011
+ /**
1012
+ * Cross-file-dependent validation, deferred to diagnostic time
1013
+ * (`AtscriptDoc.getDiagMessages`) where imported target types finally resolve.
1014
+ *
1015
+ * Runs the `defType` target-type guard for inline props and the
1016
+ * plugin-provided `validate` hook. Both introspect the field's resolved type
1017
+ * via `doc.unwindType`, so running them at parse time — before cross-file
1018
+ * dependencies are wired — yielded unresolved imports and spurious
1019
+ * diagnostics. Annotate-block entries' `defType` guard is handled separately
1020
+ * by `getDiagMessages` (the `referred` loop) and is skipped here.
1021
+ */ validateDeferred(mainToken, args, doc) {
1022
+ if (!mainToken.parentNode) return undefined;
1023
+ const messages = [];
1024
+ if (this.config.defType?.length) {
1025
+ const parentNode = mainToken.parentNode;
1026
+ const idToken = isRef(parentNode) ? parentNode.token("identifier") : undefined;
1027
+ const isAnnotateEntry = !!idToken && !!doc.annotateBlockAt(idToken.range.start.line, idToken.range.start.character);
1028
+ if (!isAnnotateEntry) {
1029
+ let def = parentNode.getDefinition();
1030
+ if (isRef(def)) def = doc.unwindType(def.id, def.chain)?.def || def;
1031
+ messages.push(...this.validateTargetType(def, mainToken.range) || []);
1017
1032
  }
1018
1033
  }
1019
1034
  if (this.config.validate) messages.push(...this.config.validate(mainToken, args, doc) || []);
@@ -4095,6 +4110,10 @@ else group$1.nested.push({
4095
4110
  }
4096
4111
  }
4097
4112
  }
4113
+ for (const a of this.annotations) {
4114
+ const spec = this.resolveAnnotation(a.name);
4115
+ if (spec) this._allMessages.push(...spec.validateDeferred(a.token, a.args, this) || []);
4116
+ }
4098
4117
  }
4099
4118
  return this._allMessages;
4100
4119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/core",
3
- "version": "0.1.76",
3
+ "version": "0.1.78",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "keywords": [
6
6
  "annotations",