Subversion Repositories oidplus

Rev

Rev 1042 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1042 Rev 1308
Line 259... Line 259...
259
 
259
 
260
        $this->patterns[] = array($pattern, $replacement);
260
        $this->patterns[] = array($pattern, $replacement);
261
    }
261
    }
262
 
262
 
263
    /**
263
    /**
-
 
264
     * Both JS and CSS use the same form of multi-line comment, so putting the common code here.
-
 
265
     */
-
 
266
    protected function stripMultilineComments()
-
 
267
    {
-
 
268
        // First extract comments we want to keep, so they can be restored later
-
 
269
        // PHP only supports $this inside anonymous functions since 5.4
-
 
270
        $minifier = $this;
-
 
271
        $callback = function ($match) use ($minifier) {
-
 
272
            $count = count($minifier->extracted);
-
 
273
            $placeholder = '/*'.$count.'*/';
-
 
274
            $minifier->extracted[$placeholder] = $match[0];
-
 
275
 
-
 
276
            return $placeholder;
-
 
277
        };
-
 
278
        $this->registerPattern('/
-
 
279
            # optional newline
-
 
280
            \n?
-
 
281
 
-
 
282
            # start comment
-
 
283
            \/\*
-
 
284
 
-
 
285
            # comment content
-
 
286
            (?:
-
 
287
                # either starts with an !
-
 
288
                !
-
 
289
            |
-
 
290
                # or, after some number of characters which do not end the comment
-
 
291
                (?:(?!\*\/).)*?
-
 
292
 
-
 
293
                # there is either a @license or @preserve tag
-
 
294
                @(?:license|preserve)
-
 
295
            )
-
 
296
 
-
 
297
            # then match to the end of the comment
-
 
298
            .*?\*\/\n?
-
 
299
 
-
 
300
            /ixs', $callback);
-
 
301
 
-
 
302
        // Then strip all other comments
-
 
303
        $this->registerPattern('/\/\*.*?\*\//s', '');
-
 
304
    }
-
 
305
 
-
 
306
    /**
264
     * We can't "just" run some regular expressions against JavaScript: it's a
307
     * We can't "just" run some regular expressions against JavaScript: it's a
265
     * complex language. E.g. having an occurrence of // xyz would be a comment,
308
     * complex language. E.g. having an occurrence of // xyz would be a comment,
266
     * unless it's used within a string. Of you could have something that looks
309
     * unless it's used within a string. Of you could have something that looks
267
     * like a 'string', but inside a comment.
310
     * like a 'string', but inside a comment.
268
     * The only way to accurately replace these pieces is to traverse the JS one
311
     * The only way to accurately replace these pieces is to traverse the JS one