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
91 changes: 84 additions & 7 deletions packages/liquid-html-parser/src/stage-1-cst.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2182,13 +2182,90 @@ describe('Unit: Stage 1 (CST)', () => {
});

it('should parse the theme_render_rc tag', () => {
for (const { toCST, expectPath } of testCases) {
cst = toCST(`{% theme_render_rc 'partial' %}`);
expectPath(cst, '0.type').to.equal('LiquidTag');
expectPath(cst, '0.name').to.equal('theme_render_rc');
expectPath(cst, '0.markup.type').to.equal('RenderMarkup');
expectPath(cst, '0.markup.partial.type').to.equal('String');
}
[
{
expression: `'partial'`,
partialType: 'String',
alias: null,
renderVariableExpression: null,
namedArguments: [],
},
{
expression: `'partial' as foo`,
partialType: 'String',
alias: {
value: 'foo',
},
renderVariableExpression: null,
namedArguments: [],
},
{
expression: `'partial' with product as item`,
partialType: 'String',
alias: {
value: 'item',
},
renderVariableExpression: {
kind: 'with',
name: {
type: 'VariableLookup',
},
},
namedArguments: [],
},
{
expression: `'partial' for products as product`,
partialType: 'String',
alias: {
value: 'product',
},
renderVariableExpression: {
kind: 'for',
name: {
type: 'VariableLookup',
},
},
namedArguments: [],
},
{
expression: `'my/partial', key1: val1, key2: "hi"`,
partialType: 'String',
alias: null,
renderVariableExpression: null,
namedArguments: [
{ name: 'key1', valueType: 'VariableLookup' },
{ name: 'key2', valueType: 'String' },
],
},
].forEach(
({ expression, partialType, renderVariableExpression, alias, namedArguments }) => {
for (const { toCST, expectPath } of testCases) {
cst = toCST(`{% theme_render_rc ${expression} -%}`);
expectPath(cst, '0.type').to.equal('LiquidTag');
expectPath(cst, '0.name').to.equal('theme_render_rc');
expectPath(cst, '0.markup.type').to.equal('RenderMarkup');
expectPath(cst, '0.markup.partial.type').to.equal(partialType);
if (renderVariableExpression) {
expectPath(cst, '0.markup.variable.type').to.equal('RenderVariableExpression');
expectPath(cst, '0.markup.variable.kind').to.equal(renderVariableExpression.kind);
expectPath(cst, '0.markup.variable.name.type').to.equal(
renderVariableExpression.name.type,
);
} else {
expectPath(cst, '0.markup.variable').to.equal(null);
}
expectPath(cst, '0.markup.alias.value').to.equal(alias?.value);
expectPath(cst, '0.markup.renderArguments').to.have.lengthOf(namedArguments.length);
namedArguments.forEach(({ name, valueType }, i) => {
expectPath(cst, `0.markup.renderArguments.${i}.type`).to.equal('NamedArgument');
expectPath(cst, `0.markup.renderArguments.${i}.name`).to.equal(name);
expectPath(cst, `0.markup.renderArguments.${i}.value.type`).to.equal(valueType);
});
expectPath(cst, '0.whitespaceStart').to.equal(null);
expectPath(cst, '0.whitespaceEnd').to.equal('-');
}
},
);
});

it('should parse the response_status tag', () => {
Expand Down
105 changes: 96 additions & 9 deletions packages/liquid-html-parser/src/stage-2-ast.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1543,15 +1543,102 @@ describe('Unit: Stage 2 (AST)', () => {
});

it('should parse the theme_render_rc tag', () => {
for (const { toAST, expectPath, expectPosition } of testCases) {
ast = toAST(`{% theme_render_rc 'partial' %}`);
expectPath(ast, 'children.0.type').to.equal('LiquidTag');
expectPath(ast, 'children.0.name').to.equal('theme_render_rc');
expectPath(ast, 'children.0.markup.type').to.equal('RenderMarkup');
expectPath(ast, 'children.0.markup.partial.type').to.equal('String');
expectPosition(ast, 'children.0');
expectPosition(ast, 'children.0.markup');
}
[
{
expression: `'partial'`,
partialType: 'String',
alias: null,
renderVariableExpression: null,
namedArguments: [],
},
{
expression: `'partial' as foo`,
partialType: 'String',
alias: {
value: 'foo',
},
renderVariableExpression: null,
namedArguments: [],
},
{
expression: `'partial' with product as item`,
partialType: 'String',
alias: {
value: 'item',
},
renderVariableExpression: {
kind: 'with',
name: {
type: 'VariableLookup',
},
},
namedArguments: [],
},
{
expression: `'partial' for products as product`,
partialType: 'String',
alias: {
value: 'product',
},
renderVariableExpression: {
kind: 'for',
name: {
type: 'VariableLookup',
},
},
namedArguments: [],
},
{
expression: `'my/partial', key1: val1, key2: "hi"`,
partialType: 'String',
alias: null,
renderVariableExpression: null,
namedArguments: [
{ name: 'key1', valueType: 'VariableLookup' },
{ name: 'key2', valueType: 'String' },
],
},
].forEach(
({ expression, partialType, renderVariableExpression, alias, namedArguments }) => {
for (const { toAST, expectPath, expectPosition } of testCases) {
ast = toAST(`{% theme_render_rc ${expression} -%}`);
expectPath(ast, 'children.0.type').to.equal('LiquidTag');
expectPath(ast, 'children.0.name').to.equal('theme_render_rc');
expectPath(ast, 'children.0.markup.type').to.equal('RenderMarkup');
expectPath(ast, 'children.0.markup.partial.type').to.equal(partialType);
if (renderVariableExpression) {
expectPath(ast, 'children.0.markup.variable.type').to.equal(
'RenderVariableExpression',
);
expectPath(ast, 'children.0.markup.variable.kind').to.equal(
renderVariableExpression.kind,
);
expectPath(ast, 'children.0.markup.variable.name.type').to.equal(
renderVariableExpression.name.type,
);
} else {
expectPath(ast, 'children.0.markup.variable').to.equal(null);
}
if (alias) {
expectPath(ast, 'children.0.markup.alias.value').to.equal(alias.value);
} else {
expectPath(ast, 'children.0.markup.alias').to.equal(null);
}
expectPath(ast, 'children.0.markup.args').to.have.lengthOf(namedArguments.length);
namedArguments.forEach(({ name, valueType }, i) => {
expectPath(ast, `children.0.markup.args.${i}.type`).to.equal('NamedArgument');
expectPath(ast, `children.0.markup.args.${i}.name`).to.equal(name);
expectPath(ast, `children.0.markup.args.${i}.value.type`).to.equal(valueType);
expectPosition(ast, `children.0.markup.args.${i}`);
expectPosition(ast, `children.0.markup.args.${i}.value`);
});
expectPath(ast, 'children.0.whitespaceStart').to.equal('');
expectPath(ast, 'children.0.whitespaceEnd').to.equal('-');
expectPosition(ast, 'children.0');
expectPosition(ast, 'children.0.markup');
}
},
);
});

it('should parse the response_status tag', () => {
Expand Down
29 changes: 10 additions & 19 deletions packages/platformos-check-common/src/checks/missing-page/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import {
HtmlElement,
LiquidTag,
NamedTags,
LiquidTagAssign,
AssignMarkup,
} from '@platformos/liquid-html-parser';
import { HtmlElement, LiquidTag } from '@platformos/liquid-html-parser';
import { RouteTable } from '@platformos/platformos-common';
import {
shouldSkipUrl,
isValuedAttrNode,
getAttrName,
extractUrlPattern,
getEffectiveMethod,
resolveAssignToUrlPattern,
tryExtractAssignUrl,
} from '../../url-helpers';
import { LiquidCheckDefinition, Severity, SourceCodeType } from '../../types';
import { isHtmlTag } from '../utils';
Expand Down Expand Up @@ -56,22 +50,19 @@ export const MissingPage: LiquidCheckDefinition = {
}

return {
async LiquidTag(node: LiquidTag) {
if (node.name !== NamedTags.assign) return;
const markup = (node as LiquidTagAssign).markup as AssignMarkup;
if (markup.lookups.length > 0) return;
async onCodePathStart() {
// Front-load the route table build so individual HtmlElement visits don't wait.
routeTable = await context.getRouteTable();
},

const urlPattern = resolveAssignToUrlPattern(markup);
if (urlPattern !== null) {
variableMap.set(markup.name, urlPattern);
async LiquidTag(node: LiquidTag) {
const extracted = tryExtractAssignUrl(node);
if (extracted) {
variableMap.set(extracted.name, extracted.urlPattern);
}
},

async HtmlElement(node) {
if (!routeTable) {
routeTable = await context.getRouteTable();
}

if (isHtmlTag(node, 'a')) {
const hrefAttr = node.attributes.find(
(a) => isValuedAttrNode(a) && getAttrName(a) === 'href',
Expand Down
Loading