File tree Expand file tree Collapse file tree 4 files changed +239
-56
lines changed Expand file tree Collapse file tree 4 files changed +239
-56
lines changed Original file line number Diff line number Diff line change
1
+ const SatisfiesSnapshot = {
2
+ Normal : {
3
+ 'type' : 'Program' ,
4
+ 'start' : 0 ,
5
+ 'end' : 25 ,
6
+ 'loc' : {
7
+ 'start' : {
8
+ 'line' : 1 ,
9
+ 'column' : 0 ,
10
+ 'index' : 0
11
+ } ,
12
+ 'end' : {
13
+ 'line' : 1 ,
14
+ 'column' : 25 ,
15
+ 'index' : 25
16
+ }
17
+ } ,
18
+ 'body' : [
19
+ {
20
+ 'type' : 'VariableDeclaration' ,
21
+ 'start' : 0 ,
22
+ 'end' : 25 ,
23
+ 'loc' : {
24
+ 'start' : {
25
+ 'line' : 1 ,
26
+ 'column' : 0 ,
27
+ 'index' : 0
28
+ } ,
29
+ 'end' : {
30
+ 'line' : 1 ,
31
+ 'column' : 25 ,
32
+ 'index' : 25
33
+ }
34
+ } ,
35
+ 'declarations' : [
36
+ {
37
+ 'type' : 'VariableDeclarator' ,
38
+ 'start' : 6 ,
39
+ 'end' : 25 ,
40
+ 'loc' : {
41
+ 'start' : {
42
+ 'line' : 1 ,
43
+ 'column' : 6 ,
44
+ 'index' : 6
45
+ } ,
46
+ 'end' : {
47
+ 'line' : 1 ,
48
+ 'column' : 25 ,
49
+ 'index' : 25
50
+ }
51
+ } ,
52
+ 'id' : {
53
+ 'type' : 'Identifier' ,
54
+ 'start' : 6 ,
55
+ 'end' : 7 ,
56
+ 'loc' : {
57
+ 'start' : {
58
+ 'line' : 1 ,
59
+ 'column' : 6 ,
60
+ 'index' : 6
61
+ } ,
62
+ 'end' : {
63
+ 'line' : 1 ,
64
+ 'column' : 7 ,
65
+ 'index' : 7
66
+ }
67
+ } ,
68
+ 'name' : 'a'
69
+ } ,
70
+ 'init' : {
71
+ 'type' : 'TSSatisfiesExpression' ,
72
+ 'start' : 10 ,
73
+ 'end' : 25 ,
74
+ 'loc' : {
75
+ 'start' : {
76
+ 'line' : 1 ,
77
+ 'column' : 10 ,
78
+ 'index' : 10
79
+ } ,
80
+ 'end' : {
81
+ 'line' : 1 ,
82
+ 'column' : 25 ,
83
+ 'index' : 25
84
+ }
85
+ } ,
86
+ 'expression' : {
87
+ 'type' : 'Literal' ,
88
+ 'start' : 10 ,
89
+ 'end' : 11 ,
90
+ 'loc' : {
91
+ 'start' : {
92
+ 'line' : 1 ,
93
+ 'column' : 10 ,
94
+ 'index' : 10
95
+ } ,
96
+ 'end' : {
97
+ 'line' : 1 ,
98
+ 'column' : 11 ,
99
+ 'index' : 11
100
+ }
101
+ } ,
102
+ 'value' : 1 ,
103
+ 'raw' : '1'
104
+ } ,
105
+ 'typeAnnotation' : {
106
+ 'type' : 'TSAnyKeyword' ,
107
+ 'start' : 22 ,
108
+ 'end' : 25 ,
109
+ 'loc' : {
110
+ 'start' : {
111
+ 'line' : 1 ,
112
+ 'column' : 22 ,
113
+ 'index' : 22
114
+ } ,
115
+ 'end' : {
116
+ 'line' : 1 ,
117
+ 'column' : 25 ,
118
+ 'index' : 25
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ ] ,
125
+ 'kind' : 'const'
126
+ }
127
+ ] ,
128
+ 'sourceType' : 'module'
129
+ }
130
+ }
131
+
132
+ export default SatisfiesSnapshot
Original file line number Diff line number Diff line change
1
+ import {
2
+ equalNode ,
3
+ parseSourceAllowSatisfies ,
4
+ parseSourceShouldThrowError
5
+ } from '../utils'
6
+ import SatisfiesSnapshot from '../__snapshot__/satisfies'
7
+
8
+ describe ( 'satisfies' , function ( ) {
9
+ it ( 'normal' , function ( ) {
10
+ const node = parseSourceAllowSatisfies ( 'const a = 1 satisfies any' )
11
+
12
+ equalNode ( node , SatisfiesSnapshot . Normal )
13
+ } )
14
+
15
+ it ( 'should error' , function ( ) {
16
+ const res = parseSourceShouldThrowError (
17
+ 'const a = 1 satisfies any' ,
18
+ 'Unexpected token' ,
19
+ '(1:12)'
20
+ )
21
+
22
+ expect ( res ) . toBe ( true )
23
+ } )
24
+ } )
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ export const DtsParser = acorn.Parser.extend(tsPlugin({
7
7
dts : true
8
8
} ) )
9
9
10
+ export const AllowSatisfiesParser = acorn . Parser . extend ( tsPlugin ( {
11
+ allowSatisfies : true
12
+ } ) )
13
+
10
14
export function equalNode ( node , snapshot ) {
11
15
expect ( node ) . toEqual ( snapshot )
12
16
}
@@ -27,6 +31,14 @@ export function parseSource(input: string) {
27
31
} )
28
32
}
29
33
34
+ export function parseSourceAllowSatisfies ( input : string ) {
35
+ return AllowSatisfiesParser . parse ( input , {
36
+ sourceType : 'module' ,
37
+ ecmaVersion : 'latest' ,
38
+ locations : true
39
+ } )
40
+ }
41
+
30
42
export function parseSourceShouldThrowError ( input : string , message : string , loc : string ) : boolean {
31
43
try {
32
44
Parser . parse ( input , {
You can’t perform that action at this time.
0 commit comments