1- import { invariant } from '@zenstackhq/common-helpers' ;
21import { AstUtils , URI , type AstNode , type LangiumDocument , type LangiumDocuments , type Reference } from 'langium' ;
32import fs from 'node:fs' ;
43import path from 'path' ;
@@ -172,7 +171,10 @@ export function getRecursiveBases(
172171 }
173172 seen . add ( decl ) ;
174173 decl . mixins . forEach ( ( mixin ) => {
175- const baseDecl = mixin . ref ;
174+ // avoid using mixin.ref since this function can be called before linking
175+ const baseDecl = decl . $container . declarations . find (
176+ ( d ) : d is TypeDef => isTypeDef ( d ) && d . name === mixin . $refText ,
177+ ) ;
176178 if ( baseDecl ) {
177179 if ( ! includeDelegate && isDelegateModel ( baseDecl ) ) {
178180 return ;
@@ -517,13 +519,15 @@ export function getAllFields(
517519
518520 const fields : DataField [ ] = [ ] ;
519521 for ( const mixin of decl . mixins ) {
520- invariant ( mixin . ref , `Mixin ${ mixin . $refText } is not resolved` ) ;
521- fields . push ( ...getAllFields ( mixin . ref , includeIgnored , seen ) ) ;
522+ if ( mixin . ref ) {
523+ fields . push ( ...getAllFields ( mixin . ref , includeIgnored , seen ) ) ;
524+ }
522525 }
523526
524527 if ( isDataModel ( decl ) && decl . baseModel ) {
525- invariant ( decl . baseModel . ref , `Base model ${ decl . baseModel . $refText } is not resolved` ) ;
526- fields . push ( ...getAllFields ( decl . baseModel . ref , includeIgnored , seen ) ) ;
528+ if ( decl . baseModel . ref ) {
529+ fields . push ( ...getAllFields ( decl . baseModel . ref , includeIgnored , seen ) ) ;
530+ }
527531 }
528532
529533 fields . push ( ...decl . fields . filter ( ( f ) => includeIgnored || ! hasAttribute ( f , '@ignore' ) ) ) ;
@@ -541,13 +545,15 @@ export function getAllAttributes(
541545
542546 const attributes : DataModelAttribute [ ] = [ ] ;
543547 for ( const mixin of decl . mixins ) {
544- invariant ( mixin . ref , `Mixin ${ mixin . $refText } is not resolved` ) ;
545- attributes . push ( ...getAllAttributes ( mixin . ref , seen ) ) ;
548+ if ( mixin . ref ) {
549+ attributes . push ( ...getAllAttributes ( mixin . ref , seen ) ) ;
550+ }
546551 }
547552
548553 if ( isDataModel ( decl ) && decl . baseModel ) {
549- invariant ( decl . baseModel . ref , `Base model ${ decl . baseModel . $refText } is not resolved` ) ;
550- attributes . push ( ...getAllAttributes ( decl . baseModel . ref , seen ) ) ;
554+ if ( decl . baseModel . ref ) {
555+ attributes . push ( ...getAllAttributes ( decl . baseModel . ref , seen ) ) ;
556+ }
551557 }
552558
553559 attributes . push ( ...decl . attributes ) ;
0 commit comments