sass-embedded-go 1.104.0-alpha0
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/LICENSE +21 -0
- package/README.md +37 -0
- package/lib/index.js +100 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +215 -0
- package/lib/src/canonicalize-context.js +31 -0
- package/lib/src/canonicalize-context.js.map +1 -0
- package/lib/src/compile.js +51 -0
- package/lib/src/compile.js.map +1 -0
- package/lib/src/compiler/async.js +187 -0
- package/lib/src/compiler/async.js.map +1 -0
- package/lib/src/compiler/sync.js +204 -0
- package/lib/src/compiler/sync.js.map +1 -0
- package/lib/src/compiler/utils.js +210 -0
- package/lib/src/compiler/utils.js.map +1 -0
- package/lib/src/compiler-module.js +64 -0
- package/lib/src/compiler-module.js.map +1 -0
- package/lib/src/compiler-path.js +82 -0
- package/lib/src/compiler-path.js.map +1 -0
- package/lib/src/deprecations.js +121 -0
- package/lib/src/deprecations.js.map +1 -0
- package/lib/src/deprotofy-span.js +41 -0
- package/lib/src/deprotofy-span.js.map +1 -0
- package/lib/src/dispatcher.js +241 -0
- package/lib/src/dispatcher.js.map +1 -0
- package/lib/src/elf.js +114 -0
- package/lib/src/elf.js.map +1 -0
- package/lib/src/exception.js +23 -0
- package/lib/src/exception.js.map +1 -0
- package/lib/src/function-registry.js +127 -0
- package/lib/src/function-registry.js.map +1 -0
- package/lib/src/importer-registry.js +201 -0
- package/lib/src/importer-registry.js.map +1 -0
- package/lib/src/legacy/importer.js +296 -0
- package/lib/src/legacy/importer.js.map +1 -0
- package/lib/src/legacy/index.js +329 -0
- package/lib/src/legacy/index.js.map +1 -0
- package/lib/src/legacy/resolve-path.js +133 -0
- package/lib/src/legacy/resolve-path.js.map +1 -0
- package/lib/src/legacy/utils.js +58 -0
- package/lib/src/legacy/utils.js.map +1 -0
- package/lib/src/legacy/value/base.js +18 -0
- package/lib/src/legacy/value/base.js.map +1 -0
- package/lib/src/legacy/value/color.js +65 -0
- package/lib/src/legacy/value/color.js.map +1 -0
- package/lib/src/legacy/value/index.js +23 -0
- package/lib/src/legacy/value/index.js.map +1 -0
- package/lib/src/legacy/value/list.js +50 -0
- package/lib/src/legacy/value/list.js.map +1 -0
- package/lib/src/legacy/value/map.js +74 -0
- package/lib/src/legacy/value/map.js.map +1 -0
- package/lib/src/legacy/value/number.js +60 -0
- package/lib/src/legacy/value/number.js.map +1 -0
- package/lib/src/legacy/value/string.js +27 -0
- package/lib/src/legacy/value/string.js.map +1 -0
- package/lib/src/legacy/value/wrap.js +115 -0
- package/lib/src/legacy/value/wrap.js.map +1 -0
- package/lib/src/logger.js +10 -0
- package/lib/src/logger.js.map +1 -0
- package/lib/src/message-transformer.js +108 -0
- package/lib/src/message-transformer.js.map +1 -0
- package/lib/src/messages.js +6 -0
- package/lib/src/messages.js.map +1 -0
- package/lib/src/packet-transformer.js +171 -0
- package/lib/src/packet-transformer.js.map +1 -0
- package/lib/src/protofier.js +492 -0
- package/lib/src/protofier.js.map +1 -0
- package/lib/src/request-tracker.js +52 -0
- package/lib/src/request-tracker.js.map +1 -0
- package/lib/src/utils.js +177 -0
- package/lib/src/utils.js.map +1 -0
- package/lib/src/value/argument-list.js +66 -0
- package/lib/src/value/argument-list.js.map +1 -0
- package/lib/src/value/boolean.js +69 -0
- package/lib/src/value/boolean.js.map +1 -0
- package/lib/src/value/calculations.js +114 -0
- package/lib/src/value/calculations.js.map +1 -0
- package/lib/src/value/color.js +869 -0
- package/lib/src/value/color.js.map +1 -0
- package/lib/src/value/function.js +74 -0
- package/lib/src/value/function.js.map +1 -0
- package/lib/src/value/index.js +166 -0
- package/lib/src/value/index.js.map +1 -0
- package/lib/src/value/list.js +101 -0
- package/lib/src/value/list.js.map +1 -0
- package/lib/src/value/map.js +92 -0
- package/lib/src/value/map.js.map +1 -0
- package/lib/src/value/mixin.js +50 -0
- package/lib/src/value/mixin.js.map +1 -0
- package/lib/src/value/null.js +49 -0
- package/lib/src/value/null.js.map +1 -0
- package/lib/src/value/number.js +583 -0
- package/lib/src/value/number.js.map +1 -0
- package/lib/src/value/string.js +118 -0
- package/lib/src/value/string.js.map +1 -0
- package/lib/src/value/utils.js +124 -0
- package/lib/src/value/utils.js.map +1 -0
- package/lib/src/vendor/deprecations.js +216 -0
- package/lib/src/vendor/deprecations.js.map +1 -0
- package/lib/src/vendor/embedded_sass_pb.js +432 -0
- package/lib/src/vendor/embedded_sass_pb.js.map +1 -0
- package/lib/src/vendor/sass/README.md +162 -0
- package/lib/src/vendor/sass/compile.d.ts +342 -0
- package/lib/src/vendor/sass/deprecations.d.ts +312 -0
- package/lib/src/vendor/sass/exception.d.ts +41 -0
- package/lib/src/vendor/sass/importer.d.ts +471 -0
- package/lib/src/vendor/sass/index.d.ts +122 -0
- package/lib/src/vendor/sass/index.m.d.ts +122 -0
- package/lib/src/vendor/sass/legacy/exception.d.ts +55 -0
- package/lib/src/vendor/sass/legacy/function.d.ts +757 -0
- package/lib/src/vendor/sass/legacy/importer.d.ts +169 -0
- package/lib/src/vendor/sass/legacy/options.d.ts +700 -0
- package/lib/src/vendor/sass/legacy/plugin_this.d.ts +74 -0
- package/lib/src/vendor/sass/legacy/render.d.ts +144 -0
- package/lib/src/vendor/sass/logger/index.d.ts +115 -0
- package/lib/src/vendor/sass/logger/source_location.d.ts +21 -0
- package/lib/src/vendor/sass/logger/source_span.d.ts +34 -0
- package/lib/src/vendor/sass/options.d.ts +468 -0
- package/lib/src/vendor/sass/util/promise_or.d.ts +17 -0
- package/lib/src/vendor/sass/value/argument_list.d.ts +47 -0
- package/lib/src/vendor/sass/value/boolean.d.ts +29 -0
- package/lib/src/vendor/sass/value/calculation.d.ts +137 -0
- package/lib/src/vendor/sass/value/color.d.ts +567 -0
- package/lib/src/vendor/sass/value/function.d.ts +22 -0
- package/lib/src/vendor/sass/value/index.d.ts +219 -0
- package/lib/src/vendor/sass/value/list.d.ts +54 -0
- package/lib/src/vendor/sass/value/map.d.ts +41 -0
- package/lib/src/vendor/sass/value/mixin.d.ts +14 -0
- package/lib/src/vendor/sass/value/number.d.ts +305 -0
- package/lib/src/vendor/sass/value/string.d.ts +84 -0
- package/lib/src/version.js +28 -0
- package/lib/src/version.js.map +1 -0
- package/package.json +36 -0
- package/types/compile.d.ts +342 -0
- package/types/deprecations.d.ts +312 -0
- package/types/exception.d.ts +41 -0
- package/types/importer.d.ts +471 -0
- package/types/index.d.ts +122 -0
- package/types/index.m.d.ts +122 -0
- package/types/legacy/exception.d.ts +55 -0
- package/types/legacy/function.d.ts +757 -0
- package/types/legacy/importer.d.ts +169 -0
- package/types/legacy/options.d.ts +700 -0
- package/types/legacy/plugin_this.d.ts +74 -0
- package/types/legacy/render.d.ts +144 -0
- package/types/logger/index.d.ts +115 -0
- package/types/logger/source_location.d.ts +21 -0
- package/types/logger/source_span.d.ts +34 -0
- package/types/options.d.ts +468 -0
- package/types/util/promise_or.d.ts +17 -0
- package/types/value/argument_list.d.ts +47 -0
- package/types/value/boolean.d.ts +29 -0
- package/types/value/calculation.d.ts +137 -0
- package/types/value/color.d.ts +567 -0
- package/types/value/function.d.ts +22 -0
- package/types/value/index.d.ts +219 -0
- package/types/value/list.d.ts +54 -0
- package/types/value/map.d.ts +41 -0
- package/types/value/mixin.d.ts +14 -0
- package/types/value/number.d.ts +305 -0
- package/types/value/string.d.ts +84 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2020 Google Inc. Use of this source code is governed by an
|
|
3
|
+
// MIT-style license that can be found in the LICENSE file or at
|
|
4
|
+
// https://opensource.org/licenses/MIT.
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PacketTransformer = void 0;
|
|
7
|
+
const rxjs_1 = require("rxjs");
|
|
8
|
+
const operators_1 = require("rxjs/operators");
|
|
9
|
+
/**
|
|
10
|
+
* Decodes arbitrarily-chunked buffers, for example
|
|
11
|
+
* [ 0 1 2 3 4 5 6 7 ... ],
|
|
12
|
+
* into packets of set length in the form
|
|
13
|
+
* +---------+------------- ...
|
|
14
|
+
* | 0 1 2 3 | 4 5 6 7 ...
|
|
15
|
+
* +---------+------------- ...
|
|
16
|
+
* | HEADER | PAYLOAD (PROTOBUF)
|
|
17
|
+
* +---------+------------- ...
|
|
18
|
+
* and emits the payload of each packet.
|
|
19
|
+
*
|
|
20
|
+
* Encodes packets by attaching a header to a protobuf that describes the
|
|
21
|
+
* protobuf's length.
|
|
22
|
+
*/
|
|
23
|
+
class PacketTransformer {
|
|
24
|
+
outboundBuffers$;
|
|
25
|
+
writeInboundBuffer;
|
|
26
|
+
// The packet that is actively being decoded as buffers come in.
|
|
27
|
+
packet = new Packet();
|
|
28
|
+
// The decoded protobufs are written to this Subject. It is publicly exposed
|
|
29
|
+
// as a readonly Observable.
|
|
30
|
+
outboundProtobufsInternal$ = new rxjs_1.Subject();
|
|
31
|
+
/**
|
|
32
|
+
* The fully-decoded, outbound protobufs. If any errors are encountered
|
|
33
|
+
* during encoding/decoding, this Observable will error out.
|
|
34
|
+
*/
|
|
35
|
+
outboundProtobufs$ = this.outboundProtobufsInternal$.pipe();
|
|
36
|
+
constructor(outboundBuffers$, writeInboundBuffer) {
|
|
37
|
+
this.outboundBuffers$ = outboundBuffers$;
|
|
38
|
+
this.writeInboundBuffer = writeInboundBuffer;
|
|
39
|
+
this.outboundBuffers$
|
|
40
|
+
.pipe((0, operators_1.mergeMap)(buffer => this.decode(buffer)))
|
|
41
|
+
.subscribe(this.outboundProtobufsInternal$);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Encodes a packet by pre-fixing `protobuf` with a header that describes its
|
|
45
|
+
* length.
|
|
46
|
+
*/
|
|
47
|
+
writeInboundProtobuf(protobuf) {
|
|
48
|
+
try {
|
|
49
|
+
let length = protobuf.length;
|
|
50
|
+
if (length === 0) {
|
|
51
|
+
this.writeInboundBuffer(Buffer.alloc(1));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Write the length in varint format, 7 bits at a time from least to most
|
|
55
|
+
// significant.
|
|
56
|
+
const header = Buffer.alloc(8);
|
|
57
|
+
let offset = 0;
|
|
58
|
+
while (length > 0) {
|
|
59
|
+
// The highest-order bit indicates whether more bytes are necessary to
|
|
60
|
+
// fully express the number. The lower 7 bits indicate the number's
|
|
61
|
+
// value.
|
|
62
|
+
header.writeUInt8((length > 0x7f ? 0x80 : 0) | (length & 0x7f), offset);
|
|
63
|
+
offset++;
|
|
64
|
+
length >>= 7;
|
|
65
|
+
}
|
|
66
|
+
const packet = Buffer.alloc(offset + protobuf.length);
|
|
67
|
+
header.copy(packet, 0, 0, offset);
|
|
68
|
+
packet.set(protobuf, offset);
|
|
69
|
+
this.writeInboundBuffer(packet);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
this.outboundProtobufsInternal$.error(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Decodes a buffer, filling up the packet that is actively being decoded.
|
|
76
|
+
// Returns a list of decoded payloads.
|
|
77
|
+
decode(buffer) {
|
|
78
|
+
const payloads = [];
|
|
79
|
+
let decodedBytes = 0;
|
|
80
|
+
while (decodedBytes < buffer.length) {
|
|
81
|
+
decodedBytes += this.packet.write(buffer.slice(decodedBytes));
|
|
82
|
+
if (this.packet.isComplete && this.packet.payload) {
|
|
83
|
+
payloads.push(this.packet.payload);
|
|
84
|
+
this.packet = new Packet();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return payloads;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.PacketTransformer = PacketTransformer;
|
|
91
|
+
/** A length-delimited packet comprised of a header and payload. */
|
|
92
|
+
class Packet {
|
|
93
|
+
// The number of bits we've consumed so far to fill out `payloadLength`.
|
|
94
|
+
payloadLengthBits = 0;
|
|
95
|
+
// The length of the next message, in bytes.
|
|
96
|
+
//
|
|
97
|
+
// This is built up from a [varint]. Once it's fully consumed, `payload` is
|
|
98
|
+
// initialized and this is reset to 0.
|
|
99
|
+
//
|
|
100
|
+
// [varint]: https://developers.google.com/protocol-buffers/docs/encoding#varints
|
|
101
|
+
payloadLength = 0;
|
|
102
|
+
/**
|
|
103
|
+
* The packet's payload. Constructed by calls to write().
|
|
104
|
+
* @see write
|
|
105
|
+
*/
|
|
106
|
+
payload;
|
|
107
|
+
// The offset in [payload] that should be written to next time data arrives.
|
|
108
|
+
payloadOffset = 0;
|
|
109
|
+
/** Whether the packet construction is complete. */
|
|
110
|
+
get isComplete() {
|
|
111
|
+
return !!(this.payload && this.payloadOffset >= this.payloadLength);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Takes arbitrary binary input and slots it into the header and payload
|
|
115
|
+
* appropriately. Returns the number of bytes that were written into the
|
|
116
|
+
* packet. This method can be called repeatedly, incrementally building
|
|
117
|
+
* up the packet until it is complete.
|
|
118
|
+
*/
|
|
119
|
+
write(source) {
|
|
120
|
+
if (this.isComplete) {
|
|
121
|
+
throw Error('Cannot write to a completed Packet.');
|
|
122
|
+
}
|
|
123
|
+
// The index of the next byte to read from [source]. We have to track this
|
|
124
|
+
// because the source may contain the length *and* the message.
|
|
125
|
+
let i = 0;
|
|
126
|
+
// We can be in one of two states here:
|
|
127
|
+
//
|
|
128
|
+
// * [payload] is `null`, in which case we're adding data to [payloadLength]
|
|
129
|
+
// until we reach a byte with its most significant bit set to 0.
|
|
130
|
+
//
|
|
131
|
+
// * [payload] is not `null`, in which case we're waiting for
|
|
132
|
+
// [payloadOffset] to reach [payloadLength] bytes in it so this packet is
|
|
133
|
+
// complete.
|
|
134
|
+
if (!this.payload) {
|
|
135
|
+
for (;;) {
|
|
136
|
+
const byte = source[i];
|
|
137
|
+
// Varints encode data in the 7 lower bits of each byte, which we access
|
|
138
|
+
// by masking with 0x7f = 0b01111111.
|
|
139
|
+
this.payloadLength += (byte & 0x7f) << this.payloadLengthBits;
|
|
140
|
+
this.payloadLengthBits += 7;
|
|
141
|
+
i++;
|
|
142
|
+
if (byte <= 0x7f) {
|
|
143
|
+
// If the byte is lower than 0x7f = 0b01111111, that means its high
|
|
144
|
+
// bit is unset which and we now know the full message length and can
|
|
145
|
+
// initialize [this.payload].
|
|
146
|
+
this.payload = Buffer.alloc(this.payloadLength);
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
else if (i === source.length) {
|
|
150
|
+
// If we've hit the end of the source chunk, we need to wait for the
|
|
151
|
+
// next chunk to arrive. Just return the number of bytes we've
|
|
152
|
+
// consumed so far.
|
|
153
|
+
return i;
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
// Otherwise, we continue reading bytes from the source data to fill
|
|
157
|
+
// in [this.payloadLength].
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Copy as many bytes as we can from [source] to [payload], making sure not
|
|
162
|
+
// to try to copy more than the payload can hold (if the source has another
|
|
163
|
+
// message after the current one) or more than the source has available (if
|
|
164
|
+
// the current message is split across multiple chunks).
|
|
165
|
+
const bytesToWrite = Math.min(this.payload.length - this.payloadOffset, source.length - i);
|
|
166
|
+
this.payload.set(source.subarray(i, i + bytesToWrite), this.payloadOffset);
|
|
167
|
+
this.payloadOffset += bytesToWrite;
|
|
168
|
+
return i + bytesToWrite;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=packet-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packet-transformer.js","sourceRoot":"","sources":["../../../lib/src/packet-transformer.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAEvC,+BAAyC;AACzC,8CAAwC;AAExC;;;;;;;;;;;;;GAaG;AACH;IAeqB,gBAAgB;IAChB,kBAAkB;IAfrC,gEAAgE;IACxD,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;IAE9B,4EAA4E;IAC5E,4BAA4B;IACX,0BAA0B,GAAG,IAAI,cAAO,EAAU,CAAC;IAE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AC,MAAM,GAAG,CAAC,CAClB,CAAC;QACF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC3E,IAAI,CAAC,aAAa,IAAI,YAAY,CAAC;QAEnC,OAAO,CAAC,GAAG,YAAY,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 Google Inc. Use of this source code is governed by an
|
|
3
|
+
// MIT-style license that can be found in the LICENSE file or at
|
|
4
|
+
// https://opensource.org/licenses/MIT.
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Protofier = void 0;
|
|
40
|
+
const immutable_1 = require("immutable");
|
|
41
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
42
|
+
const proto = __importStar(require("./vendor/embedded_sass_pb"));
|
|
43
|
+
const utils = __importStar(require("./utils"));
|
|
44
|
+
const argument_list_1 = require("./value/argument-list");
|
|
45
|
+
const color_1 = require("./value/color");
|
|
46
|
+
const function_1 = require("./value/function");
|
|
47
|
+
const list_1 = require("./value/list");
|
|
48
|
+
const map_1 = require("./value/map");
|
|
49
|
+
const number_1 = require("./value/number");
|
|
50
|
+
const string_1 = require("./value/string");
|
|
51
|
+
const null_1 = require("./value/null");
|
|
52
|
+
const boolean_1 = require("./value/boolean");
|
|
53
|
+
const calculations_1 = require("./value/calculations");
|
|
54
|
+
const mixin_1 = require("./value/mixin");
|
|
55
|
+
/**
|
|
56
|
+
* A class that converts [Value] objects into protobufs.
|
|
57
|
+
*
|
|
58
|
+
* A given [Protofier] instance is valid only within the scope of a single
|
|
59
|
+
* custom function call.
|
|
60
|
+
*/
|
|
61
|
+
class Protofier {
|
|
62
|
+
functions;
|
|
63
|
+
/** All the argument lists returned by `deprotofy()`. */
|
|
64
|
+
argumentLists = [];
|
|
65
|
+
/**
|
|
66
|
+
* Returns IDs of all argument lists passed to `deprotofy()` whose keywords
|
|
67
|
+
* have been accessed.
|
|
68
|
+
*/
|
|
69
|
+
get accessedArgumentLists() {
|
|
70
|
+
return this.argumentLists
|
|
71
|
+
.filter(list => list.keywordsAccessed)
|
|
72
|
+
.map(list => list.id);
|
|
73
|
+
}
|
|
74
|
+
constructor(
|
|
75
|
+
/**
|
|
76
|
+
* The registry of custom functions that can be invoked by the compiler.
|
|
77
|
+
* This is used to register first-class functions so that the compiler may
|
|
78
|
+
* invoke them.
|
|
79
|
+
*/
|
|
80
|
+
functions) {
|
|
81
|
+
this.functions = functions;
|
|
82
|
+
}
|
|
83
|
+
/** Converts `value` to its protocol buffer representation. */
|
|
84
|
+
protofy(value) {
|
|
85
|
+
const result = (0, protobuf_1.create)(proto.ValueSchema, {});
|
|
86
|
+
if (value instanceof string_1.SassString) {
|
|
87
|
+
const string = (0, protobuf_1.create)(proto.Value_StringSchema, {
|
|
88
|
+
text: value.text,
|
|
89
|
+
quoted: value.hasQuotes,
|
|
90
|
+
});
|
|
91
|
+
result.value = { case: 'string', value: string };
|
|
92
|
+
}
|
|
93
|
+
else if (value instanceof number_1.SassNumber) {
|
|
94
|
+
result.value = { case: 'number', value: this.protofyNumber(value) };
|
|
95
|
+
}
|
|
96
|
+
else if (value instanceof color_1.SassColor) {
|
|
97
|
+
const channels = value.channelsOrNull;
|
|
98
|
+
const color = (0, protobuf_1.create)(proto.Value_ColorSchema, {
|
|
99
|
+
channel1: channels.get(0),
|
|
100
|
+
channel2: channels.get(1),
|
|
101
|
+
channel3: channels.get(2),
|
|
102
|
+
alpha: value.isChannelMissing('alpha') ? undefined : value.alpha,
|
|
103
|
+
space: value.space,
|
|
104
|
+
});
|
|
105
|
+
result.value = { case: 'color', value: color };
|
|
106
|
+
}
|
|
107
|
+
else if (value instanceof list_1.SassList) {
|
|
108
|
+
const list = (0, protobuf_1.create)(proto.Value_ListSchema, {
|
|
109
|
+
separator: this.protofySeparator(value.separator),
|
|
110
|
+
hasBrackets: value.hasBrackets,
|
|
111
|
+
contents: value.asList.map(element => this.protofy(element)).toArray(),
|
|
112
|
+
});
|
|
113
|
+
result.value = { case: 'list', value: list };
|
|
114
|
+
}
|
|
115
|
+
else if (value instanceof argument_list_1.SassArgumentList) {
|
|
116
|
+
if (value.compileContext === this.functions.compileContext) {
|
|
117
|
+
const list = (0, protobuf_1.create)(proto.Value_ArgumentListSchema, { id: value.id });
|
|
118
|
+
result.value = { case: 'argumentList', value: list };
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const list = (0, protobuf_1.create)(proto.Value_ArgumentListSchema, {
|
|
122
|
+
separator: this.protofySeparator(value.separator),
|
|
123
|
+
contents: value.asList
|
|
124
|
+
.map(element => this.protofy(element))
|
|
125
|
+
.toArray(),
|
|
126
|
+
});
|
|
127
|
+
for (const [key, mapValue] of value.keywordsInternal) {
|
|
128
|
+
list.keywords[key] = this.protofy(mapValue);
|
|
129
|
+
}
|
|
130
|
+
result.value = { case: 'argumentList', value: list };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (value instanceof map_1.SassMap) {
|
|
134
|
+
const map = (0, protobuf_1.create)(proto.Value_MapSchema, {
|
|
135
|
+
entries: value.contents.toArray().map(([key, value]) => ({
|
|
136
|
+
key: this.protofy(key),
|
|
137
|
+
value: this.protofy(value),
|
|
138
|
+
})),
|
|
139
|
+
});
|
|
140
|
+
result.value = { case: 'map', value: map };
|
|
141
|
+
}
|
|
142
|
+
else if (value instanceof function_1.SassFunction) {
|
|
143
|
+
if (value.id !== undefined) {
|
|
144
|
+
if (value.compileContext !== this.functions.compileContext) {
|
|
145
|
+
throw utils.compilerError(`Value ${value} does not belong to this compilation`);
|
|
146
|
+
}
|
|
147
|
+
const fn = (0, protobuf_1.create)(proto.Value_CompilerFunctionSchema, value);
|
|
148
|
+
result.value = { case: 'compilerFunction', value: fn };
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const fn = (0, protobuf_1.create)(proto.Value_HostFunctionSchema, {
|
|
152
|
+
id: this.functions.register(value.callback),
|
|
153
|
+
signature: value.signature,
|
|
154
|
+
});
|
|
155
|
+
result.value = { case: 'hostFunction', value: fn };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
else if (value instanceof mixin_1.SassMixin) {
|
|
159
|
+
if (value.compileContext !== this.functions.compileContext) {
|
|
160
|
+
throw utils.compilerError(`Value ${value} does not belong to this compilation`);
|
|
161
|
+
}
|
|
162
|
+
const mixin = (0, protobuf_1.create)(proto.Value_CompilerMixinSchema, value);
|
|
163
|
+
result.value = { case: 'compilerMixin', value: mixin };
|
|
164
|
+
}
|
|
165
|
+
else if (value instanceof calculations_1.SassCalculation) {
|
|
166
|
+
result.value = {
|
|
167
|
+
case: 'calculation',
|
|
168
|
+
value: this.protofyCalculation(value),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
else if (value === boolean_1.sassTrue) {
|
|
172
|
+
result.value = { case: 'singleton', value: proto.SingletonValue.TRUE };
|
|
173
|
+
}
|
|
174
|
+
else if (value === boolean_1.sassFalse) {
|
|
175
|
+
result.value = { case: 'singleton', value: proto.SingletonValue.FALSE };
|
|
176
|
+
}
|
|
177
|
+
else if (value === null_1.sassNull) {
|
|
178
|
+
result.value = { case: 'singleton', value: proto.SingletonValue.NULL };
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
throw utils.compilerError(`Unknown Value ${value}`);
|
|
182
|
+
}
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
/** Converts `number` to its protocol buffer representation. */
|
|
186
|
+
protofyNumber(number) {
|
|
187
|
+
return (0, protobuf_1.create)(proto.Value_NumberSchema, {
|
|
188
|
+
value: number.value,
|
|
189
|
+
numerators: number.numeratorUnits.toArray(),
|
|
190
|
+
denominators: number.denominatorUnits.toArray(),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/** Converts `separator` to its protocol buffer representation. */
|
|
194
|
+
protofySeparator(separator) {
|
|
195
|
+
switch (separator) {
|
|
196
|
+
case ',':
|
|
197
|
+
return proto.ListSeparator.COMMA;
|
|
198
|
+
case ' ':
|
|
199
|
+
return proto.ListSeparator.SPACE;
|
|
200
|
+
case '/':
|
|
201
|
+
return proto.ListSeparator.SLASH;
|
|
202
|
+
case null:
|
|
203
|
+
return proto.ListSeparator.UNDECIDED;
|
|
204
|
+
default:
|
|
205
|
+
throw utils.compilerError(`Unknown ListSeparator ${separator}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/** Converts `calculation` to its protocol buffer representation. */
|
|
209
|
+
protofyCalculation(calculation) {
|
|
210
|
+
return (0, protobuf_1.create)(proto.Value_CalculationSchema, {
|
|
211
|
+
name: calculation.name,
|
|
212
|
+
arguments: calculation.arguments
|
|
213
|
+
.map(this.protofyCalculationValue.bind(this))
|
|
214
|
+
.toArray(),
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/** Converts a CalculationValue that appears within a `SassCalculation` to
|
|
218
|
+
* its protocol buffer representation. */
|
|
219
|
+
protofyCalculationValue(value) {
|
|
220
|
+
const result = (0, protobuf_1.create)(proto.Value_Calculation_CalculationValueSchema, {});
|
|
221
|
+
if (value instanceof calculations_1.SassCalculation) {
|
|
222
|
+
result.value = {
|
|
223
|
+
case: 'calculation',
|
|
224
|
+
value: this.protofyCalculation(value),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
else if (value instanceof calculations_1.CalculationOperation) {
|
|
228
|
+
result.value = {
|
|
229
|
+
case: 'operation',
|
|
230
|
+
value: (0, protobuf_1.create)(proto.Value_Calculation_CalculationOperationSchema, {
|
|
231
|
+
operator: this.protofyCalculationOperator(value.operator),
|
|
232
|
+
left: this.protofyCalculationValue(value.left),
|
|
233
|
+
right: this.protofyCalculationValue(value.right),
|
|
234
|
+
}),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
else if (value instanceof calculations_1.CalculationInterpolation) {
|
|
238
|
+
result.value = { case: 'interpolation', value: value.value };
|
|
239
|
+
}
|
|
240
|
+
else if (value instanceof string_1.SassString) {
|
|
241
|
+
result.value = { case: 'string', value: value.text };
|
|
242
|
+
}
|
|
243
|
+
else if (value instanceof number_1.SassNumber) {
|
|
244
|
+
result.value = { case: 'number', value: this.protofyNumber(value) };
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
throw utils.compilerError(`Unknown CalculationValue ${value}`);
|
|
248
|
+
}
|
|
249
|
+
return result;
|
|
250
|
+
}
|
|
251
|
+
/** Converts `operator` to its protocol buffer representation. */
|
|
252
|
+
protofyCalculationOperator(operator) {
|
|
253
|
+
switch (operator) {
|
|
254
|
+
case '+':
|
|
255
|
+
return proto.CalculationOperator.PLUS;
|
|
256
|
+
case '-':
|
|
257
|
+
return proto.CalculationOperator.MINUS;
|
|
258
|
+
case '*':
|
|
259
|
+
return proto.CalculationOperator.TIMES;
|
|
260
|
+
case '/':
|
|
261
|
+
return proto.CalculationOperator.DIVIDE;
|
|
262
|
+
default:
|
|
263
|
+
throw utils.compilerError(`Unknown CalculationOperator ${operator}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/** Converts `value` to its JS representation. */
|
|
267
|
+
deprotofy(value) {
|
|
268
|
+
switch (value.value.case) {
|
|
269
|
+
case 'string': {
|
|
270
|
+
const string = value.value.value;
|
|
271
|
+
return string.text.length === 0
|
|
272
|
+
? string_1.SassString.empty({ quotes: string.quoted })
|
|
273
|
+
: new string_1.SassString(string.text, { quotes: string.quoted });
|
|
274
|
+
}
|
|
275
|
+
case 'number': {
|
|
276
|
+
return this.deprotofyNumber(value.value.value);
|
|
277
|
+
}
|
|
278
|
+
case 'color': {
|
|
279
|
+
const color = value.value.value;
|
|
280
|
+
const channel1 = color.channel1 ?? null;
|
|
281
|
+
const channel2 = color.channel2 ?? null;
|
|
282
|
+
const channel3 = color.channel3 ?? null;
|
|
283
|
+
const alpha = color.alpha ?? null;
|
|
284
|
+
const space = color.space;
|
|
285
|
+
switch (color.space.toLowerCase()) {
|
|
286
|
+
case 'rgb':
|
|
287
|
+
case 'srgb':
|
|
288
|
+
case 'srgb-linear':
|
|
289
|
+
case 'display-p3':
|
|
290
|
+
case 'display-p3-linear':
|
|
291
|
+
case 'a98-rgb':
|
|
292
|
+
case 'prophoto-rgb':
|
|
293
|
+
case 'rec2020':
|
|
294
|
+
return new color_1.SassColor({
|
|
295
|
+
red: channel1,
|
|
296
|
+
green: channel2,
|
|
297
|
+
blue: channel3,
|
|
298
|
+
alpha,
|
|
299
|
+
space,
|
|
300
|
+
});
|
|
301
|
+
case 'hsl':
|
|
302
|
+
return new color_1.SassColor({
|
|
303
|
+
hue: channel1,
|
|
304
|
+
saturation: channel2,
|
|
305
|
+
lightness: channel3,
|
|
306
|
+
alpha,
|
|
307
|
+
space,
|
|
308
|
+
});
|
|
309
|
+
case 'hwb':
|
|
310
|
+
return new color_1.SassColor({
|
|
311
|
+
hue: channel1,
|
|
312
|
+
whiteness: channel2,
|
|
313
|
+
blackness: channel3,
|
|
314
|
+
alpha,
|
|
315
|
+
space,
|
|
316
|
+
});
|
|
317
|
+
case 'lab':
|
|
318
|
+
case 'oklab':
|
|
319
|
+
return new color_1.SassColor({
|
|
320
|
+
lightness: channel1,
|
|
321
|
+
a: channel2,
|
|
322
|
+
b: channel3,
|
|
323
|
+
alpha,
|
|
324
|
+
space,
|
|
325
|
+
});
|
|
326
|
+
case 'lch':
|
|
327
|
+
case 'oklch':
|
|
328
|
+
return new color_1.SassColor({
|
|
329
|
+
lightness: channel1,
|
|
330
|
+
chroma: channel2,
|
|
331
|
+
hue: channel3,
|
|
332
|
+
alpha,
|
|
333
|
+
space,
|
|
334
|
+
});
|
|
335
|
+
case 'xyz':
|
|
336
|
+
case 'xyz-d65':
|
|
337
|
+
case 'xyz-d50':
|
|
338
|
+
return new color_1.SassColor({
|
|
339
|
+
x: channel1,
|
|
340
|
+
y: channel2,
|
|
341
|
+
z: channel3,
|
|
342
|
+
alpha,
|
|
343
|
+
space,
|
|
344
|
+
});
|
|
345
|
+
default:
|
|
346
|
+
throw utils.compilerError(`Unknown color space "${color.space}"`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
case 'list': {
|
|
350
|
+
const list = value.value.value;
|
|
351
|
+
const separator = this.deprotofySeparator(list.separator);
|
|
352
|
+
if (separator === null && list.contents.length > 1) {
|
|
353
|
+
throw utils.compilerError(`Value.List ${list} can't have an undecided separator because it ` +
|
|
354
|
+
`has ${list.contents.length} elements`);
|
|
355
|
+
}
|
|
356
|
+
return new list_1.SassList(list.contents.map(element => this.deprotofy(element)), { separator, brackets: list.hasBrackets });
|
|
357
|
+
}
|
|
358
|
+
case 'argumentList': {
|
|
359
|
+
const list = value.value.value;
|
|
360
|
+
const separator = this.deprotofySeparator(list.separator);
|
|
361
|
+
if (separator === null && list.contents.length > 1) {
|
|
362
|
+
throw utils.compilerError(`Value.List ${list} can't have an undecided separator because it ` +
|
|
363
|
+
`has ${list.contents.length} elements`);
|
|
364
|
+
}
|
|
365
|
+
const result = new argument_list_1.SassArgumentList(list.contents.map(element => this.deprotofy(element)), (0, immutable_1.OrderedMap)(Object.entries(list.keywords).map(([key, value]) => [
|
|
366
|
+
key,
|
|
367
|
+
this.deprotofy(value),
|
|
368
|
+
])), separator, list.id, this.functions.compileContext);
|
|
369
|
+
this.argumentLists.push(result);
|
|
370
|
+
return result;
|
|
371
|
+
}
|
|
372
|
+
case 'map':
|
|
373
|
+
return new map_1.SassMap((0, immutable_1.OrderedMap)(value.value.value.entries.map(entry => {
|
|
374
|
+
const key = entry.key;
|
|
375
|
+
if (!key)
|
|
376
|
+
throw utils.mandatoryError('Value.Map.Entry.key');
|
|
377
|
+
const value = entry.value;
|
|
378
|
+
if (!value)
|
|
379
|
+
throw utils.mandatoryError('Value.Map.Entry.value');
|
|
380
|
+
return [this.deprotofy(key), this.deprotofy(value)];
|
|
381
|
+
})));
|
|
382
|
+
case 'compilerFunction':
|
|
383
|
+
return new function_1.SassFunction(value.value.value.id, this.functions.compileContext);
|
|
384
|
+
case 'hostFunction':
|
|
385
|
+
throw utils.compilerError('The compiler may not send Value.host_function');
|
|
386
|
+
case 'compilerMixin':
|
|
387
|
+
return new mixin_1.SassMixin(value.value.value.id, this.functions.compileContext);
|
|
388
|
+
case 'calculation':
|
|
389
|
+
return this.deprotofyCalculation(value.value.value);
|
|
390
|
+
case 'singleton':
|
|
391
|
+
switch (value.value.value) {
|
|
392
|
+
case proto.SingletonValue.TRUE:
|
|
393
|
+
return boolean_1.sassTrue;
|
|
394
|
+
case proto.SingletonValue.FALSE:
|
|
395
|
+
return boolean_1.sassFalse;
|
|
396
|
+
case proto.SingletonValue.NULL:
|
|
397
|
+
return null_1.sassNull;
|
|
398
|
+
}
|
|
399
|
+
// eslint-disable-next-line no-fallthrough
|
|
400
|
+
default:
|
|
401
|
+
throw utils.mandatoryError('Value.value');
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
/** Converts `number` to its JS representation. */
|
|
405
|
+
deprotofyNumber(number) {
|
|
406
|
+
return new number_1.SassNumber(number.value, {
|
|
407
|
+
numeratorUnits: number.numerators,
|
|
408
|
+
denominatorUnits: number.denominators,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
/** Converts `separator` to its JS representation. */
|
|
412
|
+
deprotofySeparator(separator) {
|
|
413
|
+
switch (separator) {
|
|
414
|
+
case proto.ListSeparator.COMMA:
|
|
415
|
+
return ',';
|
|
416
|
+
case proto.ListSeparator.SPACE:
|
|
417
|
+
return ' ';
|
|
418
|
+
case proto.ListSeparator.SLASH:
|
|
419
|
+
return '/';
|
|
420
|
+
case proto.ListSeparator.UNDECIDED:
|
|
421
|
+
return null;
|
|
422
|
+
default:
|
|
423
|
+
throw utils.compilerError(`Unknown separator ${separator}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
/** Converts `calculation` to its Sass representation. */
|
|
427
|
+
deprotofyCalculation(calculation) {
|
|
428
|
+
switch (calculation.name) {
|
|
429
|
+
case 'calc':
|
|
430
|
+
if (calculation.arguments.length !== 1) {
|
|
431
|
+
throw utils.compilerError('Value.Calculation.arguments must have exactly one argument for calc()');
|
|
432
|
+
}
|
|
433
|
+
return calculations_1.SassCalculation.calc(this.deprotofyCalculationValue(calculation.arguments[0]));
|
|
434
|
+
case 'clamp':
|
|
435
|
+
if (calculation.arguments.length === 0 ||
|
|
436
|
+
calculation.arguments.length > 3) {
|
|
437
|
+
throw utils.compilerError('Value.Calculation.arguments must have 1 to 3 arguments for clamp()');
|
|
438
|
+
}
|
|
439
|
+
return calculations_1.SassCalculation.clamp(this.deprotofyCalculationValue(calculation.arguments[0]), calculation.arguments.length > 1
|
|
440
|
+
? this.deprotofyCalculationValue(calculation.arguments[1])
|
|
441
|
+
: undefined, calculation.arguments.length > 2
|
|
442
|
+
? this.deprotofyCalculationValue(calculation.arguments[2])
|
|
443
|
+
: undefined);
|
|
444
|
+
case 'min':
|
|
445
|
+
if (calculation.arguments.length === 0) {
|
|
446
|
+
throw utils.compilerError('Value.Calculation.arguments must have at least 1 argument for min()');
|
|
447
|
+
}
|
|
448
|
+
return calculations_1.SassCalculation.min(calculation.arguments.map(this.deprotofyCalculationValue));
|
|
449
|
+
case 'max':
|
|
450
|
+
if (calculation.arguments.length === 0) {
|
|
451
|
+
throw utils.compilerError('Value.Calculation.arguments must have at least 1 argument for max()');
|
|
452
|
+
}
|
|
453
|
+
return calculations_1.SassCalculation.max(calculation.arguments.map(this.deprotofyCalculationValue));
|
|
454
|
+
default:
|
|
455
|
+
throw utils.compilerError(`Value.Calculation.name "${calculation.name}" is not a recognized calculation type`);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
/** Converts `value` to its Sass representation. */
|
|
459
|
+
deprotofyCalculationValue(value) {
|
|
460
|
+
switch (value.value.case) {
|
|
461
|
+
case 'number':
|
|
462
|
+
return this.deprotofyNumber(value.value.value);
|
|
463
|
+
case 'calculation':
|
|
464
|
+
return this.deprotofyCalculation(value.value.value);
|
|
465
|
+
case 'string':
|
|
466
|
+
return new string_1.SassString(value.value.value, { quotes: false });
|
|
467
|
+
case 'operation':
|
|
468
|
+
return new calculations_1.CalculationOperation(this.deprotofyCalculationOperator(value.value.value.operator), this.deprotofyCalculationValue(value.value.value.left), this.deprotofyCalculationValue(value.value.value.right));
|
|
469
|
+
case 'interpolation':
|
|
470
|
+
return new calculations_1.CalculationInterpolation(value.value.value);
|
|
471
|
+
default:
|
|
472
|
+
throw utils.mandatoryError('Calculation.CalculationValue.value');
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
/** Converts `operator` to its Sass representation. */
|
|
476
|
+
deprotofyCalculationOperator(operator) {
|
|
477
|
+
switch (operator) {
|
|
478
|
+
case proto.CalculationOperator.PLUS:
|
|
479
|
+
return '+';
|
|
480
|
+
case proto.CalculationOperator.MINUS:
|
|
481
|
+
return '-';
|
|
482
|
+
case proto.CalculationOperator.TIMES:
|
|
483
|
+
return '*';
|
|
484
|
+
case proto.CalculationOperator.DIVIDE:
|
|
485
|
+
return '/';
|
|
486
|
+
default:
|
|
487
|
+
throw utils.compilerError(`Unknown CalculationOperator ${operator}`);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
exports.Protofier = Protofier;
|
|
492
|
+
//# sourceMappingURL=protofier.js.map
|