@xaendar/compiler 0.7.10 → 0.7.12
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 +14 -19
- package/package.json +3 -3
|
@@ -532,15 +532,12 @@ function generateElement(node, parentNode, index, compilerContext, anchor) {
|
|
|
532
532
|
fn: {
|
|
533
533
|
node,
|
|
534
534
|
parentNode: nodeName,
|
|
535
|
-
context: compilerContext
|
|
535
|
+
context: compilerContext,
|
|
536
|
+
precode: getPrecode(tagName)
|
|
536
537
|
},
|
|
537
|
-
args: [
|
|
538
|
-
nodeName,
|
|
539
|
-
"parentContext",
|
|
540
|
-
"namespace"
|
|
541
|
-
]
|
|
538
|
+
args: [nodeName, "parentContext"]
|
|
542
539
|
});
|
|
543
|
-
retval.code.push(`this.${nodeName}Children(${nodeName}, context
|
|
540
|
+
retval.code.push(`this.${nodeName}Children(${nodeName}, context);`);
|
|
544
541
|
}
|
|
545
542
|
return retval;
|
|
546
543
|
}
|
|
@@ -593,6 +590,13 @@ function mapEvents(events, compilerContext) {
|
|
|
593
590
|
compilerContext.removeIdentifier("$event");
|
|
594
591
|
return mappedEvents;
|
|
595
592
|
}
|
|
593
|
+
function getPrecode(tagName) {
|
|
594
|
+
switch (tagName) {
|
|
595
|
+
case "svg": return "context.createElement = (tagName) => document.createElementNS(SVG_NS, tagName).bind(document);";
|
|
596
|
+
case "math": return "context.createElement = (tagName) => document.createElementNS(MATHML_NS, tagName).bind(document);";
|
|
597
|
+
default: return "";
|
|
598
|
+
}
|
|
599
|
+
}
|
|
596
600
|
//#endregion
|
|
597
601
|
//#region ../packages/compiler/src/generator/states/generate-for.state.ts
|
|
598
602
|
/**
|
|
@@ -626,7 +630,7 @@ function mapEvents(events, compilerContext) {
|
|
|
626
630
|
* @param compilerContext - The enclosing scope context.
|
|
627
631
|
* @returns Array of generated code lines.
|
|
628
632
|
*/
|
|
629
|
-
function generateFor(node, parentNode, index, compilerContext
|
|
633
|
+
function generateFor(node, parentNode, index, compilerContext) {
|
|
630
634
|
const retVal = {
|
|
631
635
|
code: [],
|
|
632
636
|
functionsToProcess: /* @__PURE__ */ new Map()
|
|
@@ -670,7 +674,6 @@ function generateFor(node, parentNode, index, compilerContext, anchor) {
|
|
|
670
674
|
"parentContext",
|
|
671
675
|
itemsName,
|
|
672
676
|
counterName,
|
|
673
|
-
"namespace",
|
|
674
677
|
"anchor"
|
|
675
678
|
]
|
|
676
679
|
});
|
|
@@ -717,7 +720,6 @@ function generateIf(node, parentNode, index, compilerContext) {
|
|
|
717
720
|
args: [
|
|
718
721
|
ifKey,
|
|
719
722
|
"parentContext",
|
|
720
|
-
"namespace",
|
|
721
723
|
"anchor"
|
|
722
724
|
]
|
|
723
725
|
});
|
|
@@ -742,7 +744,6 @@ function generateIf(node, parentNode, index, compilerContext) {
|
|
|
742
744
|
args: [
|
|
743
745
|
parentNode,
|
|
744
746
|
"parentContext",
|
|
745
|
-
"namespace",
|
|
746
747
|
"anchor"
|
|
747
748
|
]
|
|
748
749
|
});
|
|
@@ -767,7 +768,6 @@ function generateIf(node, parentNode, index, compilerContext) {
|
|
|
767
768
|
args: [
|
|
768
769
|
parentNode,
|
|
769
770
|
"parentContext",
|
|
770
|
-
"namespace",
|
|
771
771
|
"anchor"
|
|
772
772
|
]
|
|
773
773
|
});
|
|
@@ -805,7 +805,6 @@ function generateSwitch(node, parentNode, index, compilerContext) {
|
|
|
805
805
|
args: [
|
|
806
806
|
caseKey,
|
|
807
807
|
"parentContext",
|
|
808
|
-
"namespace",
|
|
809
808
|
"anchor"
|
|
810
809
|
]
|
|
811
810
|
});
|
|
@@ -852,11 +851,7 @@ var Generator = class {
|
|
|
852
851
|
generate() {
|
|
853
852
|
this._nodeToProcess.clear();
|
|
854
853
|
const compilerContext = new CompilerContext();
|
|
855
|
-
const renderFunctions = ["_render() {", ...indent([
|
|
856
|
-
`const ${ROOT_NODE} = this._root;`,
|
|
857
|
-
"const context = new Context(this);",
|
|
858
|
-
"const namespace = undefined;"
|
|
859
|
-
])];
|
|
854
|
+
const renderFunctions = ["_render() {", ...indent([`const ${ROOT_NODE} = this._root;`, "const context = new Context(this, { createElement: document.createElement.bind(document), get: () => undefined });"])];
|
|
860
855
|
if (this._cssVariableName) renderFunctions.push(indent(`${ROOT_NODE}.adoptedStyleSheets = [${this._cssVariableName}];`));
|
|
861
856
|
for (let i = 0; i < this._ast.length; i++) {
|
|
862
857
|
const { code, functionsToProcess } = this._processNode(this._ast[i], ROOT_NODE, i.toString(), compilerContext, null);
|
|
@@ -867,7 +862,7 @@ var Generator = class {
|
|
|
867
862
|
for (const [key, fnData] of this._nodeToProcess.entries()) {
|
|
868
863
|
const { node, parentNode, context, precode, anchor } = fnData.fn;
|
|
869
864
|
renderFunctions.push(`\n${key}(${fnData.args?.join(", ")}) {`, ...indent([
|
|
870
|
-
"const context = new Context(this, parentContext
|
|
865
|
+
"const context = new Context(this, parentContext);",
|
|
871
866
|
...node.children.map((child, i) => {
|
|
872
867
|
const { code, functionsToProcess } = this._processNode(child, parentNode, i.toString(), context, anchor ?? null);
|
|
873
868
|
functionsToProcess?.forEach((value, key) => this._nodeToProcess.set(key, value));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xaendar/compiler",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.12",
|
|
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.12",
|
|
20
|
+
"@xaendar/types": "0.7.12",
|
|
21
21
|
"typescript": "^6.0.3"
|
|
22
22
|
}
|
|
23
23
|
}
|