porffor 0.55.2 → 0.55.3
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/.fails.cjs +1 -0
- package/compiler/builtins/_internal_object.ts +1 -0
- package/compiler/builtins/generator.ts +18 -2
- package/compiler/builtins_precompiled.js +372 -360
- package/compiler/codegen.js +27 -16
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -567,13 +567,8 @@ const generateReturn = (scope, decl) => {
|
|
567
567
|
...generate(scope, arg),
|
568
568
|
...getNodeType(scope, arg),
|
569
569
|
|
570
|
-
[ Opcodes.call, includeBuiltin(scope, scope.async ? '
|
571
|
-
|
572
|
-
[ Opcodes.drop ],
|
573
|
-
|
574
|
-
// return generator
|
575
|
-
[ Opcodes.local_get, scope.locals['#generator_out'].idx ],
|
576
|
-
number(scope.async ? TYPES.__porffor_asyncgenerator : TYPES.__porffor_generator, Valtype.i32),
|
570
|
+
[ Opcodes.call, includeBuiltin(scope, scope.async ? '__Porffor_AsyncGenerator_return' : '__Porffor_Generator_return').index ],
|
571
|
+
// returns generator
|
577
572
|
[ Opcodes.return ]
|
578
573
|
];
|
579
574
|
}
|
@@ -1709,6 +1704,7 @@ const getNodeType = (scope, node) => {
|
|
1709
1704
|
}
|
1710
1705
|
|
1711
1706
|
if (node.type === 'ThisExpression') {
|
1707
|
+
if (scope.overrideThisType) return scope.overrideThisType;
|
1712
1708
|
if (!scope.constr) return getType(scope, 'globalThis');
|
1713
1709
|
return [ [ Opcodes.local_get, scope.locals['#this#type'].idx ] ];
|
1714
1710
|
}
|
@@ -2717,18 +2713,18 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2717
2713
|
};
|
2718
2714
|
|
2719
2715
|
const generateThis = (scope, decl) => {
|
2716
|
+
if (scope.overrideThis) return scope.overrideThis;
|
2717
|
+
|
2720
2718
|
if (!scope.constr) {
|
2721
2719
|
// this in a non-constructor context is a reference to globalThis
|
2722
2720
|
return [
|
2723
|
-
...generate(scope, { type: 'Identifier', name: 'globalThis' })
|
2724
|
-
...setLastType(scope, getType(scope, 'globalThis'))
|
2721
|
+
...generate(scope, { type: 'Identifier', name: 'globalThis' })
|
2725
2722
|
];
|
2726
2723
|
}
|
2727
2724
|
|
2728
2725
|
// opt: do not check for pure constructors or strict mode
|
2729
2726
|
if ((!globalThis.precompile && scope.strict) || scope._onlyConstr || scope._onlyThisMethod || decl._noGlobalThis) return [
|
2730
|
-
[ Opcodes.local_get, scope.locals['#this'].idx ]
|
2731
|
-
...setLastType(scope, [ [ Opcodes.local_get, scope.locals['#this#type'].idx ] ])
|
2727
|
+
[ Opcodes.local_get, scope.locals['#this'].idx ]
|
2732
2728
|
];
|
2733
2729
|
|
2734
2730
|
return [
|
@@ -2749,8 +2745,7 @@ const generateThis = (scope, decl) => {
|
|
2749
2745
|
];
|
2750
2746
|
}, 0 ],
|
2751
2747
|
|
2752
|
-
[ Opcodes.local_get, scope.locals['#this'].idx ]
|
2753
|
-
...setLastType(scope, [ [ Opcodes.local_get, scope.locals['#this#type'].idx ] ])
|
2748
|
+
[ Opcodes.local_get, scope.locals['#this'].idx ]
|
2754
2749
|
];
|
2755
2750
|
};
|
2756
2751
|
|
@@ -6190,12 +6185,25 @@ const generateClass = (scope, decl) => {
|
|
6190
6185
|
);
|
6191
6186
|
}
|
6192
6187
|
|
6188
|
+
scope.overrideThis = generate(scope, root);
|
6189
|
+
scope.overrideThisType = TYPES.function;
|
6190
|
+
|
6193
6191
|
for (const x of body) {
|
6194
6192
|
let { type, key, value, kind, static: _static, computed } = x;
|
6195
|
-
if (type !== 'MethodDefinition' && type !== 'PropertyDefinition') return todo(scope, `class body type ${type} is not supported yet`, true);
|
6196
|
-
|
6197
6193
|
if (kind === 'constructor') continue;
|
6198
6194
|
|
6195
|
+
if (type === 'StaticBlock') {
|
6196
|
+
// todo: make this more compliant
|
6197
|
+
out.push(
|
6198
|
+
...generate(scope, {
|
6199
|
+
type: 'BlockStatement',
|
6200
|
+
body: x.body
|
6201
|
+
}),
|
6202
|
+
[ Opcodes.drop ]
|
6203
|
+
);
|
6204
|
+
continue;
|
6205
|
+
}
|
6206
|
+
|
6199
6207
|
let object = _static ? root : proto;
|
6200
6208
|
|
6201
6209
|
const k = getProperty(x, true);
|
@@ -6253,6 +6261,9 @@ const generateClass = (scope, decl) => {
|
|
6253
6261
|
);
|
6254
6262
|
}
|
6255
6263
|
|
6264
|
+
delete scope.overrideThis;
|
6265
|
+
delete scope.overrideThisType;
|
6266
|
+
|
6256
6267
|
// error if not being constructed
|
6257
6268
|
func.wasm.unshift(
|
6258
6269
|
[ Opcodes.local_get, func.locals['#newtarget'].idx ],
|
@@ -6537,7 +6548,7 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
|
|
6537
6548
|
addVarMetadata(func, name, false, typeAnno);
|
6538
6549
|
|
6539
6550
|
// automatically add throws if unexpected this type to builtins
|
6540
|
-
if (globalThis.precompile && i === 0 && func.name.includes('_prototype_')) {
|
6551
|
+
if (globalThis.precompile && i === 0 && func.name.includes('_prototype_') && !func.name.startsWith('__Porffor_')) {
|
6541
6552
|
if (typeAnno.type === TYPES.array) {
|
6542
6553
|
// Array.from
|
6543
6554
|
wasm.push(
|
package/package.json
CHANGED