@shapeshift-labs/frontier-lang-compiler 0.2.6 → 0.2.8
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 +50 -0
- package/bench/smoke.mjs +45 -2
- package/dist/index.d.ts +178 -1
- package/dist/index.js +2266 -121
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -38,6 +38,56 @@ console.log(imported.nativeSource.ast.rootId);
|
|
|
38
38
|
console.log(imported.patch.operations.length);
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
Native imports include source maps, semantic merge candidates, and a loss summary for admission queues and dashboards. Informational losses produce `ready-with-losses`, warning losses produce `needs-review`, and error losses or failed import evidence produce `blocked`:
|
|
42
|
+
|
|
43
|
+
```js
|
|
44
|
+
import { classifyNativeImportReadiness, summarizeNativeImportLosses } from '@shapeshift-labs/frontier-lang-compiler';
|
|
45
|
+
|
|
46
|
+
const summary = summarizeNativeImportLosses(imported.losses, { evidence: imported.evidence });
|
|
47
|
+
const readiness = classifyNativeImportReadiness(imported.losses, { evidence: imported.evidence });
|
|
48
|
+
|
|
49
|
+
console.log(summary.categories);
|
|
50
|
+
console.log(readiness.readiness);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Use injected parser adapters when a real language parser is available but should not become a compiler runtime dependency:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import {
|
|
57
|
+
createBabelNativeImporterAdapter,
|
|
58
|
+
importNativeProject,
|
|
59
|
+
runNativeImporterAdapter
|
|
60
|
+
} from '@shapeshift-labs/frontier-lang-compiler';
|
|
61
|
+
|
|
62
|
+
const babelAdapter = createBabelNativeImporterAdapter({
|
|
63
|
+
parserModule: await import('@babel/parser')
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const imported = await runNativeImporterAdapter(babelAdapter, {
|
|
67
|
+
sourcePath: 'src/todo.ts',
|
|
68
|
+
sourceText
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const project = await importNativeProject({
|
|
72
|
+
projectRoot: 'src',
|
|
73
|
+
adapters: [babelAdapter],
|
|
74
|
+
sources: [
|
|
75
|
+
{ language: 'typescript', adapter: babelAdapter.id, sourcePath: 'src/todo.ts', sourceText },
|
|
76
|
+
{ language: 'python', sourcePath: 'tools/todo.py', sourceText: pythonSource }
|
|
77
|
+
]
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
console.log(imported.universalAst.sourceMaps.length);
|
|
81
|
+
console.log(project.semanticIndex.symbols.length);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The built-in adapter factories are dependency-light wrappers for caller-owned parsers or ASTs:
|
|
85
|
+
|
|
86
|
+
- `createEstreeNativeImporterAdapter`
|
|
87
|
+
- `createBabelNativeImporterAdapter`
|
|
88
|
+
- `createTypeScriptCompilerNativeImporterAdapter`
|
|
89
|
+
- `createTreeSitterNativeImporterAdapter`
|
|
90
|
+
|
|
41
91
|
## Related Packages
|
|
42
92
|
|
|
43
93
|
The published Frontier package family is generated from one shared package catalog so READMEs stay in sync across packages:
|
package/bench/smoke.mjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { performance } from 'node:perf_hooks';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
compileFrontierSource,
|
|
4
|
+
createEstreeNativeImporterAdapter,
|
|
5
|
+
importNativeSource,
|
|
6
|
+
runNativeImporterAdapter
|
|
7
|
+
} from '../dist/index.js';
|
|
3
8
|
|
|
4
9
|
const source = `
|
|
5
10
|
module Bench @id("mod_bench")
|
|
@@ -22,4 +27,42 @@ let bytes = 0;
|
|
|
22
27
|
for (let index = 0; index < 250; index += 1) {
|
|
23
28
|
bytes += compileFrontierSource(source, { target: targets[index % targets.length] }).output.length;
|
|
24
29
|
}
|
|
25
|
-
|
|
30
|
+
const compileDurationMs = performance.now() - start;
|
|
31
|
+
|
|
32
|
+
const importStart = performance.now();
|
|
33
|
+
const estreeAdapter = createEstreeNativeImporterAdapter();
|
|
34
|
+
let nativeSymbols = 0;
|
|
35
|
+
for (let index = 0; index < 150; index += 1) {
|
|
36
|
+
const imported = index % 2 === 0
|
|
37
|
+
? importNativeSource({
|
|
38
|
+
language: 'javascript',
|
|
39
|
+
sourcePath: `src/bench-${index}.js`,
|
|
40
|
+
sourceText: `export function bench${index}() { return ${index}; }\n`
|
|
41
|
+
})
|
|
42
|
+
: await runNativeImporterAdapter(estreeAdapter, {
|
|
43
|
+
sourcePath: `src/bench-${index}.js`,
|
|
44
|
+
sourceText: `export function bench${index}() { return ${index}; }\n`,
|
|
45
|
+
adapterOptions: {
|
|
46
|
+
ast: {
|
|
47
|
+
type: 'Program',
|
|
48
|
+
loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 42 } },
|
|
49
|
+
body: [{
|
|
50
|
+
type: 'FunctionDeclaration',
|
|
51
|
+
id: { type: 'Identifier', name: `bench${index}` },
|
|
52
|
+
loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 42 } }
|
|
53
|
+
}]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
nativeSymbols += imported.semanticIndex?.symbols?.length ?? 0;
|
|
58
|
+
}
|
|
59
|
+
const importDurationMs = performance.now() - importStart;
|
|
60
|
+
|
|
61
|
+
console.log(JSON.stringify({
|
|
62
|
+
compiles: 250,
|
|
63
|
+
bytes,
|
|
64
|
+
compileDurationMs: Number(compileDurationMs.toFixed(2)),
|
|
65
|
+
nativeImports: 150,
|
|
66
|
+
nativeSymbols,
|
|
67
|
+
nativeImportDurationMs: Number(importDurationMs.toFixed(2))
|
|
68
|
+
}));
|
package/dist/index.d.ts
CHANGED
|
@@ -11,9 +11,13 @@ import type {
|
|
|
11
11
|
NativeAstNode,
|
|
12
12
|
NativeAstRecord,
|
|
13
13
|
NativeSourceNode,
|
|
14
|
+
SemanticMergeCandidateRecord,
|
|
15
|
+
SemanticMergeReadiness,
|
|
14
16
|
SemanticIndexRecord,
|
|
15
17
|
SemanticNode,
|
|
16
18
|
SemanticPatchBundle,
|
|
19
|
+
SourceMapMappingRecord,
|
|
20
|
+
SourceMapRecord,
|
|
17
21
|
SourceSpan
|
|
18
22
|
} from '@shapeshift-labs/frontier-lang-kernel';
|
|
19
23
|
import type { Diagnostic } from '@shapeshift-labs/frontier-lang-checker';
|
|
@@ -69,6 +73,68 @@ export interface CapabilityResolution {
|
|
|
69
73
|
readonly reason?: string;
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
export type NativeImportTaxonomyKind =
|
|
77
|
+
| 'exactAstImport'
|
|
78
|
+
| 'declarationsOnly'
|
|
79
|
+
| 'opaqueBodies'
|
|
80
|
+
| 'macroExpansion'
|
|
81
|
+
| 'preprocessor'
|
|
82
|
+
| 'metaprogramming'
|
|
83
|
+
| 'generatedCode'
|
|
84
|
+
| 'sourcePreservation'
|
|
85
|
+
| 'parserDiagnostics'
|
|
86
|
+
| 'unsupportedSyntax'
|
|
87
|
+
| 'partialSemanticIndex'
|
|
88
|
+
| 'sourceMapApproximation'
|
|
89
|
+
| string;
|
|
90
|
+
|
|
91
|
+
export type NativeImportKnownLossKind =
|
|
92
|
+
| 'declarationOnlyCoverage'
|
|
93
|
+
| 'opaqueNative'
|
|
94
|
+
| 'macroExpansion'
|
|
95
|
+
| 'preprocessor'
|
|
96
|
+
| 'metaprogramming'
|
|
97
|
+
| 'generatedCode'
|
|
98
|
+
| 'sourcePreservation'
|
|
99
|
+
| 'parserDiagnostic'
|
|
100
|
+
| 'unsupportedSyntax'
|
|
101
|
+
| 'partialSemanticIndex'
|
|
102
|
+
| 'sourceMapApproximation'
|
|
103
|
+
| string;
|
|
104
|
+
|
|
105
|
+
export interface NativeImportLossSummaryOptions {
|
|
106
|
+
readonly exactAst?: boolean;
|
|
107
|
+
readonly evidence?: readonly EvidenceRecord[];
|
|
108
|
+
readonly parser?: string;
|
|
109
|
+
readonly scanKind?: string;
|
|
110
|
+
readonly semanticStatus?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface NativeImportLossSummary {
|
|
114
|
+
readonly total: number;
|
|
115
|
+
readonly hasLosses: boolean;
|
|
116
|
+
readonly exactAst: boolean;
|
|
117
|
+
readonly highestSeverity: 'none' | NativeAstLossRecord['severity'];
|
|
118
|
+
readonly semanticMergeReadiness: SemanticMergeReadiness;
|
|
119
|
+
readonly readinessReasons: readonly string[];
|
|
120
|
+
readonly categories: readonly NativeImportTaxonomyKind[];
|
|
121
|
+
readonly bySeverity: Readonly<Record<NativeAstLossRecord['severity'], number>>;
|
|
122
|
+
readonly byKind: Readonly<Record<string, number>>;
|
|
123
|
+
readonly blockingLossIds: readonly string[];
|
|
124
|
+
readonly reviewLossIds: readonly string[];
|
|
125
|
+
readonly informationalLossIds: readonly string[];
|
|
126
|
+
readonly failedEvidenceIds: readonly string[];
|
|
127
|
+
readonly parser?: string;
|
|
128
|
+
readonly scanKind?: string;
|
|
129
|
+
readonly semanticStatus?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface NativeImportReadinessClassification {
|
|
133
|
+
readonly readiness: SemanticMergeReadiness;
|
|
134
|
+
readonly reasons: readonly string[];
|
|
135
|
+
readonly summary: NativeImportLossSummary;
|
|
136
|
+
}
|
|
137
|
+
|
|
72
138
|
export interface NativeImporterAdapterDiagnostic {
|
|
73
139
|
readonly id?: string;
|
|
74
140
|
readonly severity?: 'info' | 'warning' | 'error';
|
|
@@ -104,7 +170,7 @@ export interface ImportNativeSourceOptions {
|
|
|
104
170
|
readonly nodes?: Readonly<Record<string, NativeAstNode>>;
|
|
105
171
|
readonly semanticNodes?: readonly SemanticNode[];
|
|
106
172
|
readonly frontierNodeIds?: readonly string[];
|
|
107
|
-
readonly mappings?: readonly
|
|
173
|
+
readonly mappings?: readonly SourceMapMappingRecord[];
|
|
108
174
|
readonly semanticStatus?: 'native-only' | 'mapped' | 'partial' | string;
|
|
109
175
|
readonly losses?: readonly NativeAstLossRecord[];
|
|
110
176
|
readonly evidence?: readonly EvidenceRecord[];
|
|
@@ -113,7 +179,11 @@ export interface ImportNativeSourceOptions {
|
|
|
113
179
|
readonly patchId?: string;
|
|
114
180
|
readonly author?: string;
|
|
115
181
|
readonly target?: CompileTarget;
|
|
182
|
+
readonly targetPath?: string;
|
|
183
|
+
readonly targetHash?: string;
|
|
116
184
|
readonly semanticIndex?: SemanticIndexRecord;
|
|
185
|
+
readonly sourceMapId?: string;
|
|
186
|
+
readonly sourceMaps?: readonly SourceMapRecord[];
|
|
117
187
|
readonly universalAstId?: string;
|
|
118
188
|
readonly universalAstMetadata?: Record<string, unknown>;
|
|
119
189
|
readonly metadata?: Record<string, unknown>;
|
|
@@ -153,6 +223,56 @@ export interface NativeImporterAdapter {
|
|
|
153
223
|
readonly parse: (input: NativeImporterAdapterParseInput) => NativeImporterAdapterParseResult | Promise<NativeImporterAdapterParseResult>;
|
|
154
224
|
}
|
|
155
225
|
|
|
226
|
+
export interface JavaScriptNativeImporterAdapterOptions {
|
|
227
|
+
readonly id?: string;
|
|
228
|
+
readonly language?: FrontierSourceLanguage;
|
|
229
|
+
readonly parser?: string;
|
|
230
|
+
readonly version?: string;
|
|
231
|
+
readonly capabilities?: readonly string[];
|
|
232
|
+
readonly supportedExtensions?: readonly string[];
|
|
233
|
+
readonly diagnostics?: readonly NativeImporterAdapterDiagnostic[];
|
|
234
|
+
readonly ast?: unknown;
|
|
235
|
+
readonly parse?: (sourceText: string, options: Record<string, unknown>) => unknown;
|
|
236
|
+
readonly parserModule?: { readonly parse: (sourceText: string, options: Record<string, unknown>) => unknown };
|
|
237
|
+
readonly babelParser?: { readonly parse: (sourceText: string, options: Record<string, unknown>) => unknown };
|
|
238
|
+
readonly parserOptions?: Record<string, unknown> | ((input: NativeImporterAdapterParseInput) => Record<string, unknown>);
|
|
239
|
+
readonly maxNodes?: number;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface TypeScriptCompilerNativeImporterAdapterOptions {
|
|
243
|
+
readonly id?: string;
|
|
244
|
+
readonly language?: FrontierSourceLanguage;
|
|
245
|
+
readonly parser?: string;
|
|
246
|
+
readonly version?: string;
|
|
247
|
+
readonly capabilities?: readonly string[];
|
|
248
|
+
readonly supportedExtensions?: readonly string[];
|
|
249
|
+
readonly diagnostics?: readonly NativeImporterAdapterDiagnostic[];
|
|
250
|
+
readonly typescript?: unknown;
|
|
251
|
+
readonly ts?: unknown;
|
|
252
|
+
readonly sourceFile?: unknown;
|
|
253
|
+
readonly createSourceFile?: (input: NativeImporterAdapterParseInput, typescript?: unknown) => unknown;
|
|
254
|
+
readonly scriptTarget?: unknown;
|
|
255
|
+
readonly scriptKind?: unknown;
|
|
256
|
+
readonly maxNodes?: number;
|
|
257
|
+
readonly includeTokens?: boolean;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export interface TreeSitterNativeImporterAdapterOptions {
|
|
261
|
+
readonly id?: string;
|
|
262
|
+
readonly language?: FrontierSourceLanguage;
|
|
263
|
+
readonly parser?: string | { readonly parse?: (sourceText: string) => unknown };
|
|
264
|
+
readonly parserName?: string;
|
|
265
|
+
readonly version?: string;
|
|
266
|
+
readonly capabilities?: readonly string[];
|
|
267
|
+
readonly supportedExtensions?: readonly string[];
|
|
268
|
+
readonly diagnostics?: readonly NativeImporterAdapterDiagnostic[];
|
|
269
|
+
readonly parserInstance?: { readonly parse: (sourceText: string) => unknown };
|
|
270
|
+
readonly treeSitterParser?: { readonly parse: (sourceText: string) => unknown };
|
|
271
|
+
readonly parse?: (input: NativeImporterAdapterParseInput) => unknown;
|
|
272
|
+
readonly tree?: unknown;
|
|
273
|
+
readonly maxNodes?: number;
|
|
274
|
+
}
|
|
275
|
+
|
|
156
276
|
export interface NativeImporterAdapterSummary {
|
|
157
277
|
readonly id: string;
|
|
158
278
|
readonly language: FrontierSourceLanguage;
|
|
@@ -177,18 +297,75 @@ export type NativeImporterAdapterImportResult = NativeSourceImportResult & {
|
|
|
177
297
|
readonly diagnostics: readonly NativeImporterAdapterDiagnostic[];
|
|
178
298
|
};
|
|
179
299
|
|
|
300
|
+
export interface NativeProjectSourceInput extends ImportNativeSourceOptions {
|
|
301
|
+
readonly adapter?: NativeImporterAdapter | string;
|
|
302
|
+
readonly adapterOptions?: Record<string, unknown>;
|
|
303
|
+
readonly adapterMetadata?: Record<string, unknown>;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export interface ImportNativeProjectOptions {
|
|
307
|
+
readonly id?: string;
|
|
308
|
+
readonly name?: string;
|
|
309
|
+
readonly language?: FrontierSourceLanguage | 'mixed';
|
|
310
|
+
readonly projectRoot?: string;
|
|
311
|
+
readonly documentId?: string;
|
|
312
|
+
readonly documentName?: string;
|
|
313
|
+
readonly documentMetadata?: Record<string, unknown>;
|
|
314
|
+
readonly universalAstId?: string;
|
|
315
|
+
readonly universalAstMetadata?: Record<string, unknown>;
|
|
316
|
+
readonly semanticIndexId?: string;
|
|
317
|
+
readonly patchId?: string;
|
|
318
|
+
readonly author?: string;
|
|
319
|
+
readonly metadata?: Record<string, unknown>;
|
|
320
|
+
readonly adapterOptions?: Record<string, unknown>;
|
|
321
|
+
readonly adapterMetadata?: Record<string, unknown>;
|
|
322
|
+
readonly adapters?: readonly NativeImporterAdapter[];
|
|
323
|
+
readonly adapterResolver?: (source: NativeProjectSourceInput, adapters: readonly NativeImporterAdapter[]) => NativeImporterAdapter | undefined;
|
|
324
|
+
readonly sources: readonly NativeProjectSourceInput[];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export interface NativeProjectImportResult {
|
|
328
|
+
readonly kind: 'frontier.lang.projectImportResult';
|
|
329
|
+
readonly version: 1;
|
|
330
|
+
readonly id: string;
|
|
331
|
+
readonly language: FrontierSourceLanguage | 'mixed';
|
|
332
|
+
readonly projectRoot?: string;
|
|
333
|
+
readonly imports: readonly NativeSourceImportResult[];
|
|
334
|
+
readonly document: FrontierLangDocument;
|
|
335
|
+
readonly patch: SemanticPatchBundle;
|
|
336
|
+
readonly nativeSources: readonly NativeSourceNode[];
|
|
337
|
+
readonly semanticIndex?: SemanticIndexRecord;
|
|
338
|
+
readonly universalAst: FrontierUniversalAstEnvelope;
|
|
339
|
+
readonly sourceMaps: readonly SourceMapRecord[];
|
|
340
|
+
readonly losses: readonly NativeAstLossRecord[];
|
|
341
|
+
readonly evidence: readonly EvidenceRecord[];
|
|
342
|
+
readonly mergeCandidates: readonly SemanticMergeCandidateRecord[];
|
|
343
|
+
readonly metadata?: Record<string, unknown>;
|
|
344
|
+
}
|
|
345
|
+
|
|
180
346
|
export declare const FrontierCompileTargets: readonly FrontierCompileTarget[];
|
|
347
|
+
export declare const NativeImportTaxonomyKinds: readonly NativeImportTaxonomyKind[];
|
|
348
|
+
export declare const NativeImportLossKinds: readonly NativeImportKnownLossKind[];
|
|
349
|
+
export declare const NativeImportReadinessBySeverity: Readonly<Record<NativeImportLossSummary['highestSeverity'], SemanticMergeReadiness>>;
|
|
181
350
|
export declare function normalizeCompileTarget(target?: string): FrontierCompileTarget;
|
|
182
351
|
export declare function compileFrontierSource(source: string, options?: FrontierCompileOptions): FrontierCompileResult;
|
|
183
352
|
export declare function compileFrontierDocument(document: FrontierLangDocument, options?: FrontierCompileOptions): FrontierCompileResult;
|
|
184
353
|
export declare function projectFrontierAst(document: FrontierLangDocument, target?: FrontierCompileOptions['target'], options?: FrontierCompileEmitOptions): FrontierTargetAst;
|
|
185
354
|
export declare function renderTargetAst(ast: FrontierTargetAst, target?: FrontierCompileOptions['target']): string;
|
|
186
355
|
export declare function resolveCapabilityAdapters(document: FrontierLangDocument, target?: FrontierCompileOptions['target'], options?: { readonly platform?: string }): readonly CapabilityResolution[];
|
|
356
|
+
export declare function summarizeNativeImportLosses(losses?: readonly NativeAstLossRecord[], options?: NativeImportLossSummaryOptions): NativeImportLossSummary;
|
|
357
|
+
export declare function classifyNativeImportReadiness(losses?: readonly NativeAstLossRecord[], options?: NativeImportLossSummaryOptions): NativeImportReadinessClassification;
|
|
358
|
+
export declare function createEstreeNativeImporterAdapter(options?: JavaScriptNativeImporterAdapterOptions): NativeImporterAdapter;
|
|
359
|
+
export declare function createBabelNativeImporterAdapter(options?: JavaScriptNativeImporterAdapterOptions): NativeImporterAdapter;
|
|
360
|
+
export declare function createTypeScriptCompilerNativeImporterAdapter(options?: TypeScriptCompilerNativeImporterAdapterOptions): NativeImporterAdapter;
|
|
361
|
+
export declare function createTreeSitterNativeImporterAdapter(options?: TreeSitterNativeImporterAdapterOptions): NativeImporterAdapter;
|
|
187
362
|
export declare function runNativeImporterAdapter(adapter: NativeImporterAdapter, input: RunNativeImporterAdapterOptions): Promise<NativeImporterAdapterImportResult>;
|
|
188
363
|
export declare function importNativeSource(input: ImportNativeSourceOptions): NativeSourceImportResult;
|
|
364
|
+
export declare function importNativeProject(input: ImportNativeProjectOptions): Promise<NativeProjectImportResult>;
|
|
189
365
|
export declare function createUniversalAstFromDocument(document: FrontierLangDocument, input?: {
|
|
190
366
|
readonly id?: string;
|
|
191
367
|
readonly semanticIndex?: SemanticIndexRecord;
|
|
368
|
+
readonly sourceMaps?: readonly SourceMapRecord[];
|
|
192
369
|
readonly evidence?: readonly EvidenceRecord[];
|
|
193
370
|
readonly metadata?: Record<string, unknown>;
|
|
194
371
|
}): FrontierUniversalAstEnvelope;
|