(node: ExpressionNode)
| 2168 | } |
| 2169 | |
| 2170 | private _parseTypeAnnotation(node: ExpressionNode): TypeAnnotationExpression { |
| 2171 | let rawExpression = node; |
| 2172 | let parsedExpression = node; |
| 2173 | |
| 2174 | if (rawExpression instanceof StringNode) { |
| 2175 | if (rawExpression.tokens.length > 1) { |
| 2176 | this._addError('Type hints cannot span multiple string literals', node); |
| 2177 | } else if (rawExpression.tokens[0].quoteTypeFlags & QuoteTypeFlags.Triplicate) { |
| 2178 | this._addError('Type hints cannot use triple quotes', node); |
| 2179 | } else if (rawExpression.tokens[0].quoteTypeFlags & |
| 2180 | (QuoteTypeFlags.Raw | QuoteTypeFlags.Unicode | QuoteTypeFlags.Byte)) { |
| 2181 | this._addError('Type hints cannot use raw, unicode or byte string literals', node); |
| 2182 | } else if (rawExpression.tokens[0].value.length !== rawExpression.tokens[0].length - 2) { |
| 2183 | this._addError('Type hints cannot contain escape characters', node); |
| 2184 | } else { |
| 2185 | let stringValue = rawExpression.tokens[0].value; |
| 2186 | let tokenOffset = rawExpression.tokens[0].start; |
| 2187 | let parser = new Parser(); |
| 2188 | let parseResults = parser.parseTextExpression(this._fileContents!, |
| 2189 | tokenOffset + 1, stringValue.length, this._parseOptions); |
| 2190 | |
| 2191 | parseResults.diagnostics.forEach(diag => { |
| 2192 | this._addError(diag.message, node); |
| 2193 | }); |
| 2194 | |
| 2195 | if (parseResults.parseTree) { |
| 2196 | parsedExpression = parseResults.parseTree; |
| 2197 | } |
| 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | return { |
| 2202 | rawExpression, |
| 2203 | expression: parsedExpression |
| 2204 | }; |
| 2205 | } |
| 2206 | |
| 2207 | // Peeks at the next token and returns true if it can never |
| 2208 | // represent the start of an expression. |
no test coverage detected