-
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathinterpolation.js
More file actions
30 lines (24 loc) · 771 Bytes
/
Copy pathinterpolation.js
File metadata and controls
30 lines (24 loc) · 771 Bytes
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
/* eslint no-param-reassign: off */
module.exports = {
interpolation(token) {
const tokens = [token, this.tokenizer.nextToken()];
const validTypes = ['word', '}'];
// look for @{ but not @[word]{
if (tokens[0][1].length > 1 || tokens[1][0] !== '{') {
this.tokenizer.back(tokens[1]);
return false;
}
token = this.tokenizer.nextToken();
while (token && validTypes.includes(token[0])) {
tokens.push(token);
token = this.tokenizer.nextToken();
}
const words = tokens.map((tokn) => tokn[1]);
const [first] = tokens;
const last = tokens.pop();
const newToken = ['word', words.join(''), first[2], last[2]];
this.tokenizer.back(token);
this.tokenizer.back(newToken);
return true;
}
};