Verified Commit 79035ac1 authored by Dave Long's avatar Dave Long
Browse files

Issue #3302755 by catch, nod_, xjm, Wim Leers, longwave, alexpott, mfb:...

Issue #3302755 by catch, nod_, xjm, Wim Leers, longwave, alexpott, mfb: On-the-fly JavaScript minification
parent afc9dc2c
Loading
Loading
Loading
Loading
+52 −1
Original line number Diff line number Diff line
@@ -443,7 +443,7 @@
            "dist": {
                "type": "path",
                "url": "core",
                "reference": "938187e9cd9745789a97efca65f1515cd4aed57f"
                "reference": "03111049ab167a24a06da256ed9e8fbb44effcf2"
            },
            "require": {
                "asm89/stack-cors": "^2.1",
@@ -467,6 +467,7 @@
                "guzzlehttp/guzzle": "^7.5",
                "guzzlehttp/psr7": "^2.4",
                "masterminds/html5": "^2.7",
                "mck89/peast": "^1.14",
                "pear/archive_tar": "^1.4.14",
                "php": ">=8.1.0",
                "psr/log": "^3.0",
@@ -1123,6 +1124,56 @@
            },
            "time": "2022-08-18T16:18:26+00:00"
        },
        {
            "name": "mck89/peast",
            "version": "v1.15.0",
            "source": {
                "type": "git",
                "url": "https://github.com/mck89/peast.git",
                "reference": "733cd8f62dcb8239094688063a92766bbfcbf523"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/mck89/peast/zipball/733cd8f62dcb8239094688063a92766bbfcbf523",
                "reference": "733cd8f62dcb8239094688063a92766bbfcbf523",
                "shasum": ""
            },
            "require": {
                "ext-mbstring": "*",
                "php": ">=5.4.0"
            },
            "require-dev": {
                "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
            },
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-master": "1.15.0-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Peast\\": "lib/Peast/",
                    "Peast\\test\\": "test/Peast/"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "BSD-3-Clause"
            ],
            "authors": [
                {
                    "name": "Marco Marchiò",
                    "email": "marco.mm89@gmail.com"
                }
            ],
            "description": "Peast is PHP library that generates AST for JavaScript code",
            "support": {
                "issues": "https://github.com/mck89/peast/issues",
                "source": "https://github.com/mck89/peast/tree/v1.15.0"
            },
            "time": "2022-09-13T15:56:53+00:00"
        },
        {
            "name": "pear/archive_tar",
            "version": "1.4.14",
+1 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
        "guzzlehttp/promises": "~1.5.2",
        "guzzlehttp/psr7": "~2.4.3",
        "masterminds/html5": "~2.7.6",
        "mck89/peast": "~v1.15.0",
        "pear/archive_tar": "~1.4.14",
        "pear/console_getopt": "~v1.4.3",
        "pear/pear-core-minimal": "~v1.10.11",
+2 −1
Original line number Diff line number Diff line
@@ -41,7 +41,8 @@
        "composer/semver": "^3.3",
        "asm89/stack-cors": "^2.1",
        "pear/archive_tar": "^1.4.14",
        "psr/log": "^3.0"
        "psr/log": "^3.0",
        "mck89/peast": "^1.14"
    },
    "conflict": {
        "drush/drush": "<8.1.10"
+8 −3
Original line number Diff line number Diff line
@@ -3,6 +3,9 @@
namespace Drupal\Core\Asset;

use Drupal\Component\Utility\Unicode;
use Peast\Formatter\Compact as CompactFormatter;
use Peast\Peast;
use Peast\Renderer;

/**
 * Optimizes a JavaScript asset.
@@ -30,9 +33,11 @@ public function optimize(array $js_asset) {
    elseif (isset($js_asset['attributes']['charset'])) {
      $data = Unicode::convertToUtf8($data, $js_asset['attributes']['charset']);
    }

    // No-op optimizer: no optimizations are applied to JavaScript assets.
    return $data;
    // Remove comments, whitespace, and optional braces.
    $ast = Peast::latest($data)->parse();
    $renderer = new Renderer();
    $renderer->setFormatter(new CompactFormatter());
    return $renderer->render($ast);
  }

  /**
+1 −0
Original line number Diff line number Diff line
@@ -893,6 +893,7 @@ pathnames
pcre
pcss
pdma
peast
percona
permissionless
persistable
Loading