nesquick 2.2.0 → 2.2.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/lib/NesquickComponent.js +20 -17
- package/lib/cli/transformer.js +7 -5
- package/lib/types/util.d.ts +1 -0
- package/lib/util.js +6 -0
- package/package.json +1 -1
package/lib/NesquickComponent.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NesquickComponent = void 0;
|
|
4
4
|
const State_1 = require("./State");
|
|
5
|
+
const util_1 = require("./util");
|
|
5
6
|
const SVGNamespaces = new Map([
|
|
6
7
|
["xlink", "http://www.w3.org/1999/xlink"],
|
|
7
8
|
["xml", "http://www.w3.org/XML/1998/namespace"]
|
|
@@ -166,23 +167,23 @@ class NesquickComponent {
|
|
|
166
167
|
this._renderStyle(element, props[k]);
|
|
167
168
|
}
|
|
168
169
|
else if (typeof props[k] === "function") {
|
|
169
|
-
|
|
170
|
-
|
|
170
|
+
const attribute = getAttributeNs(attributes, k);
|
|
171
|
+
if (attribute) {
|
|
172
|
+
(0, State_1.useRender)(props[k], v => {
|
|
173
|
+
element.setAttributeNS(attribute.namespace, attribute.name, String(v));
|
|
174
|
+
this._onUpdated();
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
else if ((0, util_1.isEvent)(k)) {
|
|
178
|
+
(0, State_1.useRender)(props[k], v => {
|
|
179
|
+
element[k.toLowerCase()] = v;
|
|
180
|
+
});
|
|
171
181
|
}
|
|
172
182
|
else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
(
|
|
176
|
-
|
|
177
|
-
this._onUpdated();
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
(0, State_1.useRender)(props[k], v => {
|
|
182
|
-
element.setAttribute(k, String(v));
|
|
183
|
-
this._onUpdated();
|
|
184
|
-
});
|
|
185
|
-
}
|
|
183
|
+
(0, State_1.useRender)(props[k], v => {
|
|
184
|
+
element.setAttribute(k, String(v));
|
|
185
|
+
this._onUpdated();
|
|
186
|
+
});
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
189
|
else {
|
|
@@ -205,8 +206,10 @@ class NesquickComponent {
|
|
|
205
206
|
this._renderStyle(element, props[k]);
|
|
206
207
|
}
|
|
207
208
|
else if (typeof props[k] === "function") {
|
|
208
|
-
if (
|
|
209
|
-
|
|
209
|
+
if ((0, util_1.isEvent)(k)) {
|
|
210
|
+
(0, State_1.useRender)(props[k], v => {
|
|
211
|
+
element[k.toLowerCase()] = v;
|
|
212
|
+
});
|
|
210
213
|
}
|
|
211
214
|
else {
|
|
212
215
|
(0, State_1.useRender)(props[k], v => {
|
package/lib/cli/transformer.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transformer = void 0;
|
|
4
4
|
const TS = require("typescript");
|
|
5
|
+
const util_1 = require("../util");
|
|
5
6
|
function getSingleIdentifier(node) {
|
|
6
7
|
let identifier = null;
|
|
7
8
|
node.forEachChild(node => {
|
|
@@ -87,8 +88,9 @@ const transformer = context => {
|
|
|
87
88
|
node = res.node;
|
|
88
89
|
}
|
|
89
90
|
else if (TS.isJsxAttribute(node)) {
|
|
91
|
+
const propIsEvent = TS.isIdentifier(node.name) && (0, util_1.isEvent)(node.name.text);
|
|
90
92
|
node = TS.visitEachChild(node, node => {
|
|
91
|
-
const res = visitGeneric(node, { ...options, isJsxAttribute: true });
|
|
93
|
+
const res = visitGeneric(node, { ...options, isJsxAttribute: true, isEvent: propIsEvent });
|
|
92
94
|
hasCallExpression = hasCallExpression || res.hasCallExpression;
|
|
93
95
|
return res.node;
|
|
94
96
|
}, context);
|
|
@@ -97,7 +99,7 @@ const transformer = context => {
|
|
|
97
99
|
node = TS.visitEachChild(node, node => visitorExpression(node, { ...options, isJsxAttribute: false }), context);
|
|
98
100
|
}
|
|
99
101
|
else if (options.isJsxAttribute && TS.isStringLiteral(node)) {
|
|
100
|
-
const returnNode = TS.visitNode(node, node => visitorExpression(node, { ...options, isJsxAttribute: false }), TS.isExpression);
|
|
102
|
+
const returnNode = TS.visitNode(node, node => visitorExpression(node, { ...options, isJsxAttribute: false, isEvent: false }), TS.isExpression);
|
|
101
103
|
if (TS.isStringLiteral(returnNode)) {
|
|
102
104
|
node = returnNode;
|
|
103
105
|
}
|
|
@@ -107,13 +109,13 @@ const transformer = context => {
|
|
|
107
109
|
}
|
|
108
110
|
else if (TS.isFunctionLike(node)) {
|
|
109
111
|
node = TS.visitEachChild(node, node => {
|
|
110
|
-
const res = visitGeneric(node, { ...options, isJsxAttribute: false });
|
|
112
|
+
const res = visitGeneric(node, { ...options, isJsxAttribute: false, isEvent: false });
|
|
111
113
|
return res.node;
|
|
112
114
|
}, context);
|
|
113
115
|
}
|
|
114
116
|
else {
|
|
115
117
|
node = TS.visitEachChild(node, node => {
|
|
116
|
-
const res = visitGeneric(node, { ...options, isJsxAttribute: false });
|
|
118
|
+
const res = visitGeneric(node, { ...options, isJsxAttribute: false, isEvent: false });
|
|
117
119
|
hasCallExpression = hasCallExpression || res.hasCallExpression;
|
|
118
120
|
return res.node;
|
|
119
121
|
}, context);
|
|
@@ -138,7 +140,7 @@ const transformer = context => {
|
|
|
138
140
|
}
|
|
139
141
|
const res = visitGeneric(node, {});
|
|
140
142
|
node = res.node;
|
|
141
|
-
if (TS.isConciseBody(node) && (options.userComponent || res.hasCallExpression)) {
|
|
143
|
+
if (TS.isConciseBody(node) && (options.userComponent || res.hasCallExpression || options.isEvent)) {
|
|
142
144
|
node = arrowify(node);
|
|
143
145
|
}
|
|
144
146
|
return node;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isEvent(name: string): boolean;
|
package/lib/util.js
ADDED