Skip to content

Commit

Permalink
Use getExportedElements in validation of ExportDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
georg-schwarz committed May 28, 2024
1 parent 7108f05 commit 7f2dfe5
Showing 1 changed file with 2 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import { strict as assert } from 'assert';

import { AstUtils } from 'langium';

import { getExportedElements } from '../../ast';
import {
type ExportDefinition,
type ExportableElement,
type JayveeModel,
isExportableElement,
isExportableElementDefinition,
isJayveeModel,
} from '../../ast/generated/ast';
Expand Down Expand Up @@ -65,7 +63,7 @@ function checkUniqueAlias(

const model = AstUtils.getContainerOfType(exportDefinition, isJayveeModel);
assert(model !== undefined);
const allExports = collectAllExportsWithinSameFile(model);
const allExports = getExportedElements(model);

const elementsWithSameName = allExports.filter(
(e) => e.alias === exportDefinition.alias,
Expand All @@ -87,48 +85,3 @@ function checkUniqueAlias(
);
}
}

function collectAllExportsWithinSameFile(model: JayveeModel): {
alias: string;
element: ExportDefinition | ExportableElement;
}[] {
const exportedElementNames: {
alias: string;
element: ExportDefinition | ExportableElement;
}[] = [];

for (const node of model.exportableElements) {
if (node.isPublished) {
assert(
isExportableElement(node),
'Exported node is not an ExportableElement',
);
exportedElementNames.push({
alias: node.name,
element: node,
});
}
}

for (const node of model.exports) {
if (node.alias !== undefined) {
exportedElementNames.push({
alias: node.alias,
element: node,
});
continue;
}

const originalDefinition = node.element?.ref;
if (
originalDefinition !== undefined &&
originalDefinition.name !== undefined
) {
exportedElementNames.push({
alias: originalDefinition.name,
element: originalDefinition,
});
}
}
return exportedElementNames;
}

0 comments on commit 7f2dfe5

Please sign in to comment.