@@ -10,10 +10,12 @@ const ConcatSource = require("webpack-sources").ConcatSource;
1010const START_LOWERCASE_ALPHABET_CODE = "a" . charCodeAt ( 0 ) ;
1111const START_UPPERCASE_ALPHABET_CODE = "A" . charCodeAt ( 0 ) ;
1212const DELTA_A_TO_Z = "z" . charCodeAt ( 0 ) - START_LOWERCASE_ALPHABET_CODE + 1 ;
13- const FUNCTION_CONTENT_REGEX = / ^ f u n c t i o n \s ? \( \) \s ? \{ \n ? | \n ? \} $ / g;
13+ const FUNCTION_CONTENT_REGEX = / ^ f u n c t i o n \s ? \( \) \s ? \{ \r ? \ n? | \r ? \n ? \} $ / g;
1414const INDENT_MULTILINE_REGEX = / ^ \t / mg;
15- const IDENTIFIER_NAME_REPLACE_REGEX = / ^ [ ^ a - z A - Z $ _ ] / ;
16- const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = / [ ^ a - z A - Z 0 - 9 $ _ ] / g;
15+ const LINE_SEPARATOR_REGEX = / \r ? \n / g;
16+ const IDENTIFIER_NAME_REPLACE_REGEX = / ^ ( [ ^ a - z A - Z $ _ ] ) / ;
17+ const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = / [ ^ a - z A - Z 0 - 9 $ ] + / g;
18+ const COMMENT_END_REGEX = / \* \/ / g;
1719const PATH_NAME_NORMALIZE_REPLACE_REGEX = / [ ^ a - z A - Z 0 - 9 _ ! § $ ( ) = \- ^ ° ] + / g;
1820const MATCH_PADDED_HYPHENS_REPLACE_REGEX = / ^ - | - $ / g;
1921
@@ -24,12 +26,22 @@ module.exports = class Template extends Tapable {
2426 }
2527
2628 static getFunctionContent ( fn ) {
27- return fn . toString ( ) . replace ( FUNCTION_CONTENT_REGEX , "" ) . replace ( INDENT_MULTILINE_REGEX , "" ) ;
29+ return fn . toString ( ) . replace ( FUNCTION_CONTENT_REGEX , "" ) . replace ( INDENT_MULTILINE_REGEX , "" ) . replace ( LINE_SEPARATOR_REGEX , "\n" ) ;
2830 }
2931
3032 static toIdentifier ( str ) {
3133 if ( typeof str !== "string" ) return "" ;
32- return str . replace ( IDENTIFIER_NAME_REPLACE_REGEX , "_" ) . replace ( IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX , "_" ) ;
34+ return str . replace ( IDENTIFIER_NAME_REPLACE_REGEX , "_$1" ) . replace ( IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX , "_" ) ;
35+ }
36+
37+ static toComment ( str ) {
38+ if ( ! str ) return "" ;
39+ return `/*! ${ str . replace ( COMMENT_END_REGEX , "* /" ) } */` ;
40+ }
41+
42+ static toNormalComment ( str ) {
43+ if ( ! str ) return "" ;
44+ return `/* ${ str . replace ( COMMENT_END_REGEX , "* /" ) } */` ;
3345 }
3446
3547 static toPath ( str ) {
0 commit comments