porffor 0.48.0 → 0.48.2

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.
@@ -1608,6 +1608,10 @@ const getNodeType = (scope, node) => {
1608
1608
  }
1609
1609
  }
1610
1610
 
1611
+ if (node.type === 'SequenceExpression') {
1612
+ return getNodeType(scope, node.expressions.at(-1));
1613
+ }
1614
+
1611
1615
  return getLastType(scope);
1612
1616
  })();
1613
1617
 
@@ -2961,6 +2965,19 @@ const setLocalWithType = (scope, name, isGlobal, decl, tee = false, overrideType
2961
2965
  return out;
2962
2966
  };
2963
2967
 
2968
+ const setDefaultFuncName = (decl, name) => {
2969
+ if (decl.id) return;
2970
+
2971
+ if (decl.type === 'ClassExpression') {
2972
+ // check if it has a name definition
2973
+ for (const x of decl.body.body) {
2974
+ if (x.key.name === 'name') return;
2975
+ }
2976
+ }
2977
+
2978
+ decl.id = { name };
2979
+ };
2980
+
2964
2981
  const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
2965
2982
  // statically analyzed ffi dlopen hack to let 2c handle it
2966
2983
  if (init && init.type === 'CallExpression' && init.callee.name === '__Porffor_dlopen') {
@@ -3029,7 +3046,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3029
3046
  if (init && isFuncType(init.type)) {
3030
3047
  // hack for let a = function () { ... }
3031
3048
  if (!init.id) {
3032
- init.id = { name };
3049
+ setDefaultFuncName(init, name);
3033
3050
  generateFunc(scope, init, true);
3034
3051
  return out;
3035
3052
  }
@@ -3037,7 +3054,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3037
3054
 
3038
3055
  if (defaultValue && isFuncType(defaultValue.type)) {
3039
3056
  // set id as name, but do not use it as it is only default value
3040
- if (!defaultValue.id) defaultValue.id = { name };
3057
+ setDefaultFuncName(defaultValue, name);
3041
3058
  }
3042
3059
 
3043
3060
  if (topLevel && Object.hasOwn(builtinVars, name)) {
@@ -3165,7 +3182,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
3165
3182
  out = out.concat([
3166
3183
  // check tmp is iterable
3167
3184
  // array or string or bytestring
3168
- ...typeIsOneOf(getType(scope, tmpName), [ TYPES.array, TYPES.string, TYPES.bytestring ]),
3185
+ ...typeIsOneOf(getType(scope, tmpName), [ TYPES.array, TYPES.string, TYPES.bytestring, TYPES.__porffor_generator ]),
3169
3186
  // typed array
3170
3187
  ...getType(scope, tmpName),
3171
3188
  ...number(TYPES.uint8array, Valtype.i32),
@@ -4103,7 +4120,7 @@ const generateForOf = (scope, decl) => {
4103
4120
 
4104
4121
  // check tmp is iterable
4105
4122
  // array or string or bytestring
4106
- ...typeIsOneOf(iterType, [ TYPES.array, TYPES.set, TYPES.string, TYPES.bytestring ]),
4123
+ ...typeIsOneOf(iterType, [ TYPES.array, TYPES.set, TYPES.string, TYPES.bytestring, TYPES.__porffor_generator ]),
4107
4124
  // typed array
4108
4125
  ...iterType,
4109
4126
  ...number(TYPES.uint8array, Valtype.i32),
@@ -4443,6 +4460,8 @@ const generateForOf = (scope, decl) => {
4443
4460
  ]
4444
4461
  }),
4445
4462
 
4463
+ [TYPES.__porffor_generator]: () => [],
4464
+
4446
4465
  // note: should be impossible to reach?
4447
4466
  default: internalThrow(scope, 'TypeError', `Tried for..of on non-iterable type`)
4448
4467
  }, Blocktype.void));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.48.0",
4
+ "version": "0.48.2",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.48.0';
3
+ globalThis.version = '0.48.2';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {