Skip to content

Commit 3d3b69f

Browse files
petebacondarwinatscott
authored andcommitted
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
1 parent c8a46bf commit 3d3b69f

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎packages/compiler/src/chars.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,7 @@ export function isNewLine(code: number): boolean {
9898
export function isOctalDigit(code: number): boolean {
9999
return $0 <= code && code <= $7;
100100
}
101+
102+
export function isQuote(code: number): boolean {
103+
return code === $SQ || code === $DQ || code === $BT;
104+
}

‎packages/compiler/src/expression_parser/lexer.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,6 @@ function isExponentSign(code: number): boolean {
436436
return code == chars.$MINUS || code == chars.$PLUS;
437437
}
438438

439-
export function isQuote(code: number): boolean {
440-
return code === chars.$SQ || code === chars.$DQ || code === chars.$BT;
441-
}
442-
443439
function unescape(code: number): number {
444440
switch (code) {
445441
case chars.$n:

‎packages/compiler/src/expression_parser/parser.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as chars from '../chars';
1010
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../ml_parser/interpolation_config';
1111

1212
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';
13-
import {EOF, isIdentifier, isQuote, Lexer, Token, TokenType} from './lexer';
13+
import {EOF, isIdentifier, Lexer, Token, TokenType} from './lexer';
1414

1515
export interface InterpolationPiece {
1616
text: string;
@@ -291,7 +291,7 @@ export class Parser {
291291

292292
if (outerQuote === char) {
293293
outerQuote = null;
294-
} else if (outerQuote == null && isQuote(char)) {
294+
} else if (outerQuote == null && chars.isQuote(char)) {
295295
outerQuote = char;
296296
}
297297
}
@@ -355,7 +355,7 @@ export class Parser {
355355
const char = input[i];
356356
// Skip the characters inside quotes. Note that we only care about the outer-most
357357
// quotes matching up and we need to account for escape characters.
358-
if (isQuote(input.charCodeAt(i)) && (currentQuote === null || currentQuote === char) &&
358+
if (chars.isQuote(input.charCodeAt(i)) && (currentQuote === null || currentQuote === char) &&
359359
escapeCount % 2 === 0) {
360360
currentQuote = currentQuote === null ? char : null;
361361
} else if (currentQuote === null) {

0 commit comments

Comments
 (0)