@atscript/core 0.1.103 → 0.1.104
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 +39 -14
- package/dist/index.d.ts +19 -3
- package/dist/index.mjs +39 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -549,17 +549,20 @@ function toAnnotationTokens(name, value, spec) {
|
|
|
549
549
|
if (typeof value === "boolean") return {
|
|
550
550
|
name,
|
|
551
551
|
token: dummyToken,
|
|
552
|
-
args: []
|
|
552
|
+
args: [],
|
|
553
|
+
intrinsic: true
|
|
553
554
|
};
|
|
554
555
|
if (typeof value === "string") return {
|
|
555
556
|
name,
|
|
556
557
|
token: dummyToken,
|
|
557
|
-
args: [text$1(value)]
|
|
558
|
+
args: [text$1(value)],
|
|
559
|
+
intrinsic: true
|
|
558
560
|
};
|
|
559
561
|
if (typeof value === "number") return {
|
|
560
562
|
name,
|
|
561
563
|
token: dummyToken,
|
|
562
|
-
args: [num(value)]
|
|
564
|
+
args: [num(value)],
|
|
565
|
+
intrinsic: true
|
|
563
566
|
};
|
|
564
567
|
const raw = (spec?.arguments.map((a) => a.name) ?? Object.keys(value)).map((argName) => {
|
|
565
568
|
const v = value[argName];
|
|
@@ -570,7 +573,8 @@ function toAnnotationTokens(name, value, spec) {
|
|
|
570
573
|
return {
|
|
571
574
|
name,
|
|
572
575
|
token: dummyToken,
|
|
573
|
-
args: raw.map((t) => t ?? text$1(""))
|
|
576
|
+
args: raw.map((t) => t ?? text$1("")),
|
|
577
|
+
intrinsic: true
|
|
574
578
|
};
|
|
575
579
|
}
|
|
576
580
|
const dummyToken = new Token({
|
|
@@ -4213,37 +4217,58 @@ var AtscriptDoc = class AtscriptDoc {
|
|
|
4213
4217
|
const token = this.tokensIndex.at(line, character);
|
|
4214
4218
|
if (token) return this.usageListFor(token, character);
|
|
4215
4219
|
}
|
|
4216
|
-
evalAnnotationsForNode(givenNode) {
|
|
4217
|
-
let right =
|
|
4220
|
+
evalAnnotationsForNode(givenNode, own = givenNode.annotations) {
|
|
4221
|
+
let right = own;
|
|
4218
4222
|
let def = givenNode.getDefinition();
|
|
4219
4223
|
if (def) {
|
|
4220
4224
|
const refDef = isRef(def) ? def : void 0;
|
|
4225
|
+
let viaProp = false;
|
|
4221
4226
|
if (refDef) {
|
|
4222
4227
|
const chainNodes = [];
|
|
4223
4228
|
const unwound = this.unwindType(refDef.token("identifier").text, refDef.chain, (intermediate) => {
|
|
4229
|
+
if (isProp(intermediate) && intermediate !== givenNode) viaProp = true;
|
|
4224
4230
|
if (intermediate?.annotations?.length) chainNodes.push(intermediate);
|
|
4225
4231
|
});
|
|
4226
|
-
if (unwound?.node && unwound.node !== givenNode
|
|
4227
|
-
|
|
4232
|
+
if (unwound?.node && unwound.node !== givenNode) {
|
|
4233
|
+
viaProp || (viaProp = isProp(unwound.node));
|
|
4234
|
+
if (unwound.node.annotations?.length && !chainNodes.includes(unwound.node)) chainNodes.unshift(unwound.node);
|
|
4235
|
+
}
|
|
4236
|
+
for (const chainNode of chainNodes) {
|
|
4237
|
+
if (chainNode === unwound?.def) continue;
|
|
4238
|
+
right = this.mergeNodesAnnotations(this.filterPassedWhenReferred(chainNode.annotations, viaProp), right);
|
|
4239
|
+
}
|
|
4228
4240
|
def = unwound?.def || def;
|
|
4229
4241
|
}
|
|
4230
4242
|
if (def) {
|
|
4231
4243
|
const merged = this.mergeIntersection(def);
|
|
4232
|
-
right = this.mergeNodesAnnotations(refDef ? this.filterPassedWhenReferred(merged.annotations) : merged.annotations, right);
|
|
4244
|
+
right = this.mergeNodesAnnotations(refDef ? this.filterPassedWhenReferred(merged.annotations, viaProp) : merged.annotations, right);
|
|
4233
4245
|
}
|
|
4234
4246
|
}
|
|
4235
4247
|
return right;
|
|
4236
4248
|
}
|
|
4237
4249
|
/**
|
|
4250
|
+
* The annotations a reference to `node` (`field: Alias`) inherits: its evaluated
|
|
4251
|
+
* set without the `passedWhenReferred: false` ones. The node's own are filtered
|
|
4252
|
+
* before the merge, so a dropped one cannot shadow a primitive's intrinsic
|
|
4253
|
+
* annotation of the same name (`@meta.required 'msg'` on `type N = string.required`).
|
|
4254
|
+
*/ evalReferredAnnotations(node) {
|
|
4255
|
+
return this.filterPassedWhenReferred(this.evalAnnotationsForNode(node, this.filterPassedWhenReferred(node.annotations)));
|
|
4256
|
+
}
|
|
4257
|
+
/**
|
|
4238
4258
|
* Drops annotations whose spec declares `passedWhenReferred: false` — used
|
|
4239
4259
|
* when folding annotations across a ref boundary. Annotations without a
|
|
4240
|
-
* resolvable spec pass through (default is to inherit)
|
|
4260
|
+
* resolvable spec pass through (default is to inherit), and so do a
|
|
4261
|
+
* primitive's intrinsic ones (`number.timestamp.created` → `@db.default.now`)
|
|
4262
|
+
* unless the boundary is a reference to a prop (`viaProp`). Returns the input
|
|
4241
4263
|
* array unchanged when nothing is dropped.
|
|
4242
|
-
*/ filterPassedWhenReferred(annotations) {
|
|
4264
|
+
*/ filterPassedWhenReferred(annotations, viaProp = false) {
|
|
4243
4265
|
if (!annotations?.length) return annotations;
|
|
4244
4266
|
let filtered;
|
|
4245
|
-
for (let i = 0; i < annotations.length; i++)
|
|
4246
|
-
|
|
4267
|
+
for (let i = 0; i < annotations.length; i++) {
|
|
4268
|
+
const a = annotations[i];
|
|
4269
|
+
if ((viaProp || !a.intrinsic) && this.resolveAnnotation(a.name)?.config.passedWhenReferred === false) filtered ?? (filtered = annotations.slice(0, i));
|
|
4270
|
+
else filtered?.push(a);
|
|
4271
|
+
}
|
|
4247
4272
|
return filtered ?? annotations;
|
|
4248
4273
|
}
|
|
4249
4274
|
/**
|
|
@@ -5661,7 +5686,7 @@ const primitives = {
|
|
|
5661
5686
|
annotations: { "db.default.now": true }
|
|
5662
5687
|
},
|
|
5663
5688
|
updated: {
|
|
5664
|
-
documentation: "
|
|
5689
|
+
documentation: "Last-modified timestamp (tag \"updated\"). A marker only: it carries no default and is not set on write.",
|
|
5665
5690
|
tags: ["updated"]
|
|
5666
5691
|
}
|
|
5667
5692
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -291,6 +291,13 @@ interface TAnnotationTokens {
|
|
|
291
291
|
name: string;
|
|
292
292
|
token: Token;
|
|
293
293
|
args: Token[];
|
|
294
|
+
/**
|
|
295
|
+
* Built into a primitive extension (`number.timestamp.created` → `@db.default.now`,
|
|
296
|
+
* `string.required` → `@meta.required`). Part of the type itself, so it follows
|
|
297
|
+
* type references and aliases even when its spec sets `passedWhenReferred: false`;
|
|
298
|
+
* only a reference to a prop (`User.createdAt`) drops such an annotation.
|
|
299
|
+
*/
|
|
300
|
+
intrinsic?: true;
|
|
294
301
|
}
|
|
295
302
|
type TPrimitiveAnnotationArg = string | number | boolean;
|
|
296
303
|
type TPrimitiveAnnotationArgs = Record<string, TPrimitiveAnnotationArg>;
|
|
@@ -595,14 +602,23 @@ declare class AtscriptDoc {
|
|
|
595
602
|
range: Token["range"];
|
|
596
603
|
token: Token;
|
|
597
604
|
}[] | undefined;
|
|
598
|
-
evalAnnotationsForNode(givenNode: SemanticNode): TAnnotationTokens[] | undefined;
|
|
605
|
+
evalAnnotationsForNode(givenNode: SemanticNode, own?: TAnnotationTokens[] | undefined): TAnnotationTokens[] | undefined;
|
|
606
|
+
/**
|
|
607
|
+
* The annotations a reference to `node` (`field: Alias`) inherits: its evaluated
|
|
608
|
+
* set without the `passedWhenReferred: false` ones. The node's own are filtered
|
|
609
|
+
* before the merge, so a dropped one cannot shadow a primitive's intrinsic
|
|
610
|
+
* annotation of the same name (`@meta.required 'msg'` on `type N = string.required`).
|
|
611
|
+
*/
|
|
612
|
+
evalReferredAnnotations(node: SemanticNode): TAnnotationTokens[] | undefined;
|
|
599
613
|
/**
|
|
600
614
|
* Drops annotations whose spec declares `passedWhenReferred: false` — used
|
|
601
615
|
* when folding annotations across a ref boundary. Annotations without a
|
|
602
|
-
* resolvable spec pass through (default is to inherit)
|
|
616
|
+
* resolvable spec pass through (default is to inherit), and so do a
|
|
617
|
+
* primitive's intrinsic ones (`number.timestamp.created` → `@db.default.now`)
|
|
618
|
+
* unless the boundary is a reference to a prop (`viaProp`). Returns the input
|
|
603
619
|
* array unchanged when nothing is dropped.
|
|
604
620
|
*/
|
|
605
|
-
filterPassedWhenReferred(annotations?: TAnnotationTokens[]): TAnnotationTokens[] | undefined;
|
|
621
|
+
filterPassedWhenReferred(annotations?: TAnnotationTokens[], viaProp?: boolean): TAnnotationTokens[] | undefined;
|
|
606
622
|
/**
|
|
607
623
|
* If the position falls inside an `annotate` block, returns that block's node
|
|
608
624
|
* (whose `targetName` is the annotated interface). Entry refs within the block
|
package/dist/index.mjs
CHANGED
|
@@ -518,17 +518,20 @@ function toAnnotationTokens(name, value, spec) {
|
|
|
518
518
|
if (typeof value === "boolean") return {
|
|
519
519
|
name,
|
|
520
520
|
token: dummyToken,
|
|
521
|
-
args: []
|
|
521
|
+
args: [],
|
|
522
|
+
intrinsic: true
|
|
522
523
|
};
|
|
523
524
|
if (typeof value === "string") return {
|
|
524
525
|
name,
|
|
525
526
|
token: dummyToken,
|
|
526
|
-
args: [text$1(value)]
|
|
527
|
+
args: [text$1(value)],
|
|
528
|
+
intrinsic: true
|
|
527
529
|
};
|
|
528
530
|
if (typeof value === "number") return {
|
|
529
531
|
name,
|
|
530
532
|
token: dummyToken,
|
|
531
|
-
args: [num(value)]
|
|
533
|
+
args: [num(value)],
|
|
534
|
+
intrinsic: true
|
|
532
535
|
};
|
|
533
536
|
const raw = (spec?.arguments.map((a) => a.name) ?? Object.keys(value)).map((argName) => {
|
|
534
537
|
const v = value[argName];
|
|
@@ -539,7 +542,8 @@ function toAnnotationTokens(name, value, spec) {
|
|
|
539
542
|
return {
|
|
540
543
|
name,
|
|
541
544
|
token: dummyToken,
|
|
542
|
-
args: raw.map((t) => t ?? text$1(""))
|
|
545
|
+
args: raw.map((t) => t ?? text$1("")),
|
|
546
|
+
intrinsic: true
|
|
543
547
|
};
|
|
544
548
|
}
|
|
545
549
|
const dummyToken = new Token({
|
|
@@ -4182,37 +4186,58 @@ var AtscriptDoc = class AtscriptDoc {
|
|
|
4182
4186
|
const token = this.tokensIndex.at(line, character);
|
|
4183
4187
|
if (token) return this.usageListFor(token, character);
|
|
4184
4188
|
}
|
|
4185
|
-
evalAnnotationsForNode(givenNode) {
|
|
4186
|
-
let right =
|
|
4189
|
+
evalAnnotationsForNode(givenNode, own = givenNode.annotations) {
|
|
4190
|
+
let right = own;
|
|
4187
4191
|
let def = givenNode.getDefinition();
|
|
4188
4192
|
if (def) {
|
|
4189
4193
|
const refDef = isRef(def) ? def : void 0;
|
|
4194
|
+
let viaProp = false;
|
|
4190
4195
|
if (refDef) {
|
|
4191
4196
|
const chainNodes = [];
|
|
4192
4197
|
const unwound = this.unwindType(refDef.token("identifier").text, refDef.chain, (intermediate) => {
|
|
4198
|
+
if (isProp(intermediate) && intermediate !== givenNode) viaProp = true;
|
|
4193
4199
|
if (intermediate?.annotations?.length) chainNodes.push(intermediate);
|
|
4194
4200
|
});
|
|
4195
|
-
if (unwound?.node && unwound.node !== givenNode
|
|
4196
|
-
|
|
4201
|
+
if (unwound?.node && unwound.node !== givenNode) {
|
|
4202
|
+
viaProp || (viaProp = isProp(unwound.node));
|
|
4203
|
+
if (unwound.node.annotations?.length && !chainNodes.includes(unwound.node)) chainNodes.unshift(unwound.node);
|
|
4204
|
+
}
|
|
4205
|
+
for (const chainNode of chainNodes) {
|
|
4206
|
+
if (chainNode === unwound?.def) continue;
|
|
4207
|
+
right = this.mergeNodesAnnotations(this.filterPassedWhenReferred(chainNode.annotations, viaProp), right);
|
|
4208
|
+
}
|
|
4197
4209
|
def = unwound?.def || def;
|
|
4198
4210
|
}
|
|
4199
4211
|
if (def) {
|
|
4200
4212
|
const merged = this.mergeIntersection(def);
|
|
4201
|
-
right = this.mergeNodesAnnotations(refDef ? this.filterPassedWhenReferred(merged.annotations) : merged.annotations, right);
|
|
4213
|
+
right = this.mergeNodesAnnotations(refDef ? this.filterPassedWhenReferred(merged.annotations, viaProp) : merged.annotations, right);
|
|
4202
4214
|
}
|
|
4203
4215
|
}
|
|
4204
4216
|
return right;
|
|
4205
4217
|
}
|
|
4206
4218
|
/**
|
|
4219
|
+
* The annotations a reference to `node` (`field: Alias`) inherits: its evaluated
|
|
4220
|
+
* set without the `passedWhenReferred: false` ones. The node's own are filtered
|
|
4221
|
+
* before the merge, so a dropped one cannot shadow a primitive's intrinsic
|
|
4222
|
+
* annotation of the same name (`@meta.required 'msg'` on `type N = string.required`).
|
|
4223
|
+
*/ evalReferredAnnotations(node) {
|
|
4224
|
+
return this.filterPassedWhenReferred(this.evalAnnotationsForNode(node, this.filterPassedWhenReferred(node.annotations)));
|
|
4225
|
+
}
|
|
4226
|
+
/**
|
|
4207
4227
|
* Drops annotations whose spec declares `passedWhenReferred: false` — used
|
|
4208
4228
|
* when folding annotations across a ref boundary. Annotations without a
|
|
4209
|
-
* resolvable spec pass through (default is to inherit)
|
|
4229
|
+
* resolvable spec pass through (default is to inherit), and so do a
|
|
4230
|
+
* primitive's intrinsic ones (`number.timestamp.created` → `@db.default.now`)
|
|
4231
|
+
* unless the boundary is a reference to a prop (`viaProp`). Returns the input
|
|
4210
4232
|
* array unchanged when nothing is dropped.
|
|
4211
|
-
*/ filterPassedWhenReferred(annotations) {
|
|
4233
|
+
*/ filterPassedWhenReferred(annotations, viaProp = false) {
|
|
4212
4234
|
if (!annotations?.length) return annotations;
|
|
4213
4235
|
let filtered;
|
|
4214
|
-
for (let i = 0; i < annotations.length; i++)
|
|
4215
|
-
|
|
4236
|
+
for (let i = 0; i < annotations.length; i++) {
|
|
4237
|
+
const a = annotations[i];
|
|
4238
|
+
if ((viaProp || !a.intrinsic) && this.resolveAnnotation(a.name)?.config.passedWhenReferred === false) filtered ?? (filtered = annotations.slice(0, i));
|
|
4239
|
+
else filtered?.push(a);
|
|
4240
|
+
}
|
|
4216
4241
|
return filtered ?? annotations;
|
|
4217
4242
|
}
|
|
4218
4243
|
/**
|
|
@@ -5630,7 +5655,7 @@ const primitives = {
|
|
|
5630
5655
|
annotations: { "db.default.now": true }
|
|
5631
5656
|
},
|
|
5632
5657
|
updated: {
|
|
5633
|
-
documentation: "
|
|
5658
|
+
documentation: "Last-modified timestamp (tag \"updated\"). A marker only: it carries no default and is not set on write.",
|
|
5634
5659
|
tags: ["updated"]
|
|
5635
5660
|
}
|
|
5636
5661
|
}
|