File tree Expand file tree Collapse file tree 3 files changed +28
-9
lines changed
Expand file tree Collapse file tree 3 files changed +28
-9
lines changed Original file line number Diff line number Diff line change @@ -218,11 +218,13 @@ export class LiteralArray extends AST {
218218 }
219219}
220220
221- export type LiteralMapKey = {
221+ export interface LiteralMapKey {
222222 key : string ;
223223 quoted : boolean ;
224+ span : ParseSpan ;
225+ sourceSpan : AbsoluteSourceSpan ;
224226 isShorthandInitialized ?: boolean ;
225- } ;
227+ }
226228
227229export class LiteralMap extends AST {
228230 constructor (
Original file line number Diff line number Diff line change @@ -1197,7 +1197,14 @@ class _ParseAST {
11971197 const keyStart = this . inputIndex ;
11981198 const quoted = this . next . isString ( ) ;
11991199 const key = this . expectIdentifierOrKeywordOrString ( ) ;
1200- const literalMapKey : LiteralMapKey = { key, quoted} ;
1200+ const keySpan = this . span ( keyStart ) ;
1201+ const keySourceSpan = this . sourceSpan ( keyStart ) ;
1202+ const literalMapKey : LiteralMapKey = {
1203+ key,
1204+ quoted,
1205+ span : keySpan ,
1206+ sourceSpan : keySourceSpan ,
1207+ } ;
12011208 keys . push ( literalMapKey ) ;
12021209
12031210 // Properties with quoted keys can't use the shorthand syntax.
@@ -1209,14 +1216,12 @@ class _ParseAST {
12091216 } else {
12101217 literalMapKey . isShorthandInitialized = true ;
12111218
1212- const span = this . span ( keyStart ) ;
1213- const sourceSpan = this . sourceSpan ( keyStart ) ;
12141219 values . push (
12151220 new PropertyRead (
1216- span ,
1217- sourceSpan ,
1218- sourceSpan ,
1219- new ImplicitReceiver ( span , sourceSpan ) ,
1221+ keySpan ,
1222+ keySourceSpan ,
1223+ keySourceSpan ,
1224+ new ImplicitReceiver ( keySpan , keySourceSpan ) ,
12201225 key ,
12211226 ) ,
12221227 ) ;
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
1818 TemplateBinding ,
1919 VariableBinding ,
2020 BindingPipeType ,
21+ ParseSpan ,
2122} from '../../src/expression_parser/ast' ;
2223import { ParseError } from '../../src/parse_util' ;
2324import { Lexer } from '../../src/expression_parser/lexer' ;
@@ -733,6 +734,17 @@ describe('parser', () => {
733734 '/^http:\\/\\/foo\\.bar/gim' ,
734735 ] ) ;
735736 } ) ;
737+
738+ it ( 'should record span for literal map keys' , ( ) => {
739+ const ast = parseBinding ( '{one: 1, two: "the number two", three, "four": 4}' ) ;
740+ const literal = ast . ast as LiteralMap ;
741+ const getSource = ( span : ParseSpan ) => ast . source ?. substring ( span . start , span . end ) ;
742+
743+ expect ( getSource ( literal . keys [ 0 ] . span ) ) . toBe ( 'one' ) ;
744+ expect ( getSource ( literal . keys [ 1 ] . span ) ) . toBe ( 'two' ) ;
745+ expect ( getSource ( literal . keys [ 2 ] . span ) ) . toBe ( 'three' ) ;
746+ expect ( getSource ( literal . keys [ 3 ] . span ) ) . toBe ( '"four"' ) ;
747+ } ) ;
736748 } ) ;
737749
738750 describe ( 'general error handling' , ( ) => {
You can’t perform that action at this time.
0 commit comments