crankscript 0.9.8 → 0.9.9
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/assets/plugin.js +45 -1
- package/assets/plugin.ts +51 -0
- package/package.json +1 -1
package/assets/plugin.js
CHANGED
@@ -181,15 +181,59 @@ var transformSuperExpression = function (expression, context) {
|
|
181
181
|
return lua.createTableIndexExpression(className, lua.createStringLiteral('super'));
|
182
182
|
};
|
183
183
|
exports.transformSuperExpression = transformSuperExpression;
|
184
|
+
var importMap = {
|
185
|
+
graphics: new Set(['graphics']),
|
186
|
+
sprites: new Set(['sprite']),
|
187
|
+
crank: new Set(['getCrankTicks']),
|
188
|
+
object: new Set(['printTable']),
|
189
|
+
'utilities/where': new Set(['where']),
|
190
|
+
easing: new Set(['easingFunctions']),
|
191
|
+
nineSlice: new Set(['nineSlice']),
|
192
|
+
qrcode: new Set(['generateQRCode']),
|
193
|
+
animation: new Set(['animation']),
|
194
|
+
animator: new Set(['animator']),
|
195
|
+
keyboard: new Set(['keyboard']),
|
196
|
+
math: new Set(['math']),
|
197
|
+
string: new Set(['string']),
|
198
|
+
timer: new Set(['timer']),
|
199
|
+
frameTimer: new Set(['frameTimer']),
|
200
|
+
ui: new Set(['ui']),
|
201
|
+
};
|
202
|
+
var imports = new Set();
|
203
|
+
var processFunction = function (name) {
|
204
|
+
for (var _i = 0, _a = Object.entries(importMap); _i < _a.length; _i++) {
|
205
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
206
|
+
if (value instanceof Set && value.has(name)) {
|
207
|
+
imports.add(key);
|
208
|
+
}
|
209
|
+
}
|
210
|
+
};
|
184
211
|
var plugin = {
|
212
|
+
beforeEmit: function (_, __, ___, result) {
|
213
|
+
var importsString = Array.from(imports)
|
214
|
+
.map(function (importString) { return "import \"CoreLibs/".concat(importString, "\""); })
|
215
|
+
.join('\n');
|
216
|
+
if (importsString.trim() === '') {
|
217
|
+
return;
|
218
|
+
}
|
219
|
+
result[0].code = "-- These imports were added automatically\n\n".concat(importsString, "\n\n-- End of automatic imports\n\n").concat(result[0].code);
|
220
|
+
},
|
185
221
|
visitors: (_a = {},
|
186
222
|
_a[ts.SyntaxKind.ClassDeclaration] = exports.transformClassDeclaration,
|
187
223
|
_a[ts.SyntaxKind.SuperKeyword] = exports.transformSuperExpression,
|
188
224
|
_a[ts.SyntaxKind.NewExpression] = transformNewExpression,
|
225
|
+
_a[ts.SyntaxKind.PropertyAccessExpression] = function (node, context) {
|
226
|
+
if (ts.isIdentifier(node.expression)) {
|
227
|
+
processFunction(node.name.text);
|
228
|
+
}
|
229
|
+
return context.superTransformExpression(node);
|
230
|
+
},
|
189
231
|
_a[ts.SyntaxKind.CallExpression] = function (node, context) {
|
232
|
+
if (ts.isIdentifier(node.expression)) {
|
233
|
+
processFunction(node.expression.escapedText.toString());
|
234
|
+
}
|
190
235
|
if (ts.isIdentifier(node.expression) &&
|
191
236
|
node.expression.escapedText === 'require') {
|
192
|
-
console.log(1);
|
193
237
|
var normalNode = context.superTransformExpression(node);
|
194
238
|
normalNode.expression.text = 'import';
|
195
239
|
normalNode.expression.originalName = 'import';
|
package/assets/plugin.ts
CHANGED
@@ -266,12 +266,63 @@ export const transformSuperExpression: FunctionVisitor<ts.SuperExpression> = (
|
|
266
266
|
);
|
267
267
|
};
|
268
268
|
|
269
|
+
const importMap = {
|
270
|
+
graphics: new Set(['graphics']),
|
271
|
+
sprites: new Set(['sprite']),
|
272
|
+
crank: new Set(['getCrankTicks']),
|
273
|
+
object: new Set(['printTable']),
|
274
|
+
'utilities/where': new Set(['where']),
|
275
|
+
easing: new Set(['easingFunctions']),
|
276
|
+
nineSlice: new Set(['nineSlice']),
|
277
|
+
qrcode: new Set(['generateQRCode']),
|
278
|
+
animation: new Set(['animation']),
|
279
|
+
animator: new Set(['animator']),
|
280
|
+
keyboard: new Set(['keyboard']),
|
281
|
+
math: new Set(['math']),
|
282
|
+
string: new Set(['string']),
|
283
|
+
timer: new Set(['timer']),
|
284
|
+
frameTimer: new Set(['frameTimer']),
|
285
|
+
ui: new Set(['ui']),
|
286
|
+
};
|
287
|
+
|
288
|
+
const imports = new Set<string>();
|
289
|
+
|
290
|
+
const processFunction = (name: string) => {
|
291
|
+
for (const [key, value] of Object.entries(importMap)) {
|
292
|
+
if (value instanceof Set && value.has(name)) {
|
293
|
+
imports.add(key);
|
294
|
+
}
|
295
|
+
}
|
296
|
+
};
|
297
|
+
|
269
298
|
const plugin = {
|
299
|
+
beforeEmit: (_, __, ___, result) => {
|
300
|
+
const importsString = Array.from(imports)
|
301
|
+
.map((importString) => `import "CoreLibs/${importString}"`)
|
302
|
+
.join('\n');
|
303
|
+
|
304
|
+
if (importsString.trim() === '') {
|
305
|
+
return;
|
306
|
+
}
|
307
|
+
|
308
|
+
result[0].code = `-- These imports were added automatically\n\n${importsString}\n\n-- End of automatic imports\n\n${result[0].code}`;
|
309
|
+
},
|
270
310
|
visitors: {
|
271
311
|
[ts.SyntaxKind.ClassDeclaration]: transformClassDeclaration,
|
272
312
|
[ts.SyntaxKind.SuperKeyword]: transformSuperExpression,
|
273
313
|
[ts.SyntaxKind.NewExpression]: transformNewExpression,
|
314
|
+
[ts.SyntaxKind.PropertyAccessExpression]: (node, context) => {
|
315
|
+
if (ts.isIdentifier(node.expression)) {
|
316
|
+
processFunction(node.name.text);
|
317
|
+
}
|
318
|
+
|
319
|
+
return context.superTransformExpression(node);
|
320
|
+
},
|
274
321
|
[ts.SyntaxKind.CallExpression]: (node, context) => {
|
322
|
+
if (ts.isIdentifier(node.expression)) {
|
323
|
+
processFunction(node.expression.escapedText.toString());
|
324
|
+
}
|
325
|
+
|
275
326
|
if (
|
276
327
|
ts.isIdentifier(node.expression) &&
|
277
328
|
node.expression.escapedText === 'require'
|