@shapeshift-labs/frontier-lang-compiler 0.2.25 → 0.2.27

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/README.md CHANGED
@@ -116,6 +116,7 @@ Ask the compiler what is actually covered before sending native imports into a m
116
116
  ```js
117
117
  import {
118
118
  createNativeImportCoverageMatrix,
119
+ createNativeParserAstFormatMatrix,
119
120
  createProjectionTargetLossMatrix,
120
121
  importNativeSource
121
122
  } from '@shapeshift-labs/frontier-lang-compiler';
@@ -132,6 +133,9 @@ const python = matrix.languages.find((entry) => entry.language === 'python');
132
133
  console.log(python.imports.readiness); // scanner imports are intentionally review-required
133
134
  console.log(python.parserAdapters); // host-owned exact parsers such as LibCST can be injected
134
135
 
136
+ const parserMatrix = createNativeParserAstFormatMatrix({ imports: [imported] });
137
+ console.log(parserMatrix.formats.find((entry) => entry.id === 'python-ast')?.adapters.total ?? 0);
138
+
135
139
  const projectionMatrix = createProjectionTargetLossMatrix({ imports: [imported] });
136
140
  const pythonProjection = projectionMatrix.languages.find((entry) => entry.language === 'python');
137
141
 
@@ -328,6 +332,8 @@ Use injected parser adapters when a real language parser is available but should
328
332
  ```js
329
333
  import {
330
334
  createBabelNativeImporterAdapter,
335
+ createPythonAstNativeImporterAdapter,
336
+ createRustSynNativeImporterAdapter,
331
337
  importNativeProject,
332
338
  runNativeImporterAdapter
333
339
  } from '@shapeshift-labs/frontier-lang-compiler';
@@ -335,6 +341,13 @@ import {
335
341
  const babelAdapter = createBabelNativeImporterAdapter({
336
342
  parserModule: await import('@babel/parser')
337
343
  });
344
+ const pythonAstAdapter = createPythonAstNativeImporterAdapter({
345
+ parserModule: hostPythonAstParser
346
+ });
347
+ const rustSynAdapter = createRustSynNativeImporterAdapter({
348
+ parserModule: hostRustSynParser,
349
+ rustEdition: '2021'
350
+ });
338
351
 
339
352
  const imported = await runNativeImporterAdapter(babelAdapter, {
340
353
  sourcePath: 'src/todo.ts',
@@ -343,10 +356,11 @@ const imported = await runNativeImporterAdapter(babelAdapter, {
343
356
 
344
357
  const project = await importNativeProject({
345
358
  projectRoot: 'src',
346
- adapters: [babelAdapter],
359
+ adapters: [babelAdapter, pythonAstAdapter, rustSynAdapter],
347
360
  sources: [
348
361
  { language: 'typescript', adapter: babelAdapter.id, sourcePath: 'src/todo.ts', sourceText },
349
- { language: 'python', sourcePath: 'tools/todo.py', sourceText: pythonSource }
362
+ { language: 'python', adapter: pythonAstAdapter.id, sourcePath: 'tools/todo.py', sourceText: pythonSource },
363
+ { language: 'rust', adapter: rustSynAdapter.id, sourcePath: 'src/todo.rs', sourceText: rustSource }
350
364
  ]
351
365
  });
352
366
 
@@ -365,6 +379,8 @@ The built-in adapter factories are dependency-light wrappers for caller-owned pa
365
379
  - `createEstreeNativeImporterAdapter`
366
380
  - `createBabelNativeImporterAdapter`
367
381
  - `createTypeScriptCompilerNativeImporterAdapter`
382
+ - `createPythonAstNativeImporterAdapter`
383
+ - `createRustSynNativeImporterAdapter`
368
384
  - `createTreeSitterNativeImporterAdapter`
369
385
 
370
386
  Adapter summaries include a structured `coverage` record so merge queues can distinguish exact parser AST imports from declaration scans. The record declares exactness, parser token/trivia support, diagnostics support, source-range and generated-range support, and semantic coverage. Built-in wrappers normalize native AST/CST nodes and declaration-level semantic indexes; they do not claim resolved references, types, control flow, generated ranges, or token/trivia fidelity unless the host adapter supplies that evidence.
package/bench/smoke.mjs CHANGED
@@ -4,8 +4,11 @@ import {
4
4
  compileFrontierSource,
5
5
  createEstreeNativeImporterAdapter,
6
6
  createNativeImportCoverageMatrix,
7
+ createNativeParserAstFormatMatrix,
7
8
  createProjectionTargetLossMatrix,
8
9
  createNativeSourcePreservation,
10
+ createPythonAstNativeImporterAdapter,
11
+ createRustSynNativeImporterAdapter,
9
12
  createSemanticImportSidecar,
10
13
  diffNativeSources,
11
14
  importExternalSemanticIndex,
@@ -73,6 +76,13 @@ const matrixStart = performance.now();
73
76
  const coverageMatrix = createNativeImportCoverageMatrix({ imports: nativeImportResults });
74
77
  const matrixDurationMs = performance.now() - matrixStart;
75
78
 
79
+ const parserFormatMatrixStart = performance.now();
80
+ const parserFormatMatrix = createNativeParserAstFormatMatrix({
81
+ imports: nativeImportResults,
82
+ adapters: [estreeAdapter, createPythonAstNativeImporterAdapter(), createRustSynNativeImporterAdapter()]
83
+ });
84
+ const parserFormatMatrixDurationMs = performance.now() - parserFormatMatrixStart;
85
+
76
86
  const projectionMatrixStart = performance.now();
77
87
  const projectionLossMatrix = createProjectionTargetLossMatrix({ imports: nativeImportResults });
78
88
  const projectionMatrixDurationMs = performance.now() - projectionMatrixStart;
@@ -228,6 +238,10 @@ console.log(JSON.stringify({
228
238
  adapterCoverageTokenGaps: coverageMatrix.summary.adapterCoverage.gaps.tokens ?? 0,
229
239
  adapterCoverageReferenceGaps: coverageMatrix.summary.adapterCoverage.gaps.references ?? 0,
230
240
  coverageMatrixDurationMs: Number(matrixDurationMs.toFixed(2)),
241
+ parserFormatMatrixFormats: parserFormatMatrix.summary.formats,
242
+ parserFormatMatrixImports: parserFormatMatrix.summary.imports,
243
+ parserFormatMatrixNativeAstNodes: parserFormatMatrix.summary.nativeAstNodes,
244
+ parserFormatMatrixDurationMs: Number(parserFormatMatrixDurationMs.toFixed(2)),
231
245
  projectionMatrixLanguages: projectionLossMatrix.summary.languages,
232
246
  projectionMatrixMissingAdapters: projectionLossMatrix.summary.missingAdapters,
233
247
  projectionMatrixUnsupportedTargetFeatures: projectionLossMatrix.summary.unsupportedTargetFeatures,
package/dist/index.d.ts CHANGED
@@ -236,6 +236,88 @@ export interface NativeImportLanguageProfile {
236
236
  readonly notes: readonly string[];
237
237
  }
238
238
 
239
+ export type NativeParserAstFormatKind =
240
+ | 'abstract-ast'
241
+ | 'concrete-syntax-tree'
242
+ | 'compiler-ast'
243
+ | 'semantic-index'
244
+ | string;
245
+
246
+ export interface NativeParserAstFormatProfile {
247
+ readonly id: string;
248
+ readonly aliases: readonly string[];
249
+ readonly kind: NativeParserAstFormatKind;
250
+ readonly languages: readonly (FrontierSourceLanguage | 'mixed' | string)[];
251
+ readonly parserAdapters: readonly string[];
252
+ readonly exactness: NativeImporterAdapterExactness;
253
+ readonly sourceRangeModel: string;
254
+ readonly preservesTokens: boolean;
255
+ readonly preservesTrivia: boolean;
256
+ readonly supportsIncremental: boolean;
257
+ readonly supportsErrorRecovery: boolean;
258
+ readonly notes: readonly string[];
259
+ }
260
+
261
+ export interface NativeParserAstFormatCoverage {
262
+ readonly id: string;
263
+ readonly kind: NativeParserAstFormatKind;
264
+ readonly languages: readonly (FrontierSourceLanguage | 'mixed' | string)[];
265
+ readonly parserAdapters: readonly string[];
266
+ readonly exactness: NativeImporterAdapterExactness;
267
+ readonly sourceRangeModel: string;
268
+ readonly preservesTokens: boolean;
269
+ readonly preservesTrivia: boolean;
270
+ readonly supportsIncremental: boolean;
271
+ readonly supportsErrorRecovery: boolean;
272
+ readonly notes: readonly string[];
273
+ readonly adapters: {
274
+ readonly total: number;
275
+ readonly ids: readonly string[];
276
+ readonly parsers: readonly string[];
277
+ readonly effectiveCapabilities: Readonly<Record<string, number>>;
278
+ };
279
+ readonly imports: {
280
+ readonly total: number;
281
+ readonly sourcePaths: readonly string[];
282
+ readonly readiness: SemanticMergeReadiness;
283
+ readonly nativeAstNodes: number;
284
+ readonly symbols: number;
285
+ readonly sourceMapMappings: number;
286
+ readonly losses: number;
287
+ };
288
+ }
289
+
290
+ export interface NativeParserAstFormatMatrix {
291
+ readonly kind: 'frontier.lang.nativeParserAstFormatMatrix';
292
+ readonly version: 1;
293
+ readonly generatedAt: number;
294
+ readonly formats: readonly NativeParserAstFormatCoverage[];
295
+ readonly summary: {
296
+ readonly formats: number;
297
+ readonly adapterSlots: number;
298
+ readonly adapters: number;
299
+ readonly imports: number;
300
+ readonly nativeAstNodes: number;
301
+ readonly symbols: number;
302
+ readonly sourceMapMappings: number;
303
+ readonly losses: number;
304
+ readonly byKind: Readonly<Record<string, number>>;
305
+ readonly byReadiness: Readonly<Record<string, number>>;
306
+ readonly effectiveCapabilities: Readonly<Record<string, number>>;
307
+ };
308
+ readonly metadata: {
309
+ readonly note: string;
310
+ readonly profileIds: readonly string[];
311
+ };
312
+ }
313
+
314
+ export interface NativeParserAstFormatMatrixOptions {
315
+ readonly formats?: readonly NativeParserAstFormatProfile[];
316
+ readonly imports?: readonly NativeSourceImportResult[];
317
+ readonly adapters?: readonly NativeImporterAdapter[];
318
+ readonly generatedAt?: number;
319
+ }
320
+
239
321
  export interface NativeImporterAdapterCoverageAggregate {
240
322
  readonly total: number;
241
323
  readonly declared: Readonly<Record<string, number>>;
@@ -1283,6 +1365,51 @@ export interface TypeScriptCompilerNativeImporterAdapterOptions {
1283
1365
  readonly includeTokens?: boolean;
1284
1366
  }
1285
1367
 
1368
+ export interface PythonAstNativeImporterAdapterOptions {
1369
+ readonly id?: string;
1370
+ readonly language?: FrontierSourceLanguage;
1371
+ readonly parser?: string;
1372
+ readonly version?: string;
1373
+ readonly capabilities?: readonly string[];
1374
+ readonly coverage?: NativeImporterAdapterCoverageInput;
1375
+ readonly supportedExtensions?: readonly string[];
1376
+ readonly diagnostics?: readonly NativeImporterAdapterDiagnostic[];
1377
+ readonly ast?: unknown;
1378
+ readonly parse?: (sourceText: string, options: Record<string, unknown>) => unknown;
1379
+ readonly parserModule?: { readonly parse: (sourceText: string, options: Record<string, unknown>) => unknown };
1380
+ readonly pythonAst?: { readonly parse: (sourceText: string, options: Record<string, unknown>) => unknown };
1381
+ readonly parserOptions?: Record<string, unknown>;
1382
+ readonly mode?: 'exec' | 'eval' | 'single' | 'func_type' | string;
1383
+ readonly pythonVersion?: string;
1384
+ readonly featureVersion?: string | number;
1385
+ readonly typeComments?: boolean;
1386
+ readonly optimize?: number;
1387
+ readonly includeAttributes?: boolean;
1388
+ readonly maxNodes?: number;
1389
+ }
1390
+
1391
+ export interface RustSynNativeImporterAdapterOptions {
1392
+ readonly id?: string;
1393
+ readonly language?: FrontierSourceLanguage;
1394
+ readonly parser?: string;
1395
+ readonly version?: string;
1396
+ readonly capabilities?: readonly string[];
1397
+ readonly coverage?: NativeImporterAdapterCoverageInput;
1398
+ readonly supportedExtensions?: readonly string[];
1399
+ readonly diagnostics?: readonly NativeImporterAdapterDiagnostic[];
1400
+ readonly ast?: unknown;
1401
+ readonly file?: unknown;
1402
+ readonly sourceFile?: unknown;
1403
+ readonly parse?: (sourceText: string, options: Record<string, unknown>) => unknown;
1404
+ readonly parserModule?: { readonly parse: (sourceText: string, options: Record<string, unknown>) => unknown };
1405
+ readonly rustSyn?: { readonly parse: (sourceText: string, options: Record<string, unknown>) => unknown };
1406
+ readonly syn?: { readonly parse: (sourceText: string, options: Record<string, unknown>) => unknown };
1407
+ readonly parserOptions?: Record<string, unknown>;
1408
+ readonly rustEdition?: '2015' | '2018' | '2021' | '2024' | string;
1409
+ readonly includeAttributes?: boolean;
1410
+ readonly maxNodes?: number;
1411
+ }
1412
+
1286
1413
  export interface TreeSitterNativeImporterAdapterOptions {
1287
1414
  readonly id?: string;
1288
1415
  readonly language?: FrontierSourceLanguage;
@@ -1625,6 +1752,8 @@ export declare const ProjectionTargetLossClasses: readonly ProjectionTargetLossC
1625
1752
  export declare const NativeImportReadinessBySeverity: Readonly<Record<NativeImportLossSummary['highestSeverity'], SemanticMergeReadiness>>;
1626
1753
  export declare const NativeImportFeatureEvidencePolicies: Readonly<Record<string, NativeImportFeatureEvidencePolicy>>;
1627
1754
  export declare const NativeImportLanguageProfiles: readonly NativeImportLanguageProfile[];
1755
+ export declare const NativeParserAstFormatProfiles: readonly NativeParserAstFormatProfile[];
1756
+ export declare const NativeParserAstFormats: readonly string[];
1628
1757
  export declare const ExternalSemanticIndexFormats: readonly ExternalSemanticIndexFormat[];
1629
1758
  export declare function normalizeCompileTarget(target?: string): FrontierCompileTarget;
1630
1759
  export declare function compileFrontierSource(source: string, options?: FrontierCompileOptions): FrontierCompileResult;
@@ -1641,6 +1770,8 @@ export declare function summarizeNativeImportLosses(losses?: readonly NativeAstL
1641
1770
  export declare function classifyNativeImportReadiness(losses?: readonly NativeAstLossRecord[], options?: NativeImportLossSummaryOptions): NativeImportReadinessClassification;
1642
1771
  export declare function classifyNativeImportRoundtripReadiness(importResult: NativeSourceImportResult | NativeProjectImportResult, options?: NativeImportRoundtripReadinessOptions): NativeImportRoundtripReadinessClassification;
1643
1772
  export declare function createNativeImportCoverageMatrix(options?: NativeImportCoverageMatrixOptions): NativeImportCoverageMatrix;
1773
+ export declare function getNativeParserAstFormatProfile(format?: string): NativeParserAstFormatProfile | undefined;
1774
+ export declare function createNativeParserAstFormatMatrix(options?: NativeParserAstFormatMatrixOptions): NativeParserAstFormatMatrix;
1644
1775
  export declare function createProjectionTargetLossMatrix(options?: ProjectionTargetLossMatrixOptions): ProjectionTargetLossMatrix;
1645
1776
  export declare function createNativeSourcePreservation(options: CreateNativeSourcePreservationOptions): NativeSourcePreservation;
1646
1777
  export declare function createSemanticImportSidecar(importResult: NativeSourceImportResult | NativeProjectImportResult, options?: SemanticImportSidecarOptions): SemanticImportSidecar;
@@ -1648,6 +1779,8 @@ export declare function createNativeImportResultContract(importResult: NativeSou
1648
1779
  export declare function createEstreeNativeImporterAdapter(options?: JavaScriptNativeImporterAdapterOptions): NativeImporterAdapter;
1649
1780
  export declare function createBabelNativeImporterAdapter(options?: JavaScriptNativeImporterAdapterOptions): NativeImporterAdapter;
1650
1781
  export declare function createTypeScriptCompilerNativeImporterAdapter(options?: TypeScriptCompilerNativeImporterAdapterOptions): NativeImporterAdapter;
1782
+ export declare function createPythonAstNativeImporterAdapter(options?: PythonAstNativeImporterAdapterOptions): NativeImporterAdapter;
1783
+ export declare function createRustSynNativeImporterAdapter(options?: RustSynNativeImporterAdapterOptions): NativeImporterAdapter;
1651
1784
  export declare function createTreeSitterNativeImporterAdapter(options?: TreeSitterNativeImporterAdapterOptions): NativeImporterAdapter;
1652
1785
  export declare function runNativeImporterAdapter(adapter: NativeImporterAdapter, input: RunNativeImporterAdapterOptions): Promise<NativeImporterAdapterImportResult>;
1653
1786
  export declare function runNativeTargetProjectionAdapter(adapter: NativeTargetProjectionAdapter, input: NativeTargetProjectionAdapterInput): NativeTargetProjectionResult;