@playcanvas/attribute-parser 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "engines": {
6
6
  "node": ">=18.0.0"
7
7
  },
8
- "version": "1.0.2",
8
+ "version": "1.0.3",
9
9
  "dependencies": {
10
10
  "@microsoft/tsdoc": "^0.15.0",
11
11
  "@typescript/vfs": "^1.6.0",
package/src/index.js CHANGED
@@ -32,14 +32,20 @@ export class JSDocParser {
32
32
  */
33
33
  _errors = [];
34
34
 
35
- async init(basePath = '') {
35
+ /**
36
+ * Initializes the JSDocParser with the standard library files
37
+ *
38
+ * @param {string} libPath - The path to standard library files
39
+ * @returns {Promise<JSDocParser>} - The initialized JSDocParser
40
+ */
41
+ async init(libPath = '') {
36
42
  if (this._env) {
37
- return;
43
+ return this;
38
44
  }
39
45
 
40
46
  let fsMap;
41
- if (basePath) {
42
- fsMap = await createDefaultMapFromCDN({ target: ts.ScriptTarget.ES2022 }, basePath, ts);
47
+ if (libPath) {
48
+ fsMap = await createDefaultMapFromCDN({ target: ts.ScriptTarget.ES2022 }, libPath, ts);
43
49
  } else {
44
50
  fsMap = await createDefaultMapFromNodeModules(COMPILER_OPTIONS, ts);
45
51
  }
@@ -47,6 +53,8 @@ export class JSDocParser {
47
53
  // Set up the virtual file system and environment
48
54
  const system = createSystem(fsMap);
49
55
  this._env = createVirtualTypeScriptEnvironment(system, Array.from(fsMap.keys()), ts, COMPILER_OPTIONS);
56
+
57
+ return this;
50
58
  }
51
59
 
52
60
  /**
@@ -190,6 +190,11 @@ const mapAttributesToOutput = (attribute) => {
190
190
  // set the default value
191
191
  if (attribute.value !== undefined) attribute.default = attribute.value;
192
192
 
193
+ // Curve Attributes specifically should not expose a default value if it's an empty array
194
+ if (attribute.type === 'curve' && Array.isArray(attribute.value) && attribute.value.length === 0) {
195
+ delete attribute.default;
196
+ }
197
+
193
198
  // remove typeName from the output
194
199
  delete attribute.typeName;
195
200
  delete attribute.value;
@@ -27,7 +27,7 @@ describe('VALID: Curve attribute', function () {
27
27
  expect(data[0].example.attributes.a.name).to.equal('a');
28
28
  expect(data[0].example.attributes.a.type).to.equal('curve');
29
29
  expect(data[0].example.attributes.a.array).to.equal(false);
30
- expect(data[0].example.attributes.a.default).to.eql([]);
30
+ expect(data[0].example.attributes.a.default).to.not.exist;
31
31
  });
32
32
 
33
33
  it('b: should be a curve attribute with a default value', function () {
@@ -43,7 +43,7 @@ describe('VALID: Curve attribute', function () {
43
43
  expect(data[0].example.attributes.c.name).to.equal('c');
44
44
  expect(data[0].example.attributes.c.type).to.equal('curve');
45
45
  expect(data[0].example.attributes.c.array).to.equal(false);
46
- expect(data[0].example.attributes.c.default).to.eql([]);
46
+ expect(data[0].example.attributes.a.default).to.not.exist;
47
47
  expect(data[0].example.attributes.c.color).to.equal('r');
48
48
  });
49
49
 
@@ -52,7 +52,7 @@ describe('VALID: Curve attribute', function () {
52
52
  expect(data[0].example.attributes.d.name).to.equal('d');
53
53
  expect(data[0].example.attributes.d.type).to.equal('curve');
54
54
  expect(data[0].example.attributes.d.array).to.equal(false);
55
- expect(data[0].example.attributes.d.default).to.eql([]);
55
+ expect(data[0].example.attributes.a.default).to.not.exist;
56
56
  expect(data[0].example.attributes.d.color).to.equal('rgb');
57
57
  expect(data[0].example.attributes.d.curves).to.deep.equal(['x', 'y', 'z']);
58
58
  });
@@ -63,7 +63,7 @@ describe('VALID: Curve attribute', function () {
63
63
  expect(data[0].example.attributes.e.type).to.equal('curve');
64
64
  expect(data[0].example.attributes.e.array).to.equal(true);
65
65
  expect(data[0].example.attributes.e.size).to.equal(2);
66
- expect(data[0].example.attributes.e.default).equal(null);
66
+ expect(data[0].example.attributes.e.default).to.not.exist;
67
67
  });
68
68
 
69
69
  it('f: should be a curve attribute in an unsual format', function () {