@playcanvas/attribute-parser 1.0.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.
Files changed (56) hide show
  1. package/.github/workflows/ci.yml +28 -0
  2. package/README.md +76 -0
  3. package/package.json +24 -0
  4. package/src/index.js +226 -0
  5. package/src/parsers/attribute-parser.js +280 -0
  6. package/src/parsers/parsing-error.js +14 -0
  7. package/src/parsers/script-parser.js +404 -0
  8. package/src/utils/attribute-utils.js +72 -0
  9. package/src/utils/generic-utils.js +18 -0
  10. package/src/utils/tag-utils.js +65 -0
  11. package/src/utils/ts-utils.js +501 -0
  12. package/test/fixtures/asset.invalid.js +26 -0
  13. package/test/fixtures/asset.valid.js +25 -0
  14. package/test/fixtures/checkbox.valid.js +23 -0
  15. package/test/fixtures/color.valid.js +23 -0
  16. package/test/fixtures/curve.invalid.js +28 -0
  17. package/test/fixtures/curve.valid.js +49 -0
  18. package/test/fixtures/entity.valid.js +23 -0
  19. package/test/fixtures/enum.valid.js +78 -0
  20. package/test/fixtures/export.import.js +3 -0
  21. package/test/fixtures/export.valid.js +23 -0
  22. package/test/fixtures/inherit.valid.js +52 -0
  23. package/test/fixtures/intellisense.valid.js +37 -0
  24. package/test/fixtures/json.invalid.js +22 -0
  25. package/test/fixtures/json.valid.js +103 -0
  26. package/test/fixtures/misc.invalid.js +25 -0
  27. package/test/fixtures/misc.valid.js +33 -0
  28. package/test/fixtures/numeric.invalid.js +38 -0
  29. package/test/fixtures/numeric.valid.js +63 -0
  30. package/test/fixtures/playcanvas.d.ts +47963 -0
  31. package/test/fixtures/program.invalid.js +11 -0
  32. package/test/fixtures/text.valid.js +30 -0
  33. package/test/fixtures/vector.invalid.js +13 -0
  34. package/test/fixtures/vector.valid.js +23 -0
  35. package/test/tests/invalid/asset.test.js +48 -0
  36. package/test/tests/invalid/curve.test.js +24 -0
  37. package/test/tests/invalid/json.test.js +28 -0
  38. package/test/tests/invalid/misc.test.js +42 -0
  39. package/test/tests/invalid/numeric.test.js +56 -0
  40. package/test/tests/invalid/program.test.js +18 -0
  41. package/test/tests/invalid/vector.test.js +29 -0
  42. package/test/tests/valid/asset.test.js +51 -0
  43. package/test/tests/valid/checkbox.test.js +50 -0
  44. package/test/tests/valid/color.test.js +50 -0
  45. package/test/tests/valid/curve.test.js +77 -0
  46. package/test/tests/valid/entity.test.js +50 -0
  47. package/test/tests/valid/enum.test.js +74 -0
  48. package/test/tests/valid/export.test.js +56 -0
  49. package/test/tests/valid/inherit.test.js +103 -0
  50. package/test/tests/valid/intellisense.test.js +36 -0
  51. package/test/tests/valid/json.test.js +150 -0
  52. package/test/tests/valid/misc.test.js +47 -0
  53. package/test/tests/valid/numeric.test.js +104 -0
  54. package/test/tests/valid/text.test.js +59 -0
  55. package/test/tests/valid/vector.test.js +54 -0
  56. package/test/utils.js +53 -0
@@ -0,0 +1,78 @@
1
+ import { Script, Vec3 } from 'playcanvas';
2
+
3
+ /**
4
+ * @enum {number}
5
+ */
6
+ const NumberEnum = {
7
+ A: 0,
8
+ B: 1,
9
+ C: 2
10
+ };
11
+
12
+ /**
13
+ * @enum {string}
14
+ */
15
+ const StringEnum = {
16
+ A: 'a',
17
+ B: 'b',
18
+ C: 'c'
19
+ }
20
+
21
+ /**
22
+ * @enum {Vec3}
23
+ */
24
+ const Vec3Enum = {
25
+ A: new Vec3(1, 2, 3),
26
+ B: new Vec3(4, 5, 6),
27
+ C: new Vec3(7, 8, 9)
28
+ };
29
+
30
+ /**
31
+ * @enum {NumberEnum}
32
+ */
33
+ const NumberNumberEnum = {
34
+ A: NumberEnum.A,
35
+ B: NumberEnum.B,
36
+ C: NumberEnum.C
37
+ }
38
+
39
+ class Example extends Script {
40
+ /**
41
+ * @attribute
42
+ * @type {NumberEnum}
43
+ */
44
+ e;
45
+
46
+ /**
47
+ * @attribute
48
+ * @type {NumberEnum}
49
+ */
50
+ f = 1;
51
+
52
+ /**
53
+ * @attribute
54
+ * @type {NumberEnum[]}
55
+ * @size 2
56
+ */
57
+ g;
58
+
59
+ /**
60
+ * @attribute
61
+ * @type {StringEnum}
62
+ */
63
+ h;
64
+
65
+ /**
66
+ * @attribute
67
+ * @type {Vec3Enum}
68
+ */
69
+ i;
70
+
71
+ /**
72
+ * @attribute
73
+ * @type {NumberNumberEnum}
74
+ */
75
+ j = 2;
76
+ }
77
+
78
+ export { Example };
@@ -0,0 +1,3 @@
1
+ import { Script } from 'playcanvas';
2
+
3
+ export class ExampleImport extends Script {}
@@ -0,0 +1,23 @@
1
+
2
+ import { Script } from 'playcanvas';
3
+
4
+ import { ExampleImport } from './export.import.js';
5
+
6
+ class ExampleImportExtend extends ExampleImport {};
7
+
8
+ export { ExampleImport as ExampleImportExportAs } from './export.import.js';
9
+
10
+ class Example extends Script {};
11
+
12
+ export default class ExampleDefault extends Script {};
13
+
14
+ export class ExampleExport extends Script {}
15
+
16
+ class ExampleNotExported extends Script {}
17
+
18
+ export {
19
+ Example,
20
+ Example as ExampleExportAs,
21
+ ExampleImport,
22
+ ExampleImportExtend
23
+ }
@@ -0,0 +1,52 @@
1
+
2
+ import { Script } from 'playcanvas';
3
+
4
+ class Example extends Script {
5
+ /**
6
+ * @attribute
7
+ * @type {boolean}
8
+ */
9
+ a;
10
+ };
11
+
12
+ class ExampleExtended extends Example {
13
+ /**
14
+ * @attribute
15
+ * @type {number}
16
+ */
17
+ b;
18
+ };
19
+
20
+ class ExampleExtendedExtended extends ExampleExtended {
21
+ /**
22
+ * @attribute
23
+ * @type {string}
24
+ */
25
+ c;
26
+ }
27
+
28
+ const ScriptAlias = Script;
29
+
30
+ class ExampleAlias extends ScriptAlias {
31
+ /**
32
+ * @attribute
33
+ * @type {boolean}
34
+ */
35
+ a;
36
+ }
37
+
38
+ class ExampleNoExtend {
39
+ /**
40
+ * @attribute
41
+ * @type {number}
42
+ */
43
+ a;
44
+ }
45
+
46
+ export {
47
+ Example,
48
+ ExampleExtended,
49
+ ExampleExtendedExtended,
50
+ ExampleAlias,
51
+ ExampleNoExtend
52
+ };
@@ -0,0 +1,37 @@
1
+ /* eslint-disable */
2
+ import { Script, Vec3 } from 'playcanvas';
3
+
4
+ /**
5
+ * @interface
6
+ */
7
+ class Folder {
8
+ /**
9
+ * @attribute
10
+ */
11
+ a;
12
+
13
+ b = 10;
14
+ }
15
+
16
+ export class Example extends Script {
17
+ /**
18
+ * @attribute
19
+ */
20
+ a;
21
+
22
+ b = 10;
23
+
24
+ c = true;
25
+
26
+ d = 'hello';
27
+
28
+ e = {};
29
+
30
+ f = new Vec3();
31
+
32
+ /**
33
+ * @attribute
34
+ * @type {Folder}
35
+ */
36
+ g;
37
+ }
@@ -0,0 +1,22 @@
1
+ import { Script } from 'playcanvas';
2
+
3
+ class NoInterfaceFolder {
4
+ /**
5
+ * @attribute
6
+ * @type {boolean}
7
+ */
8
+ a;
9
+ }
10
+
11
+ /**
12
+ * @interface
13
+ */
14
+ class Example extends Script {
15
+ /**
16
+ * @attribute
17
+ * @type {NoInterfaceFolder}
18
+ */
19
+ o;
20
+ }
21
+
22
+ export { Example };
@@ -0,0 +1,103 @@
1
+ import { Script, Vec3 } from 'playcanvas';
2
+
3
+ /**
4
+ * @interface
5
+ */
6
+ class Folder {
7
+ /**
8
+ * @attribute
9
+ * @type {boolean}
10
+ */
11
+ a;
12
+
13
+ /**
14
+ * @attribute
15
+ */
16
+ b = 10;
17
+
18
+ c = 'hello';
19
+
20
+ /**
21
+ * @attribute
22
+ * @type {Vec3[]}
23
+ */
24
+ d;
25
+ }
26
+
27
+ /**
28
+ * @interface
29
+ */
30
+ class NestedFolder {
31
+ /**
32
+ * @attribute
33
+ * @type {Folder}
34
+ */
35
+ x;
36
+ }
37
+
38
+ /**
39
+ * @interface
40
+ */
41
+ class Example extends Script {
42
+ /**
43
+ * @attribute
44
+ * @type {Folder}
45
+ */
46
+ f;
47
+
48
+ /**
49
+ * @attribute
50
+ * @type {Folder[]}
51
+ * @size 2
52
+ */
53
+ g;
54
+
55
+ /**
56
+ * @attribute
57
+ * @type {NestedFolder}
58
+ */
59
+ h;
60
+
61
+ /**
62
+ * @attribute
63
+ */
64
+ i = { a: true, b: 10, c: 'hello', d: [new Vec3(1, 2, 3)] };
65
+
66
+ /**
67
+ * @typedef {object} TypeDefFolder
68
+ * @property {number} x - The x component
69
+ * @property {number} y - The y component
70
+ */
71
+
72
+ /**
73
+ * @attribute
74
+ * @type {TypeDefFolder}
75
+ */
76
+ j;
77
+
78
+ /**
79
+ * @typedef {{ x: number, y: number }} InlineTypeDefFolder
80
+ */
81
+
82
+ /**
83
+ * @attribute
84
+ * @type {InlineTypeDefFolder}
85
+ */
86
+ k;
87
+
88
+ /**
89
+ * @attribute
90
+ * @type {{ x: number, y: number }}
91
+ */
92
+ l;
93
+
94
+ /**
95
+ * @attribute
96
+ * @type {Example}
97
+ */
98
+ m;
99
+
100
+ n = 10;
101
+ }
102
+
103
+ export { Example };
@@ -0,0 +1,25 @@
1
+ import { Script } from 'playcanvas';
2
+ import { GraphNode } from './playcanvas';
3
+
4
+ class Vec3 {};
5
+
6
+ class Example extends Script {
7
+ /**
8
+ * @attribute
9
+ */
10
+ e = new GraphNode();
11
+
12
+ /**
13
+ * @attribute
14
+ */
15
+ f = new Vec3(); // Vec3 is not from playcanvas. It's type cannot be inferred
16
+
17
+ /**
18
+ * @attribute
19
+ * @type {number[]}
20
+ * @size a
21
+ */
22
+ g;
23
+ }
24
+
25
+ export { Example };
@@ -0,0 +1,33 @@
1
+ import { Script } from 'playcanvas';
2
+
3
+ class Example extends Script {
4
+ /**
5
+ * This is a description of the attribute.
6
+ *
7
+ * @attribute
8
+ * @type {number}
9
+ * @title A number
10
+ */
11
+ a;
12
+
13
+ _b = 10;
14
+
15
+ /**
16
+ * @attribute
17
+ * @type {number}
18
+ */
19
+ set b(v) {
20
+ this._b = v;
21
+ }
22
+
23
+ get b() {
24
+ return this._b;
25
+ }
26
+
27
+ /**
28
+ * @type {number}
29
+ */
30
+ c;
31
+ }
32
+
33
+ export { Example };
@@ -0,0 +1,38 @@
1
+ import { Script } from 'playcanvas';
2
+
3
+ class Example extends Script {
4
+ /**
5
+ * @attribute
6
+ * @range ['a', 'b']
7
+ */
8
+ a = 0;
9
+
10
+ /**
11
+ * @attribute
12
+ * @step 0.1
13
+ */
14
+ b;
15
+
16
+ /**
17
+ * @attribute
18
+ * @precision 2
19
+ */
20
+ c;
21
+
22
+ /**
23
+ * @attribute
24
+ * @type {number}
25
+ * @step a
26
+ * @precision b
27
+ */
28
+ d;
29
+
30
+ /**
31
+ * @attribute
32
+ * @type {number}
33
+ * @step
34
+ */
35
+ e;
36
+ }
37
+
38
+ export { Example };
@@ -0,0 +1,63 @@
1
+ import { Script } from 'playcanvas';
2
+
3
+ class Example extends Script {
4
+ /**
5
+ * @attribute
6
+ * @type {number}
7
+ */
8
+ a;
9
+
10
+ /**
11
+ * @attribute
12
+ */
13
+ b = 1;
14
+
15
+ /**
16
+ * @attribute
17
+ * @type {number}
18
+ * @precision 2
19
+ * @step 0.01
20
+ */
21
+ c;
22
+
23
+ /**
24
+ * @attribute
25
+ * @type {number}
26
+ * @range [0, 1]
27
+ * @precision 2
28
+ * @step 0.01
29
+ */
30
+ d;
31
+
32
+ /**
33
+ * @attribute
34
+ * @type {number[]}
35
+ * @size 2
36
+ */
37
+ e;
38
+
39
+ /**
40
+ * @attribute
41
+ * @type {number}
42
+ * @range [ - 0xFF, 0o0 ]
43
+ * @precision 0b10
44
+ * @step 1e-2
45
+ */
46
+ f;
47
+
48
+ /**
49
+ * @attribute
50
+ * @type {number}
51
+ * @range [1]
52
+ */
53
+ g;
54
+
55
+ /**
56
+ * @attribute
57
+ * @type {number}
58
+ * @range []
59
+ */
60
+ h;
61
+ }
62
+
63
+ export { Example };