Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 and 403]

JavaScript minifier Please report bugs on https://github.com/matthiasmullie/minify/issues

Author: Matthias Mullie <minify@mullie.eu>
Copyright: Copyright (c) 2012, Matthias Mullie. All rights reserved
License: MIT License
File Size: 612 lines (39 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: JS  - X-Ref

JavaScript Minifier Class

Please report bugs on https://github.com/matthiasmullie/minify/issues

__construct()   X-Ref
{@inheritdoc}


execute($path = null)   X-Ref
Minify the data.
Perform JS optimizations.

param: string[optional] $path Path to write the data to
return: string The minified data

stripComments()   X-Ref
Strip comments from source code.


extractRegex()   X-Ref
JS can have /-delimited regular expressions, like: /ab+c/.match(string).

The content inside the regex can contain characters that may be confused
for JS code: e.g. it could contain whitespace it needs to match & we
don't want to strip whitespace in there.

The regex can be pretty simple: we don't have to care about comments,
(which also use slashes) because stripComments() will have stripped those
already.

This method will replace all string content with simple REGEX#
placeholder text, so we've rid all regular expressions from characters
that may be misinterpreted. Original regex content will be saved in
$this->extracted and after doing all other minifying, we can restore the
original content via restoreRegex()

stripWhitespace($content)   X-Ref
Strip whitespace.

We won't strip *all* whitespace, but as much as possible. The thing that
we'll preserve are newlines we're unsure about.
JavaScript doesn't require statements to be terminated with a semicolon.
It will automatically fix missing semicolons with ASI (automatic semi-
colon insertion) at the end of line causing errors (without semicolon.)

Because it's sometimes hard to tell if a newline is part of a statement
that should be terminated or not, we'll just leave some of them alone.

param: string $content The content to strip the whitespace for
return: string

getOperatorsForRegex(array $operators, $delimiter = '/')   X-Ref
We'll strip whitespace around certain operators with regular expressions.
This will prepare the given array by escaping all characters.

param: string[] $operators
param: string   $delimiter
return: string[]

getKeywordsForRegex(array $keywords, $delimiter = '/')   X-Ref
We'll strip whitespace around certain keywords with regular expressions.
This will prepare the given array by escaping all characters.

param: string[] $keywords
param: string   $delimiter
return: string[]

propertyNotation($content)   X-Ref
Replaces all occurrences of array['key'] by array.key.

param: string $content
return: string

shortenBools($content)   X-Ref
Replaces true & false by !0 and !1.

param: string $content
return: string