@shapeshift-labs/frontier-lang-compiler 0.2.31 → 0.2.33

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.js CHANGED
@@ -439,6 +439,18 @@ export const NativeParserAstFormatProfiles = Object.freeze([
439
439
  supportsErrorRecovery: true,
440
440
  notes: ['Java compiler/parser ASTs expose package/import/type/member declarations and source ranges; classpath/module-path, bindings, annotation processors, generated sources, Lombok expansion, comments/trivia, and control-flow evidence remain host-owned.']
441
441
  }),
442
+ nativeParserAstFormatProfile('kotlin-psi', {
443
+ aliases: ['kotlin-compiler', 'kotlin-compiler-psi', 'intellij-psi', 'kt-psi', 'kotlin-ast'],
444
+ kind: 'compiler-ast',
445
+ languages: ['kotlin'],
446
+ parserAdapters: ['kotlin-compiler', 'kotlin-psi', 'intellij-psi'],
447
+ exactness: 'exact-parser-ast',
448
+ sourceRangeModel: 'text-range-line-column',
449
+ preservesTokens: true,
450
+ preservesTrivia: true,
451
+ supportsErrorRecovery: true,
452
+ notes: ['Kotlin PSI exposes source syntax and IntelliJ parser errors; Analysis API symbols, FIR/K2 types, expect/actual matching, compiler plugins, generated sources, scripts, and build variants remain host-owned evidence.']
453
+ }),
442
454
  nativeParserAstFormatProfile('roslyn-csharp', {
443
455
  aliases: ['roslyn', 'csharp-roslyn', 'c#-roslyn', 'microsoft-codeanalysis-csharp', 'csharp-syntax'],
444
456
  kind: 'compiler-ast',
@@ -452,6 +464,19 @@ export const NativeParserAstFormatProfiles = Object.freeze([
452
464
  supportsErrorRecovery: true,
453
465
  notes: ['Roslyn C# syntax trees expose immutable nodes, tokens, trivia, spans, diagnostics, directives, and skipped text; SemanticModel symbols, nullable analysis, generated sources, partial type stitching, analyzer results, and project references remain host-owned evidence.']
454
466
  }),
467
+ nativeParserAstFormatProfile('swift-syntax', {
468
+ aliases: ['swiftsyntax', 'swiftparser', 'swift-parser', 'swift-syntax-json'],
469
+ kind: 'concrete-syntax-tree',
470
+ languages: ['swift'],
471
+ parserAdapters: ['swift-syntax', 'swiftparser'],
472
+ exactness: 'parser-tree',
473
+ sourceRangeModel: 'absolute-position-source-location',
474
+ preservesTokens: true,
475
+ preservesTrivia: true,
476
+ supportsIncremental: false,
477
+ supportsErrorRecovery: true,
478
+ notes: ['SwiftSyntax exposes a source-accurate syntax tree with missing/unexpected nodes and token/trivia structure; SourceKit symbols, macro expansion, conditional compilation branch resolution, type checking, generated sources, and package/module dependency resolution remain host-owned evidence.']
479
+ }),
455
480
  nativeParserAstFormatProfile('tree-sitter', {
456
481
  kind: 'concrete-syntax-tree',
457
482
  languages: ['mixed'],
@@ -2945,6 +2970,78 @@ export function createJavaAstNativeImporterAdapter(options = {}) {
2945
2970
  };
2946
2971
  }
2947
2972
 
2973
+ export function createKotlinPsiNativeImporterAdapter(options = {}) {
2974
+ return {
2975
+ id: options.id ?? 'frontier.kotlin-psi-native-importer',
2976
+ language: options.language ?? 'kotlin',
2977
+ parser: options.parser ?? 'kotlin-psi',
2978
+ version: options.version,
2979
+ capabilities: uniqueStrings(['nativeAst', 'semanticIndex', 'sourceMaps', 'diagnostics', ...(options.capabilities ?? [])]),
2980
+ coverage: nativeImporterAdapterCoverage({
2981
+ exactness: 'exact-parser-ast',
2982
+ exactAst: true,
2983
+ tokens: true,
2984
+ trivia: true,
2985
+ diagnostics: true,
2986
+ sourceRanges: true,
2987
+ generatedRanges: false,
2988
+ semanticCoverage: declarationSemanticCoverage(),
2989
+ notes: [
2990
+ 'Normalizes caller-owned Kotlin PSI/KtFile-shaped syntax trees into native AST nodes and declaration-level semantic index records.',
2991
+ 'Kotlin PSI imports do not resolve Analysis API symbols, FIR/K2 types, overloads, nullability flow, expect/actual matching, compiler-plugin generated declarations, KSP/KAPT output, scripts, build variants, or control flow by themselves; attach host evidence for those claims.'
2992
+ ]
2993
+ }, options.coverage),
2994
+ supportedExtensions: options.supportedExtensions ?? ['.kt', '.kts'],
2995
+ diagnostics: options.diagnostics,
2996
+ parse(input) {
2997
+ const parsed = input.options?.ast
2998
+ ?? input.options?.nativeAst
2999
+ ?? input.options?.ktFile
3000
+ ?? input.options?.file
3001
+ ?? input.options?.sourceFile
3002
+ ?? input.options?.root
3003
+ ?? options.ast
3004
+ ?? options.ktFile
3005
+ ?? options.file
3006
+ ?? options.sourceFile
3007
+ ?? options.root
3008
+ ?? parseKotlinPsiSource(input, options);
3009
+ const root = kotlinPsiRoot(parsed);
3010
+ if (!root) {
3011
+ return missingInjectedParserResult(input, {
3012
+ parser: options.parser ?? 'kotlin-psi',
3013
+ adapterId: options.id ?? 'frontier.kotlin-psi-native-importer',
3014
+ message: 'createKotlinPsiNativeImporterAdapter requires an injected Kotlin PSI KtFile-shaped object, parserModule.parse function, parse function, or adapterOptions.ast.'
3015
+ });
3016
+ }
3017
+ const parseDiagnostics = normalizeParserErrors(parsed?.errors ?? parsed?.diagnostics ?? parsed?.parseDiagnostics, input, {
3018
+ parser: options.parser ?? 'kotlin-psi'
3019
+ });
3020
+ return createNativeImportFromKotlinPsi(root, input, {
3021
+ parser: options.parser ?? 'kotlin-psi',
3022
+ astFormat: 'kotlin-psi',
3023
+ maxNodes: options.maxNodes,
3024
+ diagnostics: parseDiagnostics,
3025
+ kotlinVersion: options.kotlinVersion ?? input.options?.kotlinVersion ?? parsed?.kotlinVersion,
3026
+ languageVersion: options.languageVersion ?? input.options?.languageVersion ?? parsed?.languageVersion,
3027
+ apiVersion: options.apiVersion ?? input.options?.apiVersion ?? parsed?.apiVersion,
3028
+ script: input.options?.script ?? options.script ?? parsed?.script ?? /\.kts$/i.test(input.sourcePath ?? ''),
3029
+ generated: input.options?.generated ?? options.generated ?? parsed?.generated ?? kotlinGeneratedSourcePath(input.sourcePath),
3030
+ analysisApiEvidence: input.options?.analysisApiEvidence ?? options.analysisApiEvidence ?? parsed?.analysisApiEvidence,
3031
+ firEvidence: input.options?.firEvidence ?? options.firEvidence ?? parsed?.firEvidence,
3032
+ compilerPluginEvidence: input.options?.compilerPluginEvidence ?? options.compilerPluginEvidence ?? parsed?.compilerPluginEvidence,
3033
+ kspEvidence: input.options?.kspEvidence ?? options.kspEvidence ?? parsed?.kspEvidence,
3034
+ kaptEvidence: input.options?.kaptEvidence ?? options.kaptEvidence ?? parsed?.kaptEvidence,
3035
+ multiplatformEvidence: input.options?.multiplatformEvidence ?? options.multiplatformEvidence ?? parsed?.multiplatformEvidence,
3036
+ buildVariantEvidence: input.options?.buildVariantEvidence ?? options.buildVariantEvidence ?? parsed?.buildVariantEvidence,
3037
+ positionResolver: input.options?.positionResolver ?? options.positionResolver,
3038
+ lineMap: input.options?.lineMap ?? options.lineMap ?? parsed?.lineMap,
3039
+ includeAnnotations: options.includeAnnotations ?? input.options?.includeAnnotations
3040
+ });
3041
+ }
3042
+ };
3043
+ }
3044
+
2948
3045
  export function createCSharpRoslynNativeImporterAdapter(options = {}) {
2949
3046
  return {
2950
3047
  id: options.id ?? 'frontier.csharp-roslyn-native-importer',
@@ -3012,6 +3109,67 @@ export function createCSharpRoslynNativeImporterAdapter(options = {}) {
3012
3109
  };
3013
3110
  }
3014
3111
 
3112
+ export function createSwiftSyntaxNativeImporterAdapter(options = {}) {
3113
+ return {
3114
+ id: options.id ?? 'frontier.swift-syntax-native-importer',
3115
+ language: options.language ?? 'swift',
3116
+ parser: options.parser ?? 'swift-syntax',
3117
+ version: options.version,
3118
+ capabilities: uniqueStrings(['nativeAst', 'semanticIndex', 'sourceMaps', 'diagnostics', ...(options.capabilities ?? [])]),
3119
+ coverage: nativeImporterAdapterCoverage({
3120
+ exactness: 'parser-tree',
3121
+ exactAst: true,
3122
+ tokens: true,
3123
+ trivia: true,
3124
+ diagnostics: true,
3125
+ sourceRanges: true,
3126
+ generatedRanges: false,
3127
+ semanticCoverage: declarationSemanticCoverage(),
3128
+ notes: [
3129
+ 'Normalizes caller-owned SwiftSyntax/SwiftParser-shaped SourceFileSyntax trees into native AST nodes and declaration-level semantic index records.',
3130
+ 'SwiftSyntax imports do not resolve SourceKit symbols, type checking, macro expansions, conditional compilation branches, Objective-C bridging, generated sources, package/module dependencies, or control flow by themselves; attach host evidence for those claims.'
3131
+ ]
3132
+ }, options.coverage),
3133
+ supportedExtensions: options.supportedExtensions ?? ['.swift'],
3134
+ diagnostics: options.diagnostics,
3135
+ parse(input) {
3136
+ const parsed = input.options?.ast
3137
+ ?? input.options?.nativeAst
3138
+ ?? input.options?.sourceFile
3139
+ ?? input.options?.sourceFileSyntax
3140
+ ?? input.options?.root
3141
+ ?? options.ast
3142
+ ?? options.sourceFile
3143
+ ?? options.sourceFileSyntax
3144
+ ?? options.root
3145
+ ?? parseSwiftSyntaxSource(input, options);
3146
+ const root = swiftSyntaxRoot(parsed);
3147
+ if (!root) {
3148
+ return missingInjectedParserResult(input, {
3149
+ parser: options.parser ?? 'swift-syntax',
3150
+ adapterId: options.id ?? 'frontier.swift-syntax-native-importer',
3151
+ message: 'createSwiftSyntaxNativeImporterAdapter requires an injected SwiftSyntax SourceFileSyntax-shaped object, parserModule.parse function, parse function, or adapterOptions.ast.'
3152
+ });
3153
+ }
3154
+ const parseDiagnostics = normalizeParserErrors(parsed?.errors ?? parsed?.diagnostics ?? parsed?.parseDiagnostics, input, {
3155
+ parser: options.parser ?? 'swift-syntax'
3156
+ });
3157
+ return createNativeImportFromSwiftSyntax(root, input, {
3158
+ parser: options.parser ?? 'swift-syntax',
3159
+ astFormat: 'swift-syntax',
3160
+ maxNodes: options.maxNodes,
3161
+ diagnostics: parseDiagnostics,
3162
+ swiftVersion: options.swiftVersion ?? input.options?.swiftVersion ?? parsed?.swiftVersion,
3163
+ languageMode: options.languageMode ?? input.options?.languageMode ?? parsed?.languageMode,
3164
+ generated: input.options?.generated ?? options.generated ?? parsed?.generated ?? swiftGeneratedSourcePath(input.sourcePath),
3165
+ sourceKitEvidence: input.options?.sourceKitEvidence ?? options.sourceKitEvidence ?? parsed?.sourceKitEvidence,
3166
+ macroExpansionEvidence: input.options?.macroExpansionEvidence ?? options.macroExpansionEvidence ?? parsed?.macroExpansionEvidence,
3167
+ packageResolutionEvidence: input.options?.packageResolutionEvidence ?? options.packageResolutionEvidence ?? parsed?.packageResolutionEvidence
3168
+ });
3169
+ }
3170
+ };
3171
+ }
3172
+
3015
3173
  export function createTreeSitterNativeImporterAdapter(options = {}) {
3016
3174
  return {
3017
3175
  id: options.id ?? `frontier.tree-sitter-${idFragment(options.language ?? 'source')}-native-importer`,
@@ -7455,7 +7613,9 @@ function parserAstFormatIdForParser(parser) {
7455
7613
  if (text.includes('clang') || text.includes('libclang')) return 'clang-ast-json';
7456
7614
  if (text === 'go' || text.includes('go-parser') || text.includes('go-ast') || text.includes('go/parser') || text.includes('go/ast')) return 'go-ast';
7457
7615
  if (text === 'java' || text.includes('javac') || text.includes('jdt') || text.includes('javaparser') || text.includes('java-parser') || text.includes('java-ast')) return 'java-ast';
7616
+ if (text === 'kotlin' || text === 'kt' || text.includes('kotlin-psi') || text.includes('kotlin-compiler') || text.includes('intellij-psi') || text.includes('kt-psi')) return 'kotlin-psi';
7458
7617
  if (text === 'csharp' || text === 'c#' || text === 'cs' || text.includes('roslyn') || text.includes('microsoft-codeanalysis-csharp') || text.includes('csharp-syntax')) return 'roslyn-csharp';
7618
+ if (text.includes('swift-syntax') || text.includes('swiftsyntax') || text.includes('swiftparser') || text.includes('swift-parser')) return 'swift-syntax';
7459
7619
  if (text.includes('tree-sitter') || text.includes('treesitter')) return 'tree-sitter';
7460
7620
  if (text.includes('babel')) return 'babel';
7461
7621
  if (text.includes('estree')) return 'estree';
@@ -8554,6 +8714,23 @@ function parseJavaAstSource(input, options) {
8554
8714
  return parse(input.sourceText, parserOptions);
8555
8715
  }
8556
8716
 
8717
+ function parseKotlinPsiSource(input, options) {
8718
+ const parse = options.parse ?? options.parserModule?.parse ?? options.kotlinPsi?.parse ?? options.kotlinCompiler?.parse ?? options.intellijPsi?.parse;
8719
+ if (typeof parse !== 'function') return undefined;
8720
+ const parserOptions = {
8721
+ sourcePath: input.sourcePath,
8722
+ filename: input.sourcePath,
8723
+ kotlinVersion: options.kotlinVersion ?? input.options?.kotlinVersion,
8724
+ languageVersion: options.languageVersion ?? input.options?.languageVersion,
8725
+ apiVersion: options.apiVersion ?? input.options?.apiVersion,
8726
+ script: options.script ?? input.options?.script ?? /\.kts$/i.test(input.sourcePath ?? ''),
8727
+ includeAnnotations: options.includeAnnotations ?? input.options?.includeAnnotations,
8728
+ ...(options.parserOptions ?? {}),
8729
+ ...(input.options?.parserOptions ?? {})
8730
+ };
8731
+ return parse(input.sourceText, parserOptions);
8732
+ }
8733
+
8557
8734
  function parseCSharpRoslynSource(input, options) {
8558
8735
  const parse = options.parse ?? options.parserModule?.parse ?? options.roslyn?.parse ?? options.csharpRoslyn?.parse;
8559
8736
  if (typeof parse !== 'function') return undefined;
@@ -8570,6 +8747,22 @@ function parseCSharpRoslynSource(input, options) {
8570
8747
  return parse(input.sourceText, parserOptions);
8571
8748
  }
8572
8749
 
8750
+ function parseSwiftSyntaxSource(input, options) {
8751
+ const parse = options.parse ?? options.parserModule?.parse ?? options.swiftSyntax?.parse ?? options.swiftParser?.parse;
8752
+ if (typeof parse !== 'function') return undefined;
8753
+ const parserOptions = {
8754
+ sourcePath: input.sourcePath,
8755
+ filename: input.sourcePath,
8756
+ swiftVersion: options.swiftVersion ?? input.options?.swiftVersion,
8757
+ languageMode: options.languageMode ?? input.options?.languageMode,
8758
+ enableBareSlashRegex: options.enableBareSlashRegex ?? input.options?.enableBareSlashRegex,
8759
+ parseTransition: options.parseTransition ?? input.options?.parseTransition,
8760
+ ...(options.parserOptions ?? {}),
8761
+ ...(input.options?.parserOptions ?? {})
8762
+ };
8763
+ return parse(input.sourceText, parserOptions);
8764
+ }
8765
+
8573
8766
  function createNativeImportFromSyntaxAst(ast, input, options) {
8574
8767
  const root = normalizeSyntaxAstRoot(ast, options.astFormat);
8575
8768
  if (!root) {
@@ -8800,6 +8993,53 @@ function createNativeImportFromJavaAst(root, input, options) {
8800
8993
  };
8801
8994
  }
8802
8995
 
8996
+ function createNativeImportFromKotlinPsi(root, input, options) {
8997
+ const context = createAstNormalizationContext(input, options);
8998
+ visitKotlinPsiNode(root, context, 'root');
8999
+ if (context.truncated) {
9000
+ context.losses.push(truncatedAstLoss(input, context, options));
9001
+ }
9002
+ if (options.generated && !context.losses.some((loss) => loss.kind === 'generatedCode')) {
9003
+ context.losses.push(kotlinGeneratedCodeLoss(input, context.rootId, undefined, options));
9004
+ }
9005
+ if (options.script && !context.losses.some((loss) => loss.metadata?.script === true)) {
9006
+ context.losses.push(kotlinScriptLoss(input, context.rootId, undefined, options));
9007
+ }
9008
+ const semantic = semanticIndexFromNativeDeclarations(context.declarations, input, options);
9009
+ return {
9010
+ rootId: context.rootId,
9011
+ nodes: context.nodes,
9012
+ semanticIndex: semantic.semanticIndex,
9013
+ mappings: semantic.mappings,
9014
+ losses: mergeNativeLosses(context.losses, options.diagnostics?.map((diagnostic, index) => adapterDiagnosticToLoss(diagnostic, index, {
9015
+ id: input.adapterId,
9016
+ version: input.adapterVersion
9017
+ }, input)) ?? []),
9018
+ evidence: semantic.evidence,
9019
+ diagnostics: options.diagnostics,
9020
+ metadata: {
9021
+ astFormat: options.astFormat,
9022
+ parser: options.parser,
9023
+ kotlinVersion: options.kotlinVersion,
9024
+ languageVersion: options.languageVersion,
9025
+ apiVersion: options.apiVersion,
9026
+ script: Boolean(options.script),
9027
+ generated: options.generated,
9028
+ analysisApiEvidence: kotlinEvidenceSummary(options.analysisApiEvidence),
9029
+ firEvidence: kotlinEvidenceSummary(options.firEvidence),
9030
+ compilerPluginEvidence: kotlinEvidenceSummary(options.compilerPluginEvidence),
9031
+ kspEvidence: kotlinEvidenceSummary(options.kspEvidence),
9032
+ kaptEvidence: kotlinEvidenceSummary(options.kaptEvidence),
9033
+ multiplatformEvidence: kotlinEvidenceSummary(options.multiplatformEvidence),
9034
+ buildVariantEvidence: kotlinEvidenceSummary(options.buildVariantEvidence),
9035
+ includeAnnotations: Boolean(options.includeAnnotations),
9036
+ normalizedNodeCount: Object.keys(context.nodes).length,
9037
+ declarationCount: context.declarations.length,
9038
+ truncated: context.truncated
9039
+ }
9040
+ };
9041
+ }
9042
+
8803
9043
  function createNativeImportFromCSharpRoslyn(root, input, options) {
8804
9044
  const context = createAstNormalizationContext(input, options);
8805
9045
  visitCSharpRoslynNode(root, context, 'root');
@@ -8839,6 +9079,43 @@ function createNativeImportFromCSharpRoslyn(root, input, options) {
8839
9079
  };
8840
9080
  }
8841
9081
 
9082
+ function createNativeImportFromSwiftSyntax(root, input, options) {
9083
+ const context = createAstNormalizationContext(input, options);
9084
+ visitSwiftSyntaxNode(root, context, 'root');
9085
+ if (context.truncated) {
9086
+ context.losses.push(truncatedAstLoss(input, context, options));
9087
+ }
9088
+ if (options.generated && !context.losses.some((loss) => loss.kind === 'generatedCode')) {
9089
+ context.losses.push(swiftGeneratedCodeLoss(input, context.rootId, undefined, options));
9090
+ }
9091
+ const semantic = semanticIndexFromNativeDeclarations(context.declarations, input, options);
9092
+ return {
9093
+ rootId: context.rootId,
9094
+ nodes: context.nodes,
9095
+ semanticIndex: semantic.semanticIndex,
9096
+ mappings: semantic.mappings,
9097
+ losses: mergeNativeLosses(context.losses, options.diagnostics?.map((diagnostic, index) => adapterDiagnosticToLoss(diagnostic, index, {
9098
+ id: input.adapterId,
9099
+ version: input.adapterVersion
9100
+ }, input)) ?? []),
9101
+ evidence: semantic.evidence,
9102
+ diagnostics: options.diagnostics,
9103
+ metadata: {
9104
+ astFormat: options.astFormat,
9105
+ parser: options.parser,
9106
+ swiftVersion: options.swiftVersion,
9107
+ languageMode: options.languageMode,
9108
+ generated: options.generated,
9109
+ sourceKitEvidence: swiftEvidenceSummary(options.sourceKitEvidence),
9110
+ macroExpansionEvidence: swiftEvidenceSummary(options.macroExpansionEvidence),
9111
+ packageResolutionEvidence: swiftEvidenceSummary(options.packageResolutionEvidence),
9112
+ normalizedNodeCount: Object.keys(context.nodes).length,
9113
+ declarationCount: context.declarations.length,
9114
+ truncated: context.truncated
9115
+ }
9116
+ };
9117
+ }
9118
+
8842
9119
  function createNativeImportFromTreeSitter(root, input, options) {
8843
9120
  const context = createAstNormalizationContext(input, options);
8844
9121
  visitTreeSitterNode(root, context, 'root');
@@ -9400,6 +9677,108 @@ function visitCSharpRoslynNode(node, context, propertyPath) {
9400
9677
  return id;
9401
9678
  }
9402
9679
 
9680
+ function visitSwiftSyntaxNode(node, context, propertyPath) {
9681
+ if (!isSwiftSyntaxNode(node) || context.truncated) return undefined;
9682
+ if (context.objectIds.has(node)) return context.objectIds.get(node);
9683
+ if (context.counter >= context.maxNodes) {
9684
+ context.truncated = true;
9685
+ return undefined;
9686
+ }
9687
+ const kind = swiftSyntaxKind(node);
9688
+ const span = spanFromSwiftSyntaxNode(node, context.input, context.options);
9689
+ const id = nativeNodeId(context, kind, { start: { line: span?.startLine, column: span?.startColumn } }, propertyPath);
9690
+ context.objectIds.set(node, id);
9691
+ if (!context.rootId) context.rootId = id;
9692
+ const children = [];
9693
+ for (const [field, value] of swiftSyntaxChildEntries(node, kind)) {
9694
+ if (Array.isArray(value)) {
9695
+ value.forEach((entry, index) => {
9696
+ const childId = visitSwiftSyntaxNode(entry, context, `${propertyPath}.${field}[${index}]`);
9697
+ if (childId) children.push(childId);
9698
+ });
9699
+ } else {
9700
+ const childId = visitSwiftSyntaxNode(value, context, `${propertyPath}.${field}`);
9701
+ if (childId) children.push(childId);
9702
+ }
9703
+ }
9704
+ const declarations = swiftSyntaxDeclarations(node, kind, id, context.input);
9705
+ const declaration = declarations[0];
9706
+ const nativeNode = {
9707
+ id,
9708
+ kind,
9709
+ languageKind: `${context.input.language}.${kind}`,
9710
+ span,
9711
+ value: declaration?.name ?? swiftSyntaxNodeValue(node),
9712
+ fields: primitiveSwiftSyntaxFields(node, kind),
9713
+ children,
9714
+ metadata: {
9715
+ astFormat: context.options.astFormat,
9716
+ propertyPath,
9717
+ positionKind: swiftSyntaxPositionKind(node),
9718
+ parser: context.options.parser
9719
+ }
9720
+ };
9721
+ context.nodes[id] = nativeNode;
9722
+ for (const entry of declarations) {
9723
+ context.declarations.push({ ...entry, nativeNode });
9724
+ }
9725
+ if (swiftSyntaxRecoveredKind(kind) || swiftSyntaxProblemNode(node, kind)) {
9726
+ context.losses.push({
9727
+ id: `loss_${idFragment(id)}_swift_syntax_recovered_node`,
9728
+ severity: 'error',
9729
+ phase: 'parse',
9730
+ sourceFormat: context.input.language,
9731
+ kind: 'unsupportedSyntax',
9732
+ message: 'SwiftSyntax reported missing, unexpected, skipped, or error syntax; semantic import is partial until syntax errors are resolved.',
9733
+ span,
9734
+ nodeId: id,
9735
+ metadata: {
9736
+ parser: context.options.parser,
9737
+ astFormat: context.options.astFormat,
9738
+ nodeKind: kind
9739
+ }
9740
+ });
9741
+ }
9742
+ if (swiftSyntaxConditionalCompilationKind(kind)) {
9743
+ context.losses.push({
9744
+ id: `loss_${idFragment(id)}_swift_conditional_compilation`,
9745
+ severity: 'warning',
9746
+ phase: 'parse',
9747
+ sourceFormat: context.input.language,
9748
+ kind: 'conditionalCompilation',
9749
+ message: 'Swift conditional compilation syntax was imported; active branch selection and inactive branch source ownership require host build-setting evidence.',
9750
+ span,
9751
+ nodeId: id,
9752
+ metadata: {
9753
+ parser: context.options.parser,
9754
+ astFormat: context.options.astFormat,
9755
+ nodeKind: kind
9756
+ }
9757
+ });
9758
+ }
9759
+ if (swiftSyntaxMacroKind(kind)) {
9760
+ context.losses.push({
9761
+ id: `loss_${idFragment(id)}_swift_macro_expansion`,
9762
+ severity: 'warning',
9763
+ phase: 'parse',
9764
+ sourceFormat: context.input.language,
9765
+ kind: 'macroExpansion',
9766
+ message: 'Swift macro syntax was imported, but expansion, generated declarations, and binding effects require host macro-expansion evidence.',
9767
+ span,
9768
+ nodeId: id,
9769
+ metadata: {
9770
+ parser: context.options.parser,
9771
+ astFormat: context.options.astFormat,
9772
+ nodeKind: kind
9773
+ }
9774
+ });
9775
+ }
9776
+ if (swiftGeneratedCodeMarker(node, kind)) {
9777
+ context.losses.push(swiftGeneratedCodeLoss(context.input, id, span, context.options, { nodeKind: kind }));
9778
+ }
9779
+ return id;
9780
+ }
9781
+
9403
9782
  function visitTreeSitterNode(node, context, propertyPath) {
9404
9783
  if (!node || typeof node !== 'object' || context.truncated) return undefined;
9405
9784
  if (context.objectIds.has(node)) return context.objectIds.get(node);
@@ -12118,137 +12497,1281 @@ function javaBindingEvidenceSummary(value) {
12118
12497
  return Object.keys(summary).length ? summary : { present: true };
12119
12498
  }
12120
12499
 
12121
- function csharpRoslynRoot(value) {
12500
+ function kotlinPsiRoot(value) {
12122
12501
  if (!value || typeof value !== 'object') return undefined;
12123
- if (isCSharpRoslynNode(value)) return value;
12124
- if (isCSharpRoslynNode(value.ast)) return value.ast;
12125
- if (isCSharpRoslynNode(value.root)) return value.root;
12126
- if (isCSharpRoslynNode(value.rootNode)) return value.rootNode;
12127
- if (isCSharpRoslynNode(value.compilationUnit)) return value.compilationUnit;
12128
- if (isCSharpRoslynNode(value.syntaxTree)) return csharpRoslynRoot(value.syntaxTree);
12129
- if (isCSharpRoslynNode(value.tree)) return csharpRoslynRoot(value.tree);
12130
- if (Array.isArray(value.members) || Array.isArray(value.usings) || Array.isArray(value.externs)) {
12131
- return { kind: 'CompilationUnit', ...value };
12502
+ if (isKotlinPsiNode(value)) return value;
12503
+ if (isKotlinPsiNode(value.ast)) return value.ast;
12504
+ if (isKotlinPsiNode(value.root)) return value.root;
12505
+ if (isKotlinPsiNode(value.rootNode)) return value.rootNode;
12506
+ if (isKotlinPsiNode(value.ktFile)) return value.ktFile;
12507
+ if (isKotlinPsiNode(value.file)) return value.file;
12508
+ if (isKotlinPsiNode(value.sourceFile)) return value.sourceFile;
12509
+ if (Array.isArray(value.declarations) || Array.isArray(value.imports) || value.packageDirective) {
12510
+ return { kind: 'KtFile', ...value };
12132
12511
  }
12133
12512
  return undefined;
12134
12513
  }
12135
12514
 
12136
- function isCSharpRoslynNode(value) {
12137
- return Boolean(value && typeof value === 'object' && typeof csharpRoslynKind(value) === 'string');
12515
+ function isKotlinPsiNode(value) {
12516
+ return Boolean(value && typeof value === 'object' && typeof kotlinPsiKind(value) === 'string');
12138
12517
  }
12139
12518
 
12140
- function csharpRoslynKind(node) {
12519
+ function kotlinPsiKind(node) {
12141
12520
  if (!node || typeof node !== 'object') return undefined;
12142
- const declared = node.kind ?? node.Kind ?? node._type ?? node.type ?? node.nodeType ?? node.syntaxKind ?? node.SyntaxKind;
12143
- if (typeof declared === 'string') return normalizeCSharpRoslynKind(declared);
12144
- if (Array.isArray(node.members) || Array.isArray(node.usings) || Array.isArray(node.externs)) return 'CompilationUnit';
12145
- if (node.identifier && (node.members || node.baseList || node.parameterList || node.modifiers)) return 'ClassDeclaration';
12146
- if (node.declaration && (node.eventKeyword || node.eventField)) return 'EventFieldDeclaration';
12147
- if (node.declaration && Array.isArray(node.declaration.variables)) return 'FieldDeclaration';
12521
+ const declared = node.kind ?? node.nodeType ?? node.elementType ?? node.psiKind ?? node._type ?? node.type;
12522
+ if (typeof declared === 'string') return normalizeKotlinPsiKind(declared);
12523
+ if (Array.isArray(node.declarations) || Array.isArray(node.imports) || node.packageDirective) return 'KtFile';
12524
+ if (node.fqName || node.packageFqName) return 'KtPackageDirective';
12525
+ if (node.importedFqName || node.importedReference) return 'KtImportDirective';
12526
+ if (node.classKind || node.primaryConstructor || node.superTypeListEntries) return 'KtClass';
12527
+ if (node.funKeyword || node.valueParameters || node.bodyExpression) return 'KtNamedFunction';
12528
+ if (node.valOrVarKeyword || node.delegateExpression || node.initializer) return 'KtProperty';
12148
12529
  return undefined;
12149
12530
  }
12150
12531
 
12151
- function normalizeCSharpRoslynKind(kind) {
12532
+ function normalizeKotlinPsiKind(kind) {
12152
12533
  const text = String(kind)
12153
- .replace(/^(?:Microsoft\.CodeAnalysis\.CSharp\.Syntax\.|Microsoft\.CodeAnalysis\.CSharp\.)/, '')
12154
- .replace(/Syntax$/, '');
12534
+ .replace(/^org\.jetbrains\.kotlin\.psi\./, '')
12535
+ .replace(/^KtNodeTypes\./, '')
12536
+ .replace(/ElementType$/, '');
12155
12537
  const compact = text.replace(/[_\s.-]+/g, '').toLowerCase();
12156
- if (compact === 'compilationunit') return 'CompilationUnit';
12157
- if (compact === 'usingdirective') return 'UsingDirective';
12158
- if (compact === 'namespacedeclaration') return 'NamespaceDeclaration';
12159
- if (compact === 'filescopednamespacedeclaration') return 'FileScopedNamespaceDeclaration';
12160
- if (compact === 'classdeclaration') return 'ClassDeclaration';
12161
- if (compact === 'interfacedeclaration') return 'InterfaceDeclaration';
12162
- if (compact === 'structdeclaration') return 'StructDeclaration';
12163
- if (compact === 'recorddeclaration') return 'RecordDeclaration';
12164
- if (compact === 'recordstructdeclaration') return 'RecordStructDeclaration';
12165
- if (compact === 'enumdeclaration') return 'EnumDeclaration';
12166
- if (compact === 'methoddeclaration') return 'MethodDeclaration';
12167
- if (compact === 'constructordeclaration') return 'ConstructorDeclaration';
12168
- if (compact === 'destructordeclaration') return 'DestructorDeclaration';
12169
- if (compact === 'operatordeclaration') return 'OperatorDeclaration';
12170
- if (compact === 'conversionoperatordeclaration') return 'ConversionOperatorDeclaration';
12171
- if (compact === 'propertydeclaration') return 'PropertyDeclaration';
12172
- if (compact === 'indexerdeclaration') return 'IndexerDeclaration';
12173
- if (compact === 'fielddeclaration') return 'FieldDeclaration';
12174
- if (compact === 'variabledeclarator') return 'VariableDeclarator';
12175
- if (compact === 'eventdeclaration') return 'EventDeclaration';
12176
- if (compact === 'eventfielddeclaration') return 'EventFieldDeclaration';
12177
- if (compact === 'delegatedeclaration') return 'DelegateDeclaration';
12178
- if (compact === 'enummemberdeclaration') return 'EnumMemberDeclaration';
12179
- if (compact === 'attributelist') return 'AttributeList';
12180
- if (compact === 'attribute') return 'Attribute';
12181
- if (compact === 'parameter') return 'Parameter';
12182
- if (compact === 'incompletemember') return 'IncompleteMember';
12183
- if (compact === 'skippedtokenstrivia' || compact === 'skippedtokens') return 'SkippedTokensTrivia';
12184
- if (compact.endsWith('directivetrivia')) return `${upperFirst(compact.slice(0, -'directivetrivia'.length))}DirectiveTrivia`;
12538
+ const known = {
12539
+ kotlinfile: 'KtFile',
12540
+ ktfile: 'KtFile',
12541
+ file: 'KtFile',
12542
+ script: 'KtScript',
12543
+ ktscript: 'KtScript',
12544
+ packagedirective: 'KtPackageDirective',
12545
+ ktpackagedirective: 'KtPackageDirective',
12546
+ importdirective: 'KtImportDirective',
12547
+ ktimportdirective: 'KtImportDirective',
12548
+ class: 'KtClass',
12549
+ ktclass: 'KtClass',
12550
+ classorobject: 'KtClassOrObject',
12551
+ ktclassorobject: 'KtClassOrObject',
12552
+ objectdeclaration: 'KtObjectDeclaration',
12553
+ ktobjectdeclaration: 'KtObjectDeclaration',
12554
+ enumentry: 'KtEnumEntry',
12555
+ ktenumentry: 'KtEnumEntry',
12556
+ namedfunction: 'KtNamedFunction',
12557
+ ktnamedfunction: 'KtNamedFunction',
12558
+ function: 'KtNamedFunction',
12559
+ property: 'KtProperty',
12560
+ ktproperty: 'KtProperty',
12561
+ typealias: 'KtTypeAlias',
12562
+ kttypealias: 'KtTypeAlias',
12563
+ parameter: 'KtParameter',
12564
+ ktparameter: 'KtParameter',
12565
+ primaryconstructor: 'KtPrimaryConstructor',
12566
+ ktprimaryconstructor: 'KtPrimaryConstructor',
12567
+ secondaryconstructor: 'KtSecondaryConstructor',
12568
+ ktsecondaryconstructor: 'KtSecondaryConstructor',
12569
+ classinitializer: 'KtClassInitializer',
12570
+ ktclassinitializer: 'KtClassInitializer',
12571
+ annotationentry: 'KtAnnotationEntry',
12572
+ ktannotationentry: 'KtAnnotationEntry',
12573
+ contracteffect: 'KtContractEffect',
12574
+ ktcontracteffect: 'KtContractEffect',
12575
+ contractdescription: 'KtContractDescription',
12576
+ ktcontractdescription: 'KtContractDescription',
12577
+ error: 'PsiErrorElement',
12578
+ psierror: 'PsiErrorElement',
12579
+ psierrorelement: 'PsiErrorElement'
12580
+ };
12581
+ if (known[compact]) return known[compact];
12582
+ if (/^[A-Z0-9_]+$/.test(text)) return text.toLowerCase().split('_').map(upperFirst).join('');
12583
+ return text;
12584
+ }
12585
+
12586
+ function ignoredKotlinPsiField(key) {
12587
+ return key === '_type'
12588
+ || key === 'type'
12589
+ || key === 'kind'
12590
+ || key === 'nodeType'
12591
+ || key === 'elementType'
12592
+ || key === 'psiKind'
12593
+ || key === 'parent'
12594
+ || key === 'parentKind'
12595
+ || key === 'parentField'
12596
+ || key === 'textRange'
12597
+ || key === 'range'
12598
+ || key === 'span'
12599
+ || key === 'location'
12600
+ || key === 'name'
12601
+ || key === 'nameIdentifier'
12602
+ || key === 'identifier'
12603
+ || key === 'fqName'
12604
+ || key === 'packageFqName'
12605
+ || key === 'analysisSymbol'
12606
+ || key === 'symbol'
12607
+ || key === 'typeInfo'
12608
+ || key === 'bindingContext'
12609
+ || key === 'fir'
12610
+ || key === 'ir';
12611
+ }
12612
+
12613
+ function visitKotlinPsiNode(node, context, propertyPath) {
12614
+ if (!isKotlinPsiNode(node) || context.truncated) return undefined;
12615
+ if (context.objectIds.has(node)) return context.objectIds.get(node);
12616
+ if (context.counter >= context.maxNodes) {
12617
+ context.truncated = true;
12618
+ return undefined;
12619
+ }
12620
+ const kind = kotlinPsiKind(node);
12621
+ const span = spanFromKotlinPsiNode(node, context.input, context.options);
12622
+ const id = nativeNodeId(context, kind, { start: { line: span?.startLine, column: span?.startColumn } }, propertyPath);
12623
+ context.objectIds.set(node, id);
12624
+ if (!context.rootId) context.rootId = id;
12625
+ const children = [];
12626
+ for (const [field, value] of kotlinPsiChildEntries(node, kind)) {
12627
+ if (Array.isArray(value)) {
12628
+ value.forEach((entry, index) => {
12629
+ const childId = visitKotlinPsiNode(entry, context, `${propertyPath}.${field}[${index}]`);
12630
+ if (childId) children.push(childId);
12631
+ });
12632
+ } else {
12633
+ const childId = visitKotlinPsiNode(value, context, `${propertyPath}.${field}`);
12634
+ if (childId) children.push(childId);
12635
+ }
12636
+ }
12637
+ const declarations = kotlinPsiDeclarations(node, kind, id, context.input);
12638
+ const declaration = declarations[0];
12639
+ const nativeNode = {
12640
+ id,
12641
+ kind,
12642
+ languageKind: `${context.input.language}.${kind}`,
12643
+ span,
12644
+ value: declaration?.name ?? kotlinPsiNodeValue(node),
12645
+ fields: primitiveKotlinPsiFields(node, kind),
12646
+ children,
12647
+ metadata: {
12648
+ astFormat: context.options.astFormat,
12649
+ propertyPath,
12650
+ positionKind: kotlinPsiPositionKind(node),
12651
+ parser: context.options.parser
12652
+ }
12653
+ };
12654
+ context.nodes[id] = nativeNode;
12655
+ for (const entry of declarations) {
12656
+ context.declarations.push({ ...entry, nativeNode });
12657
+ }
12658
+ if (kotlinPsiRecoveredKind(kind) || kotlinPsiProblemNode(node, kind)) {
12659
+ context.losses.push({
12660
+ id: `loss_${idFragment(id)}_kotlin_psi_recovered_node`,
12661
+ severity: 'error',
12662
+ phase: 'parse',
12663
+ sourceFormat: context.input.language,
12664
+ kind: 'unsupportedSyntax',
12665
+ message: 'Kotlin PSI reported an error or recovered syntax node; semantic import is partial until syntax errors are resolved.',
12666
+ span,
12667
+ nodeId: id,
12668
+ metadata: {
12669
+ parser: context.options.parser,
12670
+ astFormat: context.options.astFormat,
12671
+ nodeKind: kind
12672
+ }
12673
+ });
12674
+ }
12675
+ if (kotlinExpectActualNode(node, kind)) {
12676
+ context.losses.push(kotlinUnsupportedSemanticLoss(context.input, id, span, context.options, {
12677
+ nodeKind: kind,
12678
+ feature: 'expect-actual',
12679
+ message: 'Kotlin expect/actual syntax was imported; matching platform declarations requires multiplatform build evidence.'
12680
+ }));
12681
+ }
12682
+ if (kotlinCoroutineNode(node, kind)) {
12683
+ context.losses.push(kotlinUnsupportedSemanticLoss(context.input, id, span, context.options, {
12684
+ nodeKind: kind,
12685
+ feature: 'coroutine',
12686
+ message: 'Kotlin coroutine syntax was imported; suspend lowering, scheduling, and effect semantics require host compiler/runtime evidence.'
12687
+ }));
12688
+ }
12689
+ if (kotlinContractNode(kind)) {
12690
+ context.losses.push(kotlinUnsupportedSemanticLoss(context.input, id, span, context.options, {
12691
+ nodeKind: kind,
12692
+ feature: 'contract',
12693
+ message: 'Kotlin contract syntax was imported; data-flow effects require Analysis API or compiler evidence.'
12694
+ }));
12695
+ }
12696
+ if (kotlinCompilerPluginAnnotationNode(node, kind) && !context.options.compilerPluginEvidence) {
12697
+ context.losses.push({
12698
+ id: `loss_${idFragment(id)}_kotlin_compiler_plugin_semantics`,
12699
+ severity: 'warning',
12700
+ phase: 'parse',
12701
+ sourceFormat: context.input.language,
12702
+ kind: 'metaprogramming',
12703
+ message: 'Kotlin compiler-plugin-style annotation was imported; generated declarations and transformed semantics require compiler plugin evidence.',
12704
+ span,
12705
+ nodeId: id,
12706
+ metadata: {
12707
+ parser: context.options.parser,
12708
+ astFormat: context.options.astFormat,
12709
+ nodeKind: kind,
12710
+ annotations: kotlinPsiAnnotationNames(node)
12711
+ }
12712
+ });
12713
+ }
12714
+ if (kotlinGeneratedCodeMarker(node, kind)) {
12715
+ context.losses.push(kotlinGeneratedCodeLoss(context.input, id, span, context.options, { nodeKind: kind }));
12716
+ }
12717
+ return id;
12718
+ }
12719
+
12720
+ function primitiveKotlinPsiFields(node, kind) {
12721
+ const fields = { kind };
12722
+ const name = kotlinPsiDeclarationName(node, kind);
12723
+ if (name) fields.name = name;
12724
+ const importPath = kotlinPsiImportPath(node);
12725
+ if (importPath) fields.importPath = importPath;
12726
+ const packageName = kotlinPsiPackageName(node);
12727
+ if (packageName) fields.packageName = packageName;
12728
+ const type = kotlinPsiTypeName(node.typeReference ?? node.returnTypeRef ?? node.returnType ?? node.type);
12729
+ if (type) fields.type = type;
12730
+ const receiver = kotlinPsiTypeName(node.receiverTypeReference ?? node.receiverTypeRef);
12731
+ if (receiver) fields.receiverType = receiver;
12732
+ const modifiers = kotlinPsiModifiers(node);
12733
+ if (modifiers.length) fields.modifiers = modifiers.join(',');
12734
+ const annotations = kotlinPsiAnnotationNames(node);
12735
+ if (annotations.length) fields.annotations = annotations.join(',');
12736
+ if (node.generated === true || node.isGenerated === true) fields.generated = true;
12737
+ if (node.isScript === true || kind === 'KtScript') fields.script = true;
12738
+ if (Array.isArray(node.typeParameters ?? node.typeParameterList?.parameters)) fields.typeParameterCount = (node.typeParameters ?? node.typeParameterList?.parameters).length;
12739
+ if (Array.isArray(node.valueParameters ?? node.valueParameterList?.parameters ?? node.parameters)) fields.parameterCount = (node.valueParameters ?? node.valueParameterList?.parameters ?? node.parameters).length;
12740
+ if (Array.isArray(node.superTypeListEntries ?? node.superTypes)) fields.superTypeCount = (node.superTypeListEntries ?? node.superTypes).length;
12741
+ return fields;
12742
+ }
12743
+
12744
+ function spanFromKotlinPsiNode(node, input, options = {}) {
12745
+ const direct = spanFromKotlinLineFields(node, input);
12746
+ if (direct) return direct;
12747
+ const range = node.sourceRange ?? node.range ?? node.span ?? node.textRange;
12748
+ const fromRange = spanFromKotlinRange(range, input);
12749
+ if (fromRange) return fromRange;
12750
+ const start = kotlinPsiPosition(node.start ?? node.startOffset ?? range?.startOffset ?? range?.start, options);
12751
+ const end = kotlinPsiPosition(node.end ?? node.endOffset ?? range?.endOffset ?? range?.end, options);
12752
+ if (!start) return undefined;
12753
+ return {
12754
+ sourceId: input.sourceHash,
12755
+ path: start.path ?? end?.path ?? input.sourcePath,
12756
+ startLine: start.line,
12757
+ startColumn: start.column,
12758
+ endLine: end?.line,
12759
+ endColumn: end?.column
12760
+ };
12761
+ }
12762
+
12763
+ function spanFromKotlinLineFields(node, input) {
12764
+ const startLine = node.startLine ?? node.line ?? node.beginLine;
12765
+ if (typeof startLine !== 'number') return undefined;
12766
+ return {
12767
+ sourceId: input.sourceHash,
12768
+ path: node.path ?? node.filePath ?? node.file ?? input.sourcePath,
12769
+ startLine,
12770
+ startColumn: node.startColumn ?? node.column ?? node.beginColumn,
12771
+ endLine: node.endLine,
12772
+ endColumn: node.endColumn
12773
+ };
12774
+ }
12775
+
12776
+ function spanFromKotlinRange(range, input) {
12777
+ if (!range || typeof range !== 'object') return undefined;
12778
+ const start = range.start ?? range.startPosition ?? range.lowerBound ?? range.begin;
12779
+ const end = range.end ?? range.endPosition ?? range.upperBound;
12780
+ const line = start?.line ?? start?.Line;
12781
+ if (typeof line !== 'number') return undefined;
12782
+ const column = start.column ?? start.character ?? start.offset ?? start.Column;
12783
+ const endLine = end?.line ?? end?.Line;
12784
+ const endColumn = end?.column ?? end?.character ?? end?.offset ?? end?.Column;
12785
+ return {
12786
+ sourceId: input.sourceHash,
12787
+ path: range.path ?? range.filePath ?? range.file ?? input.sourcePath,
12788
+ startLine: line,
12789
+ startColumn: typeof column === 'number' ? column : undefined,
12790
+ endLine: typeof endLine === 'number' ? endLine : undefined,
12791
+ endColumn: typeof endColumn === 'number' ? endColumn : undefined
12792
+ };
12793
+ }
12794
+
12795
+ function kotlinPsiPosition(value, options = {}) {
12796
+ if (value === undefined || value === null) return undefined;
12797
+ if (typeof value === 'object') {
12798
+ const position = value.position ?? value.location ?? value;
12799
+ const line = position.line ?? position.Line;
12800
+ const column = position.column ?? position.character ?? position.Column;
12801
+ if (typeof line === 'number') {
12802
+ return {
12803
+ path: position.path ?? position.filePath ?? position.file,
12804
+ line,
12805
+ column: typeof column === 'number' ? column : undefined
12806
+ };
12807
+ }
12808
+ }
12809
+ const resolver = typeof options.positionResolver === 'function'
12810
+ ? options.positionResolver
12811
+ : typeof options.lineMap?.position === 'function'
12812
+ ? options.lineMap.position.bind(options.lineMap)
12813
+ : typeof options.lineMap?.getLineAndColumn === 'function'
12814
+ ? options.lineMap.getLineAndColumn.bind(options.lineMap)
12815
+ : undefined;
12816
+ if (resolver) {
12817
+ const resolved = resolver(value);
12818
+ if (resolved !== value) return kotlinPsiPosition(resolved, options);
12819
+ }
12820
+ return undefined;
12821
+ }
12822
+
12823
+ function kotlinPsiPositionKind(node) {
12824
+ if (node.textRange || node.range) return 'text-range';
12825
+ if (typeof node.startOffset === 'number') return 'offset';
12826
+ if (typeof node.startLine === 'number' || typeof node.line === 'number') return 'line-column-fields';
12827
+ return undefined;
12828
+ }
12829
+
12830
+ function kotlinPsiDeclarations(node, kind, nativeNodeId, input) {
12831
+ if (kind === 'KtPackageDirective') {
12832
+ const name = kotlinPsiPackageName(node);
12833
+ return name ? [declarationRecord(input, nativeNodeId, name, 'namespace', 'definition')] : [];
12834
+ }
12835
+ if (kind === 'KtImportDirective') {
12836
+ const name = kotlinPsiImportPath(node);
12837
+ return name ? [declarationRecord(input, nativeNodeId, name, 'module', 'import')] : [];
12838
+ }
12839
+ if (kotlinPsiTypeDeclarationKind(kind)) {
12840
+ const name = kotlinPsiDeclarationName(node, kind);
12841
+ return name ? [declarationRecord(input, nativeNodeId, name, kotlinPsiTypeDeclarationSymbolKind(node, kind), 'definition')] : [];
12842
+ }
12843
+ if (kind === 'KtTypeAlias') {
12844
+ const name = kotlinPsiDeclarationName(node, kind);
12845
+ return name ? [declarationRecord(input, nativeNodeId, name, 'type', 'definition')] : [];
12846
+ }
12847
+ if (kind === 'KtNamedFunction') {
12848
+ const name = kotlinPsiDeclarationName(node, kind);
12849
+ return name ? [declarationRecord(input, nativeNodeId, name, node.parentKind && kotlinPsiTypeDeclarationKind(node.parentKind) ? 'method' : 'function', kotlinPsiHasBody(node) ? 'definition' : 'declaration')] : [];
12850
+ }
12851
+ if (kind === 'KtProperty') {
12852
+ return kotlinPsiVariableNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'property', 'definition'));
12853
+ }
12854
+ if (kind === 'KtParameter' && node.parentKind === 'KtPrimaryConstructor') {
12855
+ return kotlinPsiVariableNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'property', 'definition'));
12856
+ }
12857
+ if (kind === 'KtPrimaryConstructor' || kind === 'KtSecondaryConstructor') {
12858
+ return [declarationRecord(input, nativeNodeId, kotlinPsiDeclarationName(node, kind) ?? 'constructor', 'method', 'definition')];
12859
+ }
12860
+ if (kind === 'KtEnumEntry') {
12861
+ const name = kotlinPsiDeclarationName(node, kind);
12862
+ return name ? [declarationRecord(input, nativeNodeId, name, 'enumMember', 'definition')] : [];
12863
+ }
12864
+ return [];
12865
+ }
12866
+
12867
+ function kotlinPsiChildEntries(node, kind = kotlinPsiKind(node)) {
12868
+ const fieldNames = Object.keys(node).filter((key) => !ignoredKotlinPsiField(key));
12869
+ const entries = [];
12870
+ for (const field of fieldNames) {
12871
+ const value = node[field];
12872
+ if (Array.isArray(value)) {
12873
+ entries.push([field, value.map((entry) => kotlinPsiChildWithParent(entry, kind, field))]);
12874
+ continue;
12875
+ }
12876
+ if (value && typeof value === 'object') {
12877
+ entries.push([field, kotlinPsiChildWithParent(value, kind, field)]);
12878
+ }
12879
+ }
12880
+ return entries.filter(([, value]) => Array.isArray(value)
12881
+ ? value.some(isKotlinPsiNode)
12882
+ : isKotlinPsiNode(value));
12883
+ }
12884
+
12885
+ function kotlinPsiChildWithParent(entry, parentKind, parentField) {
12886
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return entry;
12887
+ if (!isKotlinPsiNode(entry)) return entry;
12888
+ return { parentKind, parentField, ...entry };
12889
+ }
12890
+
12891
+ function kotlinPsiNodeValue(node) {
12892
+ return kotlinPsiDeclarationName(node, kotlinPsiKind(node))
12893
+ ?? kotlinPsiImportPath(node)
12894
+ ?? kotlinPsiPackageName(node)
12895
+ ?? kotlinPsiTypeName(node.typeReference ?? node.returnTypeRef ?? node.type);
12896
+ }
12897
+
12898
+ function kotlinPsiDeclarationName(node, kind = kotlinPsiKind(node)) {
12899
+ if (!node || typeof node !== 'object') return undefined;
12900
+ if (kind === 'KtPrimaryConstructor' || kind === 'KtSecondaryConstructor') return 'constructor';
12901
+ if (kind === 'KtClassInitializer') return 'init';
12902
+ if (kind === 'KtObjectDeclaration' && node.isCompanion === true && !node.name && !node.nameIdentifier) return 'companion object';
12903
+ for (const key of ['nameIdentifier', 'identifier', 'name', 'simpleName', 'classId', 'fqName', 'id']) {
12904
+ const name = kotlinPsiName(node[key]);
12905
+ if (name) return name;
12906
+ }
12907
+ const variable = kotlinPsiVariableNames(node)[0];
12908
+ if (variable) return variable;
12909
+ return undefined;
12910
+ }
12911
+
12912
+ function kotlinPsiName(value) {
12913
+ if (!value) return undefined;
12914
+ if (typeof value === 'string') return value;
12915
+ if (typeof value.asString === 'string') return value.asString;
12916
+ if (typeof value.identifier === 'string') return value.identifier;
12917
+ if (typeof value.name === 'string') return value.name;
12918
+ if (typeof value.text === 'string') return value.text;
12919
+ if (typeof value.value === 'string') return value.value;
12920
+ if (typeof value.fqName === 'string') return value.fqName;
12921
+ if (value.shortName && value.shortName !== value) return kotlinPsiName(value.shortName);
12922
+ if (value.name && value.name !== value) return kotlinPsiName(value.name);
12923
+ if (value.identifier && value.identifier !== value) return kotlinPsiName(value.identifier);
12924
+ return undefined;
12925
+ }
12926
+
12927
+ function kotlinPsiImportPath(node) {
12928
+ if (!node || typeof node !== 'object') return undefined;
12929
+ const path = node.importedFqName ?? node.importedReference ?? node.importPath ?? node.path ?? node.name;
12930
+ if (typeof path === 'string') return path;
12931
+ if (path && typeof path === 'object') return kotlinPsiName(path.fqName ?? path.name ?? path);
12932
+ return undefined;
12933
+ }
12934
+
12935
+ function kotlinPsiPackageName(node) {
12936
+ if (!node || typeof node !== 'object') return undefined;
12937
+ const value = node.packageFqName ?? node.fqName ?? node.qualifiedName ?? node.packageName;
12938
+ if (typeof value === 'string') return value;
12939
+ if (value && typeof value === 'object') return kotlinPsiName(value);
12940
+ return undefined;
12941
+ }
12942
+
12943
+ function kotlinPsiVariableNames(node) {
12944
+ const variables = node.variables ?? node.entries ?? node.declarations;
12945
+ if (Array.isArray(variables)) return variables.map(kotlinPsiDeclarationName).filter(Boolean);
12946
+ const name = kotlinPsiName(node.nameIdentifier ?? node.identifier ?? node.name);
12947
+ return name ? [name] : [];
12948
+ }
12949
+
12950
+ function kotlinPsiTypeName(value) {
12951
+ if (!value) return undefined;
12952
+ if (typeof value === 'string') return value;
12953
+ if (typeof value.text === 'string') return value.text.trim();
12954
+ if (typeof value.name === 'string') return value.name;
12955
+ if (typeof value.fqName === 'string') return value.fqName;
12956
+ if (value.typeElement) return kotlinPsiTypeName(value.typeElement);
12957
+ if (value.typeReference) return kotlinPsiTypeName(value.typeReference);
12958
+ if (value.referencedName) return kotlinPsiName(value.referencedName);
12959
+ if (value.constructorReferenceExpression) return kotlinPsiTypeName(value.constructorReferenceExpression);
12960
+ if (Array.isArray(value.typeArguments) || Array.isArray(value.arguments)) {
12961
+ const base = kotlinPsiName(value.name ?? value.referencedName ?? value.constructorReferenceExpression);
12962
+ const args = (value.typeArguments ?? value.arguments).map((entry) => kotlinPsiTypeName(entry.typeReference ?? entry)).filter(Boolean);
12963
+ return base ? `${base}<${args.join(', ')}>` : undefined;
12964
+ }
12965
+ return kotlinPsiName(value);
12966
+ }
12967
+
12968
+ function kotlinPsiModifiers(node) {
12969
+ const raw = node.modifiers ?? node.modifierList?.modifiers ?? node.modifierList?.children;
12970
+ const names = [];
12971
+ if (Array.isArray(raw)) {
12972
+ for (const entry of raw) {
12973
+ const name = typeof entry === 'string' ? entry : kotlinPsiName(entry) ?? entry?.keyword ?? entry?.tokenType ?? entry?.text;
12974
+ if (name) names.push(String(name).toLowerCase());
12975
+ }
12976
+ } else if (typeof raw === 'string') {
12977
+ names.push(...raw.split(/\s+/).filter(Boolean).map((entry) => entry.toLowerCase()));
12978
+ } else if (raw && typeof raw === 'object') {
12979
+ for (const [key, enabled] of Object.entries(raw)) {
12980
+ if (enabled === true) names.push(key.toLowerCase());
12981
+ }
12982
+ }
12983
+ for (const key of ['suspend', 'expect', 'actual', 'inline', 'operator', 'infix', 'tailrec', 'external', 'override', 'data', 'sealed', 'value']) {
12984
+ if (node[key] === true || node[`is${upperFirst(key)}`] === true) names.push(key);
12985
+ }
12986
+ return uniqueStrings(names.map((entry) => entry.replace(/keyword$/i, '').replace(/_keyword$/i, '').replace(/[_\s-]+/g, '').toLowerCase()).filter(Boolean));
12987
+ }
12988
+
12989
+ function kotlinPsiAnnotationNames(node) {
12990
+ const entries = node.annotationEntries ?? node.annotations ?? node.modifierList?.annotationEntries;
12991
+ if (!entries) return [];
12992
+ if (Array.isArray(entries)) {
12993
+ return uniqueStrings(entries.map((entry) => typeof entry === 'string' ? entry : kotlinPsiName(entry.shortName ?? entry.calleeExpression ?? entry.typeReference ?? entry.name ?? entry)).filter(Boolean));
12994
+ }
12995
+ return [];
12996
+ }
12997
+
12998
+ function kotlinPsiTypeDeclarationKind(kind) {
12999
+ return kind === 'KtClass'
13000
+ || kind === 'KtClassOrObject'
13001
+ || kind === 'KtObjectDeclaration';
13002
+ }
13003
+
13004
+ function kotlinPsiTypeDeclarationSymbolKind(node, kind) {
13005
+ const classKind = String(node.classKind ?? node.kindKeyword ?? '').toLowerCase();
13006
+ if (kind === 'KtObjectDeclaration') return 'class';
13007
+ if (classKind.includes('interface')) return 'interface';
13008
+ if (classKind.includes('enum')) return 'enum';
13009
+ if (classKind.includes('annotation')) return 'type';
13010
+ return 'class';
13011
+ }
13012
+
13013
+ function kotlinPsiHasBody(node) {
13014
+ return Boolean(node.bodyExpression || node.bodyBlockExpression || node.body || Array.isArray(node.statements));
13015
+ }
13016
+
13017
+ function kotlinPsiRecoveredKind(kind) {
13018
+ return kind === 'PsiErrorElement'
13019
+ || kind === 'KtErrorElement'
13020
+ || /Error|Recovery|Incomplete|Missing|Skipped/.test(String(kind));
13021
+ }
13022
+
13023
+ function kotlinPsiProblemNode(node, kind) {
13024
+ return Boolean(
13025
+ node.hasError
13026
+ || node.containsDiagnostics
13027
+ || node.containsSkippedText
13028
+ || node.isMissing
13029
+ || kind === 'PsiErrorElement'
13030
+ || kind === 'KtErrorElement'
13031
+ );
13032
+ }
13033
+
13034
+ function kotlinExpectActualNode(node) {
13035
+ const modifiers = kotlinPsiModifiers(node);
13036
+ return modifiers.includes('expect') || modifiers.includes('actual');
13037
+ }
13038
+
13039
+ function kotlinCoroutineNode(node, kind) {
13040
+ const modifiers = kotlinPsiModifiers(node);
13041
+ return modifiers.includes('suspend')
13042
+ || /Coroutine|Suspend/i.test(String(kind))
13043
+ || node.isSuspend === true
13044
+ || node.suspend === true;
13045
+ }
13046
+
13047
+ function kotlinContractNode(kind) {
13048
+ return /Contract/i.test(String(kind));
13049
+ }
13050
+
13051
+ function kotlinCompilerPluginAnnotationNode(node) {
13052
+ const names = kotlinPsiAnnotationNames(node);
13053
+ return names.some((name) => /^(Composable|Serializable|Parcelize|Entity|Immutable|Stable|AutoService|AssistedInject|Hilt|Inject|Room|KSerializable)$/i.test(name.replace(/^.*\./, '')));
13054
+ }
13055
+
13056
+ function kotlinGeneratedCodeMarker(node) {
13057
+ if (node.generated || node.isGenerated) return true;
13058
+ const path = String(node.filePath ?? node.path ?? node.sourcePath ?? '');
13059
+ return kotlinGeneratedSourcePath(path);
13060
+ }
13061
+
13062
+ function kotlinGeneratedSourcePath(path) {
13063
+ return typeof path === 'string' && (/(\.g|\.generated)\.kts?$/i.test(path) || /[\/\\](build|generated|ksp|kapt)[\/\\]/i.test(path));
13064
+ }
13065
+
13066
+ function kotlinGeneratedCodeLoss(input, nodeId, span, options = {}, metadata = {}) {
13067
+ return {
13068
+ id: `loss_${idFragment(nodeId ?? input.sourcePath ?? 'kotlin')}_kotlin_generated_code`,
13069
+ severity: 'warning',
13070
+ phase: 'parse',
13071
+ sourceFormat: input.language,
13072
+ kind: 'generatedCode',
13073
+ message: 'Kotlin generated-source marker was imported; generated member provenance and source ownership require host evidence.',
13074
+ span,
13075
+ nodeId,
13076
+ metadata: {
13077
+ parser: options.parser,
13078
+ astFormat: options.astFormat,
13079
+ kspEvidence: kotlinEvidenceSummary(options.kspEvidence),
13080
+ kaptEvidence: kotlinEvidenceSummary(options.kaptEvidence),
13081
+ compilerPluginEvidence: kotlinEvidenceSummary(options.compilerPluginEvidence),
13082
+ ...metadata
13083
+ }
13084
+ };
13085
+ }
13086
+
13087
+ function kotlinScriptLoss(input, nodeId, span, options = {}) {
13088
+ return {
13089
+ id: `loss_${idFragment(nodeId ?? input.sourcePath ?? 'kotlin')}_kotlin_script_semantics`,
13090
+ severity: 'warning',
13091
+ phase: 'parse',
13092
+ sourceFormat: input.language,
13093
+ kind: 'unsupportedSemantic',
13094
+ message: 'Kotlin script source was imported; script templates, implicit receivers, dependencies, and host execution environment require build/runtime evidence.',
13095
+ span,
13096
+ nodeId,
13097
+ metadata: {
13098
+ parser: options.parser,
13099
+ astFormat: options.astFormat,
13100
+ feature: 'script',
13101
+ unsupportedSemanticKind: 'kotlin.scriptContext',
13102
+ script: true,
13103
+ buildVariantEvidence: kotlinEvidenceSummary(options.buildVariantEvidence)
13104
+ }
13105
+ };
13106
+ }
13107
+
13108
+ function kotlinUnsupportedSemanticLoss(input, nodeId, span, options = {}, metadata = {}) {
13109
+ return {
13110
+ id: `loss_${idFragment(nodeId ?? input.sourcePath ?? 'kotlin')}_kotlin_${idFragment(metadata.feature ?? 'semantic')}`,
13111
+ severity: 'warning',
13112
+ phase: 'parse',
13113
+ sourceFormat: input.language,
13114
+ kind: 'unsupportedSemantic',
13115
+ message: metadata.message ?? 'Kotlin semantic feature requires host compiler evidence.',
13116
+ span,
13117
+ nodeId,
13118
+ metadata: {
13119
+ parser: options.parser,
13120
+ astFormat: options.astFormat,
13121
+ unsupportedSemanticKind: metadata.unsupportedSemanticKind ?? `kotlin.${idFragment(metadata.feature ?? 'semantic')}`,
13122
+ analysisApiEvidence: kotlinEvidenceSummary(options.analysisApiEvidence),
13123
+ firEvidence: kotlinEvidenceSummary(options.firEvidence),
13124
+ multiplatformEvidence: kotlinEvidenceSummary(options.multiplatformEvidence),
13125
+ ...metadata
13126
+ }
13127
+ };
13128
+ }
13129
+
13130
+ function kotlinEvidenceSummary(value) {
13131
+ if (!value) return undefined;
13132
+ if (Array.isArray(value)) return { entryCount: value.length };
13133
+ if (typeof value === 'string') return { value };
13134
+ if (typeof value === 'object') {
13135
+ const summary = {};
13136
+ if (typeof value.hash === 'string') summary.hash = value.hash;
13137
+ if (typeof value.solver === 'string') summary.solver = value.solver;
13138
+ if (Array.isArray(value.entries)) summary.entryCount = value.entries.length;
13139
+ if (Array.isArray(value.symbols)) summary.symbolCount = value.symbols.length;
13140
+ if (Array.isArray(value.references)) summary.referenceCount = value.references.length;
13141
+ if (Array.isArray(value.types)) summary.typeCount = value.types.length;
13142
+ if (Array.isArray(value.diagnostics)) summary.diagnosticCount = value.diagnostics.length;
13143
+ if (Array.isArray(value.plugins)) summary.pluginCount = value.plugins.length;
13144
+ if (Array.isArray(value.generatedSources)) summary.generatedSourceCount = value.generatedSources.length;
13145
+ if (Array.isArray(value.platforms)) summary.platformCount = value.platforms.length;
13146
+ if (Array.isArray(value.variants)) summary.variantCount = value.variants.length;
13147
+ return Object.keys(summary).length ? summary : { present: true };
13148
+ }
13149
+ return { present: true };
13150
+ }
13151
+
13152
+ function csharpRoslynRoot(value) {
13153
+ if (!value || typeof value !== 'object') return undefined;
13154
+ if (isCSharpRoslynNode(value)) return value;
13155
+ if (isCSharpRoslynNode(value.ast)) return value.ast;
13156
+ if (isCSharpRoslynNode(value.root)) return value.root;
13157
+ if (isCSharpRoslynNode(value.rootNode)) return value.rootNode;
13158
+ if (isCSharpRoslynNode(value.compilationUnit)) return value.compilationUnit;
13159
+ if (isCSharpRoslynNode(value.syntaxTree)) return csharpRoslynRoot(value.syntaxTree);
13160
+ if (isCSharpRoslynNode(value.tree)) return csharpRoslynRoot(value.tree);
13161
+ if (Array.isArray(value.members) || Array.isArray(value.usings) || Array.isArray(value.externs)) {
13162
+ return { kind: 'CompilationUnit', ...value };
13163
+ }
13164
+ return undefined;
13165
+ }
13166
+
13167
+ function isCSharpRoslynNode(value) {
13168
+ return Boolean(value && typeof value === 'object' && typeof csharpRoslynKind(value) === 'string');
13169
+ }
13170
+
13171
+ function csharpRoslynKind(node) {
13172
+ if (!node || typeof node !== 'object') return undefined;
13173
+ const declared = node.kind ?? node.Kind ?? node._type ?? node.type ?? node.nodeType ?? node.syntaxKind ?? node.SyntaxKind;
13174
+ if (typeof declared === 'string') return normalizeCSharpRoslynKind(declared);
13175
+ if (Array.isArray(node.members) || Array.isArray(node.usings) || Array.isArray(node.externs)) return 'CompilationUnit';
13176
+ if (node.identifier && (node.members || node.baseList || node.parameterList || node.modifiers)) return 'ClassDeclaration';
13177
+ if (node.declaration && (node.eventKeyword || node.eventField)) return 'EventFieldDeclaration';
13178
+ if (node.declaration && Array.isArray(node.declaration.variables)) return 'FieldDeclaration';
13179
+ return undefined;
13180
+ }
13181
+
13182
+ function normalizeCSharpRoslynKind(kind) {
13183
+ const text = String(kind)
13184
+ .replace(/^(?:Microsoft\.CodeAnalysis\.CSharp\.Syntax\.|Microsoft\.CodeAnalysis\.CSharp\.)/, '')
13185
+ .replace(/Syntax$/, '');
13186
+ const compact = text.replace(/[_\s.-]+/g, '').toLowerCase();
13187
+ if (compact === 'compilationunit') return 'CompilationUnit';
13188
+ if (compact === 'usingdirective') return 'UsingDirective';
13189
+ if (compact === 'namespacedeclaration') return 'NamespaceDeclaration';
13190
+ if (compact === 'filescopednamespacedeclaration') return 'FileScopedNamespaceDeclaration';
13191
+ if (compact === 'classdeclaration') return 'ClassDeclaration';
13192
+ if (compact === 'interfacedeclaration') return 'InterfaceDeclaration';
13193
+ if (compact === 'structdeclaration') return 'StructDeclaration';
13194
+ if (compact === 'recorddeclaration') return 'RecordDeclaration';
13195
+ if (compact === 'recordstructdeclaration') return 'RecordStructDeclaration';
13196
+ if (compact === 'enumdeclaration') return 'EnumDeclaration';
13197
+ if (compact === 'methoddeclaration') return 'MethodDeclaration';
13198
+ if (compact === 'constructordeclaration') return 'ConstructorDeclaration';
13199
+ if (compact === 'destructordeclaration') return 'DestructorDeclaration';
13200
+ if (compact === 'operatordeclaration') return 'OperatorDeclaration';
13201
+ if (compact === 'conversionoperatordeclaration') return 'ConversionOperatorDeclaration';
13202
+ if (compact === 'propertydeclaration') return 'PropertyDeclaration';
13203
+ if (compact === 'indexerdeclaration') return 'IndexerDeclaration';
13204
+ if (compact === 'fielddeclaration') return 'FieldDeclaration';
13205
+ if (compact === 'variabledeclarator') return 'VariableDeclarator';
13206
+ if (compact === 'eventdeclaration') return 'EventDeclaration';
13207
+ if (compact === 'eventfielddeclaration') return 'EventFieldDeclaration';
13208
+ if (compact === 'delegatedeclaration') return 'DelegateDeclaration';
13209
+ if (compact === 'enummemberdeclaration') return 'EnumMemberDeclaration';
13210
+ if (compact === 'attributelist') return 'AttributeList';
13211
+ if (compact === 'attribute') return 'Attribute';
13212
+ if (compact === 'parameter') return 'Parameter';
13213
+ if (compact === 'incompletemember') return 'IncompleteMember';
13214
+ if (compact === 'skippedtokenstrivia' || compact === 'skippedtokens') return 'SkippedTokensTrivia';
13215
+ if (compact.endsWith('directivetrivia')) return `${upperFirst(compact.slice(0, -'directivetrivia'.length))}DirectiveTrivia`;
13216
+ if (/^[A-Z0-9_]+$/.test(text)) return text.toLowerCase().split('_').map(upperFirst).join('');
13217
+ return text;
13218
+ }
13219
+
13220
+ function ignoredCSharpRoslynField(key) {
13221
+ return key === '_type'
13222
+ || key === 'type'
13223
+ || key === 'kind'
13224
+ || key === 'Kind'
13225
+ || key === 'nodeType'
13226
+ || key === 'syntaxKind'
13227
+ || key === 'SyntaxKind'
13228
+ || key === 'rawKind'
13229
+ || key === 'RawKind'
13230
+ || key === 'parent'
13231
+ || key === 'parentKind'
13232
+ || key === 'parentField'
13233
+ || key === 'span'
13234
+ || key === 'Span'
13235
+ || key === 'fullSpan'
13236
+ || key === 'FullSpan'
13237
+ || key === 'lineSpan'
13238
+ || key === 'location'
13239
+ || key === 'locations'
13240
+ || key === 'identifier'
13241
+ || key === 'name'
13242
+ || key === 'simpleName'
13243
+ || key === 'qualifiedName'
13244
+ || key === 'semanticModel'
13245
+ || key === 'symbol'
13246
+ || key === 'declaredSymbol'
13247
+ || key === 'typeInfo'
13248
+ || key === 'conversion'
13249
+ || key === 'constantValue';
13250
+ }
13251
+
13252
+ function primitiveCSharpRoslynFields(node, kind) {
13253
+ const fields = { kind };
13254
+ const name = csharpRoslynDeclarationName(node);
13255
+ if (name) fields.name = name;
13256
+ const importPath = csharpRoslynUsingPath(node);
13257
+ if (importPath) fields.importPath = importPath;
13258
+ const type = csharpRoslynTypeName(node.type ?? node.Type ?? node.returnType ?? node.ReturnType);
13259
+ if (type) fields.type = type;
13260
+ const modifiers = csharpRoslynModifierNames(node);
13261
+ if (modifiers.length) fields.modifiers = modifiers.join(',');
13262
+ const alias = csharpRoslynName(node.alias ?? node.Alias);
13263
+ if (alias) fields.alias = alias;
13264
+ if (node.static === true || node.isStatic === true) fields.static = true;
13265
+ if (node.global === true || node.isGlobal === true) fields.global = true;
13266
+ if (node.generated === true || node.Generated === true) fields.generated = true;
13267
+ if (node.containsDiagnostics === true || node.ContainsDiagnostics === true) fields.containsDiagnostics = true;
13268
+ if (node.containsSkippedText === true || node.ContainsSkippedText === true) fields.containsSkippedText = true;
13269
+ if (node.isMissing === true || node.IsMissing === true) fields.isMissing = true;
13270
+ if (Array.isArray(node.parameterList?.parameters ?? node.parameters)) fields.parameterCount = (node.parameterList?.parameters ?? node.parameters).length;
13271
+ if (Array.isArray(node.attributeLists)) fields.attributeListCount = node.attributeLists.length;
13272
+ return fields;
13273
+ }
13274
+
13275
+ function spanFromCSharpRoslynNode(node, input, options = {}) {
13276
+ const lineSpan = node.lineSpan ?? node.location?.lineSpan ?? node.location?.LineSpan ?? node.FileLinePositionSpan;
13277
+ const fromLineSpan = spanFromCSharpLineSpan(lineSpan, input);
13278
+ if (fromLineSpan) return fromLineSpan;
13279
+ const direct = spanFromCSharpLineFields(node, input);
13280
+ if (direct) return direct;
13281
+ const start = csharpRoslynPosition(node.start ?? node.Start ?? node.span?.start ?? node.Span?.Start ?? node.position, options);
13282
+ const end = csharpRoslynPosition(node.end ?? node.End ?? node.span?.end ?? node.Span?.End, options);
13283
+ if (!start) return undefined;
13284
+ return {
13285
+ sourceId: input.sourceHash,
13286
+ path: start.path ?? end?.path ?? input.sourcePath,
13287
+ startLine: start.line,
13288
+ startColumn: start.column,
13289
+ endLine: end?.line,
13290
+ endColumn: end?.column
13291
+ };
13292
+ }
13293
+
13294
+ function spanFromCSharpLineSpan(lineSpan, input) {
13295
+ if (!lineSpan || typeof lineSpan !== 'object') return undefined;
13296
+ const start = lineSpan.startLinePosition ?? lineSpan.StartLinePosition ?? lineSpan.start ?? lineSpan.Start;
13297
+ const end = lineSpan.endLinePosition ?? lineSpan.EndLinePosition ?? lineSpan.end ?? lineSpan.End;
13298
+ const line = start?.line ?? start?.Line;
13299
+ if (typeof line !== 'number') return undefined;
13300
+ const character = start.character ?? start.Character ?? start.column ?? start.Column;
13301
+ const endLine = end?.line ?? end?.Line;
13302
+ const endCharacter = end?.character ?? end?.Character ?? end?.column ?? end?.Column;
13303
+ return {
13304
+ sourceId: input.sourceHash,
13305
+ path: lineSpan.path ?? lineSpan.filePath ?? lineSpan.FilePath ?? input.sourcePath,
13306
+ startLine: line + 1,
13307
+ startColumn: typeof character === 'number' ? character + 1 : undefined,
13308
+ endLine: typeof endLine === 'number' ? endLine + 1 : undefined,
13309
+ endColumn: typeof endCharacter === 'number' ? endCharacter + 1 : undefined
13310
+ };
13311
+ }
13312
+
13313
+ function spanFromCSharpLineFields(node, input) {
13314
+ const startLine = node.startLine ?? node.line ?? node.beginLine;
13315
+ if (typeof startLine !== 'number') return undefined;
13316
+ return {
13317
+ sourceId: input.sourceHash,
13318
+ path: node.path ?? node.filePath ?? node.file ?? input.sourcePath,
13319
+ startLine,
13320
+ startColumn: node.startColumn ?? node.column ?? node.beginColumn,
13321
+ endLine: node.endLine,
13322
+ endColumn: node.endColumn
13323
+ };
13324
+ }
13325
+
13326
+ function csharpRoslynPosition(value, options = {}) {
13327
+ if (value === undefined || value === null) return undefined;
13328
+ if (typeof value === 'object') {
13329
+ const position = value.position ?? value.Position ?? value;
13330
+ const line = position.line ?? position.Line;
13331
+ const column = position.column ?? position.Column ?? position.character ?? position.Character;
13332
+ if (typeof line === 'number') {
13333
+ return {
13334
+ path: position.path ?? position.filePath ?? position.FilePath ?? position.file,
13335
+ line,
13336
+ column: typeof column === 'number' ? column : undefined
13337
+ };
13338
+ }
13339
+ }
13340
+ const resolver = typeof options.positionResolver === 'function'
13341
+ ? options.positionResolver
13342
+ : typeof options.lineMap?.position === 'function'
13343
+ ? options.lineMap.position.bind(options.lineMap)
13344
+ : typeof options.lineMap?.getLinePosition === 'function'
13345
+ ? options.lineMap.getLinePosition.bind(options.lineMap)
13346
+ : undefined;
13347
+ if (resolver) {
13348
+ const resolved = resolver(value);
13349
+ if (resolved !== value) return csharpRoslynPosition(resolved, options);
13350
+ }
13351
+ return undefined;
13352
+ }
13353
+
13354
+ function csharpRoslynPositionKind(node) {
13355
+ if (node.lineSpan || node.location?.lineSpan) return 'line-position-span';
13356
+ if (node.span || node.Span) return 'text-span';
13357
+ if (typeof node.startLine === 'number' || typeof node.line === 'number') return 'line-column-fields';
13358
+ return undefined;
13359
+ }
13360
+
13361
+ function csharpRoslynDeclarations(node, kind, nativeNodeId, input) {
13362
+ if (kind === 'UsingDirective') {
13363
+ const name = csharpRoslynUsingPath(node);
13364
+ return name ? [declarationRecord(input, nativeNodeId, name, 'module', 'import')] : [];
13365
+ }
13366
+ if (kind === 'NamespaceDeclaration' || kind === 'FileScopedNamespaceDeclaration') {
13367
+ const name = csharpRoslynDeclarationName(node);
13368
+ return name ? [declarationRecord(input, nativeNodeId, name, 'namespace', 'definition')] : [];
13369
+ }
13370
+ if (csharpRoslynTypeDeclarationKind(kind)) {
13371
+ const name = csharpRoslynDeclarationName(node);
13372
+ return name ? [declarationRecord(input, nativeNodeId, name, csharpRoslynTypeDeclarationSymbolKind(kind), 'definition')] : [];
13373
+ }
13374
+ if (kind === 'DelegateDeclaration') {
13375
+ const name = csharpRoslynDeclarationName(node);
13376
+ return name ? [declarationRecord(input, nativeNodeId, name, 'type', 'definition')] : [];
13377
+ }
13378
+ if (csharpRoslynMethodLikeKind(kind)) {
13379
+ const name = csharpRoslynDeclarationName(node) ?? csharpRoslynOperatorName(node, kind);
13380
+ return name ? [declarationRecord(input, nativeNodeId, name, 'method', csharpRoslynHasBody(node) ? 'definition' : 'declaration')] : [];
13381
+ }
13382
+ if (kind === 'PropertyDeclaration' || kind === 'IndexerDeclaration') {
13383
+ const name = csharpRoslynDeclarationName(node) ?? (kind === 'IndexerDeclaration' ? 'this[]' : undefined);
13384
+ return name ? [declarationRecord(input, nativeNodeId, name, 'property', 'definition')] : [];
13385
+ }
13386
+ if (kind === 'FieldDeclaration') {
13387
+ return csharpRoslynVariableNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'property', 'definition'));
13388
+ }
13389
+ if (kind === 'EventDeclaration') {
13390
+ const name = csharpRoslynDeclarationName(node);
13391
+ return name ? [declarationRecord(input, nativeNodeId, name, 'event', 'definition')] : [];
13392
+ }
13393
+ if (kind === 'EventFieldDeclaration') {
13394
+ return csharpRoslynVariableNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'event', 'definition'));
13395
+ }
13396
+ if (kind === 'VariableDeclarator') {
13397
+ if (node.parentKind === 'FieldDeclaration') {
13398
+ const name = csharpRoslynDeclarationName(node);
13399
+ return name ? [declarationRecord(input, nativeNodeId, name, 'property', 'definition')] : [];
13400
+ }
13401
+ if (node.parentKind === 'EventFieldDeclaration') {
13402
+ const name = csharpRoslynDeclarationName(node);
13403
+ return name ? [declarationRecord(input, nativeNodeId, name, 'event', 'definition')] : [];
13404
+ }
13405
+ return [];
13406
+ }
13407
+ if (kind === 'EnumMemberDeclaration') {
13408
+ const name = csharpRoslynDeclarationName(node);
13409
+ return name ? [declarationRecord(input, nativeNodeId, name, 'enumMember', 'definition')] : [];
13410
+ }
13411
+ return [];
13412
+ }
13413
+
13414
+ function csharpRoslynChildEntries(node, kind = csharpRoslynKind(node)) {
13415
+ const fieldNames = Object.keys(node).filter((key) => !ignoredCSharpRoslynField(key));
13416
+ const entries = [];
13417
+ for (const field of fieldNames) {
13418
+ const value = node[field];
13419
+ if (Array.isArray(value)) {
13420
+ entries.push([field, value.map((entry) => csharpRoslynChildWithParent(entry, kind, field))]);
13421
+ continue;
13422
+ }
13423
+ if (value && typeof value === 'object') {
13424
+ entries.push([field, csharpRoslynChildWithParent(value, kind, field)]);
13425
+ }
13426
+ }
13427
+ return entries.filter(([, value]) => Array.isArray(value)
13428
+ ? value.some(isCSharpRoslynNode)
13429
+ : isCSharpRoslynNode(value));
13430
+ }
13431
+
13432
+ function csharpRoslynChildWithParent(entry, parentKind, parentField) {
13433
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return entry;
13434
+ if (!isCSharpRoslynNode(entry)) return entry;
13435
+ return { parentKind, parentField, ...entry };
13436
+ }
13437
+
13438
+ function csharpRoslynNodeValue(node) {
13439
+ return csharpRoslynDeclarationName(node)
13440
+ ?? csharpRoslynUsingPath(node)
13441
+ ?? csharpRoslynTypeName(node.type ?? node.returnType)
13442
+ ?? csharpRoslynLiteralValue(node);
13443
+ }
13444
+
13445
+ function csharpRoslynDeclarationName(node) {
13446
+ if (!node || typeof node !== 'object') return undefined;
13447
+ for (const key of ['identifier', 'name', 'simpleName', 'qualifiedName', 'id']) {
13448
+ const value = node[key];
13449
+ const name = csharpRoslynName(value);
13450
+ if (name) return name;
13451
+ }
13452
+ if (node.declaration && typeof node.declaration === 'object') return csharpRoslynDeclarationName(node.declaration);
13453
+ return undefined;
13454
+ }
13455
+
13456
+ function csharpRoslynName(value) {
13457
+ if (!value) return undefined;
13458
+ if (typeof value === 'string') return value;
13459
+ if (typeof value.text === 'string') return value.text;
13460
+ if (typeof value.valueText === 'string') return value.valueText;
13461
+ if (typeof value.identifier === 'string') return value.identifier;
13462
+ if (typeof value.name === 'string') return value.name;
13463
+ if (typeof value.qualifiedName === 'string') return value.qualifiedName;
13464
+ if (typeof value.value === 'string') return value.value;
13465
+ if (value.identifier && value.identifier !== value) return csharpRoslynName(value.identifier);
13466
+ if (value.name && value.name !== value) return csharpRoslynName(value.name);
13467
+ return undefined;
13468
+ }
13469
+
13470
+ function csharpRoslynUsingPath(node) {
13471
+ if (!node || typeof node !== 'object') return undefined;
13472
+ return csharpRoslynName(node.name ?? node.Name ?? node.qualifiedName ?? node.path);
13473
+ }
13474
+
13475
+ function csharpRoslynVariableNames(node) {
13476
+ const variables = node.variables
13477
+ ?? node.declaration?.variables
13478
+ ?? node.Declaration?.Variables
13479
+ ?? node.variableDeclarators;
13480
+ if (Array.isArray(variables)) return variables.map(csharpRoslynDeclarationName).filter(Boolean);
13481
+ const name = csharpRoslynDeclarationName(node);
13482
+ return name ? [name] : [];
13483
+ }
13484
+
13485
+ function csharpRoslynTypeName(value) {
13486
+ if (!value) return undefined;
13487
+ if (typeof value === 'string') return value;
13488
+ if (typeof value.name === 'string') return value.name;
13489
+ if (typeof value.text === 'string') return value.text;
13490
+ if (typeof value.valueText === 'string') return value.valueText;
13491
+ if (typeof value.qualifiedName === 'string') return value.qualifiedName;
13492
+ if (value.elementType) {
13493
+ const inner = csharpRoslynTypeName(value.elementType);
13494
+ return inner ? `${inner}[]` : '[]';
13495
+ }
13496
+ if (Array.isArray(value.typeArgumentList?.arguments ?? value.typeArguments)) {
13497
+ const base = csharpRoslynName(value.name) ?? csharpRoslynName(value);
13498
+ const args = (value.typeArgumentList?.arguments ?? value.typeArguments).map(csharpRoslynTypeName).filter(Boolean);
13499
+ return base ? `${base}<${args.join(', ')}>` : undefined;
13500
+ }
13501
+ return csharpRoslynName(value);
13502
+ }
13503
+
13504
+ function csharpRoslynModifierNames(node) {
13505
+ const modifiers = node.modifiers ?? node.Modifiers;
13506
+ if (!modifiers) return [];
13507
+ if (Array.isArray(modifiers)) {
13508
+ return uniqueStrings(modifiers.map((entry) => typeof entry === 'string' ? entry : csharpRoslynName(entry) ?? entry.kind).filter(Boolean));
13509
+ }
13510
+ if (typeof modifiers === 'string') return uniqueStrings(modifiers.split(/\s+/).filter(Boolean));
13511
+ if (typeof modifiers === 'object') {
13512
+ return uniqueStrings(Object.entries(modifiers)
13513
+ .filter(([, enabled]) => enabled === true)
13514
+ .map(([key]) => key));
13515
+ }
13516
+ return [];
13517
+ }
13518
+
13519
+ function csharpRoslynTypeDeclarationKind(kind) {
13520
+ return kind === 'ClassDeclaration'
13521
+ || kind === 'InterfaceDeclaration'
13522
+ || kind === 'StructDeclaration'
13523
+ || kind === 'RecordDeclaration'
13524
+ || kind === 'RecordStructDeclaration'
13525
+ || kind === 'EnumDeclaration';
13526
+ }
13527
+
13528
+ function csharpRoslynTypeDeclarationSymbolKind(kind) {
13529
+ if (kind === 'ClassDeclaration' || kind === 'RecordDeclaration') return 'class';
13530
+ if (kind === 'InterfaceDeclaration') return 'interface';
13531
+ return 'type';
13532
+ }
13533
+
13534
+ function csharpRoslynMethodLikeKind(kind) {
13535
+ return kind === 'MethodDeclaration'
13536
+ || kind === 'ConstructorDeclaration'
13537
+ || kind === 'DestructorDeclaration'
13538
+ || kind === 'OperatorDeclaration'
13539
+ || kind === 'ConversionOperatorDeclaration';
13540
+ }
13541
+
13542
+ function csharpRoslynHasBody(node) {
13543
+ return Boolean(node.body || node.expressionBody || node.accessorList || Array.isArray(node.statements));
13544
+ }
13545
+
13546
+ function csharpRoslynOperatorName(node, kind) {
13547
+ if (kind === 'ConstructorDeclaration') return csharpRoslynDeclarationName(node);
13548
+ if (kind === 'DestructorDeclaration') return `~${csharpRoslynDeclarationName(node) ?? 'destructor'}`;
13549
+ if (kind === 'OperatorDeclaration') return `operator ${csharpRoslynName(node.operatorToken) ?? csharpRoslynName(node.operatorKeyword) ?? 'operator'}`;
13550
+ if (kind === 'ConversionOperatorDeclaration') return `operator ${csharpRoslynTypeName(node.type) ?? 'conversion'}`;
13551
+ return undefined;
13552
+ }
13553
+
13554
+ function csharpRoslynLiteralValue(node) {
13555
+ const value = node.value ?? node.literal;
13556
+ if (value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return value;
13557
+ return undefined;
13558
+ }
13559
+
13560
+ function csharpRoslynRecoveredKind(kind) {
13561
+ return kind === 'IncompleteMember'
13562
+ || kind === 'SkippedTokensTrivia'
13563
+ || /Skipped|Missing|Bad|Incomplete/.test(String(kind));
13564
+ }
13565
+
13566
+ function csharpRoslynProblemNode(node, kind) {
13567
+ return Boolean(
13568
+ node.containsDiagnostics
13569
+ || node.ContainsDiagnostics
13570
+ || node.containsSkippedText
13571
+ || node.ContainsSkippedText
13572
+ || node.isMissing
13573
+ || node.IsMissing
13574
+ || node.hasDiagnostics
13575
+ || node.HasDiagnostics
13576
+ || kind === 'IncompleteMember'
13577
+ || kind === 'SkippedTokensTrivia'
13578
+ );
13579
+ }
13580
+
13581
+ function csharpRoslynDirectiveKind(kind) {
13582
+ return /DirectiveTrivia$/.test(String(kind)) || /^(IfDirective|ElifDirective|ElseDirective|EndIfDirective|DefineDirective|UndefDirective|NullableDirective|RegionDirective|EndRegionDirective|PragmaWarningDirective|LineDirective|ErrorDirective|WarningDirective|LoadDirective|ReferenceDirective)/.test(String(kind));
13583
+ }
13584
+
13585
+ function csharpGeneratedCodeMarker(node, kind) {
13586
+ if (node.generated || node.Generated || node.isGenerated) return true;
13587
+ const path = String(node.filePath ?? node.path ?? node.sourcePath ?? '');
13588
+ if (csharpGeneratedSourcePath(path)) return true;
13589
+ if (kind === 'Attribute') {
13590
+ const name = csharpRoslynDeclarationName(node);
13591
+ if (name && /(^|\.)(GeneratedCode|CompilerGenerated|DebuggerNonUserCode)Attribute?$/.test(name)) return true;
13592
+ }
13593
+ const attributes = node.attributeLists ?? node.attributes;
13594
+ if (Array.isArray(attributes)) {
13595
+ return JSON.stringify(attributes).includes('GeneratedCode')
13596
+ || JSON.stringify(attributes).includes('CompilerGenerated');
13597
+ }
13598
+ return false;
13599
+ }
13600
+
13601
+ function csharpGeneratedSourcePath(path) {
13602
+ return typeof path === 'string' && /\.(g|generated|designer)\.cs$/i.test(path);
13603
+ }
13604
+
13605
+ function csharpGeneratedCodeLoss(input, nodeId, span, options = {}, metadata = {}) {
13606
+ return {
13607
+ id: `loss_${idFragment(nodeId ?? input.sourcePath ?? 'csharp')}_csharp_generated_code`,
13608
+ severity: 'warning',
13609
+ phase: 'parse',
13610
+ sourceFormat: input.language,
13611
+ kind: 'generatedCode',
13612
+ message: 'C# generated-source or source-generator marker was imported; generated member provenance and source ownership require host evidence.',
13613
+ span,
13614
+ nodeId,
13615
+ metadata: {
13616
+ parser: options.parser,
13617
+ astFormat: options.astFormat,
13618
+ sourceGeneratorEvidence: csharpEvidenceSummary(options.sourceGeneratorEvidence),
13619
+ ...metadata
13620
+ }
13621
+ };
13622
+ }
13623
+
13624
+ function csharpEvidenceSummary(value) {
13625
+ if (!value) return undefined;
13626
+ if (Array.isArray(value)) return { entryCount: value.length };
13627
+ if (typeof value === 'string') return { value };
13628
+ if (typeof value === 'object') {
13629
+ const summary = {};
13630
+ if (typeof value.hash === 'string') summary.hash = value.hash;
13631
+ if (typeof value.solver === 'string') summary.solver = value.solver;
13632
+ if (Array.isArray(value.entries)) summary.entryCount = value.entries.length;
13633
+ if (Array.isArray(value.references)) summary.referenceCount = value.references.length;
13634
+ if (Array.isArray(value.symbols)) summary.symbolCount = value.symbols.length;
13635
+ if (Array.isArray(value.diagnostics)) summary.diagnosticCount = value.diagnostics.length;
13636
+ if (Array.isArray(value.generators)) summary.generatorCount = value.generators.length;
13637
+ if (Array.isArray(value.projects)) summary.projectCount = value.projects.length;
13638
+ return Object.keys(summary).length ? summary : { present: true };
13639
+ }
13640
+ return { present: true };
13641
+ }
13642
+
13643
+ function swiftSyntaxRoot(value) {
13644
+ if (!value || typeof value !== 'object') return undefined;
13645
+ if (isSwiftSyntaxNode(value)) return value;
13646
+ if (isSwiftSyntaxNode(value.ast)) return value.ast;
13647
+ if (isSwiftSyntaxNode(value.root)) return value.root;
13648
+ if (isSwiftSyntaxNode(value.rootNode)) return value.rootNode;
13649
+ if (isSwiftSyntaxNode(value.sourceFile)) return value.sourceFile;
13650
+ if (isSwiftSyntaxNode(value.sourceFileSyntax)) return value.sourceFileSyntax;
13651
+ if (isSwiftSyntaxNode(value.tree)) return swiftSyntaxRoot(value.tree);
13652
+ if (Array.isArray(value.statements) || Array.isArray(value.members) || Array.isArray(value.declarations)) {
13653
+ return { kind: 'SourceFile', ...value };
13654
+ }
13655
+ return undefined;
13656
+ }
13657
+
13658
+ function isSwiftSyntaxNode(value) {
13659
+ return Boolean(value && typeof value === 'object' && typeof swiftSyntaxKind(value) === 'string');
13660
+ }
13661
+
13662
+ function swiftSyntaxKind(node) {
13663
+ if (!node || typeof node !== 'object') return undefined;
13664
+ const declared = node.kind ?? node.syntaxKind ?? node.SyntaxKind ?? node._syntaxKind ?? node._type ?? node.type ?? node.nodeType;
13665
+ if (typeof declared === 'string') return normalizeSwiftSyntaxKind(declared);
13666
+ if (Array.isArray(node.statements) || Array.isArray(node.members) || Array.isArray(node.declarations)) return 'SourceFile';
13667
+ if (node.identifier && (node.memberBlock || node.members || node.genericParameterClause || node.inheritanceClause)) return 'ClassDecl';
13668
+ if (node.signature && node.body) return 'FunctionDecl';
13669
+ if (node.importPath || node.path) return 'ImportDecl';
13670
+ return undefined;
13671
+ }
13672
+
13673
+ function normalizeSwiftSyntaxKind(kind) {
13674
+ const text = String(kind)
13675
+ .replace(/^SwiftSyntax\./, '')
13676
+ .replace(/Syntax$/, '');
13677
+ const compact = text.replace(/[_\s.-]+/g, '').toLowerCase();
13678
+ const known = {
13679
+ sourcefile: 'SourceFile',
13680
+ importdecl: 'ImportDecl',
13681
+ classdecl: 'ClassDecl',
13682
+ structdecl: 'StructDecl',
13683
+ enumdecl: 'EnumDecl',
13684
+ protocoldecl: 'ProtocolDecl',
13685
+ actordecl: 'ActorDecl',
13686
+ extensiondecl: 'ExtensionDecl',
13687
+ typealiasdecl: 'TypeAliasDecl',
13688
+ associatedtypedecl: 'AssociatedTypeDecl',
13689
+ functiondecl: 'FunctionDecl',
13690
+ initializerdecl: 'InitializerDecl',
13691
+ initdecl: 'InitializerDecl',
13692
+ deinitializerdecl: 'DeinitializerDecl',
13693
+ deinitdecl: 'DeinitializerDecl',
13694
+ subscriptdecl: 'SubscriptDecl',
13695
+ operatordecl: 'OperatorDecl',
13696
+ precedencegroupdecl: 'PrecedenceGroupDecl',
13697
+ variabledecl: 'VariableDecl',
13698
+ patternbinding: 'PatternBinding',
13699
+ enumcasedecl: 'EnumCaseDecl',
13700
+ enumcaseelement: 'EnumCaseElement',
13701
+ macrodecl: 'MacroDecl',
13702
+ macroexpansiondecl: 'MacroExpansionDecl',
13703
+ freestandingmacroexpansion: 'FreestandingMacroExpansion',
13704
+ freestandingmacroexpansionsyntax: 'FreestandingMacroExpansion',
13705
+ attributemacroexpansion: 'AttributeMacroExpansion',
13706
+ ifconfigdecl: 'IfConfigDecl',
13707
+ ifconfigexpr: 'IfConfigExpr',
13708
+ unexpectednodes: 'UnexpectedNodes',
13709
+ missingtoken: 'MissingToken',
13710
+ skippedtoken: 'SkippedToken',
13711
+ error: 'Error'
13712
+ };
13713
+ if (known[compact]) return known[compact];
12185
13714
  if (/^[A-Z0-9_]+$/.test(text)) return text.toLowerCase().split('_').map(upperFirst).join('');
12186
13715
  return text;
12187
13716
  }
12188
13717
 
12189
- function ignoredCSharpRoslynField(key) {
13718
+ function ignoredSwiftSyntaxField(key) {
12190
13719
  return key === '_type'
12191
13720
  || key === 'type'
12192
13721
  || key === 'kind'
12193
- || key === 'Kind'
12194
- || key === 'nodeType'
12195
13722
  || key === 'syntaxKind'
12196
13723
  || key === 'SyntaxKind'
12197
- || key === 'rawKind'
12198
- || key === 'RawKind'
13724
+ || key === '_syntaxKind'
13725
+ || key === 'nodeType'
12199
13726
  || key === 'parent'
12200
13727
  || key === 'parentKind'
12201
13728
  || key === 'parentField'
12202
- || key === 'span'
12203
- || key === 'Span'
12204
- || key === 'fullSpan'
12205
- || key === 'FullSpan'
12206
- || key === 'lineSpan'
13729
+ || key === 'position'
13730
+ || key === 'absolutePosition'
13731
+ || key === 'endPosition'
12207
13732
  || key === 'location'
12208
- || key === 'locations'
13733
+ || key === 'sourceRange'
13734
+ || key === 'range'
13735
+ || key === 'span'
12209
13736
  || key === 'identifier'
12210
13737
  || key === 'name'
12211
13738
  || key === 'simpleName'
12212
- || key === 'qualifiedName'
13739
+ || key === 'typeName'
13740
+ || key === 'sourceKitSymbol'
12213
13741
  || key === 'semanticModel'
12214
- || key === 'symbol'
12215
- || key === 'declaredSymbol'
12216
- || key === 'typeInfo'
12217
- || key === 'conversion'
12218
- || key === 'constantValue';
13742
+ || key === 'resolvedSymbol'
13743
+ || key === 'typeInfo';
12219
13744
  }
12220
13745
 
12221
- function primitiveCSharpRoslynFields(node, kind) {
13746
+ function primitiveSwiftSyntaxFields(node, kind) {
12222
13747
  const fields = { kind };
12223
- const name = csharpRoslynDeclarationName(node);
13748
+ const name = swiftSyntaxDeclarationName(node, kind);
12224
13749
  if (name) fields.name = name;
12225
- const importPath = csharpRoslynUsingPath(node);
13750
+ const importPath = swiftSyntaxImportPath(node);
12226
13751
  if (importPath) fields.importPath = importPath;
12227
- const type = csharpRoslynTypeName(node.type ?? node.Type ?? node.returnType ?? node.ReturnType);
13752
+ const type = swiftSyntaxTypeName(node.type ?? node.typeAnnotation?.type ?? node.returnClause?.type ?? node.extendedType);
12228
13753
  if (type) fields.type = type;
12229
- const modifiers = csharpRoslynModifierNames(node);
13754
+ const modifiers = swiftSyntaxModifierNames(node);
12230
13755
  if (modifiers.length) fields.modifiers = modifiers.join(',');
12231
- const alias = csharpRoslynName(node.alias ?? node.Alias);
12232
- if (alias) fields.alias = alias;
12233
- if (node.static === true || node.isStatic === true) fields.static = true;
12234
- if (node.global === true || node.isGlobal === true) fields.global = true;
12235
- if (node.generated === true || node.Generated === true) fields.generated = true;
12236
- if (node.containsDiagnostics === true || node.ContainsDiagnostics === true) fields.containsDiagnostics = true;
12237
- if (node.containsSkippedText === true || node.ContainsSkippedText === true) fields.containsSkippedText = true;
12238
- if (node.isMissing === true || node.IsMissing === true) fields.isMissing = true;
12239
- if (Array.isArray(node.parameterList?.parameters ?? node.parameters)) fields.parameterCount = (node.parameterList?.parameters ?? node.parameters).length;
12240
- if (Array.isArray(node.attributeLists)) fields.attributeListCount = node.attributeLists.length;
13756
+ const attributes = swiftSyntaxAttributeNames(node);
13757
+ if (attributes.length) fields.attributes = attributes.join(',');
13758
+ if (node.generated === true || node.isGenerated === true) fields.generated = true;
13759
+ if (node.isMissing === true || node.presence === 'missing') fields.isMissing = true;
13760
+ if (node.hasError === true || node.containsDiagnostics === true) fields.hasError = true;
13761
+ if (Array.isArray(node.genericParameterClause?.parameters ?? node.genericParameters)) fields.genericParameterCount = (node.genericParameterClause?.parameters ?? node.genericParameters).length;
13762
+ if (Array.isArray(node.inheritanceClause?.inheritedTypes ?? node.inheritedTypes)) fields.inheritedTypeCount = (node.inheritanceClause?.inheritedTypes ?? node.inheritedTypes).length;
13763
+ if (Array.isArray(node.signature?.parameterClause?.parameters ?? node.parameters)) fields.parameterCount = (node.signature?.parameterClause?.parameters ?? node.parameters).length;
12241
13764
  return fields;
12242
13765
  }
12243
13766
 
12244
- function spanFromCSharpRoslynNode(node, input, options = {}) {
12245
- const lineSpan = node.lineSpan ?? node.location?.lineSpan ?? node.location?.LineSpan ?? node.FileLinePositionSpan;
12246
- const fromLineSpan = spanFromCSharpLineSpan(lineSpan, input);
12247
- if (fromLineSpan) return fromLineSpan;
12248
- const direct = spanFromCSharpLineFields(node, input);
13767
+ function spanFromSwiftSyntaxNode(node, input, options = {}) {
13768
+ const direct = spanFromSwiftLineFields(node, input);
12249
13769
  if (direct) return direct;
12250
- const start = csharpRoslynPosition(node.start ?? node.Start ?? node.span?.start ?? node.Span?.Start ?? node.position, options);
12251
- const end = csharpRoslynPosition(node.end ?? node.End ?? node.span?.end ?? node.Span?.End, options);
13770
+ const range = node.sourceRange ?? node.range ?? node.span;
13771
+ const fromRange = spanFromSwiftRange(range, input);
13772
+ if (fromRange) return fromRange;
13773
+ const start = swiftSyntaxPosition(node.position ?? node.absolutePosition ?? node.start ?? range?.start, options);
13774
+ const end = swiftSyntaxPosition(node.endPosition ?? node.end ?? range?.end, options);
12252
13775
  if (!start) return undefined;
12253
13776
  return {
12254
13777
  sourceId: input.sourceHash,
@@ -12260,26 +13783,7 @@ function spanFromCSharpRoslynNode(node, input, options = {}) {
12260
13783
  };
12261
13784
  }
12262
13785
 
12263
- function spanFromCSharpLineSpan(lineSpan, input) {
12264
- if (!lineSpan || typeof lineSpan !== 'object') return undefined;
12265
- const start = lineSpan.startLinePosition ?? lineSpan.StartLinePosition ?? lineSpan.start ?? lineSpan.Start;
12266
- const end = lineSpan.endLinePosition ?? lineSpan.EndLinePosition ?? lineSpan.end ?? lineSpan.End;
12267
- const line = start?.line ?? start?.Line;
12268
- if (typeof line !== 'number') return undefined;
12269
- const character = start.character ?? start.Character ?? start.column ?? start.Column;
12270
- const endLine = end?.line ?? end?.Line;
12271
- const endCharacter = end?.character ?? end?.Character ?? end?.column ?? end?.Column;
12272
- return {
12273
- sourceId: input.sourceHash,
12274
- path: lineSpan.path ?? lineSpan.filePath ?? lineSpan.FilePath ?? input.sourcePath,
12275
- startLine: line + 1,
12276
- startColumn: typeof character === 'number' ? character + 1 : undefined,
12277
- endLine: typeof endLine === 'number' ? endLine + 1 : undefined,
12278
- endColumn: typeof endCharacter === 'number' ? endCharacter + 1 : undefined
12279
- };
12280
- }
12281
-
12282
- function spanFromCSharpLineFields(node, input) {
13786
+ function spanFromSwiftLineFields(node, input) {
12283
13787
  const startLine = node.startLine ?? node.line ?? node.beginLine;
12284
13788
  if (typeof startLine !== 'number') return undefined;
12285
13789
  return {
@@ -12292,15 +13796,34 @@ function spanFromCSharpLineFields(node, input) {
12292
13796
  };
12293
13797
  }
12294
13798
 
12295
- function csharpRoslynPosition(value, options = {}) {
13799
+ function spanFromSwiftRange(range, input) {
13800
+ if (!range || typeof range !== 'object') return undefined;
13801
+ const start = range.start ?? range.lowerBound ?? range.begin;
13802
+ const end = range.end ?? range.upperBound;
13803
+ const line = start?.line ?? start?.Line;
13804
+ if (typeof line !== 'number') return undefined;
13805
+ const column = start.column ?? start.character ?? start.utf8Column ?? start.Column;
13806
+ const endLine = end?.line ?? end?.Line;
13807
+ const endColumn = end?.column ?? end?.character ?? end?.utf8Column ?? end?.Column;
13808
+ return {
13809
+ sourceId: input.sourceHash,
13810
+ path: range.path ?? range.filePath ?? range.file ?? input.sourcePath,
13811
+ startLine: line,
13812
+ startColumn: typeof column === 'number' ? column : undefined,
13813
+ endLine: typeof endLine === 'number' ? endLine : undefined,
13814
+ endColumn: typeof endColumn === 'number' ? endColumn : undefined
13815
+ };
13816
+ }
13817
+
13818
+ function swiftSyntaxPosition(value, options = {}) {
12296
13819
  if (value === undefined || value === null) return undefined;
12297
13820
  if (typeof value === 'object') {
12298
- const position = value.position ?? value.Position ?? value;
13821
+ const position = value.position ?? value.location ?? value;
12299
13822
  const line = position.line ?? position.Line;
12300
- const column = position.column ?? position.Column ?? position.character ?? position.Character;
13823
+ const column = position.column ?? position.character ?? position.utf8Column ?? position.Column;
12301
13824
  if (typeof line === 'number') {
12302
13825
  return {
12303
- path: position.path ?? position.filePath ?? position.FilePath ?? position.file,
13826
+ path: position.path ?? position.filePath ?? position.file,
12304
13827
  line,
12305
13828
  column: typeof column === 'number' ? column : undefined
12306
13829
  };
@@ -12310,171 +13833,164 @@ function csharpRoslynPosition(value, options = {}) {
12310
13833
  ? options.positionResolver
12311
13834
  : typeof options.lineMap?.position === 'function'
12312
13835
  ? options.lineMap.position.bind(options.lineMap)
12313
- : typeof options.lineMap?.getLinePosition === 'function'
12314
- ? options.lineMap.getLinePosition.bind(options.lineMap)
13836
+ : typeof options.sourceLocationConverter?.location === 'function'
13837
+ ? options.sourceLocationConverter.location.bind(options.sourceLocationConverter)
12315
13838
  : undefined;
12316
13839
  if (resolver) {
12317
13840
  const resolved = resolver(value);
12318
- if (resolved !== value) return csharpRoslynPosition(resolved, options);
13841
+ if (resolved !== value) return swiftSyntaxPosition(resolved, options);
12319
13842
  }
12320
13843
  return undefined;
12321
13844
  }
12322
13845
 
12323
- function csharpRoslynPositionKind(node) {
12324
- if (node.lineSpan || node.location?.lineSpan) return 'line-position-span';
12325
- if (node.span || node.Span) return 'text-span';
13846
+ function swiftSyntaxPositionKind(node) {
13847
+ if (node.sourceRange || node.range) return 'source-range';
13848
+ if (node.position || node.absolutePosition) return 'absolute-position';
12326
13849
  if (typeof node.startLine === 'number' || typeof node.line === 'number') return 'line-column-fields';
12327
13850
  return undefined;
12328
13851
  }
12329
13852
 
12330
- function csharpRoslynDeclarations(node, kind, nativeNodeId, input) {
12331
- if (kind === 'UsingDirective') {
12332
- const name = csharpRoslynUsingPath(node);
13853
+ function swiftSyntaxDeclarations(node, kind, nativeNodeId, input) {
13854
+ if (kind === 'ImportDecl') {
13855
+ const name = swiftSyntaxImportPath(node);
12333
13856
  return name ? [declarationRecord(input, nativeNodeId, name, 'module', 'import')] : [];
12334
13857
  }
12335
- if (kind === 'NamespaceDeclaration' || kind === 'FileScopedNamespaceDeclaration') {
12336
- const name = csharpRoslynDeclarationName(node);
12337
- return name ? [declarationRecord(input, nativeNodeId, name, 'namespace', 'definition')] : [];
12338
- }
12339
- if (csharpRoslynTypeDeclarationKind(kind)) {
12340
- const name = csharpRoslynDeclarationName(node);
12341
- return name ? [declarationRecord(input, nativeNodeId, name, csharpRoslynTypeDeclarationSymbolKind(kind), 'definition')] : [];
13858
+ if (swiftSyntaxTypeDeclarationKind(kind)) {
13859
+ const name = swiftSyntaxDeclarationName(node, kind);
13860
+ return name ? [declarationRecord(input, nativeNodeId, name, swiftSyntaxTypeDeclarationSymbolKind(kind), 'definition')] : [];
12342
13861
  }
12343
- if (kind === 'DelegateDeclaration') {
12344
- const name = csharpRoslynDeclarationName(node);
13862
+ if (kind === 'ExtensionDecl') {
13863
+ const name = swiftSyntaxDeclarationName(node, kind);
12345
13864
  return name ? [declarationRecord(input, nativeNodeId, name, 'type', 'definition')] : [];
12346
13865
  }
12347
- if (csharpRoslynMethodLikeKind(kind)) {
12348
- const name = csharpRoslynDeclarationName(node) ?? csharpRoslynOperatorName(node, kind);
12349
- return name ? [declarationRecord(input, nativeNodeId, name, 'method', csharpRoslynHasBody(node) ? 'definition' : 'declaration')] : [];
12350
- }
12351
- if (kind === 'PropertyDeclaration' || kind === 'IndexerDeclaration') {
12352
- const name = csharpRoslynDeclarationName(node) ?? (kind === 'IndexerDeclaration' ? 'this[]' : undefined);
12353
- return name ? [declarationRecord(input, nativeNodeId, name, 'property', 'definition')] : [];
13866
+ if (kind === 'TypeAliasDecl' || kind === 'AssociatedTypeDecl') {
13867
+ const name = swiftSyntaxDeclarationName(node, kind);
13868
+ return name ? [declarationRecord(input, nativeNodeId, name, 'type', 'definition')] : [];
12354
13869
  }
12355
- if (kind === 'FieldDeclaration') {
12356
- return csharpRoslynVariableNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'property', 'definition'));
13870
+ if (swiftSyntaxFunctionLikeKind(kind)) {
13871
+ const name = swiftSyntaxDeclarationName(node, kind) ?? swiftSyntaxOperatorName(node, kind);
13872
+ return name ? [declarationRecord(input, nativeNodeId, name, kind === 'FunctionDecl' ? 'function' : 'method', swiftSyntaxHasBody(node) ? 'definition' : 'declaration')] : [];
12357
13873
  }
12358
- if (kind === 'EventDeclaration') {
12359
- const name = csharpRoslynDeclarationName(node);
12360
- return name ? [declarationRecord(input, nativeNodeId, name, 'event', 'definition')] : [];
13874
+ if (kind === 'VariableDecl') {
13875
+ return swiftSyntaxVariableNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'property', 'definition'));
12361
13876
  }
12362
- if (kind === 'EventFieldDeclaration') {
12363
- return csharpRoslynVariableNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'event', 'definition'));
13877
+ if (kind === 'PatternBinding' && node.parentKind === 'VariableDecl') {
13878
+ const name = swiftSyntaxDeclarationName(node, kind);
13879
+ return name ? [declarationRecord(input, nativeNodeId, name, 'property', 'definition')] : [];
12364
13880
  }
12365
- if (kind === 'VariableDeclarator') {
12366
- if (node.parentKind === 'FieldDeclaration') {
12367
- const name = csharpRoslynDeclarationName(node);
12368
- return name ? [declarationRecord(input, nativeNodeId, name, 'property', 'definition')] : [];
12369
- }
12370
- if (node.parentKind === 'EventFieldDeclaration') {
12371
- const name = csharpRoslynDeclarationName(node);
12372
- return name ? [declarationRecord(input, nativeNodeId, name, 'event', 'definition')] : [];
12373
- }
12374
- return [];
13881
+ if (kind === 'EnumCaseDecl') {
13882
+ return swiftSyntaxEnumCaseNames(node).map((name) => declarationRecord(input, nativeNodeId, name, 'enumMember', 'definition'));
12375
13883
  }
12376
- if (kind === 'EnumMemberDeclaration') {
12377
- const name = csharpRoslynDeclarationName(node);
13884
+ if (kind === 'EnumCaseElement') {
13885
+ const name = swiftSyntaxDeclarationName(node, kind);
12378
13886
  return name ? [declarationRecord(input, nativeNodeId, name, 'enumMember', 'definition')] : [];
12379
13887
  }
12380
13888
  return [];
12381
13889
  }
12382
13890
 
12383
- function csharpRoslynChildEntries(node, kind = csharpRoslynKind(node)) {
12384
- const fieldNames = Object.keys(node).filter((key) => !ignoredCSharpRoslynField(key));
13891
+ function swiftSyntaxChildEntries(node, kind = swiftSyntaxKind(node)) {
13892
+ const fieldNames = Object.keys(node).filter((key) => !ignoredSwiftSyntaxField(key));
12385
13893
  const entries = [];
12386
13894
  for (const field of fieldNames) {
12387
13895
  const value = node[field];
12388
13896
  if (Array.isArray(value)) {
12389
- entries.push([field, value.map((entry) => csharpRoslynChildWithParent(entry, kind, field))]);
13897
+ entries.push([field, value.map((entry) => swiftSyntaxChildWithParent(entry, kind, field))]);
12390
13898
  continue;
12391
13899
  }
12392
13900
  if (value && typeof value === 'object') {
12393
- entries.push([field, csharpRoslynChildWithParent(value, kind, field)]);
13901
+ entries.push([field, swiftSyntaxChildWithParent(value, kind, field)]);
12394
13902
  }
12395
13903
  }
12396
13904
  return entries.filter(([, value]) => Array.isArray(value)
12397
- ? value.some(isCSharpRoslynNode)
12398
- : isCSharpRoslynNode(value));
13905
+ ? value.some(isSwiftSyntaxNode)
13906
+ : isSwiftSyntaxNode(value));
12399
13907
  }
12400
13908
 
12401
- function csharpRoslynChildWithParent(entry, parentKind, parentField) {
13909
+ function swiftSyntaxChildWithParent(entry, parentKind, parentField) {
12402
13910
  if (!entry || typeof entry !== 'object' || Array.isArray(entry)) return entry;
12403
- if (!isCSharpRoslynNode(entry)) return entry;
13911
+ if (!isSwiftSyntaxNode(entry)) return entry;
12404
13912
  return { parentKind, parentField, ...entry };
12405
13913
  }
12406
13914
 
12407
- function csharpRoslynNodeValue(node) {
12408
- return csharpRoslynDeclarationName(node)
12409
- ?? csharpRoslynUsingPath(node)
12410
- ?? csharpRoslynTypeName(node.type ?? node.returnType)
12411
- ?? csharpRoslynLiteralValue(node);
13915
+ function swiftSyntaxNodeValue(node) {
13916
+ return swiftSyntaxDeclarationName(node, swiftSyntaxKind(node))
13917
+ ?? swiftSyntaxImportPath(node)
13918
+ ?? swiftSyntaxTypeName(node.type ?? node.returnClause?.type ?? node.extendedType)
13919
+ ?? swiftSyntaxLiteralValue(node);
12412
13920
  }
12413
13921
 
12414
- function csharpRoslynDeclarationName(node) {
13922
+ function swiftSyntaxDeclarationName(node, kind = swiftSyntaxKind(node)) {
12415
13923
  if (!node || typeof node !== 'object') return undefined;
12416
- for (const key of ['identifier', 'name', 'simpleName', 'qualifiedName', 'id']) {
12417
- const value = node[key];
12418
- const name = csharpRoslynName(value);
13924
+ if (kind === 'InitializerDecl') return 'init';
13925
+ if (kind === 'DeinitializerDecl') return 'deinit';
13926
+ if (kind === 'SubscriptDecl') return 'subscript';
13927
+ if (kind === 'ExtensionDecl') {
13928
+ const extended = swiftSyntaxTypeName(node.extendedType ?? node.type ?? node.name);
13929
+ return extended ? `extension ${extended}` : undefined;
13930
+ }
13931
+ if (kind === 'OperatorDecl') return swiftSyntaxOperatorName(node, kind);
13932
+ for (const key of ['identifier', 'name', 'simpleName', 'typeName', 'id']) {
13933
+ const name = swiftSyntaxName(node[key]);
12419
13934
  if (name) return name;
12420
13935
  }
12421
- if (node.declaration && typeof node.declaration === 'object') return csharpRoslynDeclarationName(node.declaration);
13936
+ const patternName = swiftSyntaxPatternName(node.pattern);
13937
+ if (patternName) return patternName;
12422
13938
  return undefined;
12423
13939
  }
12424
13940
 
12425
- function csharpRoslynName(value) {
13941
+ function swiftSyntaxName(value) {
12426
13942
  if (!value) return undefined;
12427
13943
  if (typeof value === 'string') return value;
12428
13944
  if (typeof value.text === 'string') return value.text;
12429
- if (typeof value.valueText === 'string') return value.valueText;
13945
+ if (typeof value.trimmedDescription === 'string') return value.trimmedDescription;
13946
+ if (typeof value.description === 'string' && !value.description.includes('[object Object]')) return value.description.trim();
12430
13947
  if (typeof value.identifier === 'string') return value.identifier;
12431
13948
  if (typeof value.name === 'string') return value.name;
12432
- if (typeof value.qualifiedName === 'string') return value.qualifiedName;
12433
13949
  if (typeof value.value === 'string') return value.value;
12434
- if (value.identifier && value.identifier !== value) return csharpRoslynName(value.identifier);
12435
- if (value.name && value.name !== value) return csharpRoslynName(value.name);
13950
+ if (value.tokenKind && typeof value.tokenKind === 'object') return swiftSyntaxName(value.tokenKind);
13951
+ if (value.identifier && value.identifier !== value) return swiftSyntaxName(value.identifier);
13952
+ if (value.name && value.name !== value) return swiftSyntaxName(value.name);
12436
13953
  return undefined;
12437
13954
  }
12438
13955
 
12439
- function csharpRoslynUsingPath(node) {
13956
+ function swiftSyntaxImportPath(node) {
12440
13957
  if (!node || typeof node !== 'object') return undefined;
12441
- return csharpRoslynName(node.name ?? node.Name ?? node.qualifiedName ?? node.path);
12442
- }
12443
-
12444
- function csharpRoslynVariableNames(node) {
12445
- const variables = node.variables
12446
- ?? node.declaration?.variables
12447
- ?? node.Declaration?.Variables
12448
- ?? node.variableDeclarators;
12449
- if (Array.isArray(variables)) return variables.map(csharpRoslynDeclarationName).filter(Boolean);
12450
- const name = csharpRoslynDeclarationName(node);
12451
- return name ? [name] : [];
13958
+ const path = node.importPath ?? node.path ?? node.modulePath ?? node.name;
13959
+ if (typeof path === 'string') return path;
13960
+ if (Array.isArray(path)) {
13961
+ return path.map((entry) => swiftSyntaxName(entry.name ?? entry.identifier ?? entry)).filter(Boolean).join('.');
13962
+ }
13963
+ if (path && typeof path === 'object') {
13964
+ if (Array.isArray(path.components)) return path.components.map((entry) => swiftSyntaxName(entry.name ?? entry.identifier ?? entry)).filter(Boolean).join('.');
13965
+ return swiftSyntaxName(path);
13966
+ }
13967
+ return undefined;
12452
13968
  }
12453
13969
 
12454
- function csharpRoslynTypeName(value) {
13970
+ function swiftSyntaxTypeName(value) {
12455
13971
  if (!value) return undefined;
12456
13972
  if (typeof value === 'string') return value;
13973
+ if (typeof value.trimmedDescription === 'string') return value.trimmedDescription;
13974
+ if (typeof value.description === 'string' && !value.description.includes('[object Object]')) return value.description.trim();
12457
13975
  if (typeof value.name === 'string') return value.name;
12458
13976
  if (typeof value.text === 'string') return value.text;
12459
- if (typeof value.valueText === 'string') return value.valueText;
12460
- if (typeof value.qualifiedName === 'string') return value.qualifiedName;
12461
- if (value.elementType) {
12462
- const inner = csharpRoslynTypeName(value.elementType);
12463
- return inner ? `${inner}[]` : '[]';
13977
+ if (value.baseType) {
13978
+ const base = swiftSyntaxTypeName(value.baseType);
13979
+ return base && value.name ? `${base}.${swiftSyntaxName(value.name)}` : base;
12464
13980
  }
12465
- if (Array.isArray(value.typeArgumentList?.arguments ?? value.typeArguments)) {
12466
- const base = csharpRoslynName(value.name) ?? csharpRoslynName(value);
12467
- const args = (value.typeArgumentList?.arguments ?? value.typeArguments).map(csharpRoslynTypeName).filter(Boolean);
13981
+ if (value.argumentList && Array.isArray(value.argumentList)) {
13982
+ const base = swiftSyntaxName(value.name) ?? swiftSyntaxTypeName(value.baseName);
13983
+ const args = value.argumentList.map((entry) => swiftSyntaxTypeName(entry.type ?? entry)).filter(Boolean);
12468
13984
  return base ? `${base}<${args.join(', ')}>` : undefined;
12469
13985
  }
12470
- return csharpRoslynName(value);
13986
+ return swiftSyntaxName(value);
12471
13987
  }
12472
13988
 
12473
- function csharpRoslynModifierNames(node) {
13989
+ function swiftSyntaxModifierNames(node) {
12474
13990
  const modifiers = node.modifiers ?? node.Modifiers;
12475
13991
  if (!modifiers) return [];
12476
13992
  if (Array.isArray(modifiers)) {
12477
- return uniqueStrings(modifiers.map((entry) => typeof entry === 'string' ? entry : csharpRoslynName(entry) ?? entry.kind).filter(Boolean));
13993
+ return uniqueStrings(modifiers.map((entry) => typeof entry === 'string' ? entry : swiftSyntaxName(entry.name ?? entry.modifier ?? entry)).filter(Boolean));
12478
13994
  }
12479
13995
  if (typeof modifiers === 'string') return uniqueStrings(modifiers.split(/\s+/).filter(Boolean));
12480
13996
  if (typeof modifiers === 'object') {
@@ -12485,112 +14001,142 @@ function csharpRoslynModifierNames(node) {
12485
14001
  return [];
12486
14002
  }
12487
14003
 
12488
- function csharpRoslynTypeDeclarationKind(kind) {
12489
- return kind === 'ClassDeclaration'
12490
- || kind === 'InterfaceDeclaration'
12491
- || kind === 'StructDeclaration'
12492
- || kind === 'RecordDeclaration'
12493
- || kind === 'RecordStructDeclaration'
12494
- || kind === 'EnumDeclaration';
14004
+ function swiftSyntaxAttributeNames(node) {
14005
+ const attributes = node.attributes ?? node.attributeList;
14006
+ if (!attributes) return [];
14007
+ if (Array.isArray(attributes)) {
14008
+ return uniqueStrings(attributes.map((entry) => typeof entry === 'string' ? entry : swiftSyntaxName(entry.attributeName ?? entry.name ?? entry)).filter(Boolean));
14009
+ }
14010
+ return [];
12495
14011
  }
12496
14012
 
12497
- function csharpRoslynTypeDeclarationSymbolKind(kind) {
12498
- if (kind === 'ClassDeclaration' || kind === 'RecordDeclaration') return 'class';
12499
- if (kind === 'InterfaceDeclaration') return 'interface';
14013
+ function swiftSyntaxVariableNames(node) {
14014
+ const bindings = node.bindings ?? node.bindingSpecifier?.bindings ?? node.patternBindings;
14015
+ if (Array.isArray(bindings)) return bindings.map((binding) => swiftSyntaxPatternName(binding.pattern ?? binding)).filter(Boolean);
14016
+ const name = swiftSyntaxPatternName(node.pattern) ?? swiftSyntaxDeclarationName(node);
14017
+ return name ? [name] : [];
14018
+ }
14019
+
14020
+ function swiftSyntaxEnumCaseNames(node) {
14021
+ const elements = node.elements ?? node.caseElements ?? node.cases;
14022
+ if (Array.isArray(elements)) return elements.map((entry) => swiftSyntaxDeclarationName(entry, 'EnumCaseElement')).filter(Boolean);
14023
+ const name = swiftSyntaxDeclarationName(node);
14024
+ return name ? [name] : [];
14025
+ }
14026
+
14027
+ function swiftSyntaxPatternName(pattern) {
14028
+ if (!pattern) return undefined;
14029
+ if (typeof pattern === 'string') return pattern;
14030
+ return swiftSyntaxName(pattern.identifier ?? pattern.name ?? pattern.boundName ?? pattern.pattern ?? pattern);
14031
+ }
14032
+
14033
+ function swiftSyntaxTypeDeclarationKind(kind) {
14034
+ return kind === 'ClassDecl'
14035
+ || kind === 'StructDecl'
14036
+ || kind === 'EnumDecl'
14037
+ || kind === 'ProtocolDecl'
14038
+ || kind === 'ActorDecl';
14039
+ }
14040
+
14041
+ function swiftSyntaxTypeDeclarationSymbolKind(kind) {
14042
+ if (kind === 'ClassDecl') return 'class';
14043
+ if (kind === 'StructDecl') return 'struct';
14044
+ if (kind === 'EnumDecl') return 'enum';
14045
+ if (kind === 'ProtocolDecl') return 'protocol';
14046
+ if (kind === 'ActorDecl') return 'class';
12500
14047
  return 'type';
12501
14048
  }
12502
14049
 
12503
- function csharpRoslynMethodLikeKind(kind) {
12504
- return kind === 'MethodDeclaration'
12505
- || kind === 'ConstructorDeclaration'
12506
- || kind === 'DestructorDeclaration'
12507
- || kind === 'OperatorDeclaration'
12508
- || kind === 'ConversionOperatorDeclaration';
14050
+ function swiftSyntaxFunctionLikeKind(kind) {
14051
+ return kind === 'FunctionDecl'
14052
+ || kind === 'InitializerDecl'
14053
+ || kind === 'DeinitializerDecl'
14054
+ || kind === 'SubscriptDecl'
14055
+ || kind === 'OperatorDecl'
14056
+ || kind === 'PrecedenceGroupDecl';
12509
14057
  }
12510
14058
 
12511
- function csharpRoslynHasBody(node) {
12512
- return Boolean(node.body || node.expressionBody || node.accessorList || Array.isArray(node.statements));
14059
+ function swiftSyntaxHasBody(node) {
14060
+ return Boolean(node.body || node.accessorBlock || node.memberBlock || Array.isArray(node.statements));
12513
14061
  }
12514
14062
 
12515
- function csharpRoslynOperatorName(node, kind) {
12516
- if (kind === 'ConstructorDeclaration') return csharpRoslynDeclarationName(node);
12517
- if (kind === 'DestructorDeclaration') return `~${csharpRoslynDeclarationName(node) ?? 'destructor'}`;
12518
- if (kind === 'OperatorDeclaration') return `operator ${csharpRoslynName(node.operatorToken) ?? csharpRoslynName(node.operatorKeyword) ?? 'operator'}`;
12519
- if (kind === 'ConversionOperatorDeclaration') return `operator ${csharpRoslynTypeName(node.type) ?? 'conversion'}`;
12520
- return undefined;
14063
+ function swiftSyntaxOperatorName(node, kind) {
14064
+ if (kind === 'PrecedenceGroupDecl') return swiftSyntaxDeclarationName(node) ?? 'precedencegroup';
14065
+ const operatorToken = swiftSyntaxName(node.operatorIdentifier ?? node.operatorToken ?? node.name);
14066
+ return operatorToken ? `operator ${operatorToken}` : undefined;
12521
14067
  }
12522
14068
 
12523
- function csharpRoslynLiteralValue(node) {
14069
+ function swiftSyntaxLiteralValue(node) {
12524
14070
  const value = node.value ?? node.literal;
12525
14071
  if (value === null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return value;
12526
14072
  return undefined;
12527
14073
  }
12528
14074
 
12529
- function csharpRoslynRecoveredKind(kind) {
12530
- return kind === 'IncompleteMember'
12531
- || kind === 'SkippedTokensTrivia'
12532
- || /Skipped|Missing|Bad|Incomplete/.test(String(kind));
14075
+ function swiftSyntaxRecoveredKind(kind) {
14076
+ return kind === 'UnexpectedNodes'
14077
+ || kind === 'MissingToken'
14078
+ || kind === 'SkippedToken'
14079
+ || kind === 'Error'
14080
+ || /Unexpected|Missing|Skipped|Error/.test(String(kind));
12533
14081
  }
12534
14082
 
12535
- function csharpRoslynProblemNode(node, kind) {
14083
+ function swiftSyntaxProblemNode(node, kind) {
12536
14084
  return Boolean(
12537
- node.containsDiagnostics
12538
- || node.ContainsDiagnostics
14085
+ node.isMissing
14086
+ || node.hasError
14087
+ || node.containsDiagnostics
12539
14088
  || node.containsSkippedText
12540
- || node.ContainsSkippedText
12541
- || node.isMissing
12542
- || node.IsMissing
12543
- || node.hasDiagnostics
12544
- || node.HasDiagnostics
12545
- || kind === 'IncompleteMember'
12546
- || kind === 'SkippedTokensTrivia'
14089
+ || node.presence === 'missing'
14090
+ || kind === 'UnexpectedNodes'
14091
+ || kind === 'MissingToken'
14092
+ || kind === 'SkippedToken'
14093
+ || kind === 'Error'
12547
14094
  );
12548
14095
  }
12549
14096
 
12550
- function csharpRoslynDirectiveKind(kind) {
12551
- return /DirectiveTrivia$/.test(String(kind)) || /^(IfDirective|ElifDirective|ElseDirective|EndIfDirective|DefineDirective|UndefDirective|NullableDirective|RegionDirective|EndRegionDirective|PragmaWarningDirective|LineDirective|ErrorDirective|WarningDirective|LoadDirective|ReferenceDirective)/.test(String(kind));
14097
+ function swiftSyntaxConditionalCompilationKind(kind) {
14098
+ return /IfConfig|ConditionalCompilation|PoundIf|PoundElse|PoundElseif|PoundEndif/i.test(String(kind));
12552
14099
  }
12553
14100
 
12554
- function csharpGeneratedCodeMarker(node, kind) {
12555
- if (node.generated || node.Generated || node.isGenerated) return true;
14101
+ function swiftSyntaxMacroKind(kind) {
14102
+ return /Macro/i.test(String(kind));
14103
+ }
14104
+
14105
+ function swiftGeneratedCodeMarker(node, kind) {
14106
+ if (node.generated || node.isGenerated) return true;
12556
14107
  const path = String(node.filePath ?? node.path ?? node.sourcePath ?? '');
12557
- if (csharpGeneratedSourcePath(path)) return true;
14108
+ if (swiftGeneratedSourcePath(path)) return true;
12558
14109
  if (kind === 'Attribute') {
12559
- const name = csharpRoslynDeclarationName(node);
12560
- if (name && /(^|\.)(GeneratedCode|CompilerGenerated|DebuggerNonUserCode)Attribute?$/.test(name)) return true;
12561
- }
12562
- const attributes = node.attributeLists ?? node.attributes;
12563
- if (Array.isArray(attributes)) {
12564
- return JSON.stringify(attributes).includes('GeneratedCode')
12565
- || JSON.stringify(attributes).includes('CompilerGenerated');
14110
+ const name = swiftSyntaxDeclarationName(node);
14111
+ if (name && /(^|\.)(Generated|CompilerGenerated|_spi)Attribute?$/.test(name)) return true;
12566
14112
  }
12567
14113
  return false;
12568
14114
  }
12569
14115
 
12570
- function csharpGeneratedSourcePath(path) {
12571
- return typeof path === 'string' && /\.(g|generated|designer)\.cs$/i.test(path);
14116
+ function swiftGeneratedSourcePath(path) {
14117
+ return typeof path === 'string' && /\.(g|generated)\.swift$/i.test(path);
12572
14118
  }
12573
14119
 
12574
- function csharpGeneratedCodeLoss(input, nodeId, span, options = {}, metadata = {}) {
14120
+ function swiftGeneratedCodeLoss(input, nodeId, span, options = {}, metadata = {}) {
12575
14121
  return {
12576
- id: `loss_${idFragment(nodeId ?? input.sourcePath ?? 'csharp')}_csharp_generated_code`,
14122
+ id: `loss_${idFragment(nodeId ?? input.sourcePath ?? 'swift')}_swift_generated_code`,
12577
14123
  severity: 'warning',
12578
14124
  phase: 'parse',
12579
14125
  sourceFormat: input.language,
12580
14126
  kind: 'generatedCode',
12581
- message: 'C# generated-source or source-generator marker was imported; generated member provenance and source ownership require host evidence.',
14127
+ message: 'Swift generated-source marker was imported; generated member provenance and source ownership require host evidence.',
12582
14128
  span,
12583
14129
  nodeId,
12584
14130
  metadata: {
12585
14131
  parser: options.parser,
12586
14132
  astFormat: options.astFormat,
12587
- sourceGeneratorEvidence: csharpEvidenceSummary(options.sourceGeneratorEvidence),
14133
+ macroExpansionEvidence: swiftEvidenceSummary(options.macroExpansionEvidence),
12588
14134
  ...metadata
12589
14135
  }
12590
14136
  };
12591
14137
  }
12592
14138
 
12593
- function csharpEvidenceSummary(value) {
14139
+ function swiftEvidenceSummary(value) {
12594
14140
  if (!value) return undefined;
12595
14141
  if (Array.isArray(value)) return { entryCount: value.length };
12596
14142
  if (typeof value === 'string') return { value };
@@ -12599,11 +14145,12 @@ function csharpEvidenceSummary(value) {
12599
14145
  if (typeof value.hash === 'string') summary.hash = value.hash;
12600
14146
  if (typeof value.solver === 'string') summary.solver = value.solver;
12601
14147
  if (Array.isArray(value.entries)) summary.entryCount = value.entries.length;
12602
- if (Array.isArray(value.references)) summary.referenceCount = value.references.length;
12603
14148
  if (Array.isArray(value.symbols)) summary.symbolCount = value.symbols.length;
14149
+ if (Array.isArray(value.references)) summary.referenceCount = value.references.length;
14150
+ if (Array.isArray(value.types)) summary.typeCount = value.types.length;
12604
14151
  if (Array.isArray(value.diagnostics)) summary.diagnosticCount = value.diagnostics.length;
12605
- if (Array.isArray(value.generators)) summary.generatorCount = value.generators.length;
12606
- if (Array.isArray(value.projects)) summary.projectCount = value.projects.length;
14152
+ if (Array.isArray(value.macros)) summary.macroCount = value.macros.length;
14153
+ if (Array.isArray(value.packages)) summary.packageCount = value.packages.length;
12607
14154
  return Object.keys(summary).length ? summary : { present: true };
12608
14155
  }
12609
14156
  return { present: true };