@lass-lang/core 0.0.1
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/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/README.md +93 -0
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +32 -0
- package/dist/constants.js.map +1 -0
- package/dist/context-tracker.d.ts +46 -0
- package/dist/context-tracker.d.ts.map +1 -0
- package/dist/context-tracker.js +76 -0
- package/dist/context-tracker.js.map +1 -0
- package/dist/errors.d.ts +80 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +81 -0
- package/dist/errors.js.map +1 -0
- package/dist/helpers.d.ts +24 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.js +32 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/scanner.d.ts +326 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +815 -0
- package/dist/scanner.js.map +1 -0
- package/dist/scope-tracker.d.ts +160 -0
- package/dist/scope-tracker.d.ts.map +1 -0
- package/dist/scope-tracker.js +376 -0
- package/dist/scope-tracker.js.map +1 -0
- package/dist/transpiler.d.ts +153 -0
- package/dist/transpiler.d.ts.map +1 -0
- package/dist/transpiler.js +650 -0
- package/dist/transpiler.js.map +1 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transpiler pipeline functions for @lass-lang/core
|
|
3
|
+
*
|
|
4
|
+
* Each function represents a step in the transpilation story.
|
|
5
|
+
* See index.ts for the main entry point that orchestrates these steps.
|
|
6
|
+
*/
|
|
7
|
+
import type { DetectedZones, ProcessedTemplate, DollarResolutionResult, TranspileOptions } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Step 1: Detect and split zones.
|
|
10
|
+
*
|
|
11
|
+
* Finds the --- separator and splits source into preamble and CSS zones.
|
|
12
|
+
* If no separator, entire source is the CSS zone (pure CSS passthrough).
|
|
13
|
+
*
|
|
14
|
+
* @param source - Raw Lass source code
|
|
15
|
+
* @param options - Transpile options (filename for errors)
|
|
16
|
+
* @returns Detected zones with preamble and cssZone
|
|
17
|
+
*/
|
|
18
|
+
export declare function detectZones(source: string, options: TranspileOptions): DetectedZones;
|
|
19
|
+
/**
|
|
20
|
+
* Step 2: Strip // comments from CSS zone.
|
|
21
|
+
*
|
|
22
|
+
* Story 4.4: Single-line comment stripping.
|
|
23
|
+
* Removes // comments while respecting protected contexts (strings, url(), block comments).
|
|
24
|
+
*
|
|
25
|
+
* @param cssZone - The CSS zone content
|
|
26
|
+
* @returns CSS zone with // comments removed
|
|
27
|
+
*/
|
|
28
|
+
export declare function stripLineComments(cssZone: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Step 3a: Normalize @prop shorthands to @(prop) form.
|
|
31
|
+
*
|
|
32
|
+
* Story 4.2: Style Lookup Shorthand
|
|
33
|
+
*
|
|
34
|
+
* Finds @prop patterns in CSS value position and converts them to @(prop).
|
|
35
|
+
* This runs BEFORE @(prop) resolution so all lookups are handled uniformly.
|
|
36
|
+
*
|
|
37
|
+
* Detection rules:
|
|
38
|
+
* - @prop shorthand only works when identifier starts with a letter [a-zA-Z]
|
|
39
|
+
* - NOT detected inside {{ }} script blocks
|
|
40
|
+
* - NOT detected inside protected contexts: strings, comments, url()
|
|
41
|
+
*
|
|
42
|
+
* @param cssZone - The CSS zone content
|
|
43
|
+
* @returns CSS zone with @prop normalized to @(prop)
|
|
44
|
+
*/
|
|
45
|
+
export declare function normalizeStyleLookupShorthands(cssZone: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Step 3b: Resolve @(prop) accessors in CSS zone.
|
|
48
|
+
*
|
|
49
|
+
* Story 3.2: Basic Property Lookup
|
|
50
|
+
* Story 3.3: Lookup in {{ }} Context
|
|
51
|
+
* Refactored: Changed from @prop to @(prop) for unambiguous syntax
|
|
52
|
+
*
|
|
53
|
+
* Finds @(prop) patterns in CSS value position and resolves them to their
|
|
54
|
+
* previously-declared values using scope tracking utilities.
|
|
55
|
+
*
|
|
56
|
+
* Resolution rules:
|
|
57
|
+
* - Property found in CSS context -> Replace @(prop) with resolved value
|
|
58
|
+
* - Property found in JS context (inside {{ }}) -> Replace with quoted value
|
|
59
|
+
* - Property not found -> Preserve @(prop) unchanged (PostCSS/future CSS compatibility)
|
|
60
|
+
*
|
|
61
|
+
* This is Phase 1 of transpilation and runs BEFORE {{ }} processing.
|
|
62
|
+
*
|
|
63
|
+
* @param cssZone - The CSS zone content
|
|
64
|
+
* @param options - Transpile options (filename for errors)
|
|
65
|
+
* @returns CSS zone with @(prop) accessors resolved (or preserved if not found)
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolvePropertyAccessors(cssZone: string, _options: TranspileOptions): string;
|
|
68
|
+
/**
|
|
69
|
+
* Step 4: Replace $param variables with __lassScriptLookup() calls.
|
|
70
|
+
*
|
|
71
|
+
* Story 4.1: Variable Substitution
|
|
72
|
+
*
|
|
73
|
+
* Finds $param patterns in CSS zone and converts them to helper function calls.
|
|
74
|
+
* This enables $-prefixed variables from the preamble to be substituted into CSS
|
|
75
|
+
* with proper handling of null (-> 'unset') and undefined/missing (-> preserved).
|
|
76
|
+
*
|
|
77
|
+
* Protected contexts (strings, url(), comments) are skipped - $param inside these
|
|
78
|
+
* remains as literal text. Use {{ $param }} for dynamic content in protected contexts.
|
|
79
|
+
*
|
|
80
|
+
* @param cssZone - The CSS zone content
|
|
81
|
+
* @param _options - Transpile options (filename for errors)
|
|
82
|
+
* @returns Result with modified CSS zone and flag indicating if helpers needed
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolveDollarVariables(cssZone: string, _options: TranspileOptions): DollarResolutionResult;
|
|
85
|
+
/**
|
|
86
|
+
* Normalizes style block content by trimming and dedenting.
|
|
87
|
+
*
|
|
88
|
+
* Single-line (no newlines): Trim leading/trailing whitespace.
|
|
89
|
+
* Multi-line:
|
|
90
|
+
* - Dedent all lines by the minimum indentation found
|
|
91
|
+
* - Trim leading and trailing whitespace
|
|
92
|
+
*
|
|
93
|
+
* @param content - Raw content from inside @{ }
|
|
94
|
+
* @returns Normalized content
|
|
95
|
+
*/
|
|
96
|
+
export declare function normalizeStyleBlockContent(content: string): string;
|
|
97
|
+
/**
|
|
98
|
+
* Result from style block translation.
|
|
99
|
+
*/
|
|
100
|
+
export interface StyleBlockTranslationResult {
|
|
101
|
+
/** The translated text */
|
|
102
|
+
text: string;
|
|
103
|
+
/** Whether any $param variables were found in style blocks */
|
|
104
|
+
hasDollarVariables: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Translates @{ } style blocks to JS template literals.
|
|
108
|
+
*
|
|
109
|
+
* Story 5.1: Style Block Syntax
|
|
110
|
+
*
|
|
111
|
+
* @{ } is purely delimiter translation:
|
|
112
|
+
* - @{ → backtick (`)
|
|
113
|
+
* - } (matching @{) → backtick (`)
|
|
114
|
+
* - {{ }} inside @{ } → ${ } with __lassScriptExpression helper
|
|
115
|
+
* - $param inside @{ } → ${__lassScriptLookup(...)} for proper null/undefined handling
|
|
116
|
+
*
|
|
117
|
+
* This function handles brace matching to find the correct closing }.
|
|
118
|
+
* Nested braces (from object literals, ternaries, etc.) are tracked.
|
|
119
|
+
*
|
|
120
|
+
* Protected contexts (where @{ is NOT translated):
|
|
121
|
+
* - Inside string literals ("..." or '...')
|
|
122
|
+
* - Inside block comments
|
|
123
|
+
* - Note: url() is NOT protected - @{ inside url() IS translated
|
|
124
|
+
*
|
|
125
|
+
* @param text - JS code containing @{ } style blocks
|
|
126
|
+
* @returns Result with translated text and flag for $param usage
|
|
127
|
+
*/
|
|
128
|
+
export declare function translateStyleBlocks(text: string): StyleBlockTranslationResult;
|
|
129
|
+
/**
|
|
130
|
+
* Step 5b: Process expressions in CSS zone.
|
|
131
|
+
*
|
|
132
|
+
* Finds {{ expr }} expressions and converts them to template literal interpolations.
|
|
133
|
+
* Story 2.5: Expressions are processed EVERYWHERE in CSS zone (strings, url(), comments).
|
|
134
|
+
* Story 5.1: Also translates @{ } style blocks within expressions.
|
|
135
|
+
*
|
|
136
|
+
* @param cssZone - The CSS zone content
|
|
137
|
+
* @param hasDollarVariables - Whether $param variables were found in CSS zone
|
|
138
|
+
* @param options - Transpile options (filename for errors)
|
|
139
|
+
* @returns Processed template with body and expression flag
|
|
140
|
+
*/
|
|
141
|
+
export declare function processExpressions(cssZone: string, hasDollarVariables: boolean, options: TranspileOptions): ProcessedTemplate;
|
|
142
|
+
/**
|
|
143
|
+
* Step 6: Build final JavaScript module output.
|
|
144
|
+
*
|
|
145
|
+
* Assembles preamble, helper functions (if needed), and template literal export.
|
|
146
|
+
* Story 5.1: Also translates @{ } style blocks in preamble.
|
|
147
|
+
*
|
|
148
|
+
* @param zones - Detected zones from step 1
|
|
149
|
+
* @param template - Processed template from step 5
|
|
150
|
+
* @returns Final JavaScript module code
|
|
151
|
+
*/
|
|
152
|
+
export declare function buildOutput(zones: DetectedZones, template: ProcessedTemplate): string;
|
|
153
|
+
//# sourceMappingURL=transpiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transpiler.d.ts","sourceRoot":"","sources":["../src/transpiler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAM7G;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,GAAG,aAAa,CASpF;AAMD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,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