@atscript/core 0.1.0 → 0.1.2
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 +46 -5
- package/dist/index.d.ts +9 -1
- package/dist/index.mjs +46 -5
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -2729,7 +2729,8 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2729
2729
|
if (!this.registry.isDefined(targetName)) continue;
|
|
2730
2730
|
const chain = isRef(t.parentNode) && t.parentNode.hasChain ? [t.text, ...t.parentNode.chain.map((c) => c.text)] : [t.text];
|
|
2731
2731
|
const unwound = this.unwindType(targetName, chain);
|
|
2732
|
-
|
|
2732
|
+
const chainResolved = unwound?.def && !isGroup(unwound.def);
|
|
2733
|
+
if (!chainResolved && !this.resolveChainWithMerge(targetName, chain)) {
|
|
2733
2734
|
const lastToken = chain.length > 1 && isRef(t.parentNode) ? t.parentNode.chain[t.parentNode.chain.length - 1] || t : t;
|
|
2734
2735
|
this._allMessages.push({
|
|
2735
2736
|
severity: 1,
|
|
@@ -2742,7 +2743,8 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2742
2743
|
const token = t.parentNode.chain[i];
|
|
2743
2744
|
const memberChain = [t.text, ...t.parentNode.chain.slice(0, i + 1).map((c) => c.text)];
|
|
2744
2745
|
const decl = this.unwindType(targetName, memberChain);
|
|
2745
|
-
|
|
2746
|
+
const memberResolved = decl?.def && !isGroup(decl.def);
|
|
2747
|
+
if (!memberResolved && !this.resolveChainWithMerge(targetName, memberChain)) this._allMessages.push({
|
|
2746
2748
|
severity: 1,
|
|
2747
2749
|
message: `Unknown property "${memberChain.join(".")}" in "${targetName}"`,
|
|
2748
2750
|
range: token.range
|
|
@@ -2786,6 +2788,45 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2786
2788
|
}
|
|
2787
2789
|
return this._allMessages;
|
|
2788
2790
|
}
|
|
2791
|
+
/**
|
|
2792
|
+
* Walks a property chain step-by-step, applying mergeIntersection at each
|
|
2793
|
+
* level. Mirrors the completion logic in the LSP server so that intersection
|
|
2794
|
+
* types like `{ a: string } & { b: number }` are handled correctly.
|
|
2795
|
+
*/ resolveChainWithMerge(targetName, chain) {
|
|
2796
|
+
let def = this.unwindType(targetName)?.def;
|
|
2797
|
+
if (!def) return false;
|
|
2798
|
+
for (const prop of chain) {
|
|
2799
|
+
def = this.mergeIntersection(def);
|
|
2800
|
+
if (isProp(def)) {
|
|
2801
|
+
const inner = def.getDefinition();
|
|
2802
|
+
if (inner) def = this.mergeIntersection(inner);
|
|
2803
|
+
}
|
|
2804
|
+
if (isStructure(def) || isInterface(def)) {
|
|
2805
|
+
const next = def.props.get(prop);
|
|
2806
|
+
if (!next) return false;
|
|
2807
|
+
def = next.getDefinition() || next;
|
|
2808
|
+
} else if (isGroup(def)) {
|
|
2809
|
+
const found = this.findPropInGroup(def, prop);
|
|
2810
|
+
if (!found) return false;
|
|
2811
|
+
def = found;
|
|
2812
|
+
} else return false;
|
|
2813
|
+
}
|
|
2814
|
+
return true;
|
|
2815
|
+
}
|
|
2816
|
+
findPropInGroup(group$1, propName$1) {
|
|
2817
|
+
for (const item of group$1.unwrap()) {
|
|
2818
|
+
const merged = this.mergeIntersection(item);
|
|
2819
|
+
if (isStructure(merged) || isInterface(merged)) {
|
|
2820
|
+
const prop = merged.props.get(propName$1);
|
|
2821
|
+
if (prop) return prop.getDefinition() || prop;
|
|
2822
|
+
}
|
|
2823
|
+
if (isGroup(merged)) {
|
|
2824
|
+
const found = this.findPropInGroup(merged, propName$1);
|
|
2825
|
+
if (found) return found;
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
return undefined;
|
|
2829
|
+
}
|
|
2789
2830
|
mergeIntersection(node) {
|
|
2790
2831
|
if (!isGroup(node)) return node;
|
|
2791
2832
|
if (node.op !== "&") return node;
|
|
@@ -2890,12 +2931,12 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2890
2931
|
const savedAnnotations = new Set();
|
|
2891
2932
|
for (const a of right || []) {
|
|
2892
2933
|
annotations$1.push(a);
|
|
2893
|
-
savedAnnotations.add(a.
|
|
2934
|
+
savedAnnotations.add(a.name);
|
|
2894
2935
|
}
|
|
2895
2936
|
for (const a of left || []) {
|
|
2896
|
-
const spec = this.resolveAnnotation(a.
|
|
2937
|
+
const spec = this.resolveAnnotation(a.name);
|
|
2897
2938
|
let append = spec && spec.config.multiple && spec.config.mergeStrategy === "append";
|
|
2898
|
-
if (append || !savedAnnotations.has(a.
|
|
2939
|
+
if (append || !savedAnnotations.has(a.name)) annotations$1.push(a);
|
|
2899
2940
|
}
|
|
2900
2941
|
return annotations$1;
|
|
2901
2942
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -544,6 +544,13 @@ declare class AtscriptDoc {
|
|
|
544
544
|
getUnusedTokens(): Token[];
|
|
545
545
|
renderDiagMessage(m: TMessages[number], addSourceLinses?: boolean, colors?: boolean): string;
|
|
546
546
|
getDiagMessages(): TMessages;
|
|
547
|
+
/**
|
|
548
|
+
* Walks a property chain step-by-step, applying mergeIntersection at each
|
|
549
|
+
* level. Mirrors the completion logic in the LSP server so that intersection
|
|
550
|
+
* types like `{ a: string } & { b: number }` are handled correctly.
|
|
551
|
+
*/
|
|
552
|
+
private resolveChainWithMerge;
|
|
553
|
+
private findPropInGroup;
|
|
547
554
|
mergeIntersection(node: SemanticNode): SemanticNode;
|
|
548
555
|
mergeDefs(_left: SemanticNode, _right: SemanticNode): [SemanticNode] | [SemanticNode, SemanticNode];
|
|
549
556
|
/**
|
|
@@ -746,4 +753,5 @@ declare function resolveAnnotation(name: string, annotationsTree?: TAnnotationsT
|
|
|
746
753
|
declare function resolveAtscriptFromPath(from: string, id: string): string;
|
|
747
754
|
declare function getRelPath(fromUri: string, toUri: string): string;
|
|
748
755
|
|
|
749
|
-
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode,
|
|
756
|
+
export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BuildRepo, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticPrimitiveNode, SemanticPropNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, build, createAtscriptPlugin, defineConfig, getRelPath, isAnnotate, isAnnotationSpec, isArray, isConst, isGroup, isImport, isInterface, isPrimitive, isProp, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, resolveAnnotation, resolveAtscriptFromPath, resolveConfigFile };
|
|
757
|
+
export type { TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TMessages, TNodeEntity, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TSemanticToken };
|
package/dist/index.mjs
CHANGED
|
@@ -2705,7 +2705,8 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2705
2705
|
if (!this.registry.isDefined(targetName)) continue;
|
|
2706
2706
|
const chain = isRef(t.parentNode) && t.parentNode.hasChain ? [t.text, ...t.parentNode.chain.map((c) => c.text)] : [t.text];
|
|
2707
2707
|
const unwound = this.unwindType(targetName, chain);
|
|
2708
|
-
|
|
2708
|
+
const chainResolved = unwound?.def && !isGroup(unwound.def);
|
|
2709
|
+
if (!chainResolved && !this.resolveChainWithMerge(targetName, chain)) {
|
|
2709
2710
|
const lastToken = chain.length > 1 && isRef(t.parentNode) ? t.parentNode.chain[t.parentNode.chain.length - 1] || t : t;
|
|
2710
2711
|
this._allMessages.push({
|
|
2711
2712
|
severity: 1,
|
|
@@ -2718,7 +2719,8 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2718
2719
|
const token = t.parentNode.chain[i];
|
|
2719
2720
|
const memberChain = [t.text, ...t.parentNode.chain.slice(0, i + 1).map((c) => c.text)];
|
|
2720
2721
|
const decl = this.unwindType(targetName, memberChain);
|
|
2721
|
-
|
|
2722
|
+
const memberResolved = decl?.def && !isGroup(decl.def);
|
|
2723
|
+
if (!memberResolved && !this.resolveChainWithMerge(targetName, memberChain)) this._allMessages.push({
|
|
2722
2724
|
severity: 1,
|
|
2723
2725
|
message: `Unknown property "${memberChain.join(".")}" in "${targetName}"`,
|
|
2724
2726
|
range: token.range
|
|
@@ -2762,6 +2764,45 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2762
2764
|
}
|
|
2763
2765
|
return this._allMessages;
|
|
2764
2766
|
}
|
|
2767
|
+
/**
|
|
2768
|
+
* Walks a property chain step-by-step, applying mergeIntersection at each
|
|
2769
|
+
* level. Mirrors the completion logic in the LSP server so that intersection
|
|
2770
|
+
* types like `{ a: string } & { b: number }` are handled correctly.
|
|
2771
|
+
*/ resolveChainWithMerge(targetName, chain) {
|
|
2772
|
+
let def = this.unwindType(targetName)?.def;
|
|
2773
|
+
if (!def) return false;
|
|
2774
|
+
for (const prop of chain) {
|
|
2775
|
+
def = this.mergeIntersection(def);
|
|
2776
|
+
if (isProp(def)) {
|
|
2777
|
+
const inner = def.getDefinition();
|
|
2778
|
+
if (inner) def = this.mergeIntersection(inner);
|
|
2779
|
+
}
|
|
2780
|
+
if (isStructure(def) || isInterface(def)) {
|
|
2781
|
+
const next = def.props.get(prop);
|
|
2782
|
+
if (!next) return false;
|
|
2783
|
+
def = next.getDefinition() || next;
|
|
2784
|
+
} else if (isGroup(def)) {
|
|
2785
|
+
const found = this.findPropInGroup(def, prop);
|
|
2786
|
+
if (!found) return false;
|
|
2787
|
+
def = found;
|
|
2788
|
+
} else return false;
|
|
2789
|
+
}
|
|
2790
|
+
return true;
|
|
2791
|
+
}
|
|
2792
|
+
findPropInGroup(group$1, propName$1) {
|
|
2793
|
+
for (const item of group$1.unwrap()) {
|
|
2794
|
+
const merged = this.mergeIntersection(item);
|
|
2795
|
+
if (isStructure(merged) || isInterface(merged)) {
|
|
2796
|
+
const prop = merged.props.get(propName$1);
|
|
2797
|
+
if (prop) return prop.getDefinition() || prop;
|
|
2798
|
+
}
|
|
2799
|
+
if (isGroup(merged)) {
|
|
2800
|
+
const found = this.findPropInGroup(merged, propName$1);
|
|
2801
|
+
if (found) return found;
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
return undefined;
|
|
2805
|
+
}
|
|
2765
2806
|
mergeIntersection(node) {
|
|
2766
2807
|
if (!isGroup(node)) return node;
|
|
2767
2808
|
if (node.op !== "&") return node;
|
|
@@ -2866,12 +2907,12 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
2866
2907
|
const savedAnnotations = new Set();
|
|
2867
2908
|
for (const a of right || []) {
|
|
2868
2909
|
annotations$1.push(a);
|
|
2869
|
-
savedAnnotations.add(a.
|
|
2910
|
+
savedAnnotations.add(a.name);
|
|
2870
2911
|
}
|
|
2871
2912
|
for (const a of left || []) {
|
|
2872
|
-
const spec = this.resolveAnnotation(a.
|
|
2913
|
+
const spec = this.resolveAnnotation(a.name);
|
|
2873
2914
|
let append = spec && spec.config.multiple && spec.config.mergeStrategy === "append";
|
|
2874
|
-
if (append || !savedAnnotations.has(a.
|
|
2915
|
+
if (append || !savedAnnotations.has(a.name)) annotations$1.push(a);
|
|
2875
2916
|
}
|
|
2876
2917
|
return annotations$1;
|
|
2877
2918
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Core library for Atscript parsing and file generation.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@prostojs/parser": "^0.5.11",
|
|
39
39
|
"defu": "^6.1.4",
|
|
40
|
-
"glob": "^
|
|
41
|
-
"rolldown": "1.0.0-
|
|
40
|
+
"glob": "^13.0.2",
|
|
41
|
+
"rolldown": "1.0.0-rc.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^22.10.5",
|