Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read properties of undefined (reading 'startsWith') #220

Open
jcubic opened this issue Jan 21, 2025 · 0 comments
Open

Comments

@jcubic
Copy link

jcubic commented Jan 21, 2025

I'm trying to compile LIPS Scheme CLI, pre compiled to commonJS with tsup (the project is not TypeScript, but esbuilt was throwing an error about one require).

Got this error:

TypeError: Cannot read properties of undefined (reading 'startsWith')
    at removeBrackets (file:///home/kuba/.config/nvm/versions/node/v20.6.1/lib/node_modules/porffor/compiler/2c.js:172:13)
    at cify (file:///home/kuba/.config/nvm/versions/node/v20.6.1/lib/node_modules/porffor/compiler/2c.js:743:78)
    at cify (file:///home/kuba/.config/nvm/versions/node/v20.6.1/lib/node_modules/porffor/compiler/2c.js:681:15)
    at cify (file:///home/kuba/.config/nvm/versions/node/v20.6.1/lib/node_modules/porffor/compiler/2c.js:681:15)
    at cify (file:///home/kuba/.config/nvm/versions/node/v20.6.1/lib/node_modules/porffor/compiler/2c.js:681:15)
    at cify (file:///home/kuba/.config/nvm/versions/node/v20.6.1/lib/node_modules/porffor/compiler/2c.js:681:15)
    at cify (file:///home/kuba/.config/nvm/versions/node/v20.6.1/lib/node_modules/porffor/compiler/2c.js:681:15)
    at default (file:///home/kuba/.config/nvm/versions/node/v20.6.1/lib/node_modules/porffor/compiler/2c.js:897:3)
    at default (file:///home/kuba/.config/nvm/versions/node/v20.6.1/lib/node_modules/porffor/compiler/index.js:258:15)
    at default (file:///home/kuba/.config/nvm/versions/node/v20.6.1/lib/node_modules/porffor/compiler/wrap.js:360:102)

To reproduce:

git clone https://github.com/jcubic/lips
cd lips
npm install
npm install tsup typescript
npx tsup bin/lips.js --format cjs
porf native -d dist/lips.cjs lips

This is the source from above stack trace:

/* 165 */ const removeBrackets = str => {
/* 166 */   // return str;
/* 167 */   // if (str.startsWith('(i32)(u32)')) return '(i32)(u32)(' + removeBrackets(str.slice(22, -1)) + ')';
/* 168 */ 
/* 169 */   for (const x in CValtype) {
/* 170 */     const p = `(${x})`;
/* 171 */     // if (str.startsWith(p)) return p + removeBrackets(str.slice(p.length));
/* 172 */     if (str.startsWith(p)) return str;
/* 173 */   }
/* ... */
/* 741 */         case Opcodes.br: {
/* 742 */           const ret = rets[brDepth - i[1] - 1];
/* 743 */           if (ret !== Blocktype.void) line(`_r${brs[brDepth - i[1] - 1]} = ${removeBrackets(vals.pop())}`);
/* 744 */           line(`goto j${brs[brDepth - i[1] - 1]}`);
/* 745 */ 
/* 746 */           break;
/* 747 */         }

vals.pop() is undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant