@diplodoc/liquid 0.0.0-rc-fix-new-line-202509031344 → 0.0.0-rc-not-var-21673420971
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/README.md +128 -4
- package/lib/conditions.js +6 -0
- package/lib/conditions.js.map +1 -1
- package/lib/frontmatter.js +2 -5
- package/lib/frontmatter.js.map +1 -1
- package/lib/index.d.ts +95 -1
- package/lib/index.js +115 -6
- package/lib/index.js.map +1 -1
- package/lib/legacyConditions.d.ts +2 -0
- package/lib/legacyConditions.js +135 -0
- package/lib/legacyConditions.js.map +1 -0
- package/lib/sourcemap.js +3 -2
- package/lib/sourcemap.js.map +1 -1
- package/lib/syntax/evaluate.js +13 -2
- package/lib/syntax/evaluate.js.map +1 -1
- package/lib/syntax/lexical.js +19 -2
- package/lib/syntax/lexical.js.map +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/utils/cloneDeepWith.d.ts +9 -0
- package/lib/utils/cloneDeepWith.js +43 -0
- package/lib/utils/cloneDeepWith.js.map +1 -0
- package/lib/utils.js +6 -1
- package/lib/utils.js.map +1 -1
- package/package.json +13 -11
package/README.md
CHANGED
|
@@ -1,9 +1,133 @@
|
|
|
1
1
|
[](https://www.npmjs.org/package/@diplodoc/liquid)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @diplodoc/liquid
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A small and fast implementation of basic Liquid syntax for processing YFM (Yandex Flavored Markdown) documents. Provides template processing capabilities including variable substitutions, conditions, cycles (loops), and frontmatter handling.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Variable substitutions** — `{{ variable }}` syntax
|
|
10
|
+
- **Conditional blocks** — `{% if condition %}...{% endif %}`
|
|
11
|
+
- **Cycle/loop blocks** — `{% for item in collection %}...{% endfor %}`
|
|
12
|
+
- **Frontmatter processing** — YAML frontmatter extraction and processing
|
|
13
|
+
- **Source map support** — Optional source maps for debugging
|
|
14
|
+
- **Custom filters** — Extensible filter system
|
|
15
|
+
- **Code block preservation** — Handles code blocks without processing Liquid syntax inside
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @diplodoc/liquid
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Basic Example
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import {createContext, liquidDocument} from '@diplodoc/liquid';
|
|
29
|
+
|
|
30
|
+
// Create a context with logger and settings
|
|
31
|
+
const context = createContext({
|
|
32
|
+
info: console.log,
|
|
33
|
+
warn: console.warn,
|
|
34
|
+
error: console.error,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Process a document with variables
|
|
38
|
+
const template = `
|
|
39
|
+
---
|
|
40
|
+
title: {{ title }}
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
Hello, {{ name }}!
|
|
44
|
+
|
|
45
|
+
{% if showDetails %}
|
|
46
|
+
Details: {{ details }}
|
|
47
|
+
{% endif %}
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
const vars = {
|
|
51
|
+
title: 'My Document',
|
|
52
|
+
name: 'World',
|
|
53
|
+
showDetails: true,
|
|
54
|
+
details: 'Some important information',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const result = liquidDocument.call(context, template, vars);
|
|
58
|
+
// Result:
|
|
59
|
+
// ---
|
|
60
|
+
// title: My Document
|
|
61
|
+
// ---
|
|
62
|
+
//
|
|
63
|
+
// Hello, World!
|
|
64
|
+
//
|
|
65
|
+
// Details: Some important information
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Processing Snippets
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import {liquidSnippet} from '@diplodoc/liquid';
|
|
72
|
+
|
|
73
|
+
const snippet = 'Hello, {{ name }}!';
|
|
74
|
+
const vars = {name: 'World'};
|
|
75
|
+
|
|
76
|
+
const result = liquidSnippet.call(context, snippet, vars);
|
|
77
|
+
// Result: "Hello, World!"
|
|
9
78
|
```
|
|
79
|
+
|
|
80
|
+
### Processing JSON
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import {liquidJson} from '@diplodoc/liquid';
|
|
84
|
+
|
|
85
|
+
const json = {
|
|
86
|
+
title: '{{ title }}',
|
|
87
|
+
items: ['{{ item1 }}', '{{ item2 }}'],
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const vars = {
|
|
91
|
+
title: 'My Title',
|
|
92
|
+
item1: 'First',
|
|
93
|
+
item2: 'Second',
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const result = liquidJson.call(context, json, vars);
|
|
97
|
+
// Result: { title: 'My Title', items: ['First', 'Second'] }
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## API
|
|
101
|
+
|
|
102
|
+
### Functions
|
|
103
|
+
|
|
104
|
+
- **`liquidDocument(input, vars, sourcemap?)`** — Processes a full YFM document with frontmatter
|
|
105
|
+
- **`liquidSnippet(input, vars, sourcemap?)`** — Processes a Liquid template snippet (without frontmatter)
|
|
106
|
+
- **`liquidJson(json, vars)`** — Recursively processes Liquid syntax in JSON objects
|
|
107
|
+
- **`createContext(logger, settings?)`** — Creates a Liquid context for processing
|
|
108
|
+
|
|
109
|
+
### Types
|
|
110
|
+
|
|
111
|
+
- **`LiquidContext`** — Context object containing logger, settings, and optional path
|
|
112
|
+
- **`LiquidSettings`** — Configuration options for Liquid processing
|
|
113
|
+
- **`SourceMap`** — Source map for tracking transformations
|
|
114
|
+
|
|
115
|
+
See TypeScript definitions for detailed API documentation.
|
|
116
|
+
|
|
117
|
+
## Configuration
|
|
118
|
+
|
|
119
|
+
You can configure Liquid processing behavior via `LiquidSettings`:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
const context = createContext(logger, {
|
|
123
|
+
conditions: true, // Enable/disable conditions
|
|
124
|
+
cycles: true, // Enable/disable cycles
|
|
125
|
+
substitutions: true, // Enable/disable substitutions
|
|
126
|
+
conditionsInCode: false, // Process conditions in code blocks
|
|
127
|
+
keepNotVar: false, // Keep {{ var }} if variable not found
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
MIT
|
package/lib/conditions.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.applyConditions = applyConditions;
|
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const lexical_1 = require("./syntax/lexical");
|
|
9
9
|
const evaluate_1 = require("./syntax/evaluate");
|
|
10
|
+
const legacyConditions_1 = __importDefault(require("./legacyConditions"));
|
|
10
11
|
function resourcemap(source, ifTag, ifCon, sourcemap) {
|
|
11
12
|
const lines = sourcemap.lines(source);
|
|
12
13
|
const sourcel = sourcemap.location(ifTag.start + 1, ifTag.end - 1, lines);
|
|
@@ -139,6 +140,8 @@ function inlineConditions(content, vars, ifTag) {
|
|
|
139
140
|
const { conditions = true, keepConditionSyntaxOnTrue = false } = this.settings;
|
|
140
141
|
let ifCon = null;
|
|
141
142
|
for (const condition of ifTag) {
|
|
143
|
+
// In strict mode, missing variables return NoValue instead of undefined
|
|
144
|
+
// This affects condition evaluation - NoValue is considered falsy
|
|
142
145
|
const value = evaluate_1.evaluate.call(this, condition.expr, vars, conditions === 'strict');
|
|
143
146
|
if (condition.expr &&
|
|
144
147
|
(value === evaluate_1.NoValue || (keepConditionSyntaxOnTrue && value === true))) {
|
|
@@ -166,6 +169,9 @@ function inlineConditions(content, vars, ifTag) {
|
|
|
166
169
|
}
|
|
167
170
|
function applyConditions(input, vars, sourcemap) {
|
|
168
171
|
const { path } = this;
|
|
172
|
+
if (this.settings.legacyConditions) {
|
|
173
|
+
return legacyConditions_1.default.call(this, input, vars);
|
|
174
|
+
}
|
|
169
175
|
const tagStack = [];
|
|
170
176
|
// Consumes all between curly braces
|
|
171
177
|
// and all closest upon to first linebreak before and after braces.
|
package/lib/conditions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"conditions.js","sourceRoot":"","sources":["../src/conditions.ts"],"names":[],"mappings":";;;;;AAwOA,0CAoFC;AAzTD,kDAA0B;AAE1B,8CAAyC;AACzC,gDAAoD;AACpD,0EAAkD;AASlD,SAAS,WAAW,CAChB,MAAc,EACd,KAAkB,EAClB,KAAyB,EACzB,SAAoB;IAEpB,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC1E,MAAM,WAAW,GAAG,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,GAAG,CAAC;IAElD,IAAI,WAAW,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QACjC,OAAO;IACX,CAAC;IAED,IAAI,KAAK,EAAE,CAAC;QACR,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAElE,SAAS,CAAC,KAAK,CAAC;YACZ,MAAM,EAAE;gBACJ,EAAC,KAAK,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAC;gBAC1C,EAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,KAAK,GAAG,CAAC,EAAC;aACjD;SACJ,CAAC,CAAC;IACP,CAAC;SAAM,CAAC;QACJ,SAAS,CAAC,KAAK,CAAC,EAAC,MAAM,EAAE,CAA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AED,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;gBAE5C,MAAM,EAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;gBAEnF,IAAI,SAAS,EAAE,CAAC;oBACZ,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;gBAChD,CAAC;gBAED,QAAQ,CAAC,SAAS,GAAG,SAAS,CAAC;gBAC/B,KAAK,GAAG,MAAM,CAAC;gBAEf,MAAM;YACV,CAAC;YACD;gBACI,yBAAyB;gBACzB,4DAA4D;gBAC5D,QAAQ,CAAC,SAAS,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC7D,CAAC;IACL,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,IAAI,CAAC,CAAC,CAAC,OAAO,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/lib/frontmatter.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.composeFrontMatter = exports.extractFrontMatter = void 0;
|
|
7
4
|
const js_yaml_1 = require("js-yaml");
|
|
8
|
-
const cloneDeepWith_1 =
|
|
5
|
+
const cloneDeepWith_1 = require("./utils/cloneDeepWith");
|
|
9
6
|
const SEP = '---';
|
|
10
7
|
/**
|
|
11
8
|
* Temporary workaround to enable parsing YAML metadata from potentially
|
|
@@ -41,7 +38,7 @@ const extractFrontMatter = (content, options = {}) => {
|
|
|
41
38
|
return [{}, strippedContent, rawMeta];
|
|
42
39
|
}
|
|
43
40
|
return [
|
|
44
|
-
(0, cloneDeepWith_1.
|
|
41
|
+
(0, cloneDeepWith_1.cloneDeepWith)(loadedData, (v) => typeof v === 'string' ? unescapeLiquid(v) : undefined),
|
|
45
42
|
strippedContent,
|
|
46
43
|
rawMeta,
|
|
47
44
|
];
|
package/lib/frontmatter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../src/frontmatter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"frontmatter.js","sourceRoot":"","sources":["../src/frontmatter.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AAEnC,yDAAoD;AAMpD,MAAM,GAAG,GAAG,KAAK,CAAC;AAElB;;;;;;GAMG;AACH,MAAM,YAAY,GAAG,CAAC,OAAe,EAAU,EAAE,CAC7C,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,cAAc,GAAG,CAAC,cAAsB,EAAU,EAAE,CACtD,cAAc,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAErE,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,EAAE;IACtC,MAAM,EAAE,GAAG,8EAA8E,CAAC;IAC1F,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE/B,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAA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Ae,CAAC;IAC3B,CAAC;IAED,OAAO,GAAG,GAAG,KAAK,MAAM,KAAK,GAAG,KAAK,eAAe,EAAE,CAAC;AAC3D,CAAC,CAAC;AAXW,QAAA,kBAAkB,sBAW7B"}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,7 +4,101 @@ export type { LiquidContext } from './types';
|
|
|
4
4
|
export { evaluate, NoValue } from './syntax/evaluate';
|
|
5
5
|
export { SourceMap } from './sourcemap';
|
|
6
6
|
export { composeFrontMatter, extractFrontMatter } from './frontmatter';
|
|
7
|
+
/**
|
|
8
|
+
* Processes a Liquid template snippet (without frontmatter).
|
|
9
|
+
* Applies cycles, conditions, and substitutions based on context settings.
|
|
10
|
+
* Preserves code blocks from Liquid processing by default.
|
|
11
|
+
*
|
|
12
|
+
* **Processing Order** (current implementation):
|
|
13
|
+
* 1. Save code blocks (if conditionsInCode is false)
|
|
14
|
+
* 2. Process cycles
|
|
15
|
+
* 3. Process conditions
|
|
16
|
+
* 4. Process substitutions
|
|
17
|
+
* 5. Restore code blocks
|
|
18
|
+
*
|
|
19
|
+
* **Known Limitation**: The current order processes all cycles before conditions,
|
|
20
|
+
* which means cycles inside false condition branches are still expanded.
|
|
21
|
+
* A refactoring is planned to process constructs in document order.
|
|
22
|
+
*
|
|
23
|
+
* @param this - Liquid context
|
|
24
|
+
* @param input - Template string to process
|
|
25
|
+
* @param vars - Variables for Liquid processing
|
|
26
|
+
* @param sourcemap - Optional source map for tracking transformations
|
|
27
|
+
* @returns Processed string with Liquid syntax evaluated
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const snippet = 'Hello, {{ name }}!';
|
|
32
|
+
* const vars = { name: 'World' };
|
|
33
|
+
* const result = liquidSnippet.call(context, snippet, vars);
|
|
34
|
+
* // Result: "Hello, World!"
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
7
37
|
export declare function liquidSnippet(this: LiquidContext, input: string, vars: Record<string, unknown>, sourcemap?: SourceMap): string;
|
|
8
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Recursively processes Liquid syntax in JSON objects.
|
|
40
|
+
* Traverses the object structure and processes all string values with liquidSnippet.
|
|
41
|
+
*
|
|
42
|
+
* @param this - Liquid context
|
|
43
|
+
* @param json - JSON object to process
|
|
44
|
+
* @param vars - Variables for Liquid processing
|
|
45
|
+
* @returns Processed JSON object with Liquid syntax evaluated
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const json = { title: '{{ title }}', items: ['{{ item1 }}', '{{ item2 }}'] };
|
|
50
|
+
* const vars = { title: 'My Title', item1: 'First', item2: 'Second' };
|
|
51
|
+
* const result = liquidJson.call(context, json, vars);
|
|
52
|
+
* // Result: { title: 'My Title', items: ['First', 'Second'] }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function liquidJson(this: LiquidContext, json: Record<string, unknown>, vars: Record<string, unknown>): Record<string, unknown>;
|
|
56
|
+
/**
|
|
57
|
+
* Processes a full YFM document with frontmatter.
|
|
58
|
+
* Extracts and processes frontmatter separately, then processes the content body.
|
|
59
|
+
* Composes the result with processed frontmatter.
|
|
60
|
+
*
|
|
61
|
+
* **Frontmatter Processing**: Frontmatter is processed via `liquidJson` (not `liquidSnippet`)
|
|
62
|
+
* because it's extracted as an object structure, not a string. This allows processing
|
|
63
|
+
* Liquid syntax in all string values within the frontmatter object recursively.
|
|
64
|
+
*
|
|
65
|
+
* @param this - Liquid context
|
|
66
|
+
* @param input - Full YFM document string with optional frontmatter
|
|
67
|
+
* @param vars - Variables for Liquid processing
|
|
68
|
+
* @param sourcemap - Optional source map for tracking transformations
|
|
69
|
+
* @returns Processed document with frontmatter and content
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const document = `---
|
|
74
|
+
* title: {{ title }}
|
|
75
|
+
* ---
|
|
76
|
+
* Hello, {{ name }}!`;
|
|
77
|
+
* const vars = { title: 'My Document', name: 'World' };
|
|
78
|
+
* const result = liquidDocument.call(context, document, vars);
|
|
79
|
+
* // Result: "---\ntitle: My Document\n---\nHello, World!"
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
9
82
|
export declare function liquidDocument(this: LiquidContext, input: string, vars: Record<string, unknown>, sourcemap?: SourceMap): string;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a Liquid context for processing templates.
|
|
85
|
+
* The context contains logger and settings that control Liquid processing behavior.
|
|
86
|
+
*
|
|
87
|
+
* @param logger - Logger object with info, warn, and error methods
|
|
88
|
+
* @param settings - Optional settings to configure Liquid processing
|
|
89
|
+
* @returns Liquid context object
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const context = createContext({
|
|
94
|
+
* info: console.log,
|
|
95
|
+
* warn: console.warn,
|
|
96
|
+
* error: console.error,
|
|
97
|
+
* }, {
|
|
98
|
+
* conditions: true,
|
|
99
|
+
* cycles: true,
|
|
100
|
+
* substitutions: true,
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
10
104
|
export declare function createContext(logger: Logger, settings?: Partial<LiquidSettings>): LiquidContext;
|
package/lib/index.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.extractFrontMatter = exports.composeFrontMatter = exports.SourceMap = exports.NoValue = exports.evaluate = void 0;
|
|
7
4
|
exports.liquidSnippet = liquidSnippet;
|
|
8
5
|
exports.liquidJson = liquidJson;
|
|
9
6
|
exports.liquidDocument = liquidDocument;
|
|
10
7
|
exports.createContext = createContext;
|
|
11
|
-
const cloneDeepWith_1 = __importDefault(require("lodash/cloneDeepWith"));
|
|
12
8
|
const frontmatter_1 = require("./frontmatter");
|
|
13
9
|
const substitutions_1 = require("./substitutions");
|
|
14
10
|
const cycles_1 = require("./cycles");
|
|
15
11
|
const conditions_1 = require("./conditions");
|
|
16
12
|
const utils_1 = require("./utils");
|
|
13
|
+
const cloneDeepWith_1 = require("./utils/cloneDeepWith");
|
|
17
14
|
var evaluate_1 = require("./syntax/evaluate");
|
|
18
15
|
Object.defineProperty(exports, "evaluate", { enumerable: true, get: function () { return evaluate_1.evaluate; } });
|
|
19
16
|
Object.defineProperty(exports, "NoValue", { enumerable: true, get: function () { return evaluate_1.NoValue; } });
|
|
@@ -22,43 +19,155 @@ Object.defineProperty(exports, "SourceMap", { enumerable: true, get: function ()
|
|
|
22
19
|
var frontmatter_2 = require("./frontmatter");
|
|
23
20
|
Object.defineProperty(exports, "composeFrontMatter", { enumerable: true, get: function () { return frontmatter_2.composeFrontMatter; } });
|
|
24
21
|
Object.defineProperty(exports, "extractFrontMatter", { enumerable: true, get: function () { return frontmatter_2.extractFrontMatter; } });
|
|
22
|
+
/**
|
|
23
|
+
* Processes a Liquid template snippet (without frontmatter).
|
|
24
|
+
* Applies cycles, conditions, and substitutions based on context settings.
|
|
25
|
+
* Preserves code blocks from Liquid processing by default.
|
|
26
|
+
*
|
|
27
|
+
* **Processing Order** (current implementation):
|
|
28
|
+
* 1. Save code blocks (if conditionsInCode is false)
|
|
29
|
+
* 2. Process cycles
|
|
30
|
+
* 3. Process conditions
|
|
31
|
+
* 4. Process substitutions
|
|
32
|
+
* 5. Restore code blocks
|
|
33
|
+
*
|
|
34
|
+
* **Known Limitation**: The current order processes all cycles before conditions,
|
|
35
|
+
* which means cycles inside false condition branches are still expanded.
|
|
36
|
+
* A refactoring is planned to process constructs in document order.
|
|
37
|
+
*
|
|
38
|
+
* @param this - Liquid context
|
|
39
|
+
* @param input - Template string to process
|
|
40
|
+
* @param vars - Variables for Liquid processing
|
|
41
|
+
* @param sourcemap - Optional source map for tracking transformations
|
|
42
|
+
* @returns Processed string with Liquid syntax evaluated
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const snippet = 'Hello, {{ name }}!';
|
|
47
|
+
* const vars = { name: 'World' };
|
|
48
|
+
* const result = liquidSnippet.call(context, snippet, vars);
|
|
49
|
+
* // Result: "Hello, World!"
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
25
52
|
function liquidSnippet(input, vars, sourcemap) {
|
|
26
53
|
const { cycles = true, conditions = true, substitutions = true, conditionsInCode = false, } = this.settings;
|
|
27
54
|
const { saveCode, repairCode } = utils_1.codeUtils.call(this);
|
|
28
55
|
let output = input;
|
|
56
|
+
// Save code blocks before processing to preserve them from Liquid syntax processing
|
|
57
|
+
// This maintains source map line numbers by keeping the same number of lines
|
|
29
58
|
if (!conditionsInCode) {
|
|
30
59
|
output = saveCode(output, vars);
|
|
31
60
|
}
|
|
61
|
+
// NOTE: Current processing order (cycles -> conditions -> substitutions) is not ideal.
|
|
62
|
+
// Ideally, we should process tags in the order they appear in the document.
|
|
63
|
+
// This would allow us to skip cycles inside false condition branches.
|
|
64
|
+
// Refactoring is planned to implement proper sequential processing.
|
|
65
|
+
// Process cycles first (all {% for %} blocks)
|
|
32
66
|
if (cycles) {
|
|
33
67
|
output = cycles_1.applyCycles.call(this, output, vars, sourcemap);
|
|
34
68
|
}
|
|
69
|
+
// Process conditions (all {% if %} blocks)
|
|
70
|
+
// In strict mode, missing variables return NoValue instead of undefined
|
|
35
71
|
if (conditions) {
|
|
36
72
|
output = conditions_1.applyConditions.call(this, output, vars, sourcemap);
|
|
37
73
|
}
|
|
74
|
+
// Process substitutions last (all {{ variable }} patterns)
|
|
75
|
+
// This allows variables from cycles/conditions to be substituted
|
|
38
76
|
if (substitutions) {
|
|
39
77
|
output = substitutions_1.applySubstitutions.call(this, output, vars);
|
|
40
78
|
}
|
|
79
|
+
// Restore code blocks after processing
|
|
41
80
|
if (!conditionsInCode && typeof output === 'string') {
|
|
42
81
|
output = repairCode(output);
|
|
43
82
|
}
|
|
44
83
|
return output;
|
|
45
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Recursively processes Liquid syntax in JSON objects.
|
|
87
|
+
* Traverses the object structure and processes all string values with liquidSnippet.
|
|
88
|
+
*
|
|
89
|
+
* @param this - Liquid context
|
|
90
|
+
* @param json - JSON object to process
|
|
91
|
+
* @param vars - Variables for Liquid processing
|
|
92
|
+
* @returns Processed JSON object with Liquid syntax evaluated
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```typescript
|
|
96
|
+
* const json = { title: '{{ title }}', items: ['{{ item1 }}', '{{ item2 }}'] };
|
|
97
|
+
* const vars = { title: 'My Title', item1: 'First', item2: 'Second' };
|
|
98
|
+
* const result = liquidJson.call(context, json, vars);
|
|
99
|
+
* // Result: { title: 'My Title', items: ['First', 'Second'] }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
46
102
|
function liquidJson(json, vars) {
|
|
47
|
-
return (0, cloneDeepWith_1.
|
|
103
|
+
return (0, cloneDeepWith_1.cloneDeepWith)(json, (value) => typeof value === 'string' ? liquidSnippet.call(this, value, vars) : undefined);
|
|
48
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Processes a full YFM document with frontmatter.
|
|
107
|
+
* Extracts and processes frontmatter separately, then processes the content body.
|
|
108
|
+
* Composes the result with processed frontmatter.
|
|
109
|
+
*
|
|
110
|
+
* **Frontmatter Processing**: Frontmatter is processed via `liquidJson` (not `liquidSnippet`)
|
|
111
|
+
* because it's extracted as an object structure, not a string. This allows processing
|
|
112
|
+
* Liquid syntax in all string values within the frontmatter object recursively.
|
|
113
|
+
*
|
|
114
|
+
* @param this - Liquid context
|
|
115
|
+
* @param input - Full YFM document string with optional frontmatter
|
|
116
|
+
* @param vars - Variables for Liquid processing
|
|
117
|
+
* @param sourcemap - Optional source map for tracking transformations
|
|
118
|
+
* @returns Processed document with frontmatter and content
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* const document = `---
|
|
123
|
+
* title: {{ title }}
|
|
124
|
+
* ---
|
|
125
|
+
* Hello, {{ name }}!`;
|
|
126
|
+
* const vars = { title: 'My Document', name: 'World' };
|
|
127
|
+
* const result = liquidDocument.call(context, document, vars);
|
|
128
|
+
* // Result: "---\ntitle: My Document\n---\nHello, World!"
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
49
131
|
function liquidDocument(input, vars, sourcemap) {
|
|
132
|
+
// Normalize line endings to Unix format
|
|
50
133
|
const normalizedInput = input.replace(/\r\n/g, '\n');
|
|
134
|
+
// Extract frontmatter (returns [parsedObject, contentWithoutFrontmatter, rawFrontmatterString])
|
|
51
135
|
const [frontMatter, strippedContent, rawFrontmatter] = (0, frontmatter_1.extractFrontMatter)(normalizedInput);
|
|
136
|
+
// Process frontmatter as an object (allows recursive processing of nested structures)
|
|
52
137
|
const liquidedFrontMatter = liquidJson.call(this, frontMatter, vars);
|
|
53
138
|
const composedFrontmatter = (0, frontmatter_1.composeFrontMatter)(liquidedFrontMatter);
|
|
139
|
+
// Update source map if frontmatter was modified
|
|
140
|
+
// This is important for yfmlint to report errors on original line numbers
|
|
54
141
|
if (sourcemap && rawFrontmatter.length) {
|
|
55
142
|
sourcemap.patch({
|
|
56
143
|
replace: [[1, rawFrontmatter, composedFrontmatter]],
|
|
57
144
|
});
|
|
58
145
|
}
|
|
59
|
-
|
|
146
|
+
// Process content body as a string
|
|
147
|
+
const liquidedResult = liquidSnippet.call(this, strippedContent, vars, sourcemap);
|
|
60
148
|
return composedFrontmatter + liquidedResult;
|
|
61
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Creates a Liquid context for processing templates.
|
|
152
|
+
* The context contains logger and settings that control Liquid processing behavior.
|
|
153
|
+
*
|
|
154
|
+
* @param logger - Logger object with info, warn, and error methods
|
|
155
|
+
* @param settings - Optional settings to configure Liquid processing
|
|
156
|
+
* @returns Liquid context object
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* const context = createContext({
|
|
161
|
+
* info: console.log,
|
|
162
|
+
* warn: console.warn,
|
|
163
|
+
* error: console.error,
|
|
164
|
+
* }, {
|
|
165
|
+
* conditions: true,
|
|
166
|
+
* cycles: true,
|
|
167
|
+
* substitutions: true,
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
62
171
|
function createContext(logger, settings = {}) {
|
|
63
172
|
return {
|
|
64
173
|
logger,
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AA8CA,sCAmDC;AAmBD,gCAQC;AA4BD,wCA4BC;AAuBD,sCAQC;AAhND,+CAAqE;AACrE,mDAAmD;AACnD,qCAAqC;AACrC,6CAA6C;AAC7C,mCAAkC;AAClC,yDAAoD;AAIpD,8CAAoD;AAA5C,oGAAA,QAAQ,OAAA;AAAE,mGAAA,OAAO,OAAA;AACzB,yCAAsC;AAA9B,sGAAA,SAAS,OAAA;AACjB,6CAAqE;AAA7D,iHAAA,kBAAkB,OAAA;AAAE,iHAAA,kBAAkB,OAAA;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAgB,aAAa,CAEzB,KAAa,EACb,IAA6B,EAC7B,SAAqB;IAErB,MAAM,EACF,MAAM,GAAG,IAAI,EACb,UAAU,GAAG,IAAI,EACjB,aAAa,GAAG,IAAI,EACpB,gBAAgB,GAAG,KAAK,GAC3B,GAAG,IAAI,CAAC,QAAQ,CAAC;IAElB,MAAM,EAAC,QAAQ,EAAE,UAAU,EAAC,GAAG,iBAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEpD,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,oFAAoF;IACpF,6E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AqB;IAErB,wCAAwC;IACxC,MAAM,eAAe,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAErD,gGAAgG;IAChG,MAAM,CAAC,WAAW,EAAE,eAAe,EAAE,cAAc,CAAC,GAAG,IAAA,gCAAkB,EAAC,eAAe,CAAC,CAAC;IAE3F,sFAAsF;IACtF,MAAM,mBAAmB,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IACrE,MAAM,mBAAmB,GAAG,IAAA,gCAAkB,EAAC,mBAAmB,CAAC,CAAC;IAEpE,gDAAgD;IAChD,0EAA0E;IAC1E,IAAI,SAAS,IAAI,cAAc,CAAC,MAAM,EAAE,CAAC;QACrC,SAAS,CAAC,KAAK,CAAC;YACZ,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,mBAAmB,CAAC,CAAC;SACtD,CAAC,CAAC;IACP,CAAC;IAED,mCAAmC;IACnC,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;IAElF,OAAO,mBAAmB,GAAG,cAAc,CAAC;AAChD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,aAAa,CACzB,MAAc,EACd,WAAoC,EAAE;IAEtC,OAAO;QACH,MAAM;QACN,QAAQ;KACX,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = legacyConditions;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const lexical_1 = require("./syntax/lexical");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const evaluate_1 = require("./syntax/evaluate");
|
|
11
|
+
function getElseProp({ elses }, propName, index = 0) {
|
|
12
|
+
if (!elses.length || index >= elses.length) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return elses[index][propName];
|
|
16
|
+
}
|
|
17
|
+
function inlineConditions({ ifTag, vars, content, match, lastIndex }) {
|
|
18
|
+
let res = '';
|
|
19
|
+
if (evaluate_1.evaluate.call(this, ifTag.condition, vars)) {
|
|
20
|
+
const ifRawLastIndex = ifTag.startPos + ifTag.ifRaw.length;
|
|
21
|
+
const contentLastIndex = getElseProp(ifTag, 'startPos') || match.index;
|
|
22
|
+
res = content.substring(ifRawLastIndex, contentLastIndex);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
ifTag.elses.some(({ condition, startPos, raw }, index) => {
|
|
26
|
+
const isTruthy = !condition || evaluate_1.evaluate.call(this, condition, vars);
|
|
27
|
+
if (isTruthy) {
|
|
28
|
+
const elseRawLastIndex = startPos + raw.length;
|
|
29
|
+
const contentLastIndex = getElseProp(ifTag, 'startPos', index + 1) || match.index;
|
|
30
|
+
res = content.substring(elseRawLastIndex, contentLastIndex);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const preparedLeftContent = (0, utils_1.getPreparedLeftContent)({
|
|
37
|
+
content,
|
|
38
|
+
tagStartPos: ifTag.startPos,
|
|
39
|
+
tagContent: res,
|
|
40
|
+
});
|
|
41
|
+
let shift = 0;
|
|
42
|
+
if (res === '' &&
|
|
43
|
+
preparedLeftContent[preparedLeftContent.length - 1] === '\n' &&
|
|
44
|
+
content[lastIndex] === '\n') {
|
|
45
|
+
shift = 1;
|
|
46
|
+
}
|
|
47
|
+
if (res !== '') {
|
|
48
|
+
if (res[0] === '\n') {
|
|
49
|
+
res = res.substring(1);
|
|
50
|
+
}
|
|
51
|
+
res = (0, utils_1.removeIndentBlock)(res);
|
|
52
|
+
if (res[res.length - 1] === '\n') {
|
|
53
|
+
res = res.slice(0, -1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const leftPart = preparedLeftContent + res;
|
|
57
|
+
return {
|
|
58
|
+
result: leftPart + content.substring(lastIndex + shift),
|
|
59
|
+
idx: leftPart.length,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function legacyConditions(originInput, vars) {
|
|
63
|
+
const { path } = this;
|
|
64
|
+
const R_LIQUID = /({%-?([\s\S]*?)-?%})/g;
|
|
65
|
+
let match;
|
|
66
|
+
const tagStack = [];
|
|
67
|
+
let input = originInput;
|
|
68
|
+
while ((match = R_LIQUID.exec(input)) !== null) {
|
|
69
|
+
if (!match[1]) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const tagMatch = match[2].trim().match(lexical_1.tagLine);
|
|
73
|
+
if (!tagMatch) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const [type, args] = tagMatch.slice(1);
|
|
77
|
+
switch (type) {
|
|
78
|
+
case 'if':
|
|
79
|
+
tagStack.push({
|
|
80
|
+
condition: args,
|
|
81
|
+
startPos: match.index,
|
|
82
|
+
ifRaw: match[1],
|
|
83
|
+
elses: [],
|
|
84
|
+
});
|
|
85
|
+
break;
|
|
86
|
+
case 'else': {
|
|
87
|
+
const currentTag = tagStack[tagStack.length - 1];
|
|
88
|
+
if (!currentTag) {
|
|
89
|
+
this.logger.error(`Else block must have a preceding if block${path ? ` in ${chalk_1.default.bold(path)}` : ''}`);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
currentTag.elses.push({
|
|
93
|
+
startPos: match.index,
|
|
94
|
+
raw: match[1],
|
|
95
|
+
});
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case 'elsif': {
|
|
99
|
+
const currentTag = tagStack[tagStack.length - 1];
|
|
100
|
+
if (!currentTag) {
|
|
101
|
+
this.logger.error(`Elsif block must have a preceding if block${path ? ` in ${chalk_1.default.bold(path)}` : ''}`);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
currentTag.elses.push({
|
|
105
|
+
condition: args,
|
|
106
|
+
startPos: match.index,
|
|
107
|
+
raw: match[1],
|
|
108
|
+
});
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case 'endif': {
|
|
112
|
+
const ifTag = tagStack.pop();
|
|
113
|
+
if (!ifTag) {
|
|
114
|
+
this.logger.error(`If block must be opened before close${path ? ` in ${chalk_1.default.bold(path)}` : ''}`);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
const { idx, result } = inlineConditions.call(this, {
|
|
118
|
+
ifTag,
|
|
119
|
+
vars,
|
|
120
|
+
content: input,
|
|
121
|
+
match,
|
|
122
|
+
lastIndex: R_LIQUID.lastIndex,
|
|
123
|
+
});
|
|
124
|
+
R_LIQUID.lastIndex = idx;
|
|
125
|
+
input = result;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (tagStack.length !== 0) {
|
|
131
|
+
this.logger.error(`Condition block must be closed${path ? ` in ${chalk_1.default.bold(path)}` : ''}`);
|
|
132
|
+
}
|
|
133
|
+
return input;
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=legacyConditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacyConditions.js","sourceRoot":"","sources":["../src/legacyConditions.ts"],"names":[],"mappings":";;;;;AA6FA,mCAgGC;AA3LD,kDAA0B;AAE1B,8CAAyC;AACzC,mCAAkE;AAClE,gDAA2C;AAE3C,SAAS,WAAW,CAAwB,EAAC,KAAK,EAAmB,EAAE,QAAW,EAAE,KAAK,GAAG,CAAC;IACzF,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACzC,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,OAAO,K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I,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
package/lib/sourcemap.js
CHANGED
|
@@ -37,8 +37,9 @@ class SourceMap {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
// TODO:
|
|
41
|
-
//
|
|
40
|
+
// TODO: Consider memory optimization - clear lazy map after dump
|
|
41
|
+
// The lazy map could be cleared asynchronously after dump() is called
|
|
42
|
+
// to free memory, but this was not implemented to avoid potential race conditions
|
|
42
43
|
return lazy;
|
|
43
44
|
};
|
|
44
45
|
return new Proxy({}, {
|
package/lib/sourcemap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourcemap.js","sourceRoot":"","sources":["../src/sourcemap.ts"],"names":[],"mappings":";;;AAAA,MAAM,MAAM,GAAG;IACX,MAAM,EACF,CAAC,EAAC,KAAK,EAAE,GAAG,EAAgC,EAAE,EAAE,CAChD,CAAC,KAAa,EAAE,IAAqB,EAAE,EAAE;QACrC,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG,EAAE,CAAC;YACjC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;YACjB,OAAO,CAAC,CAAC,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAEL,MAAM,EACF,CAAC,CAAC,KAAK,EAAE,MAAM,CAAgC,EAAE,EAAE,CACnD,CAAC,KAAa,EAAE,EAAE;QACd,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC;YACjB,OAAO,KAAK,GAAG,MAAM,CAAC;QAC1B,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;CACR,CAAC;AAcF,MAAa,SAAS;IAKlB,YAAY,OAAe;QAJnB,YAAO,GAAe,EAAE,CAAC;QAK7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAA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GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACpB,QAAQ,CAAC,GAAG,GAAG,KAAK,GAAG,MAAM,CAAC;gBAC9B,MAAM;YACV,CAAC;YAED,KAAK,EAAE,CAAC;QACZ,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ;AA1JD,8BA0JC"}
|
package/lib/syntax/evaluate.js
CHANGED
|
@@ -53,7 +53,7 @@ const operators = {
|
|
|
53
53
|
try {
|
|
54
54
|
return filter(l);
|
|
55
55
|
}
|
|
56
|
-
catch (
|
|
56
|
+
catch (_a) {
|
|
57
57
|
if (!filter) {
|
|
58
58
|
throw new errors_1.SkippedEvalError('Cannot apply an unsupported filter', exp);
|
|
59
59
|
}
|
|
@@ -69,7 +69,7 @@ const operators = {
|
|
|
69
69
|
const { name, args } = parsed;
|
|
70
70
|
return l[name](...args);
|
|
71
71
|
}
|
|
72
|
-
catch (
|
|
72
|
+
catch (_a) {
|
|
73
73
|
if (!l) {
|
|
74
74
|
throw new errors_1.SkippedEvalError(`Cannot apply the function '${parsed === null || parsed === void 0 ? void 0 : parsed.name}' on an undefined variable`, exp);
|
|
75
75
|
}
|
|
@@ -78,6 +78,15 @@ const operators = {
|
|
|
78
78
|
}),
|
|
79
79
|
};
|
|
80
80
|
exports.NoValue = Symbol('NoValue');
|
|
81
|
+
/**
|
|
82
|
+
* Evaluates a value from a string expression.
|
|
83
|
+
* In strict mode, missing variables return NoValue instead of undefined.
|
|
84
|
+
*
|
|
85
|
+
* @param originStr - String expression to evaluate
|
|
86
|
+
* @param scope - Variable scope
|
|
87
|
+
* @param strict - If true, missing variables return NoValue; if false, return undefined
|
|
88
|
+
* @returns Evaluated value, NoValue (in strict mode), or undefined
|
|
89
|
+
*/
|
|
81
90
|
function evalValue(originStr, scope, strict) {
|
|
82
91
|
const str = originStr && originStr.trim();
|
|
83
92
|
if (!str) {
|
|
@@ -87,6 +96,8 @@ function evalValue(originStr, scope, strict) {
|
|
|
87
96
|
return lexical.parseLiteral(str);
|
|
88
97
|
}
|
|
89
98
|
if (lexical.isVariable(str)) {
|
|
99
|
+
// In strict mode, missing variables return NoValue (Symbol) instead of undefined
|
|
100
|
+
// This affects condition evaluation - NoValue is considered falsy
|
|
90
101
|
return (0, utils_1.getObject)(str, scope, strict ? exports.NoValue : undefined);
|
|
91
102
|
}
|
|
92
103
|
throw new TypeError(`cannot eval '${str}' as value`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../src/syntax/evaluate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../src/syntax/evaluate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2GA,4BAsEC;AA/KD,oCAA2C;AAC3C,sCAA2C;AAE3C,mDAAqC;AACrC,mDAAqC;AAYrC,MAAM,SAAS,GAAwD;IACnE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAa;IACrC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAa;IACrC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,CAAa;IAC9D,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,CAAa;IAC9D,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,CAAa;I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C,CAAC;YAC7B,OAAO,SAAS,CAAC;QACrB,CAAC;QAED,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
package/lib/syntax/lexical.js
CHANGED
|
@@ -7,8 +7,25 @@ const singleQuoted = /'[^']*'/;
|
|
|
7
7
|
const doubleQuoted = /"[^"]*"/;
|
|
8
8
|
const quoted = new RegExp(`${singleQuoted.source}|${doubleQuoted.source}`);
|
|
9
9
|
exports.quoteBalanced = new RegExp(`(?:${quoted.source}|[^'"])*`);
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// Jinja2 expression content:
|
|
11
|
+
// \w - identifiers (letters, digits, underscore)
|
|
12
|
+
// . - attribute access
|
|
13
|
+
// \- - hyphen in names, negative numbers
|
|
14
|
+
// | - filters
|
|
15
|
+
// () - function calls
|
|
16
|
+
// , - argument separator
|
|
17
|
+
// '" - string literals
|
|
18
|
+
// = - named parameters
|
|
19
|
+
// [] - indexing, subscript
|
|
20
|
+
// : - slices, dict literals
|
|
21
|
+
// +*/% - arithmetic operators
|
|
22
|
+
// <>! - comparison operators
|
|
23
|
+
// ~ - Jinja string concatenation
|
|
24
|
+
// @ - decorators (rare)
|
|
25
|
+
// \s already handled by space in character class
|
|
26
|
+
const varsContent = /[.\w\-|(),'=":[\]+*/%<>!~@\s]+/;
|
|
27
|
+
exports.vars = new RegExp(`((not_var)?({{2}(${varsContent.source})}{2}))`, 'gm');
|
|
28
|
+
exports.singleVariable = new RegExp(`^{{2}(${varsContent.source})}{2}$`);
|
|
12
29
|
// basic types
|
|
13
30
|
const number = /-?\d+\.?\d*|\.?\d+/;
|
|
14
31
|
const bool = /true|false/;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lexical.js","sourceRoot":"","sources":["../../src/syntax/lexical.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"lexical.js","sourceRoot":"","sources":["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AAC,UAAU,CAAC,CAAC;IAEhC,IAAI,GAAG,EAAE,CAAC;QACN,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IACD,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1B,IAAI,GAAG,EAAE,CAAC;QACN,OAAO,GAAG,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;IACxC,CAAC;IACD,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC5B,IAAI,GAAG,EAAE,CAAC;QACN,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,IAAI,SAAS,CAAC,iBAAiB,GAAG,cAAc,CAAC,CAAC;AAC5D,CAAC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively clones an object, applying a customizer function to each value.
|
|
3
|
+
* Similar to lodash's cloneDeepWith, but implemented natively.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to clone
|
|
6
|
+
* @param customizer - Function that produces custom cloned values
|
|
7
|
+
* @returns Cloned value
|
|
8
|
+
*/
|
|
9
|
+
export declare function cloneDeepWith<T>(value: T, customizer: (val: unknown) => unknown | undefined): T;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cloneDeepWith = cloneDeepWith;
|
|
4
|
+
/**
|
|
5
|
+
* Recursively clones an object, applying a customizer function to each value.
|
|
6
|
+
* Similar to lodash's cloneDeepWith, but implemented natively.
|
|
7
|
+
*
|
|
8
|
+
* @param value - The value to clone
|
|
9
|
+
* @param customizer - Function that produces custom cloned values
|
|
10
|
+
* @returns Cloned value
|
|
11
|
+
*/
|
|
12
|
+
function cloneDeepWith(value, customizer) {
|
|
13
|
+
if (value === null || typeof value !== 'object') {
|
|
14
|
+
const custom = customizer(value);
|
|
15
|
+
if (custom !== undefined) {
|
|
16
|
+
return custom;
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
if (value instanceof Date) {
|
|
21
|
+
return new Date(value.getTime());
|
|
22
|
+
}
|
|
23
|
+
if (value instanceof RegExp) {
|
|
24
|
+
return new RegExp(value);
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
return value.map((item) => cloneDeepWith(item, customizer));
|
|
28
|
+
}
|
|
29
|
+
const cloned = {};
|
|
30
|
+
for (const key in value) {
|
|
31
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
32
|
+
const custom = customizer(value[key]);
|
|
33
|
+
if (custom === undefined) {
|
|
34
|
+
cloned[key] = cloneDeepWith(value[key], customizer);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
cloned[key] = custom;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return cloned;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=cloneDeepWith.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloneDeepWith.js","sourceRoot":"","sources":["../../src/utils/cloneDeepWith.ts"],"names":[],"mappings":";;AAQA,sCAkCC;AA1CD;;;;;;;GAOG;AACH,SAAgB,aAAa,CAAI,KAAQ,EAAE,UAAiD;IACxF,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACvB,OAAO,MAAW,CAAC;QACvB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,IAAI,KAAK,YAAY,IAAI,EAAE,CAAC;QACxB,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAM,CAAC;IAC1C,CAAC;IAED,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;QAC1B,OAAO,IAAI,MAAM,CAAC,KAAK,CAAM,CAAC;IAClC,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,EAAE,UAAU,CAAC,CAAM,CAAC;IACrE,CAAC;IAED,MAAM,MAAM,GAAG,EAAO,CAAC;IACvB,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC;YACnD,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;YACtC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACvB,MAAM,CAAC,GAAG,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,UAAU,CAAC,CAAC;YACxD,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,GAAG,CAAC,GAAG,MAAqC,CAAC;YACxD,CAAC;QACL,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/lib/utils.js
CHANGED
|
@@ -48,13 +48,18 @@ function codeUtils() {
|
|
|
48
48
|
};
|
|
49
49
|
const saveCode = (str, vars) => {
|
|
50
50
|
return replace(fence, fence, (code) => {
|
|
51
|
+
// Apply substitutions to code blocks if enabled
|
|
52
|
+
// This allows variables in code examples to be processed
|
|
51
53
|
const codeWithVars = substitutions
|
|
52
54
|
? substitutions_1.applySubstitutions.call(this, code, vars)
|
|
53
55
|
: code;
|
|
54
56
|
const index = codes.push(codeWithVars) - 1;
|
|
55
|
-
|
|
57
|
+
// Keep the same number of lines to preserve source map accuracy
|
|
58
|
+
// Source maps are used by yfmlint to report errors on original line numbers
|
|
59
|
+
// The emptyLines preserve line count so source map mappings remain correct
|
|
56
60
|
const codeLines = codeWithVars.split('\n');
|
|
57
61
|
const emptyLines = codeLines.length > 1 ? '\n'.repeat(codeLines.length) : '';
|
|
62
|
+
// Return placeholder: index for lookup + empty lines for line count preservation
|
|
58
63
|
return `${index}${emptyLines}`;
|
|
59
64
|
}, str);
|
|
60
65
|
};
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAIA,8CAaC;AAQD,wDAQC;AAID,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;AAIA,8CAaC;AAQD,wDAQC;AAID,8BAoEC;AAGD,8BAeC;AAED,wBAMC;AAjID,mDAAmD;AAEnD,SAAgB,iBAAiB,CAAC,GAAW;IACzC,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;IACvB,IAAI,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IAErB,OAAO,OAAO,KAAK,GAAG,EAAE,CAAC;QACrB,OAAO,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC;AAQD,SAAgB,sBAAsB,CAAC,EAAC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAO;IAC3E,MAAM,mBAAmB,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;IAE9D,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;QACpB,OAAO,iBAAiB,CAAC,mBAAmB,CAAC,CAA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AAC,IAAI,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,EAAC,QAAQ,EAAE,UAAU,EAAC,CAAC;AAClC,CAAC;AAED,8DAA8D;AAC9D,SAAgB,SAAS,CAAC,IAAY,EAAE,GAAwB,EAAE,QAAc;IAC5E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE9B,IAAI,GAAG,GAAG,GAAG,CAAC;IACd,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,EAAY,CAAC;QAErC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;YACnD,OAAO,QAAQ,IAAI,SAAS,CAAC;QACjC,CAAC;QAED,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC;AAED,SAAgB,MAAM;IAClB,OAAO;QACH,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;KAClB,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diplodoc/liquid",
|
|
3
|
-
"version": "0.0.0-rc-
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "0.0.0-rc-not-var-21673420971",
|
|
4
|
+
"description": "A small and fast implementation of basic Liquid syntax for processing YFM (Yandex Flavored Markdown) documents",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
7
7
|
"yfm",
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"tools",
|
|
12
12
|
"generator"
|
|
13
13
|
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"npm": ">=11.5.1"
|
|
16
|
+
},
|
|
14
17
|
"homepage": "https://github.com/diplodoc-platform/liquid#readme",
|
|
15
18
|
"bugs": {
|
|
16
19
|
"url": "https://github.com/diplodoc-platform/liquid/issues"
|
|
@@ -37,7 +40,9 @@
|
|
|
37
40
|
"build:lib": "tsc -p tsconfig.transform.json",
|
|
38
41
|
"dev:lib": "tsc -w -p tsconfig.transform.json",
|
|
39
42
|
"prepublishOnly": "npm run lint && npm run test && npm run build",
|
|
40
|
-
"test": "
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"test:watch": "vitest",
|
|
45
|
+
"test:coverage": "vitest run --coverage",
|
|
41
46
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
42
47
|
"lint": "lint update && lint",
|
|
43
48
|
"lint:fix": "lint update && lint fix",
|
|
@@ -46,19 +51,16 @@
|
|
|
46
51
|
},
|
|
47
52
|
"dependencies": {
|
|
48
53
|
"chalk": "4",
|
|
49
|
-
"js-yaml": "^4.1.0"
|
|
50
|
-
"lodash": "^4.17.21"
|
|
54
|
+
"js-yaml": "^4.1.0"
|
|
51
55
|
},
|
|
52
56
|
"devDependencies": {
|
|
53
|
-
"@diplodoc/lint": "^1.2
|
|
57
|
+
"@diplodoc/lint": "^1.9.2",
|
|
54
58
|
"@diplodoc/tsconfig": "^1.0.2",
|
|
55
|
-
"@types/jest": "^28.1.7",
|
|
56
59
|
"@types/js-yaml": "^4.0.9",
|
|
57
|
-
"@
|
|
58
|
-
"jest": "^29.7.0",
|
|
60
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
59
61
|
"npm-run-all": "^4.1.5",
|
|
60
62
|
"ts-dedent": "^2.2.0",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
+
"typescript": "^5.2.2",
|
|
64
|
+
"vitest": "^2.1.9"
|
|
63
65
|
}
|
|
64
66
|
}
|