@@ -54,7 +54,7 @@ export class JsonLdParser extends Transform implements RDF.Sink<EventEmitter, RD
5454 // Jobs that are not started yet that process a @type (only used if streamingProfile is false)
5555 private readonly typeJobs : { job : ( ) => Promise < void > , keys : string [ ] } [ ] ;
5656 // Jobs that are not started yet because of a missing @context or @type (only used if streamingProfile is false)
57- private readonly contextAwaitingJobs : { job : ( ) => Promise < void > , keys : string [ ] } [ ] ;
57+ private readonly contextAwaitingJobs : { job : ( ) => Promise < void > , keys : string [ ] ; depth : number } [ ] ;
5858
5959 // The last depth that was processed.
6060 private lastDepth : number ;
@@ -453,12 +453,8 @@ export class JsonLdParser extends Transform implements RDF.Sink<EventEmitter, RD
453453 jobs = this . contextJobs [ depth ] = [ ] ;
454454 }
455455 jobs . push ( valueJobCb ) ;
456- } else if ( keys [ depth ] === '@type'
457- || typeof keys [ depth ] === 'number' && keys [ depth - 1 ] === '@type' ) { // Also capture @type with array values
458- // Remove @type from keys, because we want it to apply to parent later on
459- this . typeJobs . push ( { job : valueJobCb , keys : keys . slice ( 0 , keys . length - 1 ) } ) ;
460456 } else {
461- this . contextAwaitingJobs . push ( { job : valueJobCb , keys } ) ;
457+ this . contextAwaitingJobs . push ( { job : valueJobCb , keys, depth } ) ;
462458 }
463459 } else {
464460 // Make sure that our value jobs are chained synchronously
@@ -508,8 +504,20 @@ export class JsonLdParser extends Transform implements RDF.Sink<EventEmitter, RD
508504 // Clear the keyword cache.
509505 this . parsingContext . unaliasedKeywordCacheStack . splice ( 0 ) ;
510506
511- // Handle non-context jobs
507+ const contextAwaitingJobs : { job : ( ) => Promise < void > , keys : string [ ] ; depth : number } [ ] = [ ] ;
508+
512509 for ( const job of this . contextAwaitingJobs ) {
510+ if ( ( await this . util . unaliasKeyword ( job . keys [ job . depth ] , job . keys , job . depth , true ) ) === '@type'
511+ || typeof job . keys [ job . depth ] === 'number' && ( await this . util . unaliasKeyword ( job . keys [ job . depth - 1 ] , job . keys , job . depth - 1 , true ) ) === '@type' ) { // Also capture @type with array values
512+ // Remove @type from keys, because we want it to apply to parent later on
513+ this . typeJobs . push ( { job : job . job , keys : job . keys . slice ( 0 , job . keys . length - 1 ) } )
514+ } else {
515+ contextAwaitingJobs . push ( job )
516+ }
517+ }
518+
519+ // Handle non-context jobs
520+ for ( const job of contextAwaitingJobs ) {
513521 // Check if we have a type (with possible type-scoped context) that should be handled before.
514522 // We check all possible parent nodes for the current job, from root to leaves.
515523 if ( this . typeJobs . length > 0 ) {
0 commit comments