@@ -9,7 +9,6 @@ var clone = require("clone")
99var resolve = require ( "resolve" )
1010var postcss = require ( "postcss" )
1111var helpers = require ( "postcss-message-helpers" )
12- var hash = require ( "string-hash" )
1312var glob = require ( "glob" )
1413
1514var Promize = global . Promise || require ( "es6-promise" ) . Promise
@@ -353,29 +352,27 @@ function readImportedContent(
353352 return resolvedPromise
354353 }
355354
356- // skip files wich only contain @import rules
357- var newFileContent = fileContent . replace ( / @ i m p o r t ( .* ) ; / , "" )
358- if ( newFileContent . trim ( ) !== "" ) {
359- var fileContentHash = hash ( fileContent )
360-
361- // skip files already imported at the same scope and same hash
362- if (
363- state . hashFiles [ fileContentHash ] &&
364- state . hashFiles [ fileContentHash ] [ media ]
365- ) {
366- detach ( atRule )
367- return resolvedPromise
368- }
355+ // skip previous imported files not containing @import rules
356+ if (
357+ state . hashFiles [ fileContent ] &&
358+ state . hashFiles [ fileContent ] [ media ]
359+ ) {
360+ detach ( atRule )
361+ return resolvedPromise
362+ }
369363
364+ var newStyles = postcss . parse ( fileContent , options )
365+ var hasImport = newStyles . some ( function ( child ) {
366+ return child . type === "atrule" && child . name . toLowerCase ( ) === "import"
367+ } )
368+ if ( ! hasImport ) {
370369 // save hash files to skip them next time
371- if ( ! state . hashFiles [ fileContentHash ] ) {
372- state . hashFiles [ fileContentHash ] = { }
370+ if ( ! state . hashFiles [ fileContent ] ) {
371+ state . hashFiles [ fileContent ] = { }
373372 }
374- state . hashFiles [ fileContentHash ] [ media ] = true
373+ state . hashFiles [ fileContent ] [ media ] = true
375374 }
376375
377- var newStyles = postcss . parse ( fileContent , options )
378-
379376 // recursion: import @import from imported file
380377 var parsedResult = parseStyles (
381378 result ,
0 commit comments