@@ -386,6 +386,12 @@ api.expand = async ({
386386
387387/**
388388 * Drop empty object, top-level @value/@list, or object with only @id
389+ *
390+ * @param value Value to check.
391+ * @param count Number of properties in object.
392+ * @param options The expansion options.
393+ *
394+ * @return null if dropped, value otherwise.
389395 */
390396function _dropUnsafeObject ( {
391397 value,
@@ -948,15 +954,17 @@ async function _expandObject({
948954 // index cases handled above
949955 if ( container . includes ( '@graph' ) &&
950956 ! container . some ( key => key === '@id' || key === '@index' ) ) {
951- // ensure expanded values are arrays
952- // ensure an array
957+ // ensure expanded values are in an array
953958 expandedValue = _asArray ( expandedValue ) ;
954- // check if needs to be dropped
955- const count = Object . keys ( expandedValue [ 0 ] ) . length ;
956- if ( ! options . isFrame && _dropUnsafeObject ( {
957- value : expandedValue [ 0 ] , count, options
958- } ) === null ) {
959- // skip adding and continue
959+ if ( ! options . isFrame ) {
960+ // drop items if needed
961+ expandedValue = expandedValue . filter ( v => {
962+ const count = Object . keys ( v ) . length ;
963+ return _dropUnsafeObject ( { value : v , count, options} ) !== null ;
964+ } ) ;
965+ }
966+ if ( expandedValue . length === 0 ) {
967+ // all items dropped, skip adding and continue
960968 continue ;
961969 }
962970 // convert to graph
0 commit comments