@shapeshift-labs/frontier-lang-compiler 0.2.22 → 0.2.24
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 +49 -1
- package/bench/smoke.mjs +74 -1
- package/dist/index.d.ts +63 -0
- package/dist/index.js +1467 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,6 +50,34 @@ console.log(imported.nativeSource.ast.rootId);
|
|
|
50
50
|
console.log(imported.patch.operations.length);
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
Import external code-intelligence payloads into Frontier semantic evidence when a project already has language tooling such as SCIP, LSIF, LSP, or SemanticDB:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import { importExternalSemanticIndex } from '@shapeshift-labs/frontier-lang-compiler';
|
|
57
|
+
|
|
58
|
+
const importedIndex = importExternalSemanticIndex({
|
|
59
|
+
format: 'scip',
|
|
60
|
+
language: 'typescript',
|
|
61
|
+
payload: {
|
|
62
|
+
metadata: { project_root: '/repo' },
|
|
63
|
+
documents: [{
|
|
64
|
+
relative_path: 'src/todo.ts',
|
|
65
|
+
occurrences: [{
|
|
66
|
+
symbol: 'scip-typescript npm todo 1.0.0 src/todo.ts/ addTodo().',
|
|
67
|
+
range: [0, 16, 23],
|
|
68
|
+
symbol_roles: 1
|
|
69
|
+
}]
|
|
70
|
+
}]
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
console.log(importedIndex.semanticIndex.symbols.length);
|
|
75
|
+
console.log(importedIndex.summary.sourceMapMappings);
|
|
76
|
+
console.log(importedIndex.readiness.readiness); // "ready-with-losses" or review-required
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
External semantic-index imports create Frontier `SemanticIndexRecord`, `SourceMapRecord`, evidence, losses, ownership facts, and a universal AST envelope. They are a bridge from existing language servers/indexers into semantic merge tooling; they do not claim full parser AST coverage, macro expansion, type checking, comments/trivia preservation, or lossless cross-language code generation by themselves.
|
|
80
|
+
|
|
53
81
|
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`:
|
|
54
82
|
|
|
55
83
|
```js
|
|
@@ -163,10 +191,30 @@ const imported = importNativeSource({
|
|
|
163
191
|
const sidecar = createSemanticImportSidecar(imported);
|
|
164
192
|
|
|
165
193
|
console.log(sidecar.summary.emptySemanticIndex); // false when symbols were found
|
|
166
|
-
console.log(sidecar.ownershipRegions[0].key); // source#src/runtime.ts#
|
|
194
|
+
console.log(sidecar.ownershipRegions[0].key); // source#src/runtime.ts#type#Runtime
|
|
167
195
|
console.log(sidecar.patchHints[0].supportedOperations); // source-region patch operations
|
|
168
196
|
```
|
|
169
197
|
|
|
198
|
+
The built-in JavaScript/TypeScript lightweight scanner also emits review-required ownership regions for clear route/config/content/property shapes in exported objects and arrays:
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
const importedConfig = importNativeSource({
|
|
202
|
+
language: 'typescript',
|
|
203
|
+
sourcePath: 'src/routes.ts',
|
|
204
|
+
sourceText: `
|
|
205
|
+
export const appRoutes = [
|
|
206
|
+
{ path: "/home", component: Home }
|
|
207
|
+
];
|
|
208
|
+
export const siteContent = {
|
|
209
|
+
docs: { title: "Docs" }
|
|
210
|
+
};
|
|
211
|
+
`
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const configSidecar = createSemanticImportSidecar(importedConfig);
|
|
215
|
+
console.log(configSidecar.regionTaxonomy.presentKinds); // includes "route" and "content"
|
|
216
|
+
```
|
|
217
|
+
|
|
170
218
|
Compare before/after native source imports from a worker patch and emit a semantic change set for admission scoring:
|
|
171
219
|
|
|
172
220
|
```js
|
package/bench/smoke.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
createProjectionTargetLossMatrix,
|
|
8
8
|
createNativeSourcePreservation,
|
|
9
9
|
createSemanticImportSidecar,
|
|
10
|
+
importExternalSemanticIndex,
|
|
10
11
|
importNativeSource,
|
|
11
12
|
projectNativeImportToSource,
|
|
12
13
|
runNativeImporterAdapter,
|
|
@@ -134,6 +135,70 @@ const nativeTargetAdapterDurationMs = performance.now() - nativeTargetAdapterSta
|
|
|
134
135
|
const nativeTargetAdapterBytes = nativeTargetAdapterCompiles.reduce((sum, result) => sum + result.output.length, 0);
|
|
135
136
|
const nativeTargetAdapterSourceMaps = nativeTargetAdapterCompiles.reduce((sum, result) => sum + result.sourceMaps.length, 0);
|
|
136
137
|
|
|
138
|
+
const regionScanStart = performance.now();
|
|
139
|
+
const regionScanImports = [];
|
|
140
|
+
for (let index = 0; index < 100; index += 1) {
|
|
141
|
+
const imported = importNativeSource({
|
|
142
|
+
language: 'typescript',
|
|
143
|
+
sourcePath: `src/regions-${index}.ts`,
|
|
144
|
+
sourceText: `
|
|
145
|
+
export const appRoutes${index} = [
|
|
146
|
+
{ path: "/${index}", component: Screen${index} },
|
|
147
|
+
{ path: "/${index}/settings", component: Settings${index} }
|
|
148
|
+
];
|
|
149
|
+
export const contentBlocks${index} = {
|
|
150
|
+
docs: { title: "Docs ${index}" },
|
|
151
|
+
legal: { title: "Legal ${index}" }
|
|
152
|
+
};
|
|
153
|
+
export const runtimeConfig${index} = {
|
|
154
|
+
limits: { count: ${index} },
|
|
155
|
+
resolve(id) { return id; }
|
|
156
|
+
};
|
|
157
|
+
export const helpers${index} = {
|
|
158
|
+
plain: ${index}
|
|
159
|
+
};
|
|
160
|
+
`
|
|
161
|
+
});
|
|
162
|
+
regionScanImports.push({ imported, sidecar: createSemanticImportSidecar(imported) });
|
|
163
|
+
}
|
|
164
|
+
const regionScanDurationMs = performance.now() - regionScanStart;
|
|
165
|
+
const regionScanSymbols = regionScanImports.reduce((sum, entry) => sum + entry.imported.semanticIndex.symbols.length, 0);
|
|
166
|
+
const regionScanOwnershipRegions = regionScanImports.reduce((sum, entry) => sum + entry.sidecar.ownershipRegions.length, 0);
|
|
167
|
+
|
|
168
|
+
const externalSemanticStart = performance.now();
|
|
169
|
+
const externalSemanticImports = [];
|
|
170
|
+
for (let index = 0; index < 100; index += 1) {
|
|
171
|
+
externalSemanticImports.push(importExternalSemanticIndex({
|
|
172
|
+
format: index % 2 === 0 ? 'scip' : 'lsp',
|
|
173
|
+
language: index % 2 === 0 ? 'typescript' : 'python',
|
|
174
|
+
payload: index % 2 === 0
|
|
175
|
+
? {
|
|
176
|
+
metadata: { project_root: '/bench' },
|
|
177
|
+
documents: [{
|
|
178
|
+
relative_path: `src/external-${index}.ts`,
|
|
179
|
+
language: 'typescript',
|
|
180
|
+
occurrences: [{
|
|
181
|
+
symbol: `scip-typescript npm bench 1.0.0 src/external-${index}.ts/ external${index}().`,
|
|
182
|
+
range: [0, 16, 24],
|
|
183
|
+
symbol_roles: 1
|
|
184
|
+
}]
|
|
185
|
+
}]
|
|
186
|
+
}
|
|
187
|
+
: {
|
|
188
|
+
uri: `file:///bench/src/external-${index}.py`,
|
|
189
|
+
languageId: 'python',
|
|
190
|
+
documentSymbols: [{
|
|
191
|
+
name: `external_${index}`,
|
|
192
|
+
kind: 12,
|
|
193
|
+
range: { start: { line: 0, character: 0 }, end: { line: 1, character: 0 } }
|
|
194
|
+
}]
|
|
195
|
+
}
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
const externalSemanticDurationMs = performance.now() - externalSemanticStart;
|
|
199
|
+
const externalSemanticSymbols = externalSemanticImports.reduce((sum, imported) => sum + imported.semanticIndex.symbols.length, 0);
|
|
200
|
+
const externalSemanticMappings = externalSemanticImports.reduce((sum, imported) => sum + imported.summary.sourceMapMappings, 0);
|
|
201
|
+
|
|
137
202
|
console.log(JSON.stringify({
|
|
138
203
|
compiles: 250,
|
|
139
204
|
bytes,
|
|
@@ -172,5 +237,13 @@ console.log(JSON.stringify({
|
|
|
172
237
|
nativeTargetAdapterCompiles: nativeTargetAdapterCompiles.length,
|
|
173
238
|
nativeTargetAdapterBytes,
|
|
174
239
|
nativeTargetAdapterSourceMaps,
|
|
175
|
-
nativeTargetAdapterDurationMs: Number(nativeTargetAdapterDurationMs.toFixed(2))
|
|
240
|
+
nativeTargetAdapterDurationMs: Number(nativeTargetAdapterDurationMs.toFixed(2)),
|
|
241
|
+
regionScanImports: regionScanImports.length,
|
|
242
|
+
regionScanSymbols,
|
|
243
|
+
regionScanOwnershipRegions,
|
|
244
|
+
regionScanDurationMs: Number(regionScanDurationMs.toFixed(2)),
|
|
245
|
+
externalSemanticImports: externalSemanticImports.length,
|
|
246
|
+
externalSemanticSymbols,
|
|
247
|
+
externalSemanticMappings,
|
|
248
|
+
externalSemanticDurationMs: Number(externalSemanticDurationMs.toFixed(2))
|
|
176
249
|
}));
|
package/dist/index.d.ts
CHANGED
|
@@ -140,6 +140,10 @@ export type NativeImportRegionTaxonomyKind =
|
|
|
140
140
|
| 'call'
|
|
141
141
|
| 'type'
|
|
142
142
|
| 'effect'
|
|
143
|
+
| 'property'
|
|
144
|
+
| 'config'
|
|
145
|
+
| 'content'
|
|
146
|
+
| 'route'
|
|
143
147
|
| 'generatedOutput'
|
|
144
148
|
| string;
|
|
145
149
|
|
|
@@ -1067,6 +1071,63 @@ export type NativeSourceImportResult = LanguageImportResult & {
|
|
|
1067
1071
|
readonly universalAst: FrontierUniversalAstEnvelope;
|
|
1068
1072
|
};
|
|
1069
1073
|
|
|
1074
|
+
export type ExternalSemanticIndexFormat =
|
|
1075
|
+
| 'frontier-semantic-index'
|
|
1076
|
+
| 'scip'
|
|
1077
|
+
| 'lsif'
|
|
1078
|
+
| 'lsp'
|
|
1079
|
+
| 'semanticdb'
|
|
1080
|
+
| string;
|
|
1081
|
+
|
|
1082
|
+
export interface ImportExternalSemanticIndexOptions {
|
|
1083
|
+
readonly format?: ExternalSemanticIndexFormat;
|
|
1084
|
+
readonly payload?: unknown;
|
|
1085
|
+
readonly semanticIndex?: SemanticIndexRecord;
|
|
1086
|
+
readonly id?: string;
|
|
1087
|
+
readonly semanticIndexId?: string;
|
|
1088
|
+
readonly universalAstId?: string;
|
|
1089
|
+
readonly documentId?: string;
|
|
1090
|
+
readonly documentName?: string;
|
|
1091
|
+
readonly sourceMapId?: string;
|
|
1092
|
+
readonly language?: FrontierSourceLanguage | string;
|
|
1093
|
+
readonly sourcePath?: string;
|
|
1094
|
+
readonly sourceHash?: string;
|
|
1095
|
+
readonly projectRoot?: string;
|
|
1096
|
+
readonly parser?: string;
|
|
1097
|
+
readonly evidence?: readonly EvidenceRecord[];
|
|
1098
|
+
readonly metadata?: Record<string, unknown>;
|
|
1099
|
+
readonly universalAstMetadata?: Record<string, unknown>;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
export interface ExternalSemanticIndexImportSummary {
|
|
1103
|
+
readonly documents: number;
|
|
1104
|
+
readonly symbols: number;
|
|
1105
|
+
readonly occurrences: number;
|
|
1106
|
+
readonly relations: number;
|
|
1107
|
+
readonly facts: number;
|
|
1108
|
+
readonly sourceMapMappings: number;
|
|
1109
|
+
readonly losses: number;
|
|
1110
|
+
readonly readiness: SemanticMergeReadiness;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
export interface ExternalSemanticIndexImportResult {
|
|
1114
|
+
readonly kind: 'frontier.lang.externalSemanticIndexImport';
|
|
1115
|
+
readonly version: 1;
|
|
1116
|
+
readonly id: string;
|
|
1117
|
+
readonly format: ExternalSemanticIndexFormat;
|
|
1118
|
+
readonly language?: FrontierSourceLanguage | string;
|
|
1119
|
+
readonly sourcePath?: string;
|
|
1120
|
+
readonly projectRoot?: string;
|
|
1121
|
+
readonly semanticIndex: SemanticIndexRecord;
|
|
1122
|
+
readonly universalAst: FrontierUniversalAstEnvelope;
|
|
1123
|
+
readonly sourceMaps: readonly SourceMapRecord[];
|
|
1124
|
+
readonly losses: readonly NativeAstLossRecord[];
|
|
1125
|
+
readonly evidence: readonly EvidenceRecord[];
|
|
1126
|
+
readonly readiness: NativeImportReadinessClassification;
|
|
1127
|
+
readonly summary: ExternalSemanticIndexImportSummary;
|
|
1128
|
+
readonly metadata: Record<string, unknown>;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1070
1131
|
export interface NativeImporterAdapterParseInput {
|
|
1071
1132
|
readonly sourceText: string;
|
|
1072
1133
|
readonly sourcePath?: string;
|
|
@@ -1474,6 +1535,7 @@ export declare const ProjectionTargetLossClasses: readonly ProjectionTargetLossC
|
|
|
1474
1535
|
export declare const NativeImportReadinessBySeverity: Readonly<Record<NativeImportLossSummary['highestSeverity'], SemanticMergeReadiness>>;
|
|
1475
1536
|
export declare const NativeImportFeatureEvidencePolicies: Readonly<Record<string, NativeImportFeatureEvidencePolicy>>;
|
|
1476
1537
|
export declare const NativeImportLanguageProfiles: readonly NativeImportLanguageProfile[];
|
|
1538
|
+
export declare const ExternalSemanticIndexFormats: readonly ExternalSemanticIndexFormat[];
|
|
1477
1539
|
export declare function normalizeCompileTarget(target?: string): FrontierCompileTarget;
|
|
1478
1540
|
export declare function compileFrontierSource(source: string, options?: FrontierCompileOptions): FrontierCompileResult;
|
|
1479
1541
|
export declare function compileFrontierDocument(document: FrontierLangDocument, options?: FrontierCompileOptions): FrontierCompileResult;
|
|
@@ -1500,6 +1562,7 @@ export declare function createTreeSitterNativeImporterAdapter(options?: TreeSitt
|
|
|
1500
1562
|
export declare function runNativeImporterAdapter(adapter: NativeImporterAdapter, input: RunNativeImporterAdapterOptions): Promise<NativeImporterAdapterImportResult>;
|
|
1501
1563
|
export declare function runNativeTargetProjectionAdapter(adapter: NativeTargetProjectionAdapter, input: NativeTargetProjectionAdapterInput): NativeTargetProjectionResult;
|
|
1502
1564
|
export declare function projectNativeImportToSource(importResult: NativeSourceImportResult | NativeProjectImportResult, options?: ProjectNativeImportToSourceOptions): NativeSourceProjectionResult;
|
|
1565
|
+
export declare function importExternalSemanticIndex(input: ImportExternalSemanticIndexOptions | SemanticIndexRecord): ExternalSemanticIndexImportResult;
|
|
1503
1566
|
export declare function importNativeSource(input: ImportNativeSourceOptions): NativeSourceImportResult;
|
|
1504
1567
|
export declare function diffNativeSources(input: DiffNativeSourcesOptions): NativeSourceChangeSet;
|
|
1505
1568
|
export declare function diffNativeSourceImports(input: DiffNativeSourceImportsOptions): NativeSourceChangeSet;
|