@atscript/core 0.1.29 → 0.1.30
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 +149 -12
- package/dist/index.d.ts +38 -27
- package/dist/index.mjs +149 -12
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ const fs_promises = __toESM(require("fs/promises"));
|
|
|
35
35
|
const glob = __toESM(require("glob"));
|
|
36
36
|
|
|
37
37
|
//#region packages/core/src/parser/nodes/semantic-node.ts
|
|
38
|
-
function _define_property$
|
|
38
|
+
function _define_property$15(obj, key, value) {
|
|
39
39
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
40
40
|
value,
|
|
41
41
|
enumerable: true,
|
|
@@ -145,14 +145,14 @@ else this.annotationsCounter.set(name, 1);
|
|
|
145
145
|
return this.definition;
|
|
146
146
|
}
|
|
147
147
|
constructor(entity) {
|
|
148
|
-
_define_property$
|
|
149
|
-
_define_property$
|
|
150
|
-
_define_property$
|
|
151
|
-
_define_property$
|
|
152
|
-
_define_property$
|
|
153
|
-
_define_property$
|
|
154
|
-
_define_property$
|
|
155
|
-
_define_property$
|
|
148
|
+
_define_property$15(this, "entity", void 0);
|
|
149
|
+
_define_property$15(this, "tokens", void 0);
|
|
150
|
+
_define_property$15(this, "isGroup", void 0);
|
|
151
|
+
_define_property$15(this, "definition", void 0);
|
|
152
|
+
_define_property$15(this, "annotations", void 0);
|
|
153
|
+
_define_property$15(this, "annotationsCounter", void 0);
|
|
154
|
+
_define_property$15(this, "__typeId", void 0);
|
|
155
|
+
_define_property$15(this, "_documentation", void 0);
|
|
156
156
|
this.entity = entity;
|
|
157
157
|
this.isGroup = false;
|
|
158
158
|
}
|
|
@@ -249,7 +249,7 @@ var SemanticConstNode = class extends SemanticNode {
|
|
|
249
249
|
|
|
250
250
|
//#endregion
|
|
251
251
|
//#region packages/core/src/parser/nodes/group-node.ts
|
|
252
|
-
function _define_property$
|
|
252
|
+
function _define_property$14(obj, key, value) {
|
|
253
253
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
254
254
|
value,
|
|
255
255
|
enumerable: true,
|
|
@@ -294,7 +294,7 @@ var SemanticGroup = class extends SemanticNode {
|
|
|
294
294
|
return s;
|
|
295
295
|
}
|
|
296
296
|
constructor(nodes = [], operator) {
|
|
297
|
-
super("group"), _define_property$
|
|
297
|
+
super("group"), _define_property$14(this, "nodes", void 0), _define_property$14(this, "operator", void 0), _define_property$14(this, "isGroup", void 0), this.nodes = nodes, this.operator = operator, this.isGroup = true;
|
|
298
298
|
}
|
|
299
299
|
};
|
|
300
300
|
|
|
@@ -316,7 +316,26 @@ var SemanticImportNode = class extends SemanticNode {
|
|
|
316
316
|
|
|
317
317
|
//#endregion
|
|
318
318
|
//#region packages/core/src/parser/nodes/interface-node.ts
|
|
319
|
+
function _define_property$13(obj, key, value) {
|
|
320
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
321
|
+
value,
|
|
322
|
+
enumerable: true,
|
|
323
|
+
configurable: true,
|
|
324
|
+
writable: true
|
|
325
|
+
});
|
|
326
|
+
else obj[key] = value;
|
|
327
|
+
return obj;
|
|
328
|
+
}
|
|
319
329
|
var SemanticInterfaceNode = class extends SemanticNode {
|
|
330
|
+
addExtendsToken(token) {
|
|
331
|
+
this._extendsTokens.push(token);
|
|
332
|
+
}
|
|
333
|
+
get extendsTokens() {
|
|
334
|
+
return this._extendsTokens;
|
|
335
|
+
}
|
|
336
|
+
get hasExtends() {
|
|
337
|
+
return this._extendsTokens.length > 0;
|
|
338
|
+
}
|
|
320
339
|
registerAtDocument(doc) {
|
|
321
340
|
super.registerAtDocument(doc);
|
|
322
341
|
this.__typeId = doc.nextTypeId();
|
|
@@ -326,13 +345,26 @@ var SemanticInterfaceNode = class extends SemanticNode {
|
|
|
326
345
|
token.exported = true;
|
|
327
346
|
doc.registerExport(this);
|
|
328
347
|
}
|
|
348
|
+
for (const t of this._extendsTokens) {
|
|
349
|
+
t.isReference = true;
|
|
350
|
+
doc.referred.push(t);
|
|
351
|
+
doc.tokensIndex.add(t);
|
|
352
|
+
}
|
|
329
353
|
}
|
|
330
354
|
get props() {
|
|
331
355
|
if (this.definition) return isStructure(this.definition) ? this.definition.props : new Map();
|
|
332
356
|
return new Map();
|
|
333
357
|
}
|
|
358
|
+
toString(level = 0, prefix = "●") {
|
|
359
|
+
let s = super.toString(level, prefix);
|
|
360
|
+
if (this._extendsTokens.length > 0) {
|
|
361
|
+
const extendsStr = this._extendsTokens.map((t) => t.text).join(", ");
|
|
362
|
+
s = s.replace("[interface]", `[interface extends ${extendsStr}]`);
|
|
363
|
+
}
|
|
364
|
+
return s;
|
|
365
|
+
}
|
|
334
366
|
constructor() {
|
|
335
|
-
super("interface");
|
|
367
|
+
super("interface"), _define_property$13(this, "_extendsTokens", []);
|
|
336
368
|
}
|
|
337
369
|
};
|
|
338
370
|
|
|
@@ -1980,6 +2012,38 @@ function parseRegExpLiteral(literal) {
|
|
|
1980
2012
|
const [, pattern, flags] = match;
|
|
1981
2013
|
return new RegExp(pattern.replace(/\\\//g, "/"), flags);
|
|
1982
2014
|
}
|
|
2015
|
+
function extendsClause() {
|
|
2016
|
+
const s = {
|
|
2017
|
+
extends: {
|
|
2018
|
+
node: "identifier",
|
|
2019
|
+
text: "extends"
|
|
2020
|
+
},
|
|
2021
|
+
comma: {
|
|
2022
|
+
node: "punctuation",
|
|
2023
|
+
text: ","
|
|
2024
|
+
},
|
|
2025
|
+
id: { node: "identifier" }
|
|
2026
|
+
};
|
|
2027
|
+
return { handler(ni, target) {
|
|
2028
|
+
if (!ni.$ || !ni.satisfies(s.extends)) return true;
|
|
2029
|
+
ni.accepted();
|
|
2030
|
+
ni.move();
|
|
2031
|
+
ni.skip(["\n"]);
|
|
2032
|
+
const node = target.node;
|
|
2033
|
+
while (ni.$ && ni.satisfies(s.id)) {
|
|
2034
|
+
node.addExtendsToken(new Token(ni.$));
|
|
2035
|
+
ni.accepted();
|
|
2036
|
+
ni.move();
|
|
2037
|
+
ni.skip(["\n"]);
|
|
2038
|
+
if (ni.$ && ni.satisfies(s.comma)) {
|
|
2039
|
+
ni.accepted();
|
|
2040
|
+
ni.move();
|
|
2041
|
+
ni.skip(["\n"]);
|
|
2042
|
+
} else break;
|
|
2043
|
+
}
|
|
2044
|
+
return true;
|
|
2045
|
+
} };
|
|
2046
|
+
}
|
|
1983
2047
|
|
|
1984
2048
|
//#endregion
|
|
1985
2049
|
//#region packages/core/src/parser/pipes/pipes.ts
|
|
@@ -2035,6 +2099,7 @@ const interfaceType = $pipe("interface", [
|
|
|
2035
2099
|
identifier("export").saveAs("export").optional().skip("\n"),
|
|
2036
2100
|
identifier("interface").saveAs("type").skip("\n").suppressEobError(),
|
|
2037
2101
|
identifier().saveAs("identifier").global().skip("\n"),
|
|
2102
|
+
extendsClause(),
|
|
2038
2103
|
definition([structureBlock()])
|
|
2039
2104
|
]).skip("\n", ";");
|
|
2040
2105
|
function defineValuePipe(entity, name, supportArray = false) {
|
|
@@ -2467,6 +2532,38 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2467
2532
|
for (const node of this.nodes) if (isAnnotate(node) && node.targetName === targetName) result.push(node);
|
|
2468
2533
|
return result;
|
|
2469
2534
|
}
|
|
2535
|
+
/**
|
|
2536
|
+
* Resolves an interface with `extends` by merging parent structures with own props.
|
|
2537
|
+
* Parents are merged left-to-right, then own props overlay on top (own takes priority).
|
|
2538
|
+
* Only merges props and their annotations; interface-level annotations are NOT inherited.
|
|
2539
|
+
*/ resolveInterfaceExtends(node, _visited) {
|
|
2540
|
+
if (!node.hasExtends) return undefined;
|
|
2541
|
+
const visited = _visited || new Set();
|
|
2542
|
+
if (node.id && visited.has(node.id)) return undefined;
|
|
2543
|
+
if (node.id) visited.add(node.id);
|
|
2544
|
+
let mergedStruct;
|
|
2545
|
+
for (const extendsToken of node.extendsTokens) {
|
|
2546
|
+
const unwound = this.unwindType(extendsToken.text);
|
|
2547
|
+
if (!unwound?.def) continue;
|
|
2548
|
+
let parentDef = unwound.def;
|
|
2549
|
+
if (isInterface(parentDef) && parentDef.hasExtends) {
|
|
2550
|
+
const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited);
|
|
2551
|
+
parentDef = resolved || parentDef.getDefinition() || parentDef;
|
|
2552
|
+
} else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
|
|
2553
|
+
parentDef = this.mergeIntersection(parentDef);
|
|
2554
|
+
if (!mergedStruct) mergedStruct = parentDef;
|
|
2555
|
+
else {
|
|
2556
|
+
const merged = this.mergeDefs(mergedStruct, parentDef);
|
|
2557
|
+
mergedStruct = merged[0];
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
const ownDef = node.getDefinition();
|
|
2561
|
+
if (ownDef && mergedStruct) {
|
|
2562
|
+
const merged = this.mergeDefs(mergedStruct, ownDef);
|
|
2563
|
+
return merged[0];
|
|
2564
|
+
}
|
|
2565
|
+
return mergedStruct || ownDef;
|
|
2566
|
+
}
|
|
2470
2567
|
usageListFor(token) {
|
|
2471
2568
|
if (token.isDefinition) {
|
|
2472
2569
|
const refs = this.referred.filter((t) => t.text === token.text).map((r) => ({
|
|
@@ -2734,6 +2831,46 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2734
2831
|
...this.semanticMessages,
|
|
2735
2832
|
...this.messages
|
|
2736
2833
|
];
|
|
2834
|
+
for (const node of this.nodes) if (isInterface(node) && node.hasExtends) {
|
|
2835
|
+
const iface = node;
|
|
2836
|
+
for (const t of iface.extendsTokens) if (t.text === iface.id) this._allMessages.push({
|
|
2837
|
+
severity: TSeverity.Error,
|
|
2838
|
+
message: `Interface "${iface.id}" cannot extend itself`,
|
|
2839
|
+
range: t.range
|
|
2840
|
+
});
|
|
2841
|
+
const ownDef = iface.getDefinition();
|
|
2842
|
+
if (ownDef && isStructure(ownDef)) {
|
|
2843
|
+
const parentProps = new Map();
|
|
2844
|
+
for (const t of iface.extendsTokens) {
|
|
2845
|
+
if (t.text === iface.id) continue;
|
|
2846
|
+
const unwound = this.unwindType(t.text);
|
|
2847
|
+
if (!unwound?.def) continue;
|
|
2848
|
+
let parentDef = unwound.def;
|
|
2849
|
+
if (isInterface(parentDef)) {
|
|
2850
|
+
if (parentDef.hasExtends) {
|
|
2851
|
+
const resolved = unwound.doc.resolveInterfaceExtends(parentDef);
|
|
2852
|
+
if (resolved && isStructure(resolved)) {
|
|
2853
|
+
for (const [name] of resolved.props) parentProps.set(name, t.text);
|
|
2854
|
+
continue;
|
|
2855
|
+
}
|
|
2856
|
+
}
|
|
2857
|
+
parentDef = parentDef.getDefinition() || parentDef;
|
|
2858
|
+
}
|
|
2859
|
+
if (isStructure(parentDef)) for (const [name] of parentDef.props) parentProps.set(name, t.text);
|
|
2860
|
+
}
|
|
2861
|
+
for (const [name, prop] of ownDef.props) {
|
|
2862
|
+
const parentName = parentProps.get(name);
|
|
2863
|
+
if (parentName) {
|
|
2864
|
+
const propToken = prop.token("identifier");
|
|
2865
|
+
if (propToken) this._allMessages.push({
|
|
2866
|
+
severity: TSeverity.Error,
|
|
2867
|
+
message: `Property "${name}" already exists in parent "${parentName}" — override in extends is not allowed`,
|
|
2868
|
+
range: propToken.range
|
|
2869
|
+
});
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2737
2874
|
for (const t of this.referred) {
|
|
2738
2875
|
const block$2 = this.blocksIndex.at(t.range.start.line, t.range.start.character);
|
|
2739
2876
|
if (block$2?.blockType === "annotate" && isAnnotate(block$2.parentNode)) {
|
package/dist/index.d.ts
CHANGED
|
@@ -315,6 +315,38 @@ declare class SemanticNode {
|
|
|
315
315
|
getDefinition(): SemanticNode | undefined;
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
+
declare class SemanticRefNode extends SemanticNode {
|
|
319
|
+
constructor();
|
|
320
|
+
get referredIdentifiers(): Token[];
|
|
321
|
+
protected _chain: Token[];
|
|
322
|
+
protected _dots: Token[];
|
|
323
|
+
registerAtDocument(doc: AtscriptDoc): void;
|
|
324
|
+
addChain(token: Token): void;
|
|
325
|
+
addDot(token: Token): void;
|
|
326
|
+
get chain(): Token[];
|
|
327
|
+
get hasChain(): boolean;
|
|
328
|
+
toString(level?: number, prefix?: string): string;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
declare class SemanticPropNode extends SemanticNode {
|
|
332
|
+
constructor();
|
|
333
|
+
registerAtDocument(doc: AtscriptDoc): void;
|
|
334
|
+
get isPattern(): boolean;
|
|
335
|
+
get nestedProps(): Map<string, SemanticPropNode> | undefined;
|
|
336
|
+
get nestedType(): SemanticRefNode | undefined;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
declare class SemanticInterfaceNode extends SemanticNode {
|
|
340
|
+
private _extendsTokens;
|
|
341
|
+
constructor();
|
|
342
|
+
addExtendsToken(token: Token): void;
|
|
343
|
+
get extendsTokens(): Token[];
|
|
344
|
+
get hasExtends(): boolean;
|
|
345
|
+
registerAtDocument(doc: AtscriptDoc): void;
|
|
346
|
+
get props(): Map<string, SemanticPropNode>;
|
|
347
|
+
toString(level?: number, prefix?: string): string;
|
|
348
|
+
}
|
|
349
|
+
|
|
318
350
|
declare class SemanticPrimitiveNode extends SemanticNode {
|
|
319
351
|
private readonly _id;
|
|
320
352
|
readonly config: TPrimitiveConfig;
|
|
@@ -462,6 +494,12 @@ declare class AtscriptDoc {
|
|
|
462
494
|
* For entries without a chain (root-level), the key is the entry identifier.
|
|
463
495
|
*/
|
|
464
496
|
getAnnotateNodesFor(targetName: string): SemanticAnnotateNode[];
|
|
497
|
+
/**
|
|
498
|
+
* Resolves an interface with `extends` by merging parent structures with own props.
|
|
499
|
+
* Parents are merged left-to-right, then own props overlay on top (own takes priority).
|
|
500
|
+
* Only merges props and their annotations; interface-level annotations are NOT inherited.
|
|
501
|
+
*/
|
|
502
|
+
resolveInterfaceExtends(node: SemanticInterfaceNode, _visited?: Set<string>): SemanticNode | undefined;
|
|
465
503
|
usageListFor(token: Token): Array<{
|
|
466
504
|
uri: string;
|
|
467
505
|
range: Token['range'];
|
|
@@ -585,19 +623,6 @@ declare class AtscriptDoc {
|
|
|
585
623
|
mergeNodesAnnotations(left?: TAnnotationTokens[], right?: TAnnotationTokens[]): TAnnotationTokens[];
|
|
586
624
|
}
|
|
587
625
|
|
|
588
|
-
declare class SemanticRefNode extends SemanticNode {
|
|
589
|
-
constructor();
|
|
590
|
-
get referredIdentifiers(): Token[];
|
|
591
|
-
protected _chain: Token[];
|
|
592
|
-
protected _dots: Token[];
|
|
593
|
-
registerAtDocument(doc: AtscriptDoc): void;
|
|
594
|
-
addChain(token: Token): void;
|
|
595
|
-
addDot(token: Token): void;
|
|
596
|
-
get chain(): Token[];
|
|
597
|
-
get hasChain(): boolean;
|
|
598
|
-
toString(level?: number, prefix?: string): string;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
626
|
declare class SemanticAnnotateNode extends SemanticNode {
|
|
602
627
|
constructor();
|
|
603
628
|
get isMutating(): boolean;
|
|
@@ -637,20 +662,6 @@ declare class SemanticImportNode extends SemanticNode {
|
|
|
637
662
|
registerAtDocument(doc: AtscriptDoc): void;
|
|
638
663
|
}
|
|
639
664
|
|
|
640
|
-
declare class SemanticPropNode extends SemanticNode {
|
|
641
|
-
constructor();
|
|
642
|
-
registerAtDocument(doc: AtscriptDoc): void;
|
|
643
|
-
get isPattern(): boolean;
|
|
644
|
-
get nestedProps(): Map<string, SemanticPropNode> | undefined;
|
|
645
|
-
get nestedType(): SemanticRefNode | undefined;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
declare class SemanticInterfaceNode extends SemanticNode {
|
|
649
|
-
constructor();
|
|
650
|
-
registerAtDocument(doc: AtscriptDoc): void;
|
|
651
|
-
get props(): Map<string, SemanticPropNode>;
|
|
652
|
-
}
|
|
653
|
-
|
|
654
665
|
declare class SemanticStructureNode extends SemanticGroup {
|
|
655
666
|
constructor();
|
|
656
667
|
readonly props: Map<string, SemanticPropNode>;
|
package/dist/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { mkdir, writeFile } from "fs/promises";
|
|
|
11
11
|
import { glob } from "glob";
|
|
12
12
|
|
|
13
13
|
//#region packages/core/src/parser/nodes/semantic-node.ts
|
|
14
|
-
function _define_property$
|
|
14
|
+
function _define_property$15(obj, key, value) {
|
|
15
15
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
16
16
|
value,
|
|
17
17
|
enumerable: true,
|
|
@@ -121,14 +121,14 @@ else this.annotationsCounter.set(name, 1);
|
|
|
121
121
|
return this.definition;
|
|
122
122
|
}
|
|
123
123
|
constructor(entity) {
|
|
124
|
-
_define_property$
|
|
125
|
-
_define_property$
|
|
126
|
-
_define_property$
|
|
127
|
-
_define_property$
|
|
128
|
-
_define_property$
|
|
129
|
-
_define_property$
|
|
130
|
-
_define_property$
|
|
131
|
-
_define_property$
|
|
124
|
+
_define_property$15(this, "entity", void 0);
|
|
125
|
+
_define_property$15(this, "tokens", void 0);
|
|
126
|
+
_define_property$15(this, "isGroup", void 0);
|
|
127
|
+
_define_property$15(this, "definition", void 0);
|
|
128
|
+
_define_property$15(this, "annotations", void 0);
|
|
129
|
+
_define_property$15(this, "annotationsCounter", void 0);
|
|
130
|
+
_define_property$15(this, "__typeId", void 0);
|
|
131
|
+
_define_property$15(this, "_documentation", void 0);
|
|
132
132
|
this.entity = entity;
|
|
133
133
|
this.isGroup = false;
|
|
134
134
|
}
|
|
@@ -225,7 +225,7 @@ var SemanticConstNode = class extends SemanticNode {
|
|
|
225
225
|
|
|
226
226
|
//#endregion
|
|
227
227
|
//#region packages/core/src/parser/nodes/group-node.ts
|
|
228
|
-
function _define_property$
|
|
228
|
+
function _define_property$14(obj, key, value) {
|
|
229
229
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
230
230
|
value,
|
|
231
231
|
enumerable: true,
|
|
@@ -270,7 +270,7 @@ var SemanticGroup = class extends SemanticNode {
|
|
|
270
270
|
return s;
|
|
271
271
|
}
|
|
272
272
|
constructor(nodes = [], operator) {
|
|
273
|
-
super("group"), _define_property$
|
|
273
|
+
super("group"), _define_property$14(this, "nodes", void 0), _define_property$14(this, "operator", void 0), _define_property$14(this, "isGroup", void 0), this.nodes = nodes, this.operator = operator, this.isGroup = true;
|
|
274
274
|
}
|
|
275
275
|
};
|
|
276
276
|
|
|
@@ -292,7 +292,26 @@ var SemanticImportNode = class extends SemanticNode {
|
|
|
292
292
|
|
|
293
293
|
//#endregion
|
|
294
294
|
//#region packages/core/src/parser/nodes/interface-node.ts
|
|
295
|
+
function _define_property$13(obj, key, value) {
|
|
296
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
297
|
+
value,
|
|
298
|
+
enumerable: true,
|
|
299
|
+
configurable: true,
|
|
300
|
+
writable: true
|
|
301
|
+
});
|
|
302
|
+
else obj[key] = value;
|
|
303
|
+
return obj;
|
|
304
|
+
}
|
|
295
305
|
var SemanticInterfaceNode = class extends SemanticNode {
|
|
306
|
+
addExtendsToken(token) {
|
|
307
|
+
this._extendsTokens.push(token);
|
|
308
|
+
}
|
|
309
|
+
get extendsTokens() {
|
|
310
|
+
return this._extendsTokens;
|
|
311
|
+
}
|
|
312
|
+
get hasExtends() {
|
|
313
|
+
return this._extendsTokens.length > 0;
|
|
314
|
+
}
|
|
296
315
|
registerAtDocument(doc) {
|
|
297
316
|
super.registerAtDocument(doc);
|
|
298
317
|
this.__typeId = doc.nextTypeId();
|
|
@@ -302,13 +321,26 @@ var SemanticInterfaceNode = class extends SemanticNode {
|
|
|
302
321
|
token.exported = true;
|
|
303
322
|
doc.registerExport(this);
|
|
304
323
|
}
|
|
324
|
+
for (const t of this._extendsTokens) {
|
|
325
|
+
t.isReference = true;
|
|
326
|
+
doc.referred.push(t);
|
|
327
|
+
doc.tokensIndex.add(t);
|
|
328
|
+
}
|
|
305
329
|
}
|
|
306
330
|
get props() {
|
|
307
331
|
if (this.definition) return isStructure(this.definition) ? this.definition.props : new Map();
|
|
308
332
|
return new Map();
|
|
309
333
|
}
|
|
334
|
+
toString(level = 0, prefix = "●") {
|
|
335
|
+
let s = super.toString(level, prefix);
|
|
336
|
+
if (this._extendsTokens.length > 0) {
|
|
337
|
+
const extendsStr = this._extendsTokens.map((t) => t.text).join(", ");
|
|
338
|
+
s = s.replace("[interface]", `[interface extends ${extendsStr}]`);
|
|
339
|
+
}
|
|
340
|
+
return s;
|
|
341
|
+
}
|
|
310
342
|
constructor() {
|
|
311
|
-
super("interface");
|
|
343
|
+
super("interface"), _define_property$13(this, "_extendsTokens", []);
|
|
312
344
|
}
|
|
313
345
|
};
|
|
314
346
|
|
|
@@ -1956,6 +1988,38 @@ function parseRegExpLiteral(literal) {
|
|
|
1956
1988
|
const [, pattern, flags] = match;
|
|
1957
1989
|
return new RegExp(pattern.replace(/\\\//g, "/"), flags);
|
|
1958
1990
|
}
|
|
1991
|
+
function extendsClause() {
|
|
1992
|
+
const s = {
|
|
1993
|
+
extends: {
|
|
1994
|
+
node: "identifier",
|
|
1995
|
+
text: "extends"
|
|
1996
|
+
},
|
|
1997
|
+
comma: {
|
|
1998
|
+
node: "punctuation",
|
|
1999
|
+
text: ","
|
|
2000
|
+
},
|
|
2001
|
+
id: { node: "identifier" }
|
|
2002
|
+
};
|
|
2003
|
+
return { handler(ni, target) {
|
|
2004
|
+
if (!ni.$ || !ni.satisfies(s.extends)) return true;
|
|
2005
|
+
ni.accepted();
|
|
2006
|
+
ni.move();
|
|
2007
|
+
ni.skip(["\n"]);
|
|
2008
|
+
const node = target.node;
|
|
2009
|
+
while (ni.$ && ni.satisfies(s.id)) {
|
|
2010
|
+
node.addExtendsToken(new Token(ni.$));
|
|
2011
|
+
ni.accepted();
|
|
2012
|
+
ni.move();
|
|
2013
|
+
ni.skip(["\n"]);
|
|
2014
|
+
if (ni.$ && ni.satisfies(s.comma)) {
|
|
2015
|
+
ni.accepted();
|
|
2016
|
+
ni.move();
|
|
2017
|
+
ni.skip(["\n"]);
|
|
2018
|
+
} else break;
|
|
2019
|
+
}
|
|
2020
|
+
return true;
|
|
2021
|
+
} };
|
|
2022
|
+
}
|
|
1959
2023
|
|
|
1960
2024
|
//#endregion
|
|
1961
2025
|
//#region packages/core/src/parser/pipes/pipes.ts
|
|
@@ -2011,6 +2075,7 @@ const interfaceType = $pipe("interface", [
|
|
|
2011
2075
|
identifier("export").saveAs("export").optional().skip("\n"),
|
|
2012
2076
|
identifier("interface").saveAs("type").skip("\n").suppressEobError(),
|
|
2013
2077
|
identifier().saveAs("identifier").global().skip("\n"),
|
|
2078
|
+
extendsClause(),
|
|
2014
2079
|
definition([structureBlock()])
|
|
2015
2080
|
]).skip("\n", ";");
|
|
2016
2081
|
function defineValuePipe(entity, name, supportArray = false) {
|
|
@@ -2443,6 +2508,38 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2443
2508
|
for (const node of this.nodes) if (isAnnotate(node) && node.targetName === targetName) result.push(node);
|
|
2444
2509
|
return result;
|
|
2445
2510
|
}
|
|
2511
|
+
/**
|
|
2512
|
+
* Resolves an interface with `extends` by merging parent structures with own props.
|
|
2513
|
+
* Parents are merged left-to-right, then own props overlay on top (own takes priority).
|
|
2514
|
+
* Only merges props and their annotations; interface-level annotations are NOT inherited.
|
|
2515
|
+
*/ resolveInterfaceExtends(node, _visited) {
|
|
2516
|
+
if (!node.hasExtends) return undefined;
|
|
2517
|
+
const visited = _visited || new Set();
|
|
2518
|
+
if (node.id && visited.has(node.id)) return undefined;
|
|
2519
|
+
if (node.id) visited.add(node.id);
|
|
2520
|
+
let mergedStruct;
|
|
2521
|
+
for (const extendsToken of node.extendsTokens) {
|
|
2522
|
+
const unwound = this.unwindType(extendsToken.text);
|
|
2523
|
+
if (!unwound?.def) continue;
|
|
2524
|
+
let parentDef = unwound.def;
|
|
2525
|
+
if (isInterface(parentDef) && parentDef.hasExtends) {
|
|
2526
|
+
const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited);
|
|
2527
|
+
parentDef = resolved || parentDef.getDefinition() || parentDef;
|
|
2528
|
+
} else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
|
|
2529
|
+
parentDef = this.mergeIntersection(parentDef);
|
|
2530
|
+
if (!mergedStruct) mergedStruct = parentDef;
|
|
2531
|
+
else {
|
|
2532
|
+
const merged = this.mergeDefs(mergedStruct, parentDef);
|
|
2533
|
+
mergedStruct = merged[0];
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
const ownDef = node.getDefinition();
|
|
2537
|
+
if (ownDef && mergedStruct) {
|
|
2538
|
+
const merged = this.mergeDefs(mergedStruct, ownDef);
|
|
2539
|
+
return merged[0];
|
|
2540
|
+
}
|
|
2541
|
+
return mergedStruct || ownDef;
|
|
2542
|
+
}
|
|
2446
2543
|
usageListFor(token) {
|
|
2447
2544
|
if (token.isDefinition) {
|
|
2448
2545
|
const refs = this.referred.filter((t) => t.text === token.text).map((r) => ({
|
|
@@ -2710,6 +2807,46 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2710
2807
|
...this.semanticMessages,
|
|
2711
2808
|
...this.messages
|
|
2712
2809
|
];
|
|
2810
|
+
for (const node of this.nodes) if (isInterface(node) && node.hasExtends) {
|
|
2811
|
+
const iface = node;
|
|
2812
|
+
for (const t of iface.extendsTokens) if (t.text === iface.id) this._allMessages.push({
|
|
2813
|
+
severity: TSeverity.Error,
|
|
2814
|
+
message: `Interface "${iface.id}" cannot extend itself`,
|
|
2815
|
+
range: t.range
|
|
2816
|
+
});
|
|
2817
|
+
const ownDef = iface.getDefinition();
|
|
2818
|
+
if (ownDef && isStructure(ownDef)) {
|
|
2819
|
+
const parentProps = new Map();
|
|
2820
|
+
for (const t of iface.extendsTokens) {
|
|
2821
|
+
if (t.text === iface.id) continue;
|
|
2822
|
+
const unwound = this.unwindType(t.text);
|
|
2823
|
+
if (!unwound?.def) continue;
|
|
2824
|
+
let parentDef = unwound.def;
|
|
2825
|
+
if (isInterface(parentDef)) {
|
|
2826
|
+
if (parentDef.hasExtends) {
|
|
2827
|
+
const resolved = unwound.doc.resolveInterfaceExtends(parentDef);
|
|
2828
|
+
if (resolved && isStructure(resolved)) {
|
|
2829
|
+
for (const [name] of resolved.props) parentProps.set(name, t.text);
|
|
2830
|
+
continue;
|
|
2831
|
+
}
|
|
2832
|
+
}
|
|
2833
|
+
parentDef = parentDef.getDefinition() || parentDef;
|
|
2834
|
+
}
|
|
2835
|
+
if (isStructure(parentDef)) for (const [name] of parentDef.props) parentProps.set(name, t.text);
|
|
2836
|
+
}
|
|
2837
|
+
for (const [name, prop] of ownDef.props) {
|
|
2838
|
+
const parentName = parentProps.get(name);
|
|
2839
|
+
if (parentName) {
|
|
2840
|
+
const propToken = prop.token("identifier");
|
|
2841
|
+
if (propToken) this._allMessages.push({
|
|
2842
|
+
severity: TSeverity.Error,
|
|
2843
|
+
message: `Property "${name}" already exists in parent "${parentName}" — override in extends is not allowed`,
|
|
2844
|
+
range: propToken.range
|
|
2845
|
+
});
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
}
|
|
2849
|
+
}
|
|
2713
2850
|
for (const t of this.referred) {
|
|
2714
2851
|
const block$2 = this.blocksIndex.at(t.range.start.line, t.range.start.character);
|
|
2715
2852
|
if (block$2?.blockType === "annotate" && isAnnotate(block$2.parentNode)) {
|