File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ import ava from "ava" ;
2+ import stripComments from "../../src/util/stripComments" ;
3+
4+ ava ( "stripComments()" , ( t ) => {
5+ t . deepEqual ( stripComments ( "aaa/**/bbb" ) , "aaabbb" ) ;
6+ t . deepEqual ( stripComments ( "aaa/*bbb" ) , "aaa" ) ;
7+ t . deepEqual ( stripComments ( "aaa/*xxx*/bbb" ) , "aaabbb" ) ;
8+ t . deepEqual ( stripComments ( "aaa/*/xxx/*/bbb" ) , "aaabbb" ) ;
9+ t . deepEqual ( stripComments ( "aaa/*x*/bbb/**/" ) , "aaabbb" ) ;
10+ t . deepEqual ( stripComments ( "/**/aaa/*x*/bbb/**/" ) , "aaabbb" ) ;
11+ t . deepEqual ( stripComments ( "/**/" ) , "" ) ;
12+ } ) ;
Original file line number Diff line number Diff line change 11export { default as unesc } from './unesc' ;
22export { default as getProp } from './getProp' ;
33export { default as ensureObject } from './ensureObject' ;
4+ export { default as stripComments } from './stripComments' ;
Original file line number Diff line number Diff line change 1+ export default function stripComments ( str ) {
2+ let s = "" ;
3+ let commentStart = str . indexOf ( "/*" ) ;
4+ let lastEnd = 0 ;
5+ while ( commentStart >= 0 ) {
6+ s = s + str . slice ( lastEnd , commentStart ) ;
7+ let commentEnd = str . indexOf ( "*/" , commentStart + 2 ) ;
8+ if ( commentEnd < 0 ) {
9+ return s ;
10+ }
11+ lastEnd = commentEnd + 2 ;
12+ commentStart = str . indexOf ( "/*" , lastEnd ) ;
13+ }
14+ s = s + str . slice ( lastEnd ) ;
15+ return s ;
16+ }
You can’t perform that action at this time.
0 commit comments