porffor 0.48.0 → 0.48.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/compiler/codegen.js +19 -4
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -2961,6 +2961,19 @@ const setLocalWithType = (scope, name, isGlobal, decl, tee = false, overrideType
|
|
2961
2961
|
return out;
|
2962
2962
|
};
|
2963
2963
|
|
2964
|
+
const setDefaultFuncName = (decl, name) => {
|
2965
|
+
if (decl.id) return;
|
2966
|
+
|
2967
|
+
if (decl.type === 'ClassExpression') {
|
2968
|
+
// check if it has a name definition
|
2969
|
+
for (const x of decl.body.body) {
|
2970
|
+
if (x.key.name === 'name') return;
|
2971
|
+
}
|
2972
|
+
}
|
2973
|
+
|
2974
|
+
decl.id = { name };
|
2975
|
+
};
|
2976
|
+
|
2964
2977
|
const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
2965
2978
|
// statically analyzed ffi dlopen hack to let 2c handle it
|
2966
2979
|
if (init && init.type === 'CallExpression' && init.callee.name === '__Porffor_dlopen') {
|
@@ -3029,7 +3042,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3029
3042
|
if (init && isFuncType(init.type)) {
|
3030
3043
|
// hack for let a = function () { ... }
|
3031
3044
|
if (!init.id) {
|
3032
|
-
init
|
3045
|
+
setDefaultFuncName(init, name);
|
3033
3046
|
generateFunc(scope, init, true);
|
3034
3047
|
return out;
|
3035
3048
|
}
|
@@ -3037,7 +3050,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3037
3050
|
|
3038
3051
|
if (defaultValue && isFuncType(defaultValue.type)) {
|
3039
3052
|
// set id as name, but do not use it as it is only default value
|
3040
|
-
if (!defaultValue.id) defaultValue
|
3053
|
+
if (!defaultValue.id) setDefaultFuncName(defaultValue, name);
|
3041
3054
|
}
|
3042
3055
|
|
3043
3056
|
if (topLevel && Object.hasOwn(builtinVars, name)) {
|
@@ -3165,7 +3178,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3165
3178
|
out = out.concat([
|
3166
3179
|
// check tmp is iterable
|
3167
3180
|
// array or string or bytestring
|
3168
|
-
...typeIsOneOf(getType(scope, tmpName), [ TYPES.array, TYPES.string, TYPES.bytestring ]),
|
3181
|
+
...typeIsOneOf(getType(scope, tmpName), [ TYPES.array, TYPES.string, TYPES.bytestring, TYPES.__porffor_generator ]),
|
3169
3182
|
// typed array
|
3170
3183
|
...getType(scope, tmpName),
|
3171
3184
|
...number(TYPES.uint8array, Valtype.i32),
|
@@ -4103,7 +4116,7 @@ const generateForOf = (scope, decl) => {
|
|
4103
4116
|
|
4104
4117
|
// check tmp is iterable
|
4105
4118
|
// array or string or bytestring
|
4106
|
-
...typeIsOneOf(iterType, [ TYPES.array, TYPES.set, TYPES.string, TYPES.bytestring ]),
|
4119
|
+
...typeIsOneOf(iterType, [ TYPES.array, TYPES.set, TYPES.string, TYPES.bytestring, TYPES.__porffor_generator ]),
|
4107
4120
|
// typed array
|
4108
4121
|
...iterType,
|
4109
4122
|
...number(TYPES.uint8array, Valtype.i32),
|
@@ -4443,6 +4456,8 @@ const generateForOf = (scope, decl) => {
|
|
4443
4456
|
]
|
4444
4457
|
}),
|
4445
4458
|
|
4459
|
+
[TYPES.__porffor_generator]: () => [],
|
4460
|
+
|
4446
4461
|
// note: should be impossible to reach?
|
4447
4462
|
default: internalThrow(scope, 'TypeError', `Tried for..of on non-iterable type`)
|
4448
4463
|
}, Blocktype.void));
|
package/package.json
CHANGED