Skip to content

Commit b1c140e

Browse files
committed
refinement
1 parent 16dc4f8 commit b1c140e

6 files changed

Lines changed: 68 additions & 18 deletions

File tree

packages/b2c-tooling-sdk/src/operations/pipeline/generator/blocks.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,21 @@ function generateLoop(block: LoopBlock, context: GeneratorContext): string {
8080
const lines: string[] = [];
8181
const ind = indent(context.indent);
8282

83-
const iteratorVar = transformVariable(block.iteratorVar);
83+
// Transform iterator - handle dotted paths properly
84+
let iteratorVar = block.iteratorVar;
85+
if (iteratorVar.includes('.')) {
86+
const parts = iteratorVar.split('.');
87+
const firstPart = transformVariable(parts[0]);
88+
iteratorVar = [firstPart, ...parts.slice(1)].join('.');
89+
} else {
90+
iteratorVar = transformVariable(iteratorVar);
91+
}
92+
8493
const elementVar = block.elementVar;
8594

95+
// Track loop variable to avoid pdict prefixing inside loop body
96+
context.declaredVars.add(elementVar);
97+
8698
// Use for..of for iterators
8799
lines.push(`${ind}for (var ${elementVar} of ${iteratorVar}) {`);
88100

packages/b2c-tooling-sdk/src/operations/pipeline/generator/helpers.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ export function transformExpression(expr: string): string {
118118

119119
// Match capitalized identifiers that are NOT preceded by a dot (not property access)
120120
// and NOT followed by a dot or open paren (not a namespace or function call)
121-
result = result.replace(/(?<![.\w])([A-Z][a-zA-Z0-9_]*)(?!\s*[.(])/g, (match, name, offset) => {
121+
// Use word boundary \b to prevent backtracking from matching partial identifiers
122+
result = result.replace(/(?<![.\w])([A-Z][a-zA-Z0-9_]*)\b(?!\s*[.(])/g, (match, name, offset) => {
122123
// Skip our placeholder tokens
123124
if (name.startsWith('___') && name.endsWith('___')) {
124125
return match;
@@ -149,7 +150,29 @@ export function transformExpression(expr: string): string {
149150
* Transforms a pipeline variable reference to JavaScript.
150151
*/
151152
export function transformVariable(varRef: string): string {
152-
if (!varRef) return varRef;
153+
if (!varRef || varRef === 'null') return varRef;
154+
155+
// Don't transform JavaScript built-in names
156+
const jsBuiltins = new Set([
157+
'Object',
158+
'Array',
159+
'String',
160+
'Number',
161+
'Boolean',
162+
'Date',
163+
'Error',
164+
'JSON',
165+
'Math',
166+
'RegExp',
167+
'Function',
168+
'Symbol',
169+
'Map',
170+
'Set',
171+
'Promise',
172+
]);
173+
if (jsBuiltins.has(varRef)) {
174+
return varRef;
175+
}
153176

154177
// Apply known mappings
155178
for (const [prefix, replacement] of Object.entries(VARIABLE_MAPPINGS)) {

packages/b2c-tooling-sdk/src/operations/pipeline/generator/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ function generateFunction(func: AnalyzedFunction, context: GeneratorContext): st
105105
const bodyCode = generateBlock(func.body, context);
106106
if (bodyCode.trim()) {
107107
lines.push(bodyCode);
108+
} else {
109+
lines.push(`${indent(1)}// TODO: Empty pipeline - no nodes to convert`);
108110
}
109111

110112
lines.push('}');

packages/b2c-tooling-sdk/src/operations/pipeline/generator/nodes.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,32 @@ function generateCallNode(node: CallNodeIR, context: GeneratorContext): string {
198198
*/
199199
function generateJumpNode(node: JumpNodeIR, context: GeneratorContext): string {
200200
const ind = indent(context.indent);
201+
const lines: string[] = [];
201202

202203
// Dynamic dispatch - target determined at runtime from site preference
203204
if (node.isDynamic && node.dynamicKey) {
204-
return `${ind}// TODO: Dynamic pipeline jump - target resolved from key: ${node.dynamicKey}\n${ind}// Original: jump-node start-name-key="${node.dynamicKey}"`;
205+
lines.push(`${ind}// TODO: Dynamic pipeline jump - target resolved from key: ${node.dynamicKey}`);
206+
lines.push(`${ind}// Original: jump-node start-name-key="${node.dynamicKey}"`);
207+
} else {
208+
// Convert Pipeline-Start to Controller-Action URL
209+
lines.push(`${ind}response.redirect(URLUtils.url('${node.pipelineName}-${node.startName}'));`);
205210
}
211+
lines.push(`${ind}return;`);
206212

207-
// Convert Pipeline-Start to Controller-Action URL
208-
return `${ind}response.redirect(URLUtils.url('${node.pipelineName}-${node.startName}'));`;
213+
return lines.join('\n');
209214
}
210215

211216
/**
212217
* Generates code for an interaction node.
213218
*/
214219
function generateInteractionNode(node: InteractionNodeIR, context: GeneratorContext): string {
215220
const ind = indent(context.indent);
221+
const lines: string[] = [];
216222

217-
return `${ind}ISML.renderTemplate('${node.templateName}', pdict);`;
223+
lines.push(`${ind}ISML.renderTemplate('${node.templateName}', pdict);`);
224+
lines.push(`${ind}return;`);
225+
226+
return lines.join('\n');
218227
}
219228

220229
/**

packages/b2c-tooling-sdk/src/operations/pipeline/generator/pipelets/misc.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ export function generateUpdatePageMetaDataPipelet(node: PipeletNodeIR, context:
2626

2727
lines.push(`${ind}var pageMetaData = request.pageMetaData;`);
2828

29-
if (product) {
30-
lines.push(`${ind}pageMetaData.setTitle(${transformExpression(product)}.name);`);
31-
lines.push(`${ind}pageMetaData.setDescription(${transformExpression(product)}.shortDescription);`);
32-
} else if (category) {
33-
lines.push(`${ind}pageMetaData.setTitle(${transformExpression(category)}.displayName);`);
34-
lines.push(`${ind}pageMetaData.setDescription(${transformExpression(category)}.description);`);
35-
} else if (content) {
36-
lines.push(`${ind}pageMetaData.setTitle(${transformExpression(content)}.name);`);
37-
lines.push(`${ind}pageMetaData.setDescription(${transformExpression(content)}.description);`);
29+
// Only generate if binding exists and is not null
30+
if (product && product !== 'null') {
31+
const prodExpr = transformExpression(product);
32+
lines.push(`${ind}pageMetaData.setTitle(${prodExpr}.name);`);
33+
lines.push(`${ind}pageMetaData.setDescription(${prodExpr}.shortDescription);`);
34+
} else if (category && category !== 'null') {
35+
const catExpr = transformExpression(category);
36+
lines.push(`${ind}pageMetaData.setTitle(${catExpr}.displayName);`);
37+
lines.push(`${ind}pageMetaData.setDescription(${catExpr}.description);`);
38+
} else if (content && content !== 'null') {
39+
const contentExpr = transformExpression(content);
40+
lines.push(`${ind}pageMetaData.setTitle(${contentExpr}.name);`);
41+
lines.push(`${ind}pageMetaData.setDescription(${contentExpr}.description);`);
3842
}
3943

4044
return lines.join('\n');

packages/b2c-tooling-sdk/src/operations/pipeline/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ function parseNodeWrapper(
315315

316316
if (raw['key-binding']) {
317317
for (const kb of raw['key-binding']) {
318-
// Skip null bindings
319-
if (kb.$.alias !== 'null' || kb.$.key !== 'null') {
318+
// Skip null bindings - only add if BOTH alias and key are not 'null'
319+
if (kb.$.alias !== 'null' && kb.$.key !== 'null') {
320320
keyBindings.push({
321321
key: kb.$.key,
322322
value: kb.$.alias,

0 commit comments

Comments
 (0)