@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
value : true
5
5
} ) ;
6
6
exports . dedentBlockStringValue = dedentBlockStringValue ;
7
+ exports . getBlockStringIndentation = getBlockStringIndentation ;
7
8
exports . printBlockString = printBlockString ;
8
9
9
10
/**
@@ -25,24 +26,11 @@ function dedentBlockStringValue(rawString) {
25
26
// Expand a block string's raw value into independent lines.
26
27
var lines = rawString . split ( / \r \n | [ \n \r ] / g) ; // Remove common indentation from all lines but first.
27
28
28
- var commonIndent = null ;
29
-
30
- for ( var i = 1 ; i < lines . length ; i ++ ) {
31
- var line = lines [ i ] ;
32
- var indent = leadingWhitespace ( line ) ;
33
-
34
- if ( indent < line . length && ( commonIndent === null || indent < commonIndent ) ) {
35
- commonIndent = indent ;
36
-
37
- if ( commonIndent === 0 ) {
38
- break ;
39
- }
40
- }
41
- }
29
+ var commonIndent = getBlockStringIndentation ( lines ) ;
42
30
43
- if ( commonIndent ) {
44
- for ( var _i = 1 ; _i < lines . length ; _i ++ ) {
45
- lines [ _i ] = lines [ _i ] . slice ( commonIndent ) ;
31
+ if ( commonIndent !== 0 ) {
32
+ for ( var i = 1 ; i < lines . length ; i ++ ) {
33
+ lines [ i ] = lines [ i ] . slice ( commonIndent ) ;
46
34
}
47
35
} // Remove leading and trailing blank lines.
48
36
@@ -57,6 +45,30 @@ function dedentBlockStringValue(rawString) {
57
45
58
46
59
47
return lines . join ( '\n' ) ;
48
+ } // @internal
49
+
50
+
51
+ function getBlockStringIndentation ( lines ) {
52
+ var commonIndent = null ;
53
+
54
+ for ( var i = 1 ; i < lines . length ; i ++ ) {
55
+ var line = lines [ i ] ;
56
+ var indent = leadingWhitespace ( line ) ;
57
+
58
+ if ( indent === line . length ) {
59
+ continue ; // skip empty lines
60
+ }
61
+
62
+ if ( commonIndent === null || indent < commonIndent ) {
63
+ commonIndent = indent ;
64
+
65
+ if ( commonIndent === 0 ) {
66
+ break ;
67
+ }
68
+ }
69
+ }
70
+
71
+ return commonIndent === null ? 0 : commonIndent ;
60
72
}
61
73
62
74
function leadingWhitespace ( str ) {
0 commit comments