@playcanvas/attribute-parser 1.3.3 → 1.4.0

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.3.3",
8
+ "version": "1.4.0",
9
9
  "dependencies": {
10
10
  "@playcanvas/eslint-config": "^1.7.4 || ^2.0.0",
11
11
  "@typescript/vfs": "^1.6.0",
package/rollup.config.js CHANGED
@@ -22,7 +22,12 @@ export default {
22
22
  preferBuiltins: false // Prefer the local versions of built-ins instead of Node.js versions
23
23
  }),
24
24
  swc({ swc: {
25
- minify: true
25
+ minify: true,
26
+ jsc: {
27
+ minify: {
28
+ compress: true
29
+ }
30
+ }
26
31
  } })
27
32
  ]
28
33
  };
@@ -147,7 +147,9 @@ const SUPPORTED_BLOCK_TAGS = new Map([
147
147
  ['size', 'number'],
148
148
  ['step', 'number'],
149
149
  ['title', 'string'],
150
- ['default', 'any']
150
+ ['default', 'any'],
151
+ ['enabledif', 'any'],
152
+ ['visibleif', 'any']
151
153
  ]);
152
154
 
153
155
  /**
@@ -202,6 +204,16 @@ const mapAttributesToOutput = (attribute) => {
202
204
  delete attribute.default;
203
205
  }
204
206
 
207
+ // enabledif is in a {}, so strip it out
208
+ if (attribute.enabledif?.startsWith('{') && attribute.enabledif?.endsWith('}')) {
209
+ attribute.enabledif = attribute.enabledif.slice(1, -1);
210
+ }
211
+
212
+ // enabledif is in a {}, so strip it out
213
+ if (attribute.visibleif?.startsWith('{') && attribute.visibleif?.endsWith('}')) {
214
+ attribute.visibleif = attribute.visibleif.slice(1, -1);
215
+ }
216
+
205
217
  // remove typeName from the output
206
218
  delete attribute.typeName;
207
219
  delete attribute.value;
@@ -0,0 +1,22 @@
1
+ import { Script } from 'playcanvas';
2
+
3
+ class Example extends Script {
4
+ /**
5
+ * @attribute
6
+ * @visibleif {b === 2}
7
+ */
8
+ a = 1;
9
+
10
+ /**
11
+ * @attribute
12
+ * @enabledif {a === 3}
13
+ */
14
+ b = 1;
15
+
16
+ /**
17
+ * @attribute
18
+ */
19
+ c = 1;
20
+ }
21
+
22
+ export { Example };
@@ -0,0 +1,45 @@
1
+ import { expect } from 'chai';
2
+ import { describe, it, before } from 'mocha';
3
+
4
+ import { parseAttributes } from '../../utils.js';
5
+
6
+ describe('VALID: Conditional Tags', function () {
7
+ let data;
8
+ before(async function () {
9
+ data = await parseAttributes('./conditional.valid.js');
10
+ });
11
+
12
+ it('only results should exist', function () {
13
+ expect(data).to.exist;
14
+ expect(data[0]).to.not.be.empty;
15
+ expect(data[1]).to.be.empty;
16
+ });
17
+
18
+ it('Example: should exist without errors', function () {
19
+ expect(data[0]?.example).to.exist;
20
+ expect(data[0].example.attributes).to.not.be.empty;
21
+ expect(data[0].example.errors).to.be.empty;
22
+ });
23
+
24
+ it('a: should conditional `@visibleif` tag', function () {
25
+ expect(data[0].example.attributes.a).exist;
26
+ expect(data[0].example.attributes.a.name).to.equal('a');
27
+ expect(data[0].example.attributes.a.type).to.equal('number');
28
+ expect(data[0].example.attributes.a.visibleif).to.equal('b === 2');
29
+ });
30
+
31
+ it('b: should conditional `@enabledif` tag', function () {
32
+ expect(data[0].example.attributes.b).exist;
33
+ expect(data[0].example.attributes.b.name).to.equal('b');
34
+ expect(data[0].example.attributes.b.type).to.equal('number');
35
+ expect(data[0].example.attributes.b.enabledif).to.equal('a === 3');
36
+ });
37
+
38
+ it('c: should not include `@enabledif` or `@visibleif` tag if none is declared', function () {
39
+ expect(data[0].example.attributes.c).exist;
40
+ expect(data[0].example.attributes.c.name).to.equal('c');
41
+ expect(data[0].example.attributes.c.type).to.equal('number');
42
+ expect(data[0].example.attributes.c.enabledif).to.not.exist;
43
+ expect(data[0].example.attributes.c.visibleif).to.not.exist;
44
+ });
45
+ });