@playcanvas/attribute-parser 1.3.3 → 1.5.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.5.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
  };
@@ -154,7 +154,7 @@ export class AttributeParser {
154
154
 
155
155
  // Check if the declaration is a TypeScript enum
156
156
  if (ts.isEnumDeclaration(declaration)) {
157
- members = declaration.members.map(member => ({ [member.name.getText()]: member.initializer.text }));
157
+ members = declaration.members.map(member => ({ [member.name.text]: member.initializer.text }));
158
158
  }
159
159
 
160
160
  // Additionally check for JSDoc enum tag
@@ -187,7 +187,8 @@ export class AttributeParser {
187
187
  node.properties.forEach((property) => {
188
188
 
189
189
  if (ts.isPropertyAssignment(property)) {
190
- const name = property.name && ts.isIdentifier(property.name) && property.name.text;
190
+ const isValidName = ts.isIdentifier(property.name) || ts.isStringLiteral(property.name);
191
+ const name = isValidName && property.name.text;
191
192
  const value = getLiteralValue(property.initializer, this.typeChecker);
192
193
  members.push({ [name]: value });
193
194
  }
@@ -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 };
@@ -16,7 +16,8 @@ const NumberEnum = {
16
16
  const StringEnum = {
17
17
  A: 'a',
18
18
  B: 'b',
19
- C: 'c'
19
+ C: 'c',
20
+ 'A string key': 'd'
20
21
  };
21
22
 
22
23
  /**
@@ -9,7 +9,8 @@ enum NumberEnum {
9
9
  enum StringEnum {
10
10
  A = 'a',
11
11
  B = 'b',
12
- C = 'c'
12
+ C = 'c',
13
+ "A string key" = 'd'
13
14
  };
14
15
 
15
16
  enum NumberNumberEnum {
@@ -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
+ });
@@ -56,10 +56,11 @@ function runTests(fileName) {
56
56
  expect(data[0].example.attributes.h.name).to.equal('h');
57
57
  expect(data[0].example.attributes.h.type).to.equal('string');
58
58
  expect(data[0].example.attributes.h.array).to.equal(false);
59
- expect(data[0].example.attributes.h.enum).to.be.an('array').with.lengthOf(3);
59
+ expect(data[0].example.attributes.h.enum).to.be.an('array').with.lengthOf(4);
60
60
  expect(data[0].example.attributes.h.enum[0]).to.deep.equal({ A: 'a' });
61
61
  expect(data[0].example.attributes.h.enum[1]).to.deep.equal({ B: 'b' });
62
62
  expect(data[0].example.attributes.h.enum[2]).to.deep.equal({ C: 'c' });
63
+ expect(data[0].example.attributes.h.enum[3]).to.deep.equal({ 'A string key': 'd' });
63
64
  expect(data[0].example.attributes.h.default).to.equal('');
64
65
  });
65
66