Skip to content

Commit 8db2a00

Browse files
Add util method to get a child translator
1 parent e880fe4 commit 8db2a00

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

packages/malloy/src/lang/parse-malloy.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,14 @@ export abstract class MalloyTranslation {
918918
return attempt;
919919
}
920920

921+
translatorForDependency(url: string): MalloyTranslation {
922+
const child = this.childTranslators.get(url);
923+
if (child === undefined) {
924+
throw new Error(`No child translator for ${url}`);
925+
}
926+
return child;
927+
}
928+
921929
importAt(position: DocumentPosition): ImportLocation | undefined {
922930
// Here we assume that imports DO NOT overlap. And then we do a linear
923931
// search to find the one we're looking for.

packages/malloy/src/lang/test/imports.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ source: botProjQSrc is botProjQ
147147
'internal://test/langtests/grandChild': {},
148148
},
149149
});
150+
const child = docParse.translatorForDependency(
151+
'internal://test/langtests/child'
152+
);
153+
expect(child.translate().modelDef?.dependencies).toMatchObject({
154+
'internal://test/langtests/grandChild': {},
155+
});
150156
});
151157
test('relative imports', () => {
152158
const docParse = new TestTranslator('import "../parent.malloy"');

packages/malloy/src/lang/test/pretranslate.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ describe('pretranslated models', () => {
4040
expect(docParse.translate().modelDef?.dependencies).toMatchObject({
4141
'internal://test/langtests/child': {},
4242
});
43+
const child = docParse.translatorForDependency(
44+
'internal://test/langtests/child'
45+
);
46+
expect(child.translate().modelDef?.dependencies).toMatchObject({});
4347
});
4448
});

0 commit comments

Comments
 (0)