Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,33 @@ describe('extractLiquidTemplateVariables', () => {
expect(invalidVariables).to.have.lengthOf(0);
expect(validVariables[0].name).to.equal('payload.firstName');
});

it('should handle assign statements with whitespace control - both sides', () => {
const template = '{%- assign first_name = payload.first_name -%} Hello {{first_name}}';
const { validVariables, invalidVariables } = extractLiquidTemplateVariables({ template });

expect(validVariables).to.have.lengthOf(1);
expect(invalidVariables).to.have.lengthOf(0);
expect(validVariables[0].name).to.equal('payload.first_name');
});

it('should handle assign statements with whitespace control - left side only', () => {
const template = '{%- assign first_name = payload.first_name %} Hello {{first_name}}';
const { validVariables, invalidVariables } = extractLiquidTemplateVariables({ template });

expect(validVariables).to.have.lengthOf(1);
expect(invalidVariables).to.have.lengthOf(0);
expect(validVariables[0].name).to.equal('payload.first_name');
});

it('should handle assign statements with whitespace control - right side only', () => {
const template = '{% assign first_name = payload.first_name -%} Hello {{first_name}}';
const { validVariables, invalidVariables } = extractLiquidTemplateVariables({ template });

expect(validVariables).to.have.lengthOf(1);
expect(invalidVariables).to.have.lengthOf(0);
expect(validVariables[0].name).to.equal('payload.first_name');
});
});

describe('Capture tags', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ function processTagToken({
});
}
} else if (template instanceof AssignTag) {
// Extract assigned variable from token content: {% assign myVar = value %}
const assignMatch = output.match(/^\s*{%\s*assign\s+(\w+)\s*=\s*(.+?)\s*%}/);
// Extract assigned variable from token content: {% assign myVar = value %} or {%- assign myVar = value -%}
const assignMatch = output.match(/^\s*{%-?\s*assign\s+(\w+)\s*=\s*(.+?)\s*-?%}/);
if (assignMatch) {
const [, assignedVariable, valueExpression] = assignMatch;

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/utils/liquid-scope-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Scope = {
// Regex patterns for LiquidJS syntax
const LIQUID_PATTERNS = {
// Variable assignment
assign: /{%\s*assign\s+(\w+)\s*=[^%]+%}/g,
assign: /{%-?\s*assign\s+(\w+)\s*=[^%]+-?%}/g,

// Loop constructs
for: /{%\s*for\s+(\w+)\s+in\s+[^%]+%}/g,
Expand Down
Loading