You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Convert to ES6 module" not working with IIFE pattern #24297
Create a file test_file.js with the following content:
var path = require('path');
(function () {
var path = require('path');
}());
Click lightbulb and select "Convert to ES6 module" then the 1st require transforms to the import path from "path";. It is correct. Then comment 1st require and click lightbulb and select "Convert to ES6 module" for the 2nd require. 2nd require doesn't converted to the import path from "path";. ES6 imports must be at the top level of your JavaScript files. So, I suppose, for require in IIFE there should be NO option "Convert to ES6 module"
Matt Bierner (@mjbvz) , may be you just need to wait a little bit. There is a screenshot with existing "Convert to ES6 module" suggestion for require in the IIFE
I 'use strict';. Then without IIFE jshint generates warning: "Use the function form of "use strict". (W097)". So, the 1st reason for using IIFE is to avoid this warning.
Activity
mjbvz commentedon May 21, 2018
Yes, I think not converting the inner
requireis correct since imports can only appear at the top level in a program.In VS Code insiders, I do not see the
convert to es6suggestion on the inner require:osya commentedon May 21, 2018
Matt Bierner (@mjbvz) , may be you just need to wait a little bit. There is a screenshot with existing "Convert to ES6 module" suggestion for

requirein the IIFEDanielRosenwasser commentedon May 21, 2018
(As an aside, could you tell us a bit more about why this IIFE is being used?)
mhegazy commentedon May 21, 2018
osya this last report should be fixed by #24101.
osya commentedon May 21, 2018
Daniel Rosenwasser (@DanielRosenwasser) I use IIFE for the following two reasons:
'use strict';. Then without IIFEjshintgenerates warning: "Use the function form of "use strict". (W097)". So, the 1st reason for using IIFE is to avoid this warning.