main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[79a0317] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | /** @typedef {import("./index.js").MinimizedResult} MinimizedResult */
|
---|
| 4 | /** @typedef {import("./index.js").CustomOptions} CustomOptions */
|
---|
| 5 |
|
---|
| 6 | /**
|
---|
| 7 | * @template T
|
---|
| 8 | * @param {import("./index.js").InternalOptions<T>} options
|
---|
| 9 | * @returns {Promise<MinimizedResult>}
|
---|
| 10 | */
|
---|
| 11 | async function minify(options) {
|
---|
| 12 | const {
|
---|
| 13 | name,
|
---|
| 14 | input,
|
---|
| 15 | inputSourceMap,
|
---|
| 16 | extractComments
|
---|
| 17 | } = options;
|
---|
| 18 | const {
|
---|
| 19 | implementation,
|
---|
| 20 | options: minimizerOptions
|
---|
| 21 | } = options.minimizer;
|
---|
| 22 | return implementation({
|
---|
| 23 | [name]: input
|
---|
| 24 | }, inputSourceMap, minimizerOptions, extractComments);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | /**
|
---|
| 28 | * @param {string} options
|
---|
| 29 | * @returns {Promise<MinimizedResult>}
|
---|
| 30 | */
|
---|
| 31 | async function transform(options) {
|
---|
| 32 | // 'use strict' => this === undefined (Clean Scope)
|
---|
| 33 | // Safer for possible security issues, albeit not critical at all here
|
---|
| 34 | // eslint-disable-next-line no-param-reassign
|
---|
| 35 | const evaluatedOptions =
|
---|
| 36 | /**
|
---|
| 37 | * @template T
|
---|
| 38 | * @type {import("./index.js").InternalOptions<T>}
|
---|
| 39 | * */
|
---|
| 40 |
|
---|
| 41 | // eslint-disable-next-line no-new-func
|
---|
| 42 | new Function("exports", "require", "module", "__filename", "__dirname", `'use strict'\nreturn ${options}`)(exports, require, module, __filename, __dirname);
|
---|
| 43 | return minify(evaluatedOptions);
|
---|
| 44 | }
|
---|
| 45 | module.exports = {
|
---|
| 46 | minify,
|
---|
| 47 | transform
|
---|
| 48 | }; |
---|
Note:
See
TracBrowser
for help on using the repository browser.