@reteps/tree-sitter-htmlmustache 0.8.0 → 0.9.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/README.md +49 -33
- package/browser/out/browser/index.d.ts +43 -0
- package/browser/out/browser/index.d.ts.map +1 -0
- package/browser/out/browser/index.mjs +3612 -0
- package/browser/out/browser/index.mjs.map +7 -0
- package/browser/out/core/collectErrors.d.ts +36 -0
- package/browser/out/core/collectErrors.d.ts.map +1 -0
- package/browser/out/core/configSchema.d.ts +63 -0
- package/browser/out/core/configSchema.d.ts.map +1 -0
- package/browser/out/core/customCodeTags.d.ts +34 -0
- package/browser/out/core/customCodeTags.d.ts.map +1 -0
- package/browser/out/core/diagnostic.d.ts +24 -0
- package/browser/out/core/diagnostic.d.ts.map +1 -0
- package/browser/out/core/embeddedRegions.d.ts +12 -0
- package/browser/out/core/embeddedRegions.d.ts.map +1 -0
- package/browser/out/core/formatting/classifier.d.ts +68 -0
- package/browser/out/core/formatting/classifier.d.ts.map +1 -0
- package/browser/out/core/formatting/embedded.d.ts +19 -0
- package/browser/out/core/formatting/embedded.d.ts.map +1 -0
- package/browser/out/core/formatting/formatters.d.ts +85 -0
- package/browser/out/core/formatting/formatters.d.ts.map +1 -0
- package/browser/out/core/formatting/index.d.ts +44 -0
- package/browser/out/core/formatting/index.d.ts.map +1 -0
- package/browser/out/core/formatting/ir.d.ts +100 -0
- package/browser/out/core/formatting/ir.d.ts.map +1 -0
- package/browser/out/core/formatting/mergeOptions.d.ts +18 -0
- package/browser/out/core/formatting/mergeOptions.d.ts.map +1 -0
- package/browser/out/core/formatting/printer.d.ts +18 -0
- package/browser/out/core/formatting/printer.d.ts.map +1 -0
- package/browser/out/core/formatting/utils.d.ts +39 -0
- package/browser/out/core/formatting/utils.d.ts.map +1 -0
- package/browser/out/core/grammar.d.ts +3 -0
- package/browser/out/core/grammar.d.ts.map +1 -0
- package/browser/out/core/htmlBalanceChecker.d.ts +23 -0
- package/browser/out/core/htmlBalanceChecker.d.ts.map +1 -0
- package/browser/out/core/mustacheChecks.d.ts +24 -0
- package/browser/out/core/mustacheChecks.d.ts.map +1 -0
- package/browser/out/core/nodeHelpers.d.ts +54 -0
- package/browser/out/core/nodeHelpers.d.ts.map +1 -0
- package/browser/out/core/ruleMetadata.d.ts +12 -0
- package/browser/out/core/ruleMetadata.d.ts.map +1 -0
- package/browser/out/core/selectorMatcher.d.ts +74 -0
- package/browser/out/core/selectorMatcher.d.ts.map +1 -0
- package/cli/out/main.js +168 -122
- package/package.json +21 -3
- package/src/browser/browser.test.ts +207 -0
- package/src/browser/index.ts +128 -0
- package/src/browser/tsconfig.json +18 -0
- package/src/core/collectErrors.ts +233 -0
- package/src/core/configSchema.ts +273 -0
- package/src/core/customCodeTags.ts +159 -0
- package/src/core/diagnostic.ts +45 -0
- package/src/core/embeddedRegions.ts +70 -0
- package/src/core/formatting/classifier.ts +549 -0
- package/src/core/formatting/embedded.ts +56 -0
- package/src/core/formatting/formatters.ts +1272 -0
- package/src/core/formatting/index.ts +185 -0
- package/src/core/formatting/ir.ts +202 -0
- package/src/core/formatting/mergeOptions.ts +34 -0
- package/src/core/formatting/printer.ts +242 -0
- package/src/core/formatting/utils.ts +193 -0
- package/src/core/grammar.ts +2 -0
- package/src/core/htmlBalanceChecker.ts +382 -0
- package/src/core/mustacheChecks.ts +504 -0
- package/src/core/nodeHelpers.ts +126 -0
- package/src/core/ruleMetadata.ts +63 -0
- package/src/core/selectorMatcher.ts +719 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared error collection logic used by both the LSP diagnostics
|
|
3
|
+
* and the CLI linter.
|
|
4
|
+
*/
|
|
5
|
+
import type { BalanceNode } from './htmlBalanceChecker.js';
|
|
6
|
+
import type { TextReplacement } from './mustacheChecks.js';
|
|
7
|
+
import type { RulesConfig, CustomRule } from './configSchema.js';
|
|
8
|
+
/** A tree that provides walk() and rootNode, compatible with both web-tree-sitter and CLI wasm. */
|
|
9
|
+
export interface WalkableTree {
|
|
10
|
+
walk(): TreeCursor;
|
|
11
|
+
rootNode: BalanceNode;
|
|
12
|
+
}
|
|
13
|
+
interface TreeCursor {
|
|
14
|
+
currentNode: BalanceNode;
|
|
15
|
+
nodeType: string;
|
|
16
|
+
nodeIsMissing: boolean;
|
|
17
|
+
gotoFirstChild(): boolean;
|
|
18
|
+
gotoNextSibling(): boolean;
|
|
19
|
+
gotoParent(): boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Unified error result from all checkers. */
|
|
22
|
+
export interface CheckError {
|
|
23
|
+
node: BalanceNode;
|
|
24
|
+
message: string;
|
|
25
|
+
severity?: 'error' | 'warning';
|
|
26
|
+
fix?: TextReplacement[];
|
|
27
|
+
fixDescription?: string;
|
|
28
|
+
ruleName?: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Collect all errors from a parsed tree: syntax errors, balance errors,
|
|
32
|
+
* unclosed tags, and mustache lint checks.
|
|
33
|
+
*/
|
|
34
|
+
export declare function collectErrors(tree: WalkableTree, rules?: RulesConfig, customTagNames?: string[], customRules?: CustomRule[]): CheckError[];
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=collectErrors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collectErrors.d.ts","sourceRoot":"","sources":["../../../src/core/collectErrors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAa3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAgB,UAAU,EAAgC,MAAM,mBAAmB,CAAC;AAkB7G,mGAAmG;AACnG,MAAM,WAAW,YAAY;IAC3B,IAAI,IAAI,UAAU,CAAC;IACnB,QAAQ,EAAE,WAAW,CAAC;CACvB;AAED,UAAU,UAAU;IAClB,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,IAAI,OAAO,CAAC;IAC1B,eAAe,IAAI,OAAO,CAAC;IAC3B,UAAU,IAAI,OAAO,CAAC;CACvB;AAED,8CAA8C;AAC9C,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,GAAG,CAAC,EAAE,eAAe,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAkED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,EAAE,WAAW,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAsG1I"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure, browser-safe configuration schema: types, JSONC parsing, validation.
|
|
3
|
+
*
|
|
4
|
+
* No Node built-ins. File-system config discovery lives in
|
|
5
|
+
* `lsp/server/src/configFile.ts` and imports from this module.
|
|
6
|
+
*/
|
|
7
|
+
import type { CustomCodeTagConfig } from './customCodeTags.js';
|
|
8
|
+
export type RuleSeverity = 'error' | 'warning' | 'off';
|
|
9
|
+
export interface ElementContentTooLongOptions {
|
|
10
|
+
elements: Array<{
|
|
11
|
+
tag: string;
|
|
12
|
+
maxBytes: number;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
15
|
+
export type RuleEntry = RuleSeverity | {
|
|
16
|
+
severity: RuleSeverity;
|
|
17
|
+
};
|
|
18
|
+
export type RuleEntryWithOptions<TOptions> = RuleSeverity | ({
|
|
19
|
+
severity: RuleSeverity;
|
|
20
|
+
} & TOptions);
|
|
21
|
+
export interface RulesConfig {
|
|
22
|
+
nestedDuplicateSections?: RuleEntry;
|
|
23
|
+
unquotedMustacheAttributes?: RuleEntry;
|
|
24
|
+
consecutiveDuplicateSections?: RuleEntry;
|
|
25
|
+
selfClosingNonVoidTags?: RuleEntry;
|
|
26
|
+
duplicateAttributes?: RuleEntry;
|
|
27
|
+
unescapedEntities?: RuleEntry;
|
|
28
|
+
preferMustacheComments?: RuleEntry;
|
|
29
|
+
unrecognizedHtmlTags?: RuleEntry;
|
|
30
|
+
elementContentTooLong?: RuleEntryWithOptions<ElementContentTooLongOptions>;
|
|
31
|
+
}
|
|
32
|
+
export interface CustomRule {
|
|
33
|
+
id: string;
|
|
34
|
+
selector: string;
|
|
35
|
+
message: string;
|
|
36
|
+
severity?: RuleSeverity;
|
|
37
|
+
}
|
|
38
|
+
export interface NoBreakDelimiter {
|
|
39
|
+
start: string;
|
|
40
|
+
end: string;
|
|
41
|
+
}
|
|
42
|
+
export interface HtmlMustacheConfig {
|
|
43
|
+
printWidth?: number;
|
|
44
|
+
indentSize?: number;
|
|
45
|
+
mustacheSpaces?: boolean;
|
|
46
|
+
noBreakDelimiters?: NoBreakDelimiter[];
|
|
47
|
+
customTags?: CustomCodeTagConfig[];
|
|
48
|
+
include?: string[];
|
|
49
|
+
exclude?: string[];
|
|
50
|
+
rules?: RulesConfig;
|
|
51
|
+
customRules?: CustomRule[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Strip // line comments, block comments, and trailing commas from JSONC text,
|
|
55
|
+
* then JSON.parse(). Preserves comments inside strings.
|
|
56
|
+
*/
|
|
57
|
+
export declare function parseJsonc(text: string): unknown;
|
|
58
|
+
/**
|
|
59
|
+
* Validate a raw parsed config object and return a typed HtmlMustacheConfig.
|
|
60
|
+
* Ignores unknown keys and invalid values.
|
|
61
|
+
*/
|
|
62
|
+
export declare function validateConfig(raw: unknown): HtmlMustacheConfig;
|
|
63
|
+
//# sourceMappingURL=configSchema.d.ts.map
|
|
@@ -0,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,MAAM,CAAC;CACb;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACvC,UAAU,CAAC,EAAE,mBAAmB,EAAE,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CA2ChD;AAiCD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG,kBAAkB,CAwF/D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Node as SyntaxNode } from 'web-tree-sitter';
|
|
2
|
+
import type { CSSDisplay } from './formatting/classifier.js';
|
|
3
|
+
export type CustomCodeTagIndentMode = 'never' | 'always' | 'attribute';
|
|
4
|
+
export interface CustomCodeTagConfig {
|
|
5
|
+
name: string;
|
|
6
|
+
display?: CSSDisplay;
|
|
7
|
+
languageAttribute?: string;
|
|
8
|
+
languageMap?: Record<string, string>;
|
|
9
|
+
languageDefault?: string;
|
|
10
|
+
indent?: CustomCodeTagIndentMode;
|
|
11
|
+
indentAttribute?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Alias for CustomCodeTagConfig (unified name). */
|
|
14
|
+
export type CustomTagConfig = CustomCodeTagConfig;
|
|
15
|
+
/**
|
|
16
|
+
* Check if a custom tag config represents a code tag (has language settings).
|
|
17
|
+
* Code tags get preserved content and default to block display.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isCodeTag(config: CustomCodeTagConfig): boolean;
|
|
20
|
+
export interface CustomCodeTagContent {
|
|
21
|
+
text: string;
|
|
22
|
+
languageId: string;
|
|
23
|
+
startRow: number;
|
|
24
|
+
startCol: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the attribute value for a given attribute name from an element's start tag.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getAttributeValue(node: SyntaxNode, attrName: string): string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Walk the tree to find custom code tag elements and extract their content + language.
|
|
32
|
+
*/
|
|
33
|
+
export declare function findCustomCodeTagContent(rootNode: SyntaxNode, configs: CustomCodeTagConfig[]): CustomCodeTagContent[];
|
|
34
|
+
//# sourceMappingURL=customCodeTags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customCodeTags.d.ts","sourceRoot":"","sources":["../../../src/core/customCodeTags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,MAAM,uBAAuB,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEvE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,uBAAuB,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,oDAAoD;AACpD,MAAM,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAElD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAE9D;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuBnF;AAkBD;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,mBAAmB,EAAE,GAC7B,oBAAoB,EAAE,CA2ExB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared CheckError → public `Diagnostic` projection used by the browser
|
|
3
|
+
* entry and the CLI wrapper. 1-based line/column per the public contract;
|
|
4
|
+
* multi-edit fix array; severity defaults to `'error'` when the source
|
|
5
|
+
* checker didn't set one (parse errors, balance errors).
|
|
6
|
+
*/
|
|
7
|
+
import type { CheckError } from './collectErrors.js';
|
|
8
|
+
export interface DiagnosticFix {
|
|
9
|
+
range: [number, number];
|
|
10
|
+
newText: string;
|
|
11
|
+
}
|
|
12
|
+
export interface Diagnostic {
|
|
13
|
+
line: number;
|
|
14
|
+
column: number;
|
|
15
|
+
endLine: number;
|
|
16
|
+
endColumn: number;
|
|
17
|
+
message: string;
|
|
18
|
+
severity: 'error' | 'warning';
|
|
19
|
+
ruleName?: string;
|
|
20
|
+
fix?: DiagnosticFix[];
|
|
21
|
+
fixDescription?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function toDiagnostic(err: CheckError): Diagnostic;
|
|
24
|
+
//# sourceMappingURL=diagnostic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnostic.d.ts","sourceRoot":"","sources":["../../../src/core/diagnostic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGrD,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,aAAa,EAAE,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAMD,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,CAaxD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Node as SyntaxNode } from 'web-tree-sitter';
|
|
2
|
+
export interface EmbeddedRegion {
|
|
3
|
+
startIndex: number;
|
|
4
|
+
content: string;
|
|
5
|
+
languageId: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Walk the tree to collect embedded script/style regions.
|
|
9
|
+
* Skips html_raw_element (custom raw tags).
|
|
10
|
+
*/
|
|
11
|
+
export declare function collectEmbeddedRegions(rootNode: SyntaxNode): EmbeddedRegion[];
|
|
12
|
+
//# sourceMappingURL=embeddedRegions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddedRegions.d.ts","sourceRoot":"","sources":["../../../src/core/embeddedRegions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE1D,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAoCD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,UAAU,GAAG,cAAc,EAAE,CAuB7E"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node classifier - determines how to format different node types.
|
|
3
|
+
*
|
|
4
|
+
* This module uses CSS display values to classify HTML elements, matching
|
|
5
|
+
* Prettier's approach to whitespace sensitivity in HTML formatting.
|
|
6
|
+
*/
|
|
7
|
+
import type { Node as SyntaxNode } from 'web-tree-sitter';
|
|
8
|
+
import type { CustomCodeTagConfig } from '../customCodeTags.js';
|
|
9
|
+
export type CSSDisplay = 'block' | 'inline' | 'inline-block' | 'table-row' | 'table-cell' | 'table' | 'table-row-group' | 'table-header-group' | 'table-footer-group' | 'table-column' | 'table-column-group' | 'table-caption' | 'list-item' | 'ruby' | 'ruby-base' | 'ruby-text' | 'none';
|
|
10
|
+
export declare const INLINE_ELEMENTS: Set<string>;
|
|
11
|
+
export declare const PRESERVE_CONTENT_ELEMENTS: Set<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Get the CSS display value for a node.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getCSSDisplay(node: SyntaxNode, customTags?: Map<string, CustomCodeTagConfig>): CSSDisplay;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a display value means the element is whitespace-insensitive
|
|
18
|
+
* (i.e., we can freely add/remove whitespace around it).
|
|
19
|
+
*/
|
|
20
|
+
export declare function isWhitespaceInsensitive(display: CSSDisplay): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a node represents a block-level element that should cause indentation.
|
|
23
|
+
* Delegates to getCSSDisplay for classification.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isBlockLevel(node: SyntaxNode, customTags?: Map<string, CustomCodeTagConfig>): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Check if an HTML element is an inline element.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isInlineElement(node: SyntaxNode, customTags?: Map<string, CustomCodeTagConfig>): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Check if element content should be preserved as-is.
|
|
32
|
+
*/
|
|
33
|
+
export declare function shouldPreserveContent(node: SyntaxNode, customTags?: Map<string, CustomCodeTagConfig>): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Check if a mustache section contains any block-level content.
|
|
36
|
+
* A section has block content if:
|
|
37
|
+
* - It contains block-level HTML elements, OR
|
|
38
|
+
* - It contains any HTML elements with implicit end tags (HTML crossing boundaries)
|
|
39
|
+
*/
|
|
40
|
+
export declare function hasBlockContent(sectionNode: SyntaxNode, customTags?: Map<string, CustomCodeTagConfig>): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Check if a node is block-level content (for determining mustache section treatment).
|
|
43
|
+
*/
|
|
44
|
+
export declare function isBlockLevelContent(node: SyntaxNode, customTags?: Map<string, CustomCodeTagConfig>): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Get the content nodes from a mustache section (excluding begin/end tags).
|
|
47
|
+
*/
|
|
48
|
+
export declare function getContentNodes(sectionNode: SyntaxNode): SyntaxNode[];
|
|
49
|
+
/**
|
|
50
|
+
* Check if any HTML elements in the given nodes have implicit end tags
|
|
51
|
+
* (forced closed by mustache section end rather than explicit </tag>).
|
|
52
|
+
*/
|
|
53
|
+
export declare function hasImplicitEndTags(nodes: SyntaxNode[]): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Check if a node is part of a text flow (adjacent to non-whitespace text).
|
|
56
|
+
* Nodes that are part of text flow should stay inline.
|
|
57
|
+
*/
|
|
58
|
+
export declare function isInTextFlow(node: SyntaxNode, index: number, nodes: SyntaxNode[]): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Check if an HTML element should stay inline.
|
|
61
|
+
* Elements stay inline if they're part of a text flow or adjacent to other inline elements.
|
|
62
|
+
*/
|
|
63
|
+
export declare function shouldHtmlElementStayInline(node: SyntaxNode, index: number, nodes: SyntaxNode[], customTags?: Map<string, CustomCodeTagConfig>): boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Determine if a node should be treated as block-level for formatting purposes.
|
|
66
|
+
*/
|
|
67
|
+
export declare function shouldTreatAsBlock(node: SyntaxNode, index: number, nodes: SyntaxNode[], customTags?: Map<string, CustomCodeTagConfig>): boolean;
|
|
68
|
+
//# sourceMappingURL=classifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classifier.d.ts","sourceRoot":"","sources":["../../../../src/core/formatting/classifier.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG1D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAKhE,MAAM,MAAM,UAAU,GAClB,OAAO,GACP,QAAQ,GACR,cAAc,GACd,WAAW,GACX,YAAY,GACZ,OAAO,GACP,iBAAiB,GACjB,oBAAoB,GACpB,oBAAoB,GACpB,cAAc,GACd,oBAAoB,GACpB,eAAe,GACf,WAAW,GACX,MAAM,GACN,WAAW,GACX,WAAW,GACX,MAAM,CAAC;AAgGX,eAAO,MAAM,eAAe,aAoC1B,CAAC;AAGH,eAAO,MAAM,yBAAyB,aAMpC,CAAC;AAEH;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,GAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAa,GAAG,UAAU,CA+BpH;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAkBpE;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,GAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAa,GAAG,OAAO,CAoBhH;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,GAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAa,GAAG,OAAO,CAMnH;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,GAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAa,GAAG,OAAO,CAkBzH;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,UAAU,EAAE,UAAU,GAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAa,GAAG,OAAO,CAe1H;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,GAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAa,GAAG,OAAO,CAqBvH;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,UAAU,GAAG,UAAU,EAAE,CAwBrE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAO/D;AA4CD;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,EAAE,GAClB,OAAO,CAkBT;AA2BD;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,EAAE,EACnB,UAAU,GAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAa,GACvD,OAAO,CAqCT;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,EAAE,EACnB,UAAU,GAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAa,GACvD,OAAO,CAWT"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared embedded-region formatter used by both the CLI and the browser entry.
|
|
3
|
+
* Takes the already-parsed rootNode, extracts `<script>` / `<style>` regions,
|
|
4
|
+
* and returns a map of startIndex → prettier-formatted content. If no prettier
|
|
5
|
+
* is provided, returns an empty map (caller falls back to leaving regions as-is).
|
|
6
|
+
*/
|
|
7
|
+
import type { Node as SyntaxNode } from 'web-tree-sitter';
|
|
8
|
+
import type { FormattingOptions } from './index.js';
|
|
9
|
+
export declare const LANGUAGE_TO_PRETTIER_PARSER: Record<string, string>;
|
|
10
|
+
export interface PrettierLike {
|
|
11
|
+
format(source: string, options: {
|
|
12
|
+
parser: string;
|
|
13
|
+
tabWidth?: number;
|
|
14
|
+
useTabs?: boolean;
|
|
15
|
+
plugins?: unknown[];
|
|
16
|
+
}): string | Promise<string>;
|
|
17
|
+
}
|
|
18
|
+
export declare function formatEmbeddedRegions(rootNode: SyntaxNode, options: FormattingOptions, prettier: PrettierLike | null | undefined): Promise<Map<number, string>>;
|
|
19
|
+
//# sourceMappingURL=embedded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded.d.ts","sourceRoot":"","sources":["../../../../src/core/formatting/embedded.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAI9D,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE;QAC9B,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;KACrB,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC9B;AAED,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,UAAU,EACpB,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,GACxC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAyB9B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formatters - convert AST nodes to Doc IR.
|
|
3
|
+
*
|
|
4
|
+
* This module converts tree-sitter AST nodes to the Doc intermediate
|
|
5
|
+
* representation. It uses CSS display-based classification to determine
|
|
6
|
+
* whitespace sensitivity and wraps elements in groups so the printer
|
|
7
|
+
* can decide flat vs break based on print width.
|
|
8
|
+
*/
|
|
9
|
+
import type { Node as SyntaxNode } from 'web-tree-sitter';
|
|
10
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
11
|
+
import { Doc } from './ir.js';
|
|
12
|
+
import type { CustomCodeTagConfig } from '../customCodeTags.js';
|
|
13
|
+
import type { NoBreakDelimiter } from '../configSchema.js';
|
|
14
|
+
export interface FormatterContext {
|
|
15
|
+
document: TextDocument;
|
|
16
|
+
customTags?: Map<string, CustomCodeTagConfig>;
|
|
17
|
+
embeddedFormatted?: Map<number, string>;
|
|
18
|
+
mustacheSpaces?: boolean;
|
|
19
|
+
noBreakDelimiters?: NoBreakDelimiter[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Check if an attribute value is truthy (not null, empty, "false", or "0").
|
|
23
|
+
*/
|
|
24
|
+
export declare function isAttributeTruthy(value: string | null): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Dedent content by stripping leading/trailing empty lines and removing the
|
|
27
|
+
* minimum common indentation from all non-empty lines.
|
|
28
|
+
*/
|
|
29
|
+
export declare function dedentContent(rawContent: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Format the document root node.
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatDocument(node: SyntaxNode, context: FormatterContext): Doc;
|
|
34
|
+
/**
|
|
35
|
+
* Format a node based on its type.
|
|
36
|
+
* @param forceInline - If true, format as inline even if content would normally be block-level
|
|
37
|
+
*/
|
|
38
|
+
export declare function formatNode(node: SyntaxNode, context: FormatterContext, forceInline?: boolean): Doc;
|
|
39
|
+
/**
|
|
40
|
+
* Format a text node.
|
|
41
|
+
*/
|
|
42
|
+
export declare function formatText(node: SyntaxNode): Doc;
|
|
43
|
+
/**
|
|
44
|
+
* Format an HTML element.
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatHtmlElement(node: SyntaxNode, context: FormatterContext, forceInline?: boolean): Doc;
|
|
47
|
+
/**
|
|
48
|
+
* Format script or style element.
|
|
49
|
+
* Uses pre-formatted content from embeddedFormatted map when available,
|
|
50
|
+
* otherwise preserves raw content as-is.
|
|
51
|
+
*/
|
|
52
|
+
export declare function formatScriptStyleElement(node: SyntaxNode, context: FormatterContext): Doc;
|
|
53
|
+
/**
|
|
54
|
+
* Format a mustache section ({{#...}} or {{^...}}).
|
|
55
|
+
*/
|
|
56
|
+
export declare function formatMustacheSection(node: SyntaxNode, context: FormatterContext): Doc;
|
|
57
|
+
/**
|
|
58
|
+
* Format a start tag with attributes.
|
|
59
|
+
* Wraps in a group so attributes break onto separate lines when
|
|
60
|
+
* the tag exceeds print width.
|
|
61
|
+
* When `bare` is true, returns the tag IR without the outer group wrapper.
|
|
62
|
+
*/
|
|
63
|
+
export declare function formatStartTag(node: SyntaxNode, context?: FormatterContext, bare?: boolean): Doc;
|
|
64
|
+
/**
|
|
65
|
+
* Format an end tag.
|
|
66
|
+
*/
|
|
67
|
+
export declare function formatEndTag(node: SyntaxNode): Doc;
|
|
68
|
+
/**
|
|
69
|
+
* Format an HTML attribute.
|
|
70
|
+
*/
|
|
71
|
+
export declare function formatAttribute(node: SyntaxNode, context?: FormatterContext): Doc;
|
|
72
|
+
/**
|
|
73
|
+
* Replace `line` separators with `" "` inside delimited regions so the
|
|
74
|
+
* fill algorithm treats delimited content as unbreakable.
|
|
75
|
+
*
|
|
76
|
+
* Scans string parts for delimiter boundaries. Between an opening and closing
|
|
77
|
+
* delimiter, any `line` separator is replaced with a literal space string.
|
|
78
|
+
* Delimiters are matched longest-first to handle e.g. `$$` before `$`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function collapseDelimitedRegions(parts: Doc[], delimiters: NoBreakDelimiter[]): Doc[];
|
|
81
|
+
/**
|
|
82
|
+
* Format block-level children with display-aware separators.
|
|
83
|
+
*/
|
|
84
|
+
export declare function formatBlockChildren(nodes: SyntaxNode[], context: FormatterContext): Doc;
|
|
85
|
+
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../../../src/core/formatting/formatters.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EACL,GAAG,EAaJ,MAAM,SAAS,CAAC;AAWjB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,YAAY,CAAC;IACvB,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;IAC9C,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACxC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAK/D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CA2BxD;AAiCD;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,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4
|
+
* Architecture: AST Node → Doc IR → String
|
|
5
|
+
*
|
|
6
|
+
* Three phases:
|
|
7
|
+
* 1. Classification - Determine node type (block/inline/preserve)
|
|
8
|
+
* 2. AST → IR - Convert nodes to formatting commands
|
|
9
|
+
* 3. IR → String - Print with proper indentation
|
|
10
|
+
*/
|
|
11
|
+
import type { Tree } from 'web-tree-sitter';
|
|
12
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
13
|
+
/** Formatting options (structurally compatible with LSP FormattingOptions). */
|
|
14
|
+
export interface FormattingOptions {
|
|
15
|
+
tabSize: number;
|
|
16
|
+
insertSpaces: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** A position in a text document (0-based line and character). */
|
|
19
|
+
export interface Position {
|
|
20
|
+
line: number;
|
|
21
|
+
character: number;
|
|
22
|
+
}
|
|
23
|
+
/** A range in a text document. */
|
|
24
|
+
export interface Range {
|
|
25
|
+
start: Position;
|
|
26
|
+
end: Position;
|
|
27
|
+
}
|
|
28
|
+
/** A text edit to apply to a document. */
|
|
29
|
+
export interface TextEdit {
|
|
30
|
+
range: Range;
|
|
31
|
+
newText: string;
|
|
32
|
+
}
|
|
33
|
+
import type { NoBreakDelimiter } from '../configSchema.js';
|
|
34
|
+
import type { CustomCodeTagConfig } from '../customCodeTags.js';
|
|
35
|
+
export interface FormatDocumentParams {
|
|
36
|
+
customTags?: CustomCodeTagConfig[];
|
|
37
|
+
printWidth?: number;
|
|
38
|
+
embeddedFormatted?: Map<number, string>;
|
|
39
|
+
mustacheSpaces?: boolean;
|
|
40
|
+
noBreakDelimiters?: NoBreakDelimiter[];
|
|
41
|
+
}
|
|
42
|
+
export declare function formatDocument(tree: Tree, document: TextDocument, options: FormattingOptions, params?: FormatDocumentParams): TextEdit[];
|
|
43
|
+
export declare function formatDocumentRange(tree: Tree, document: TextDocument, range: Range, options: FormattingOptions, params?: FormatDocumentParams): TextEdit[];
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,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I,EACV,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,iBAAiB,EAC1B,MAAM,GAAE,oBAAyB,GAChC,QAAQ,EAAE,CAsDZ"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Intermediate Representation (IR) for document formatting.
|
|
3
|
+
*
|
|
4
|
+
* This module defines the Doc type and builder functions for creating
|
|
5
|
+
* formatting commands. The IR is inspired by Prettier's document model.
|
|
6
|
+
*/
|
|
7
|
+
export type Doc = string | Concat | Indent | Hardline | Softline | Line | Group | Fill | BreakParent | IfBreak;
|
|
8
|
+
export interface Concat {
|
|
9
|
+
type: 'concat';
|
|
10
|
+
parts: Doc[];
|
|
11
|
+
}
|
|
12
|
+
export interface Indent {
|
|
13
|
+
type: 'indent';
|
|
14
|
+
contents: Doc;
|
|
15
|
+
}
|
|
16
|
+
export interface Hardline {
|
|
17
|
+
type: 'hardline';
|
|
18
|
+
}
|
|
19
|
+
export interface Softline {
|
|
20
|
+
type: 'softline';
|
|
21
|
+
}
|
|
22
|
+
export interface Line {
|
|
23
|
+
type: 'line';
|
|
24
|
+
}
|
|
25
|
+
export interface Group {
|
|
26
|
+
type: 'group';
|
|
27
|
+
contents: Doc;
|
|
28
|
+
break?: boolean;
|
|
29
|
+
id?: symbol;
|
|
30
|
+
}
|
|
31
|
+
export interface Fill {
|
|
32
|
+
type: 'fill';
|
|
33
|
+
parts: Doc[];
|
|
34
|
+
}
|
|
35
|
+
export interface BreakParent {
|
|
36
|
+
type: 'breakParent';
|
|
37
|
+
}
|
|
38
|
+
export interface IfBreak {
|
|
39
|
+
type: 'ifBreak';
|
|
40
|
+
breakContents: Doc;
|
|
41
|
+
flatContents: Doc;
|
|
42
|
+
groupId?: symbol;
|
|
43
|
+
}
|
|
44
|
+
export declare const hardline: Hardline;
|
|
45
|
+
export declare const softline: Softline;
|
|
46
|
+
export declare const line: Line;
|
|
47
|
+
export declare const breakParent: BreakParent;
|
|
48
|
+
export declare const empty = "";
|
|
49
|
+
/**
|
|
50
|
+
* Create a literal text node.
|
|
51
|
+
*/
|
|
52
|
+
export declare function text(value: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Concatenate multiple docs into a single doc.
|
|
55
|
+
*/
|
|
56
|
+
export declare function concat(parts: Doc[]): Doc;
|
|
57
|
+
/**
|
|
58
|
+
* Indent the contents by one level.
|
|
59
|
+
*/
|
|
60
|
+
export declare function indent(contents: Doc): Doc;
|
|
61
|
+
/**
|
|
62
|
+
* Indent the contents by N levels.
|
|
63
|
+
*/
|
|
64
|
+
export declare function indentN(contents: Doc, n: number): Doc;
|
|
65
|
+
/**
|
|
66
|
+
* Create a group that may be printed flat or broken across lines.
|
|
67
|
+
* When `shouldBreak` is true, the group will always break.
|
|
68
|
+
* When `id` is set, the group's mode can be referenced by `ifBreak` nodes.
|
|
69
|
+
*/
|
|
70
|
+
export declare function group(contents: Doc, options?: {
|
|
71
|
+
shouldBreak?: boolean;
|
|
72
|
+
id?: symbol;
|
|
73
|
+
}): Doc;
|
|
74
|
+
/**
|
|
75
|
+
* Create an ifBreak node that prints different content depending on
|
|
76
|
+
* whether the enclosing group breaks or stays flat.
|
|
77
|
+
* When `groupId` is set, checks that specific group's mode instead.
|
|
78
|
+
*/
|
|
79
|
+
export declare function ifBreak(breakContents: Doc, flatContents: Doc, options?: {
|
|
80
|
+
groupId?: symbol;
|
|
81
|
+
}): Doc;
|
|
82
|
+
/**
|
|
83
|
+
* Create a fill for inline content that wraps when needed.
|
|
84
|
+
* Parts alternate between content and separators.
|
|
85
|
+
*/
|
|
86
|
+
export declare function fill(parts: Doc[]): Doc;
|
|
87
|
+
/**
|
|
88
|
+
* Join docs with a separator.
|
|
89
|
+
*/
|
|
90
|
+
export declare function join(separator: Doc, docs: Doc[]): Doc;
|
|
91
|
+
export declare function isConcat(doc: Doc): doc is Concat;
|
|
92
|
+
export declare function isIndent(doc: Doc): doc is Indent;
|
|
93
|
+
export declare function isHardline(doc: Doc): doc is Hardline;
|
|
94
|
+
export declare function isSoftline(doc: Doc): doc is Softline;
|
|
95
|
+
export declare function isLine(doc: Doc): doc is Line;
|
|
96
|
+
export declare function isGroup(doc: Doc): doc is Group;
|
|
97
|
+
export declare function isFill(doc: Doc): doc is Fill;
|
|
98
|
+
export declare function isBreakParent(doc: Doc): doc is BreakParent;
|
|
99
|
+
export declare function isIfBreak(doc: Doc): doc is IfBreak;
|
|
100
|
+
//# sourceMappingURL=ir.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir.d.ts","sourceRoot":"","sources":["../../../../src/core/formatting/ir.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,MAAM,MAAM,GAAG,GACX,MAAM,GACN,MAAM,GACN,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,WAAW,GACX,OAAO,CAAC;AAEZ,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,GAAG,EAAE,CAAC;CACd;AAED,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,GAAG,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,GAAG,EAAE,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EA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AAE,GAAG,GAAG,CAUrD;AAGD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAEhD;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAEhD;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,QAAQ,CAEpD;AAED,wBAAgB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,QAAQ,CAEpD;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,IAAI,CAE5C;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,KAAK,CAE9C;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,IAAI,CAE5C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,WAAW,CAE1D;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,OAAO,CAElD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure option merging + indent-unit construction.
|
|
3
|
+
*
|
|
4
|
+
* EditorConfig-aware merging lives in `lsp/server/src/formatting/editorconfig.ts`
|
|
5
|
+
* and layers on top of these results by passing its result as `overrides`.
|
|
6
|
+
*/
|
|
7
|
+
import type { FormattingOptions } from './index.js';
|
|
8
|
+
import type { HtmlMustacheConfig } from '../configSchema.js';
|
|
9
|
+
/**
|
|
10
|
+
* Merge base options with `configFile` (indentSize only) and optional
|
|
11
|
+
* `overrides` (tabSize / insertSpaces). Pure; no fs.
|
|
12
|
+
*
|
|
13
|
+
* Priority (low → high): lspOptions < configFile.indentSize < overrides.
|
|
14
|
+
* `insertSpaces` never comes from `configFile` — only `lspOptions` or `overrides`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function mergeOptions(lspOptions: FormattingOptions, configFile?: HtmlMustacheConfig | null, overrides?: Partial<FormattingOptions>): FormattingOptions;
|
|
17
|
+
export declare function createIndentUnit(options: FormattingOptions): string;
|
|
18
|
+
//# sourceMappingURL=mergeOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeOptions.d.ts","sourceRoot":"","sources":["../../../../src/core/formatting/mergeOptions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,iBAAiB,EAC7B,UAAU,CAAC,EAAE,kBAAkB,GAAG,IAAI,EACtC,SAAS,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GACrC,iBAAiB,CAQnB;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAEnE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Printer module - converts Doc IR to formatted string.
|
|
3
|
+
*
|
|
4
|
+
* The printer traverses the Doc tree and produces a string with proper
|
|
5
|
+
* indentation and line breaks.
|
|
6
|
+
*/
|
|
7
|
+
import type { Doc } from './ir.js';
|
|
8
|
+
export interface PrinterOptions {
|
|
9
|
+
/** The indentation string (e.g., ' ' for 2 spaces or '\t' for tab) */
|
|
10
|
+
indentUnit: string;
|
|
11
|
+
/** Maximum line width before breaking (used for group fitting) */
|
|
12
|
+
printWidth?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Print a Doc to a string with the given options.
|
|
16
|
+
*/
|
|
17
|
+
export declare function print(doc: Doc, options: PrinterOptions): string;
|
|
18
|
+
//# sourceMappingURL=printer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printer.d.ts","sourceRoot":"","sources":["../../../../src/core/formatting/printer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,WAAW,cAAc;IAC7B,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAQD;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,GAAG,MAAM,CAO/D"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for formatting.
|
|
3
|
+
*/
|
|
4
|
+
import type { Node as SyntaxNode } from 'web-tree-sitter';
|
|
5
|
+
export { getTagName } from '../nodeHelpers.js';
|
|
6
|
+
/**
|
|
7
|
+
* Normalize text content - collapse horizontal whitespace while preserving line breaks.
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizeText(text: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Get visible children of a node (excluding anonymous nodes starting with _).
|
|
12
|
+
*/
|
|
13
|
+
export declare function getVisibleChildren(node: SyntaxNode): SyntaxNode[];
|
|
14
|
+
/**
|
|
15
|
+
* Calculate the indent level of a node based on its parent chain.
|
|
16
|
+
*/
|
|
17
|
+
export declare function calculateIndentLevel(node: SyntaxNode, isBlockLevel: (node: SyntaxNode) => boolean, hasImplicitEndTags: (nodes: SyntaxNode[]) => boolean, getContentNodes: (node: SyntaxNode) => SyntaxNode[]): number;
|
|
18
|
+
/**
|
|
19
|
+
* Normalize whitespace inside a single mustache expression.
|
|
20
|
+
* Handles triple ({{{...}}}), prefixed ({{#, {{/, {{^, {{!, {{>), and plain ({{...}}).
|
|
21
|
+
* For multiline comments, preserves internal newlines, only normalizes space adjacent to delimiters.
|
|
22
|
+
*/
|
|
23
|
+
export declare function normalizeMustacheWhitespace(raw: string, addSpaces: boolean): string;
|
|
24
|
+
/**
|
|
25
|
+
* Normalize whitespace in ALL mustache expressions within a string.
|
|
26
|
+
* Used for force-inlined sections where the full section text (e.g. `{{#plural}}s{{/plural}}`)
|
|
27
|
+
* is emitted as one string.
|
|
28
|
+
*/
|
|
29
|
+
export declare function normalizeMustacheWhitespaceAll(raw: string, addSpaces: boolean): string;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a node is a format-ignore directive comment.
|
|
32
|
+
* Returns the directive type or null if not a directive.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getIgnoreDirective(node: SyntaxNode): 'ignore' | 'ignore-start' | 'ignore-end' | null;
|
|
35
|
+
/**
|
|
36
|
+
* Find the smallest node that contains the entire range.
|
|
37
|
+
*/
|
|
38
|
+
export declare function findContainingNode(node: SyntaxNode, startOffset: number, endOffset: number): SyntaxNode | null;
|
|
39
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/core/formatting/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQlD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,EAAE,CASjE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,UAAU,EAChB,YAAY,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,EAC3C,kBAAkB,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,OAAO,EACpD,eAAe,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,EAAE,GAClD,MAAM,CAsBR;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CA0CnF;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,CAKtF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,UAAU,GACf,QAAQ,GAAG,cAAc,GAAG,YAAY,GAAG,IAAI,CA4BjD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,UAAU,EAChB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,UAAU,GAAG,IAAI,CAoBnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../../src/core/grammar.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,kCAAkC,CAAC"}
|