(options)
| 10 | } |
| 11 | |
| 12 | toCSS(options) { |
| 13 | let evaldRoot; |
| 14 | const result = {}; |
| 15 | let sourceMapBuilder; |
| 16 | try { |
| 17 | evaldRoot = transformTree(this.root, options); |
| 18 | } catch (e) { |
| 19 | throw new LessError(e, this.imports); |
| 20 | } |
| 21 | |
| 22 | try { |
| 23 | const compress = Boolean(options.compress); |
| 24 | if (compress) { |
| 25 | logger.warn('The compress option has been deprecated. ' + |
| 26 | 'We recommend you use a dedicated css minifier, for instance see less-plugin-clean-css.'); |
| 27 | } |
| 28 | |
| 29 | const toCSSOptions = { |
| 30 | compress, |
| 31 | // @deprecated The dumpLineNumbers option is deprecated. Use sourcemaps instead. All modes will be removed in a future version. |
| 32 | dumpLineNumbers: options.dumpLineNumbers, |
| 33 | strictUnits: Boolean(options.strictUnits), |
| 34 | numPrecision: 8}; |
| 35 | |
| 36 | if (options.sourceMap) { |
| 37 | // Normalize sourceMap option: if it's just true, convert to object |
| 38 | if (options.sourceMap === true) { |
| 39 | options.sourceMap = {}; |
| 40 | } |
| 41 | const sourceMapOpts = options.sourceMap; |
| 42 | |
| 43 | // Set sourceMapInputFilename if not set and filename is available |
| 44 | if (!sourceMapOpts.sourceMapInputFilename && options.filename) { |
| 45 | sourceMapOpts.sourceMapInputFilename = options.filename; |
| 46 | } |
| 47 | |
| 48 | // Default sourceMapBasepath to the input file's directory if not set |
| 49 | // This matches the behavior documented and implemented in bin/lessc |
| 50 | if (sourceMapOpts.sourceMapBasepath === undefined && options.filename) { |
| 51 | // Get directory from filename using string manipulation (works cross-platform) |
| 52 | const lastSlash = Math.max(options.filename.lastIndexOf('/'), options.filename.lastIndexOf('\\')); |
| 53 | if (lastSlash >= 0) { |
| 54 | sourceMapOpts.sourceMapBasepath = options.filename.substring(0, lastSlash); |
| 55 | } else { |
| 56 | // No directory separator found, use current directory |
| 57 | sourceMapOpts.sourceMapBasepath = '.'; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // Handle sourceMapFullFilename (CLI-specific: --source-map=filename) |
| 62 | // This is converted to sourceMapFilename and sourceMapOutputFilename |
| 63 | if (sourceMapOpts.sourceMapFullFilename && !sourceMapOpts.sourceMapFileInline) { |
| 64 | // This case is handled by lessc before calling render |
| 65 | // We just need to ensure sourceMapFilename is set if sourceMapFullFilename is provided |
| 66 | if (!sourceMapOpts.sourceMapFilename && !sourceMapOpts.sourceMapURL) { |
| 67 | // Extract just the basename for the sourceMappingURL comment |
| 68 | const mapBase = sourceMapOpts.sourceMapFullFilename.split(/[/\\]/).pop(); |
| 69 | sourceMapOpts.sourceMapFilename = mapBase; |
no test coverage detected