crankscript 0.9.8 → 0.9.10
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 +46 -1
- package/assets/plugin.ts +53 -0
- package/package.json +1 -1
- package/src/constants.d.ts +0 -1
- package/src/constants.js +0 -1
- package/src/constants.js.map +1 -1
package/assets/plugin.js
CHANGED
@@ -34,6 +34,25 @@ var call_1 = require("typescript-to-lua/dist/transformation/visitors/call");
|
|
34
34
|
var fields_1 = require("typescript-to-lua/dist/transformation/visitors/class/members/fields");
|
35
35
|
var utils_1 = require("typescript-to-lua/dist/transformation/visitors/class/utils");
|
36
36
|
var function_1 = require("typescript-to-lua/dist/transformation/visitors/function");
|
37
|
+
var importMap = {
|
38
|
+
graphics: new Set(['graphics']),
|
39
|
+
sprites: new Set(['sprite']),
|
40
|
+
crank: new Set(['getCrankTicks']),
|
41
|
+
object: new Set(['printTable']),
|
42
|
+
'utilities/where': new Set(['where']),
|
43
|
+
easing: new Set(['easingFunctions']),
|
44
|
+
nineSlice: new Set(['nineSlice']),
|
45
|
+
qrcode: new Set(['generateQRCode']),
|
46
|
+
animation: new Set(['animation']),
|
47
|
+
animator: new Set(['animator']),
|
48
|
+
keyboard: new Set(['keyboard']),
|
49
|
+
math: new Set(['math']),
|
50
|
+
string: new Set(['string']),
|
51
|
+
timer: new Set(['timer']),
|
52
|
+
frameTimer: new Set(['frameTimer']),
|
53
|
+
ui: new Set(['ui']),
|
54
|
+
};
|
55
|
+
var imports = new Set();
|
37
56
|
function createClassCall(context, className, extendsNode) {
|
38
57
|
// class('X')
|
39
58
|
var classCall = tstl.createCallExpression(tstl.createIdentifier('class'), [tstl.createStringLiteral(className.text)]);
|
@@ -101,6 +120,7 @@ function transformMethodDeclaration(context, node, className) {
|
|
101
120
|
return tstl.createAssignmentStatement(tstl.createTableIndexExpression(className, transformPropertyName(context, node.name)), functionExpression);
|
102
121
|
}
|
103
122
|
var transformClassDeclaration = function (declaration, context) {
|
123
|
+
imports.add('object');
|
104
124
|
var className;
|
105
125
|
if (declaration.name) {
|
106
126
|
className = tstl.createIdentifier(declaration.name.text);
|
@@ -181,15 +201,40 @@ var transformSuperExpression = function (expression, context) {
|
|
181
201
|
return lua.createTableIndexExpression(className, lua.createStringLiteral('super'));
|
182
202
|
};
|
183
203
|
exports.transformSuperExpression = transformSuperExpression;
|
204
|
+
var processName = function (name) {
|
205
|
+
for (var _i = 0, _a = Object.entries(importMap); _i < _a.length; _i++) {
|
206
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
207
|
+
if (value instanceof Set && value.has(name)) {
|
208
|
+
imports.add(key);
|
209
|
+
}
|
210
|
+
}
|
211
|
+
};
|
184
212
|
var plugin = {
|
213
|
+
beforeEmit: function (_, __, ___, result) {
|
214
|
+
var importsString = Array.from(imports)
|
215
|
+
.map(function (importString) { return "import \"CoreLibs/".concat(importString, "\""); })
|
216
|
+
.join('\n');
|
217
|
+
if (importsString.trim() === '') {
|
218
|
+
return;
|
219
|
+
}
|
220
|
+
result[0].code = "-- These imports were added automatically\n\n".concat(importsString, "\n\n-- End of automatic imports\n\n").concat(result[0].code);
|
221
|
+
},
|
185
222
|
visitors: (_a = {},
|
186
223
|
_a[ts.SyntaxKind.ClassDeclaration] = exports.transformClassDeclaration,
|
187
224
|
_a[ts.SyntaxKind.SuperKeyword] = exports.transformSuperExpression,
|
188
225
|
_a[ts.SyntaxKind.NewExpression] = transformNewExpression,
|
226
|
+
_a[ts.SyntaxKind.PropertyAccessExpression] = function (node, context) {
|
227
|
+
if (ts.isIdentifier(node.expression)) {
|
228
|
+
processName(node.name.text);
|
229
|
+
}
|
230
|
+
return context.superTransformExpression(node);
|
231
|
+
},
|
189
232
|
_a[ts.SyntaxKind.CallExpression] = function (node, context) {
|
233
|
+
if (ts.isIdentifier(node.expression)) {
|
234
|
+
processName(node.expression.escapedText.toString());
|
235
|
+
}
|
190
236
|
if (ts.isIdentifier(node.expression) &&
|
191
237
|
node.expression.escapedText === 'require') {
|
192
|
-
console.log(1);
|
193
238
|
var normalNode = context.superTransformExpression(node);
|
194
239
|
normalNode.expression.text = 'import';
|
195
240
|
normalNode.expression.originalName = 'import';
|
package/assets/plugin.ts
CHANGED
@@ -15,6 +15,27 @@ import {
|
|
15
15
|
transformParameters,
|
16
16
|
} from 'typescript-to-lua/dist/transformation/visitors/function';
|
17
17
|
|
18
|
+
const importMap = {
|
19
|
+
graphics: new Set(['graphics']),
|
20
|
+
sprites: new Set(['sprite']),
|
21
|
+
crank: new Set(['getCrankTicks']),
|
22
|
+
object: new Set(['printTable']),
|
23
|
+
'utilities/where': new Set(['where']),
|
24
|
+
easing: new Set(['easingFunctions']),
|
25
|
+
nineSlice: new Set(['nineSlice']),
|
26
|
+
qrcode: new Set(['generateQRCode']),
|
27
|
+
animation: new Set(['animation']),
|
28
|
+
animator: new Set(['animator']),
|
29
|
+
keyboard: new Set(['keyboard']),
|
30
|
+
math: new Set(['math']),
|
31
|
+
string: new Set(['string']),
|
32
|
+
timer: new Set(['timer']),
|
33
|
+
frameTimer: new Set(['frameTimer']),
|
34
|
+
ui: new Set(['ui']),
|
35
|
+
};
|
36
|
+
|
37
|
+
const imports = new Set<string>();
|
38
|
+
|
18
39
|
function createClassCall(
|
19
40
|
context: tstl.TransformationContext,
|
20
41
|
className: tstl.Identifier,
|
@@ -154,6 +175,8 @@ export const transformClassDeclaration: FunctionVisitor<
|
|
154
175
|
declaration,
|
155
176
|
context: TransformationContext & { classSuperInfos?: [ClassSuperInfo] }
|
156
177
|
) => {
|
178
|
+
imports.add('object');
|
179
|
+
|
157
180
|
let className: tstl.Identifier;
|
158
181
|
if (declaration.name) {
|
159
182
|
className = tstl.createIdentifier(declaration.name.text);
|
@@ -266,12 +289,42 @@ export const transformSuperExpression: FunctionVisitor<ts.SuperExpression> = (
|
|
266
289
|
);
|
267
290
|
};
|
268
291
|
|
292
|
+
const processName = (name: string) => {
|
293
|
+
for (const [key, value] of Object.entries(importMap)) {
|
294
|
+
if (value instanceof Set && value.has(name)) {
|
295
|
+
imports.add(key);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
};
|
299
|
+
|
269
300
|
const plugin = {
|
301
|
+
beforeEmit: (_, __, ___, result) => {
|
302
|
+
const importsString = Array.from(imports)
|
303
|
+
.map((importString) => `import "CoreLibs/${importString}"`)
|
304
|
+
.join('\n');
|
305
|
+
|
306
|
+
if (importsString.trim() === '') {
|
307
|
+
return;
|
308
|
+
}
|
309
|
+
|
310
|
+
result[0].code = `-- These imports were added automatically\n\n${importsString}\n\n-- End of automatic imports\n\n${result[0].code}`;
|
311
|
+
},
|
270
312
|
visitors: {
|
271
313
|
[ts.SyntaxKind.ClassDeclaration]: transformClassDeclaration,
|
272
314
|
[ts.SyntaxKind.SuperKeyword]: transformSuperExpression,
|
273
315
|
[ts.SyntaxKind.NewExpression]: transformNewExpression,
|
316
|
+
[ts.SyntaxKind.PropertyAccessExpression]: (node, context) => {
|
317
|
+
if (ts.isIdentifier(node.expression)) {
|
318
|
+
processName(node.name.text);
|
319
|
+
}
|
320
|
+
|
321
|
+
return context.superTransformExpression(node);
|
322
|
+
},
|
274
323
|
[ts.SyntaxKind.CallExpression]: (node, context) => {
|
324
|
+
if (ts.isIdentifier(node.expression)) {
|
325
|
+
processName(node.expression.escapedText.toString());
|
326
|
+
}
|
327
|
+
|
275
328
|
if (
|
276
329
|
ts.isIdentifier(node.expression) &&
|
277
330
|
node.expression.escapedText === 'require'
|
package/package.json
CHANGED
package/src/constants.d.ts
CHANGED
package/src/constants.js
CHANGED
package/src/constants.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../libs/cli/src/constants.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { __dirname } from './utils/dirname.js';\n\nexport const
|
1
|
+
{"version":3,"sources":["../../../../libs/cli/src/constants.ts"],"sourcesContent":["import { join } from 'node:path';\nimport { __dirname } from './utils/dirname.js';\n\nexport const TypescriptReservedNamed = ['delete', 'new', 'function'];\nexport const RootFolder = join(__dirname, '..', '..');\nexport const DataFolder = join(RootFolder, 'src', 'data');\n"],"names":["join","__dirname","TypescriptReservedNamed","RootFolder","DataFolder"],"rangeMappings":";;;;;;;;","mappings":"AAAA,SAASA,IAAI,QAAQ,YAAY;AACjC,SAASC,SAAS,QAAQ,qBAAqB;AAE/C,OAAO,MAAMC,0BAA0B;IAAC;IAAU;IAAO;CAAW,CAAC;AACrE,OAAO,MAAMC,aAAaH,KAAKC,WAAW,MAAM,MAAM;AACtD,OAAO,MAAMG,aAAaJ,KAAKG,YAAY,OAAO,QAAQ"}
|