Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(compiler): share isQuote() via chars.ts
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.
  • Loading branch information
petebacondarwin committed Jul 31, 2021
commit 49462aa249edc5debcca634d9f13a3474eeccb76
4 changes: 4 additions & 0 deletions packages/compiler/src/chars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 0 additions & 4 deletions packages/compiler/src/expression_parser/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler/src/expression_parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down