@@ -1952,6 +1952,65 @@ describe('completions', () => {
19521952 expectReplacementText ( completions , templateFile . contents , 'mat-' ) ;
19531953 } ) ;
19541954 } ) ;
1955+
1956+ describe ( 'let declarations' , ( ) => {
1957+ it ( 'should complete a let declaration' , ( ) => {
1958+ const { templateFile} = setup (
1959+ `
1960+ @let message = 'hello';
1961+ {{mess}}
1962+ ` ,
1963+ '' ,
1964+ ) ;
1965+ templateFile . moveCursorToText ( '{{mess¦}}' ) ;
1966+ const completions = templateFile . getCompletionsAtPosition ( ) ;
1967+ expectContain ( completions , DisplayInfoKind . LET , [ 'message' ] ) ;
1968+ } ) ;
1969+
1970+ it ( 'should complete an empty let declaration with a terminating character' , ( ) => {
1971+ const { templateFile} = setup ( '@let foo = ;' , `title!: string; hero!52: number;` ) ;
1972+ templateFile . moveCursorToText ( '@let foo = ¦;' ) ;
1973+ const completions = templateFile . getCompletionsAtPosition ( ) ;
1974+ expectContain ( completions , ts . ScriptElementKind . memberVariableElement , [ 'title' , 'hero' ] ) ;
1975+ } ) ;
1976+
1977+ it ( 'should complete a single let declaration without a terminating character' , ( ) => {
1978+ const { templateFile} = setup ( '@let foo = ' , `title!: string; hero!52: number;` ) ;
1979+ templateFile . moveCursorToText ( '@let foo = ¦' ) ;
1980+ const completions = templateFile . getCompletionsAtPosition ( ) ;
1981+ expectContain ( completions , ts . ScriptElementKind . memberVariableElement , [ 'title' , 'hero' ] ) ;
1982+ } ) ;
1983+
1984+ it ( 'should complete a let declaration property in the global scope' , ( ) => {
1985+ const { templateFile} = setup (
1986+ `
1987+ @let hobbit = {name: 'Frodo', age: 53};
1988+ {{hobbit.}}
1989+ ` ,
1990+ '' ,
1991+ ) ;
1992+ templateFile . moveCursorToText ( '{{hobbit.¦}}' ) ;
1993+ const completions = templateFile . getCompletionsAtPosition ( ) ;
1994+ expectContain ( completions , ts . ScriptElementKind . memberVariableElement , [ 'age' , 'name' ] ) ;
1995+ } ) ;
1996+
1997+ it ( 'should complete a shadowed let declaration property' , ( ) => {
1998+ const { templateFile} = setup (
1999+ `
2000+ @let hobbit = {name: 'Frodo', age: 53};
2001+
2002+ @if (true) {
2003+ @let hobbit = {hasRing: true, size: 'small'};
2004+ {{hobbit.}}
2005+ }
2006+ ` ,
2007+ '' ,
2008+ ) ;
2009+ templateFile . moveCursorToText ( '{{hobbit.¦}}' ) ;
2010+ const completions = templateFile . getCompletionsAtPosition ( ) ;
2011+ expectContain ( completions , ts . ScriptElementKind . memberVariableElement , [ 'hasRing' , 'size' ] ) ;
2012+ } ) ;
2013+ } ) ;
19552014} ) ;
19562015
19572016function expectContainInsertText (
@@ -2061,8 +2120,10 @@ function setup(
20612120 const otherDirectiveClassDecls = Object . values ( otherDeclarations ) . join ( '\n\n' ) ;
20622121
20632122 const env = LanguageServiceTestEnv . setup ( ) ;
2064- const project = env . addProject ( 'test' , {
2065- 'test.ts' : `
2123+ const project = env . addProject (
2124+ 'test' ,
2125+ {
2126+ 'test.ts' : `
20662127 import {Component,
20672128 input,
20682129 output,
@@ -2093,8 +2154,14 @@ function setup(
20932154 })
20942155 export class AppModule {}
20952156 ` ,
2096- 'test.html' : template ,
2097- } ) ;
2157+ 'test.html' : template ,
2158+ } ,
2159+ // Note: this object is cast to `any`, because for some reason the typing
2160+ // changes to the `TestableOption` type aren't being picked up in tests.
2161+ {
2162+ _enableLetSyntax : true ,
2163+ } as any ,
2164+ ) ;
20982165 return { templateFile : project . openFile ( 'test.html' ) } ;
20992166}
21002167
0 commit comments