porffor 0.57.27 → 0.57.28

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.
@@ -1255,28 +1255,16 @@ const generateBinaryExp = (scope, decl) => {
1255
1255
  const asmFuncToAsm = (scope, func, extra) => func(scope, {
1256
1256
  Valtype, Opcodes, TYPES, TYPE_NAMES, usedTypes, typeSwitch, makeString, internalThrow,
1257
1257
  getNodeType, generate, generateIdent,
1258
- builtin: (n, offset = false) => {
1259
- let idx = importedFuncs[n] ?? funcIndex[n];
1260
- if (idx == null && Object.hasOwn(builtinFuncs, n)) {
1261
- includeBuiltin(scope, n);
1262
- idx = funcIndex[n];
1263
- }
1264
-
1265
- scope.includes ??= new Set();
1266
- scope.includes.add(n);
1267
-
1268
- if (idx == null) throw new Error(`builtin('${n}') failed: could not find func (from ${scope.name})`);
1258
+ builtin: (name, offset = false) => {
1259
+ let idx = importedFuncs[name] ?? includeBuiltin(scope, name)?.index;
1260
+ if (idx == null) throw new Error(`builtin('${name}') failed: could not find func (from ${scope.name})`);
1269
1261
  if (offset) idx -= importedFuncs.length;
1270
1262
 
1271
1263
  return idx;
1272
1264
  },
1273
1265
  hasFunc: x => funcIndex[x] != null,
1274
1266
  funcRef: name => {
1275
- if (funcIndex[name] == null && Object.hasOwn(builtinFuncs, name)) {
1276
- includeBuiltin(scope, name);
1277
- }
1278
-
1279
- const func = funcByName(name);
1267
+ const func = includeBuiltin(scope, name);
1280
1268
  return funcRef(func);
1281
1269
  },
1282
1270
  glbl: (opcode, name, type) => {
@@ -1340,7 +1328,7 @@ const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTy
1340
1328
  wasm = [];
1341
1329
  }
1342
1330
 
1343
- const existing = funcByName(name);
1331
+ const existing = builtinFuncByName(name);
1344
1332
  if (existing) return existing;
1345
1333
 
1346
1334
  const allLocals = params.concat(localTypes);
@@ -2498,20 +2486,24 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
2498
2486
  [ Opcodes.local_get, thisLocal ],
2499
2487
  [ Opcodes.local_get, thisLocalType ]
2500
2488
  ];
2501
- getCallee = [
2502
- ...generate(scope, object),
2503
- [ Opcodes.local_set, thisLocal ],
2504
- ...getNodeType(scope, object),
2505
- [ Opcodes.local_set, thisLocalType ],
2506
-
2507
- ...generate(scope, {
2508
- type: 'MemberExpression',
2509
- object: { type: 'Identifier', name: tmpName + 'caller' },
2510
- property,
2511
- computed,
2512
- optional
2513
- })
2514
- ];
2489
+ getCallee = generate(scope, {
2490
+ type: 'MemberExpression',
2491
+ object: {
2492
+ type: 'Wasm',
2493
+ wasm: () => [
2494
+ ...generate(scope, object),
2495
+ [ Opcodes.local_tee, thisLocal ],
2496
+ ...getNodeType(scope, object),
2497
+ [ Opcodes.local_set, thisLocalType ]
2498
+ ],
2499
+ _type: [
2500
+ [ Opcodes.local_get, thisLocalType ]
2501
+ ]
2502
+ },
2503
+ property,
2504
+ computed,
2505
+ optional
2506
+ });
2515
2507
  }
2516
2508
  }
2517
2509
 
@@ -6539,6 +6531,13 @@ const funcByIndex = idx => {
6539
6531
  };
6540
6532
  const funcByName = name => funcByIndex(funcIndex[name]);
6541
6533
 
6534
+ const builtinFuncByName = name => {
6535
+ const normal = funcByName(name);
6536
+ if (!normal || normal.internal) return normal;
6537
+
6538
+ return funcs.find(x => x.name === name && x.internal);
6539
+ };
6540
+
6542
6541
  const generateFunc = (scope, decl, forceNoExpr = false) => {
6543
6542
  doNotMarkFuncRef = false;
6544
6543
 
package/foo.js ADDED
@@ -0,0 +1,8 @@
1
+ const a = {
2
+ b: {
3
+ c: () => {}
4
+ },
5
+ c: () => {}
6
+ };
7
+
8
+ a.c();
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.57.27",
4
+ "version": "0.57.28",
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.57.27';
3
+ globalThis.version = '0.57.28';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {