@@ -20,15 +20,17 @@ function getNextStep(content, pos, stop) {
2020// will blow up. Template strings are not tested and might also be
2121// broken.
2222function extractFunction ( content , functionName ) {
23- var indent = 0 ;
23+ var level = 0 ;
2424 var splitter = "function " + functionName + "(" ;
25+ var stop ;
26+ var pos , start ;
2527
2628 while ( true ) {
27- var start = content . indexOf ( splitter ) ;
29+ start = content . indexOf ( splitter ) ;
2830 if ( start === - 1 ) {
2931 break ;
3032 }
31- var pos = start ;
33+ pos = start ;
3234 while ( pos < content . length && content [ pos ] !== ')' ) {
3335 pos += 1 ;
3436 }
@@ -44,30 +46,33 @@ function extractFunction(content, functionName) {
4446 }
4547 while ( pos < content . length ) {
4648 // Eat single-line comments
47- if ( content [ pos ] === '/' && pos > 0 && content [ pos - 1 ] === '/' ) {
49+ if ( content [ pos ] === '/' && pos > 0 && content [ pos - 1 ] === '/' ) {
4850 do {
4951 pos += 1 ;
5052 } while ( pos < content . length && content [ pos ] !== '\n' ) ;
5153
54+ // Eat multiline comment.
55+ } else if ( content [ pos ] === '*' && pos > 0 && content [ pos - 1 ] === '/' ) {
56+ do {
57+ pos += 1 ;
58+ } while ( pos < content . length && content [ pos ] !== '/' && content [ pos - 1 ] !== '*' ) ;
59+
5260 // Eat quoted strings
5361 } else if ( content [ pos ] === '"' || content [ pos ] === "'" || content [ pos ] === "`" ) {
54- var stop = content [ pos ] ;
55- var is_escaped = false ;
62+ stop = content [ pos ] ;
5663 do {
5764 if ( content [ pos ] === '\\' ) {
58- pos += 2 ;
59- } else {
6065 pos += 1 ;
6166 }
62- } while ( pos < content . length &&
63- ( content [ pos ] !== stop || content [ pos - 1 ] === '\\' ) ) ;
67+ pos += 1 ;
68+ } while ( pos < content . length && content [ pos ] !== stop ) ;
6469
65- // Otherwise, check for indent
70+ // Otherwise, check for block level.
6671 } else if ( content [ pos ] === '{' ) {
67- indent += 1 ;
72+ level += 1 ;
6873 } else if ( content [ pos ] === '}' ) {
69- indent -= 1 ;
70- if ( indent === 0 ) {
74+ level -= 1 ;
75+ if ( level === 0 ) {
7176 return content . slice ( start , pos + 1 ) ;
7277 }
7378 }
0 commit comments