OLD | NEW |
(Empty) | |
| 1 "use strict"; |
| 2 |
| 3 |
| 4 module.exports = { |
| 5 /** |
| 6 * Simplifies the token stream to ease the matching with the expected to
ken stream. |
| 7 * |
| 8 * * Strings are kept as-is |
| 9 * * In arrays each value is transformed individually |
| 10 * * Values that are empty (empty arrays or strings only containing whit
espace) |
| 11 * |
| 12 * |
| 13 * @param {Array} tokenStream |
| 14 * @returns {Array.<string[]|Array>} |
| 15 */ |
| 16 simplify: function (tokenStream) { |
| 17 if (Array.isArray(tokenStream)) { |
| 18 return tokenStream |
| 19 .map(this.simplify.bind(this)) |
| 20 .filter(function (value) { |
| 21 return !(Array.isArray(value) && !value.
length) && !(typeof value === "string" && !value.trim().length); |
| 22 } |
| 23 ); |
| 24 } |
| 25 else if (typeof tokenStream === "object") { |
| 26 return [tokenStream.type, this.simplify(tokenStream.cont
ent)]; |
| 27 } |
| 28 else { |
| 29 return tokenStream; |
| 30 } |
| 31 } |
| 32 }; |
OLD | NEW |