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,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2024 Google LLC. 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.activeDeprecationOptions = exports.deprecations = void 0;
|
|
7
|
+
exports.getDeprecationIds = getDeprecationIds;
|
|
8
|
+
exports.warnForHostSideDeprecation = warnForHostSideDeprecation;
|
|
9
|
+
const version_1 = require("./version");
|
|
10
|
+
var deprecations_1 = require("./vendor/deprecations");
|
|
11
|
+
Object.defineProperty(exports, "deprecations", { enumerable: true, get: function () { return deprecations_1.deprecations; } });
|
|
12
|
+
/**
|
|
13
|
+
* Converts a mixed array of deprecations, IDs, and versions to an array of IDs
|
|
14
|
+
* that's ready to include in a CompileRequest.
|
|
15
|
+
*/
|
|
16
|
+
function getDeprecationIds(arr) {
|
|
17
|
+
return arr.map(item => {
|
|
18
|
+
if (item instanceof version_1.Version) {
|
|
19
|
+
return item.toString();
|
|
20
|
+
}
|
|
21
|
+
else if (typeof item === 'string') {
|
|
22
|
+
return item;
|
|
23
|
+
}
|
|
24
|
+
return item.id;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Map between active compilations and the deprecation options they use.
|
|
29
|
+
*
|
|
30
|
+
* This is used to determine which options to use when handling host-side
|
|
31
|
+
* deprecation warnings that aren't explicitly tied to a particular compilation.
|
|
32
|
+
*/
|
|
33
|
+
exports.activeDeprecationOptions = new Map();
|
|
34
|
+
/**
|
|
35
|
+
* Handles a host-side deprecation warning, either emitting a warning, throwing
|
|
36
|
+
* an error, or doing nothing depending on the deprecation options used.
|
|
37
|
+
*
|
|
38
|
+
* If no specific deprecation options are passed here, then options will be
|
|
39
|
+
* determined based on the options of the active compilations.
|
|
40
|
+
*/
|
|
41
|
+
function warnForHostSideDeprecation(message, deprecation, options) {
|
|
42
|
+
if (deprecation.status === 'future' &&
|
|
43
|
+
!isEnabledFuture(deprecation, options)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const fullMessage = `Deprecation [${deprecation.id}]: ${message}`;
|
|
47
|
+
if (isFatal(deprecation, options)) {
|
|
48
|
+
throw Error(fullMessage);
|
|
49
|
+
}
|
|
50
|
+
if (!isSilent(deprecation, options)) {
|
|
51
|
+
console.warn(fullMessage);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Checks whether the given deprecation is included in the given list of silent
|
|
56
|
+
* deprecations or is silenced by at least one active compilation.
|
|
57
|
+
*/
|
|
58
|
+
function isSilent(deprecation, options) {
|
|
59
|
+
if (!options) {
|
|
60
|
+
for (const potentialOptions of exports.activeDeprecationOptions.values()) {
|
|
61
|
+
if (isSilent(deprecation, potentialOptions))
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return getDeprecationIds(options.silenceDeprecations ?? []).includes(deprecation.id);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks whether the given deprecation is included in the given list of future
|
|
70
|
+
* deprecations that should be enabled or is enabled in all active compilations.
|
|
71
|
+
*/
|
|
72
|
+
function isEnabledFuture(deprecation, options) {
|
|
73
|
+
if (!options) {
|
|
74
|
+
for (const potentialOptions of exports.activeDeprecationOptions.values()) {
|
|
75
|
+
if (!isEnabledFuture(deprecation, potentialOptions))
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return exports.activeDeprecationOptions.size > 0;
|
|
79
|
+
}
|
|
80
|
+
return getDeprecationIds(options.futureDeprecations ?? []).includes(deprecation.id);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Checks whether the given deprecation is included in the given list of
|
|
84
|
+
* fatal deprecations or is marked as fatal in all active compilations.
|
|
85
|
+
*/
|
|
86
|
+
function isFatal(deprecation, options) {
|
|
87
|
+
if (!options) {
|
|
88
|
+
for (const potentialOptions of exports.activeDeprecationOptions.values()) {
|
|
89
|
+
if (!isFatal(deprecation, potentialOptions))
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
return exports.activeDeprecationOptions.size > 0;
|
|
93
|
+
}
|
|
94
|
+
const versionNumber = deprecation.deprecatedIn === null
|
|
95
|
+
? null
|
|
96
|
+
: deprecation.deprecatedIn.major * 1000000 +
|
|
97
|
+
deprecation.deprecatedIn.minor * 1000 +
|
|
98
|
+
deprecation.deprecatedIn.patch;
|
|
99
|
+
for (const fatal of options.fatalDeprecations ?? []) {
|
|
100
|
+
if (fatal instanceof version_1.Version) {
|
|
101
|
+
if (versionNumber === null)
|
|
102
|
+
continue;
|
|
103
|
+
if (deprecation.obsoleteIn !== null)
|
|
104
|
+
continue;
|
|
105
|
+
if (versionNumber <=
|
|
106
|
+
fatal.major * 1000000 + fatal.minor * 1000 + fatal.patch) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (typeof fatal === 'string') {
|
|
111
|
+
if (fatal === deprecation.id)
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (fatal.id === deprecation.id)
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=deprecations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecations.js","sourceRoot":"","sources":["../../../lib/src/deprecations.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;;;AAGvC,uCAAkC;AAElC,sDAAmD;AAA3C,4GAAA,YAAY,OAAA;AAGpB;;;GAGG;AACH,2BACE,GAAkC;IAElC,OAAO,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QACpB,IAAI,IAAI,YAAY,iBAAO,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzB,CAAC;aAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,EAAE,CAAC;IACjB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACU,QAAA,wBAAwB,GACnC,IAAI,GAAG,EAAE,CAAC;AAUZ;;;;;;GAMG;AACH,oCACE,OAAe,EACf,WAAwB,EACxB,OAA4B;IAE5B,IACE,WAAW,CAAC,MAAM,KAAK,QAAQ;QAC/B,CAAC,eAAe,C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AO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 Google LLC. 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.deprotofySourceSpan = deprotofySourceSpan;
|
|
7
|
+
const url_1 = require("url");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
// Creates a SourceSpan from the given protocol `buffer`. Throws if the buffer
|
|
10
|
+
// has invalid fields.
|
|
11
|
+
function deprotofySourceSpan(buffer) {
|
|
12
|
+
const text = buffer.text;
|
|
13
|
+
if (buffer.start === undefined) {
|
|
14
|
+
throw (0, utils_1.compilerError)('Expected SourceSpan to have start');
|
|
15
|
+
}
|
|
16
|
+
let end;
|
|
17
|
+
if (buffer.end === undefined) {
|
|
18
|
+
if (text !== '') {
|
|
19
|
+
throw (0, utils_1.compilerError)('Expected SourceSpan text to be empty');
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
end = buffer.start;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
end = buffer.end;
|
|
27
|
+
if (end.offset < buffer.start.offset) {
|
|
28
|
+
throw (0, utils_1.compilerError)('Expected SourceSpan end to be after start');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const url = buffer.url === '' ? undefined : new url_1.URL(buffer.url);
|
|
32
|
+
const context = buffer.context === '' ? undefined : buffer.context;
|
|
33
|
+
return {
|
|
34
|
+
text,
|
|
35
|
+
start: buffer.start,
|
|
36
|
+
end,
|
|
37
|
+
url,
|
|
38
|
+
context,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=deprotofy-span.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprotofy-span.js","sourceRo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
+
"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
|
+
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.Dispatcher = void 0;
|
|
40
|
+
const rxjs_1 = require("rxjs");
|
|
41
|
+
const operators_1 = require("rxjs/operators");
|
|
42
|
+
const protobuf_1 = require("@bufbuild/protobuf");
|
|
43
|
+
const proto = __importStar(require("./vendor/embedded_sass_pb"));
|
|
44
|
+
const request_tracker_1 = require("./request-tracker");
|
|
45
|
+
const utils_1 = require("./utils");
|
|
46
|
+
/**
|
|
47
|
+
* Dispatches requests, responses, and events for a single compilation.
|
|
48
|
+
*
|
|
49
|
+
* Accepts callbacks for processing different types of outbound requests. When
|
|
50
|
+
* an outbound request arrives, this runs the appropriate callback to process
|
|
51
|
+
* it, and then sends the result inbound. A single callback must be provided for
|
|
52
|
+
* each outbound request type. The callback does not need to set the response
|
|
53
|
+
* ID; the dispatcher handles it.
|
|
54
|
+
*
|
|
55
|
+
* Consumers can send an inbound request. This returns a promise that will
|
|
56
|
+
* either resolve with the corresponding outbound response, or error if any
|
|
57
|
+
* Protocol Errors were encountered. The consumer does not need to set the
|
|
58
|
+
* request ID; the dispatcher handles it.
|
|
59
|
+
*
|
|
60
|
+
* Outbound events are exposed as Observables.
|
|
61
|
+
*
|
|
62
|
+
* Errors are not otherwise exposed to the top-level. Instead, they are surfaced
|
|
63
|
+
* as an Observable that consumers may choose to subscribe to. Subscribers must
|
|
64
|
+
* perform proper error handling.
|
|
65
|
+
*/
|
|
66
|
+
class Dispatcher {
|
|
67
|
+
compilationId;
|
|
68
|
+
outboundMessages$;
|
|
69
|
+
writeInboundMessage;
|
|
70
|
+
outboundRequestHandlers;
|
|
71
|
+
// Tracks the IDs of all outbound requests. An inbound response with matching
|
|
72
|
+
// ID and type will remove the ID.
|
|
73
|
+
pendingOutboundRequests = new request_tracker_1.RequestTracker();
|
|
74
|
+
// All outbound messages for this compilation. If we detect any errors while
|
|
75
|
+
// dispatching messages, this completes.
|
|
76
|
+
messages$ = new rxjs_1.Subject();
|
|
77
|
+
// Subject to unsubscribe from all outbound messages to prevent past
|
|
78
|
+
// dispatchers with compilation IDs reused by future dispatchers from
|
|
79
|
+
// receiving messages intended for future dispatchers.
|
|
80
|
+
unsubscribe$ = new rxjs_1.Subject();
|
|
81
|
+
// If the dispatcher encounters an error, this errors out. It is publicly
|
|
82
|
+
// exposed as a readonly Observable.
|
|
83
|
+
errorInternal$ = new rxjs_1.Subject();
|
|
84
|
+
/**
|
|
85
|
+
* If the dispatcher encounters an error, this errors out. Upon error, the
|
|
86
|
+
* dispatcher rejects all promises awaiting an outbound response, and silently
|
|
87
|
+
* closes all subscriptions to outbound events.
|
|
88
|
+
*/
|
|
89
|
+
error$ = this.errorInternal$.pipe();
|
|
90
|
+
/**
|
|
91
|
+
* Outbound log events. If an error occurs, the dispatcher closes this
|
|
92
|
+
* silently.
|
|
93
|
+
*/
|
|
94
|
+
logEvents$ = this.messages$.pipe((0, operators_1.filter)(message => message.message.case === 'logEvent'), (0, operators_1.map)(message => message.message.value));
|
|
95
|
+
constructor(compilationId, outboundMessages$, writeInboundMessage, outboundRequestHandlers) {
|
|
96
|
+
this.compilationId = compilationId;
|
|
97
|
+
this.outboundMessages$ = outboundMessages$;
|
|
98
|
+
this.writeInboundMessage = writeInboundMessage;
|
|
99
|
+
this.outboundRequestHandlers = outboundRequestHandlers;
|
|
100
|
+
if (compilationId < 1) {
|
|
101
|
+
throw Error(`Invalid compilation ID ${compilationId}.`);
|
|
102
|
+
}
|
|
103
|
+
this.outboundMessages$
|
|
104
|
+
.pipe((0, operators_1.filter)(([compilationId]) => compilationId === this.compilationId), (0, operators_1.map)(([, message]) => message), (0, operators_1.mergeMap)(message => {
|
|
105
|
+
const result = this.handleOutboundMessage(message);
|
|
106
|
+
return result instanceof Promise
|
|
107
|
+
? result.then(() => message)
|
|
108
|
+
: [message];
|
|
109
|
+
}), (0, operators_1.takeUntil)(this.unsubscribe$))
|
|
110
|
+
.subscribe({
|
|
111
|
+
next: message => this.messages$.next(message),
|
|
112
|
+
error: error => this.throwAndClose(error),
|
|
113
|
+
complete: () => {
|
|
114
|
+
this.messages$.complete();
|
|
115
|
+
this.errorInternal$.complete();
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Sends a CompileRequest inbound. Passes the corresponding outbound
|
|
121
|
+
* CompileResponse or an error to `callback` and unsubscribes from all
|
|
122
|
+
* outbound events.
|
|
123
|
+
*
|
|
124
|
+
* This uses an old-style callback argument so that it can work either
|
|
125
|
+
* synchronously or asynchronously. If the underlying stdout stream emits
|
|
126
|
+
* events synchronously, `callback` will be called synchronously.
|
|
127
|
+
*/
|
|
128
|
+
sendCompileRequest(request, callback) {
|
|
129
|
+
// Call the callback but unsubscribe first
|
|
130
|
+
const callback_ = (err, response) => {
|
|
131
|
+
this.unsubscribe();
|
|
132
|
+
return callback(err, response);
|
|
133
|
+
};
|
|
134
|
+
if (this.messages$.isStopped) {
|
|
135
|
+
callback_(new Error('Tried writing to closed dispatcher'), undefined);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.messages$
|
|
139
|
+
.pipe((0, operators_1.filter)(message => message.message.case === 'compileResponse'), (0, operators_1.map)(message => message.message.value))
|
|
140
|
+
.subscribe({ next: response => callback_(null, response) });
|
|
141
|
+
this.error$.subscribe({
|
|
142
|
+
error: error => callback_(error, undefined),
|
|
143
|
+
});
|
|
144
|
+
try {
|
|
145
|
+
this.writeInboundMessage([
|
|
146
|
+
this.compilationId,
|
|
147
|
+
(0, protobuf_1.create)(proto.InboundMessageSchema, {
|
|
148
|
+
message: { value: request, case: 'compileRequest' },
|
|
149
|
+
}),
|
|
150
|
+
]);
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
this.throwAndClose(error);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
// Stop the outbound message subscription.
|
|
157
|
+
unsubscribe() {
|
|
158
|
+
this.unsubscribe$.next(undefined);
|
|
159
|
+
this.unsubscribe$.complete();
|
|
160
|
+
}
|
|
161
|
+
// Rejects with `error` all promises awaiting an outbound response, and
|
|
162
|
+
// silently closes all subscriptions awaiting outbound events.
|
|
163
|
+
throwAndClose(error) {
|
|
164
|
+
this.messages$.complete();
|
|
165
|
+
this.errorInternal$.error(error);
|
|
166
|
+
this.unsubscribe();
|
|
167
|
+
}
|
|
168
|
+
// Keeps track of all outbound messages. If the outbound `message` contains a
|
|
169
|
+
// request or response, registers it with pendingOutboundRequests. If it
|
|
170
|
+
// contains a request, runs the appropriate callback to generate an inbound
|
|
171
|
+
// response, and then sends it inbound.
|
|
172
|
+
handleOutboundMessage(message) {
|
|
173
|
+
switch (message.message.case) {
|
|
174
|
+
case 'logEvent':
|
|
175
|
+
// Handled separately by `logEvents$`.
|
|
176
|
+
return undefined;
|
|
177
|
+
case 'compileResponse':
|
|
178
|
+
// Handled separately by `sendCompileRequest`.
|
|
179
|
+
return undefined;
|
|
180
|
+
case 'importRequest': {
|
|
181
|
+
const request = message.message.value;
|
|
182
|
+
const id = request.id;
|
|
183
|
+
const type = 'importResponse';
|
|
184
|
+
this.pendingOutboundRequests.add(id, type);
|
|
185
|
+
return (0, utils_1.thenOr)(this.outboundRequestHandlers.handleImportRequest(request), response => {
|
|
186
|
+
this.sendInboundMessage(id, { case: type, value: response });
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
case 'fileImportRequest': {
|
|
190
|
+
const request = message.message.value;
|
|
191
|
+
const id = request.id;
|
|
192
|
+
const type = 'fileImportResponse';
|
|
193
|
+
this.pendingOutboundRequests.add(id, type);
|
|
194
|
+
return (0, utils_1.thenOr)(this.outboundRequestHandlers.handleFileImportRequest(request), response => {
|
|
195
|
+
this.sendInboundMessage(id, { case: type, value: response });
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
case 'canonicalizeRequest': {
|
|
199
|
+
const request = message.message.value;
|
|
200
|
+
const id = request.id;
|
|
201
|
+
const type = 'canonicalizeResponse';
|
|
202
|
+
this.pendingOutboundRequests.add(id, type);
|
|
203
|
+
return (0, utils_1.thenOr)(this.outboundRequestHandlers.handleCanonicalizeRequest(request), response => {
|
|
204
|
+
this.sendInboundMessage(id, { case: type, value: response });
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
case 'functionCallRequest': {
|
|
208
|
+
const request = message.message.value;
|
|
209
|
+
const id = request.id;
|
|
210
|
+
const type = 'functionCallResponse';
|
|
211
|
+
this.pendingOutboundRequests.add(id, type);
|
|
212
|
+
return (0, utils_1.thenOr)(this.outboundRequestHandlers.handleFunctionCallRequest(request), response => {
|
|
213
|
+
this.sendInboundMessage(id, { case: type, value: response });
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
case 'error':
|
|
217
|
+
throw (0, utils_1.hostError)(message.message.value.message);
|
|
218
|
+
default:
|
|
219
|
+
throw (0, utils_1.compilerError)(`Unknown message type ${message.message.case}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// Sends a message inbound. Keeps track of all pending inbound requests.
|
|
223
|
+
sendInboundMessage(requestId, message) {
|
|
224
|
+
message.value.id = requestId;
|
|
225
|
+
if (message.case === 'importResponse' ||
|
|
226
|
+
message.case === 'fileImportResponse' ||
|
|
227
|
+
message.case === 'canonicalizeResponse' ||
|
|
228
|
+
message.case === 'functionCallResponse') {
|
|
229
|
+
this.pendingOutboundRequests.resolve(requestId, message.case);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
throw Error(`Unknown message type ${message.case}`);
|
|
233
|
+
}
|
|
234
|
+
this.writeInboundMessage([
|
|
235
|
+
this.compilationId,
|
|
236
|
+
(0, protobuf_1.create)(proto.InboundMessageSchema, { message }),
|
|
237
|
+
]);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.Dispatcher = Dispatcher;
|
|
241
|
+
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../../lib/src/dispatcher.ts"],"names":[],"mappings":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AwB,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;IAED,wEAAwE;IAChE,kBAAkB,CACxB,SAAiB,EACjB,OAGC;QAED,OAAO,CAAC,KAAK,CAAC,EAAE,GAAG,SAAS,CAAC;QAE7B,IACE,OAAO,CAAC,IAAI,KAAK,gBAAgB;YACjC,OAAO,CAAC,IAAI,KAAK,oBAAoB;YACrC,OAAO,CAAC,IAAI,KAAK,sBAAsB;YACvC,OAAO,CAAC,IAAI,KAAK,sBAAsB,EACvC,CAAC;YACD,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAChE,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,CAAC,wBAAwB,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,CAAC,mBAAmB,CAAC;YACvB,IAAI,CAAC,aAAa;YAClB,IAAA,iBAAM,EAAC,KAAK,CAAC,oBAAoB,EAAE,EAAC,OAAO,EAAC,CAAC;SAC9C,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/lib/src/elf.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2024 Google LLC. 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.getElfInterpreter = getElfInterpreter;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
/** Read a chunk of data from a file descriptor into a new Buffer. */
|
|
42
|
+
function readFileDescriptor(fd, position, length) {
|
|
43
|
+
const buffer = Buffer.alloc(length);
|
|
44
|
+
let offset = 0;
|
|
45
|
+
while (offset < length) {
|
|
46
|
+
const bytesRead = fs.readSync(fd, buffer, {
|
|
47
|
+
offset: offset,
|
|
48
|
+
position: position + offset,
|
|
49
|
+
});
|
|
50
|
+
if (bytesRead === 0) {
|
|
51
|
+
throw new Error(`failed to read fd ${fd}`);
|
|
52
|
+
}
|
|
53
|
+
offset += bytesRead;
|
|
54
|
+
}
|
|
55
|
+
return buffer;
|
|
56
|
+
}
|
|
57
|
+
/** Parse an ELF file and return its interpreter. */
|
|
58
|
+
function getElfInterpreter(path) {
|
|
59
|
+
const fd = fs.openSync(path, 'r');
|
|
60
|
+
try {
|
|
61
|
+
const elfIdentification = new DataView(readFileDescriptor(fd, 0, 64).buffer);
|
|
62
|
+
if (elfIdentification.getUint8(0) !== 0x7f ||
|
|
63
|
+
elfIdentification.getUint8(1) !== 0x45 ||
|
|
64
|
+
elfIdentification.getUint8(2) !== 0x4c ||
|
|
65
|
+
elfIdentification.getUint8(3) !== 0x46) {
|
|
66
|
+
throw new Error(`${path} is not an ELF file.`);
|
|
67
|
+
}
|
|
68
|
+
const elfIdentificationClass = elfIdentification.getUint8(4);
|
|
69
|
+
if (elfIdentificationClass !== 1 && elfIdentificationClass !== 2) {
|
|
70
|
+
throw new Error(`${path} has an invalid ELF class.`);
|
|
71
|
+
}
|
|
72
|
+
const elfClass32 = elfIdentificationClass === 1;
|
|
73
|
+
const elfIdentificationData = elfIdentification.getUint8(5);
|
|
74
|
+
if (elfIdentificationData !== 1 && elfIdentificationData !== 2) {
|
|
75
|
+
throw new Error(`${path} has an invalid endianness.`);
|
|
76
|
+
}
|
|
77
|
+
const littleEndian = elfIdentificationData === 1;
|
|
78
|
+
// Converting BigUint64 to Number because node Buffer length has to be
|
|
79
|
+
// number type, and we don't expect any elf we check with this method to
|
|
80
|
+
// be larger than 9007199254740991 bytes.
|
|
81
|
+
const programHeadersOffset = elfClass32
|
|
82
|
+
? elfIdentification.getUint32(28, littleEndian)
|
|
83
|
+
: Number(elfIdentification.getBigUint64(32, littleEndian));
|
|
84
|
+
const programHeadersEntrySize = elfClass32
|
|
85
|
+
? elfIdentification.getUint16(42, littleEndian)
|
|
86
|
+
: elfIdentification.getUint16(54, littleEndian);
|
|
87
|
+
const programHeadersEntryCount = elfClass32
|
|
88
|
+
? elfIdentification.getUint16(44, littleEndian)
|
|
89
|
+
: elfIdentification.getUint16(56, littleEndian);
|
|
90
|
+
const programHeaders = new DataView(readFileDescriptor(fd, programHeadersOffset, programHeadersEntrySize * programHeadersEntryCount).buffer);
|
|
91
|
+
for (let i = 0; i < programHeadersEntryCount; i++) {
|
|
92
|
+
const byteOffset = i * programHeadersEntrySize;
|
|
93
|
+
const segmentType = programHeaders.getUint32(byteOffset, littleEndian);
|
|
94
|
+
if (segmentType !== 3)
|
|
95
|
+
continue; // 3 is PT_INTERP, the interpreter
|
|
96
|
+
const segmentOffset = elfClass32
|
|
97
|
+
? programHeaders.getUint32(byteOffset + 4, littleEndian)
|
|
98
|
+
: Number(programHeaders.getBigUint64(byteOffset + 8, littleEndian));
|
|
99
|
+
const segmentFileSize = elfClass32
|
|
100
|
+
? programHeaders.getUint32(byteOffset + 16, littleEndian)
|
|
101
|
+
: Number(programHeaders.getBigUint64(byteOffset + 32, littleEndian));
|
|
102
|
+
const buffer = readFileDescriptor(fd, segmentOffset, segmentFileSize);
|
|
103
|
+
if (buffer[segmentFileSize - 1] !== 0) {
|
|
104
|
+
throw new Error(`${path} is corrupted.`);
|
|
105
|
+
}
|
|
106
|
+
return buffer.toString('utf8', 0, segmentFileSize - 1);
|
|
107
|
+
}
|
|
108
|
+
throw new Error(`${path} does not contain an interpreter entry.`);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
fs.closeSync(fd);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=elf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elf.js","sourceRoot":"","sources":["../../../lib/src/elf.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEvC,MAAY,EAAE,+BAAW;AAEzB,qEAAqE;AACrE,SAAS,kBAAkB,CACzB,EAAU,EACV,QAAgB,EAChB,MAAc;IAEd,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,I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,CAAC,CAAC;YACvE,IAAI,WAAW,KAAK,CAAC;gBAAE,SAAS,CAAC,kCAAkC;YAEnE,MAAM,aAAa,GAAG,UAAU;gBAC9B,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,EAAE,YAAY,CAAC;gBACxD,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,UAAU,GAAG,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC;YACtE,MAAM,eAAe,GAAG,UAAU;gBAChC,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,UAAU,GAAG,EAAE,EAAE,YAAY,CAAC;gBACzD,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,UAAU,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC,CAAC;YAEvE,MAAM,MAAM,GAAG,kBAAkB,CAAC,EAAE,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;YACtE,IAAI,MAAM,CAAC,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;gBACtC,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,gBAAgB,CAAC,CAAC;YAC3C,CAAC;YAED,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,eAAe,GAAG,CAAC,CAAC,CAAC;QACzD,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,yCAAyC,CAAC,CAAC;IACpE,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
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.Exception = void 0;
|
|
7
|
+
const deprotofy_span_1 = require("./deprotofy-span");
|
|
8
|
+
class Exception extends Error {
|
|
9
|
+
sassMessage;
|
|
10
|
+
sassStack;
|
|
11
|
+
span;
|
|
12
|
+
constructor(failure) {
|
|
13
|
+
super(failure.formatted);
|
|
14
|
+
this.sassMessage = failure.message;
|
|
15
|
+
this.sassStack = failure.stackTrace;
|
|
16
|
+
this.span = (0, deprotofy_span_1.deprotofySourceSpan)(failure.span);
|
|
17
|
+
}
|
|
18
|
+
toString() {
|
|
19
|
+
return this.message;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.Exception = Exception;
|
|
23
|
+
//# sourceMappingURL=exception.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception.js","sourceRoot":"","sources":["../../../lib/src/exception.ts"],"names":[],"mappings":";AAAA,uEAAuE;AACvE,gEAAgE;AAChE,uCAAuC;;;AAIvC,qDAAqD;AAErD,eAAuB,SAAQ,KAAK;IACzB,WAAW,CAAS;IACpB,SAAS,CAAS;IAClB,IAAI,CAAa;IAE1B,YAAY,OAA6D;QACvE,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAEzB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,IAAA,oCAAmB,EAAC,OAAO,CAAC,IAAK,CAAC,CAAC;IACjD,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|