aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/css-tree/cjs/generator/sourceMap.cjs
diff options
context:
space:
mode:
authorAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
committerAdam Mathes <adam@adammathes.com>2026-02-13 21:34:48 -0800
commit76cb9c2a39d477a64824a985ade40507e3bbade1 (patch)
tree41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/css-tree/cjs/generator/sourceMap.cjs
parent819a39a21ac992b1393244a4c283bbb125208c69 (diff)
downloadneko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.gz
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.bz2
neko-76cb9c2a39d477a64824a985ade40507e3bbade1.zip
feat(vanilla): add testing infrastructure and tests (NK-wjnczv)
Diffstat (limited to 'vanilla/node_modules/css-tree/cjs/generator/sourceMap.cjs')
-rw-r--r--vanilla/node_modules/css-tree/cjs/generator/sourceMap.cjs96
1 files changed, 96 insertions, 0 deletions
diff --git a/vanilla/node_modules/css-tree/cjs/generator/sourceMap.cjs b/vanilla/node_modules/css-tree/cjs/generator/sourceMap.cjs
new file mode 100644
index 0000000..efbc5b9
--- /dev/null
+++ b/vanilla/node_modules/css-tree/cjs/generator/sourceMap.cjs
@@ -0,0 +1,96 @@
+'use strict';
+
+const sourceMapGenerator_js = require('source-map-js/lib/source-map-generator.js');
+
+const trackNodes = new Set(['Atrule', 'Selector', 'Declaration']);
+
+function generateSourceMap(handlers) {
+ const map = new sourceMapGenerator_js.SourceMapGenerator();
+ const generated = {
+ line: 1,
+ column: 0
+ };
+ const original = {
+ line: 0, // should be zero to add first mapping
+ column: 0
+ };
+ const activatedGenerated = {
+ line: 1,
+ column: 0
+ };
+ const activatedMapping = {
+ generated: activatedGenerated
+ };
+ let line = 1;
+ let column = 0;
+ let sourceMappingActive = false;
+
+ const origHandlersNode = handlers.node;
+ handlers.node = function(node) {
+ if (node.loc && node.loc.start && trackNodes.has(node.type)) {
+ const nodeLine = node.loc.start.line;
+ const nodeColumn = node.loc.start.column - 1;
+
+ if (original.line !== nodeLine ||
+ original.column !== nodeColumn) {
+ original.line = nodeLine;
+ original.column = nodeColumn;
+
+ generated.line = line;
+ generated.column = column;
+
+ if (sourceMappingActive) {
+ sourceMappingActive = false;
+ if (generated.line !== activatedGenerated.line ||
+ generated.column !== activatedGenerated.column) {
+ map.addMapping(activatedMapping);
+ }
+ }
+
+ sourceMappingActive = true;
+ map.addMapping({
+ source: node.loc.source,
+ original,
+ generated
+ });
+ }
+ }
+
+ origHandlersNode.call(this, node);
+
+ if (sourceMappingActive && trackNodes.has(node.type)) {
+ activatedGenerated.line = line;
+ activatedGenerated.column = column;
+ }
+ };
+
+ const origHandlersEmit = handlers.emit;
+ handlers.emit = function(value, type, auto) {
+ for (let i = 0; i < value.length; i++) {
+ if (value.charCodeAt(i) === 10) { // \n
+ line++;
+ column = 0;
+ } else {
+ column++;
+ }
+ }
+
+ origHandlersEmit(value, type, auto);
+ };
+
+ const origHandlersResult = handlers.result;
+ handlers.result = function() {
+ if (sourceMappingActive) {
+ map.addMapping(activatedMapping);
+ }
+
+ return {
+ css: origHandlersResult(),
+ map
+ };
+ };
+
+ return handlers;
+}
+
+exports.generateSourceMap = generateSourceMap;