@lokascript/compilation-service 2.2.0 → 2.3.0

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.
@@ -2768,7 +2768,7 @@ var CompilationService = class _CompilationService {
2768
2768
  initValidation({
2769
2769
  validateSemanticResult: semantic.validateSemanticResult
2770
2770
  });
2771
- const aot = await import("./dist-A6VWPCPB.js");
2771
+ const aot = await import("./dist-CXRMMXI7.js");
2772
2772
  const compiler = aot.createCompiler();
2773
2773
  initBridge(
2774
2774
  {
@@ -3206,4 +3206,4 @@ export {
3206
3206
  SvelteRenderer,
3207
3207
  CompilationService
3208
3208
  };
3209
- //# sourceMappingURL=chunk-PVQF6QYP.js.map
3209
+ //# sourceMappingURL=chunk-BHZMWRBA.js.map
@@ -24,7 +24,7 @@ function convertCoreASTToAOT(node) {
24
24
  return node;
25
25
  }
26
26
  async function createCoreParserAdapter() {
27
- const core = await import("./dist-CYO3JGTJ.js");
27
+ const core = await import("./dist-5S22WYM3.js");
28
28
  const api = core.hyperscript ?? core.default ?? core;
29
29
  if (!api?.compileSync) {
30
30
  throw new Error(
@@ -46,4 +46,4 @@ export {
46
46
  convertCoreASTToAOT,
47
47
  createCoreParserAdapter
48
48
  };
49
- //# sourceMappingURL=chunk-ZQ3GX55O.js.map
49
+ //# sourceMappingURL=chunk-BW34XOBT.js.map
@@ -2,11 +2,11 @@ import {
2
2
  CoreParserAdapter,
3
3
  convertCoreASTToAOT,
4
4
  createCoreParserAdapter
5
- } from "./chunk-ZQ3GX55O.js";
5
+ } from "./chunk-BW34XOBT.js";
6
6
  import "./chunk-GBPMR66W.js";
7
7
  export {
8
8
  CoreParserAdapter,
9
9
  convertCoreASTToAOT,
10
10
  createCoreParserAdapter
11
11
  };
12
- //# sourceMappingURL=core-parser-adapter-VCJB52SO-7T2PARW4.js.map
12
+ //# sourceMappingURL=core-parser-adapter-VCJB52SO-I5AIPWJQ.js.map
@@ -440,7 +440,8 @@ function tokenize$1(input) {
440
440
  const isCommandContext = prevToken && prevToken.kind === TokenKind.IDENTIFIER && COMMANDS.has(prevToken.value.toLowerCase());
441
441
  const isKeywordContext = prevToken && prevToken.kind === TokenKind.IDENTIFIER && SELECTOR_CONTEXT_KEYWORDS.has(prevToken.value.toLowerCase());
442
442
  const isCSSSelectorContext = !prevToken || prevToken.kind === TokenKind.OPERATOR && prevToken.value !== ")" && prevToken.value !== "]" || isCommandContext || isKeywordContext || prevToken.value === "(" || prevToken.value === "[" || prevToken.value === "{" || prevToken.value === "," || prevToken.value === ";";
443
- if (isCSSSelectorContext && isAlpha(peek(tokenizer))) {
443
+ const isAdjacentToPrev = prevToken && prevToken.end === tokenizer.position;
444
+ if (isCSSSelectorContext && !isAdjacentToPrev && (isAlpha(peek(tokenizer)) || peek(tokenizer) === "{")) {
444
445
  tokenizeCSSSelector(tokenizer);
445
446
  continue;
446
447
  }
@@ -656,6 +657,17 @@ function tokenizeCSSSelector(tokenizer) {
656
657
  const start = tokenizer.position;
657
658
  const prefix2 = advance(tokenizer);
658
659
  let value = prefix2;
660
+ if (tokenizer.position < tokenizer.input.length && tokenizer.input[tokenizer.position] === "{") {
661
+ value += advance(tokenizer);
662
+ while (tokenizer.position < tokenizer.input.length) {
663
+ const ch = tokenizer.input[tokenizer.position];
664
+ value += advance(tokenizer);
665
+ if (ch === "}")
666
+ break;
667
+ }
668
+ addToken(tokenizer, TokenKind.SELECTOR, value, start);
669
+ return;
670
+ }
659
671
  while (tokenizer.position < tokenizer.input.length) {
660
672
  const char = tokenizer.input[tokenizer.position];
661
673
  if (isAlphaNumeric(char) || char === "-" || char === "_" || char === ":") {
@@ -2238,31 +2250,14 @@ function parseTriggerCommand(ctx, identifierNode) {
2238
2250
  });
2239
2251
  }
2240
2252
  }
2241
- while (!isCommandBoundary(ctx)) {
2242
- allArgs.push(ctx.parsePrimary());
2243
- }
2244
- let operationIndex = -1;
2245
- let operationKeyword = "on";
2246
- for (let i = 0; i < allArgs.length; i++) {
2247
- const arg = allArgs[i];
2248
- const argRecord = arg;
2249
- const argValue = argRecord.name || argRecord.value;
2250
- if ((arg.type === "identifier" || arg.type === "literal" || arg.type === "keyword") && (argValue === "on" || argValue === "to")) {
2251
- operationIndex = i;
2252
- operationKeyword = argValue;
2253
- break;
2253
+ const finalArgs = [...allArgs];
2254
+ if (ctx.check("on") || ctx.check("to")) {
2255
+ const keyword = ctx.advance().value;
2256
+ finalArgs.push(ctx.createIdentifier(keyword));
2257
+ while (!isCommandBoundary(ctx)) {
2258
+ finalArgs.push(ctx.parsePrimary());
2254
2259
  }
2255
2260
  }
2256
- const finalArgs = [];
2257
- if (operationIndex === -1) {
2258
- finalArgs.push(...allArgs);
2259
- } else {
2260
- const eventArgs = allArgs.slice(0, operationIndex);
2261
- const targetArgs = allArgs.slice(operationIndex + 1);
2262
- finalArgs.push(...eventArgs);
2263
- finalArgs.push(ctx.createIdentifier(operationKeyword));
2264
- finalArgs.push(...targetArgs);
2265
- }
2266
2261
  return CommandNodeBuilder.fromIdentifier(identifierNode).withArgs(...finalArgs).endingAt(ctx.getPosition()).build();
2267
2262
  }
2268
2263
  function parseHaltCommand(ctx, identifierNode) {
@@ -2899,8 +2894,9 @@ function parseSwapCommand(ctx, identifierNode) {
2899
2894
  }
2900
2895
  function parseWaitCommand(ctx, commandToken) {
2901
2896
  const args = [];
2902
- if (ctx.checkTimeExpression() || ctx.checkLiteral()) {
2903
- const timeExpr = ctx.parsePrimary();
2897
+ const isExpressionStart = ctx.checkTimeExpression() || ctx.checkLiteral() || ctx.checkContextVar() || ctx.check("(") || ctx.checkIdentifierLike() && !ctx.check("for") && !isCommandBoundary(ctx);
2898
+ if (isExpressionStart) {
2899
+ const timeExpr = ctx.parseExpression();
2904
2900
  args.push(timeExpr);
2905
2901
  return CommandNodeBuilder.from(commandToken).withArgs(...args).blocking().endingAt(ctx.getPosition()).build();
2906
2902
  }
@@ -3068,43 +3064,24 @@ function parsePropertyOfTarget(ctx, startPosition) {
3068
3064
  return null;
3069
3065
  const thePosition = ctx.savePosition();
3070
3066
  ctx.advance();
3071
- const nextToken = ctx.peek();
3072
- const tokenAfterNext = ctx.peekAt(1);
3073
- if (nextToken && tokenAfterNext && tokenAfterNext.value === KEYWORDS$1.OF) {
3074
- const propertyToken = ctx.advance();
3075
- if (ctx.check(KEYWORDS$1.OF)) {
3076
- ctx.advance();
3077
- const targetToken = ctx.advance();
3078
- const isIdSelector2 = targetToken.value.startsWith("#");
3079
- return {
3080
- type: "propertyOfExpression",
3081
- property: {
3082
- type: "identifier",
3083
- name: propertyToken.value,
3084
- start: propertyToken.start,
3085
- end: propertyToken.end
3086
- },
3087
- target: {
3088
- type: isIdSelector2 ? "idSelector" : "cssSelector",
3089
- value: targetToken.value,
3090
- start: targetToken.start,
3091
- end: targetToken.end
3092
- },
3093
- start: startPosition,
3094
- end: ctx.savePosition()
3095
- };
3096
- }
3097
- ctx.restorePosition(startPosition);
3067
+ const propertyExpr = ctx.parseExpression();
3068
+ if (!propertyExpr) {
3069
+ ctx.restorePosition(thePosition);
3098
3070
  return null;
3099
3071
  }
3100
- if (nextToken && tokenAfterNext && tokenAfterNext.value === KEYWORDS$1.TO) {
3101
- const variableToken = ctx.advance();
3102
- return {
3103
- type: "identifier",
3104
- name: variableToken.value,
3105
- start: variableToken.start,
3106
- end: variableToken.end
3107
- };
3072
+ const exprAny = propertyExpr;
3073
+ if (exprAny.type === "binaryExpression" && exprAny.operator === KEYWORDS$1.OF) {
3074
+ const property = exprAny.left;
3075
+ const target = exprAny.right;
3076
+ return createPropertyOfExpression(property, target, {
3077
+ start: property.start ?? 0,
3078
+ end: target.end ?? 0,
3079
+ line: property.line ?? 1,
3080
+ column: property.column ?? 1
3081
+ });
3082
+ }
3083
+ if (ctx.check(KEYWORDS$1.TO)) {
3084
+ return propertyExpr;
3108
3085
  }
3109
3086
  ctx.restorePosition(thePosition);
3110
3087
  return null;
@@ -3428,6 +3405,68 @@ function parseFetchNakedNamedArgs(ctx) {
3428
3405
  column: startPos.column
3429
3406
  };
3430
3407
  }
3408
+ function findJsEndBoundary(ctx, startPos) {
3409
+ const input = ctx.getInputSlice(startPos);
3410
+ if (!input) {
3411
+ return startPos;
3412
+ }
3413
+ let i = 0;
3414
+ while (i < input.length) {
3415
+ const ch = input[i];
3416
+ if (ch === "'" || ch === "\u2019" || ch === "\u2018") {
3417
+ i++;
3418
+ while (i < input.length && input[i] !== ch) {
3419
+ if (input[i] === "\\")
3420
+ i++;
3421
+ i++;
3422
+ }
3423
+ i++;
3424
+ continue;
3425
+ }
3426
+ if (ch === '"') {
3427
+ i++;
3428
+ while (i < input.length && input[i] !== '"') {
3429
+ if (input[i] === "\\")
3430
+ i++;
3431
+ i++;
3432
+ }
3433
+ i++;
3434
+ continue;
3435
+ }
3436
+ if (ch === "`") {
3437
+ i++;
3438
+ while (i < input.length && input[i] !== "`") {
3439
+ if (input[i] === "\\")
3440
+ i++;
3441
+ i++;
3442
+ }
3443
+ i++;
3444
+ continue;
3445
+ }
3446
+ if (ch === "/" && i + 1 < input.length && input[i + 1] === "/") {
3447
+ i += 2;
3448
+ while (i < input.length && input[i] !== "\n")
3449
+ i++;
3450
+ continue;
3451
+ }
3452
+ if (ch === "/" && i + 1 < input.length && input[i + 1] === "*") {
3453
+ i += 2;
3454
+ while (i < input.length && !(input[i] === "*" && i + 1 < input.length && input[i + 1] === "/"))
3455
+ i++;
3456
+ i += 2;
3457
+ continue;
3458
+ }
3459
+ if ((ch === "e" || ch === "E") && i + 3 <= input.length && input.slice(i, i + 3).toLowerCase() === "end") {
3460
+ const before = i === 0 || !/[a-zA-Z0-9_]/.test(input[i - 1]);
3461
+ const after = i + 3 >= input.length || !/[a-zA-Z0-9_]/.test(input[i + 3]);
3462
+ if (before && after) {
3463
+ return startPos + i;
3464
+ }
3465
+ }
3466
+ i++;
3467
+ }
3468
+ return startPos + input.length;
3469
+ }
3431
3470
  function parseJsCommand(ctx, identifierNode) {
3432
3471
  const parameters = [];
3433
3472
  if (ctx.match("(")) {
@@ -3440,11 +3479,12 @@ function parseJsCommand(ctx, identifierNode) {
3440
3479
  ctx.consume(")", "Expected ) after js parameters");
3441
3480
  }
3442
3481
  const jsCodeStart = ctx.peek().start;
3443
- while (!ctx.check(KEYWORDS$1.END) && !ctx.isAtEnd()) {
3482
+ const jsCodeEnd = findJsEndBoundary(ctx, jsCodeStart);
3483
+ while (!ctx.isAtEnd() && !ctx.check(KEYWORDS$1.END)) {
3484
+ if (ctx.peek().start >= jsCodeEnd)
3485
+ break;
3444
3486
  ctx.advance();
3445
3487
  }
3446
- const endToken = ctx.peek();
3447
- const jsCodeEnd = endToken.start;
3448
3488
  ctx.consume(KEYWORDS$1.END, "Expected end after js code body");
3449
3489
  const rawSlice = ctx.getInputSlice(jsCodeStart, jsCodeEnd);
3450
3490
  const code = rawSlice.trim();
@@ -4288,7 +4328,7 @@ var Parser = class _Parser {
4288
4328
  }
4289
4329
  } else {
4290
4330
  const commandName = expr.name.toLowerCase();
4291
- if (commandName === "wait" && this.checkTimeExpression()) {
4331
+ if (commandName === "wait" && (this.checkTimeExpression() || this.checkNumber() || this.checkIdentifier() || this.checkContextVar() || this.check("("))) {
4292
4332
  const command2 = this.createCommandFromIdentifier(expr);
4293
4333
  if (command2) {
4294
4334
  expr = command2;
@@ -5398,9 +5438,7 @@ var Parser = class _Parser {
5398
5438
  while (!this.isAtEnd() && !this.check("end")) {
5399
5439
  if (this.match("on")) {
5400
5440
  const handlerPos = this.getPosition();
5401
- const eventToken = this.peek();
5402
- const eventName = eventToken.value;
5403
- this.advance();
5441
+ const eventName = this.parseEventNameWithNamespace("Expected event name after 'on'");
5404
5442
  const eventArgs = [];
5405
5443
  if (this.check("(")) {
5406
5444
  this.advance();
@@ -8092,6 +8130,8 @@ var BaseExpressionEvaluator = class {
8092
8130
  return this.evaluateIdSelector(node, context);
8093
8131
  case "attributeAccess":
8094
8132
  return this.evaluateAttributeAccess(node, context);
8133
+ case "asExpression":
8134
+ return this.evaluateAsExpression(node, context);
8095
8135
  default:
8096
8136
  throw new Error(`Unsupported AST node type for evaluation: ${node.type}`);
8097
8137
  }
@@ -8367,6 +8407,14 @@ var BaseExpressionEvaluator = class {
8367
8407
  }
8368
8408
  return `@${node.attributeName}`;
8369
8409
  }
8410
+ async evaluateAsExpression(node, context) {
8411
+ const value = await this.evaluate(node.expression, context);
8412
+ const asExpr = this.expressionRegistry.get("as");
8413
+ if (asExpr) {
8414
+ return asExpr.evaluate(context, value, node.targetType);
8415
+ }
8416
+ throw new Error(`Conversion type 'as' not registered`);
8417
+ }
8370
8418
  getAvailableExpressions() {
8371
8419
  return Array.from(this.expressionRegistry.keys());
8372
8420
  }
@@ -13744,6 +13792,8 @@ var RuntimeBase = class _RuntimeBase {
13744
13792
  this.behaviorAPI = {
13745
13793
  has: (name) => this.behaviorRegistry.has(name),
13746
13794
  get: (name) => this.behaviorRegistry.get(name),
13795
+ set: (name, definition) => this.behaviorRegistry.set(name, definition),
13796
+ resolve: null,
13747
13797
  install: async (behaviorName, element, parameters) => {
13748
13798
  return await this.installBehaviorOnElement(behaviorName, element, parameters);
13749
13799
  }
@@ -14207,9 +14257,14 @@ var RuntimeBase = class _RuntimeBase {
14207
14257
  }
14208
14258
  async installBehaviorOnElement(behaviorName, element, parameters) {
14209
14259
  debug.runtime(`BEHAVIOR: installBehaviorOnElement called: ${behaviorName}`);
14210
- const behavior = this.behaviorRegistry.get(behaviorName);
14211
- if (!behavior)
14212
- throw new Error(`Behavior "${behaviorName}" not found`);
14260
+ let behavior = this.behaviorRegistry.get(behaviorName);
14261
+ if (!behavior) {
14262
+ if (this.behaviorAPI.resolve && this.behaviorAPI.resolve(behaviorName)) {
14263
+ behavior = this.behaviorRegistry.get(behaviorName);
14264
+ }
14265
+ if (!behavior)
14266
+ throw new Error(`Behavior "${behaviorName}" not found`);
14267
+ }
14213
14268
  if (behavior.type === "imperative" && typeof behavior.install === "function") {
14214
14269
  debug.runtime(`BEHAVIOR: Installing imperative behavior '${behaviorName}'`);
14215
14270
  behavior.install(element, parameters);
@@ -19287,7 +19342,9 @@ var SetCommand = (() => {
19287
19342
  return { type: "property", element: firstValue[0], property: "textContent", value: value2 };
19288
19343
  }
19289
19344
  if (typeof firstValue !== "string") {
19290
- throw new Error("set command target must be a string or object literal");
19345
+ const isMember = firstArg?.type === "memberExpression" || firstArg?.type === "propertyAccess";
19346
+ const hint = isMember ? ` (a property chain evaluated to ${firstValue === null ? "null" : typeof firstValue} \u2014 check that all intermediate objects exist)` : "";
19347
+ throw new Error(`set command target must be a string or object literal${hint}`);
19291
19348
  }
19292
19349
  const value = await this.extractValue(raw, evaluator, context);
19293
19350
  return { type: "variable", name: firstValue, value };
@@ -22342,12 +22399,18 @@ var InstallCommand = class _InstallCommand {
22342
22399
  const behaviorRegistry = context.locals.get("_behaviors");
22343
22400
  if (behaviorRegistry && typeof behaviorRegistry === "object") {
22344
22401
  const registry = behaviorRegistry;
22345
- return registry.has(behaviorName);
22402
+ if (registry.has(behaviorName))
22403
+ return true;
22404
+ if (registry.resolve && registry.resolve(behaviorName))
22405
+ return true;
22346
22406
  }
22347
22407
  if (typeof globalThis !== "undefined") {
22348
22408
  const hyperscriptGlobal = globalThis._hyperscript;
22349
22409
  if (hyperscriptGlobal?.behaviors) {
22350
- return hyperscriptGlobal.behaviors.has(behaviorName);
22410
+ if (hyperscriptGlobal.behaviors.has(behaviorName))
22411
+ return true;
22412
+ if (hyperscriptGlobal.behaviors.resolve && hyperscriptGlobal.behaviors.resolve(behaviorName))
22413
+ return true;
22351
22414
  }
22352
22415
  }
22353
22416
  return false;
@@ -74673,4 +74736,4 @@ export {
74673
74736
  toCoreAST,
74674
74737
  validatePartialContent
74675
74738
  };
74676
- //# sourceMappingURL=dist-CYO3JGTJ.js.map
74739
+ //# sourceMappingURL=dist-5S22WYM3.js.map