@atscript/core 0.2.17 → 0.2.18

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
@@ -123,6 +123,22 @@ var SemanticNode = class {
123
123
  this.tokens.set(semantic, token);
124
124
  return this;
125
125
  }
126
+ /**
127
+ * `define` for a node built from others (a merged prop, a copy of one): a definition
128
+ * another node declares stays that node's.
129
+ */ carryDefinition(node) {
130
+ var _node;
131
+ this.definition = node;
132
+ (_node = node).ownerNode ?? (_node.ownerNode = this);
133
+ return this;
134
+ }
135
+ /** `saveToken` for a node built from others: a token another node declares stays that node's. */ carryToken(token, semantic) {
136
+ var _token;
137
+ if (!this.tokens) this.tokens = /* @__PURE__ */ new Map();
138
+ (_token = token).parentNode ?? (_token.parentNode = this);
139
+ this.tokens.set(semantic, token);
140
+ return this;
141
+ }
126
142
  wrap(node, token) {
127
143
  this.define(node);
128
144
  this.saveToken(token, "identifier");
@@ -972,11 +988,13 @@ function _define_property$11(obj, key, value) {
972
988
  }
973
989
  var SemanticStructureNode = class extends SemanticGroup {
974
990
  /**
975
- * Shortcut to set props, used as utility
991
+ * Shortcut to set props, used as utility. A prop another structure declares keeps that
992
+ * structure as its owner: a merged or copied structure carries such props by reference.
976
993
  */ setProps(props) {
977
994
  this.nodes = props;
978
995
  for (const prop of props) {
979
- prop.ownerNode = this;
996
+ var _prop;
997
+ (_prop = prop).ownerNode ?? (_prop.ownerNode = this);
980
998
  this.props.set(prop.id, prop);
981
999
  }
982
1000
  }
@@ -9131,11 +9149,11 @@ var AtscriptDoc = class AtscriptDoc {
9131
9149
  const cloned = new SemanticPropNode();
9132
9150
  copiedFrom.set(cloned, prop);
9133
9151
  const idToken = prop.token("identifier");
9134
- if (idToken) cloned.saveToken(idToken, "identifier");
9135
- if (newDef) cloned.define(newDef);
9152
+ if (idToken) cloned.carryToken(idToken, "identifier");
9153
+ if (newDef) cloned.carryDefinition(newDef);
9136
9154
  cloned.annotations = group.own.length === 0 ? prop.annotations : this.mergeNodesAnnotations(prop.annotations, group.own, true);
9137
9155
  const optionalToken = prop.token("optional");
9138
- if (optionalToken) cloned.saveToken(optionalToken, "optional");
9156
+ if (optionalToken) cloned.carryToken(optionalToken, "optional");
9139
9157
  newProps.push(cloned);
9140
9158
  changed = true;
9141
9159
  }
@@ -10229,8 +10247,8 @@ var AtscriptDoc = class AtscriptDoc {
10229
10247
  if (isPrimitive(def)) def = createSyntheticRef(def.key);
10230
10248
  }
10231
10249
  const prop = new SemanticPropNode();
10232
- prop.saveToken(l.token("identifier"), "identifier");
10233
- prop.define(def);
10250
+ prop.carryToken(l.token("identifier"), "identifier");
10251
+ prop.carryDefinition(def);
10234
10252
  prop.annotations = this.mergeNodesAnnotations(l.annotations, r.annotations);
10235
10253
  keepOptional(prop, l, r);
10236
10254
  declaringDocs.set(prop, declaringDocs.get(l) ?? leftDoc);
@@ -10511,7 +10529,7 @@ const zeroRange = {
10511
10529
  * accepts a value without `u`, as 0.1.110 did).
10512
10530
  */ function keepOptional(prop, ...members) {
10513
10531
  const token = members[0]?.token("optional");
10514
- if (token && members.every((m) => m.token("optional"))) prop.saveToken(token, "optional");
10532
+ if (token && members.every((m) => m.token("optional"))) prop.carryToken(token, "optional");
10515
10533
  }
10516
10534
  /** The declarations whose type-level annotations are being evaluated (see `intersectionAnnotations`). */ const evaluatingMembers = /* @__PURE__ */ new Set();
10517
10535
  /** Why each `never` a merge built could not merge its members (see `neverReasonIn`). */ const neverReasons = /* @__PURE__ */ new WeakMap();
package/dist/index.d.ts CHANGED
@@ -404,6 +404,13 @@ declare class SemanticNode {
404
404
  get def(): SemanticNode | undefined;
405
405
  get identifier(): string | undefined;
406
406
  saveToken(token: Token, semantic: TSemanticToken): this;
407
+ /**
408
+ * `define` for a node built from others (a merged prop, a copy of one): a definition
409
+ * another node declares stays that node's.
410
+ */
411
+ carryDefinition(node: SemanticNode): this;
412
+ /** `saveToken` for a node built from others: a token another node declares stays that node's. */
413
+ carryToken(token: Token, semantic: TSemanticToken): this;
407
414
  wrap(node: SemanticNode, token: Token): this;
408
415
  token(s: TSemanticToken): Token | undefined;
409
416
  has(s: TSemanticToken): boolean | undefined;
@@ -2471,7 +2478,8 @@ declare class SemanticStructureNode extends SemanticGroup {
2471
2478
  constructor();
2472
2479
  readonly props: Map<string, SemanticPropNode>;
2473
2480
  /**
2474
- * Shortcut to set props, used as utility
2481
+ * Shortcut to set props, used as utility. A prop another structure declares keeps that
2482
+ * structure as its owner: a merged or copied structure carries such props by reference.
2475
2483
  */
2476
2484
  setProps(props: SemanticPropNode[]): void;
2477
2485
  registerAtDocument(doc: AtscriptDoc): void;
package/dist/index.mjs CHANGED
@@ -92,6 +92,22 @@ var SemanticNode = class {
92
92
  this.tokens.set(semantic, token);
93
93
  return this;
94
94
  }
95
+ /**
96
+ * `define` for a node built from others (a merged prop, a copy of one): a definition
97
+ * another node declares stays that node's.
98
+ */ carryDefinition(node) {
99
+ var _node;
100
+ this.definition = node;
101
+ (_node = node).ownerNode ?? (_node.ownerNode = this);
102
+ return this;
103
+ }
104
+ /** `saveToken` for a node built from others: a token another node declares stays that node's. */ carryToken(token, semantic) {
105
+ var _token;
106
+ if (!this.tokens) this.tokens = /* @__PURE__ */ new Map();
107
+ (_token = token).parentNode ?? (_token.parentNode = this);
108
+ this.tokens.set(semantic, token);
109
+ return this;
110
+ }
95
111
  wrap(node, token) {
96
112
  this.define(node);
97
113
  this.saveToken(token, "identifier");
@@ -941,11 +957,13 @@ function _define_property$11(obj, key, value) {
941
957
  }
942
958
  var SemanticStructureNode = class extends SemanticGroup {
943
959
  /**
944
- * Shortcut to set props, used as utility
960
+ * Shortcut to set props, used as utility. A prop another structure declares keeps that
961
+ * structure as its owner: a merged or copied structure carries such props by reference.
945
962
  */ setProps(props) {
946
963
  this.nodes = props;
947
964
  for (const prop of props) {
948
- prop.ownerNode = this;
965
+ var _prop;
966
+ (_prop = prop).ownerNode ?? (_prop.ownerNode = this);
949
967
  this.props.set(prop.id, prop);
950
968
  }
951
969
  }
@@ -9100,11 +9118,11 @@ var AtscriptDoc = class AtscriptDoc {
9100
9118
  const cloned = new SemanticPropNode();
9101
9119
  copiedFrom.set(cloned, prop);
9102
9120
  const idToken = prop.token("identifier");
9103
- if (idToken) cloned.saveToken(idToken, "identifier");
9104
- if (newDef) cloned.define(newDef);
9121
+ if (idToken) cloned.carryToken(idToken, "identifier");
9122
+ if (newDef) cloned.carryDefinition(newDef);
9105
9123
  cloned.annotations = group.own.length === 0 ? prop.annotations : this.mergeNodesAnnotations(prop.annotations, group.own, true);
9106
9124
  const optionalToken = prop.token("optional");
9107
- if (optionalToken) cloned.saveToken(optionalToken, "optional");
9125
+ if (optionalToken) cloned.carryToken(optionalToken, "optional");
9108
9126
  newProps.push(cloned);
9109
9127
  changed = true;
9110
9128
  }
@@ -10198,8 +10216,8 @@ var AtscriptDoc = class AtscriptDoc {
10198
10216
  if (isPrimitive(def)) def = createSyntheticRef(def.key);
10199
10217
  }
10200
10218
  const prop = new SemanticPropNode();
10201
- prop.saveToken(l.token("identifier"), "identifier");
10202
- prop.define(def);
10219
+ prop.carryToken(l.token("identifier"), "identifier");
10220
+ prop.carryDefinition(def);
10203
10221
  prop.annotations = this.mergeNodesAnnotations(l.annotations, r.annotations);
10204
10222
  keepOptional(prop, l, r);
10205
10223
  declaringDocs.set(prop, declaringDocs.get(l) ?? leftDoc);
@@ -10480,7 +10498,7 @@ const zeroRange = {
10480
10498
  * accepts a value without `u`, as 0.1.110 did).
10481
10499
  */ function keepOptional(prop, ...members) {
10482
10500
  const token = members[0]?.token("optional");
10483
- if (token && members.every((m) => m.token("optional"))) prop.saveToken(token, "optional");
10501
+ if (token && members.every((m) => m.token("optional"))) prop.carryToken(token, "optional");
10484
10502
  }
10485
10503
  /** The declarations whose type-level annotations are being evaluated (see `intersectionAnnotations`). */ const evaluatingMembers = /* @__PURE__ */ new Set();
10486
10504
  /** Why each `never` a merge built could not merge its members (see `neverReasonIn`). */ const neverReasons = /* @__PURE__ */ new WeakMap();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/core",
3
- "version": "0.2.17",
3
+ "version": "0.2.18",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "keywords": [
6
6
  "annotations",