@@ -40,7 +40,7 @@ test("isBoolean", (t) => {
4040 t . false ( ASTUtils . isBoolean ( falseLiteral , true ) , "is a literal and value does not matches" ) ;
4141} ) ;
4242
43- test ( "isIdentifier" , ( t ) => {
43+ test ( "isIdentifier (identifier) " , ( t ) => {
4444 const literal = parseJS ( "'testValue47'" ) . body [ 0 ] . expression ;
4545
4646 t . false ( ASTUtils . isIdentifier ( literal ) , "A literal is not an identifier" ) ;
@@ -58,6 +58,36 @@ test("isIdentifier", (t) => {
5858 t . false ( ASTUtils . isIdentifier ( identifier , [ ] , "value does not match" ) ) ;
5959} ) ;
6060
61+ test ( "isIdentifier (object pattern)" , ( t ) => {
62+ const identifier = parseJS ( "const { a, b } = { a: 'x', b: 'y' }" ) . body [ 0 ] . declarations [ 0 ] . id ;
63+
64+ t . true ( ASTUtils . isIdentifier ( identifier , [ "*" ] , "asterisk matches any string" ) ) ;
65+ t . true ( ASTUtils . isIdentifier ( identifier , [ "a" ] , "value matches" ) ) ;
66+ t . true ( ASTUtils . isIdentifier ( identifier , "a" ) , "value matches" ) ;
67+ t . true ( ASTUtils . isIdentifier ( identifier , [ "b" ] , "value matches" ) ) ;
68+ t . true ( ASTUtils . isIdentifier ( identifier , "b" ) , "value matches" ) ;
69+
70+ t . false ( ASTUtils . isIdentifier ( identifier , "" ) , "value does not match" ) ;
71+ t . false ( ASTUtils . isIdentifier ( identifier , "*" ) , "value does not match" ) ;
72+ t . false ( ASTUtils . isIdentifier ( identifier , "c" ) , "value does not match" ) ;
73+ t . false ( ASTUtils . isIdentifier ( identifier , [ ] , "value does not match" ) ) ;
74+ } ) ;
75+
76+ test ( "isIdentifier (arry pattern)" , ( t ) => {
77+ const identifier = parseJS ( "const [ a, b ] = [ 'x', 'y' ]" ) . body [ 0 ] . declarations [ 0 ] . id ;
78+
79+ t . true ( ASTUtils . isIdentifier ( identifier , [ "*" ] , "asterisk matches any string" ) ) ;
80+ t . true ( ASTUtils . isIdentifier ( identifier , [ "a" ] , "value matches" ) ) ;
81+ t . true ( ASTUtils . isIdentifier ( identifier , "a" ) , "value matches" ) ;
82+ t . true ( ASTUtils . isIdentifier ( identifier , [ "b" ] , "value matches" ) ) ;
83+ t . true ( ASTUtils . isIdentifier ( identifier , "b" ) , "value matches" ) ;
84+
85+ t . false ( ASTUtils . isIdentifier ( identifier , "" ) , "value does not match" ) ;
86+ t . false ( ASTUtils . isIdentifier ( identifier , "*" ) , "value does not match" ) ;
87+ t . false ( ASTUtils . isIdentifier ( identifier , "c" ) , "value does not match" ) ;
88+ t . false ( ASTUtils . isIdentifier ( identifier , [ ] , "value does not match" ) ) ;
89+ } ) ;
90+
6191
6292test ( "isNamedObject" , ( t ) => {
6393 const identifier = parseJS ( "testValue47" ) . body [ 0 ] . expression ;
@@ -136,6 +166,13 @@ test("getPropertyKey (spread element)", (t) => {
136166 "spread elements in object expressions should be ignored" ) ;
137167} ) ;
138168
169+ test ( "getPropertyKey (object pattern)" , ( t ) => {
170+ const propertiesWithObjectPattern =
171+ parseJS ( "const { a, b } = { a: 'x', b: 'y' }" ) . body [ 0 ] . declarations [ 0 ] . init . properties ;
172+ t . is ( ASTUtils . getPropertyKey ( propertiesWithObjectPattern [ 0 ] ) , "a" ,
173+ "object pattern in variable declaration" ) ;
174+ } ) ;
175+
139176test ( "findOwnProperty" , ( t ) => {
140177 const literal = cleanse ( parseJS ( "'x'" ) . body [ 0 ] . expression ) ;
141178 const identifier = cleanse ( parseJS ( "a" ) . body [ 0 ] . expression ) ;
0 commit comments