@atscript/core 0.2.16 → 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 +52 -8
- package/dist/index.d.ts +9 -1
- package/dist/index.mjs +52 -8
- package/package.json +1 -1
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
|
-
|
|
996
|
+
var _prop;
|
|
997
|
+
(_prop = prop).ownerNode ?? (_prop.ownerNode = this);
|
|
980
998
|
this.props.set(prop.id, prop);
|
|
981
999
|
}
|
|
982
1000
|
}
|
|
@@ -4054,6 +4072,7 @@ function definition(pipes) {
|
|
|
4054
4072
|
return true;
|
|
4055
4073
|
}
|
|
4056
4074
|
const resolvedPipes = pipes.map((p) => typeof p === "function" ? p() : p);
|
|
4075
|
+
skipLeadingOperator(fork, opts);
|
|
4057
4076
|
const node = runPipesOnce(resolvedPipes, fork);
|
|
4058
4077
|
if (node) {
|
|
4059
4078
|
fork.accepted();
|
|
@@ -4078,9 +4097,11 @@ function definition(pipes) {
|
|
|
4078
4097
|
fork.unexpected(false, "Unexpected end of group");
|
|
4079
4098
|
break;
|
|
4080
4099
|
}
|
|
4100
|
+
const isComma = fork.$.text === ",";
|
|
4081
4101
|
fork.accepted();
|
|
4082
4102
|
fork.move();
|
|
4083
4103
|
fork.skip(opts.skip);
|
|
4104
|
+
if (isComma) skipLeadingOperator(fork, opts);
|
|
4084
4105
|
} else {
|
|
4085
4106
|
if (fork.$) fork.unexpected();
|
|
4086
4107
|
break;
|
|
@@ -4133,6 +4154,29 @@ function definition(pipes) {
|
|
|
4133
4154
|
}
|
|
4134
4155
|
};
|
|
4135
4156
|
}
|
|
4157
|
+
const LEADING_OPERATORS = ["|", "&"];
|
|
4158
|
+
/**
|
|
4159
|
+
* Step over one `|` or `&` written before the first member of a union or
|
|
4160
|
+
* intersection (a formatting style: one member per line, each starting with the
|
|
4161
|
+
* operator). It carries no meaning. An operator that no member follows (the end
|
|
4162
|
+
* of the block, or more punctuation) is left in place, so it is reported as
|
|
4163
|
+
* unexpected and the rest of the block parses as before.
|
|
4164
|
+
*/ function skipLeadingOperator(ni, opts) {
|
|
4165
|
+
const text = LEADING_OPERATORS.filter((op) => opts.sep.includes(op));
|
|
4166
|
+
if (text.length === 0) return;
|
|
4167
|
+
const ahead = ni.fork().skip(opts.skip);
|
|
4168
|
+
if (!ahead.satisfies({
|
|
4169
|
+
node: "punctuation",
|
|
4170
|
+
text
|
|
4171
|
+
})) return;
|
|
4172
|
+
const member = ahead.next(opts.skip).$;
|
|
4173
|
+
if (member && member.type !== "punctuation") {
|
|
4174
|
+
ni.unfork(ahead);
|
|
4175
|
+
ni.accepted();
|
|
4176
|
+
ni.move();
|
|
4177
|
+
ni.skip(opts.skip);
|
|
4178
|
+
}
|
|
4179
|
+
}
|
|
4136
4180
|
function unwrap(attr) {
|
|
4137
4181
|
const opts = { pipes: [] };
|
|
4138
4182
|
return {
|
|
@@ -9105,11 +9149,11 @@ var AtscriptDoc = class AtscriptDoc {
|
|
|
9105
9149
|
const cloned = new SemanticPropNode();
|
|
9106
9150
|
copiedFrom.set(cloned, prop);
|
|
9107
9151
|
const idToken = prop.token("identifier");
|
|
9108
|
-
if (idToken) cloned.
|
|
9109
|
-
if (newDef) cloned.
|
|
9152
|
+
if (idToken) cloned.carryToken(idToken, "identifier");
|
|
9153
|
+
if (newDef) cloned.carryDefinition(newDef);
|
|
9110
9154
|
cloned.annotations = group.own.length === 0 ? prop.annotations : this.mergeNodesAnnotations(prop.annotations, group.own, true);
|
|
9111
9155
|
const optionalToken = prop.token("optional");
|
|
9112
|
-
if (optionalToken) cloned.
|
|
9156
|
+
if (optionalToken) cloned.carryToken(optionalToken, "optional");
|
|
9113
9157
|
newProps.push(cloned);
|
|
9114
9158
|
changed = true;
|
|
9115
9159
|
}
|
|
@@ -10203,8 +10247,8 @@ var AtscriptDoc = class AtscriptDoc {
|
|
|
10203
10247
|
if (isPrimitive(def)) def = createSyntheticRef(def.key);
|
|
10204
10248
|
}
|
|
10205
10249
|
const prop = new SemanticPropNode();
|
|
10206
|
-
prop.
|
|
10207
|
-
prop.
|
|
10250
|
+
prop.carryToken(l.token("identifier"), "identifier");
|
|
10251
|
+
prop.carryDefinition(def);
|
|
10208
10252
|
prop.annotations = this.mergeNodesAnnotations(l.annotations, r.annotations);
|
|
10209
10253
|
keepOptional(prop, l, r);
|
|
10210
10254
|
declaringDocs.set(prop, declaringDocs.get(l) ?? leftDoc);
|
|
@@ -10485,7 +10529,7 @@ const zeroRange = {
|
|
|
10485
10529
|
* accepts a value without `u`, as 0.1.110 did).
|
|
10486
10530
|
*/ function keepOptional(prop, ...members) {
|
|
10487
10531
|
const token = members[0]?.token("optional");
|
|
10488
|
-
if (token && members.every((m) => m.token("optional"))) prop.
|
|
10532
|
+
if (token && members.every((m) => m.token("optional"))) prop.carryToken(token, "optional");
|
|
10489
10533
|
}
|
|
10490
10534
|
/** The declarations whose type-level annotations are being evaluated (see `intersectionAnnotations`). */ const evaluatingMembers = /* @__PURE__ */ new Set();
|
|
10491
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
|
-
|
|
965
|
+
var _prop;
|
|
966
|
+
(_prop = prop).ownerNode ?? (_prop.ownerNode = this);
|
|
949
967
|
this.props.set(prop.id, prop);
|
|
950
968
|
}
|
|
951
969
|
}
|
|
@@ -4023,6 +4041,7 @@ function definition(pipes) {
|
|
|
4023
4041
|
return true;
|
|
4024
4042
|
}
|
|
4025
4043
|
const resolvedPipes = pipes.map((p) => typeof p === "function" ? p() : p);
|
|
4044
|
+
skipLeadingOperator(fork, opts);
|
|
4026
4045
|
const node = runPipesOnce(resolvedPipes, fork);
|
|
4027
4046
|
if (node) {
|
|
4028
4047
|
fork.accepted();
|
|
@@ -4047,9 +4066,11 @@ function definition(pipes) {
|
|
|
4047
4066
|
fork.unexpected(false, "Unexpected end of group");
|
|
4048
4067
|
break;
|
|
4049
4068
|
}
|
|
4069
|
+
const isComma = fork.$.text === ",";
|
|
4050
4070
|
fork.accepted();
|
|
4051
4071
|
fork.move();
|
|
4052
4072
|
fork.skip(opts.skip);
|
|
4073
|
+
if (isComma) skipLeadingOperator(fork, opts);
|
|
4053
4074
|
} else {
|
|
4054
4075
|
if (fork.$) fork.unexpected();
|
|
4055
4076
|
break;
|
|
@@ -4102,6 +4123,29 @@ function definition(pipes) {
|
|
|
4102
4123
|
}
|
|
4103
4124
|
};
|
|
4104
4125
|
}
|
|
4126
|
+
const LEADING_OPERATORS = ["|", "&"];
|
|
4127
|
+
/**
|
|
4128
|
+
* Step over one `|` or `&` written before the first member of a union or
|
|
4129
|
+
* intersection (a formatting style: one member per line, each starting with the
|
|
4130
|
+
* operator). It carries no meaning. An operator that no member follows (the end
|
|
4131
|
+
* of the block, or more punctuation) is left in place, so it is reported as
|
|
4132
|
+
* unexpected and the rest of the block parses as before.
|
|
4133
|
+
*/ function skipLeadingOperator(ni, opts) {
|
|
4134
|
+
const text = LEADING_OPERATORS.filter((op) => opts.sep.includes(op));
|
|
4135
|
+
if (text.length === 0) return;
|
|
4136
|
+
const ahead = ni.fork().skip(opts.skip);
|
|
4137
|
+
if (!ahead.satisfies({
|
|
4138
|
+
node: "punctuation",
|
|
4139
|
+
text
|
|
4140
|
+
})) return;
|
|
4141
|
+
const member = ahead.next(opts.skip).$;
|
|
4142
|
+
if (member && member.type !== "punctuation") {
|
|
4143
|
+
ni.unfork(ahead);
|
|
4144
|
+
ni.accepted();
|
|
4145
|
+
ni.move();
|
|
4146
|
+
ni.skip(opts.skip);
|
|
4147
|
+
}
|
|
4148
|
+
}
|
|
4105
4149
|
function unwrap(attr) {
|
|
4106
4150
|
const opts = { pipes: [] };
|
|
4107
4151
|
return {
|
|
@@ -9074,11 +9118,11 @@ var AtscriptDoc = class AtscriptDoc {
|
|
|
9074
9118
|
const cloned = new SemanticPropNode();
|
|
9075
9119
|
copiedFrom.set(cloned, prop);
|
|
9076
9120
|
const idToken = prop.token("identifier");
|
|
9077
|
-
if (idToken) cloned.
|
|
9078
|
-
if (newDef) cloned.
|
|
9121
|
+
if (idToken) cloned.carryToken(idToken, "identifier");
|
|
9122
|
+
if (newDef) cloned.carryDefinition(newDef);
|
|
9079
9123
|
cloned.annotations = group.own.length === 0 ? prop.annotations : this.mergeNodesAnnotations(prop.annotations, group.own, true);
|
|
9080
9124
|
const optionalToken = prop.token("optional");
|
|
9081
|
-
if (optionalToken) cloned.
|
|
9125
|
+
if (optionalToken) cloned.carryToken(optionalToken, "optional");
|
|
9082
9126
|
newProps.push(cloned);
|
|
9083
9127
|
changed = true;
|
|
9084
9128
|
}
|
|
@@ -10172,8 +10216,8 @@ var AtscriptDoc = class AtscriptDoc {
|
|
|
10172
10216
|
if (isPrimitive(def)) def = createSyntheticRef(def.key);
|
|
10173
10217
|
}
|
|
10174
10218
|
const prop = new SemanticPropNode();
|
|
10175
|
-
prop.
|
|
10176
|
-
prop.
|
|
10219
|
+
prop.carryToken(l.token("identifier"), "identifier");
|
|
10220
|
+
prop.carryDefinition(def);
|
|
10177
10221
|
prop.annotations = this.mergeNodesAnnotations(l.annotations, r.annotations);
|
|
10178
10222
|
keepOptional(prop, l, r);
|
|
10179
10223
|
declaringDocs.set(prop, declaringDocs.get(l) ?? leftDoc);
|
|
@@ -10454,7 +10498,7 @@ const zeroRange = {
|
|
|
10454
10498
|
* accepts a value without `u`, as 0.1.110 did).
|
|
10455
10499
|
*/ function keepOptional(prop, ...members) {
|
|
10456
10500
|
const token = members[0]?.token("optional");
|
|
10457
|
-
if (token && members.every((m) => m.token("optional"))) prop.
|
|
10501
|
+
if (token && members.every((m) => m.token("optional"))) prop.carryToken(token, "optional");
|
|
10458
10502
|
}
|
|
10459
10503
|
/** The declarations whose type-level annotations are being evaluated (see `intersectionAnnotations`). */ const evaluatingMembers = /* @__PURE__ */ new Set();
|
|
10460
10504
|
/** Why each `never` a merge built could not merge its members (see `neverReasonIn`). */ const neverReasons = /* @__PURE__ */ new WeakMap();
|