Skip to content

Commit

Permalink
Fixed a CJS circular reference issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JrMasterModelBuilder committed Sep 29, 2023
1 parent 49094f8 commit d45948f
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 14 deletions.
53 changes: 53 additions & 0 deletions spec/fixtures/hdiutil.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>system-entities</key>
<array>
<dict>
<key>content-hint</key>
<string>Apple_APFS</string>
<key>dev-entry</key>
<string>/dev/disk6s1</string>
<key>potentially-mountable</key>
<false/>
<key>unmapped-content-hint</key>
<string>7C3457EF-0000-11AA-AA11-00306543ECAC</string>
</dict>
<dict>
<key>content-hint</key>
<string>GUID_partition_scheme</string>
<key>dev-entry</key>
<string>/dev/disk6</string>
<key>potentially-mountable</key>
<false/>
<key>unmapped-content-hint</key>
<string>GUID_partition_scheme</string>
</dict>
<dict>
<key>content-hint</key>
<string>EF57347C-0000-11AA-AA11-00306543ECAC</string>
<key>dev-entry</key>
<string>/dev/disk7</string>
<key>potentially-mountable</key>
<false/>
<key>unmapped-content-hint</key>
<string>EF57347C-0000-11AA-AA11-00306543ECAC</string>
</dict>
<dict>
<key>content-hint</key>
<string>41504653-0000-11AA-AA11-00306543ECAC</string>
<key>dev-entry</key>
<string>/dev/disk7s1</string>
<key>mount-point</key>
<string>/Volumes/test</string>
<key>potentially-mountable</key>
<true/>
<key>unmapped-content-hint</key>
<string>41504653-0000-11AA-AA11-00306543ECAC</string>
<key>volume-kind</key>
<string>apfs</string>
</dict>
</array>
</dict>
</plist>
10 changes: 10 additions & 0 deletions src/plist.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
});
});
});
});
4 changes: 2 additions & 2 deletions src/plist.ts
Original file line number Diff line number Diff line change
@@ -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 = '<?xml version="1.0" encoding="UTF-8"?>';
const xmlDoctype =
Expand Down Expand Up @@ -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);
}

Expand Down
23 changes: 17 additions & 6 deletions src/value/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<string, new () => Value>>;

Expand All @@ -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);
}
}
}
Expand Down
23 changes: 17 additions & 6 deletions src/value/dict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Map<string, new () => Value>>;

Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit d45948f

Please sign in to comment.