@playcanvas/attribute-parser 1.4.0 → 1.5.1

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.1",
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
  }
@@ -218,9 +218,19 @@ export function getJSDocTags(node, typeChecker) {
218
218
  heritageChain.forEach((classNode) => {
219
219
  // for each class iterate over it's class members
220
220
  classNode.members.forEach((member) => {
221
- if (ts.isPropertyDeclaration(member) || ts.isSetAccessor(member) || ts.isPropertySignature(member)) {
221
+ const isSetter = ts.isSetAccessor(member);
222
+ if (ts.isPropertyDeclaration(member) || isSetter || ts.isPropertySignature(member)) {
222
223
  const memberName = member.name && ts.isIdentifier(member.name) ? member.name.text : 'unnamed';
223
- const hasJsDoc = member.jsDoc?.length > 0;
224
+
225
+ let hasJsDoc = member.jsDoc?.length > 0;
226
+
227
+ // If we are a setter with no jsdoc block, check any associated getter
228
+ if (isSetter && !hasJsDoc) {
229
+ const symbol = typeChecker.getSymbolAtLocation(member.name);
230
+ member = symbol.declarations.find(accessor => accessor.jsDoc?.length > 0);
231
+ hasJsDoc = !!member;
232
+ }
233
+
224
234
  if (hasJsDoc) {
225
235
  tags.push({
226
236
  memberName,
@@ -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 {
@@ -12,6 +12,8 @@ class Example extends Script {
12
12
 
13
13
  _b = 10;
14
14
 
15
+ _d = 10;
16
+
15
17
  /**
16
18
  * @attribute
17
19
  * @type {number}
@@ -28,6 +30,20 @@ class Example extends Script {
28
30
  * @type {number}
29
31
  */
30
32
  c;
33
+
34
+ /**
35
+ * Reverse order gett/setter accessor
36
+ * @attribute
37
+ * @type {number}
38
+ */
39
+ get d() {
40
+ return this._d;
41
+ }
42
+
43
+ // eslint-disable-next-line grouped-accessor-pairs
44
+ set d(v) {
45
+ this._d = v;
46
+ }
31
47
  }
32
48
 
33
49
  export { Example };
@@ -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
 
@@ -43,4 +43,12 @@ describe('VALID: Misc attribute types', function () {
43
43
  expect(data[0].example.attributes.c).to.not.exist;
44
44
  });
45
45
 
46
+ it('d: should be a numeric attribute with a getter and setter defined in reverse order', function () {
47
+ expect(data[0].example.attributes.d).to.exist;
48
+ expect(data[0].example.attributes.d.name).to.equal('d');
49
+ expect(data[0].example.attributes.d.type).to.equal('number');
50
+ expect(data[0].example.attributes.d.array).to.equal(false);
51
+ expect(data[0].example.attributes.d.default).to.equal(0);
52
+ });
53
+
46
54
  });
package/rollup.config.js DELETED
@@ -1,33 +0,0 @@
1
- import commonjs from '@rollup/plugin-commonjs';
2
- import resolve from '@rollup/plugin-node-resolve';
3
- import swc from '@rollup/plugin-swc';
4
-
5
- export default {
6
- input: 'src/index.js',
7
- treeshake: { moduleSideEffects: false },
8
- // Mark 'typescript' as external, so it won’t get bundled
9
- // external: ['typescript'],
10
- output: {
11
- dir: 'dist',
12
- format: 'esm'
13
- },
14
- plugins: [
15
- commonjs({
16
- include: /node_modules/,
17
- ignoreGlobal: true,
18
- sourceMap: false
19
- }),
20
- resolve({
21
- browser: true, // This instructs the plugin to resolve for the browser
22
- preferBuiltins: false // Prefer the local versions of built-ins instead of Node.js versions
23
- }),
24
- swc({ swc: {
25
- minify: true,
26
- jsc: {
27
- minify: {
28
- compress: true
29
- }
30
- }
31
- } })
32
- ]
33
- };