efront 3.24.2 → 3.24.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,78 +0,0 @@
1
- var scanner = require("./scanner");
2
- var keywords = require("./keywords");
3
- var strings = require("../basic/strings");
4
- var hasOwnProperty = {}.hasOwnProperty;
5
- var getReadableKey = function ($key, value) {
6
- value = value.replace(/-->/g, '--\\>');
7
- if (!/^[a-z][\w\$]*$/i.test($key)) {
8
- $key = $key.replace(/[^\w\$]+/g, '_');
9
- if ($key.length > 20) $key = $key.slice(0, 4) + $key.slice(-20);
10
- }
11
- $key = $key.replace(/(\d\.?)px/ig, "$1_px");
12
- var id = 0;
13
- while (($key in paramsMap) && paramsMap[$key] !== value || $key in keywords) {
14
- $key = $key.replace(/\d+$/, '') + ++id;
15
- }
16
- if (!hasOwnProperty.call(paramsMap, $key)) {
17
- paramsMap[$key] = value;
18
- }
19
- return $key;
20
- };
21
- var setMatchedConstString = function (k) {
22
-
23
- if (/^(['"])user?\s+strict\1$/i.test(k)) return `"use strict"`;
24
- if (k.length < 3) return k;
25
- k = strings.decode(k);
26
- k = strings.encode(k);
27
- var $key = "str_" + k.replace(/^(['"])([\s\S]*)\1$/g, '$2');
28
- var key = getReadableKey($key, k);
29
- return " " + key + " ";
30
- };
31
- var setMatchedConstRegExp = function (k) {
32
- var $key = "reg_" + k.replace(/^\/([\s\S]*)\/(\w*)$/g, '$1_$2');
33
- $key = getReadableKey($key, k);
34
- return " " + $key + " ";
35
- };
36
- var trimStringLiteral = function (block) {
37
- var block_string = module_string.slice(block.start, block.end);
38
- if (block.type === block.single_quote_scanner || block.type === block.double_quote_scanner) {
39
- return setMatchedConstString(block_string);
40
- }
41
- if (block.type === block.regexp_quote_scanner) {
42
- return setMatchedConstRegExp(block_string);
43
- }
44
- if (block.type === block.template_quote_scanner) {
45
- var { start, end } = block;
46
- if (block.children) {
47
- var res = [];
48
- for (var c of block.children) {
49
- res.push(
50
- module_string.slice(start, c.start),
51
- trimStringLiteral(c)
52
- );
53
- start = c.end;
54
- }
55
- res.push(module_string.slice(start, end));
56
- return res.join('');
57
- }
58
- }
59
- return block_string;
60
- };
61
- var paramsMap = Object.create(null);
62
- var module_string = '';
63
- function breakcode(data, args) {
64
- if (!args) return [data];
65
- module_string = data;
66
- Object.keys(args).forEach(function (key) {
67
- paramsMap[key] = true;
68
- });
69
- var code_blocks = scanner(module_string);
70
- module_string = code_blocks.map(trimStringLiteral).join("");
71
- var res = Object.keys(paramsMap).filter(k => !hasOwnProperty.call(args, k));
72
- var val = res.map(k => paramsMap[k]);
73
- paramsMap = Object.create(null);
74
- data = module_string;
75
- module_string = '';
76
- return [data, res, val];
77
- }
78
- module.exports = breakcode;