@xaendar/compiler 0.7.22 → 0.7.24
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 +33 -18
- package/package.json +3 -3
|
@@ -891,7 +891,7 @@ var Generator = class {
|
|
|
891
891
|
generatedCode.push(...indent(["return context;"]), "}");
|
|
892
892
|
for (const [key, fnData] of this._nodeToProcess.entries()) {
|
|
893
893
|
const { node, parentNode, context, precode, anchor } = fnData.fn;
|
|
894
|
-
generatedCode.push(`\n${key}
|
|
894
|
+
generatedCode.push(`\n${key}(${fnData.args?.join(", ")}) {`, ...indent(["const context = new Context(this, parentContext);"]));
|
|
895
895
|
if (precode) generatedCode.push(indent(precode));
|
|
896
896
|
generatedCode.push(...indent([...node.children.map((child, i) => {
|
|
897
897
|
const result = this._processNode(child, parentNode, i.toString(), context, anchor ?? null);
|
|
@@ -2921,16 +2921,16 @@ function typeCheckElement(node, parentNode, index, context) {
|
|
|
2921
2921
|
} else return `${resolvedParameter}`;
|
|
2922
2922
|
}).join(", ");
|
|
2923
2923
|
const beginning = parsedEventParameter ? "($event)" : "()";
|
|
2924
|
-
retVal.code.push(`const ${nodeName}_${name} = ${beginning} => root.${handler}(${mappedParameters})
|
|
2924
|
+
retVal.code.push(`const ${nodeName}_${name} = ${beginning} => root.${handler}(${mappedParameters});`);
|
|
2925
2925
|
});
|
|
2926
|
-
if (node.children.length) retVal.functionsToProcess.set(`${nodeName}Children`, {
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2926
|
+
if (node.children.length) retVal.functionsToProcess.set(`${nodeName}Children`, { fn: {
|
|
2927
|
+
node,
|
|
2928
|
+
parentNode: {
|
|
2929
|
+
identifier: nodeName,
|
|
2930
|
+
type: "HTMLElement"
|
|
2931
2931
|
},
|
|
2932
|
-
|
|
2933
|
-
});
|
|
2932
|
+
context
|
|
2933
|
+
} });
|
|
2934
2934
|
return retVal;
|
|
2935
2935
|
}
|
|
2936
2936
|
//#endregion
|
|
@@ -2961,16 +2961,19 @@ function typeCheckFor(node, parentNode, index, compilerContext) {
|
|
|
2961
2961
|
retVal.functionsToProcess.set(forKey, {
|
|
2962
2962
|
fn: {
|
|
2963
2963
|
node,
|
|
2964
|
-
parentNode
|
|
2964
|
+
parentNode: {
|
|
2965
|
+
identifier: forKey,
|
|
2966
|
+
type: "HTMLElement"
|
|
2967
|
+
},
|
|
2965
2968
|
context: forContext
|
|
2966
2969
|
},
|
|
2967
2970
|
args: [`${itemsName}: typeof ${iterableExpr}`, `${counterName}: number`]
|
|
2968
2971
|
});
|
|
2969
|
-
retVal.code.push(`const ${forKey}_${itemsName} = ${iterableExpr}
|
|
2972
|
+
retVal.code.push(`const ${forKey}_${itemsName} = ${iterableExpr};`);
|
|
2970
2973
|
retVal.code.push(`const ${forKey}_${node.itemAlias} = ${resolveExpression(node.trackExpression, forContext, {
|
|
2971
2974
|
skipResolution: true,
|
|
2972
2975
|
resolver: `${iterableExpr}`
|
|
2973
|
-
})}
|
|
2976
|
+
})};`);
|
|
2974
2977
|
return retVal;
|
|
2975
2978
|
}
|
|
2976
2979
|
/**
|
|
@@ -3000,7 +3003,10 @@ function typeCheckIf(node, parentNode, index, compilerContext) {
|
|
|
3000
3003
|
retVal.code.push(`const ${ifKey} = ${resolveExpression(node.conditionNode, compilerContext, { resolver: "root" })};`);
|
|
3001
3004
|
retVal.functionsToProcess.set(ifKey, { fn: {
|
|
3002
3005
|
node,
|
|
3003
|
-
parentNode
|
|
3006
|
+
parentNode: {
|
|
3007
|
+
identifier: ifKey,
|
|
3008
|
+
type: "HTMLElement"
|
|
3009
|
+
},
|
|
3004
3010
|
context: ifContext
|
|
3005
3011
|
} });
|
|
3006
3012
|
let alt = node.alternate;
|
|
@@ -3012,7 +3018,10 @@ function typeCheckIf(node, parentNode, index, compilerContext) {
|
|
|
3012
3018
|
retVal.code.push(`const ${keyElseIf} = ${resolveExpression(conditionNode, compilerContext, { resolver: "root" })};`);
|
|
3013
3019
|
retVal.functionsToProcess.set(keyElseIf, { fn: {
|
|
3014
3020
|
node: alt,
|
|
3015
|
-
parentNode
|
|
3021
|
+
parentNode: {
|
|
3022
|
+
identifier: keyElseIf,
|
|
3023
|
+
type: "HTMLElement"
|
|
3024
|
+
},
|
|
3016
3025
|
context: elseIfContext
|
|
3017
3026
|
} });
|
|
3018
3027
|
alt = alt.alternate;
|
|
@@ -3023,7 +3032,10 @@ function typeCheckIf(node, parentNode, index, compilerContext) {
|
|
|
3023
3032
|
const keyElse = getBlockIdentifier("else", parentNode.identifier, index);
|
|
3024
3033
|
retVal.functionsToProcess.set(keyElse, { fn: {
|
|
3025
3034
|
node: alt,
|
|
3026
|
-
parentNode
|
|
3035
|
+
parentNode: {
|
|
3036
|
+
identifier: getBlockIdentifier("else", parentNode.identifier, index),
|
|
3037
|
+
type: "HTMLElement"
|
|
3038
|
+
},
|
|
3027
3039
|
context: elseContext
|
|
3028
3040
|
} });
|
|
3029
3041
|
}
|
|
@@ -3044,7 +3056,10 @@ function typeCheckSwitch(node, parentNode, index, compilerContext) {
|
|
|
3044
3056
|
const caseKey = caseNode.condition ? getBlockIdentifier("case", parentNode.identifier, `${index}_${i}`) : getBlockIdentifier("default", parentNode.identifier, index);
|
|
3045
3057
|
retVal.functionsToProcess.set(caseKey, { fn: {
|
|
3046
3058
|
node: caseNode,
|
|
3047
|
-
parentNode
|
|
3059
|
+
parentNode: {
|
|
3060
|
+
identifier: caseKey,
|
|
3061
|
+
type: "HTMLElement"
|
|
3062
|
+
},
|
|
3048
3063
|
context: caseContext
|
|
3049
3064
|
} });
|
|
3050
3065
|
caseNode.condition?.forEach((condition, i) => retVal.code.push(`const ${caseKey}_${i}: typeof ${expression} = ${condition};`));
|
|
@@ -3054,7 +3069,7 @@ function typeCheckSwitch(node, parentNode, index, compilerContext) {
|
|
|
3054
3069
|
//#endregion
|
|
3055
3070
|
//#region ../packages/compiler/src/type-checker/states/type-check-text-and-interpolation.state.ts
|
|
3056
3071
|
function typeCheckTextAndInterpolation(node, parentNode, index, compilerContext) {
|
|
3057
|
-
return { code: [`const ${getTextIdentifier("text", parentNode.identifier, index)} = ${node.type === ASTNodeType.Text ? node.value : resolveExpression(node.expression, compilerContext, { resolver: "root" })};`] };
|
|
3072
|
+
return { code: [`const ${getTextIdentifier("text", parentNode.identifier, index)} = ${node.type === ASTNodeType.Text ? `'${node.value}'` : resolveExpression(node.expression, compilerContext, { resolver: "root" })};`] };
|
|
3058
3073
|
}
|
|
3059
3074
|
//#endregion
|
|
3060
3075
|
//#region ../packages/compiler/src/type-checker/type-checker.ts
|
|
@@ -3091,7 +3106,7 @@ var TypeChecker = class {
|
|
|
3091
3106
|
generatedCode.push("}");
|
|
3092
3107
|
for (const [key, fnData] of this._nodeToProcess.entries()) {
|
|
3093
3108
|
const { node, parentNode, precode, context } = fnData.fn;
|
|
3094
|
-
generatedCode.push(`\nfunction ${key}
|
|
3109
|
+
generatedCode.push(`\nfunction ${key}(${fnData.args?.join(", ") ?? ""}): void {`);
|
|
3095
3110
|
if (precode) generatedCode.push(indent(precode));
|
|
3096
3111
|
generatedCode.push(...indent([...node.children.map((child, i) => {
|
|
3097
3112
|
const result = this._processNode(child, parentNode, i.toString(), context);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xaendar/compiler",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.24",
|
|
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.24",
|
|
20
|
+
"@xaendar/types": "0.7.24",
|
|
21
21
|
"typescript": "^6.0.3"
|
|
22
22
|
}
|
|
23
23
|
}
|