Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 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