janja 4.1.0 → 4.3.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.
package/dist/index.d.ts CHANGED
@@ -99,7 +99,7 @@ declare class Context extends OutScript {
99
99
  }
100
100
 
101
101
  type UnaryExpTokenType = 'NOT';
102
- type BinaryExpTokenType = 'AND' | 'OR' | 'IS' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'ASSIGN';
102
+ type BinaryExpTokenType = 'AND' | 'OR' | 'IS' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'WITH' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'ASSIGN';
103
103
  type TernaryExpTokenType = 'IF' | 'ELSE';
104
104
  type ExpTokenType = UnaryExpTokenType | BinaryExpTokenType | TernaryExpTokenType | 'LP' | 'RP' | 'COMMA' | 'DOT' | 'ID' | 'LIT';
105
105
  type UnaryExpType = UnaryExpTokenType;
@@ -165,6 +165,15 @@ declare class BlockNode extends Traversal {
165
165
  constructor(val: IdExp, body: SyntaxNode[], loc: Loc, strip: Strip);
166
166
  }
167
167
 
168
+ /** CSS co-located with a section/snippet (Shopify `{% stylesheet %}` analogue). */
169
+ declare class StylesheetNode extends Traversal {
170
+ readonly body: SyntaxNode[];
171
+ readonly loc: Loc;
172
+ readonly strip: Strip;
173
+ readonly type = "STYLESHEET";
174
+ constructor(body: SyntaxNode[], loc: Loc, strip: Strip);
175
+ }
176
+
168
177
  interface CompiledTemplate {
169
178
  code: string;
170
179
  mappings: Mapping[];
@@ -185,6 +194,10 @@ declare class Compiler extends Context {
185
194
  private rootNode;
186
195
  private partials;
187
196
  private blocks;
197
+ /** Stylesheet bodies keyed by include path (or `\0root` for the root template). */
198
+ private stylesheets;
199
+ /** Key used when collecting stylesheets from the template currently compiling. */
200
+ private stylesheetKey;
188
201
  private sources;
189
202
  private cache?;
190
203
  private compiled?;
@@ -194,7 +207,7 @@ declare class Compiler extends Context {
194
207
  */
195
208
  flushable: boolean;
196
209
  constructor(options: Required<CompilerOptions>, cache?: LRUCache<CompiledTemplate>, revalidate?: boolean, stream?: boolean);
197
- compile(template: string, root?: boolean, partials?: Map<string, string>, blocks?: Map<string, BlockNode[]>, sources?: Map<string, string>): Promise<this>;
210
+ compile(template: string, root?: boolean, partials?: Map<string, string>, blocks?: Map<string, BlockNode[]>, sources?: Map<string, string>, stylesheets?: Map<string, StylesheetNode[]>, stylesheetKey?: string): Promise<this>;
198
211
  get script(): Script;
199
212
  private generateCacheKey;
200
213
  private fingerprint;
@@ -975,17 +988,30 @@ declare function generateDeclarations({ variables }: Pick<TemplateAnalysis, 'var
975
988
  includeRuntime?: boolean | undefined;
976
989
  }): string;
977
990
 
978
- type FormatOptions = Pick<ParserOptions, 'commentOpen' | 'commentClose' | 'directiveOpen' | 'directiveClose' | 'outputOpen' | 'outputClose'>;
991
+ type FormatOptions = Pick<ParserOptions, 'commentOpen' | 'commentClose' | 'directiveOpen' | 'directiveClose' | 'outputOpen' | 'outputClose'> & {
992
+ /** Spaces per indent level when reformatting HTML (default 2). */
993
+ tabWidth?: number;
994
+ /**
995
+ * Reindent HTML and block directives. Default `true`. Pass `false` to only
996
+ * normalise spacing inside tags (legacy behaviour).
997
+ */
998
+ html?: boolean;
999
+ };
979
1000
  /**
980
- * Normalise the tags of a template:
1001
+ * Format a template:
1002
+ *
1003
+ * 1. Normalise spacing inside tags:
1004
+ *
1005
+ * {{=name|upper}} -> {{= name | upper }}
1006
+ * {{if a eq 1}} -> {{ if a eq 1 }}
1007
+ * {{#note#}} -> {{# note #}}
981
1008
  *
982
- * {{=name|upper}} -> {{= name | upper }}
983
- * {{if a eq 1}} -> {{ if a eq 1 }}
984
- * {{#note#}} -> {{# note #}}
1009
+ * 2. Unless `html: false`, reindent HTML elements and block directives
1010
+ * (`if` / `for` / …). Only leading whitespace on each line changes;
1011
+ * attribute values (including embedded tags) and whitespace-sensitive
1012
+ * elements (`pre`, `script`, …) are left alone.
985
1013
  *
986
- * Only what is inside tags changes. Text between tags, where whitespace may
987
- * matter, is kept byte for byte, as are whitespace-control markers. A tag is
988
- * left exactly as written whenever its expression does not parse or
1014
+ * A tag is left exactly as written whenever its expression does not parse or
989
1015
  * reformatting would not provably keep its meaning. Formatting twice gives
990
1016
  * the same result as formatting once.
991
1017
  *