@mojir/lits 2.0.17 → 2.0.19

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/dist/lits.iife.js CHANGED
@@ -5613,6 +5613,7 @@ var Lits = (function (exports) {
5613
5613
  if (normalExpressionKeys.includes(name)) {
5614
5614
  throw new Error("Cannot shadow builtin function \"".concat(name, "\""));
5615
5615
  }
5616
+ this.addValue(name, value);
5616
5617
  this.globalContext[name] = { value: value };
5617
5618
  };
5618
5619
  ContextStackImpl.prototype.addValue = function (name, value) {
@@ -7397,27 +7398,49 @@ var Lits = (function (exports) {
7397
7398
  AlgebraicParser.prototype.parseExport = function (token) {
7398
7399
  var _a;
7399
7400
  this.advance();
7400
- var symbol = parseSymbol(this.tokenStream, this.parseState);
7401
- if (isA_OperatorToken(this.peek(), ';')) {
7401
+ if (isA_SymbolToken(this.peek(), 'let')) {
7402
+ this.advance();
7403
+ var symbol = parseSymbol(this.tokenStream, this.parseState);
7404
+ assertA_OperatorToken(this.peek(), '=');
7405
+ this.advance();
7406
+ var value = this.parseExpression();
7407
+ assertA_OperatorToken(this.peek(), ';');
7402
7408
  return {
7403
7409
  t: exports.AstNodeType.SpecialExpression,
7404
7410
  n: 'def',
7405
- p: [symbol, symbol],
7411
+ p: [symbol, value],
7412
+ token: getTokenDebugData(symbol.token) && symbol.token,
7413
+ };
7414
+ }
7415
+ else if (isA_ReservedSymbolToken(this.peek(), 'function')) {
7416
+ this.advance();
7417
+ var symbol = parseSymbol(this.tokenStream, this.parseState);
7418
+ var _b = this.parseFunctionArguments(), functionArguments = _b.functionArguments, arity = _b.arity;
7419
+ var body = [];
7420
+ while (!this.isAtEnd() && !isA_ReservedSymbolToken(this.peek(), 'end')) {
7421
+ body.push(this.parseExpression());
7422
+ if (isA_OperatorToken(this.peek(), ';')) {
7423
+ this.advance();
7424
+ }
7425
+ }
7426
+ assertA_ReservedSymbolToken(this.peek(), 'end');
7427
+ this.advance();
7428
+ return {
7429
+ t: exports.AstNodeType.SpecialExpression,
7430
+ n: 'defn',
7431
+ f: symbol,
7432
+ p: [],
7433
+ o: [{
7434
+ as: functionArguments,
7435
+ b: body,
7436
+ a: arity,
7437
+ }],
7406
7438
  token: getTokenDebugData(token) && token,
7407
7439
  };
7408
7440
  }
7409
- if (!isA_OperatorToken(this.peek(), '=')) {
7410
- throw new LitsError('Expected = or ;', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7441
+ else {
7442
+ throw new LitsError('Expected let or function', (_a = getTokenDebugData(this.peek())) === null || _a === void 0 ? void 0 : _a.sourceCodeInfo);
7411
7443
  }
7412
- this.advance();
7413
- var value = this.parseExpression();
7414
- assertA_OperatorToken(this.peek(), ';');
7415
- return {
7416
- t: exports.AstNodeType.SpecialExpression,
7417
- n: 'def',
7418
- p: [symbol, value],
7419
- token: getTokenDebugData(token) && token,
7420
- };
7421
7444
  };
7422
7445
  return AlgebraicParser;
7423
7446
  }());