codesandboxer icon indicating copy to clipboard operation
codesandboxer copied to clipboard

Import parsing pulls in commented out imports

Open tikotzky opened this issue 7 years ago • 1 comments

for example a file that looks like

// import colors from '../colors';
import Dropdown from '../Dropdown';

will try to include both colors and Dropdown in the codesandbox when only Dropdown is being used.

tikotzky avatar Jun 07 '18 16:06 tikotzky

Thanks for raising this!

Because we are currently using regex to match imports, determining whether an import is in a comment (or in a string) is near impossible, for example:

/*
import colors from '../colors'
*/

we need a solid way to detect they are in a comment block.

I've got a task to look at the cost of using babel to parse files instead of regex matching for imports, as it would allow us to be way more reliable about edge case matches. Will update this issue once I have a clear idea of the cost/benefits of moving to full AST parsing.

Noviny avatar Jun 08 '18 05:06 Noviny