feat(compiler): adds support for quoted object keys in the parser
This commit is contained in:

committed by
Jason Aden

parent
7ae8ad6aab
commit
798947efa4
@ -136,8 +136,12 @@ export class LiteralArray extends AST {
|
||||
}
|
||||
}
|
||||
|
||||
export type LiteralMapKey = {
|
||||
key: string; quoted: boolean;
|
||||
};
|
||||
|
||||
export class LiteralMap extends AST {
|
||||
constructor(span: ParseSpan, public keys: any[], public values: any[]) { super(span); }
|
||||
constructor(span: ParseSpan, public keys: LiteralMapKey[], public values: any[]) { super(span); }
|
||||
visit(visitor: AstVisitor, context: any = null): any {
|
||||
return visitor.visitLiteralMap(this, context);
|
||||
}
|
||||
|
@ -11,10 +11,9 @@ import {CompilerInjectable} from '../injectable';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../ml_parser/interpolation_config';
|
||||
import {escapeRegExp} from '../util';
|
||||
|
||||
import {AST, ASTWithSource, AstVisitor, Binary, BindingPipe, Chain, Conditional, EmptyExpr, FunctionCall, ImplicitReceiver, Interpolation, KeyedRead, KeyedWrite, LiteralArray, LiteralMap, LiteralPrimitive, MethodCall, NonNullAssert, ParseSpan, ParserError, PrefixNot, PropertyRead, PropertyWrite, Quote, SafeMethodCall, SafePropertyRead, TemplateBinding} from './ast';
|
||||
import {AST, ASTWithSource, AstVisitor, Binary, BindingPipe, Chain, Conditional, EmptyExpr, FunctionCall, ImplicitReceiver, Interpolation, KeyedRead, KeyedWrite, LiteralArray, LiteralMap, LiteralMapKey, LiteralPrimitive, MethodCall, NonNullAssert, ParseSpan, ParserError, PrefixNot, PropertyRead, PropertyWrite, Quote, SafeMethodCall, SafePropertyRead, TemplateBinding} from './ast';
|
||||
import {EOF, Lexer, Token, TokenType, isIdentifier, isQuote} from './lexer';
|
||||
|
||||
|
||||
export class SplitInterpolation {
|
||||
constructor(public strings: string[], public expressions: string[], public offsets: number[]) {}
|
||||
}
|
||||
@ -605,15 +604,16 @@ export class _ParseAST {
|
||||
}
|
||||
|
||||
parseLiteralMap(): LiteralMap {
|
||||
const keys: string[] = [];
|
||||
const keys: LiteralMapKey[] = [];
|
||||
const values: AST[] = [];
|
||||
const start = this.inputIndex;
|
||||
this.expectCharacter(chars.$LBRACE);
|
||||
if (!this.optionalCharacter(chars.$RBRACE)) {
|
||||
this.rbracesExpected++;
|
||||
do {
|
||||
const quoted = this.next.isString();
|
||||
const key = this.expectIdentifierOrKeywordOrString();
|
||||
keys.push(key);
|
||||
keys.push({key, quoted});
|
||||
this.expectCharacter(chars.$COLON);
|
||||
values.push(this.parsePipe());
|
||||
} while (this.optionalCharacter(chars.$COMMA));
|
||||
|
Reference in New Issue
Block a user