miki-template 1.2.0 → 1.3.3

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.
Files changed (60) hide show
  1. package/.github/release-notes/v1.3.1.md +55 -0
  2. package/CHANGELOG.md +72 -0
  3. package/README.md +43 -26
  4. package/assets/banner.png +0 -0
  5. package/benchmarks/stress.mjs +647 -0
  6. package/dir/base.html +23 -0
  7. package/dir/cmpnt.html +11 -0
  8. package/dir/footer.html +3 -0
  9. package/dir/home.html +80 -0
  10. package/dir/navbar.html +9 -0
  11. package/docs/api.md +20 -3
  12. package/docs/filters.md +301 -133
  13. package/docs/partialdef.md +30 -1
  14. package/docs/tags.md +63 -0
  15. package/docs/usage.md +50 -3
  16. package/eslint.config.mjs +9 -1
  17. package/ex.mjs +33 -0
  18. package/miki-template-extension/.github/workflows/ci.yml +116 -0
  19. package/miki-template-extension/.vscodeignore +7 -0
  20. package/miki-template-extension/CHANGELOG.md +99 -0
  21. package/miki-template-extension/README.md +244 -53
  22. package/miki-template-extension/extension.js +1013 -0
  23. package/miki-template-extension/icon.png +0 -0
  24. package/miki-template-extension/miki-template-1.7.1.vsix +0 -0
  25. package/miki-template-extension/package.json +244 -10
  26. package/miki-template-extension/snippets/miki-template.json +612 -72
  27. package/miki-template-extension/syntaxes/language-configuration.json +101 -13
  28. package/miki-template-extension/syntaxes/miki-template.tmLanguage.json +270 -61
  29. package/miki-template-extension/tests/grammar-tests.json +162 -0
  30. package/miki-template-extension/tests/run-grammar-tests.js +82 -0
  31. package/package.json +7 -4
  32. package/scripts/build-vsix.js +129 -0
  33. package/scripts/build-vsix.ps1 +15 -0
  34. package/src/cache.js +41 -2
  35. package/src/context.js +9 -5
  36. package/src/context_processors.js +9 -2
  37. package/src/esm.mjs +12 -0
  38. package/src/filters.js +472 -24
  39. package/src/index.js +571 -85
  40. package/src/lexer.js +76 -54
  41. package/src/libraries.js +134 -3
  42. package/src/parser.js +22 -2
  43. package/src/security.js +4 -2
  44. package/src/tags/control.js +150 -21
  45. package/src/tags/extra.js +154 -0
  46. package/src/tags/i18n.js +49 -23
  47. package/src/tags/inheritance.js +142 -23
  48. package/src/tags/util.js +102 -24
  49. package/tests/esm.test.mjs +37 -2
  50. package/tests/filters.test.js +155 -0
  51. package/tests/integration/README.md +32 -0
  52. package/tests/integration/features.test.cjs +1681 -0
  53. package/tests/integration/features.test.mjs +1697 -0
  54. package/tests/integration/templates/base.miki +6 -0
  55. package/tests/integration/templates/child.miki +6 -0
  56. package/tests/integration/templates/index.html +17 -0
  57. package/tests/parser.test.js +5 -3
  58. package/tests/partialdef.test.js +40 -1
  59. package/tests/tags.test.js +30 -0
  60. package/miki-template-1.2.0.vsix +0 -0
@@ -0,0 +1,162 @@
1
+ {
2
+ "grammarTests": [
3
+ {
4
+ "name": "Basic template structure",
5
+ "input": "{% extends \"base.html\" %}\n{% block content %}\n{{ title }}\n{% endblock %}",
6
+ "expectedTokens": [
7
+ { "line": 0, "scope": "meta.tag.django" },
8
+ { "line": 0, "scope": "entity.name.tag.django" },
9
+ { "line": 1, "scope": "meta.tag.django" },
10
+ { "line": 2, "scope": "meta.variable.django" },
11
+ { "line": 2, "scope": "support.function.django" }
12
+ ]
13
+ },
14
+ {
15
+ "name": "If/else/endif tags",
16
+ "input": "{% if user.is_authenticated %}\n <p>Hello</p>\n{% else %}\n <p>Login</p>\n{% endif %}",
17
+ "expectedTags": ["if", "else", "endif"]
18
+ },
19
+ {
20
+ "name": "For loop with empty",
21
+ "input": "{% for item in items %}\n {{ item }}\n{% empty %}\n No items\n{% endfor %}",
22
+ "expectedTags": ["for", "empty", "endfor"]
23
+ },
24
+ {
25
+ "name": "Filter chain",
26
+ "input": "{{ name|lower|capfirst|truncatewords:10 }}",
27
+ "expectedFilters": ["lower", "capfirst", "truncatewords"]
28
+ },
29
+ {
30
+ "name": "Comment block",
31
+ "input": "{# This is a comment #}",
32
+ "scope": "comment.block.django"
33
+ },
34
+ {
35
+ "name": "Prettier ignore",
36
+ "input": "{# prettier-ignore #}",
37
+ "scope": "meta.prettier-ignore.django"
38
+ },
39
+ {
40
+ "name": "Include with context",
41
+ "input": "{% include \"partial.html\" with user=user %}",
42
+ "expectedTags": ["include"]
43
+ },
44
+ {
45
+ "name": "Partialdef and partial",
46
+ "input": "{% partialdef card %}\n<div>{{ title }}</div>\n{% endpartialdef %}\n{% partial card %}",
47
+ "expectedTags": ["partialdef", "endpartialdef", "partial"]
48
+ },
49
+ {
50
+ "name": "i18n tags",
51
+ "input": "{% trans \"Hello\" %}\n{% blocktrans with name=user.name %}\n {{ name }}\n{% endblocktrans %}",
52
+ "expectedTags": ["trans", "blocktrans", "endblocktrans"]
53
+ },
54
+ {
55
+ "name": "Operators",
56
+ "input": "{% if user.age >= 18 and user.is_verified or user.is_admin %}",
57
+ "expectedOperators": ["and", "or"]
58
+ },
59
+ {
60
+ "name": "Cycle tag",
61
+ "input": "{% cycle 'odd' 'even' as marker silent %}",
62
+ "expectedTags": ["cycle"]
63
+ },
64
+ {
65
+ "name": "Widthratio",
66
+ "input": "{% widthratio this_value max_value 100 %}",
67
+ "expectedTags": ["widthratio"]
68
+ },
69
+ {
70
+ "name": "Cache tag",
71
+ "input": "{% cache 500 my_key %}\n{{ content }}\n{% endcache %}",
72
+ "expectedTags": ["cache", "endcache"]
73
+ },
74
+ {
75
+ "name": "Spaceless",
76
+ "input": "{% spaceless %}\n <p> </p>\n{% endspaceless %}",
77
+ "expectedTags": ["spaceless", "endspaceless"]
78
+ },
79
+ {
80
+ "name": "Autoescape",
81
+ "input": "{% autoescape off %}\n{{ html|safe }}\n{% endautoescape %}",
82
+ "expectedTags": ["autoescape", "endautoescape"]
83
+ },
84
+ {
85
+ "name": "With block",
86
+ "input": "{% with user.profile as profile %}\n {{ profile.name }}\n{% endwith %}",
87
+ "expectedTags": ["with", "endwith"]
88
+ },
89
+ {
90
+ "name": "Regroup",
91
+ "input": "{% regroup items by category as grouped %}\n{% for group in grouped %}\n {{ group.grouper }}\n{% endfor %}",
92
+ "expectedTags": ["regroup"]
93
+ },
94
+ {
95
+ "name": "Block.super",
96
+ "input": "{% block content %}\n {{ block.super }}\n{% endblock %}",
97
+ "expectedTokens": [{ "scope": "variable.other.django" }]
98
+ },
99
+ {
100
+ "name": "CSRF token",
101
+ "input": "{% csrf_token %}",
102
+ "expectedTags": ["csrf_token"]
103
+ },
104
+ {
105
+ "name": "Static tag",
106
+ "input": "{% static \"css/style.css\" %}",
107
+ "expectedTags": ["static"]
108
+ },
109
+ {
110
+ "name": "URL tag",
111
+ "input": "{% url \"home\" user.id %}",
112
+ "expectedTags": ["url"]
113
+ },
114
+ {
115
+ "name": "Debug tag",
116
+ "input": "{% debug %}",
117
+ "expectedTags": ["debug"]
118
+ },
119
+ {
120
+ "name": "Verbatim",
121
+ "input": "{% verbatim %}\n {{ not_a_variable }}\n {% not_a_tag %}\n{% endverbatim %}",
122
+ "expectedTags": ["verbatim", "endverbatim"]
123
+ },
124
+ {
125
+ "name": "Filter block",
126
+ "input": "{% filter upper %}\n {{ name }}\n{% endfilter %}",
127
+ "expectedTags": ["filter", "endfilter"]
128
+ },
129
+ {
130
+ "name": "Template tag symbol",
131
+ "input": "{% templatetag openblock %}",
132
+ "expectedTags": ["templatetag"]
133
+ },
134
+ {
135
+ "name": "Addtoblock",
136
+ "input": "{% addtoblock css %}\n.selector { color: red; }\n{% endaddtoblock %}",
137
+ "expectedTags": ["addtoblock", "endaddtoblock"]
138
+ }
139
+ ],
140
+ "validationTests": [
141
+ {
142
+ "name": "Unclosed if tag",
143
+ "input": "{% if condition %}\n content\n{% endfor %}",
144
+ "expectedErrors": ["Unclosed tag: {% if %}"]
145
+ },
146
+ {
147
+ "name": "Mismatched tags",
148
+ "input": "{% if condition %}\n content\n{% endfor %}",
149
+ "expectedErrors": ["Mismatched tag: expected {% endif %} but found {% endfor %}"]
150
+ },
151
+ {
152
+ "name": "Extends not first",
153
+ "input": "{% if true %}\n{% extends \"base.html\" %}\n{% endif %}",
154
+ "expectedErrors": ["{% extends %} must be the first tag"]
155
+ },
156
+ {
157
+ "name": "Tag after extends",
158
+ "input": "{% extends \"base.html\" %}\n{% if true %}\n{% include \"other.html\" %}\n{% endif %}",
159
+ "expectedErrors": []
160
+ }
161
+ ]
162
+ }
@@ -0,0 +1,82 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ const grammarTests = JSON.parse(fs.readFileSync(__dirname + '/grammar-tests.json', 'utf8'));
5
+
6
+ let passed = 0;
7
+ let failed = 0;
8
+
9
+ console.log('Running grammar tests...\n');
10
+
11
+ grammarTests.grammarTests.forEach(test => {
12
+ try {
13
+ console.log(`Test: ${test.name}`);
14
+
15
+ if (test.input) {
16
+ console.log(` Input: ${test.input.substring(0, 50)}${test.input.length > 50 ? '...' : ''}`);
17
+ }
18
+
19
+ if (test.expectedTags) {
20
+ const missing = test.expectedTags.filter(tag => !test.input.includes(`{% ${tag}`));
21
+ if (missing.length > 0) {
22
+ console.log(` FAIL: Missing tags: ${missing.join(', ')}`);
23
+ failed++;
24
+ return;
25
+ }
26
+ }
27
+
28
+ if (test.expectedFilters) {
29
+ const missing = test.expectedFilters.filter(f => !test.input.includes(`|${f}`));
30
+ if (missing.length > 0) {
31
+ console.log(` FAIL: Missing filters: ${missing.join(', ')}`);
32
+ failed++;
33
+ return;
34
+ }
35
+ }
36
+
37
+ if (test.expectedOperators) {
38
+ const missing = test.expectedOperators.filter(op => !test.input.includes(op));
39
+ if (missing.length > 0) {
40
+ console.log(` FAIL: Missing operators: ${missing.join(', ')}`);
41
+ failed++;
42
+ return;
43
+ }
44
+ }
45
+
46
+ console.log(' PASS');
47
+ passed++;
48
+ } catch (err) {
49
+ console.log(` ERROR: ${err.message}`);
50
+ failed++;
51
+ }
52
+ });
53
+
54
+ console.log('\nValidation tests...\n');
55
+
56
+ grammarTests.validationTests.forEach(test => {
57
+ try {
58
+ console.log(`Test: ${test.name}`);
59
+ console.log(` Input: ${test.input.substring(0, 50)}${test.input.length > 50 ? '...' : ''}`);
60
+
61
+ // Simple validation checks
62
+ if (test.input.includes('{% extends') && test.input.indexOf('{% extends') > 0) {
63
+ const firstNonWhitespace = test.input.match(/^\s*({%)/);
64
+ if (firstNonWhitespace && firstNonWhitespace.index > 0) {
65
+ console.log(` PASS: Detected extends not first`);
66
+ passed++;
67
+ }
68
+ }
69
+
70
+ console.log(' PASS');
71
+ passed++;
72
+ } catch (err) {
73
+ console.log(` ERROR: ${err.message}`);
74
+ failed++;
75
+ }
76
+ });
77
+
78
+ console.log(`\n========================================`);
79
+ console.log(`Tests: ${passed} passed, ${failed} failed`);
80
+ console.log(`========================================`);
81
+
82
+ process.exit(failed > 0 ? 1 : 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "miki-template",
3
- "version": "1.2.0",
3
+ "version": "1.3.3",
4
4
  "description": "Django-Style template engine for Node.js and Express",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -11,7 +11,7 @@
11
11
  }
12
12
  },
13
13
  "scripts": {
14
- "test": "node -e \"const fs=require('fs');const path=require('path');const files=fs.readdirSync('tests').filter(f=>f.endsWith('.test.js')||f.endsWith('.test.mjs')).map(f=>path.join('tests',f));require('child_process').execSync('node --test '+files.join(' '),{stdio:'inherit'})\"",
14
+ "test": "node -e \"const fs=require('fs');const path=require('path');function walk(d){const out=[];for(const e of fs.readdirSync(d,{withFileTypes:true})){const p=path.join(d,e.name);if(e.isDirectory())out.push(...walk(p));else if(/\\\\.test\\\\.(cjs|mjs|js)$/.test(e.name))out.push(p);}return out;}const files=walk('tests');require('child_process').execSync('node --test '+files.join(' '),{stdio:'inherit'})\"",
15
15
  "bench": "node benchmarks/run.js"
16
16
  },
17
17
  "keywords": [
@@ -25,7 +25,10 @@
25
25
  "author": "",
26
26
  "license": "MIT",
27
27
  "dependencies": {
28
- "he": "^1.2.0",
29
- "date-fns": "^3.6.0"
28
+ "date-fns": "^3.6.0",
29
+ "he": "^1.2.0"
30
+ },
31
+ "devDependencies": {
32
+ "express": "^5.2.1"
30
33
  }
31
34
  }
@@ -0,0 +1,129 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const zlib = require('zlib');
4
+
5
+ const extDir = 'miki-template-extension';
6
+ const buildDir = 'miki-template-extension/.vsix-build';
7
+ const vsixPath = 'miki-template-1.2.0.vsix';
8
+
9
+ if (fs.existsSync(buildDir)) fs.rmSync(buildDir, { recursive: true });
10
+ if (fs.existsSync(vsixPath)) fs.unlinkSync(vsixPath);
11
+
12
+ fs.mkdirSync(buildDir, { recursive: true });
13
+ const extTarget = path.join(buildDir, 'extension');
14
+ fs.mkdirSync(extTarget, { recursive: true });
15
+
16
+ function copyDirSync(src, dest) {
17
+ fs.readdirSync(src).forEach(item => {
18
+ const s = path.join(src, item);
19
+ const d = path.join(dest, item);
20
+ if (fs.statSync(s).isDirectory()) {
21
+ fs.mkdirSync(d, { recursive: true });
22
+ copyDirSync(s, d);
23
+ } else {
24
+ fs.copyFileSync(s, d);
25
+ }
26
+ });
27
+ }
28
+
29
+ copyDirSync(extDir, extTarget);
30
+
31
+ const manifest = '<?xml version="1.0" encoding="utf-8"?><PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011"><Metadata><Identity Id="alainmiki.miki-template" Version="1.2.0" Language="en-US" Publisher="alainmiki" /><DisplayName>miki-template</DisplayName><Description>Django-style template language syntax highlighting and snippets for miki-template</Description><Tags>django template miki syntax highlight snippet</Tags><Categories>Programming Languages,Snippets</Categories><GalleryFlags>Public</GalleryFlags><License>LICENSE</License><Icon>extension/icon.png</Icon></Metadata><Installation><InstallationTarget Id="Microsoft.VisualStudio.Code" /></Installation><Dependencies /><Assets><Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Content" Path="extension/syntaxes/miki-template.tmLanguage.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Content" Path="extension/syntaxes/language-configuration.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Snippet" Path="extension/snippets/miki-template.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Image" Path="extension/icon.png" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Image" Path="extension/icon.svg" Addressable="true" /></Assets></PackageManifest>';
32
+ const ct = '<?xml version="1.0" encoding="utf-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="json" ContentType="application/json" /><Default Extension="png" ContentType="image/png" /><Default Extension="svg" ContentType="image/svg+xml" /><Default Extension="md" ContentType="text/markdown" /></Types>';
33
+ fs.writeFileSync(path.join(buildDir, 'extension.vsixmanifest'), manifest);
34
+ fs.writeFileSync(path.join(buildDir, '[Content_Types].xml'), ct);
35
+
36
+ const files = [];
37
+ function collectFiles(dir, base) {
38
+ fs.readdirSync(dir).forEach(item => {
39
+ const s = path.join(dir, item);
40
+ const d = path.join(base, item);
41
+ if (fs.statSync(s).isDirectory()) {
42
+ collectFiles(s, d);
43
+ } else {
44
+ files.push({ path: d, content: fs.readFileSync(s) });
45
+ }
46
+ });
47
+ }
48
+ collectFiles(buildDir, '');
49
+
50
+ function crc32(buf) {
51
+ let crc = 0xFFFFFFFF;
52
+ const table = new Uint32Array(256);
53
+ for (let i = 0; i < 256; i++) {
54
+ let c = i;
55
+ for (let j = 0; j < 8; j++) c = (c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1);
56
+ table[i] = c;
57
+ }
58
+ for (let i = 0; i < buf.length; i++) crc = table[(crc ^ buf[i]) & 0xFF] ^ (crc >>> 8);
59
+ return (crc ^ 0xFFFFFFFF) >>> 0;
60
+ }
61
+
62
+ const localFiles = [];
63
+ const centralDir = [];
64
+ let offset = 0;
65
+
66
+ for (const file of files) {
67
+ const pathBytes = Buffer.from(file.path);
68
+ const data = file.content;
69
+ const compressed = zlib.deflateSync(data);
70
+ const crc = crc32(data);
71
+
72
+ const localHeader = Buffer.alloc(30);
73
+ localHeader.writeUInt32LE(0x04034b50, 0);
74
+ localHeader.writeUInt16LE(20, 4);
75
+ localHeader.writeUInt16LE(0, 6);
76
+ localHeader.writeUInt16LE(8, 8);
77
+ localHeader.writeUInt16LE(0, 10);
78
+ localHeader.writeUInt16LE(0, 12);
79
+ localHeader.writeUInt32LE(crc, 14);
80
+ localHeader.writeUInt32LE(compressed.length, 18);
81
+ localHeader.writeUInt32LE(data.length, 22);
82
+ localHeader.writeUInt16LE(pathBytes.length, 26);
83
+ localHeader.writeUInt16LE(0, 28);
84
+
85
+ const localFile = Buffer.concat([localHeader, pathBytes, compressed]);
86
+ localFiles.push(localFile);
87
+
88
+ const centralHeader = Buffer.alloc(46);
89
+ centralHeader.writeUInt32LE(0x02014b50, 0);
90
+ centralHeader.writeUInt16LE(20, 4);
91
+ centralHeader.writeUInt16LE(20, 6);
92
+ centralHeader.writeUInt16LE(0, 8);
93
+ centralHeader.writeUInt16LE(8, 10);
94
+ centralHeader.writeUInt16LE(0, 12);
95
+ centralHeader.writeUInt16LE(0, 14);
96
+ centralHeader.writeUInt32LE(crc, 16);
97
+ centralHeader.writeUInt32LE(compressed.length, 20);
98
+ centralHeader.writeUInt32LE(data.length, 24);
99
+ centralHeader.writeUInt16LE(pathBytes.length, 28);
100
+ centralHeader.writeUInt16LE(0, 30);
101
+ centralHeader.writeUInt16LE(0, 32);
102
+ centralHeader.writeUInt16LE(0, 34);
103
+ centralHeader.writeUInt16LE(0, 36);
104
+ centralHeader.writeUInt32LE(0, 38);
105
+ centralHeader.writeUInt32LE(offset, 42);
106
+
107
+ const centralEntry = Buffer.concat([centralHeader, pathBytes]);
108
+ centralDir.push(centralEntry);
109
+
110
+ offset += localFile.length;
111
+ }
112
+
113
+ const centralDirOffset = offset;
114
+ const centralDirSize = centralDir.reduce((sum, entry) => sum + entry.length, 0);
115
+ const endRecord = Buffer.alloc(22);
116
+ endRecord.writeUInt32LE(0x06054b50, 0);
117
+ endRecord.writeUInt16LE(0, 4);
118
+ endRecord.writeUInt16LE(0, 6);
119
+ endRecord.writeUInt16LE(centralDir.length, 8);
120
+ endRecord.writeUInt16LE(centralDir.length, 10);
121
+ endRecord.writeUInt32LE(centralDirSize, 12);
122
+ endRecord.writeUInt32LE(centralDirOffset, 16);
123
+ endRecord.writeUInt16LE(0, 20);
124
+
125
+ const zipBuffer = Buffer.concat([...localFiles, ...centralDir, endRecord]);
126
+ fs.writeFileSync(vsixPath, zipBuffer);
127
+
128
+ if (fs.existsSync(buildDir)) fs.rmSync(buildDir, { recursive: true });
129
+ console.log('VSIX created:', vsixPath, 'size:', zipBuffer.length);
@@ -0,0 +1,15 @@
1
+ $ErrorActionPreference = 'Stop'
2
+ $extDir = Join-Path $PWD 'miki-template-extension'
3
+ $vsixPath = Join-Path $PWD 'miki-template-1.2.0.vsix'
4
+ if (Test-Path $vsixPath) { Remove-Item $vsixPath -Force }
5
+ $tempDir = Join-Path $env:TEMP ('vsix-build-' + [Guid]::NewGuid().ToString('N').Substring(0,8))
6
+ New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
7
+ $extTarget = Join-Path $tempDir 'extension'
8
+ Copy-Item -Path $extDir -Destination $extTarget -Recurse -Force
9
+ $manifest = '<?xml version="1.0" encoding="utf-8"?><PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011"><Metadata><Identity Id="alainmiki.miki-template" Version="1.2.0" Language="en-US" Publisher="alainmiki" /><DisplayName>miki-template</DisplayName><Description>Django-style template language syntax highlighting and snippets for miki-template</Description><Tags>django template miki syntax highlight snippet</Tags><Categories>Programming Languages,Snippets</Categories><GalleryFlags>Public</GalleryFlags><License>LICENSE</License><Icon>extension/icon.png</Icon></Metadata><Installation><InstallationTarget Id="Microsoft.VisualStudio.Code" /></Installation><Dependencies /><Assets><Asset Type="Microsoft.VisualStudio.Code.Manifest" Path="extension/package.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Content" Path="extension/syntaxes/miki-template.tmLanguage.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Content" Path="extension/syntaxes/language-configuration.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Snippet" Path="extension/snippets/miki-template.json" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Image" Path="extension/icon.png" Addressable="true" /><Asset Type="Microsoft.VisualStudio.Code.Image" Path="extension/icon.svg" Addressable="true" /></Assets></PackageManifest>'
10
+ Set-Content -Path (Join-Path $tempDir 'extension.vsixmanifest') -Value $manifest -Encoding UTF8
11
+ $ct = '<?xml version="1.0" encoding="utf-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="json" ContentType="application/json" /><Default Extension="png" ContentType="image/png" /><Default Extension="svg" ContentType="image/svg+xml" /><Default Extension="md" ContentType="text/markdown" /></Types>'
12
+ Set-Content -Path (Join-Path $tempDir '[Content_Types].xml') -Value $ct -Encoding UTF8
13
+ Compress-Archive -Path (Join-Path $tempDir '*') -DestinationPath $vsixPath -Force
14
+ Remove-Item $tempDir -Recurse -Force
15
+ Write-Host "VSIX created at $vsixPath"
package/src/cache.js CHANGED
@@ -7,6 +7,36 @@
7
7
  const CACHE_LIMIT = 100;
8
8
  const cache = new Map();
9
9
 
10
+ /**
11
+ * Parent-source cache shared across renders. Populated by
12
+ * renderAST/renderASTAsync in src/index.js so that `{% extends %}`
13
+ * doesn't re-read the parent file from disk on every render.
14
+ */
15
+ const parentSourceCache = new Map();
16
+ const PARENT_SOURCE_LIMIT = 64;
17
+
18
+ function getParentSource(key, loader) {
19
+ if (parentSourceCache.has(key)) {
20
+ const v = parentSourceCache.get(key);
21
+ parentSourceCache.delete(key);
22
+ parentSourceCache.set(key, v);
23
+ return v;
24
+ }
25
+ const v = loader();
26
+ if (v != null) {
27
+ parentSourceCache.set(key, v);
28
+ if (parentSourceCache.size > PARENT_SOURCE_LIMIT) {
29
+ const firstKey = parentSourceCache.keys().next().value;
30
+ parentSourceCache.delete(firstKey);
31
+ }
32
+ }
33
+ return v;
34
+ }
35
+
36
+ function hasParentSource(key) {
37
+ return parentSourceCache.has(key);
38
+ }
39
+
10
40
  /**
11
41
  * Retrieve a compiled template from cache or compile it and store.
12
42
  * @param {string} templateStr – template source
@@ -15,7 +45,15 @@ const cache = new Map();
15
45
  * @returns {object} compiled template object
16
46
  */
17
47
  function getCompiled(templateStr, compileOptions, compileFn) {
18
- const key = JSON.stringify({ templateStr, compileOptions });
48
+ // Build a cache key that ignores non-serializable option values
49
+ // (e.g. functions like urlHelper, custom callbacks) — those don't
50
+ // affect template compilation, only render behavior.
51
+ const serializable = {};
52
+ for (const [k, v] of Object.entries(compileOptions || {})) {
53
+ if (typeof v === 'function' || typeof v === 'undefined') continue;
54
+ serializable[k] = v;
55
+ }
56
+ const key = JSON.stringify({ templateStr, compileOptions: serializable });
19
57
  if (cache.has(key)) {
20
58
  // Move to end to mark as recently used
21
59
  const value = cache.get(key);
@@ -36,6 +74,7 @@ function getCompiled(templateStr, compileOptions, compileFn) {
36
74
  /** Clear the cache – useful for tests */
37
75
  function clearCache() {
38
76
  cache.clear();
77
+ parentSourceCache.clear();
39
78
  }
40
79
 
41
- module.exports = { getCompiled, clearCache };
80
+ module.exports = { getCompiled, clearCache, getParentSource, hasParentSource };
package/src/context.js CHANGED
@@ -52,7 +52,7 @@ class Context {
52
52
  const parts = path.split('.');
53
53
  const baseName = parts[0];
54
54
 
55
- let current = null;
55
+ let current = undefined;
56
56
  let found = false;
57
57
 
58
58
  // Search scopes from top (most local) to bottom (most global)
@@ -65,13 +65,16 @@ class Context {
65
65
  }
66
66
 
67
67
  if (!found) {
68
- return '';
68
+ // Variable truly missing — return undefined so templates can
69
+ // distinguish "missing" from "explicitly null". The variable node
70
+ // and filters handle undefined gracefully.
71
+ return undefined;
69
72
  }
70
73
 
71
74
  // Traverse the rest of the dotted segments
72
75
  for (let i = 1; i < parts.length; i++) {
73
76
  if (current === undefined || current === null) {
74
- return '';
77
+ return current === null ? null : undefined;
75
78
  }
76
79
 
77
80
  const parent = current;
@@ -84,7 +87,7 @@ class Context {
84
87
  // Handle array index resolution, e.g. items.0
85
88
  current = current[parseInt(part, 10)];
86
89
  } else {
87
- return '';
90
+ return undefined;
88
91
  }
89
92
 
90
93
  // If the property value is a function, evaluate it (Django style)
@@ -98,7 +101,8 @@ class Context {
98
101
  current = current.call(null);
99
102
  }
100
103
 
101
- return current !== undefined && current !== null ? current : '';
104
+ // Preserve null/undefined so filters like default_if_none can detect them.
105
+ return current;
102
106
  }
103
107
 
104
108
  /**
@@ -25,14 +25,21 @@ function clearContextProcessors() {
25
25
 
26
26
  /**
27
27
  * Apply all registered processors to the given context object.
28
- * Mutates the context object by merging any returned values.
28
+ * Values returned by a processor that are already defined in the
29
+ * context are kept as-is (Django-style "existing values win" semantics
30
+ * so explicit render-time data always takes precedence over processor
31
+ * defaults).
29
32
  * @param {Object} ctx
30
33
  */
31
34
  function applyContextProcessors(ctx) {
32
35
  for (const fn of processors) {
33
36
  const result = fn(ctx);
34
37
  if (result && typeof result === 'object') {
35
- Object.assign(ctx, result);
38
+ for (const [k, v] of Object.entries(result)) {
39
+ if (ctx[k] === undefined) {
40
+ ctx[k] = v;
41
+ }
42
+ }
36
43
  }
37
44
  }
38
45
  return ctx;
package/src/esm.mjs CHANGED
@@ -11,14 +11,20 @@ const {
11
11
  compile,
12
12
  render,
13
13
  asyncRender,
14
+ renderPartialFromFile,
15
+ renderPartialFromSource,
14
16
  __express,
15
17
  __expressAsync,
18
+ express,
19
+ setupExpress,
20
+ expressPartialRenderer,
16
21
  stripExpressContext,
17
22
  clearCache,
18
23
  registerTag,
19
24
  registerFilter,
20
25
  registerHelper,
21
26
  registerContextProcessor,
27
+ clearContextProcessors,
22
28
  registerTranslation,
23
29
  unregisterTranslation,
24
30
  setLanguage,
@@ -42,14 +48,20 @@ export {
42
48
  compile,
43
49
  render,
44
50
  asyncRender,
51
+ renderPartialFromFile,
52
+ renderPartialFromSource,
45
53
  __express,
46
54
  __expressAsync,
55
+ express,
56
+ setupExpress,
57
+ expressPartialRenderer,
47
58
  stripExpressContext,
48
59
  clearCache,
49
60
  registerTag,
50
61
  registerFilter,
51
62
  registerHelper,
52
63
  registerContextProcessor,
64
+ clearContextProcessors,
53
65
  registerTranslation,
54
66
  unregisterTranslation,
55
67
  setLanguage,