@platformos/platformos-check-common 0.0.11 → 0.0.13
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/CHANGELOG.md +39 -0
- package/CLAUDE.md +150 -0
- package/dist/AugmentedPlatformOSDocset.js +1 -0
- package/dist/AugmentedPlatformOSDocset.js.map +1 -1
- package/dist/checks/circular-render/index.d.ts +2 -0
- package/dist/checks/circular-render/index.js +164 -0
- package/dist/checks/circular-render/index.js.map +1 -0
- package/dist/checks/deprecated-filter/index.js +15 -0
- package/dist/checks/deprecated-filter/index.js.map +1 -1
- package/dist/checks/duplicate-content-for-arguments/index.js +1 -1
- package/dist/checks/duplicate-content-for-arguments/index.js.map +1 -1
- package/dist/checks/graphql/index.d.ts +1 -0
- package/dist/checks/graphql/index.js +20 -7
- package/dist/checks/graphql/index.js.map +1 -1
- package/dist/checks/index.d.ts +1 -1
- package/dist/checks/index.js +6 -0
- package/dist/checks/index.js.map +1 -1
- package/dist/checks/invalid-hash-assign-target/index.js +4 -3
- package/dist/checks/invalid-hash-assign-target/index.js.map +1 -1
- package/dist/checks/missing-content-for-arguments/index.js +1 -1
- package/dist/checks/missing-content-for-arguments/index.js.map +1 -1
- package/dist/checks/missing-page/index.d.ts +2 -0
- package/dist/checks/missing-page/index.js +73 -0
- package/dist/checks/missing-page/index.js.map +1 -0
- package/dist/checks/missing-partial/index.js +31 -31
- package/dist/checks/missing-partial/index.js.map +1 -1
- package/dist/checks/missing-render-partial-arguments/index.d.ts +2 -0
- package/dist/checks/missing-render-partial-arguments/index.js +37 -0
- package/dist/checks/missing-render-partial-arguments/index.js.map +1 -0
- package/dist/checks/nested-graphql-query/index.d.ts +2 -0
- package/dist/checks/nested-graphql-query/index.js +146 -0
- package/dist/checks/nested-graphql-query/index.js.map +1 -0
- package/dist/checks/pagination-size/index.js +1 -1
- package/dist/checks/pagination-size/index.js.map +1 -1
- package/dist/checks/translation-key-exists/index.js +16 -19
- package/dist/checks/translation-key-exists/index.js.map +1 -1
- package/dist/checks/translation-utils.d.ts +20 -0
- package/dist/checks/translation-utils.js +51 -0
- package/dist/checks/translation-utils.js.map +1 -0
- package/dist/checks/undefined-object/index.js +35 -13
- package/dist/checks/undefined-object/index.js.map +1 -1
- package/dist/checks/unknown-property/index.js +75 -10
- package/dist/checks/unknown-property/index.js.map +1 -1
- package/dist/checks/unknown-property/property-shape.js +14 -1
- package/dist/checks/unknown-property/property-shape.js.map +1 -1
- package/dist/checks/unrecognized-content-for-arguments/index.js +1 -1
- package/dist/checks/unrecognized-content-for-arguments/index.js.map +1 -1
- package/dist/checks/unused-assign/index.js +23 -1
- package/dist/checks/unused-assign/index.js.map +1 -1
- package/dist/checks/unused-translation-key/index.d.ts +4 -0
- package/dist/checks/unused-translation-key/index.js +85 -0
- package/dist/checks/unused-translation-key/index.js.map +1 -0
- package/dist/checks/valid-content-for-argument-types/index.js +1 -1
- package/dist/checks/valid-content-for-argument-types/index.js.map +1 -1
- package/dist/checks/valid-render-partial-argument-types/index.js +2 -1
- package/dist/checks/valid-render-partial-argument-types/index.js.map +1 -1
- package/dist/checks/variable-name/index.js +4 -0
- package/dist/checks/variable-name/index.js.map +1 -1
- package/dist/context-utils.d.ts +2 -1
- package/dist/context-utils.js +31 -1
- package/dist/context-utils.js.map +1 -1
- package/dist/doc-generator/DocBlockGenerator.d.ts +16 -0
- package/dist/doc-generator/DocBlockGenerator.js +464 -0
- package/dist/doc-generator/DocBlockGenerator.js.map +1 -0
- package/dist/doc-generator/index.d.ts +1 -0
- package/dist/doc-generator/index.js +6 -0
- package/dist/doc-generator/index.js.map +1 -0
- package/dist/frontmatter/index.d.ts +59 -0
- package/dist/frontmatter/index.js +301 -0
- package/dist/frontmatter/index.js.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/liquid-doc/arguments.js +9 -0
- package/dist/liquid-doc/arguments.js.map +1 -1
- package/dist/liquid-doc/utils.d.ts +10 -2
- package/dist/liquid-doc/utils.js +26 -1
- package/dist/liquid-doc/utils.js.map +1 -1
- package/dist/path.d.ts +1 -1
- package/dist/path.js +3 -1
- package/dist/path.js.map +1 -1
- package/dist/to-schema.d.ts +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.js.map +1 -1
- package/dist/url-helpers.d.ts +55 -0
- package/dist/url-helpers.js +334 -0
- package/dist/url-helpers.js.map +1 -0
- package/dist/utils/block.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/levenshtein.d.ts +3 -0
- package/dist/utils/levenshtein.js +39 -0
- package/dist/utils/levenshtein.js.map +1 -0
- package/package.json +2 -2
- package/src/AugmentedPlatformOSDocset.ts +1 -0
- package/src/checks/deprecated-filter/index.spec.ts +41 -1
- package/src/checks/deprecated-filter/index.ts +17 -0
- package/src/checks/graphql/index.spec.ts +173 -0
- package/src/checks/graphql/index.ts +21 -10
- package/src/checks/index.ts +6 -0
- package/src/checks/invalid-hash-assign-target/index.spec.ts +26 -0
- package/src/checks/invalid-hash-assign-target/index.ts +6 -4
- package/src/checks/missing-page/index.spec.ts +755 -0
- package/src/checks/missing-page/index.ts +89 -0
- package/src/checks/missing-partial/index.spec.ts +361 -0
- package/src/checks/missing-partial/index.ts +39 -47
- package/src/checks/missing-render-partial-arguments/index.spec.ts +74 -0
- package/src/checks/missing-render-partial-arguments/index.ts +44 -0
- package/src/checks/nested-graphql-query/index.spec.ts +175 -0
- package/src/checks/nested-graphql-query/index.ts +203 -0
- package/src/checks/parser-blocking-script/index.spec.ts +7 -3
- package/src/checks/translation-key-exists/index.spec.ts +79 -2
- package/src/checks/translation-key-exists/index.ts +18 -27
- package/src/checks/translation-utils.ts +63 -0
- package/src/checks/undefined-object/index.spec.ts +153 -19
- package/src/checks/undefined-object/index.ts +43 -19
- package/src/checks/unknown-property/index.spec.ts +133 -0
- package/src/checks/unknown-property/index.ts +84 -10
- package/src/checks/unknown-property/property-shape.ts +15 -1
- package/src/checks/unused-assign/index.spec.ts +75 -1
- package/src/checks/unused-assign/index.ts +26 -1
- package/src/checks/unused-doc-param/index.spec.ts +4 -2
- package/src/checks/valid-doc-param-types/index.spec.ts +1 -1
- package/src/checks/valid-render-partial-argument-types/index.spec.ts +24 -1
- package/src/checks/valid-render-partial-argument-types/index.ts +3 -2
- package/src/checks/variable-name/index.spec.ts +10 -1
- package/src/checks/variable-name/index.ts +5 -0
- package/src/context-utils.ts +33 -1
- package/src/frontmatter/index.ts +344 -0
- package/src/index.ts +6 -0
- package/src/liquid-doc/arguments.ts +9 -0
- package/src/liquid-doc/utils.ts +26 -2
- package/src/path.ts +2 -0
- package/src/types.ts +9 -1
- package/src/url-helpers.spec.ts +241 -0
- package/src/url-helpers.ts +363 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/levenshtein.ts +41 -0
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
BasicParamTypes,
|
|
14
14
|
getDefaultValueForType,
|
|
15
15
|
inferArgumentType,
|
|
16
|
+
isNullLiteral,
|
|
16
17
|
isTypeCompatible,
|
|
17
18
|
} from './utils';
|
|
18
19
|
import { isLiquidString } from '../checks/utils';
|
|
@@ -129,6 +130,13 @@ export function findTypeMismatchParams(
|
|
|
129
130
|
}
|
|
130
131
|
} else if (arg.value.type === NodeTypes.VariableLookup) {
|
|
131
132
|
continue;
|
|
133
|
+
} else if (arg.value.type === NodeTypes.NamedArgument) {
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// null/nil is compatible with any type — skip type checking
|
|
138
|
+
if (isNullLiteral(arg.value)) {
|
|
139
|
+
continue;
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
const liquidDocParamDef = liquidDocParameters.get(arg.name);
|
|
@@ -159,6 +167,7 @@ export function reportTypeMismatches(
|
|
|
159
167
|
for (const arg of typeMismatchArgs) {
|
|
160
168
|
const paramDef = liquidDocParameters.get(arg.name);
|
|
161
169
|
if (!paramDef || !paramDef.type) continue;
|
|
170
|
+
if (arg.value.type === NodeTypes.NamedArgument) continue;
|
|
162
171
|
|
|
163
172
|
const expectedType = paramDef.type.toLowerCase();
|
|
164
173
|
const actualType = inferArgumentType(arg.value);
|
package/src/liquid-doc/utils.ts
CHANGED
|
@@ -18,6 +18,11 @@ export enum BasicParamTypes {
|
|
|
18
18
|
Object = 'object',
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/** Inferred type for null/nil literals — not a valid @param type, only used in type mismatch messages. */
|
|
22
|
+
export const InferredNull = 'null' as const;
|
|
23
|
+
|
|
24
|
+
export type InferredParamType = BasicParamTypes | typeof InferredNull;
|
|
25
|
+
|
|
21
26
|
export enum SupportedDocTagTypes {
|
|
22
27
|
Param = 'param',
|
|
23
28
|
Example = 'example',
|
|
@@ -44,7 +49,7 @@ export function getDefaultValueForType(type: string | null) {
|
|
|
44
49
|
/**
|
|
45
50
|
* Casts the value of a LiquidNamedArgument to a string representing the type of the value.
|
|
46
51
|
*/
|
|
47
|
-
export function inferArgumentType(arg: LiquidExpression | LiquidVariable):
|
|
52
|
+
export function inferArgumentType(arg: LiquidExpression | LiquidVariable): InferredParamType {
|
|
48
53
|
if (arg.type === NodeTypes.LiquidVariable) {
|
|
49
54
|
// A variable with filters — delegate to the base expression if there are no filters,
|
|
50
55
|
// otherwise we can't statically determine the filtered output type.
|
|
@@ -59,6 +64,8 @@ export function inferArgumentType(arg: LiquidExpression | LiquidVariable): Basic
|
|
|
59
64
|
case NodeTypes.Number:
|
|
60
65
|
return BasicParamTypes.Number;
|
|
61
66
|
case NodeTypes.LiquidLiteral:
|
|
67
|
+
if (arg.value === null) return InferredNull;
|
|
68
|
+
if (arg.value === '') return BasicParamTypes.String;
|
|
62
69
|
return BasicParamTypes.Boolean;
|
|
63
70
|
case NodeTypes.Range:
|
|
64
71
|
case NodeTypes.VariableLookup:
|
|
@@ -71,12 +78,29 @@ export function inferArgumentType(arg: LiquidExpression | LiquidVariable): Basic
|
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Checks if a LiquidExpression is a null/nil literal.
|
|
83
|
+
* null/nil is compatible with any type — it represents "no value".
|
|
84
|
+
*/
|
|
85
|
+
export function isNullLiteral(arg: LiquidExpression | LiquidVariable): boolean {
|
|
86
|
+
if (arg.type === NodeTypes.LiquidVariable) {
|
|
87
|
+
if (arg.filters.length > 0) return false;
|
|
88
|
+
const expr = arg.expression;
|
|
89
|
+
if (expr.type === NodeTypes.BooleanExpression) return false;
|
|
90
|
+
return isNullLiteral(expr);
|
|
91
|
+
}
|
|
92
|
+
if (arg.type === NodeTypes.LiquidLiteral) {
|
|
93
|
+
return arg.value === null;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
74
98
|
/**
|
|
75
99
|
* Checks if the provided argument type is compatible with the expected type.
|
|
76
100
|
* Makes certain types more permissive:
|
|
77
101
|
* - Boolean accepts any value, since everything is truthy / falsy in Liquid
|
|
78
102
|
*/
|
|
79
|
-
export function isTypeCompatible(expectedType: string, actualType:
|
|
103
|
+
export function isTypeCompatible(expectedType: string, actualType: InferredParamType): boolean {
|
|
80
104
|
const normalizedExpectedType = expectedType.toLowerCase();
|
|
81
105
|
|
|
82
106
|
if (normalizedExpectedType === BasicParamTypes.Boolean) {
|
package/src/path.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LiquidHtmlNode, NodeTypes as LiquidHtmlNodeTypes } from '@platformos/li
|
|
|
2
2
|
|
|
3
3
|
import { Schema, Settings } from './types/schema-prop-factory';
|
|
4
4
|
|
|
5
|
-
import { AbstractFileSystem, UriString } from '@platformos/platformos-common';
|
|
5
|
+
import { AbstractFileSystem, RouteTable, UriString } from '@platformos/platformos-common';
|
|
6
6
|
import { JSONCorrector, StringCorrector } from './fixes';
|
|
7
7
|
|
|
8
8
|
import {
|
|
@@ -355,6 +355,12 @@ export interface Dependencies {
|
|
|
355
355
|
* Returns an empty array if no files reference this file
|
|
356
356
|
*/
|
|
357
357
|
getReferences?: (uri: string) => Promise<Reference[]>;
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Optional pre-built RouteTable. When provided (e.g. by the LSP),
|
|
361
|
+
* the check pipeline reuses it instead of building a new one per run.
|
|
362
|
+
*/
|
|
363
|
+
routeTable?: RouteTable;
|
|
358
364
|
}
|
|
359
365
|
|
|
360
366
|
export type ValidateJSON = (
|
|
@@ -377,6 +383,8 @@ export interface AugmentedDependencies extends Dependencies {
|
|
|
377
383
|
* Covers both `{base}/{locale}.yml` and `{base}/{locale}/*.yml`.
|
|
378
384
|
*/
|
|
379
385
|
getTranslationsForBase(translationBaseUri: string, locale: string): Promise<Translations>;
|
|
386
|
+
/** Lazily builds and returns a shared RouteTable for the current check run. */
|
|
387
|
+
getRouteTable(): Promise<RouteTable>;
|
|
380
388
|
}
|
|
381
389
|
|
|
382
390
|
type StaticContextProperties<T extends SourceCodeType> = T extends SourceCodeType
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
toLiquidHtmlAST,
|
|
4
|
+
NodeTypes,
|
|
5
|
+
HtmlElement,
|
|
6
|
+
LiquidTag,
|
|
7
|
+
LiquidTagAssign,
|
|
8
|
+
AssignMarkup,
|
|
9
|
+
LiquidHtmlNode,
|
|
10
|
+
} from '@platformos/liquid-html-parser';
|
|
11
|
+
import {
|
|
12
|
+
resolveAssignToUrlPattern,
|
|
13
|
+
extractUrlPattern,
|
|
14
|
+
isValuedAttrNode,
|
|
15
|
+
getAttrName,
|
|
16
|
+
ValuedAttrNode,
|
|
17
|
+
} from './url-helpers';
|
|
18
|
+
|
|
19
|
+
/** Parse a Liquid template and extract the first {% assign %} markup. */
|
|
20
|
+
function parseAssign(source: string): AssignMarkup {
|
|
21
|
+
const ast = toLiquidHtmlAST(source);
|
|
22
|
+
const assignTag = ast.children.find(
|
|
23
|
+
(n: LiquidHtmlNode) => n.type === NodeTypes.LiquidTag && (n as LiquidTag).name === 'assign',
|
|
24
|
+
) as LiquidTagAssign | undefined;
|
|
25
|
+
if (!assignTag) throw new Error('No assign tag found in: ' + source);
|
|
26
|
+
return assignTag.markup as AssignMarkup;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Parse HTML with an <a> tag and return the href attribute node. */
|
|
30
|
+
function parseHrefAttr(source: string): ValuedAttrNode {
|
|
31
|
+
const ast = toLiquidHtmlAST(source);
|
|
32
|
+
const aTag = ast.children.find(
|
|
33
|
+
(n: LiquidHtmlNode) =>
|
|
34
|
+
n.type === NodeTypes.HtmlElement && (n as HtmlElement).name[0].type === NodeTypes.TextNode,
|
|
35
|
+
) as HtmlElement | undefined;
|
|
36
|
+
if (!aTag) throw new Error('No HTML element found in: ' + source);
|
|
37
|
+
const href = (aTag.attributes as LiquidHtmlNode[]).find(
|
|
38
|
+
(a) => isValuedAttrNode(a) && getAttrName(a) === 'href',
|
|
39
|
+
);
|
|
40
|
+
if (!href || !isValuedAttrNode(href)) throw new Error('No href attribute found in: ' + source);
|
|
41
|
+
return href;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('resolveAssignToUrlPattern', () => {
|
|
45
|
+
describe('string literal base', () => {
|
|
46
|
+
it('resolves a simple string literal', () => {
|
|
47
|
+
const markup = parseAssign('{% assign url = "/about" %}');
|
|
48
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/about');
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('resolves a string with trailing slash', () => {
|
|
52
|
+
const markup = parseAssign('{% assign url = "/groups/" %}');
|
|
53
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/groups/');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('resolves a root path', () => {
|
|
57
|
+
const markup = parseAssign('{% assign url = "/" %}');
|
|
58
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('append filter', () => {
|
|
63
|
+
it('appends a string literal', () => {
|
|
64
|
+
const markup = parseAssign('{% assign url = "/groups" | append: "/edit" %}');
|
|
65
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/groups/edit');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('appends a variable as :_liquid_ placeholder', () => {
|
|
69
|
+
const markup = parseAssign('{% assign url = "/groups/" | append: group.id %}');
|
|
70
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/groups/:_liquid_');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('chains multiple append filters', () => {
|
|
74
|
+
const markup = parseAssign(
|
|
75
|
+
'{% assign url = "/groups/" | append: group.id | append: "/edit" %}',
|
|
76
|
+
);
|
|
77
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/groups/:_liquid_/edit');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('chains append with string and variable args', () => {
|
|
81
|
+
const markup = parseAssign(
|
|
82
|
+
'{% assign url = "/users/" | append: user.id | append: "/posts/" | append: post.id %}',
|
|
83
|
+
);
|
|
84
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/users/:_liquid_/posts/:_liquid_');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('prepend filter', () => {
|
|
89
|
+
it('prepends a string literal', () => {
|
|
90
|
+
const markup = parseAssign('{% assign url = "/edit" | prepend: "/groups" %}');
|
|
91
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/groups/edit');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('prepends a variable as :_liquid_ placeholder', () => {
|
|
95
|
+
const markup = parseAssign('{% assign url = "/edit" | prepend: group.id %}');
|
|
96
|
+
// Result is ":_liquid_/edit" — doesn't start with /, returns null
|
|
97
|
+
expect(resolveAssignToUrlPattern(markup)).toBe(null);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('chains prepend filters', () => {
|
|
101
|
+
const markup = parseAssign(
|
|
102
|
+
'{% assign url = "/edit" | prepend: user.id | prepend: "/users/" %}',
|
|
103
|
+
);
|
|
104
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/users/:_liquid_/edit');
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('mixed append and prepend', () => {
|
|
109
|
+
it('handles append then prepend', () => {
|
|
110
|
+
const markup = parseAssign('{% assign url = "/" | append: "edit" | prepend: "/groups" %}');
|
|
111
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/groups/edit');
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('variable lookup base', () => {
|
|
116
|
+
it('resolves a variable base to :_liquid_', () => {
|
|
117
|
+
const markup = parseAssign('{% assign url = base_path %}');
|
|
118
|
+
// Result is ":_liquid_" — doesn't start with /, returns null
|
|
119
|
+
expect(resolveAssignToUrlPattern(markup)).toBe(null);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('resolves a variable base with prepend to produce a valid URL', () => {
|
|
123
|
+
const markup = parseAssign('{% assign url = slug | prepend: "/" %}');
|
|
124
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/:_liquid_');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('resolves a variable base with append', () => {
|
|
128
|
+
const markup = parseAssign('{% assign url = base | append: "/edit" %}');
|
|
129
|
+
// Result is ":_liquid_/edit" — doesn't start with /, returns null
|
|
130
|
+
expect(resolveAssignToUrlPattern(markup)).toBe(null);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('returns null for unsupported patterns', () => {
|
|
135
|
+
it('returns null for << operator (array push)', () => {
|
|
136
|
+
const markup = parseAssign('{% assign arr << "/item" %}');
|
|
137
|
+
expect(resolveAssignToUrlPattern(markup)).toBe(null);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('returns null for non-append/prepend filters', () => {
|
|
141
|
+
const markup = parseAssign('{% assign url = "/ABOUT" | downcase %}');
|
|
142
|
+
expect(resolveAssignToUrlPattern(markup)).toBe(null);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('returns null for unknown filter in chain', () => {
|
|
146
|
+
const markup = parseAssign('{% assign url = "/groups" | append: "/edit" | strip %}');
|
|
147
|
+
expect(resolveAssignToUrlPattern(markup)).toBe(null);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('returns null when value does not start with /', () => {
|
|
151
|
+
const markup = parseAssign('{% assign url = "about" %}');
|
|
152
|
+
expect(resolveAssignToUrlPattern(markup)).toBe(null);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('returns null for number literal base', () => {
|
|
156
|
+
const markup = parseAssign('{% assign num = 42 %}');
|
|
157
|
+
expect(resolveAssignToUrlPattern(markup)).toBe(null);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('returns null when :_liquid_ is mixed with text in a segment', () => {
|
|
161
|
+
const markup = parseAssign('{% assign url = "/groups/group-" | append: group.id %}');
|
|
162
|
+
// Result would be "/groups/group-:_liquid_" — mixed segment
|
|
163
|
+
expect(resolveAssignToUrlPattern(markup)).toBe(null);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe('query string and fragment stripping', () => {
|
|
168
|
+
it('strips query string from resolved URL', () => {
|
|
169
|
+
const markup = parseAssign('{% assign url = "/search?q=test" %}');
|
|
170
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/search');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('strips fragment from resolved URL', () => {
|
|
174
|
+
const markup = parseAssign('{% assign url = "/page#section" %}');
|
|
175
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/page');
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('strips both query string and fragment', () => {
|
|
179
|
+
const markup = parseAssign('{% assign url = "/page?q=1#top" %}');
|
|
180
|
+
expect(resolveAssignToUrlPattern(markup)).toBe('/page');
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('extractUrlPattern with variableMap', () => {
|
|
186
|
+
it('resolves a single {{ var }} from variableMap', () => {
|
|
187
|
+
const variableMap = new Map([['url', '/about']]);
|
|
188
|
+
const attr = parseHrefAttr('<a href="{{ url }}">link</a>');
|
|
189
|
+
expect(extractUrlPattern(attr, variableMap)).toBe('/about');
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('resolves a tracked variable with :_liquid_ segments', () => {
|
|
193
|
+
const variableMap = new Map([['edit_url', '/users/:_liquid_/edit']]);
|
|
194
|
+
const attr = parseHrefAttr('<a href="{{ edit_url }}">edit</a>');
|
|
195
|
+
expect(extractUrlPattern(attr, variableMap)).toBe('/users/:_liquid_/edit');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('falls back to :_liquid_ for untracked variables', () => {
|
|
199
|
+
const variableMap = new Map<string, string>();
|
|
200
|
+
const attr = parseHrefAttr('<a href="{{ unknown_var }}">link</a>');
|
|
201
|
+
// Single dynamic variable with no static text → fully dynamic → null
|
|
202
|
+
expect(extractUrlPattern(attr, variableMap)).toBe(null);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('does not resolve variables with filters', () => {
|
|
206
|
+
const variableMap = new Map([['url', '/about']]);
|
|
207
|
+
const attr = parseHrefAttr('<a href="{{ url | escape }}">link</a>');
|
|
208
|
+
// Variable has a filter → not a simple variable → falls through to normal logic → fully dynamic
|
|
209
|
+
expect(extractUrlPattern(attr, variableMap)).toBe(null);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('does not resolve variables with lookups (e.g. url.path)', () => {
|
|
213
|
+
const variableMap = new Map([['url', '/about']]);
|
|
214
|
+
const attr = parseHrefAttr('<a href="{{ url.path }}">link</a>');
|
|
215
|
+
// Variable has lookups → not a simple variable → falls through → fully dynamic
|
|
216
|
+
expect(extractUrlPattern(attr, variableMap)).toBe(null);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('does not resolve when attr has multiple nodes (mixed static + variable)', () => {
|
|
220
|
+
const variableMap = new Map([['slug', 'about']]);
|
|
221
|
+
const attr = parseHrefAttr('<a href="/{{ slug }}">link</a>');
|
|
222
|
+
// attr.value.length > 1, so variableMap lookup is skipped; normal extraction applies
|
|
223
|
+
expect(extractUrlPattern(attr, variableMap)).toBe('/:_liquid_');
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('works without variableMap (backward compatible)', () => {
|
|
227
|
+
const attr = parseHrefAttr('<a href="/about">link</a>');
|
|
228
|
+
expect(extractUrlPattern(attr)).toBe('/about');
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('works with empty variableMap', () => {
|
|
232
|
+
const attr = parseHrefAttr('<a href="/about">link</a>');
|
|
233
|
+
expect(extractUrlPattern(attr, new Map())).toBe('/about');
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('resolves a tracked simple variable from variableMap', () => {
|
|
237
|
+
const variableMap = new Map([['url', '/about']]);
|
|
238
|
+
const attr = parseHrefAttr('<a href="{{ url }}">link</a>');
|
|
239
|
+
expect(extractUrlPattern(attr, variableMap)).toBe('/about');
|
|
240
|
+
});
|
|
241
|
+
});
|