@@ -9,6 +9,7 @@ const Parser = require("../Parser");
99const ConstDependency = require ( "../dependencies/ConstDependency" ) ;
1010const CssExportDependency = require ( "../dependencies/CssExportDependency" ) ;
1111const CssImportDependency = require ( "../dependencies/CssImportDependency" ) ;
12+ const CssLocalIdentifierDependency = require ( "../dependencies/CssLocalIdentifierDependency" ) ;
1213const CssUrlDependency = require ( "../dependencies/CssUrlDependency" ) ;
1314const StaticExportsDependency = require ( "../dependencies/StaticExportsDependency" ) ;
1415const walkCssTokens = require ( "./walkCssTokens" ) ;
@@ -95,9 +96,15 @@ const explainMode = mode => {
9596} ;
9697
9798class CssParser extends Parser {
98- constructor ( { allowPseudoBlocks = true } = { } ) {
99+ constructor ( {
100+ allowPseudoBlocks = true ,
101+ allowModeSwitch = true ,
102+ defaultMode = "global"
103+ } = { } ) {
99104 super ( ) ;
100105 this . allowPseudoBlocks = allowPseudoBlocks ;
106+ this . allowModeSwitch = allowModeSwitch ;
107+ this . defaultMode = defaultMode ;
101108 }
102109
103110 /**
@@ -340,6 +347,27 @@ class CssParser extends Parser {
340347 }
341348 return end ;
342349 } ,
350+ class : ( input , start , end ) => {
351+ switch ( mode ) {
352+ case CSS_MODE_TOP_LEVEL : {
353+ if (
354+ modeData === "local" ||
355+ ( this . defaultMode === "local" && modeData === undefined )
356+ ) {
357+ const dep = new CssLocalIdentifierDependency (
358+ input . slice ( start + 1 , end ) ,
359+ [ start + 1 , end ]
360+ ) ;
361+ const { line : sl , column : sc } = locConverter . get ( start ) ;
362+ const { line : el , column : ec } = locConverter . get ( end ) ;
363+ dep . setLoc ( sl , sc , el , ec ) ;
364+ module . addDependency ( dep ) ;
365+ }
366+ break ;
367+ }
368+ }
369+ return end ;
370+ } ,
343371 leftParenthesis : ( input , start , end ) => {
344372 return end ;
345373 } ,
@@ -349,24 +377,30 @@ class CssParser extends Parser {
349377 pseudoClass : ( input , start , end ) => {
350378 switch ( mode ) {
351379 case CSS_MODE_TOP_LEVEL : {
352- if ( this . allowPseudoBlocks ) {
353- const name = input . slice ( start , end ) ;
354- if ( name === ":global" ) {
355- modeData = ":global" ;
356- } else if ( name === ":local" ) {
357- modeData = ":local" ;
358- } else if ( name === ":export" ) {
359- const pos = parseExports ( input , end ) ;
360- const dep = new ConstDependency ( "" , [ start , pos ] ) ;
361- module . addPresentationalDependency ( dep ) ;
362- return pos ;
363- }
380+ const name = input . slice ( start , end ) ;
381+ if ( this . allowModeSwitch && name === ":global" ) {
382+ modeData = "global" ;
383+ } else if ( this . allowModeSwitch && name === ":local" ) {
384+ modeData = "local" ;
385+ } else if ( this . allowPseudoBlocks && name === ":export" ) {
386+ const pos = parseExports ( input , end ) ;
387+ const dep = new ConstDependency ( "" , [ start , pos ] ) ;
388+ module . addPresentationalDependency ( dep ) ;
389+ return pos ;
364390 }
365391 break ;
366392 }
367393 }
368394 return end ;
369395 } ,
396+ pseudoFunction : ( input , start , end ) => {
397+ switch ( mode ) {
398+ case CSS_MODE_TOP_LEVEL : {
399+ break ;
400+ }
401+ }
402+ return end ;
403+ } ,
370404 comma : ( input , start , end ) => {
371405 switch ( mode ) {
372406 case CSS_MODE_TOP_LEVEL :
0 commit comments