weapp-tailwindcss 3.0.11 → 3.1.0
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.
- package/dist/cli.js +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/core.d.ts +2 -2
- package/dist/core.js +12 -10
- package/dist/core.mjs +12 -10
- package/dist/gulp.js +2 -2
- package/dist/gulp.mjs +2 -2
- package/dist/{index-DG4lzarS.mjs → index-BatBMY3C.mjs} +7 -7
- package/dist/{index-FotLKQvj.js → index-C9cFs8_u.js} +7 -7
- package/dist/{index-CgOpm8dH.mjs → index-DEWZ8_xX.mjs} +7 -7
- package/dist/{index-BgWX0vrB.js → index-jf-1m663.js} +7 -7
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/handlers.d.ts +9 -2
- package/dist/js/index.d.ts +2 -1
- package/dist/{options-Zf1-GLWG.js → options-AIjWBFPo.js} +133 -50
- package/dist/{options-D8LYG9j8.mjs → options-D6Mza941.mjs} +133 -50
- package/dist/types.d.ts +5 -2
- package/dist/{v5-eVqDacrp.js → v5-BV64BMJS.js} +7 -7
- package/dist/{v5-B8nkZNYC.mjs → v5-CH-EIloz.mjs} +7 -7
- package/dist/vite.js +2 -2
- package/dist/vite.mjs +2 -2
- package/dist/webpack.js +2 -2
- package/dist/webpack.mjs +2 -2
- package/dist/webpack4.js +7 -7
- package/dist/webpack4.mjs +7 -7
- package/dist/wxml/utils.d.ts +2 -2
- package/package.json +26 -21
package/dist/cli.js
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import semver from 'semver';
|
|
2
|
-
import { g as getOptions, a as createPatch } from './options-
|
|
2
|
+
import { g as getOptions, a as createPatch } from './options-D6Mza941.mjs';
|
|
3
3
|
import { W as WEAPP_TW_REQUIRED_NODE_VERSION } from './index-DKNUquoz.mjs';
|
|
4
4
|
import 'magic-string';
|
|
5
5
|
import './replace.mjs';
|
package/dist/core.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { UserDefinedOptions } from "./types";
|
|
2
2
|
export declare function createContext(options?: UserDefinedOptions): {
|
|
3
3
|
transformWxss: (rawCss: string) => Promise<string>;
|
|
4
|
-
transformWxml: (rawWxml: string) => string
|
|
4
|
+
transformWxml: (rawWxml: string) => Promise<string>;
|
|
5
5
|
transformJs: (rawJs: string, options?: {
|
|
6
6
|
runtimeSet?: Set<string> | undefined;
|
|
7
|
-
}) => string
|
|
7
|
+
}) => Promise<string>;
|
|
8
8
|
};
|
package/dist/core.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var options = require('./options-
|
|
5
|
+
var options = require('./options-AIjWBFPo.js');
|
|
6
6
|
require('magic-string');
|
|
7
7
|
require('./replace.js');
|
|
8
8
|
require('@weapp-core/escape');
|
|
@@ -43,15 +43,17 @@ function createContext(options$1 = {}) {
|
|
|
43
43
|
return code;
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
function transformJs(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
function transformJs(rawJs_1) {
|
|
47
|
+
return options.__awaiter(this, arguments, void 0, function* (rawJs, options = {}) {
|
|
48
|
+
runtimeSet =
|
|
49
|
+
options && options.runtimeSet
|
|
50
|
+
? options.runtimeSet
|
|
51
|
+
: twPatcher.getClassSet({
|
|
52
|
+
basedir: tailwindcssBasedir
|
|
53
|
+
});
|
|
54
|
+
const { code } = yield jsHandler(rawJs, runtimeSet);
|
|
55
|
+
return code;
|
|
56
|
+
});
|
|
55
57
|
}
|
|
56
58
|
function transformWxml(rawWxml) {
|
|
57
59
|
const code = templateHandler(rawWxml, {
|
package/dist/core.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getOptions, c as createTailwindcssPatcher, _ as __awaiter } from './options-
|
|
1
|
+
import { g as getOptions, c as createTailwindcssPatcher, _ as __awaiter } from './options-D6Mza941.mjs';
|
|
2
2
|
import 'magic-string';
|
|
3
3
|
import './replace.mjs';
|
|
4
4
|
import '@weapp-core/escape';
|
|
@@ -39,15 +39,17 @@ function createContext(options = {}) {
|
|
|
39
39
|
return code;
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
function transformJs(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
42
|
+
function transformJs(rawJs_1) {
|
|
43
|
+
return __awaiter(this, arguments, void 0, function* (rawJs, options = {}) {
|
|
44
|
+
runtimeSet =
|
|
45
|
+
options && options.runtimeSet
|
|
46
|
+
? options.runtimeSet
|
|
47
|
+
: twPatcher.getClassSet({
|
|
48
|
+
basedir: tailwindcssBasedir
|
|
49
|
+
});
|
|
50
|
+
const { code } = yield jsHandler(rawJs, runtimeSet);
|
|
51
|
+
return code;
|
|
52
|
+
});
|
|
51
53
|
}
|
|
52
54
|
function transformWxml(rawWxml) {
|
|
53
55
|
const code = templateHandler(rawWxml, {
|
package/dist/gulp.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var index = require('./index-
|
|
6
|
-
require('./options-
|
|
5
|
+
var index = require('./index-C9cFs8_u.js');
|
|
6
|
+
require('./options-AIjWBFPo.js');
|
|
7
7
|
require('magic-string');
|
|
8
8
|
require('./replace.js');
|
|
9
9
|
require('@weapp-core/escape');
|
package/dist/gulp.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { c as createPlugins } from './index-
|
|
2
|
-
import './options-
|
|
1
|
+
export { c as createPlugins } from './index-DEWZ8_xX.mjs';
|
|
2
|
+
import './options-D6Mza941.mjs';
|
|
3
3
|
import 'magic-string';
|
|
4
4
|
import './replace.mjs';
|
|
5
5
|
import '@weapp-core/escape';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getOptions, c as createTailwindcssPatcher, _ as __awaiter } from './options-
|
|
1
|
+
import { g as getOptions, c as createTailwindcssPatcher, _ as __awaiter } from './options-D6Mza941.mjs';
|
|
2
2
|
import { v as vitePluginName } from './index-DKNUquoz.mjs';
|
|
3
3
|
import { g as getGroupedEntries } from './defaults-CBb6_9nJ.mjs';
|
|
4
4
|
import { c as createDebug } from './index-CsZGfl55.mjs';
|
|
@@ -46,8 +46,8 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
46
46
|
else {
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
|
-
}, () => {
|
|
50
|
-
originalSource.source = templateHandler(oldVal, {
|
|
49
|
+
}, () => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
originalSource.source = yield templateHandler(oldVal, {
|
|
51
51
|
runtimeSet
|
|
52
52
|
});
|
|
53
53
|
onUpdate(file, oldVal, originalSource.source);
|
|
@@ -57,7 +57,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
57
57
|
key: file,
|
|
58
58
|
source: originalSource.source
|
|
59
59
|
};
|
|
60
|
-
});
|
|
60
|
+
}));
|
|
61
61
|
}
|
|
62
62
|
debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
|
|
63
63
|
}
|
|
@@ -77,10 +77,10 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
77
77
|
else {
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
|
-
}, () => {
|
|
80
|
+
}, () => __awaiter(this, void 0, void 0, function* () {
|
|
81
81
|
const mapFilename = file + '.map';
|
|
82
82
|
const hasMap = Boolean(bundle[mapFilename]);
|
|
83
|
-
const { code, map } = jsHandler(rawSource, runtimeSet, {
|
|
83
|
+
const { code, map } = yield jsHandler(rawSource, runtimeSet, {
|
|
84
84
|
generateMap: hasMap
|
|
85
85
|
});
|
|
86
86
|
originalSource.code = code;
|
|
@@ -94,7 +94,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
94
94
|
key: file,
|
|
95
95
|
source: code
|
|
96
96
|
};
|
|
97
|
-
});
|
|
97
|
+
}));
|
|
98
98
|
}
|
|
99
99
|
debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
|
|
100
100
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var options = require('./options-
|
|
3
|
+
var options = require('./options-AIjWBFPo.js');
|
|
4
4
|
var stream = require('node:stream');
|
|
5
5
|
var index = require('./index-DyK5Vd4R.js');
|
|
6
6
|
|
|
@@ -75,15 +75,15 @@ function createPlugins(options$1 = {}) {
|
|
|
75
75
|
else {
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
78
|
-
}, () => {
|
|
79
|
-
const { code } = jsHandler(rawSource, runtimeSet);
|
|
78
|
+
}, () => options.__awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const { code } = yield jsHandler(rawSource, runtimeSet);
|
|
80
80
|
file.contents = Buffer.from(code);
|
|
81
81
|
debug('js handle: %s', file.path);
|
|
82
82
|
return {
|
|
83
83
|
key: file.path,
|
|
84
84
|
source: code
|
|
85
85
|
};
|
|
86
|
-
});
|
|
86
|
+
}));
|
|
87
87
|
}
|
|
88
88
|
callback(error, file);
|
|
89
89
|
});
|
|
@@ -109,8 +109,8 @@ function createPlugins(options$1 = {}) {
|
|
|
109
109
|
else {
|
|
110
110
|
return false;
|
|
111
111
|
}
|
|
112
|
-
}, () => {
|
|
113
|
-
const code = templateHandler(rawSource, {
|
|
112
|
+
}, () => options.__awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const code = yield templateHandler(rawSource, {
|
|
114
114
|
runtimeSet
|
|
115
115
|
});
|
|
116
116
|
file.contents = Buffer.from(code);
|
|
@@ -119,7 +119,7 @@ function createPlugins(options$1 = {}) {
|
|
|
119
119
|
key: file.path,
|
|
120
120
|
source: code
|
|
121
121
|
};
|
|
122
|
-
});
|
|
122
|
+
}));
|
|
123
123
|
}
|
|
124
124
|
callback(error, file);
|
|
125
125
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as getOptions, c as createTailwindcssPatcher, _ as __awaiter } from './options-
|
|
1
|
+
import { g as getOptions, c as createTailwindcssPatcher, _ as __awaiter } from './options-D6Mza941.mjs';
|
|
2
2
|
import stream from 'node:stream';
|
|
3
3
|
import { c as createDebug } from './index-CsZGfl55.mjs';
|
|
4
4
|
|
|
@@ -69,15 +69,15 @@ function createPlugins(options = {}) {
|
|
|
69
69
|
else {
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
|
-
}, () => {
|
|
73
|
-
const { code } = jsHandler(rawSource, runtimeSet);
|
|
72
|
+
}, () => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const { code } = yield jsHandler(rawSource, runtimeSet);
|
|
74
74
|
file.contents = Buffer.from(code);
|
|
75
75
|
debug('js handle: %s', file.path);
|
|
76
76
|
return {
|
|
77
77
|
key: file.path,
|
|
78
78
|
source: code
|
|
79
79
|
};
|
|
80
|
-
});
|
|
80
|
+
}));
|
|
81
81
|
}
|
|
82
82
|
callback(error, file);
|
|
83
83
|
});
|
|
@@ -103,8 +103,8 @@ function createPlugins(options = {}) {
|
|
|
103
103
|
else {
|
|
104
104
|
return false;
|
|
105
105
|
}
|
|
106
|
-
}, () => {
|
|
107
|
-
const code = templateHandler(rawSource, {
|
|
106
|
+
}, () => __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const code = yield templateHandler(rawSource, {
|
|
108
108
|
runtimeSet
|
|
109
109
|
});
|
|
110
110
|
file.contents = Buffer.from(code);
|
|
@@ -113,7 +113,7 @@ function createPlugins(options = {}) {
|
|
|
113
113
|
key: file.path,
|
|
114
114
|
source: code
|
|
115
115
|
};
|
|
116
|
-
});
|
|
116
|
+
}));
|
|
117
117
|
}
|
|
118
118
|
callback(error, file);
|
|
119
119
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var options = require('./options-
|
|
3
|
+
var options = require('./options-AIjWBFPo.js');
|
|
4
4
|
var index = require('./index-CarwQa1I.js');
|
|
5
5
|
var defaults = require('./defaults-BT3A8Rzc.js');
|
|
6
6
|
var index$1 = require('./index-DyK5Vd4R.js');
|
|
@@ -48,8 +48,8 @@ function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
|
|
|
48
48
|
else {
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
|
-
}, () => {
|
|
52
|
-
originalSource.source = templateHandler(oldVal, {
|
|
51
|
+
}, () => options.__awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
originalSource.source = yield templateHandler(oldVal, {
|
|
53
53
|
runtimeSet
|
|
54
54
|
});
|
|
55
55
|
onUpdate(file, oldVal, originalSource.source);
|
|
@@ -59,7 +59,7 @@ function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
|
|
|
59
59
|
key: file,
|
|
60
60
|
source: originalSource.source
|
|
61
61
|
};
|
|
62
|
-
});
|
|
62
|
+
}));
|
|
63
63
|
}
|
|
64
64
|
debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
|
|
65
65
|
}
|
|
@@ -79,10 +79,10 @@ function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
|
|
|
79
79
|
else {
|
|
80
80
|
return false;
|
|
81
81
|
}
|
|
82
|
-
}, () => {
|
|
82
|
+
}, () => options.__awaiter(this, void 0, void 0, function* () {
|
|
83
83
|
const mapFilename = file + '.map';
|
|
84
84
|
const hasMap = Boolean(bundle[mapFilename]);
|
|
85
|
-
const { code, map } = jsHandler(rawSource, runtimeSet, {
|
|
85
|
+
const { code, map } = yield jsHandler(rawSource, runtimeSet, {
|
|
86
86
|
generateMap: hasMap
|
|
87
87
|
});
|
|
88
88
|
originalSource.code = code;
|
|
@@ -96,7 +96,7 @@ function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
|
|
|
96
96
|
key: file,
|
|
97
97
|
source: code
|
|
98
98
|
};
|
|
99
|
-
});
|
|
99
|
+
}));
|
|
100
100
|
}
|
|
101
101
|
debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
|
|
102
102
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var v5 = require('./v5-
|
|
6
|
-
var index = require('./index-
|
|
7
|
-
var index$1 = require('./index-
|
|
8
|
-
require('./options-
|
|
5
|
+
var v5 = require('./v5-BV64BMJS.js');
|
|
6
|
+
var index = require('./index-jf-1m663.js');
|
|
7
|
+
var index$1 = require('./index-C9cFs8_u.js');
|
|
8
|
+
require('./options-AIjWBFPo.js');
|
|
9
9
|
require('magic-string');
|
|
10
10
|
require('./replace.js');
|
|
11
11
|
require('@weapp-core/escape');
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { U as UnifiedWebpackPluginV5 } from './v5-
|
|
2
|
-
export { U as UnifiedViteWeappTailwindcssPlugin } from './index-
|
|
3
|
-
export { c as createPlugins } from './index-
|
|
4
|
-
import './options-
|
|
1
|
+
export { U as UnifiedWebpackPluginV5 } from './v5-CH-EIloz.mjs';
|
|
2
|
+
export { U as UnifiedViteWeappTailwindcssPlugin } from './index-BatBMY3C.mjs';
|
|
3
|
+
export { c as createPlugins } from './index-DEWZ8_xX.mjs';
|
|
4
|
+
import './options-D6Mza941.mjs';
|
|
5
5
|
import 'magic-string';
|
|
6
6
|
import './replace.mjs';
|
|
7
7
|
import '@weapp-core/escape';
|
package/dist/js/handlers.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type { StringLiteral, TemplateElement } from '@babel/types';
|
|
2
1
|
import MagicString from 'magic-string';
|
|
3
2
|
import type { IJsHandlerOptions } from "../types";
|
|
4
|
-
|
|
3
|
+
interface ReplaceNode {
|
|
4
|
+
leadingComments?: {
|
|
5
|
+
value: string;
|
|
6
|
+
}[] | null | undefined;
|
|
7
|
+
start?: number | null;
|
|
8
|
+
end?: number | null;
|
|
9
|
+
}
|
|
10
|
+
export declare function replaceHandleValue(str: string, node: ReplaceNode, options: IJsHandlerOptions, ms: MagicString, offset?: number): string;
|
|
11
|
+
export {};
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { CreateJsHandlerOptions, IJsHandlerOptions, JsHandlerResult } from "../types";
|
|
2
2
|
export declare function jsHandler(rawSource: string, options: IJsHandlerOptions): JsHandlerResult;
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function jsHandlerAsync(rawSource: string, options: IJsHandlerOptions): Promise<JsHandlerResult>;
|
|
4
|
+
export declare function createJsHandler(options: CreateJsHandlerOptions): (rawSource: string, set: Set<string>, options?: CreateJsHandlerOptions) => JsHandlerResult | Promise<JsHandlerResult>;
|
|
@@ -91,12 +91,23 @@ const splitCode = (code, allowDoubleQuotes = false) => {
|
|
|
91
91
|
return code.split(splitter).filter((element) => isValidSelector(element));
|
|
92
92
|
};
|
|
93
93
|
|
|
94
|
+
function decodeUnicode(s) {
|
|
95
|
+
return unescape(s.replaceAll(/\\(u[\dA-Fa-f]{4})/gm, '%$1'));
|
|
96
|
+
}
|
|
94
97
|
function replaceHandleValue(str, node, options, ms, offset = 0) {
|
|
95
|
-
const { classNameSet: set, escapeMap, mangleContext: ctx, needEscaped = false, jsPreserveClass, arbitraryValues, always } = options;
|
|
98
|
+
const { classNameSet: set, escapeMap, mangleContext: ctx, needEscaped = false, jsPreserveClass, arbitraryValues, always, unescapeUnicode } = options;
|
|
96
99
|
const allowDoubleQuotes = arbitraryValues === null || arbitraryValues === void 0 ? void 0 : arbitraryValues.allowDoubleQuotes;
|
|
97
100
|
const arr = splitCode(str, allowDoubleQuotes);
|
|
98
101
|
let rawStr = str;
|
|
99
|
-
|
|
102
|
+
let needDecodeUnicode = false;
|
|
103
|
+
if (unescapeUnicode && rawStr.includes('\\')) {
|
|
104
|
+
rawStr = decodeUnicode(rawStr);
|
|
105
|
+
needDecodeUnicode = true;
|
|
106
|
+
}
|
|
107
|
+
for (let v of arr) {
|
|
108
|
+
if (needDecodeUnicode && v.includes('\\')) {
|
|
109
|
+
v = decodeUnicode(v);
|
|
110
|
+
}
|
|
100
111
|
if (always || (set && set.has(v) && !(jsPreserveClass === null || jsPreserveClass === void 0 ? void 0 : jsPreserveClass(v)))) {
|
|
101
112
|
let ignoreFlag = false;
|
|
102
113
|
if (Array.isArray(node.leadingComments)) {
|
|
@@ -130,7 +141,46 @@ function isEvalPath(p) {
|
|
|
130
141
|
}
|
|
131
142
|
return false;
|
|
132
143
|
}
|
|
144
|
+
function getAstGrep() {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
try {
|
|
147
|
+
const { js } = yield import('@ast-grep/napi');
|
|
148
|
+
return js;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
console.warn('请先安装 `@ast-grep/napi` , 安装完成后再尝试运行!');
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function astGrepUpdateString(ast, options, ms) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
const js = yield getAstGrep();
|
|
159
|
+
const nodes = ast.findAll(js.kind('string'));
|
|
160
|
+
for (const node of nodes) {
|
|
161
|
+
const range = node.range();
|
|
162
|
+
const text = node.text();
|
|
163
|
+
replaceHandleValue(text.slice(1, -1), {
|
|
164
|
+
end: range.end.index - 1,
|
|
165
|
+
start: range.start.index + 1
|
|
166
|
+
}, Object.assign(Object.assign({}, options), { unescapeUnicode: true }), ms, 0);
|
|
167
|
+
}
|
|
168
|
+
const templateNodes = ast.findAll(js.kind('template_string'));
|
|
169
|
+
for (const node of templateNodes) {
|
|
170
|
+
const fragments = node.findAll(js.kind('string_fragment'));
|
|
171
|
+
for (const fragment of fragments) {
|
|
172
|
+
const range = fragment.range();
|
|
173
|
+
const text = fragment.text();
|
|
174
|
+
replaceHandleValue(text, {
|
|
175
|
+
end: range.end.index,
|
|
176
|
+
start: range.start.index
|
|
177
|
+
}, Object.assign(Object.assign({}, options), { unescapeUnicode: true }), ms, 0);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
133
182
|
function jsHandler(rawSource, options) {
|
|
183
|
+
const ms = new MagicString__default["default"](rawSource);
|
|
134
184
|
let ast;
|
|
135
185
|
try {
|
|
136
186
|
ast = parser.parse(rawSource, {
|
|
@@ -142,8 +192,7 @@ function jsHandler(rawSource, options) {
|
|
|
142
192
|
code: rawSource
|
|
143
193
|
};
|
|
144
194
|
}
|
|
145
|
-
const
|
|
146
|
-
const ropt = {
|
|
195
|
+
const traverseOptions = {
|
|
147
196
|
StringLiteral: {
|
|
148
197
|
enter(p) {
|
|
149
198
|
var _a;
|
|
@@ -204,14 +253,33 @@ function jsHandler(rawSource, options) {
|
|
|
204
253
|
}
|
|
205
254
|
}
|
|
206
255
|
};
|
|
207
|
-
traverse__default["default"](ast,
|
|
208
|
-
|
|
256
|
+
traverse__default["default"](ast, traverseOptions);
|
|
257
|
+
return {
|
|
209
258
|
code: ms.toString()
|
|
210
259
|
};
|
|
211
|
-
|
|
260
|
+
}
|
|
261
|
+
function jsHandlerAsync(rawSource, options) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
const ms = new MagicString__default["default"](rawSource);
|
|
264
|
+
const js = yield getAstGrep();
|
|
265
|
+
let ast;
|
|
266
|
+
try {
|
|
267
|
+
const root = yield js.parseAsync(rawSource);
|
|
268
|
+
ast = root.root();
|
|
269
|
+
}
|
|
270
|
+
catch (_a) {
|
|
271
|
+
return {
|
|
272
|
+
code: rawSource
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
yield astGrepUpdateString(ast, options, ms);
|
|
276
|
+
return {
|
|
277
|
+
code: ms.toString()
|
|
278
|
+
};
|
|
279
|
+
});
|
|
212
280
|
}
|
|
213
281
|
function createJsHandler(options) {
|
|
214
|
-
const { mangleContext, arbitraryValues, escapeMap, jsPreserveClass, generateMap } = options;
|
|
282
|
+
const { mangleContext, arbitraryValues, escapeMap, jsPreserveClass, generateMap, jsAstTool } = options;
|
|
215
283
|
return (rawSource, set, options) => {
|
|
216
284
|
const opts = defaults.defuOverrideArray(options, {
|
|
217
285
|
classNameSet: set,
|
|
@@ -219,8 +287,12 @@ function createJsHandler(options) {
|
|
|
219
287
|
arbitraryValues,
|
|
220
288
|
mangleContext,
|
|
221
289
|
jsPreserveClass,
|
|
222
|
-
generateMap
|
|
290
|
+
generateMap,
|
|
291
|
+
jsAstTool
|
|
223
292
|
});
|
|
293
|
+
if (opts.jsAstTool === 'ast-grep') {
|
|
294
|
+
return jsHandlerAsync(rawSource, opts);
|
|
295
|
+
}
|
|
224
296
|
return jsHandler(rawSource, opts);
|
|
225
297
|
};
|
|
226
298
|
}
|
|
@@ -338,53 +410,63 @@ function isPropsMatch(props, attr) {
|
|
|
338
410
|
}
|
|
339
411
|
}
|
|
340
412
|
function customTemplateHandler(rawSource, options) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
update();
|
|
355
|
-
}
|
|
356
|
-
for (const [t, props] of customAttributesEntities) {
|
|
357
|
-
if (t === '*') {
|
|
358
|
-
if (isPropsMatch(props, name)) {
|
|
359
|
-
update();
|
|
360
|
-
}
|
|
413
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
414
|
+
const { customAttributesEntities = [], disabledDefaultTemplateHandler, inlineWxs, runtimeSet, jsHandler } = options !== null && options !== void 0 ? options : {};
|
|
415
|
+
const s = new MagicString__default["default"](rawSource);
|
|
416
|
+
let tag = '';
|
|
417
|
+
const wxsArray = [];
|
|
418
|
+
const parser = new htmlparser2.Parser({
|
|
419
|
+
onopentagname(name) {
|
|
420
|
+
tag = name;
|
|
421
|
+
},
|
|
422
|
+
onattribute(name, value, quote) {
|
|
423
|
+
if (value) {
|
|
424
|
+
function update() {
|
|
425
|
+
s.update(parser.startIndex + name.length + 2, parser.endIndex - 1, templateReplacer(value, Object.assign(Object.assign({}, options), { quote })));
|
|
361
426
|
}
|
|
362
|
-
|
|
363
|
-
|
|
427
|
+
if (!disabledDefaultTemplateHandler && (name === 'class' || name === 'hover-class' || name === 'virtualHostClass' || name === 'virtualhostclass')) {
|
|
428
|
+
update();
|
|
429
|
+
}
|
|
430
|
+
for (const [t, props] of customAttributesEntities) {
|
|
431
|
+
if (t === '*') {
|
|
432
|
+
if (isPropsMatch(props, name)) {
|
|
433
|
+
update();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
else if (typeof t === 'string') {
|
|
437
|
+
if (t === tag && isPropsMatch(props, name)) {
|
|
438
|
+
update();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
else if (regTest(t, tag) && isPropsMatch(props, name)) {
|
|
364
442
|
update();
|
|
365
443
|
}
|
|
366
444
|
}
|
|
367
|
-
else if (regTest(t, tag) && isPropsMatch(props, name)) {
|
|
368
|
-
update();
|
|
369
|
-
}
|
|
370
445
|
}
|
|
446
|
+
},
|
|
447
|
+
ontext(data) {
|
|
448
|
+
if (inlineWxs && tag === 'wxs') {
|
|
449
|
+
wxsArray.push({
|
|
450
|
+
data,
|
|
451
|
+
endIndex: parser.endIndex + 1,
|
|
452
|
+
startIndex: parser.startIndex
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
onclosetag() {
|
|
457
|
+
tag = '';
|
|
371
458
|
}
|
|
372
|
-
},
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
tag = '';
|
|
459
|
+
}, {
|
|
460
|
+
xmlMode: true
|
|
461
|
+
});
|
|
462
|
+
parser.write(s.original);
|
|
463
|
+
parser.end();
|
|
464
|
+
for (const { data, endIndex, startIndex } of wxsArray) {
|
|
465
|
+
const { code } = yield jsHandler(data, runtimeSet);
|
|
466
|
+
s.update(startIndex, endIndex, code);
|
|
381
467
|
}
|
|
382
|
-
|
|
383
|
-
xmlMode: true
|
|
468
|
+
return s.toString();
|
|
384
469
|
});
|
|
385
|
-
parser.write(s.original);
|
|
386
|
-
parser.end();
|
|
387
|
-
return s.toString();
|
|
388
470
|
}
|
|
389
471
|
function createTemplateHandler(options = {}) {
|
|
390
472
|
return (rawSource, opt = {}) => {
|
|
@@ -683,7 +765,7 @@ function getOptions(options = {}) {
|
|
|
683
765
|
options.customReplaceDictionary = escape$1.SimpleMappingChars2String;
|
|
684
766
|
}
|
|
685
767
|
const result = defaults.defuOverrideArray(options, defaults.defaultOptions, {});
|
|
686
|
-
const { cssPreflight, customRuleCallback, cssPreflightRange, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope, jsPreserveClass, disabledDefaultTemplateHandler, cssSelectorReplacement, rem2rpx, cache } = result;
|
|
768
|
+
const { cssPreflight, customRuleCallback, cssPreflightRange, customAttributes, customReplaceDictionary, supportCustomLengthUnitsPatch, arbitraryValues, cssChildCombinatorReplaceValue, inlineWxs, injectAdditionalCssVarScope, jsPreserveClass, disabledDefaultTemplateHandler, cssSelectorReplacement, rem2rpx, cache, jsAstTool } = result;
|
|
687
769
|
result.escapeMap = customReplaceDictionary;
|
|
688
770
|
const cssInjectPreflight = createInjectPreflight(cssPreflight);
|
|
689
771
|
const customAttributesEntities = defaults.isMap(options.customAttributes)
|
|
@@ -709,7 +791,8 @@ function getOptions(options = {}) {
|
|
|
709
791
|
mangleContext,
|
|
710
792
|
arbitraryValues,
|
|
711
793
|
jsPreserveClass,
|
|
712
|
-
generateMap: true
|
|
794
|
+
generateMap: true,
|
|
795
|
+
jsAstTool
|
|
713
796
|
});
|
|
714
797
|
result.jsHandler = jsHandler;
|
|
715
798
|
const templateHandler = createTemplateHandler({
|