From d45948fda0262acdccbc872df08da787ca9fe796 Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Fri, 29 Sep 2023 01:54:24 -0400 Subject: [PATCH] Fixed a CJS circular reference issue --- spec/fixtures/hdiutil.plist | 53 +++++++++++++++++++++++++++++++++++++ src/plist.test.ts | 10 +++++++ src/plist.ts | 4 +-- src/value/array.ts | 23 +++++++++++----- src/value/dict.ts | 23 +++++++++++----- 5 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 spec/fixtures/hdiutil.plist diff --git a/spec/fixtures/hdiutil.plist b/spec/fixtures/hdiutil.plist new file mode 100644 index 0000000..8a5d5b8 --- /dev/null +++ b/spec/fixtures/hdiutil.plist @@ -0,0 +1,53 @@ + + + + + system-entities + + + content-hint + Apple_APFS + dev-entry + /dev/disk6s1 + potentially-mountable + + unmapped-content-hint + 7C3457EF-0000-11AA-AA11-00306543ECAC + + + content-hint + GUID_partition_scheme + dev-entry + /dev/disk6 + potentially-mountable + + unmapped-content-hint + GUID_partition_scheme + + + content-hint + EF57347C-0000-11AA-AA11-00306543ECAC + dev-entry + /dev/disk7 + potentially-mountable + + unmapped-content-hint + EF57347C-0000-11AA-AA11-00306543ECAC + + + content-hint + 41504653-0000-11AA-AA11-00306543ECAC + dev-entry + /dev/disk7s1 + mount-point + /Volumes/test + potentially-mountable + + unmapped-content-hint + 41504653-0000-11AA-AA11-00306543ECAC + volume-kind + apfs + + + + diff --git a/src/plist.test.ts b/src/plist.test.ts index cc05a8d..4d4a1b0 100644 --- a/src/plist.test.ts +++ b/src/plist.test.ts @@ -1,6 +1,7 @@ /* eslint-disable max-nested-callbacks */ import {describe, it} from 'node:test'; import {ok, strictEqual, throws} from 'node:assert'; +import {readFile} from 'node:fs/promises'; import {Plist} from './plist'; import {ValueBoolean} from './value/boolean'; @@ -174,6 +175,15 @@ void describe('document', () => { strictEqual(value.toXml(), new ValueBoolean(false).toXml()); } }); + + void it('hdiutil', async () => { + const xml = await readFile( + './spec/fixtures/hdiutil.plist', + 'utf8' + ); + const doc = new Plist(); + doc.fromXml(xml); + }); }); }); }); diff --git a/src/plist.ts b/src/plist.ts index 03a6036..c2561b2 100644 --- a/src/plist.ts +++ b/src/plist.ts @@ -1,7 +1,7 @@ import {INDENT_ROOT, IToXmlOptions, NEWLINE_STRING} from './options'; import {IElement, xmlDecode, xmlElementChildElements} from './util'; import {Value} from './value'; -import {ValueArray} from './value/array'; +import {ValueDict} from './value/dict'; const xmlDeclaration = ''; const xmlDoctype = @@ -130,7 +130,7 @@ export class Plist { * @returns Value element. */ public childFromXmlElement(element: IElement) { - const a = new ValueArray(); + const a = new ValueDict(); return a.childFromXmlElement(element); } diff --git a/src/value/array.ts b/src/value/array.ts index e25b05a..409c92c 100644 --- a/src/value/array.ts +++ b/src/value/array.ts @@ -2,7 +2,12 @@ import {INDENT_STRING, NEWLINE_STRING, IToXmlOptions} from '../options'; import {IElement, assertXmlTagName, xmlElementChildElements} from '../util'; import {Value} from '../value'; -import * as tags from './index'; +import {ValueBoolean} from './boolean'; +import {ValueData} from './data'; +import {ValueDict} from './dict'; +import {ValueInteger} from './integer'; +import {ValueReal} from './real'; +import {ValueString} from './string'; let childTagNames: Readonly Value>>; @@ -28,11 +33,17 @@ export class ValueArray extends Value { public static get CHILD_TAG_NAMES() { if (!childTagNames) { childTagNames = new Map(); - for (const ValueType of Object.values(tags)) { - if (ValueType?.prototype instanceof Value) { - for (const t of ValueType.TAG_NAMES) { - childTagNames.set(t, ValueType); - } + for (const ValueType of [ + ValueArray, + ValueBoolean, + ValueData, + ValueDict, + ValueInteger, + ValueReal, + ValueString + ]) { + for (const t of ValueType.TAG_NAMES) { + childTagNames.set(t, ValueType); } } } diff --git a/src/value/dict.ts b/src/value/dict.ts index 13bf586..e309c79 100644 --- a/src/value/dict.ts +++ b/src/value/dict.ts @@ -7,7 +7,12 @@ import { } from '../util'; import {Value} from '../value'; -import * as tags from './index'; +import {ValueArray} from './array'; +import {ValueBoolean} from './boolean'; +import {ValueData} from './data'; +import {ValueInteger} from './integer'; +import {ValueReal} from './real'; +import {ValueString} from './string'; let childTagNames: Readonly Value>>; @@ -33,11 +38,17 @@ export class ValueDict extends Value { public static get CHILD_TAG_NAMES() { if (!childTagNames) { childTagNames = new Map(); - for (const ValueType of Object.values(tags)) { - if (ValueType?.prototype instanceof Value) { - for (const t of ValueType.TAG_NAMES) { - childTagNames.set(t, ValueType); - } + for (const ValueType of [ + ValueArray, + ValueBoolean, + ValueData, + ValueDict, + ValueInteger, + ValueReal, + ValueString + ]) { + for (const t of ValueType.TAG_NAMES) { + childTagNames.set(t, ValueType); } } }