@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
package/dist/index.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lass-lang/core
|
|
3
|
+
*
|
|
4
|
+
* Lass language transpiler core package.
|
|
5
|
+
* Converts .lass files to executable JavaScript modules that produce CSS.
|
|
6
|
+
*
|
|
7
|
+
* Transpilation Pipeline (The Story):
|
|
8
|
+
* 1. detectZones() - Split source into preamble and CSS zones
|
|
9
|
+
* 2. stripLineComments() - Remove // comments from CSS zone
|
|
10
|
+
* 3. normalizeStyleLookupShorthands() - @prop -> @(prop)
|
|
11
|
+
* 4. resolvePropertyAccessors() - @(prop) -> value
|
|
12
|
+
* 5. resolveDollarVariables() - $param -> ${...}
|
|
13
|
+
* 6. processExpressions() - {{ expr }} -> ${...}
|
|
14
|
+
* 7. buildOutput() - Assemble final JS module
|
|
15
|
+
*
|
|
16
|
+
* This is the "igloo" view - each function is a building block.
|
|
17
|
+
* Drill into transpiler.ts for step implementations.
|
|
18
|
+
*/
|
|
19
|
+
import { detectZones, stripLineComments, normalizeStyleLookupShorthands, resolvePropertyAccessors, resolveDollarVariables, processExpressions, buildOutput, } from './transpiler.js';
|
|
20
|
+
// ============================================================================
|
|
21
|
+
// MAIN ENTRY POINT
|
|
22
|
+
// ============================================================================
|
|
23
|
+
/**
|
|
24
|
+
* Transpiles Lass source code to a JavaScript module.
|
|
25
|
+
*
|
|
26
|
+
* The Story (Igloo Principle):
|
|
27
|
+
* 1. Split the file into preamble and CSS zones at the ---
|
|
28
|
+
* 2. Strip // comments from CSS zone
|
|
29
|
+
* 3. Normalize @prop -> @(prop) shorthands
|
|
30
|
+
* 4. Resolve @(prop) accessors to their values
|
|
31
|
+
* 5. Replace $param with ${...} for variable substitution
|
|
32
|
+
* 6. Find {{ expressions }} and make them interpolations
|
|
33
|
+
* 7. Wrap it all in a JS module that exports CSS
|
|
34
|
+
*
|
|
35
|
+
* Implementation History:
|
|
36
|
+
* - Story 1.4: CSS passthrough - wraps input in JS module export
|
|
37
|
+
* - Story 2.1: Two-zone detection - splits on ---, identifies preamble and CSS zones
|
|
38
|
+
* - Story 2.2: Preamble execution - includes preamble in output, executes when imported
|
|
39
|
+
* - Story 2.3: Expression interpolation - transforms {{ expr }} to ${expr} in template literal
|
|
40
|
+
* - Story 2.4: Array auto-join - wraps expressions in __lassScriptExpression() for array/null handling
|
|
41
|
+
* - Story 2.5: Universal {{ }} - processed everywhere in CSS zone (strings, url(), comments)
|
|
42
|
+
* - Story 3.2: @(prop) resolution - resolves @(prop) to previously-declared CSS values (Phase 1)
|
|
43
|
+
* - Story 3.3: @(prop) in {{ }} - detects @(prop) inside expressions, quotes values for JS context
|
|
44
|
+
* - Refactored: Changed from @prop to @(prop) for unambiguous syntax (supports custom properties)
|
|
45
|
+
* - Story 4.1: $param substitution - replaces $param with ${$param} for template literal interpolation
|
|
46
|
+
* - Story 4.2: @prop shorthand - normalizes @prop to @(prop) before resolution
|
|
47
|
+
* - Story 4.4: // comment stripping - removes single-line comments from CSS zone
|
|
48
|
+
*
|
|
49
|
+
* @param source - The Lass source code
|
|
50
|
+
* @param options - Transpilation options
|
|
51
|
+
* @returns The transpiled JavaScript module code
|
|
52
|
+
*/
|
|
53
|
+
export function transpile(source, options = {}) {
|
|
54
|
+
// Step 1: Split source into preamble and CSS zones
|
|
55
|
+
const zones = detectZones(source, options);
|
|
56
|
+
// Step 2: Strip // comments from CSS zone (before any symbol resolution)
|
|
57
|
+
const strippedCssZone = stripLineComments(zones.cssZone);
|
|
58
|
+
// Step 3a: Normalize @prop shorthands to @(prop) form
|
|
59
|
+
const normalizedCssZone = normalizeStyleLookupShorthands(strippedCssZone);
|
|
60
|
+
// Step 3b: Resolve @(prop) accessors (Phase 1 - before {{ }} processing)
|
|
61
|
+
const resolvedCssZone = resolvePropertyAccessors(normalizedCssZone, options);
|
|
62
|
+
// Step 4: Replace $param with __lassScriptLookup() calls for variable substitution
|
|
63
|
+
const dollarResult = resolveDollarVariables(resolvedCssZone, options);
|
|
64
|
+
// Step 5: Process {{ expressions }} in CSS zone (Phase 2)
|
|
65
|
+
const template = processExpressions(dollarResult.cssZone, dollarResult.hasDollarVariables, options);
|
|
66
|
+
// Step 6: Assemble final JS module
|
|
67
|
+
const code = buildOutput(zones, template);
|
|
68
|
+
return { code };
|
|
69
|
+
}
|
|
70
|
+
// ============================================================================
|
|
71
|
+
// RE-EXPORTS: SCANNER
|
|
72
|
+
// ============================================================================
|
|
73
|
+
export { Scanner } from './scanner.js';
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// RE-EXPORTS: ERRORS
|
|
76
|
+
// ============================================================================
|
|
77
|
+
export { LassTranspileError, ErrorCategory, formatLocation, } from './errors.js';
|
|
78
|
+
// ============================================================================
|
|
79
|
+
// RE-EXPORTS: SCOPE TRACKER (for consumers needing low-level access)
|
|
80
|
+
// ============================================================================
|
|
81
|
+
export { cutByBraces, findPropertyValue, areSiblingTrees, isInsideAtRule, } from './scope-tracker.js';
|
|
82
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,8BAA8B,EAC9B,wBAAwB,EACxB,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAGzB,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,SAAS,CACvB,MAAc,EACd,UAA4B,EAAE;IAE9B,mDAAmD;IACnD,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE3C,yEAAyE;IACzE,MAAM,eAAe,GAAG,iBAAiB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAEzD,sDAAsD;IACtD,MAAM,iBAAiB,GAAG,8BAA8B,CAAC,eAAe,CAAC,CAAC;IAE1E,yEAAyE;IACzE,MAAM,eAAe,GAAG,wBAAwB,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;IAE7E,mFAAmF;IACnF,MAAM,YAAY,GAAG,sBAAsB,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAEtE,0DAA0D;IAC1D,MAAM,QAAQ,GAAG,kBAAkB,CAAC,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;IAEpG,mCAAmC;IACnC,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAE1C,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC;AAQD,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAavC,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,cAAc,GAGf,MAAM,aAAa,CAAC;AAErB,+EAA+E;AAC/E,qEAAqE;AACrE,+EAA+E;AAE/E,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,cAAc,GAGf,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-pass text scanner for Lass language.
|
|
3
|
+
*
|
|
4
|
+
* The scanner processes input in a single pass. It does NOT parse CSS - it
|
|
5
|
+
* only scans for Lass symbols within CSS text.
|
|
6
|
+
*
|
|
7
|
+
* Story 1.4: Passthrough-only
|
|
8
|
+
* Story 2.1: Zone detection (--- separator)
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Result of a scan operation.
|
|
12
|
+
* For passthrough mode, this simply returns the input unchanged.
|
|
13
|
+
*/
|
|
14
|
+
export interface ScanResult {
|
|
15
|
+
/** The processed CSS text (unchanged in passthrough mode) */
|
|
16
|
+
css: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Result of zone separation.
|
|
20
|
+
* Story 2.1: Detects --- separator and splits into JS preamble and CSS zone.
|
|
21
|
+
*/
|
|
22
|
+
export interface ZoneSplit {
|
|
23
|
+
/** Content above --- (empty string if no separator or empty preamble) */
|
|
24
|
+
preamble: string;
|
|
25
|
+
/** Content below --- (entire file if no separator) */
|
|
26
|
+
cssZone: string;
|
|
27
|
+
/** Whether a --- separator was found */
|
|
28
|
+
hasSeparator: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Result of expression splitting.
|
|
32
|
+
* Story 2.3: Detects {{ expr }} and splits CSS zone into alternating parts.
|
|
33
|
+
*/
|
|
34
|
+
export interface ExpressionSplit {
|
|
35
|
+
/** Alternating: [css, expr, css, expr, ...] - always starts and ends with css (possibly empty) */
|
|
36
|
+
parts: string[];
|
|
37
|
+
/** Character offsets of expression starts ({{ positions) for error reporting */
|
|
38
|
+
expressionPositions: number[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Information about a detected @(prop) accessor.
|
|
42
|
+
* Story 3.2: Basic Property Lookup
|
|
43
|
+
* Refactored: Changed from @prop to @(prop) for unambiguous syntax
|
|
44
|
+
*/
|
|
45
|
+
export interface PropertyAccessor {
|
|
46
|
+
/** The property name (without @ and parentheses) */
|
|
47
|
+
propName: string;
|
|
48
|
+
/** Start index of @(propname) in the CSS string */
|
|
49
|
+
startIndex: number;
|
|
50
|
+
/** End index (exclusive) of @(propname) in the CSS string */
|
|
51
|
+
endIndex: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Information about a detected $param variable.
|
|
55
|
+
* Story 4.1: Variable Substitution
|
|
56
|
+
*/
|
|
57
|
+
export interface DollarVariable {
|
|
58
|
+
/** The variable name including $ prefix (e.g., '$primary', '$$var') */
|
|
59
|
+
varName: string;
|
|
60
|
+
/** Start index of $varname in the CSS string */
|
|
61
|
+
startIndex: number;
|
|
62
|
+
/** End index (exclusive) of $varname in the CSS string */
|
|
63
|
+
endIndex: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Information about a detected @prop shorthand.
|
|
67
|
+
* Story 4.2: Style Lookup Shorthand
|
|
68
|
+
*/
|
|
69
|
+
export interface StyleLookupShorthand {
|
|
70
|
+
/** The property name (without @ prefix) */
|
|
71
|
+
propName: string;
|
|
72
|
+
/** Start index of @propname in the CSS string */
|
|
73
|
+
startIndex: number;
|
|
74
|
+
/** End index (exclusive) of @propname in the CSS string */
|
|
75
|
+
endIndex: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Scanner options for customizing scan behavior.
|
|
79
|
+
*/
|
|
80
|
+
export interface ScanOptions {
|
|
81
|
+
/** Source file path for error messages */
|
|
82
|
+
filename?: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Single-pass text scanner for Lass language.
|
|
86
|
+
*
|
|
87
|
+
* Story 1.4: Passthrough mode - returns input unchanged
|
|
88
|
+
* Story 2.1: Zone detection - finds --- separator, splits into preamble/CSS
|
|
89
|
+
* Story 3.2: @(prop) detection - finds property accessors in value position
|
|
90
|
+
*
|
|
91
|
+
* Future implementations will:
|
|
92
|
+
* - Detect $name, $(name), {{ expr }}, @{ } symbols
|
|
93
|
+
* - Track context to skip symbols inside strings, urls, and comments
|
|
94
|
+
*/
|
|
95
|
+
export declare class Scanner {
|
|
96
|
+
private readonly source;
|
|
97
|
+
constructor(source: string, _options?: ScanOptions);
|
|
98
|
+
/**
|
|
99
|
+
* Finds the --- separator and splits source into preamble and CSS zones.
|
|
100
|
+
*
|
|
101
|
+
* Story 2.1: Zone detection
|
|
102
|
+
*
|
|
103
|
+
* Rules:
|
|
104
|
+
* - Separator must be exactly "---" at column 0 (start of line)
|
|
105
|
+
* - May have trailing whitespace
|
|
106
|
+
* - Must NOT be inside a multi-line comment (slash-star ... star-slash)
|
|
107
|
+
* - Only one separator allowed per file
|
|
108
|
+
*
|
|
109
|
+
* Note: Line endings are normalized to \n during processing.
|
|
110
|
+
* When no separator is found, cssZone returns the original source unchanged.
|
|
111
|
+
*
|
|
112
|
+
* @returns Zone split result with preamble, cssZone, and hasSeparator
|
|
113
|
+
* @throws LassTranspileError if multiple separators found
|
|
114
|
+
*/
|
|
115
|
+
findSeparator(): ZoneSplit;
|
|
116
|
+
/**
|
|
117
|
+
* Checks if a line is the --- separator.
|
|
118
|
+
* Must be exactly "---" with optional trailing whitespace.
|
|
119
|
+
*/
|
|
120
|
+
private isSeparatorLine;
|
|
121
|
+
/**
|
|
122
|
+
* Checks if line at index is inside a block comment.
|
|
123
|
+
* Scans from start of file to determine comment state at the START of the line.
|
|
124
|
+
*/
|
|
125
|
+
private isInBlockComment;
|
|
126
|
+
/**
|
|
127
|
+
* Calculates character offset for a given line.
|
|
128
|
+
*/
|
|
129
|
+
private getOffset;
|
|
130
|
+
/**
|
|
131
|
+
* Scans the input and returns processed CSS.
|
|
132
|
+
*
|
|
133
|
+
* In passthrough mode (Story 1.4), this returns the input unchanged.
|
|
134
|
+
*
|
|
135
|
+
* @returns Scan result with processed CSS
|
|
136
|
+
*/
|
|
137
|
+
scan(): ScanResult;
|
|
138
|
+
/**
|
|
139
|
+
* Finds {{ expr }} expressions in CSS zone and splits into alternating parts.
|
|
140
|
+
*
|
|
141
|
+
* Story 2.3: Expression interpolation
|
|
142
|
+
* Story 2.5: Universal {{ }} processing - works EVERYWHERE in CSS zone
|
|
143
|
+
*
|
|
144
|
+
* Returns alternating CSS chunks and JS expressions:
|
|
145
|
+
* - [css, expr, css, expr, css] - always starts and ends with CSS (possibly empty)
|
|
146
|
+
* - Expression content is trimmed of leading/trailing whitespace
|
|
147
|
+
*
|
|
148
|
+
* Handles nested braces in expressions (e.g., {{ fn({x:1}) }}) by tracking brace depth.
|
|
149
|
+
*
|
|
150
|
+
* Universal processing: {{ }} is detected and processed in ALL contexts:
|
|
151
|
+
* - Value position: `color: {{ x }};`
|
|
152
|
+
* - Inside strings: `content: "Hello {{ name }}!";`
|
|
153
|
+
* - Inside url(): `background: url("{{ path }}.jpg");`
|
|
154
|
+
* - Inside comments: `/* Version: {{ version }} */`
|
|
155
|
+
*
|
|
156
|
+
* @param cssZone - The CSS zone content to scan
|
|
157
|
+
* @returns ExpressionSplit with parts and expression positions
|
|
158
|
+
* @throws LassTranspileError for empty or unclosed expressions
|
|
159
|
+
*/
|
|
160
|
+
findExpressions(cssZone: string): ExpressionSplit;
|
|
161
|
+
/**
|
|
162
|
+
* Gets the 1-based line number for a character offset.
|
|
163
|
+
*/
|
|
164
|
+
private getLineNumber;
|
|
165
|
+
/**
|
|
166
|
+
* Gets the 1-based column number for a character offset.
|
|
167
|
+
*/
|
|
168
|
+
private getColumnNumber;
|
|
169
|
+
/**
|
|
170
|
+
* Known CSS at-rules - kept for reference but not needed for @(prop) detection.
|
|
171
|
+
* The @(prop) syntax with parentheses is unambiguous - no collision with CSS at-rules.
|
|
172
|
+
*/
|
|
173
|
+
private static readonly CSS_AT_RULES;
|
|
174
|
+
/**
|
|
175
|
+
* Finds @(prop) accessors in CSS zone.
|
|
176
|
+
*
|
|
177
|
+
* Story 3.2: Basic Property Lookup
|
|
178
|
+
* Refactored: Changed from @prop to @(prop) for unambiguous syntax
|
|
179
|
+
*
|
|
180
|
+
* Detection rules:
|
|
181
|
+
* - @(propname) in CSS value position (after :) is a Lass accessor
|
|
182
|
+
* - The explicit parentheses make this unambiguous - no collision with CSS at-rules
|
|
183
|
+
* - Supports both standard properties and custom properties: @(border), @(--custom)
|
|
184
|
+
*
|
|
185
|
+
* Valid CSS property names inside @():
|
|
186
|
+
* - Standard: letter or hyphen start, then letters/digits/hyphens
|
|
187
|
+
* - Custom: -- followed by letters/digits/hyphens
|
|
188
|
+
*
|
|
189
|
+
* @param cssZone - The CSS zone content to scan
|
|
190
|
+
* @returns Array of PropertyAccessor objects with propName and indices
|
|
191
|
+
*/
|
|
192
|
+
findPropertyAccessors(cssZone: string): PropertyAccessor[];
|
|
193
|
+
/**
|
|
194
|
+
* Static version of findPropertyAccessors for use without Scanner instantiation.
|
|
195
|
+
* Used internally by transpiler to avoid creating unnecessary Scanner instances.
|
|
196
|
+
*
|
|
197
|
+
* Story 3.3: Handles @(prop) inside {{ }} expressions.
|
|
198
|
+
* - {{ doesn't reset inValuePosition (JS expression can contain @(prop))
|
|
199
|
+
* - }} doesn't reset inValuePosition (exiting expression, still in value)
|
|
200
|
+
* - Single { resets inValuePosition (entering CSS block)
|
|
201
|
+
* - @(prop) inside {{ }} is detected and will be quoted during resolution
|
|
202
|
+
*
|
|
203
|
+
* Refactored: Changed from @prop to @(prop) for unambiguous syntax.
|
|
204
|
+
* This eliminates ambiguity in JS context: @(border-width) is clear,
|
|
205
|
+
* unlike @border-width which could be @border minus width.
|
|
206
|
+
*
|
|
207
|
+
* @param cssZone - The CSS zone content to scan
|
|
208
|
+
* @returns Array of PropertyAccessor objects with propName and indices
|
|
209
|
+
*/
|
|
210
|
+
static findPropertyAccessorsStatic(cssZone: string): PropertyAccessor[];
|
|
211
|
+
/**
|
|
212
|
+
* Finds $param variables in CSS zone.
|
|
213
|
+
*
|
|
214
|
+
* Story 4.1: Variable Substitution
|
|
215
|
+
*
|
|
216
|
+
* Detection rules:
|
|
217
|
+
* - $param is detected when $ is followed by a valid JS identifier character
|
|
218
|
+
* - Valid identifier start: [a-zA-Z_$]
|
|
219
|
+
* - Valid identifier char: [a-zA-Z0-9_$]
|
|
220
|
+
* - Identifier stops at first non-identifier character (hyphen, space, ;, {, etc.)
|
|
221
|
+
* - Bare $ (not followed by valid identifier start) is treated as literal text
|
|
222
|
+
*
|
|
223
|
+
* Protected contexts (detection skipped):
|
|
224
|
+
* - Inside CSS string literals ("..." or '...')
|
|
225
|
+
* - Inside /* ... */ block comments
|
|
226
|
+
*
|
|
227
|
+
* Note: url() is NOT a protected context - $param inside url() IS substituted.
|
|
228
|
+
* Use {{ $param }} bridge syntax if you need dynamic content inside strings.
|
|
229
|
+
*
|
|
230
|
+
* @param cssZone - The CSS zone content to scan
|
|
231
|
+
* @returns Array of DollarVariable objects with varName and indices
|
|
232
|
+
*/
|
|
233
|
+
findDollarVariables(cssZone: string): DollarVariable[];
|
|
234
|
+
/**
|
|
235
|
+
* Static version of findDollarVariables for use without Scanner instantiation.
|
|
236
|
+
* Used internally by transpiler to avoid creating unnecessary Scanner instances.
|
|
237
|
+
*
|
|
238
|
+
* Story 4.1: Variable Substitution
|
|
239
|
+
*
|
|
240
|
+
* @param cssZone - The CSS zone content to scan
|
|
241
|
+
* @returns Array of DollarVariable objects with varName and indices
|
|
242
|
+
*/
|
|
243
|
+
static findDollarVariablesStatic(cssZone: string): DollarVariable[];
|
|
244
|
+
/**
|
|
245
|
+
* Checks if a character is a valid JS identifier start.
|
|
246
|
+
* Valid: a-z, A-Z, _, $
|
|
247
|
+
*/
|
|
248
|
+
private static isIdentifierStart;
|
|
249
|
+
/**
|
|
250
|
+
* Checks if a character is a valid JS identifier character.
|
|
251
|
+
* Valid: a-z, A-Z, 0-9, _, $
|
|
252
|
+
*/
|
|
253
|
+
private static isIdentifierChar;
|
|
254
|
+
/**
|
|
255
|
+
* Finds @prop shorthand accessors in CSS zone.
|
|
256
|
+
*
|
|
257
|
+
* Story 4.2: Style Lookup Shorthand
|
|
258
|
+
*
|
|
259
|
+
* Detection rules:
|
|
260
|
+
* - @prop in CSS value position (after :) is a Lass shorthand accessor
|
|
261
|
+
* - @prop shorthand only works when identifier starts with a letter [a-zA-Z]
|
|
262
|
+
* - Identifier continues with letters, digits, hyphens, underscores
|
|
263
|
+
* - NOT detected inside {{ }} script blocks (use explicit @(prop) there)
|
|
264
|
+
* - NOT detected inside protected contexts: strings, comments, url()
|
|
265
|
+
*
|
|
266
|
+
* Examples:
|
|
267
|
+
* - @border → shorthand for @(border)
|
|
268
|
+
* - @border-color → shorthand for @(border-color)
|
|
269
|
+
* - @--custom → NOT detected (starts with hyphen, use @(--custom))
|
|
270
|
+
* - @-webkit-foo → NOT detected (starts with hyphen, use @(-webkit-foo))
|
|
271
|
+
*
|
|
272
|
+
* @param cssZone - The CSS zone content to scan
|
|
273
|
+
* @returns Array of StyleLookupShorthand objects with propName and indices
|
|
274
|
+
*/
|
|
275
|
+
findStyleLookupShorthands(cssZone: string): StyleLookupShorthand[];
|
|
276
|
+
/**
|
|
277
|
+
* Static version of findStyleLookupShorthands for use without Scanner instantiation.
|
|
278
|
+
* Used internally by transpiler to avoid creating unnecessary Scanner instances.
|
|
279
|
+
*
|
|
280
|
+
* Story 4.2: Style Lookup Shorthand
|
|
281
|
+
*
|
|
282
|
+
* @param cssZone - The CSS zone content to scan
|
|
283
|
+
* @returns Array of StyleLookupShorthand objects with propName and indices
|
|
284
|
+
*/
|
|
285
|
+
static findStyleLookupShorthandsStatic(cssZone: string): StyleLookupShorthand[];
|
|
286
|
+
/**
|
|
287
|
+
* Checks if a character is a valid CSS identifier character.
|
|
288
|
+
* Valid: a-z, A-Z, 0-9, -, _
|
|
289
|
+
*/
|
|
290
|
+
private static isCssIdentifierChar;
|
|
291
|
+
/**
|
|
292
|
+
* Strips // single-line comments from CSS zone.
|
|
293
|
+
*
|
|
294
|
+
* Story 4.4: Single-Line Comment Stripping
|
|
295
|
+
*
|
|
296
|
+
* Detection rules:
|
|
297
|
+
* - // to end of line (including newline) is removed
|
|
298
|
+
* - Skip detection inside protected contexts: strings, url(), /* *\/
|
|
299
|
+
* - Full-line comments remove the entire line
|
|
300
|
+
* - Inline comments preserve content before //
|
|
301
|
+
*
|
|
302
|
+
* Note: url() is protected here (unlike $param/@prop) because
|
|
303
|
+
* url(https://...) contains // as part of the URL protocol.
|
|
304
|
+
*
|
|
305
|
+
* @param cssZone - The CSS zone content to process
|
|
306
|
+
* @returns CSS zone with // comments stripped
|
|
307
|
+
* @throws LassTranspileError if unclosed /* comment detected
|
|
308
|
+
*/
|
|
309
|
+
stripLineComments(cssZone: string): string;
|
|
310
|
+
/**
|
|
311
|
+
* Static version of stripLineComments for use without Scanner instantiation.
|
|
312
|
+
* Used internally by transpiler to avoid creating unnecessary Scanner instances.
|
|
313
|
+
*
|
|
314
|
+
* Story 4.4: Single-Line Comment Stripping
|
|
315
|
+
*
|
|
316
|
+
* @param cssZone - The CSS zone content to process
|
|
317
|
+
* @returns CSS zone with // comments stripped
|
|
318
|
+
* @throws LassTranspileError if unclosed /* comment detected
|
|
319
|
+
*/
|
|
320
|
+
static stripLineCommentsStatic(cssZone: string): string;
|
|
321
|
+
/**
|
|
322
|
+
* Gets the 1-based line number for a character offset (static version).
|
|
323
|
+
*/
|
|
324
|
+
private static getLineNumberStatic;
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scanner.d.ts","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"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"}
|