@@ -52,7 +52,7 @@ describe("ES6 arrow function expression", () => {
52
52
scope = scopeManager . scopes [ 1 ] ;
53
53
expect ( scope . type ) . to . be . equal ( "function" ) ;
54
54
expect ( scope . block . type ) . to . be . equal ( "ArrowFunctionExpression" ) ;
55
- expect ( scope . isStrict ) . to . be . true ;
55
+ expect ( scope . isStrict ) . to . be . false ;
56
56
expect ( scope . variables ) . to . have . length ( 2 ) ;
57
57
58
58
// There's no "arguments"
@@ -77,7 +77,7 @@ describe("ES6 arrow function expression", () => {
77
77
scope = scopeManager . scopes [ 1 ] ;
78
78
expect ( scope . type ) . to . be . equal ( "function" ) ;
79
79
expect ( scope . block . type ) . to . be . equal ( "ArrowFunctionExpression" ) ;
80
- expect ( scope . isStrict ) . to . be . true ;
80
+ expect ( scope . isStrict ) . to . be . false ;
81
81
expect ( scope . variables ) . to . have . length ( 4 ) ;
82
82
83
83
// There's no "arguments"
@@ -86,6 +86,72 @@ describe("ES6 arrow function expression", () => {
86
86
expect ( scope . variables [ 2 ] . name ) . to . be . equal ( "c" ) ;
87
87
expect ( scope . variables [ 3 ] . name ) . to . be . equal ( "d" ) ;
88
88
} ) ;
89
+
90
+ it ( "inherits upper scope strictness" , ( ) => {
91
+ const ast = espree ( `
92
+ "use strict";
93
+ var arrow = () => {};
94
+ ` ) ;
95
+
96
+ const scopeManager = analyze ( ast , { ecmaVersion : 6 } ) ;
97
+
98
+ expect ( scopeManager . scopes ) . to . have . length ( 2 ) ;
99
+
100
+ let scope = scopeManager . scopes [ 0 ] ;
101
+
102
+ expect ( scope . type ) . to . be . equal ( "global" ) ;
103
+ expect ( scope . block . type ) . to . be . equal ( "Program" ) ;
104
+ expect ( scope . isStrict ) . to . be . true ;
105
+ expect ( scope . variables ) . to . have . length ( 1 ) ;
106
+
107
+ scope = scopeManager . scopes [ 1 ] ;
108
+
109
+ expect ( scope . type ) . to . be . equal ( "function" ) ;
110
+ expect ( scope . block . type ) . to . be . equal ( "ArrowFunctionExpression" ) ;
111
+ expect ( scope . isStrict ) . to . be . true ;
112
+ expect ( scope . variables ) . to . have . length ( 0 ) ;
113
+ } ) ;
114
+
115
+ it ( "is strict when a strictness directive is used" , ( ) => {
116
+ const ast = espree ( `
117
+ var arrow = () => {
118
+ "use strict";
119
+ };
120
+ ` ) ;
121
+
122
+ const scopeManager = analyze ( ast , { ecmaVersion : 6 } ) ;
123
+
124
+ expect ( scopeManager . scopes ) . to . have . length ( 2 ) ;
125
+
126
+ let scope = scopeManager . scopes [ 0 ] ;
127
+
128
+ expect ( scope . type ) . to . be . equal ( "global" ) ;
129
+ expect ( scope . block . type ) . to . be . equal ( "Program" ) ;
130
+ expect ( scope . isStrict ) . to . be . false ;
131
+ expect ( scope . variables ) . to . have . length ( 1 ) ;
132
+
133
+ scope = scopeManager . scopes [ 1 ] ;
134
+
135
+ expect ( scope . type ) . to . be . equal ( "function" ) ;
136
+ expect ( scope . block . type ) . to . be . equal ( "ArrowFunctionExpression" ) ;
137
+ expect ( scope . isStrict ) . to . be . true ;
138
+ expect ( scope . variables ) . to . have . length ( 0 ) ;
139
+ } ) ;
140
+
141
+ it ( "works with no body" , ( ) => {
142
+ const ast = espree ( "var arrow = a => a;" ) ;
143
+
144
+ const scopeManager = analyze ( ast , { ecmaVersion : 6 } ) ;
145
+
146
+ expect ( scopeManager . scopes ) . to . have . length ( 2 ) ;
147
+
148
+ const scope = scopeManager . scopes [ 1 ] ;
149
+
150
+ expect ( scope . type ) . to . be . equal ( "function" ) ;
151
+ expect ( scope . block . type ) . to . be . equal ( "ArrowFunctionExpression" ) ;
152
+ expect ( scope . isStrict ) . to . be . false ;
153
+ expect ( scope . variables ) . to . have . length ( 1 ) ;
154
+ } ) ;
89
155
} ) ;
90
156
91
157
// vim: set sw=4 ts=4 et tw=80 :
0 commit comments