porffor 0.58.7 → 0.58.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.
@@ -405,6 +405,9 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
405
405
  if (Prefs.d) log.warning('codegen', 'with is not supported, treating as expression');
406
406
  return cacheAst(decl, generate(scope, decl.body));
407
407
 
408
+ case 'TSEnumDeclaration':
409
+ return cacheAst(decl, generateEnum(scope, decl));
410
+
408
411
  default:
409
412
  // ignore typescript nodes
410
413
  if (decl.type.startsWith('TS') ||
@@ -416,6 +419,61 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
416
419
  }
417
420
  };
418
421
 
422
+ const generateEnum = (scope, decl) => {
423
+ // todo: opt const enum into compile-time values
424
+
425
+ if (decl.body) decl = decl.body; // non-standard ast node :)
426
+
427
+ const properties = [];
428
+
429
+ let value = -1;
430
+ for (const x of decl.members) {
431
+ if (x.initializer) {
432
+ value = x.initializer;
433
+ } else {
434
+ if (typeof value === 'number') {
435
+ value = {
436
+ type: 'Literal',
437
+ value: value + 1
438
+ };
439
+ } else {
440
+ value = {
441
+ type: 'Identifier',
442
+ value: undefined
443
+ };
444
+ }
445
+ }
446
+
447
+ // enum.key = value
448
+ properties.push({
449
+ key: x.id,
450
+ value,
451
+ kind: 'init'
452
+ });
453
+
454
+ // enum[value] = key
455
+ properties.push({
456
+ key: value,
457
+ value: {
458
+ type: 'Literal',
459
+ value: x.id.name
460
+ },
461
+ computed: true,
462
+ kind: 'init'
463
+ });
464
+
465
+ value = value?.value;
466
+ }
467
+
468
+ return [
469
+ ...generateVarDstr(scope, decl.const ? 'const' : 'let', decl.id, {
470
+ type: 'ObjectExpression',
471
+ properties
472
+ }),
473
+ number(UNDEFINED)
474
+ ];
475
+ };
476
+
419
477
  const optional = (op, clause = op.at(-1)) => clause || clause === 0 ? (Array.isArray(op[0]) ? op : [ op ]) : [];
420
478
 
421
479
  const lookupName = (scope, name) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "An ahead-of-time JavaScript compiler",
4
- "version": "0.58.7",
4
+ "version": "0.58.9",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runtime/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.58.7';
3
+ globalThis.version = '0.58.9';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
package/foo.js DELETED
@@ -1,5 +0,0 @@
1
- var result = /1/; // eval('{}/1/;');
2
-
3
- console.log(Object.getPrototypeOf(result) === RegExp.prototype);
4
- console.log(result.flags);
5
- console.log(result.toString());