porffor 0.34.21 → 0.35.0
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 +20 -44
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -1066,9 +1066,6 @@ const generateBinaryExp = (scope, decl, _global, _name) => {
|
|
1066
1066
|
}
|
1067
1067
|
|
1068
1068
|
if (decl.operator === 'in') {
|
1069
|
-
// hack: a in b -> Object.hasOwn(b, a)
|
1070
|
-
// todo: not spec compliant, in should check prototype chain too (once we have it)
|
1071
|
-
|
1072
1069
|
return generate(scope, {
|
1073
1070
|
type: 'CallExpression',
|
1074
1071
|
callee: {
|
@@ -1112,6 +1109,7 @@ const asmFuncToAsm = (scope, func) => {
|
|
1112
1109
|
builtin: (n, offset = false) => {
|
1113
1110
|
let idx = funcIndex[n] ?? importedFuncs[n];
|
1114
1111
|
if (idx == null && builtinFuncs[n]) {
|
1112
|
+
// console.log(scope.name, '->', n);
|
1115
1113
|
includeBuiltin(scope, n);
|
1116
1114
|
idx = funcIndex[n];
|
1117
1115
|
}
|
@@ -3173,7 +3171,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3173
3171
|
const usedProps = [];
|
3174
3172
|
for (const prop of properties) {
|
3175
3173
|
if (prop.type == 'Property') { // let { foo } = {}
|
3176
|
-
usedProps.push(
|
3174
|
+
usedProps.push(getProperty(prop));
|
3177
3175
|
|
3178
3176
|
if (prop.value.type === 'AssignmentPattern') { // let { foo = defaultValue } = {}
|
3179
3177
|
decls.push(
|
@@ -3257,13 +3255,22 @@ const generateVar = (scope, decl) => {
|
|
3257
3255
|
return out;
|
3258
3256
|
};
|
3259
3257
|
|
3260
|
-
const
|
3261
|
-
|
3258
|
+
const privateIDName = name => '.#.' + name;
|
3259
|
+
const privateIdentifierToIdentifier = decl => ({
|
3260
|
+
type: 'Identifier',
|
3261
|
+
name: privateIDName(decl.name)
|
3262
|
+
});
|
3263
|
+
|
3264
|
+
const getProperty = decl => {
|
3265
|
+
const prop = decl.property ?? decl.key;
|
3266
|
+
if (decl.computed) return prop;
|
3262
3267
|
|
3263
|
-
return {
|
3268
|
+
if (prop.name) return {
|
3264
3269
|
type: 'Literal',
|
3265
|
-
value:
|
3270
|
+
value: prop.type === 'PrivateIdentifier' ? privateIDName(prop.name) : prop.name,
|
3266
3271
|
};
|
3272
|
+
|
3273
|
+
return prop;
|
3267
3274
|
};
|
3268
3275
|
|
3269
3276
|
// todo: optimize this func for valueUnused
|
@@ -3348,7 +3355,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
3348
3355
|
const pointerTmp = localTmp(scope, '#member_setter_ptr_tmp', Valtype.i32);
|
3349
3356
|
|
3350
3357
|
const object = decl.left.object;
|
3351
|
-
const property =
|
3358
|
+
const property = getProperty(decl.left);
|
3352
3359
|
|
3353
3360
|
// todo/perf: use i32 object (and prop?) locals
|
3354
3361
|
const objectWasm = [ [ Opcodes.local_get, localTmp(scope, '#member_obj') ] ];
|
@@ -3751,7 +3758,7 @@ const generateUnary = (scope, decl) => {
|
|
3751
3758
|
case 'delete': {
|
3752
3759
|
if (decl.argument.type === 'MemberExpression') {
|
3753
3760
|
const object = decl.argument.object;
|
3754
|
-
const property =
|
3761
|
+
const property = getProperty(decl.argument);
|
3755
3762
|
|
3756
3763
|
if (property.value === 'length' || property.value === 'name') scope.noFastFuncMembers = true;
|
3757
3764
|
|
@@ -5183,12 +5190,7 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
|
|
5183
5190
|
continue;
|
5184
5191
|
}
|
5185
5192
|
|
5186
|
-
|
5187
|
-
if (!computed && key.type !== 'Literal') k = {
|
5188
|
-
type: 'Literal',
|
5189
|
-
value: key.name
|
5190
|
-
};
|
5191
|
-
|
5193
|
+
const k = getProperty(x);
|
5192
5194
|
if (isFuncType(value.type)) {
|
5193
5195
|
let id = value.id;
|
5194
5196
|
|
@@ -5287,7 +5289,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
|
|
5287
5289
|
}
|
5288
5290
|
|
5289
5291
|
const object = decl.object;
|
5290
|
-
const property =
|
5292
|
+
const property = getProperty(decl);
|
5291
5293
|
|
5292
5294
|
// generate now so type is gotten correctly later (it gets cached)
|
5293
5295
|
generate(scope, object);
|
@@ -5721,28 +5723,6 @@ const generateClass = (scope, decl) => {
|
|
5721
5723
|
|
5722
5724
|
if (decl.superClass) {
|
5723
5725
|
out.push(
|
5724
|
-
// ...generateCall(scope, {
|
5725
|
-
// type: 'CallExpression',
|
5726
|
-
// callee: {
|
5727
|
-
// type: 'Identifier',
|
5728
|
-
// name: '__Porffor_object_assignAll'
|
5729
|
-
// },
|
5730
|
-
// arguments: [
|
5731
|
-
// proto,
|
5732
|
-
// {
|
5733
|
-
// type: 'MemberExpression',
|
5734
|
-
// object: decl.superClass,
|
5735
|
-
// property: {
|
5736
|
-
// type: 'Identifier',
|
5737
|
-
// name: 'prototype'
|
5738
|
-
// },
|
5739
|
-
// computed: false,
|
5740
|
-
// optional: false
|
5741
|
-
// }
|
5742
|
-
// ]
|
5743
|
-
// }),
|
5744
|
-
// [ Opcodes.drop ]
|
5745
|
-
|
5746
5726
|
// class Foo {}
|
5747
5727
|
// class Bar extends Foo {}
|
5748
5728
|
// Bar.__proto__ = Foo
|
@@ -5760,11 +5740,7 @@ const generateClass = (scope, decl) => {
|
|
5760
5740
|
|
5761
5741
|
let object = _static ? root : proto;
|
5762
5742
|
|
5763
|
-
|
5764
|
-
if (!computed && key.type !== 'Literal') k = {
|
5765
|
-
type: 'Literal',
|
5766
|
-
value: key.name
|
5767
|
-
};
|
5743
|
+
const k = getProperty(x);
|
5768
5744
|
|
5769
5745
|
let initKind = 'init';
|
5770
5746
|
if (kind === 'get' || kind === 'set') initKind = kind;
|
package/package.json
CHANGED