fez-lisp 1.0.6 → 1.0.8

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/src/utils.js CHANGED
@@ -127,7 +127,7 @@ export const handleUnbalancedQuotes = (source) => {
127
127
  if (diff !== 0) throw new SyntaxError(`Quotes are unbalanced "`)
128
128
  return source
129
129
  }
130
-
130
+ export const removeMutation = (source) => source.replace(new RegExp(/!/g), 'ǃ')
131
131
  export const treeShake = (ast, libs) => {
132
132
  const deps = libs.reduce((a, x) => a.add(x.at(1)[VALUE]), new Set())
133
133
  const visited = new Set()
@@ -179,6 +179,7 @@ export const fez = (source, options = {}) => {
179
179
  handleUnbalancedParens(removeNoCode(source))
180
180
  )
181
181
  else code = removeNoCode(source)
182
+ if (options.immutable) code = removeMutation(code)
182
183
  const parsed = parse(code)
183
184
  const standard = options.std
184
185
  ? options.shake
@@ -186,7 +187,10 @@ export const fez = (source, options = {}) => {
186
187
  : std
187
188
  : []
188
189
  const ast = [...standard, ...parsed]
189
- if (options.compile) return Object.values(comp(deepClone(ast))).join('')
190
+ if (options.compile) {
191
+ const js = Object.values(comp(deepClone(ast))).join('')
192
+ return options.eval ? eval(js) : js
193
+ }
190
194
  return run(ast, env)
191
195
  } catch (error) {
192
196
  const err = error.message
@@ -204,8 +208,8 @@ export const dotNamesToEmpty = (name) => name.replace(new RegExp(/\./g), '')
204
208
  export const colonNamesTo$ = (name) => name.replace(new RegExp(/\:/g), '$')
205
209
  export const commaToLodash = (name) => name.replace(new RegExp(/\,/g), '_')
206
210
  export const arrowToTo = (name) => name.replace(new RegExp(/->/g), '-to-')
207
- export const moduleNameToNothing = (name) =>
208
- name.replace(new RegExp(/::/g), '_')
211
+ export const moduleNameToLodashes = (name) =>
212
+ name.replace(new RegExp(/:/g), '_')
209
213
 
210
214
  export const questionMarkToLodash = (name) =>
211
215
  name.replace(new RegExp(/\?/g), 'Predicate')
@@ -238,7 +242,7 @@ export const lispToJavaScriptVariableName = (name) =>
238
242
  colonNamesTo$(
239
243
  exclamationMarkMarkToLodash(
240
244
  questionMarkToLodash(
241
- commaToLodash(moduleNameToNothing(earMuffsToLodashes(name)))
245
+ commaToLodash(moduleNameToLodashes(earMuffsToLodashes(name)))
242
246
  )
243
247
  )
244
248
  )