@xaendar/compiler 0.7.2 → 0.7.3
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/xaendar-compiler.es.js +71 -71
- package/package.json +3 -3
|
@@ -426,7 +426,7 @@ function emitNode(node, parent, compilerContext, skipResolution = false) {
|
|
|
426
426
|
function resolveIdentifierAccess(text, compilerContext) {
|
|
427
427
|
if (compilerContext.hasIdentifier(text)) {
|
|
428
428
|
const kind = compilerContext.getIdentifierKind(text);
|
|
429
|
-
const access = `
|
|
429
|
+
const access = `context.get('${text}')`;
|
|
430
430
|
return kind === "signal" ? `${access}()` : access;
|
|
431
431
|
}
|
|
432
432
|
return `this.${text}`;
|
|
@@ -497,7 +497,7 @@ function getIdentifier(prefix, parentNode, index) {
|
|
|
497
497
|
return (parentNode !== "root" ? `${parentNode}__${prefix}${index}` : `${prefix}${index}`).replace(/-/g, "_");
|
|
498
498
|
}
|
|
499
499
|
//#endregion
|
|
500
|
-
//#region ../packages/compiler/src/generator/states/
|
|
500
|
+
//#region ../packages/compiler/src/generator/states/generate-element.state.ts
|
|
501
501
|
/**
|
|
502
502
|
* Generates code for an HTML element node: creates the DOM element, sets attributes,
|
|
503
503
|
* attaches event listeners, appends it to the parent, and recursively processes children.
|
|
@@ -508,7 +508,7 @@ function getIdentifier(prefix, parentNode, index) {
|
|
|
508
508
|
* @param compilerContext - Current render scope context.
|
|
509
509
|
* @returns Array of generated code lines.
|
|
510
510
|
*/
|
|
511
|
-
function
|
|
511
|
+
function generateElement(node, parentNode, index, compilerContext, anchor) {
|
|
512
512
|
const attributes = mapAttributes(node.attributes, compilerContext);
|
|
513
513
|
const events = mapEvents(node.events, compilerContext);
|
|
514
514
|
const nodeName = getElementIdentifier(node, parentNode, index);
|
|
@@ -589,7 +589,7 @@ function mapEvents(events, compilerContext) {
|
|
|
589
589
|
return mappedEvents;
|
|
590
590
|
}
|
|
591
591
|
//#endregion
|
|
592
|
-
//#region ../packages/compiler/src/generator/states/
|
|
592
|
+
//#region ../packages/compiler/src/generator/states/generate-for.state.ts
|
|
593
593
|
/**
|
|
594
594
|
* Generates code for a `@for` iteration node.
|
|
595
595
|
*
|
|
@@ -621,7 +621,7 @@ function mapEvents(events, compilerContext) {
|
|
|
621
621
|
* @param compilerContext - The enclosing scope context.
|
|
622
622
|
* @returns Array of generated code lines.
|
|
623
623
|
*/
|
|
624
|
-
function
|
|
624
|
+
function generateFor(node, parentNode, index, compilerContext, anchor) {
|
|
625
625
|
const retVal = {
|
|
626
626
|
code: [],
|
|
627
627
|
functionsToProcess: /* @__PURE__ */ new Map()
|
|
@@ -655,7 +655,7 @@ function processFor(node, parentNode, index, compilerContext, anchor) {
|
|
|
655
655
|
});
|
|
656
656
|
const { ${node.itemAlias}, ${indexName}, ${firstName}, ${lastName}, ${evenName}, ${oddName} } = vars;`,
|
|
657
657
|
node,
|
|
658
|
-
parentNode
|
|
658
|
+
parentNode: `${parentNode}${forKey}`,
|
|
659
659
|
context: forContext,
|
|
660
660
|
anchor: "anchor",
|
|
661
661
|
isForBody: true
|
|
@@ -687,8 +687,8 @@ function resolveImplicit(node, implicit) {
|
|
|
687
687
|
return node.implicitAliases.get(implicit) ?? implicit;
|
|
688
688
|
}
|
|
689
689
|
//#endregion
|
|
690
|
-
//#region ../packages/compiler/src/generator/states/
|
|
691
|
-
function
|
|
690
|
+
//#region ../packages/compiler/src/generator/states/generate-if.state.ts
|
|
691
|
+
function generateIf(node, parentNode, index, compilerContext) {
|
|
692
692
|
const ifContext = new CompilerContext([], compilerContext);
|
|
693
693
|
const retVal = {
|
|
694
694
|
code: [],
|
|
@@ -704,7 +704,7 @@ function processIf(node, parentNode, index, compilerContext) {
|
|
|
704
704
|
retVal.functionsToProcess.set(ifKey, {
|
|
705
705
|
fn: {
|
|
706
706
|
node,
|
|
707
|
-
parentNode
|
|
707
|
+
parentNode: `${parentNode}${ifKey}`,
|
|
708
708
|
context: ifContext,
|
|
709
709
|
anchor: "anchor"
|
|
710
710
|
},
|
|
@@ -767,7 +767,7 @@ function processIf(node, parentNode, index, compilerContext) {
|
|
|
767
767
|
return retVal;
|
|
768
768
|
}
|
|
769
769
|
//#endregion
|
|
770
|
-
//#region ../packages/compiler/src/generator/states/
|
|
770
|
+
//#region ../packages/compiler/src/generator/states/generate-switch.state.ts
|
|
771
771
|
/**
|
|
772
772
|
* Generates code for a `@switch` node.
|
|
773
773
|
* Emits a `_switch(...)` call that delegates to the reactive `_switch` runtime utility.
|
|
@@ -778,7 +778,7 @@ function processIf(node, parentNode, index, compilerContext) {
|
|
|
778
778
|
* @param compilerContext - Current render scope context.
|
|
779
779
|
* @returns An object with the main block code lines and a map of helper functions to register.
|
|
780
780
|
*/
|
|
781
|
-
function
|
|
781
|
+
function generateSwitch(node, parentNode, index, compilerContext) {
|
|
782
782
|
const retVal = {
|
|
783
783
|
code: [],
|
|
784
784
|
functionsToProcess: /* @__PURE__ */ new Map()
|
|
@@ -786,11 +786,11 @@ function processSwitch(node, parentNode, index, compilerContext) {
|
|
|
786
786
|
retVal.code.push(`_switch(${parentNode}, context, () => ${resolveExpression(node.expression, compilerContext)}, [`);
|
|
787
787
|
node.children.forEach((caseNode, i) => {
|
|
788
788
|
const caseContext = new CompilerContext([], compilerContext);
|
|
789
|
-
const
|
|
790
|
-
retVal.functionsToProcess.set(
|
|
789
|
+
const caseKey = caseNode.condition ? getBlockIdentifier("case", parentNode, `${index}_${i}`) : getBlockIdentifier("default", parentNode, index);
|
|
790
|
+
retVal.functionsToProcess.set(caseKey, {
|
|
791
791
|
fn: {
|
|
792
792
|
node: caseNode,
|
|
793
|
-
parentNode
|
|
793
|
+
parentNode: `${parentNode}${caseKey}`,
|
|
794
794
|
context: caseContext
|
|
795
795
|
},
|
|
796
796
|
args: [
|
|
@@ -799,14 +799,14 @@ function processSwitch(node, parentNode, index, compilerContext) {
|
|
|
799
799
|
"anchor"
|
|
800
800
|
]
|
|
801
801
|
});
|
|
802
|
-
const fnName = `this.${
|
|
802
|
+
const fnName = `this.${caseKey}.bind(this)`;
|
|
803
803
|
retVal.code.push("{", ...indent([`condition: ${caseNode.condition ? `[${caseNode.condition.join(", ")}]` : `null`},`, `block: ${fnName}`]), "},");
|
|
804
804
|
});
|
|
805
805
|
retVal.code.push("])");
|
|
806
806
|
return retVal;
|
|
807
807
|
}
|
|
808
808
|
//#endregion
|
|
809
|
-
//#region ../packages/compiler/src/generator/states/
|
|
809
|
+
//#region ../packages/compiler/src/generator/states/generate-text-and-interpolation.state.ts
|
|
810
810
|
/**
|
|
811
811
|
* Generates code for a text or interpolation node.
|
|
812
812
|
*
|
|
@@ -818,7 +818,7 @@ function processSwitch(node, parentNode, index, compilerContext) {
|
|
|
818
818
|
* @param parentNode - Variable name of the parent DOM node to append to.
|
|
819
819
|
* @returns Array of generated code lines.
|
|
820
820
|
*/
|
|
821
|
-
function
|
|
821
|
+
function generateTextAndInterpolation(node, parentNode, _index, compilerContext) {
|
|
822
822
|
return { code: [`${node.type === ASTNodeType.Text ? `_renderLiteralText(${parentNode}, context, '${node.value}');` : `_renderText(${parentNode}, context, () => ${resolveExpression(node.expression, compilerContext)});`}`] };
|
|
823
823
|
}
|
|
824
824
|
//#endregion
|
|
@@ -828,12 +828,12 @@ var Generator = class {
|
|
|
828
828
|
_cssVariableName;
|
|
829
829
|
_nodeToProcess = /* @__PURE__ */ new Map();
|
|
830
830
|
_states = {
|
|
831
|
-
[ASTNodeType.Text]:
|
|
832
|
-
[ASTNodeType.Interpolation]:
|
|
833
|
-
[ASTNodeType.Element]:
|
|
834
|
-
[ASTNodeType.If]:
|
|
835
|
-
[ASTNodeType.For]:
|
|
836
|
-
[ASTNodeType.Switch]:
|
|
831
|
+
[ASTNodeType.Text]: generateTextAndInterpolation,
|
|
832
|
+
[ASTNodeType.Interpolation]: generateTextAndInterpolation,
|
|
833
|
+
[ASTNodeType.Element]: generateElement,
|
|
834
|
+
[ASTNodeType.If]: generateIf,
|
|
835
|
+
[ASTNodeType.For]: generateFor,
|
|
836
|
+
[ASTNodeType.Switch]: generateSwitch
|
|
837
837
|
};
|
|
838
838
|
constructor(_ast, _cssVariableName) {
|
|
839
839
|
this._ast = _ast;
|
|
@@ -1041,7 +1041,7 @@ var TokenType = /* @__PURE__ */ function(TokenType) {
|
|
|
1041
1041
|
return TokenType;
|
|
1042
1042
|
}({});
|
|
1043
1043
|
//#endregion
|
|
1044
|
-
//#region ../packages/compiler/src/lexer/states/attribute-value.state.ts
|
|
1044
|
+
//#region ../packages/compiler/src/lexer/states/lex-attribute-value.state.ts
|
|
1045
1045
|
/**
|
|
1046
1046
|
* Consumes a quoted attribute value `"..."`, collecting characters until
|
|
1047
1047
|
* the closing `"` is found. Emits an ATTRIBUTE_VALUE token and transitions
|
|
@@ -1051,7 +1051,7 @@ var TokenType = /* @__PURE__ */ function(TokenType) {
|
|
|
1051
1051
|
* @param _context - Unused lexer context.
|
|
1052
1052
|
* @returns Transition result with the ATTRIBUTE_VALUE token and the TAG_BODY state.
|
|
1053
1053
|
*/
|
|
1054
|
-
function
|
|
1054
|
+
function lexAttributeValue(cursor, _context) {
|
|
1055
1055
|
let read = true;
|
|
1056
1056
|
let value = "";
|
|
1057
1057
|
let retVal;
|
|
@@ -1075,7 +1075,7 @@ function consumeAttributeValue(cursor, _context) {
|
|
|
1075
1075
|
return retVal;
|
|
1076
1076
|
}
|
|
1077
1077
|
//#endregion
|
|
1078
|
-
//#region ../packages/compiler/src/lexer/states/attribute.state.ts
|
|
1078
|
+
//#region ../packages/compiler/src/lexer/states/lex-attribute.state.ts
|
|
1079
1079
|
/**
|
|
1080
1080
|
* Consumes an attribute name and optional value from the current position,
|
|
1081
1081
|
* transitioning back to TAG_BODY when a space, `/`, or `>` is encountered.
|
|
@@ -1085,7 +1085,7 @@ function consumeAttributeValue(cursor, _context) {
|
|
|
1085
1085
|
* @param _context - Unused lexer context.
|
|
1086
1086
|
* @returns Transition result with the ATTRIBUTE token and next state.
|
|
1087
1087
|
*/
|
|
1088
|
-
function
|
|
1088
|
+
function lexAttribute(cursor, _context) {
|
|
1089
1089
|
let read = true;
|
|
1090
1090
|
let attribute = "";
|
|
1091
1091
|
let retVal;
|
|
@@ -1173,7 +1173,7 @@ function addCharacter$3(cursor, expression) {
|
|
|
1173
1173
|
return `${expression}${cursor.currentChar.value}`;
|
|
1174
1174
|
}
|
|
1175
1175
|
//#endregion
|
|
1176
|
-
//#region ../packages/compiler/src/lexer/states/case-flow-control-condition.state.ts
|
|
1176
|
+
//#region ../packages/compiler/src/lexer/states/lex-case-flow-control-condition.state.ts
|
|
1177
1177
|
/**
|
|
1178
1178
|
* Consumes the condition expression `(...)` of a flow-control directive,
|
|
1179
1179
|
* handling nested parentheses correctly. Emits a CONDITION token with the
|
|
@@ -1183,7 +1183,7 @@ function addCharacter$3(cursor, expression) {
|
|
|
1183
1183
|
* @param _context - Unused lexer context.
|
|
1184
1184
|
* @returns Transition result with the CONDITION token and the FLOW_CONTROL_BLOCK state.
|
|
1185
1185
|
*/
|
|
1186
|
-
function
|
|
1186
|
+
function lexCaseFlowControlCondition(cursor, _context) {
|
|
1187
1187
|
const condition = consumeFlowControlCondition(cursor, _context);
|
|
1188
1188
|
cursor.skipSpaces();
|
|
1189
1189
|
return {
|
|
@@ -1196,7 +1196,7 @@ function consumeCaseFlowControlCondition(cursor, _context) {
|
|
|
1196
1196
|
};
|
|
1197
1197
|
}
|
|
1198
1198
|
//#endregion
|
|
1199
|
-
//#region ../packages/compiler/src/lexer/states/default-flow-control-condition.state.ts
|
|
1199
|
+
//#region ../packages/compiler/src/lexer/states/lex-default-flow-control-condition.state.ts
|
|
1200
1200
|
/**
|
|
1201
1201
|
* Consumes the condition expression `(...)` of a flow-control directive,
|
|
1202
1202
|
* handling nested parentheses correctly. Emits a CONDITION token with the
|
|
@@ -1206,7 +1206,7 @@ function consumeCaseFlowControlCondition(cursor, _context) {
|
|
|
1206
1206
|
* @param _context - Unused lexer context.
|
|
1207
1207
|
* @returns Transition result with the CONDITION token and the FLOW_CONTROL_BLOCK state.
|
|
1208
1208
|
*/
|
|
1209
|
-
function
|
|
1209
|
+
function lexDefaultFlowControlCondition(cursor, _context) {
|
|
1210
1210
|
return {
|
|
1211
1211
|
state: LexerState.FLOW_CONTROL_BLOCK,
|
|
1212
1212
|
tokens: [{
|
|
@@ -1217,7 +1217,7 @@ function consumeDefaultFlowControlCondition(cursor, _context) {
|
|
|
1217
1217
|
};
|
|
1218
1218
|
}
|
|
1219
1219
|
//#endregion
|
|
1220
|
-
//#region ../packages/compiler/src/lexer/states/event-parameter.state.ts
|
|
1220
|
+
//#region ../packages/compiler/src/lexer/states/lex-event-parameter.state.ts
|
|
1221
1221
|
/**
|
|
1222
1222
|
* Consumes an event parameter and reads until a ',' or ')'.
|
|
1223
1223
|
* Emits an EVENT_ATTRIBUTE token containing the raw paremeter string.
|
|
@@ -1226,7 +1226,7 @@ function consumeDefaultFlowControlCondition(cursor, _context) {
|
|
|
1226
1226
|
* @param _context - Unused lexer context.
|
|
1227
1227
|
* @returns Transition result with the EVENT_PAREMETER token and the EVENT state.
|
|
1228
1228
|
*/
|
|
1229
|
-
function
|
|
1229
|
+
function lexEventParameter(cursor, _context) {
|
|
1230
1230
|
let read = true;
|
|
1231
1231
|
let eventParameter = "";
|
|
1232
1232
|
let charDelimiter = "";
|
|
@@ -1275,7 +1275,7 @@ function addCharacter$2(cursor, eventParameter) {
|
|
|
1275
1275
|
return `${eventParameter}${cursor.currentChar.value}`;
|
|
1276
1276
|
}
|
|
1277
1277
|
//#endregion
|
|
1278
|
-
//#region ../packages/compiler/src/lexer/states/event.state.ts
|
|
1278
|
+
//#region ../packages/compiler/src/lexer/states/lex-event.state.ts
|
|
1279
1279
|
/**
|
|
1280
1280
|
* Consumes a DOM event binding starting with `@` and reads until a delimiter
|
|
1281
1281
|
* (space, `/`, or `>`) is found. Emits an EVENT token containing the raw binding string.
|
|
@@ -1284,7 +1284,7 @@ function addCharacter$2(cursor, eventParameter) {
|
|
|
1284
1284
|
* @param _context - Unused lexer context.
|
|
1285
1285
|
* @returns Transition result with the EVENT token and the TAG_BODY state.
|
|
1286
1286
|
*/
|
|
1287
|
-
function
|
|
1287
|
+
function lexEvent(cursor, _context) {
|
|
1288
1288
|
let read = true;
|
|
1289
1289
|
let event = "";
|
|
1290
1290
|
let retVal;
|
|
@@ -1320,7 +1320,7 @@ function consumeEvent(cursor, _context) {
|
|
|
1320
1320
|
return retVal;
|
|
1321
1321
|
}
|
|
1322
1322
|
//#endregion
|
|
1323
|
-
//#region ../packages/compiler/src/lexer/states/flow-control.ts
|
|
1323
|
+
//#region ../packages/compiler/src/lexer/states/lex-flow-control.ts
|
|
1324
1324
|
/**
|
|
1325
1325
|
* Dispatches on a `@keyword` to determine which flow-control directive begins here.
|
|
1326
1326
|
* Recognises `@if`, `@for`, `@else`, `@switch`, `@case`, `@default`, and `@const`.
|
|
@@ -1330,7 +1330,7 @@ function consumeEvent(cursor, _context) {
|
|
|
1330
1330
|
* @param _context - Unused lexer context.
|
|
1331
1331
|
* @returns Transition result with the matching flow-control token and next state.
|
|
1332
1332
|
*/
|
|
1333
|
-
function
|
|
1333
|
+
function lexFlowControl(cursor, _context) {
|
|
1334
1334
|
let retVal;
|
|
1335
1335
|
cursor.advance();
|
|
1336
1336
|
if (cursor.peekMatch("for ")) {
|
|
@@ -1384,7 +1384,7 @@ function consumeFlowControl(cursor, _context) {
|
|
|
1384
1384
|
return retVal;
|
|
1385
1385
|
}
|
|
1386
1386
|
//#endregion
|
|
1387
|
-
//#region ../packages/compiler/src/lexer/states/flow-control-block.state.ts
|
|
1387
|
+
//#region ../packages/compiler/src/lexer/states/lex-flow-control-block.state.ts
|
|
1388
1388
|
/**
|
|
1389
1389
|
* Consumes the opening `{` of a flow-control block body,
|
|
1390
1390
|
* skipping any leading whitespace before it.
|
|
@@ -1399,7 +1399,7 @@ function consumeFlowControl(cursor, _context) {
|
|
|
1399
1399
|
* @param _context - Unused lexer context.
|
|
1400
1400
|
* @returns Transition result with the BLOCK_OPEN token and the TEXT state.
|
|
1401
1401
|
*/
|
|
1402
|
-
function
|
|
1402
|
+
function lexFlowControlBlock(cursor, _context) {
|
|
1403
1403
|
cursor.skipSpaces();
|
|
1404
1404
|
if (cursor.peek() !== 123) throw new Error(`Expected '{' but got '${String.fromCharCode(cursor.peek())}' at row ${cursor.position.row}, col ${cursor.position.column}`);
|
|
1405
1405
|
cursor.advance();
|
|
@@ -1410,7 +1410,7 @@ function consumeFlowControlBlock(cursor, _context) {
|
|
|
1410
1410
|
};
|
|
1411
1411
|
}
|
|
1412
1412
|
//#endregion
|
|
1413
|
-
//#region ../packages/compiler/src/lexer/states/interpolation-expression.state.ts
|
|
1413
|
+
//#region ../packages/compiler/src/lexer/states/lex-interpolation-expression.state.ts
|
|
1414
1414
|
/**
|
|
1415
1415
|
* Consumes a JavaScript expression interpolation `{ expression }`, tracking nested
|
|
1416
1416
|
* brace depth. Emits an INTERPOLATION_EXPRESSION token and pops the state stack to
|
|
@@ -1420,7 +1420,7 @@ function consumeFlowControlBlock(cursor, _context) {
|
|
|
1420
1420
|
* @param context - The lexer context used to retrieve the previous state for restoration.
|
|
1421
1421
|
* @returns Transition result with the INTERPOLATION_EXPRESSION token and restored state.
|
|
1422
1422
|
*/
|
|
1423
|
-
function
|
|
1423
|
+
function lexInterpolationExpression(cursor, context) {
|
|
1424
1424
|
let read = true;
|
|
1425
1425
|
let interpolation = "";
|
|
1426
1426
|
let deep = 1;
|
|
@@ -1475,7 +1475,7 @@ function addCharacter$1(cursor, interpolation) {
|
|
|
1475
1475
|
return `${interpolation}${cursor.currentChar.value}`;
|
|
1476
1476
|
}
|
|
1477
1477
|
//#endregion
|
|
1478
|
-
//#region ../packages/compiler/src/lexer/states/interpolation-literal.state.ts
|
|
1478
|
+
//#region ../packages/compiler/src/lexer/states/lex-interpolation-literal.state.ts
|
|
1479
1479
|
/**
|
|
1480
1480
|
* Consumes a template-literal interpolation `` {`...`} ``, collecting characters
|
|
1481
1481
|
* until the closing backtick followed by `}`. Emits an INTERPOLATION_LITERAL token
|
|
@@ -1485,7 +1485,7 @@ function addCharacter$1(cursor, interpolation) {
|
|
|
1485
1485
|
* @param context - The lexer context used to retrieve the previous state for restoration.
|
|
1486
1486
|
* @returns Transition result with the INTERPOLATION_LITERAL token and restored state.
|
|
1487
1487
|
*/
|
|
1488
|
-
function
|
|
1488
|
+
function lexInterpolationliteral(cursor, context) {
|
|
1489
1489
|
let read = true;
|
|
1490
1490
|
let interpolation = "`";
|
|
1491
1491
|
let retVal;
|
|
@@ -1530,7 +1530,7 @@ function addCharacter(cursor, interpolation) {
|
|
|
1530
1530
|
return `${interpolation}${cursor.currentChar.value}`;
|
|
1531
1531
|
}
|
|
1532
1532
|
//#endregion
|
|
1533
|
-
//#region ../packages/compiler/src/lexer/states/interpolation.state.ts
|
|
1533
|
+
//#region ../packages/compiler/src/lexer/states/lex-interpolation.state.ts
|
|
1534
1534
|
/**
|
|
1535
1535
|
* Dispatches between an expression and a literal interpolation after the opening `{`.
|
|
1536
1536
|
* Advances past `{` and any leading spaces, then inspects the next character:
|
|
@@ -1540,13 +1540,13 @@ function addCharacter(cursor, interpolation) {
|
|
|
1540
1540
|
* @param _context - Unused lexer context.
|
|
1541
1541
|
* @returns Transition result with the appropriate interpolation sub-state.
|
|
1542
1542
|
*/
|
|
1543
|
-
function
|
|
1543
|
+
function lexInterpolation(cursor, _context) {
|
|
1544
1544
|
cursor.advance();
|
|
1545
1545
|
cursor.skipSpaces();
|
|
1546
1546
|
return cursor.peek() === 96 ? { state: LexerState.INTERPOLATION_LITERAL } : { state: LexerState.INTERPOLATION_EXPRESSION };
|
|
1547
1547
|
}
|
|
1548
1548
|
//#endregion
|
|
1549
|
-
//#region ../packages/compiler/src/lexer/states/tag-body.state.ts
|
|
1549
|
+
//#region ../packages/compiler/src/lexer/states/lex-tag-body.state.ts
|
|
1550
1550
|
/**
|
|
1551
1551
|
* Scans the body of an open tag to determine what comes next:
|
|
1552
1552
|
* an event binding (`@`), an attribute, the end of the tag (`>` or `/`), or whitespace.
|
|
@@ -1556,7 +1556,7 @@ function consumeInterpolation(cursor, _context) {
|
|
|
1556
1556
|
* @param _context - Unused lexer context.
|
|
1557
1557
|
* @returns Transition result with the next state and no tokens.
|
|
1558
1558
|
*/
|
|
1559
|
-
function
|
|
1559
|
+
function lexTagBody(cursor, _context) {
|
|
1560
1560
|
let read = true;
|
|
1561
1561
|
let retVal;
|
|
1562
1562
|
while (read) switch (cursor.peek()) {
|
|
@@ -1579,7 +1579,7 @@ function consumeTagBody(cursor, _context) {
|
|
|
1579
1579
|
return retVal;
|
|
1580
1580
|
}
|
|
1581
1581
|
//#endregion
|
|
1582
|
-
//#region ../packages/compiler/src/lexer/states/tag-close.state.ts
|
|
1582
|
+
//#region ../packages/compiler/src/lexer/states/lex-tag-close.state.ts
|
|
1583
1583
|
/**
|
|
1584
1584
|
* Consumes a closing tag `</tagName>`, skipping the `</` prefix and any surrounding
|
|
1585
1585
|
* whitespace. Emits a TAG_CLOSE_NAME token with the tag name and transitions to TEXT.
|
|
@@ -1588,7 +1588,7 @@ function consumeTagBody(cursor, _context) {
|
|
|
1588
1588
|
* @param _context - Unused lexer context.
|
|
1589
1589
|
* @returns Transition result with the TAG_CLOSE_NAME token and the TEXT state.
|
|
1590
1590
|
*/
|
|
1591
|
-
function
|
|
1591
|
+
function lexTagClose(cursor, _context) {
|
|
1592
1592
|
let read = true;
|
|
1593
1593
|
let tagName = "";
|
|
1594
1594
|
let retVal;
|
|
@@ -1614,7 +1614,7 @@ function consumeTagClose(cursor, _context) {
|
|
|
1614
1614
|
return retVal;
|
|
1615
1615
|
}
|
|
1616
1616
|
//#endregion
|
|
1617
|
-
//#region ../packages/compiler/src/lexer/states/tag-open-end.state.ts
|
|
1617
|
+
//#region ../packages/compiler/src/lexer/states/lex-tag-open-end.state.ts
|
|
1618
1618
|
/**
|
|
1619
1619
|
* Consumes the closing characters of an open tag: `>` emits TAG_OPEN_END and
|
|
1620
1620
|
* transitions to TEXT, while `/>` emits TAG_SELF_CLOSE and also transitions to TEXT.
|
|
@@ -1623,7 +1623,7 @@ function consumeTagClose(cursor, _context) {
|
|
|
1623
1623
|
* @param _context - Unused lexer context.
|
|
1624
1624
|
* @returns Transition result with TAG_OPEN_END or TAG_SELF_CLOSE and the TEXT state.
|
|
1625
1625
|
*/
|
|
1626
|
-
function
|
|
1626
|
+
function lexTagOpenEnd(cursor, _context) {
|
|
1627
1627
|
let retVal;
|
|
1628
1628
|
if (cursor.peek() === 62) {
|
|
1629
1629
|
cursor.advance();
|
|
@@ -1651,7 +1651,7 @@ function consumeTagOpenEnd(cursor, _context) {
|
|
|
1651
1651
|
return retVal;
|
|
1652
1652
|
}
|
|
1653
1653
|
//#endregion
|
|
1654
|
-
//#region ../packages/compiler/src/lexer/states/tag-open-name.state.ts
|
|
1654
|
+
//#region ../packages/compiler/src/lexer/states/lex-tag-open-name.state.ts
|
|
1655
1655
|
/**
|
|
1656
1656
|
* Consumes an opening tag name after `<`, reading until a space, `/`, or `>` is found.
|
|
1657
1657
|
* Emits a TAG_OPEN_NAME token with the tag name and transitions to TAG_BODY.
|
|
@@ -1660,7 +1660,7 @@ function consumeTagOpenEnd(cursor, _context) {
|
|
|
1660
1660
|
* @param _context - Unused lexer context.
|
|
1661
1661
|
* @returns Transition result with the TAG_OPEN_NAME token and the TAG_BODY state.
|
|
1662
1662
|
*/
|
|
1663
|
-
function
|
|
1663
|
+
function lexTagOpenName(cursor, _context) {
|
|
1664
1664
|
let read = true;
|
|
1665
1665
|
let tagName = "";
|
|
1666
1666
|
let retVal;
|
|
@@ -1699,7 +1699,7 @@ function isNotBlank(str) {
|
|
|
1699
1699
|
return /\S/.test(str);
|
|
1700
1700
|
}
|
|
1701
1701
|
//#endregion
|
|
1702
|
-
//#region ../packages/compiler/src/lexer/states/text.state.ts
|
|
1702
|
+
//#region ../packages/compiler/src/lexer/states/lex-text.state.ts
|
|
1703
1703
|
/**
|
|
1704
1704
|
* Consumes plain text content, accumulating characters until a structural boundary
|
|
1705
1705
|
* is reached: `<` (tag open/close), `{` (interpolation), `@` (flow-control or event),
|
|
@@ -1709,7 +1709,7 @@ function isNotBlank(str) {
|
|
|
1709
1709
|
* @param context - The lexer context used to detect flow-control block boundaries.
|
|
1710
1710
|
* @returns Transition result with an optional TEXT token and the next state.
|
|
1711
1711
|
*/
|
|
1712
|
-
function
|
|
1712
|
+
function lexText(cursor, context) {
|
|
1713
1713
|
let read = true;
|
|
1714
1714
|
let text = "";
|
|
1715
1715
|
let retVal;
|
|
@@ -1940,22 +1940,22 @@ var Lexer = class {
|
|
|
1940
1940
|
* Maps each lexer state to its corresponding transition function.
|
|
1941
1941
|
*/
|
|
1942
1942
|
_states = {
|
|
1943
|
-
[LexerState.TEXT]:
|
|
1944
|
-
[LexerState.TAG_OPEN_NAME]:
|
|
1945
|
-
[LexerState.TAG_BODY]:
|
|
1946
|
-
[LexerState.TAG_OPEN_END]:
|
|
1947
|
-
[LexerState.TAG_CLOSE]:
|
|
1948
|
-
[LexerState.ATTRIBUTE]:
|
|
1949
|
-
[LexerState.ATTRIBUTE_VALUE]:
|
|
1950
|
-
[LexerState.EVENT]:
|
|
1951
|
-
[LexerState.EVENT_PARAMETER]:
|
|
1952
|
-
[LexerState.FLOW_CONTROL]:
|
|
1953
|
-
[LexerState.FLOW_CONTROL_CONDITION]:
|
|
1954
|
-
[LexerState.CASE_FLOW_CONTROL_CONDITION]:
|
|
1955
|
-
[LexerState.FLOW_CONTROL_BLOCK]:
|
|
1956
|
-
[LexerState.INTERPOLATION]:
|
|
1957
|
-
[LexerState.INTERPOLATION_EXPRESSION]:
|
|
1958
|
-
[LexerState.INTERPOLATION_LITERAL]:
|
|
1943
|
+
[LexerState.TEXT]: lexText,
|
|
1944
|
+
[LexerState.TAG_OPEN_NAME]: lexTagOpenName,
|
|
1945
|
+
[LexerState.TAG_BODY]: lexTagBody,
|
|
1946
|
+
[LexerState.TAG_OPEN_END]: lexTagOpenEnd,
|
|
1947
|
+
[LexerState.TAG_CLOSE]: lexTagClose,
|
|
1948
|
+
[LexerState.ATTRIBUTE]: lexAttribute,
|
|
1949
|
+
[LexerState.ATTRIBUTE_VALUE]: lexAttributeValue,
|
|
1950
|
+
[LexerState.EVENT]: lexEvent,
|
|
1951
|
+
[LexerState.EVENT_PARAMETER]: lexEventParameter,
|
|
1952
|
+
[LexerState.FLOW_CONTROL]: lexFlowControl,
|
|
1953
|
+
[LexerState.FLOW_CONTROL_CONDITION]: lexDefaultFlowControlCondition,
|
|
1954
|
+
[LexerState.CASE_FLOW_CONTROL_CONDITION]: lexCaseFlowControlCondition,
|
|
1955
|
+
[LexerState.FLOW_CONTROL_BLOCK]: lexFlowControlBlock,
|
|
1956
|
+
[LexerState.INTERPOLATION]: lexInterpolation,
|
|
1957
|
+
[LexerState.INTERPOLATION_EXPRESSION]: lexInterpolationExpression,
|
|
1958
|
+
[LexerState.INTERPOLATION_LITERAL]: lexInterpolationliteral
|
|
1959
1959
|
};
|
|
1960
1960
|
/**
|
|
1961
1961
|
* Creates a new Lexer instance for the given template content.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xaendar/compiler",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "A library for transpiling Xaendar Templates into JavaScript code",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@xaendar/common": "0.7.
|
|
20
|
-
"@xaendar/types": "0.7.
|
|
19
|
+
"@xaendar/common": "0.7.3",
|
|
20
|
+
"@xaendar/types": "0.7.3",
|
|
21
21
|
"typescript": "^6.0.3"
|
|
22
22
|
}
|
|
23
23
|
}
|