refactor(compiler): share `isQuote()` via `chars.ts` (#42062)
This function is general purpose and by moving it into the `chars.ts` file along with similar helpers, it can be reused in the lexer, for instance. PR Close #42062
This commit is contained in:
parent
c8a46bfdcd
commit
3d3b69ff81
|
@ -98,3 +98,7 @@ export function isNewLine(code: number): boolean {
|
|||
export function isOctalDigit(code: number): boolean {
|
||||
return $0 <= code && code <= $7;
|
||||
}
|
||||
|
||||
export function isQuote(code: number): boolean {
|
||||
return code === $SQ || code === $DQ || code === $BT;
|
||||
}
|
||||
|
|
|
@ -436,10 +436,6 @@ function isExponentSign(code: number): boolean {
|
|||
return code == chars.$MINUS || code == chars.$PLUS;
|
||||
}
|
||||
|
||||
export function isQuote(code: number): boolean {
|
||||
return code === chars.$SQ || code === chars.$DQ || code === chars.$BT;
|
||||
}
|
||||
|
||||
function unescape(code: number): number {
|
||||
switch (code) {
|
||||
case chars.$n:
|
||||
|
|
|
@ -10,7 +10,7 @@ import * as chars from '../chars';
|
|||
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../ml_parser/interpolation_config';
|
||||
|
||||
import {AbsoluteSourceSpan, AST, AstVisitor, ASTWithSource, Binary, BindingPipe, Chain, Conditional, EmptyExpr, ExpressionBinding, FunctionCall, ImplicitReceiver, Interpolation, KeyedRead, KeyedWrite, LiteralArray, LiteralMap, LiteralMapKey, LiteralPrimitive, MethodCall, NonNullAssert, ParserError, ParseSpan, PrefixNot, PropertyRead, PropertyWrite, Quote, RecursiveAstVisitor, SafeKeyedRead, SafeMethodCall, SafePropertyRead, TemplateBinding, TemplateBindingIdentifier, ThisReceiver, Unary, VariableBinding} from './ast';
|
||||
import {EOF, isIdentifier, isQuote, Lexer, Token, TokenType} from './lexer';
|
||||
import {EOF, isIdentifier, Lexer, Token, TokenType} from './lexer';
|
||||
|
||||
export interface InterpolationPiece {
|
||||
text: string;
|
||||
|
@ -291,7 +291,7 @@ export class Parser {
|
|||
|
||||
if (outerQuote === char) {
|
||||
outerQuote = null;
|
||||
} else if (outerQuote == null && isQuote(char)) {
|
||||
} else if (outerQuote == null && chars.isQuote(char)) {
|
||||
outerQuote = char;
|
||||
}
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ export class Parser {
|
|||
const char = input[i];
|
||||
// Skip the characters inside quotes. Note that we only care about the outer-most
|
||||
// quotes matching up and we need to account for escape characters.
|
||||
if (isQuote(input.charCodeAt(i)) && (currentQuote === null || currentQuote === char) &&
|
||||
if (chars.isQuote(input.charCodeAt(i)) && (currentQuote === null || currentQuote === char) &&
|
||||
escapeCount % 2 === 0) {
|
||||
currentQuote = currentQuote === null ? char : null;
|
||||
} else if (currentQuote === null) {
|
||||
|
|
Loading…
Reference in New Issue