* Tokenizes and returns method arguments, e.g. target.method(arguments). * @param {!ParserTokenizer} toks * @param {!Function} assertToken * @param {!Function} assertAction * @return {?ActionInfoArgsDef} * @private
(toks, assertToken, assertAction)
| 1045 | * @private |
| 1046 | */ |
| 1047 | function tokenizeMethodArguments(toks, assertToken, assertAction) { |
| 1048 | let peek = toks.peek(); |
| 1049 | let tok; |
| 1050 | let args = null; |
| 1051 | // Object literal. Format: {...} |
| 1052 | if (peek.type == TokenType_Enum.OBJECT) { |
| 1053 | // Don't parse object literals. Tokenize as a single expression |
| 1054 | // fragment and delegate to specific action handler. |
| 1055 | args = map(); |
| 1056 | const {value} = toks.next(); |
| 1057 | args[RAW_OBJECT_ARGS_KEY] = value; |
| 1058 | assertToken(toks.next(), [TokenType_Enum.SEPARATOR], ')'); |
| 1059 | } else { |
| 1060 | // Key-value pairs. Format: key = value, .... |
| 1061 | do { |
| 1062 | tok = toks.next(); |
| 1063 | const {type, value} = tok; |
| 1064 | if (type == TokenType_Enum.SEPARATOR && (value == ',' || value == ')')) { |
| 1065 | // Expected: ignore. |
| 1066 | } else if (type == TokenType_Enum.LITERAL || type == TokenType_Enum.ID) { |
| 1067 | // Key: "key = " |
| 1068 | assertToken(toks.next(), [TokenType_Enum.SEPARATOR], '='); |
| 1069 | // Value is either a literal or an expression: "foo.bar.baz" |
| 1070 | tok = assertToken(toks.next(/* convertValue */ true), [ |
| 1071 | TokenType_Enum.LITERAL, |
| 1072 | TokenType_Enum.ID, |
| 1073 | ]); |
| 1074 | const argValueTokens = [tok]; |
| 1075 | // Expressions have one or more dereferences: ".identifier" |
| 1076 | if (tok.type == TokenType_Enum.ID) { |
| 1077 | for ( |
| 1078 | peek = toks.peek(); |
| 1079 | peek.type == TokenType_Enum.SEPARATOR && peek.value == '.'; |
| 1080 | peek = toks.peek() |
| 1081 | ) { |
| 1082 | toks.next(); // Skip '.'. |
| 1083 | tok = assertToken(toks.next(false), [TokenType_Enum.ID]); |
| 1084 | argValueTokens.push(tok); |
| 1085 | } |
| 1086 | } |
| 1087 | const argValue = argValueForTokens(argValueTokens); |
| 1088 | if (!args) { |
| 1089 | args = map(); |
| 1090 | } |
| 1091 | args[value] = argValue; |
| 1092 | peek = toks.peek(); |
| 1093 | assertAction( |
| 1094 | peek.type == TokenType_Enum.SEPARATOR && |
| 1095 | (peek.value == ',' || peek.value == ')'), |
| 1096 | 'Expected either [,] or [)]' |
| 1097 | ); |
| 1098 | } else { |
| 1099 | // Unexpected token. |
| 1100 | assertAction(false, `; unexpected token [${tok.value || ''}]`); |
| 1101 | } |
| 1102 | } while (!(tok.type == TokenType_Enum.SEPARATOR && tok.value == ')')); |
| 1103 | } |
| 1104 | return args; |
no test coverage detected