Merge pull request 'ref keyword' (#38) from ref-keyword into main

Reviewed-on: #38
This commit is contained in:
defunkt 2025-11-09 00:03:44 +00:00
commit 012b8c8cf1
2 changed files with 13 additions and 0 deletions

View File

@ -42,6 +42,7 @@ export const globals = {
'var?': function (this: VM, v: string) { 'var?': function (this: VM, v: string) {
return typeof v !== 'string' || this.scope.has(v) return typeof v !== 'string' || this.scope.has(v)
}, },
ref: (fn: Function) => fn,
// env // env
args: Bun.argv.slice(1), args: Bun.argv.slice(1),

View File

@ -91,3 +91,15 @@ describe('environment', () => {
await expect(`list.first args | str.ends-with? 'shrimp.test.ts'`).toEvaluateTo(true) await expect(`list.first args | str.ends-with? 'shrimp.test.ts'`).toEvaluateTo(true)
}) })
}) })
describe('ref', () => {
expect(`rnd = do x: true end; rnd | type`).toEvaluateTo('boolean')
expect(`rnd = do x: true end; ref rnd | type`).toEvaluateTo('function')
expect(`math.random | type`).toEvaluateTo('number')
expect(`ref math.random | type`).toEvaluateTo('native')
expect(`rnd = math.random; rnd | type`).toEvaluateTo('number')
expect(`rnd = ref math.random; rnd | type`).toEvaluateTo('number')
expect(`rnd = ref math.random; ref rnd | type`).toEvaluateTo('native')
})