@@ -33,24 +33,38 @@ function normalizeImportSourceToFilePath(filePath, source) {
3333 return normalizeFilePath ( normalized ) ;
3434}
3535
36+ function getImportAttributeType ( attributes = [ ] ) {
37+ for ( let node of attributes ) {
38+ if ( node . type === "ImportAttribute" && node . key . type === "Identifier" && node . key . name === "type" ) {
39+ return node . value . value ;
40+ }
41+ }
42+ }
43+
3644async function findByContents ( contents , filePath , alreadyParsedSet ) {
3745 // Should we use dependency-graph for these relationships?
3846 let sources = new Set ( ) ;
47+ let nestedSources = new Set ( ) ;
3948
4049 let ast = acorn . parse ( contents , { sourceType : "module" , ecmaVersion : "latest" } ) ;
50+
4151 for ( let node of ast . body ) {
4252 if ( node . type === "ImportDeclaration" && isNonBareSpecifier ( node . source . value ) ) {
53+ let importAttributeType = getImportAttributeType ( node ?. attributes ) ;
4354 let normalized = normalizeImportSourceToFilePath ( filePath , node . source . value ) ;
44- if ( sources . has ( normalized ) || normalized === filePath ) {
45- continue ;
46- }
55+ if ( normalized !== filePath ) {
56+ sources . add ( normalized ) ;
4757
48- sources . add ( normalized ) ;
58+ // Right now only `css` and `json` are valid but others might come later
59+ if ( ! importAttributeType ) {
60+ nestedSources . add ( normalized ) ;
61+ }
62+ }
4963 }
5064 }
5165
5266 // Recurse for nested deps
53- for ( let source of sources ) {
67+ for ( let source of nestedSources ) {
5468 let s = await find ( source , alreadyParsedSet ) ;
5569 for ( let p of s ) {
5670 if ( sources . has ( p ) || p === filePath ) {
0 commit comments