@@ -146,6 +146,41 @@ ruleTester.run('named', rule, {
146146 code : 'import { common } from "./re-export-default"' ,
147147 } ) ,
148148
149+ // destructured requires with commonjs option
150+ test ( {
151+ code : 'const { destructuredProp } = require("./named-exports")' ,
152+ options : [ { commonjs : true } ] ,
153+ } ) ,
154+ test ( {
155+ code : 'let { arrayKeyProp } = require("./named-exports")' ,
156+ options : [ { commonjs : true } ] ,
157+ } ) ,
158+ test ( {
159+ code : 'const { deepProp } = require("./named-exports")' ,
160+ options : [ { commonjs : true } ] ,
161+ } ) ,
162+
163+ test ( {
164+ code : 'const { foo, bar } = require("./re-export-names")' ,
165+ options : [ { commonjs : true } ] ,
166+ } ) ,
167+
168+ test ( {
169+ code : 'const { baz } = require("./bar")' ,
170+ errors : [ error ( 'baz' , './bar' ) ] ,
171+ } ) ,
172+
173+ test ( {
174+ code : 'const { baz } = require("./bar")' ,
175+ errors : [ error ( 'baz' , './bar' ) ] ,
176+ options : [ { commonjs : false } ] ,
177+ } ) ,
178+
179+ test ( {
180+ code : 'const { default: defExport } = require("./bar")' ,
181+ options : [ { commonjs : true } ] ,
182+ } ) ,
183+
149184 ...SYNTAX_CASES ,
150185 ] ,
151186
@@ -201,6 +236,30 @@ ruleTester.run('named', rule, {
201236 errors : [ 'baz not found via broken-trampoline.js -> named-exports.js' ] ,
202237 } ) ,
203238
239+ test ( {
240+ code : 'const { baz } = require("./bar")' ,
241+ errors : [ error ( 'baz' , './bar' ) ] ,
242+ options : [ { commonjs : true } ] ,
243+ } ) ,
244+
245+ test ( {
246+ code : 'let { baz } = require("./bar")' ,
247+ errors : [ error ( 'baz' , './bar' ) ] ,
248+ options : [ { commonjs : true } ] ,
249+ } ) ,
250+
251+ test ( {
252+ code : 'const { baz: bar, bop } = require("./bar"), { a } = require("./re-export-names")' ,
253+ errors : [ error ( 'baz' , './bar' ) , error ( 'bop' , './bar' ) , error ( 'a' , './re-export-names' ) ] ,
254+ options : [ { commonjs : true } ] ,
255+ } ) ,
256+
257+ test ( {
258+ code : 'const { default: defExport } = require("./named-exports")' ,
259+ errors : [ error ( 'default' , './named-exports' ) ] ,
260+ options : [ { commonjs : true } ] ,
261+ } ) ,
262+
204263 // parse errors
205264 // test({
206265 // code: "import { a } from './test.coffee';",
0 commit comments