@needle-tools/needle-component-compiler 3.0.3 → 3.0.4-9debd7d
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/dist/Compiler.d.ts +4 -0
- package/dist/Compiler.js +38 -0
- package/package.json +8 -10
package/dist/Compiler.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export declare class Compiler {
|
|
|
7
7
|
private visit;
|
|
8
8
|
private visitClassDeclaration;
|
|
9
9
|
private visitPropertyDeclaration;
|
|
10
|
+
private hasSerializableDecorator;
|
|
11
|
+
/** Track accessor names already emitted per class to avoid duplicates when both getter and setter have @serializable() */
|
|
12
|
+
private _emittedAccessors;
|
|
13
|
+
private visitAccessorDeclaration;
|
|
10
14
|
private visitMethodDeclaration;
|
|
11
15
|
private resolveParameters;
|
|
12
16
|
private debugLog;
|
package/dist/Compiler.js
CHANGED
|
@@ -6,6 +6,8 @@ var base_compiler_1 = require("./base-compiler");
|
|
|
6
6
|
/** Typescript Walker */
|
|
7
7
|
var Compiler = /** @class */ (function () {
|
|
8
8
|
function Compiler() {
|
|
9
|
+
/** Track accessor names already emitted per class to avoid duplicates when both getter and setter have @serializable() */
|
|
10
|
+
this._emittedAccessors = new Set();
|
|
9
11
|
}
|
|
10
12
|
Compiler.prototype.compile = function (writer, code, sourceFilePath) {
|
|
11
13
|
var file = "needle_compiled.ts";
|
|
@@ -74,6 +76,9 @@ var Compiler = /** @class */ (function () {
|
|
|
74
76
|
else if (ts.isMethodDeclaration(node)) {
|
|
75
77
|
this.visitMethodDeclaration(node, writer);
|
|
76
78
|
}
|
|
79
|
+
else if (ts.isGetAccessorDeclaration(node) || ts.isSetAccessorDeclaration(node)) {
|
|
80
|
+
this.visitAccessorDeclaration(node, writer);
|
|
81
|
+
}
|
|
77
82
|
else {
|
|
78
83
|
ts.forEachChild(node, function (node) {
|
|
79
84
|
_this.visit(filePath, node, writer);
|
|
@@ -103,6 +108,7 @@ var Compiler = /** @class */ (function () {
|
|
|
103
108
|
this.debugLog("CLASS SKIPPED", name);
|
|
104
109
|
return;
|
|
105
110
|
}
|
|
111
|
+
this._emittedAccessors.clear();
|
|
106
112
|
ts.forEachChild(node, function (node) {
|
|
107
113
|
_this.visit(filePath, node, writer);
|
|
108
114
|
});
|
|
@@ -133,6 +139,38 @@ var Compiler = /** @class */ (function () {
|
|
|
133
139
|
return; // cannot determine type — skip the field
|
|
134
140
|
writer.writeMember(visibility, name, isArray, type, initialValue, this.getComments(node));
|
|
135
141
|
};
|
|
142
|
+
Compiler.prototype.hasSerializableDecorator = function (node) {
|
|
143
|
+
var _a;
|
|
144
|
+
var decorators = node.decorators;
|
|
145
|
+
return (_a = decorators === null || decorators === void 0 ? void 0 : decorators.some(function (d) { return d.expression.getText().startsWith("serializable"); })) !== null && _a !== void 0 ? _a : false;
|
|
146
|
+
};
|
|
147
|
+
Compiler.prototype.visitAccessorDeclaration = function (node, writer) {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
// Only emit if the accessor has a @serializable() decorator
|
|
150
|
+
if (!this.hasSerializableDecorator(node))
|
|
151
|
+
return;
|
|
152
|
+
var name = node.name.getText();
|
|
153
|
+
// Deduplicate: if both getter and setter are decorated, only emit once
|
|
154
|
+
if (this._emittedAccessors.has(name))
|
|
155
|
+
return;
|
|
156
|
+
this._emittedAccessors.add(name);
|
|
157
|
+
var type;
|
|
158
|
+
var typeNode;
|
|
159
|
+
if (ts.isGetAccessorDeclaration(node)) {
|
|
160
|
+
typeNode = node.type;
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// Setter: get type from the first parameter
|
|
164
|
+
typeNode = (_b = (_a = node.parameters) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type;
|
|
165
|
+
}
|
|
166
|
+
type = this.resolveType(typeNode, writer);
|
|
167
|
+
this.debugLog("[COMPILER] ACCESSOR (serializable)", name, type);
|
|
168
|
+
if (!type)
|
|
169
|
+
return;
|
|
170
|
+
var isArray = typeNode ? this.isArrayType(typeNode) : false;
|
|
171
|
+
var visibility = this.getVisibility(node);
|
|
172
|
+
writer.writeMember(visibility, name, isArray, type, undefined, this.getComments(node));
|
|
173
|
+
};
|
|
136
174
|
Compiler.prototype.visitMethodDeclaration = function (node, writer) {
|
|
137
175
|
var _a;
|
|
138
176
|
var name = node.name.getText();
|
package/package.json
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/needle-component-compiler",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4-9debd7d",
|
|
4
4
|
"description": "Compile Editor components for Needle Engine for C# and Blender",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"bin":
|
|
7
|
-
"needle-component-compiler": "dist/cli.js"
|
|
8
|
-
},
|
|
6
|
+
"bin": "dist/cli.js",
|
|
9
7
|
"scripts": {
|
|
10
|
-
"tsc": "tsc",
|
|
8
|
+
"tsc": "tsc -p tsconfig.build.json",
|
|
11
9
|
"dev": "npm-watch compile",
|
|
12
|
-
"compile": "tsc",
|
|
10
|
+
"compile": "tsc -p tsconfig.build.json",
|
|
13
11
|
"prepublishOnly": "npm run compile",
|
|
14
12
|
"test": "npm run test:csharp && npm run test:blender",
|
|
15
13
|
"test:csharp": "mocha -r ts-node/register 'test/csharp/**/*.test.ts'",
|
|
@@ -28,7 +26,7 @@
|
|
|
28
26
|
},
|
|
29
27
|
"devDependencies": {
|
|
30
28
|
"@types/chai": "^4.3.3",
|
|
31
|
-
"@types/mocha": "^
|
|
29
|
+
"@types/mocha": "^10",
|
|
32
30
|
"@types/node": "^18.7.18",
|
|
33
31
|
"chai": "^4.3.6",
|
|
34
32
|
"mocha": "^10.0.0",
|
|
@@ -57,7 +55,7 @@
|
|
|
57
55
|
"url": "git+https://github.com/needle-tools/needle-tiny-component-compiler.git"
|
|
58
56
|
},
|
|
59
57
|
"publishConfig": {
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
"access": "public",
|
|
59
|
+
"registry": "https://registry.npmjs.org/"
|
|
62
60
|
}
|
|
63
|
-
}
|
|
61
|
+
}
|