@playcanvas/attribute-parser 1.4.0 → 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.4.0",
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",
@@ -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
  }
@@ -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 {
@@ -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