@@ -16,7 +16,7 @@ const { RuleTester } = require("../../../lib/rule-tester");
16
16
// Tests
17
17
//------------------------------------------------------------------------------
18
18
19
- const ruleTester = new RuleTester ( { parserOptions : { ecmaVersion : 2020 , sourceType : "module" } } ) ;
19
+ const ruleTester = new RuleTester ( { parserOptions : { ecmaVersion : 2022 , sourceType : "module" } } ) ;
20
20
21
21
ruleTester . run ( "no-restricted-exports" , rule , {
22
22
valid : [
@@ -57,8 +57,12 @@ ruleTester.run("no-restricted-exports", rule, {
57
57
{ code : "var b; export { b as a };" , options : [ { restrictedNamedExports : [ "x" ] } ] } ,
58
58
{ code : "export { a } from 'foo';" , options : [ { restrictedNamedExports : [ "x" ] } ] } ,
59
59
{ code : "export { b as a } from 'foo';" , options : [ { restrictedNamedExports : [ "x" ] } ] } ,
60
+ { code : "export { '' } from 'foo';" , options : [ { restrictedNamedExports : [ "undefined" ] } ] } ,
61
+ { code : "export { '' } from 'foo';" , options : [ { restrictedNamedExports : [ " " ] } ] } ,
62
+ { code : "export { ' ' } from 'foo';" , options : [ { restrictedNamedExports : [ "" ] } ] } ,
63
+ { code : "export { ' a', 'a ' } from 'foo';" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
60
64
61
- // does not mistakenly disallow non-exported identifiers that appear in named export declarations
65
+ // does not mistakenly disallow non-exported names that appear in named export declarations
62
66
{ code : "export var b = a;" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
63
67
{ code : "export let [b = a] = [];" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
64
68
{ code : "export const [b] = [a];" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
@@ -69,7 +73,10 @@ ruleTester.run("no-restricted-exports", rule, {
69
73
{ code : "export class A { a(){} }" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
70
74
{ code : "export class A extends B {}" , options : [ { restrictedNamedExports : [ "B" ] } ] } ,
71
75
{ code : "var a; export { a as b };" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
76
+ { code : "var a; export { a as 'a ' };" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
72
77
{ code : "export { a as b } from 'foo';" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
78
+ { code : "export { a as 'a ' } from 'foo';" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
79
+ { code : "export { 'a' as 'a ' } from 'foo';" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
73
80
74
81
// does not check source in re-export declarations
75
82
{ code : "export { b } from 'a';" , options : [ { restrictedNamedExports : [ "a" ] } ] } ,
@@ -188,6 +195,59 @@ ruleTester.run("no-restricted-exports", rule, {
188
195
errors : [ { messageId : "restrictedNamed" , data : { name : "a" } , type : "Identifier" } ]
189
196
} ,
190
197
198
+ // string literals
199
+ {
200
+ code : "let a; export { a as 'a' };" ,
201
+ options : [ { restrictedNamedExports : [ "a" ] } ] ,
202
+ errors : [ { messageId : "restrictedNamed" , data : { name : "a" } , type : "Literal" , column : 22 } ]
203
+ } ,
204
+ {
205
+ code : "let a; export { a as 'b' };" ,
206
+ options : [ { restrictedNamedExports : [ "b" ] } ] ,
207
+ errors : [ { messageId : "restrictedNamed" , data : { name : "b" } , type : "Literal" , column : 22 } ]
208
+ } ,
209
+ {
210
+ code : "let a; export { a as ' b ' };" ,
211
+ options : [ { restrictedNamedExports : [ " b " ] } ] ,
212
+ errors : [ { messageId : "restrictedNamed" , data : { name : " b " } , type : "Literal" , column : 22 } ]
213
+ } ,
214
+ {
215
+ code : "let a; export { a as '👍' };" ,
216
+ options : [ { restrictedNamedExports : [ "👍" ] } ] ,
217
+ errors : [ { messageId : "restrictedNamed" , data : { name : "👍" } , type : "Literal" , column : 22 } ]
218
+ } ,
219
+ {
220
+ code : "export { 'a' } from 'foo';" ,
221
+ options : [ { restrictedNamedExports : [ "a" ] } ] ,
222
+ errors : [ { messageId : "restrictedNamed" , data : { name : "a" } , type : "Literal" } ]
223
+ } ,
224
+ {
225
+ code : "export { '' } from 'foo';" ,
226
+ options : [ { restrictedNamedExports : [ "" ] } ] ,
227
+ errors : [ { messageId : "restrictedNamed" , data : { name : "" } , type : "Literal" } ]
228
+ } ,
229
+ {
230
+ code : "export { ' ' } from 'foo';" ,
231
+ options : [ { restrictedNamedExports : [ " " ] } ] ,
232
+ errors : [ { messageId : "restrictedNamed" , data : { name : " " } , type : "Literal" } ]
233
+ } ,
234
+ {
235
+ code : "export { b as 'a' } from 'foo';" ,
236
+ options : [ { restrictedNamedExports : [ "a" ] } ] ,
237
+ errors : [ { messageId : "restrictedNamed" , data : { name : "a" } , type : "Literal" } ]
238
+ } ,
239
+ {
240
+ code : "export { b as '\\u0061' } from 'foo';" ,
241
+ options : [ { restrictedNamedExports : [ "a" ] } ] ,
242
+ errors : [ { messageId : "restrictedNamed" , data : { name : "a" } , type : "Literal" } ]
243
+ } ,
244
+ {
245
+ code : "export * as 'a' from 'foo';" ,
246
+ options : [ { restrictedNamedExports : [ "a" ] } ] ,
247
+ errors : [ { messageId : "restrictedNamed" , data : { name : "a" } , type : "Literal" } ]
248
+ } ,
249
+
250
+
191
251
// destructuring
192
252
{
193
253
code : "export var [a] = [];" ,
0 commit comments