-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
implementation.js
34 lines (26 loc) · 945 Bytes
/
implementation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
var ToObject = require('es-abstract/2022/ToObject');
var ToString = require('es-abstract/2022/ToString');
var LengthOfArrayLike = require('es-abstract/2022/LengthOfArrayLike');
var callBound = require('call-bind/callBound');
var $push = callBound('Array.prototype.push');
var $join = callBound('Array.prototype.join');
module.exports = function raw(template /* , ...substitutions */) {
var numberOfSubstitutions = arguments.length - 1;
var cooked = ToObject(template);
var rawObj = ToObject(cooked.raw);
var literalSegments = LengthOfArrayLike(rawObj);
if (literalSegments <= 0) {
return '';
}
var stringElements = [];
for (var nextIndex = 0; ; nextIndex++) {
$push(stringElements, ToString(rawObj[nextIndex]));
if (nextIndex + 1 === literalSegments) {
return $join(stringElements, '');
}
if (nextIndex < numberOfSubstitutions) {
$push(stringElements, ToString(arguments[nextIndex + 1]));
}
}
};