@@ -113,7 +113,7 @@ enum TokenType {
113
113
KwNew ;
114
114
115
115
/** Function code */
116
- Function (name : Null <String >, args : Array <String >, code : String );
116
+ Function (name : Null <String >, args : Array <String >, code : String , external : Bool );
117
117
118
118
/** String literal with optional attachments */
119
119
LString (quotes : Quotes , s : String , ? attachments : Array <LStringAttachment >);
@@ -806,7 +806,7 @@ class Token {
806
806
if (c == " " .code ) {
807
807
spaces ++ ;
808
808
} else if (c == " \t " .code ) {
809
- spaces + = 4 ; // Treat each tab as 4 spaces
809
+ spaces ++ ;
810
810
} else {
811
811
break ;
812
812
}
@@ -3103,6 +3103,9 @@ class Token {
3103
3103
function readFunction (start : Position ): Token {
3104
3104
skipWhitespaceAndComments ();
3105
3105
3106
+ // Evaluate min indentation
3107
+ final minIndent = start .column ; // Column is 1-based, so column 0 will mean min indent 1
3108
+
3106
3109
// Read function name if present
3107
3110
var name : Null <String > = null ;
3108
3111
if (isIdentifierStart (input .uCharCodeAt (pos ))) {
@@ -3250,14 +3253,20 @@ class Token {
3250
3253
while (pos < length ) {
3251
3254
final c = input .uCharCodeAt (pos );
3252
3255
if (c == " " .code ) indent ++ ;
3253
- else if (c == " \t " .code ) indent + = 4 ; // Count tab as 4 spaces
3256
+ else if (c == " \t " .code ) indent ++ ;
3254
3257
else break ;
3255
3258
advance ();
3256
3259
}
3257
3260
3258
3261
// If this is the first line, record the indent level
3259
3262
if (functionIndentLevel == - 1 && pos < length && input .uCharCodeAt (pos ) != " \n " .code && input .uCharCodeAt (pos ) != " \r " .code ) {
3260
3263
functionIndentLevel = indent ;
3264
+
3265
+ // Check this is indented enough
3266
+ if (functionIndentLevel < minIndent ) {
3267
+ pos = indentStart ;
3268
+ break ;
3269
+ }
3261
3270
}
3262
3271
// Check if we are done (dedent or empty line at lower indentation)
3263
3272
else if (functionIndentLevel != - 1 && indent < functionIndentLevel &&
@@ -3297,10 +3306,15 @@ class Token {
3297
3306
3298
3307
// Extract the function code from the original input
3299
3308
final bodyEnd = pos ;
3300
- final code = input .uSubstr (start .offset , bodyEnd - start .offset ).rtrim () + " \n " ;
3309
+ var code = input .uSubstr (start .offset , bodyEnd - start .offset ).rtrim ();
3310
+
3311
+ final external = (code .uIndexOf (" \n " ) == - 1 );
3312
+ if (! external ) {
3313
+ code = code + " \n " ;
3314
+ }
3301
3315
3302
3316
// Create token with the function code
3303
- final token = makeToken (Function (name , args , code ), start );
3317
+ final token = makeToken (Function (name , args , code , external ), start );
3304
3318
token .pos .length = code .uLength ();
3305
3319
return token ;
3306
3320
}
0 commit comments