mikel 0.36.0 → 0.37.0

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 (3) hide show
  1. package/README.md +15 -4
  2. package/index.js +2 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -732,9 +732,9 @@ console.log(result); // --> "Users: John Doe and Alice Smith"
732
732
 
733
733
  ### Subexpressions
734
734
 
735
- > Added in `v0.30.0`.
735
+ > Added in `v0.30.0`. Supported in helpers and partials in `v0.37.0`.
736
736
 
737
- Subexpressions allow you to evaluate a function call inside another function call. They are written using parentheses, and can be used anywhere a normal function argument is allowed. Example:
737
+ Subexpressions allow you to evaluate a function call inside another function call, helpers, or partials. They are written using parentheses, and can be used anywhere a normal function argument is allowed. Example:
738
738
 
739
739
  ```hbs
740
740
  {{=sum (sum 3 4) 3}}
@@ -751,6 +751,18 @@ Result:
751
751
  10
752
752
  ```
753
753
 
754
+ Subexpressions can be used in helpers also:
755
+
756
+ ```hbs
757
+ {{#sayHello name=(concat "John" "Doe")}}{{/sayHello}}
758
+ ```
759
+
760
+ And in partials:
761
+
762
+ ```hbs
763
+ {{>heading text=(concat "Hello" "World")}}
764
+ ```
765
+
754
766
  #### Nested subexpressions
755
767
 
756
768
  Subexpressions can be nested to any depth:
@@ -783,8 +795,7 @@ You can reference variables or paths normally:
783
795
 
784
796
  #### Limitations
785
797
 
786
- - Subexpressions are currently supported **only for functions** (`{{=...}}`).
787
- - Subexpressions inside helper arguments are not yet supported.
798
+ - Subexpressions are currently supported in **functions** (`{{=...}}`), **helpers** (`{{# ...}}`), and **partials** (`{{> ...}}`).
788
799
  - Parentheses must be balanced; malformed expressions will throw an error.
789
800
 
790
801
 
package/index.js CHANGED
@@ -130,7 +130,7 @@ const compile = (ctx, tokens, output, data, state, index = 0, section = "") => {
130
130
  output.push(tokens[i]);
131
131
  }
132
132
  else if (tokens[i].startsWith("#") && typeof ctx.helpers[tokens[i].slice(1).trim().split(" ")[0]] === "function") {
133
- const [t, args, opt] = parseArgs(tokens[i].slice(1), data, state);
133
+ const [t, args, opt] = parseArgs(tokens[i].slice(1), data, state, ctx.functions);
134
134
  const j = i + 1;
135
135
  i = findClosingToken(tokens, j, t);
136
136
  output.push(ctx.helpers[t]({
@@ -173,7 +173,7 @@ const compile = (ctx, tokens, output, data, state, index = 0, section = "") => {
173
173
  }
174
174
  }
175
175
  else if (tokens[i].startsWith(">")) {
176
- const [t, args, opt] = parseArgs(tokens[i].replace(/^>{1,2}/, ""), data, state);
176
+ const [t, args, opt] = parseArgs(tokens[i].replace(/^>{1,2}/, ""), data, state, ctx.functions);
177
177
  const j = i + 1, blockContent = []; // to store partial block content
178
178
  if (tokens[i].startsWith(">>")) {
179
179
  i = compile(ctx, tokens, blockContent, data, state, i + 1, t);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mikel",
3
3
  "description": "Micro templating library with zero dependencies",
4
- "version": "0.36.0",
4
+ "version": "0.37.0",
5
5
  "type": "module",
6
6
  "author": {
7
7
  "name": "Josemi Juanes",