weapp-tailwindcss 4.12.0 → 5.0.0-next.1
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/babel/index.d.ts +3 -0
- package/dist/bundlers/gulp/index.d.ts +7 -0
- package/dist/bundlers/shared/cache.d.ts +16 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +4 -0
- package/dist/bundlers/shared/css-imports.d.ts +8 -0
- package/dist/bundlers/shared/generator-candidates.d.ts +5 -0
- package/dist/bundlers/shared/generator-css.d.ts +41 -0
- package/dist/bundlers/shared/module-graph.d.ts +5 -0
- package/dist/bundlers/shared/run-tasks.d.ts +2 -0
- package/dist/bundlers/vite/bundle-entries.d.ts +14 -0
- package/dist/bundlers/vite/bundle-state.d.ts +43 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +19 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +20 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +21 -0
- package/dist/bundlers/vite/index.d.ts +3 -0
- package/dist/bundlers/vite/js-precheck.d.ts +1 -0
- package/dist/bundlers/vite/query.d.ts +15 -0
- package/dist/bundlers/vite/resolve-app-type.d.ts +2 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +11 -0
- package/dist/bundlers/vite/runtime-affecting-signature.d.ts +2 -0
- package/dist/bundlers/vite/utils.d.ts +9 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +20 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +14 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +15 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +9 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +17 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +19 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +9 -0
- package/dist/bundlers/webpack/index.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +12 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +11 -0
- package/dist/bundlers/webpack/shared/css-imports.d.ts +6 -0
- package/dist/bundlers/webpack/shared/loader-anchors.d.ts +8 -0
- package/dist/cache/index.d.ts +38 -0
- package/dist/cache/md5.d.ts +1 -0
- package/dist/chunk-8l464Juk.js +28 -0
- package/dist/cli/config.d.ts +5 -0
- package/dist/cli/context.d.ts +16 -0
- package/dist/cli/doctor/constants.d.ts +7 -0
- package/dist/cli/doctor/types.d.ts +31 -0
- package/dist/cli/doctor.d.ts +4 -0
- package/dist/cli/helpers/options/format.d.ts +2 -0
- package/dist/cli/helpers/options/parse.d.ts +3 -0
- package/dist/cli/helpers/options/resolve.d.ts +1 -0
- package/dist/cli/helpers/options.d.ts +3 -0
- package/dist/cli/helpers/patch-cwd.d.ts +1 -0
- package/dist/cli/helpers.d.ts +5 -0
- package/dist/cli/mount-options/patch-status.d.ts +2 -0
- package/dist/cli/mount-options.d.ts +2 -0
- package/dist/cli/patch-options.d.ts +6 -0
- package/dist/cli/tokens.d.ts +4 -0
- package/dist/cli/types.d.ts +17 -0
- package/dist/cli/vscode-entry.d.ts +14 -0
- package/dist/cli/workspace/package-dirs.d.ts +3 -0
- package/dist/cli/workspace/patch-package.d.ts +3 -0
- package/dist/cli/workspace/patch-utils.d.ts +3 -0
- package/dist/cli/workspace/types.d.ts +11 -0
- package/dist/cli/workspace/workspace-globs.d.ts +2 -0
- package/dist/cli/workspace/workspace-io.d.ts +1 -0
- package/dist/cli/workspace/workspace-lock.d.ts +1 -0
- package/dist/cli/workspace.d.ts +2 -0
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +2425 -3524
- package/dist/cli.mjs +2402 -3505
- package/dist/constants-B-_T5UnW.mjs +44 -0
- package/dist/constants-p1dyh1x1.js +73 -0
- package/dist/constants.d.ts +13 -0
- package/dist/context/compiler-context-cache.d.ts +3 -0
- package/dist/context/custom-attributes.d.ts +2 -0
- package/dist/context/handlers.d.ts +6 -0
- package/dist/context/index.d.ts +7 -0
- package/dist/context/logger.d.ts +4 -0
- package/dist/context/tailwindcss/basedir.d.ts +1 -0
- package/dist/context/tailwindcss/rax.d.ts +2 -0
- package/dist/context/tailwindcss.d.ts +4 -0
- package/dist/context/workspace.d.ts +3 -0
- package/dist/core.d.ts +5 -21
- package/dist/core.js +138 -180
- package/dist/core.mjs +135 -180
- package/dist/css-imports-BbrbluP9.js +177 -0
- package/dist/css-imports-CSdPq_Sc.mjs +128 -0
- package/dist/css-macro/constants.d.ts +14 -0
- package/dist/css-macro/index.d.ts +15 -0
- package/dist/css-macro/postcss.d.ts +3 -7
- package/dist/css-macro/postcss.js +44 -58
- package/dist/css-macro/postcss.mjs +44 -56
- package/dist/css-macro.d.ts +1 -20
- package/dist/css-macro.js +37 -50
- package/dist/css-macro.mjs +33 -47
- package/dist/debug/index.d.ts +5 -0
- package/dist/defaults.d.ts +2 -11
- package/dist/defaults.js +132 -8
- package/dist/defaults.mjs +128 -7
- package/dist/escape.js +31 -54
- package/dist/escape.mjs +18 -25
- package/dist/experimental/index.d.ts +2 -0
- package/dist/experimental/oxc/ast-utils.d.ts +30 -0
- package/dist/experimental/oxc/index.d.ts +2 -0
- package/dist/experimental/oxc/module-specifiers.d.ts +2 -0
- package/dist/experimental/shared/cache.d.ts +3 -0
- package/dist/experimental/shared/transform.d.ts +3 -0
- package/dist/experimental/shared.d.ts +8 -0
- package/dist/experimental/swc/ast-utils.d.ts +30 -0
- package/dist/experimental/swc/index.d.ts +2 -0
- package/dist/experimental/swc/module-specifiers.d.ts +2 -0
- package/dist/generator/index.d.ts +11 -0
- package/dist/generator/options.d.ts +15 -0
- package/dist/generator/types.d.ts +19 -0
- package/dist/generator-CZ-JXw6T.js +492 -0
- package/dist/generator-Dwxgra97.mjs +399 -0
- package/dist/generator-css-CnYjiMrD.js +1084 -0
- package/dist/generator-css-DhPFjSzK.mjs +1057 -0
- package/dist/generator.d.ts +1 -0
- package/dist/generator.js +19 -0
- package/dist/generator.mjs +2 -0
- package/dist/gulp.d.ts +4 -24
- package/dist/gulp.js +271 -13
- package/dist/gulp.mjs +263 -13
- package/dist/index.d.ts +8 -15
- package/dist/index.js +12 -24
- package/dist/index.mjs +6 -24
- package/dist/js/JsTokenUpdater.d.ts +14 -0
- package/dist/js/ModuleGraph.d.ts +18 -0
- package/dist/js/NodePathWalker.d.ts +33 -0
- package/dist/js/babel/parse.d.ts +9 -0
- package/dist/js/babel/process.d.ts +4 -0
- package/dist/js/babel.d.ts +13 -0
- package/dist/js/class-context.d.ts +3 -0
- package/dist/js/evalTransforms.d.ts +7 -0
- package/dist/js/handlers.d.ts +5 -0
- package/dist/js/index.d.ts +4 -0
- package/dist/js/module-graph/ignored-exports.d.ts +18 -0
- package/dist/js/module-graph/types.d.ts +17 -0
- package/dist/js/node-path-walker/export-handlers.d.ts +12 -0
- package/dist/js/node-path-walker/import-tokens.d.ts +24 -0
- package/dist/js/precheck.d.ts +2 -0
- package/dist/js/sourceAnalysis.d.ts +17 -0
- package/dist/js/syntax.d.ts +10 -0
- package/dist/js/taggedTemplateIgnore.d.ts +13 -0
- package/dist/js/types.d.ts +11 -0
- package/dist/lightningcss/index.d.ts +8 -0
- package/dist/lightningcss/style-handler/options.d.ts +3 -0
- package/dist/lightningcss/style-handler/selector-transform.d.ts +10 -0
- package/dist/lightningcss/style-handler/selector-utils.d.ts +10 -0
- package/dist/lightningcss/style-handler.d.ts +17 -0
- package/dist/loader-anchors-DvwgIYdA.mjs +205 -0
- package/dist/loader-anchors-cprm4Klq.js +273 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger-BZ45DZJT.js +1003 -0
- package/dist/logger-BoVx1Dbt.mjs +935 -0
- package/dist/patcher-options-6gJN2EXy.js +115 -0
- package/dist/patcher-options-DQfR5xxT.mjs +92 -0
- package/dist/postcss-html-transform.d.ts +3 -3
- package/dist/postcss-html-transform.js +7 -10
- package/dist/postcss-html-transform.mjs +3 -6
- package/dist/postcss.d.ts +15 -0
- package/dist/postcss.js +278 -0
- package/dist/postcss.mjs +268 -0
- package/dist/presets/hbuilderx.d.ts +4 -0
- package/dist/presets/index.d.ts +3 -0
- package/dist/presets/shared.d.ts +10 -0
- package/dist/presets/taro.d.ts +4 -0
- package/dist/presets/uni-app-x.d.ts +16 -0
- package/dist/presets/uni-app.d.ts +4 -0
- package/dist/presets.d.ts +1 -76
- package/dist/presets.js +115 -163
- package/dist/presets.mjs +107 -163
- package/dist/recorder-B_XyZ576.mjs +2763 -0
- package/dist/recorder-rn_2v_nd.js +2878 -0
- package/dist/reset/index.d.ts +2 -0
- package/dist/reset.d.ts +1 -4
- package/dist/reset.js +19 -8
- package/dist/reset.mjs +2 -8
- package/dist/shared/classname-transform.d.ts +14 -0
- package/dist/shared/mpx.d.ts +7 -0
- package/dist/shared/tailwindcss-css-redirect.d.ts +1 -0
- package/dist/tailwindcss/index.d.ts +11 -0
- package/dist/tailwindcss/miniprogram.d.ts +1 -0
- package/dist/tailwindcss/patcher-options.d.ts +56 -0
- package/dist/tailwindcss/patcher-resolve.d.ts +4 -0
- package/dist/tailwindcss/patcher.d.ts +13 -0
- package/dist/tailwindcss/recorder.d.ts +13 -0
- package/dist/tailwindcss/remove-unsupported-css.d.ts +2 -0
- package/dist/tailwindcss/runtime/cache.d.ts +11 -0
- package/dist/tailwindcss/runtime-logs.d.ts +3 -0
- package/dist/tailwindcss/runtime.d.ts +29 -0
- package/dist/tailwindcss/targets/paths.d.ts +13 -0
- package/dist/tailwindcss/targets/record-io.d.ts +5 -0
- package/dist/tailwindcss/targets/recorder.d.ts +3 -0
- package/dist/tailwindcss/targets/types.d.ts +35 -0
- package/dist/tailwindcss/targets.d.ts +6 -0
- package/dist/tailwindcss/v3-engine/generator.d.ts +2 -0
- package/dist/tailwindcss/v3-engine/index.d.ts +4 -0
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +4 -0
- package/dist/tailwindcss/v3-engine/source.d.ts +5 -0
- package/dist/tailwindcss/v3-engine/types.d.ts +55 -0
- package/dist/tailwindcss/v4/config.d.ts +5 -0
- package/dist/tailwindcss/v4/css-entries.d.ts +7 -0
- package/dist/tailwindcss/v4/index.d.ts +2 -0
- package/dist/tailwindcss/v4/multi-patcher.d.ts +2 -0
- package/dist/tailwindcss/v4/patcher-options.d.ts +24 -0
- package/dist/tailwindcss/v4/patcher.d.ts +14 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/generator.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/index.d.ts +5 -0
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +4 -0
- package/dist/tailwindcss/v4-engine/source.d.ts +7 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +17 -0
- package/dist/typedoc.export.d.ts +5 -0
- package/dist/types/base.d.ts +1 -0
- package/dist/types/disabled-options.d.ts +4 -0
- package/dist/types/index.d.ts +104 -0
- package/dist/types/shared.d.ts +7 -0
- package/dist/types/user-defined-options/general.d.ts +31 -0
- package/dist/types/user-defined-options/important.d.ts +37 -0
- package/dist/types/user-defined-options/index.d.ts +11 -0
- package/dist/types/user-defined-options/lifecycle.d.ts +6 -0
- package/dist/types/user-defined-options/matcher.d.ts +9 -0
- package/dist/types.d.ts +1 -150
- package/dist/types.js +0 -1
- package/dist/types.mjs +1 -1
- package/dist/uni-app-x/component-local-style.d.ts +19 -0
- package/dist/uni-app-x/index.d.ts +2 -0
- package/dist/uni-app-x/options.d.ts +12 -0
- package/dist/uni-app-x/style-isolation.d.ts +2 -0
- package/dist/uni-app-x/transform.d.ts +9 -0
- package/dist/uni-app-x/vite.d.ts +36 -0
- package/dist/utils/decode.d.ts +2 -0
- package/dist/utils/disabled.d.ts +6 -0
- package/dist/utils/hbuilderx.d.ts +5 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/nameMatcher.d.ts +4 -0
- package/dist/utils/resolve-package.d.ts +1 -0
- package/dist/utils/uni-platform.d.ts +11 -0
- package/dist/utils-7DUGTFED.mjs +48 -0
- package/dist/utils-DmC9_In3.js +61 -0
- package/dist/vite-BHpAqldo.js +1952 -0
- package/dist/vite-C8JlHiyR.mjs +1940 -0
- package/dist/vite.d.ts +4 -17
- package/dist/vite.js +5 -14
- package/dist/vite.mjs +2 -14
- package/dist/weapp-tw-css-import-rewrite-loader.js +59 -92
- package/dist/weapp-tw-runtime-classset-loader.js +31 -50
- package/dist/webpack-CABjKGGQ.mjs +441 -0
- package/dist/webpack-DNIJ0ysE.js +456 -0
- package/dist/webpack.d.ts +4 -25
- package/dist/webpack.js +6 -17
- package/dist/webpack.mjs +2 -17
- package/dist/webpack4.d.ts +4 -26
- package/dist/webpack4.js +375 -481
- package/dist/webpack4.mjs +366 -482
- package/dist/wxml/Tokenizer.d.ts +15 -0
- package/dist/wxml/custom-attributes.d.ts +4 -0
- package/dist/wxml/index.d.ts +2 -0
- package/dist/wxml/shared.d.ts +2 -0
- package/dist/wxml/tokenizer/types.d.ts +18 -0
- package/dist/wxml/utils/codegen/legacy-rewriter.d.ts +2 -0
- package/dist/wxml/utils/codegen/legacy-visitor.d.ts +8 -0
- package/dist/wxml/utils/codegen.d.ts +2 -0
- package/dist/wxml/utils/custom-template.d.ts +3 -0
- package/dist/wxml/utils/fragment-helpers.d.ts +6 -0
- package/dist/wxml/utils/fragment-updater.d.ts +4 -0
- package/dist/wxml/utils/template-fragments.d.ts +3 -0
- package/dist/wxml/utils.d.ts +8 -0
- package/dist/wxml/whitespace.d.ts +2 -0
- package/generator-placeholder.css +1 -0
- package/package.json +19 -5
- package/dist/chunk-24AGZQVR.js +0 -183
- package/dist/chunk-3VQKDHGP.mjs +0 -179
- package/dist/chunk-4AFQP74Z.js +0 -24
- package/dist/chunk-57SOQCAU.mjs +0 -582
- package/dist/chunk-5ZYHNDEK.mjs +0 -2439
- package/dist/chunk-76S2EME4.mjs +0 -34
- package/dist/chunk-A5PB4KZT.js +0 -138
- package/dist/chunk-DUHYLR2R.js +0 -276
- package/dist/chunk-DYLQ6UOI.js +0 -71
- package/dist/chunk-E7I5TW5K.js +0 -52
- package/dist/chunk-FS2NOOEB.js +0 -292
- package/dist/chunk-HVNGIKLS.js +0 -3930
- package/dist/chunk-JZQBZHN5.js +0 -579
- package/dist/chunk-KGTVD4EP.mjs +0 -3930
- package/dist/chunk-NNOQDMUP.mjs +0 -10
- package/dist/chunk-OF6MFURR.js +0 -34
- package/dist/chunk-OFB2KBRP.js +0 -2442
- package/dist/chunk-OOHJLO5M.mjs +0 -71
- package/dist/chunk-PCDYXXSK.mjs +0 -1515
- package/dist/chunk-RKISS72P.js +0 -7
- package/dist/chunk-RRQZL7FQ.mjs +0 -292
- package/dist/chunk-XAKAD2CR.mjs +0 -138
- package/dist/chunk-XZP3MREK.mjs +0 -276
- package/dist/chunk-ZAA5ZG3D.js +0 -1518
- package/dist/chunk-ZCH4YINE.mjs +0 -52
- package/dist/cli.d.mts +0 -2
- package/dist/core.d.mts +0 -26
- package/dist/css-macro/postcss.d.mts +0 -7
- package/dist/css-macro.d.mts +0 -18
- package/dist/defaults.d.mts +0 -11
- package/dist/gulp.d.mts +0 -24
- package/dist/index-BXrmQelt.d.mts +0 -672
- package/dist/index-BXrmQelt.d.ts +0 -672
- package/dist/index.d.mts +0 -15
- package/dist/postcss-html-transform.d.mts +0 -2
- package/dist/presets.d.mts +0 -76
- package/dist/reset.d.mts +0 -1
- package/dist/types.d.mts +0 -150
- package/dist/vite.d.mts +0 -17
- package/dist/webpack.d.mts +0 -25
- package/dist/webpack4.d.mts +0 -26
package/dist/chunk-HVNGIKLS.js
DELETED
|
@@ -1,3930 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var _chunkZAA5ZG3Djs = require('./chunk-ZAA5ZG3D.js');
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _chunkA5PB4KZTjs = require('./chunk-A5PB4KZT.js');
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var _chunkDYLQ6UOIjs = require('./chunk-DYLQ6UOI.js');
|
|
20
|
-
|
|
21
|
-
// src/debug/index.ts
|
|
22
|
-
var _debug2 = require('debug'); var _debug3 = _interopRequireDefault(_debug2);
|
|
23
|
-
var _debug = _debug3.default.call(void 0, "weapp-tw");
|
|
24
|
-
function createDebug(prefix) {
|
|
25
|
-
const debug3 = ((formatter, ...args) => {
|
|
26
|
-
return _debug((_nullishCoalesce(prefix, () => ( ""))) + formatter, ...args);
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(debug3, "enabled", {
|
|
29
|
-
enumerable: false,
|
|
30
|
-
configurable: false,
|
|
31
|
-
get() {
|
|
32
|
-
return _debug.enabled;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
return debug3;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// src/tailwindcss/runtime.ts
|
|
39
|
-
var debug = createDebug("[tailwindcss:runtime] ");
|
|
40
|
-
var refreshTailwindcssPatcherSymbol = /* @__PURE__ */ Symbol.for("weapp-tailwindcss.refreshTailwindcssPatcher");
|
|
41
|
-
function createTailwindPatchPromise(twPatcher, onPatched) {
|
|
42
|
-
return Promise.resolve(twPatcher.patch()).then(async () => {
|
|
43
|
-
_chunkZAA5ZG3Djs.invalidateRuntimeClassSet.call(void 0, twPatcher);
|
|
44
|
-
if (onPatched) {
|
|
45
|
-
try {
|
|
46
|
-
await onPatched();
|
|
47
|
-
} catch (error) {
|
|
48
|
-
debug("failed to persist patch target after patch(): %O", error);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
var runtimeClassSetStateCache = /* @__PURE__ */ new WeakMap();
|
|
54
|
-
function getRuntimeClassSetStateEntry(state) {
|
|
55
|
-
let entry = runtimeClassSetStateCache.get(state);
|
|
56
|
-
if (!entry) {
|
|
57
|
-
entry = {};
|
|
58
|
-
runtimeClassSetStateCache.set(state, entry);
|
|
59
|
-
}
|
|
60
|
-
return entry;
|
|
61
|
-
}
|
|
62
|
-
async function refreshTailwindRuntimeState(state, forceOrOptions) {
|
|
63
|
-
const normalizedOptions = typeof forceOrOptions === "boolean" ? { force: forceOrOptions } : forceOrOptions;
|
|
64
|
-
const force = normalizedOptions.force;
|
|
65
|
-
const clearCache = normalizedOptions.clearCache === true;
|
|
66
|
-
if (!force) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
debug("refresh runtime state start, clearCache=%s major=%s", clearCache, _nullishCoalesce(state.twPatcher.majorVersion, () => ( "unknown")));
|
|
70
|
-
await state.patchPromise;
|
|
71
|
-
let refreshed = false;
|
|
72
|
-
if (typeof state.refreshTailwindcssPatcher === "function") {
|
|
73
|
-
const next = await state.refreshTailwindcssPatcher({ clearCache });
|
|
74
|
-
if (next !== state.twPatcher) {
|
|
75
|
-
state.twPatcher = next;
|
|
76
|
-
}
|
|
77
|
-
refreshed = true;
|
|
78
|
-
}
|
|
79
|
-
if (refreshed) {
|
|
80
|
-
state.patchPromise = createTailwindPatchPromise(state.twPatcher, state.onPatchCompleted);
|
|
81
|
-
}
|
|
82
|
-
debug("refresh runtime state end, refreshed=%s major=%s", refreshed, _nullishCoalesce(state.twPatcher.majorVersion, () => ( "unknown")));
|
|
83
|
-
return refreshed;
|
|
84
|
-
}
|
|
85
|
-
async function ensureRuntimeClassSet(state, options = {}) {
|
|
86
|
-
const forceRefresh = options.forceRefresh === true;
|
|
87
|
-
const forceCollect = options.forceCollect === true;
|
|
88
|
-
const clearCache = options.clearCache === true;
|
|
89
|
-
const allowEmpty = options.allowEmpty === true;
|
|
90
|
-
if (forceRefresh) {
|
|
91
|
-
await refreshTailwindRuntimeState(state, {
|
|
92
|
-
force: true,
|
|
93
|
-
clearCache
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
await state.patchPromise;
|
|
97
|
-
const entry = getRuntimeClassSetStateEntry(state);
|
|
98
|
-
const signature = _chunkZAA5ZG3Djs.getRuntimeClassSetSignature.call(void 0, state.twPatcher);
|
|
99
|
-
const signatureChanged = entry.signature !== signature;
|
|
100
|
-
const shouldForceCollect = forceCollect || forceRefresh || signatureChanged;
|
|
101
|
-
if (!shouldForceCollect) {
|
|
102
|
-
if (entry.value && (allowEmpty || entry.value.size > 0)) {
|
|
103
|
-
return entry.value;
|
|
104
|
-
}
|
|
105
|
-
if (entry.promise) {
|
|
106
|
-
return entry.promise;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const task = (async () => {
|
|
110
|
-
const collected = await collectRuntimeClassSet(state.twPatcher, {
|
|
111
|
-
force: shouldForceCollect,
|
|
112
|
-
skipRefresh: true,
|
|
113
|
-
clearCache
|
|
114
|
-
});
|
|
115
|
-
if (allowEmpty || collected.size > 0) {
|
|
116
|
-
return collected;
|
|
117
|
-
}
|
|
118
|
-
await refreshTailwindRuntimeState(state, {
|
|
119
|
-
force: true,
|
|
120
|
-
clearCache: true
|
|
121
|
-
});
|
|
122
|
-
await state.patchPromise;
|
|
123
|
-
return collectRuntimeClassSet(state.twPatcher, {
|
|
124
|
-
force: true,
|
|
125
|
-
skipRefresh: true,
|
|
126
|
-
clearCache: true
|
|
127
|
-
});
|
|
128
|
-
})();
|
|
129
|
-
entry.promise = task;
|
|
130
|
-
try {
|
|
131
|
-
const runtimeSet = await task;
|
|
132
|
-
entry.value = runtimeSet;
|
|
133
|
-
entry.signature = _chunkZAA5ZG3Djs.getRuntimeClassSetSignature.call(void 0, state.twPatcher);
|
|
134
|
-
return runtimeSet;
|
|
135
|
-
} finally {
|
|
136
|
-
if (entry.promise === task) {
|
|
137
|
-
entry.promise = void 0;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function shouldPreferSync(majorVersion) {
|
|
142
|
-
if (majorVersion == null) {
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
if (majorVersion === 3) {
|
|
146
|
-
return true;
|
|
147
|
-
}
|
|
148
|
-
if (majorVersion === 4) {
|
|
149
|
-
return true;
|
|
150
|
-
}
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
function tryGetRuntimeClassSetSync(twPatcher) {
|
|
154
|
-
if (typeof twPatcher.getClassSetSync !== "function") {
|
|
155
|
-
return void 0;
|
|
156
|
-
}
|
|
157
|
-
if (!shouldPreferSync(twPatcher.majorVersion)) {
|
|
158
|
-
return void 0;
|
|
159
|
-
}
|
|
160
|
-
try {
|
|
161
|
-
const set = twPatcher.getClassSetSync();
|
|
162
|
-
if (set && set.size === 0) {
|
|
163
|
-
return void 0;
|
|
164
|
-
}
|
|
165
|
-
return set;
|
|
166
|
-
} catch (error) {
|
|
167
|
-
if (twPatcher.majorVersion === 4) {
|
|
168
|
-
debug("getClassSetSync() unavailable for tailwindcss v4, fallback to async getClassSet(): %O", error);
|
|
169
|
-
} else {
|
|
170
|
-
debug("getClassSetSync() failed, fallback to async getClassSet(): %O", error);
|
|
171
|
-
}
|
|
172
|
-
return void 0;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
async function collectRuntimeClassSet(twPatcher, options = {}) {
|
|
176
|
-
let activePatcher = twPatcher;
|
|
177
|
-
if (options.force && !options.skipRefresh) {
|
|
178
|
-
const refresh = activePatcher[refreshTailwindcssPatcherSymbol];
|
|
179
|
-
if (typeof refresh === "function") {
|
|
180
|
-
try {
|
|
181
|
-
const refreshed = await refresh({ clearCache: options.clearCache === true });
|
|
182
|
-
if (refreshed) {
|
|
183
|
-
activePatcher = refreshed;
|
|
184
|
-
}
|
|
185
|
-
} catch (error) {
|
|
186
|
-
debug("refreshTailwindcssPatcher failed, continuing with existing patcher: %O", error);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
const entry = _chunkZAA5ZG3Djs.getRuntimeClassSetCacheEntry.call(void 0, activePatcher);
|
|
191
|
-
const signature = _chunkZAA5ZG3Djs.getRuntimeClassSetSignature.call(void 0, activePatcher);
|
|
192
|
-
if (!options.force) {
|
|
193
|
-
if (entry.value && entry.signature === signature) {
|
|
194
|
-
return entry.value;
|
|
195
|
-
}
|
|
196
|
-
if (entry.promise) {
|
|
197
|
-
return entry.promise;
|
|
198
|
-
}
|
|
199
|
-
} else {
|
|
200
|
-
entry.value = void 0;
|
|
201
|
-
}
|
|
202
|
-
const task = (async () => {
|
|
203
|
-
const preExtractSyncSet = options.force ? tryGetRuntimeClassSetSync(activePatcher) : void 0;
|
|
204
|
-
if (preExtractSyncSet) {
|
|
205
|
-
debug("runtime class set snapshot via getClassSetSync() before extract(), size=%d", preExtractSyncSet.size);
|
|
206
|
-
}
|
|
207
|
-
const preferExtract = options.force === true;
|
|
208
|
-
try {
|
|
209
|
-
const result = await activePatcher.extract({ write: false });
|
|
210
|
-
if (_optionalChain([result, 'optionalAccess', _2 => _2.classSet])) {
|
|
211
|
-
if (result.classSet.size > 0) {
|
|
212
|
-
debug("runtime class set resolved via extract(), size=%d", result.classSet.size);
|
|
213
|
-
return result.classSet;
|
|
214
|
-
}
|
|
215
|
-
if (preferExtract) {
|
|
216
|
-
debug("runtime class set from extract() is empty on force collect, fallback to sync/async class set");
|
|
217
|
-
} else {
|
|
218
|
-
debug("runtime class set from extract() is empty, fallback to sync/async class set");
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
} catch (error) {
|
|
222
|
-
debug("extract() failed, fallback to getClassSet(): %O", error);
|
|
223
|
-
}
|
|
224
|
-
if (preExtractSyncSet) {
|
|
225
|
-
debug("runtime class set fallback to pre-extract sync snapshot, size=%d", preExtractSyncSet.size);
|
|
226
|
-
return preExtractSyncSet;
|
|
227
|
-
}
|
|
228
|
-
const syncSet = tryGetRuntimeClassSetSync(activePatcher);
|
|
229
|
-
if (syncSet) {
|
|
230
|
-
debug("runtime class set resolved via getClassSetSync(), size=%d", syncSet.size);
|
|
231
|
-
return syncSet;
|
|
232
|
-
}
|
|
233
|
-
try {
|
|
234
|
-
const fallbackSet = await Promise.resolve(activePatcher.getClassSet());
|
|
235
|
-
if (fallbackSet) {
|
|
236
|
-
debug("runtime class set resolved via getClassSet(), size=%d", fallbackSet.size);
|
|
237
|
-
return fallbackSet;
|
|
238
|
-
}
|
|
239
|
-
} catch (error) {
|
|
240
|
-
debug("getClassSet() failed, returning empty set: %O", error);
|
|
241
|
-
}
|
|
242
|
-
return /* @__PURE__ */ new Set();
|
|
243
|
-
})();
|
|
244
|
-
entry.promise = task;
|
|
245
|
-
entry.signature = signature;
|
|
246
|
-
try {
|
|
247
|
-
const resolved = await task;
|
|
248
|
-
entry.value = resolved;
|
|
249
|
-
entry.promise = void 0;
|
|
250
|
-
entry.signature = signature;
|
|
251
|
-
return resolved;
|
|
252
|
-
} catch (error) {
|
|
253
|
-
entry.promise = void 0;
|
|
254
|
-
throw error;
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// src/context/index.ts
|
|
259
|
-
var _promises = require('fs/promises');
|
|
260
|
-
var _logger = require('@weapp-tailwindcss/logger');
|
|
261
|
-
|
|
262
|
-
// src/cache/index.ts
|
|
263
|
-
var _lrucache = require('lru-cache');
|
|
264
|
-
|
|
265
|
-
// src/cache/md5.ts
|
|
266
|
-
var _node = require('@weapp-tailwindcss/shared/node');
|
|
267
|
-
|
|
268
|
-
// src/cache/index.ts
|
|
269
|
-
function isProcessResult(value) {
|
|
270
|
-
return typeof value === "object" && value !== null && "result" in value;
|
|
271
|
-
}
|
|
272
|
-
function createCache(options) {
|
|
273
|
-
const disabled = options === false;
|
|
274
|
-
const hashMap = /* @__PURE__ */ new Map();
|
|
275
|
-
const instance = new (0, _lrucache.LRUCache)({
|
|
276
|
-
// 可能会添加和删除一些页面和组件, 先设定 1024 吧
|
|
277
|
-
max: 1024,
|
|
278
|
-
ttl: 0,
|
|
279
|
-
ttlAutopurge: false
|
|
280
|
-
});
|
|
281
|
-
const cache = {
|
|
282
|
-
hashMap,
|
|
283
|
-
instance,
|
|
284
|
-
hasHashKey(key) {
|
|
285
|
-
return hashMap.has(key);
|
|
286
|
-
},
|
|
287
|
-
getHashValue(key) {
|
|
288
|
-
return hashMap.get(key);
|
|
289
|
-
},
|
|
290
|
-
setHashValue(key, value) {
|
|
291
|
-
return hashMap.set(key, value);
|
|
292
|
-
},
|
|
293
|
-
get(key) {
|
|
294
|
-
return instance.get(key);
|
|
295
|
-
},
|
|
296
|
-
set(key, value) {
|
|
297
|
-
return instance.set(key, value);
|
|
298
|
-
},
|
|
299
|
-
computeHash(message) {
|
|
300
|
-
return _node.md5.call(void 0, message);
|
|
301
|
-
},
|
|
302
|
-
calcHashValueChanged(key, hash) {
|
|
303
|
-
const hit = hashMap.get(key);
|
|
304
|
-
if (hit) {
|
|
305
|
-
hashMap.set(key, {
|
|
306
|
-
changed: hash !== hit.hash,
|
|
307
|
-
hash
|
|
308
|
-
});
|
|
309
|
-
} else {
|
|
310
|
-
hashMap.set(key, {
|
|
311
|
-
changed: true,
|
|
312
|
-
hash
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
return cache;
|
|
316
|
-
},
|
|
317
|
-
has(key) {
|
|
318
|
-
return instance.has(key);
|
|
319
|
-
},
|
|
320
|
-
async process({
|
|
321
|
-
key,
|
|
322
|
-
hashKey,
|
|
323
|
-
rawSource,
|
|
324
|
-
hash,
|
|
325
|
-
resolveCache,
|
|
326
|
-
transform,
|
|
327
|
-
onCacheHit
|
|
328
|
-
}) {
|
|
329
|
-
if (disabled) {
|
|
330
|
-
const value2 = await transform();
|
|
331
|
-
return isProcessResult(value2) ? value2.result : value2;
|
|
332
|
-
}
|
|
333
|
-
const cacheHashKey = _nullishCoalesce(hashKey, () => ( key));
|
|
334
|
-
let hasChanged = true;
|
|
335
|
-
if (hash != null || rawSource != null) {
|
|
336
|
-
const nextHash = _nullishCoalesce(hash, () => ( cache.computeHash(rawSource)));
|
|
337
|
-
cache.calcHashValueChanged(cacheHashKey, nextHash);
|
|
338
|
-
const entry = cache.getHashValue(cacheHashKey);
|
|
339
|
-
hasChanged = _nullishCoalesce(_optionalChain([entry, 'optionalAccess', _3 => _3.changed]), () => ( true));
|
|
340
|
-
}
|
|
341
|
-
const readCache = _nullishCoalesce(resolveCache, () => ( (() => cache.get(key))));
|
|
342
|
-
if (!hasChanged) {
|
|
343
|
-
const cached = readCache();
|
|
344
|
-
if (cached !== void 0) {
|
|
345
|
-
await _optionalChain([onCacheHit, 'optionalCall', _4 => _4(cached)]);
|
|
346
|
-
return cached;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
const value = await transform();
|
|
350
|
-
const normalized = isProcessResult(value) ? value : { result: value };
|
|
351
|
-
const stored = _nullishCoalesce(normalized.cacheValue, () => ( normalized.result));
|
|
352
|
-
cache.set(key, stored);
|
|
353
|
-
return normalized.result;
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
return cache;
|
|
357
|
-
}
|
|
358
|
-
function initializeCache(cacheConfig) {
|
|
359
|
-
if (typeof cacheConfig === "boolean" || cacheConfig === void 0) {
|
|
360
|
-
return createCache(cacheConfig);
|
|
361
|
-
}
|
|
362
|
-
return cacheConfig;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// src/tailwindcss/runtime-logs.ts
|
|
366
|
-
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
367
|
-
|
|
368
|
-
var runtimeLogDedupeHolder = globalThis;
|
|
369
|
-
var runtimeLogDedupe = _nullishCoalesce(runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__, () => ( (runtimeLogDedupeHolder.__WEAPP_TW_RUNTIME_LOG_DEDUPE__ = /* @__PURE__ */ new Set())));
|
|
370
|
-
function createRuntimeLogKey(category, baseDir, rootPath, version) {
|
|
371
|
-
return JSON.stringify([
|
|
372
|
-
category,
|
|
373
|
-
_nullishCoalesce(baseDir, () => ( _process2.default.cwd())),
|
|
374
|
-
_nullishCoalesce(rootPath, () => ( "")),
|
|
375
|
-
_nullishCoalesce(version, () => ( ""))
|
|
376
|
-
]);
|
|
377
|
-
}
|
|
378
|
-
function markRuntimeLog(category, baseDir, rootPath, version) {
|
|
379
|
-
const key = createRuntimeLogKey(category, baseDir, rootPath, version);
|
|
380
|
-
if (runtimeLogDedupe.has(key)) {
|
|
381
|
-
return false;
|
|
382
|
-
}
|
|
383
|
-
runtimeLogDedupe.add(key);
|
|
384
|
-
return true;
|
|
385
|
-
}
|
|
386
|
-
function logRuntimeTailwindcssTarget(baseDir, rootPath, version) {
|
|
387
|
-
if (!markRuntimeLog("target", baseDir, rootPath, version)) {
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
const versionText = version ? ` (v${version})` : "";
|
|
391
|
-
_logger.logger.info("%s \u4F7F\u7528 Tailwind CSS%s", "Weapp-tailwindcss", versionText);
|
|
392
|
-
}
|
|
393
|
-
function logRuntimeTailwindcssVersion(baseDir, rootPath, version) {
|
|
394
|
-
if (version) {
|
|
395
|
-
if (!markRuntimeLog("version", baseDir, rootPath, version)) {
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
_logger.logger.success(`\u5F53\u524D\u4F7F\u7528 ${_logger.pc.cyanBright("Tailwind CSS")} \u7248\u672C\u4E3A: ${_logger.pc.underline(_logger.pc.bold(_logger.pc.green(version)))}`);
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
if (!markRuntimeLog("missing", baseDir, rootPath, version)) {
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
_logger.logger.warn(`${_logger.pc.cyanBright("Tailwind CSS")} \u672A\u5B89\u88C5\uFF0C\u5DF2\u8DF3\u8FC7\u7248\u672C\u68C0\u6D4B\u4E0E\u8865\u4E01\u5E94\u7528\u3002`);
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
// src/tailwindcss/targets.ts
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
// src/tailwindcss/targets/paths.ts
|
|
412
|
-
var _fs = require('fs');
|
|
413
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
414
|
-
var PATCH_INFO_FILENAME = "tailwindcss-target.json";
|
|
415
|
-
var PATCH_INFO_CACHE_RELATIVE_PATH = _path2.default.join("node_modules", ".cache", "weapp-tailwindcss", PATCH_INFO_FILENAME);
|
|
416
|
-
var PATCH_INFO_LEGACY_RELATIVE_PATH = _path2.default.join(".tw-patch", PATCH_INFO_FILENAME);
|
|
417
|
-
function toDisplayPath(value) {
|
|
418
|
-
return _path2.default.normalize(value).replace(/\\/g, "/");
|
|
419
|
-
}
|
|
420
|
-
function formatRelativeToBase(targetPath, baseDir) {
|
|
421
|
-
if (!baseDir) {
|
|
422
|
-
return toDisplayPath(targetPath);
|
|
423
|
-
}
|
|
424
|
-
const relative = _path2.default.relative(baseDir, targetPath);
|
|
425
|
-
if (!relative || relative === ".") {
|
|
426
|
-
return ".";
|
|
427
|
-
}
|
|
428
|
-
if (relative.startsWith("..")) {
|
|
429
|
-
return toDisplayPath(targetPath);
|
|
430
|
-
}
|
|
431
|
-
return toDisplayPath(_path2.default.join(".", relative));
|
|
432
|
-
}
|
|
433
|
-
function resolveRecordLocation(baseDir) {
|
|
434
|
-
const normalizedBase = _path2.default.normalize(baseDir);
|
|
435
|
-
const packageRoot = _nullishCoalesce(_chunkZAA5ZG3Djs.findNearestPackageRoot.call(void 0, normalizedBase), () => ( normalizedBase));
|
|
436
|
-
const packageJsonPath = _path2.default.join(packageRoot, "package.json");
|
|
437
|
-
const hasPackageJson = _fs.existsSync.call(void 0, packageJsonPath);
|
|
438
|
-
const recordKeySource = hasPackageJson ? packageJsonPath : normalizedBase;
|
|
439
|
-
const recordKey = _node.md5.call(void 0, _path2.default.normalize(recordKeySource));
|
|
440
|
-
const recordDir = _path2.default.join(packageRoot, "node_modules", ".cache", "weapp-tailwindcss", recordKey);
|
|
441
|
-
const recordPath = _path2.default.join(recordDir, PATCH_INFO_FILENAME);
|
|
442
|
-
return {
|
|
443
|
-
normalizedBase,
|
|
444
|
-
packageRoot,
|
|
445
|
-
recordDir,
|
|
446
|
-
recordKey,
|
|
447
|
-
recordPath,
|
|
448
|
-
packageJsonPath: hasPackageJson ? packageJsonPath : void 0
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
function getRecordFileCandidates(baseDir) {
|
|
452
|
-
const { normalizedBase, packageRoot, recordPath } = resolveRecordLocation(baseDir);
|
|
453
|
-
const candidates = /* @__PURE__ */ new Set([
|
|
454
|
-
recordPath,
|
|
455
|
-
_path2.default.join(packageRoot, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
456
|
-
_path2.default.join(normalizedBase, PATCH_INFO_CACHE_RELATIVE_PATH),
|
|
457
|
-
_path2.default.join(normalizedBase, PATCH_INFO_LEGACY_RELATIVE_PATH)
|
|
458
|
-
]);
|
|
459
|
-
return [...candidates];
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
// src/tailwindcss/targets/record-io.ts
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
// package.json
|
|
470
|
-
var package_default = {
|
|
471
|
-
name: "weapp-tailwindcss",
|
|
472
|
-
version: "4.12.0",
|
|
473
|
-
description: "\u628A tailwindcss \u539F\u5B50\u5316\u6837\u5F0F\u601D\u60F3\uFF0C\u5E26\u7ED9\u5C0F\u7A0B\u5E8F\u5F00\u53D1\u8005\u4EEC! bring tailwindcss to miniprogram developers!",
|
|
474
|
-
author: "ice breaker <1324318532@qq.com>",
|
|
475
|
-
license: "MIT",
|
|
476
|
-
homepage: "https://tw.icebreaker.top",
|
|
477
|
-
repository: {
|
|
478
|
-
type: "git",
|
|
479
|
-
url: "git+https://github.com/sonofmagic/weapp-tailwindcss.git",
|
|
480
|
-
directory: "packages/weapp-tailwindcss"
|
|
481
|
-
},
|
|
482
|
-
bugs: {
|
|
483
|
-
url: "https://github.com/sonofmagic/weapp-tailwindcss/issues"
|
|
484
|
-
},
|
|
485
|
-
keywords: [
|
|
486
|
-
"tailwindcss",
|
|
487
|
-
"weapp",
|
|
488
|
-
"wechat",
|
|
489
|
-
"mini",
|
|
490
|
-
"miniprogram",
|
|
491
|
-
"mini app",
|
|
492
|
-
"weapp-tw",
|
|
493
|
-
"weapp-tailwindcss",
|
|
494
|
-
"taro",
|
|
495
|
-
"uni-app",
|
|
496
|
-
"remax",
|
|
497
|
-
"rax",
|
|
498
|
-
"mpx",
|
|
499
|
-
"jit",
|
|
500
|
-
"mp",
|
|
501
|
-
"android",
|
|
502
|
-
"ios",
|
|
503
|
-
"\u5C0F\u7A0B\u5E8F",
|
|
504
|
-
"vite",
|
|
505
|
-
"postcss",
|
|
506
|
-
"webpack",
|
|
507
|
-
"webpack-plugin",
|
|
508
|
-
"gulp",
|
|
509
|
-
"gulp-plugin"
|
|
510
|
-
],
|
|
511
|
-
exports: {
|
|
512
|
-
".": {
|
|
513
|
-
style: "./index.css",
|
|
514
|
-
types: "./dist/index.d.ts",
|
|
515
|
-
import: "./dist/index.mjs",
|
|
516
|
-
require: "./dist/index.js"
|
|
517
|
-
},
|
|
518
|
-
"./escape": {
|
|
519
|
-
types: "./dist/escape.d.ts",
|
|
520
|
-
import: "./dist/escape.mjs",
|
|
521
|
-
require: "./dist/escape.js"
|
|
522
|
-
},
|
|
523
|
-
"./vite": {
|
|
524
|
-
types: "./dist/vite.d.ts",
|
|
525
|
-
import: "./dist/vite.mjs",
|
|
526
|
-
require: "./dist/vite.js"
|
|
527
|
-
},
|
|
528
|
-
"./webpack": {
|
|
529
|
-
types: "./dist/webpack.d.ts",
|
|
530
|
-
import: "./dist/webpack.mjs",
|
|
531
|
-
require: "./dist/webpack.js"
|
|
532
|
-
},
|
|
533
|
-
"./webpack4": {
|
|
534
|
-
types: "./dist/webpack4.d.ts",
|
|
535
|
-
import: "./dist/webpack4.mjs",
|
|
536
|
-
require: "./dist/webpack4.js"
|
|
537
|
-
},
|
|
538
|
-
"./core": {
|
|
539
|
-
types: "./dist/core.d.ts",
|
|
540
|
-
import: "./dist/core.mjs",
|
|
541
|
-
require: "./dist/core.js"
|
|
542
|
-
},
|
|
543
|
-
"./gulp": {
|
|
544
|
-
types: "./dist/gulp.d.ts",
|
|
545
|
-
import: "./dist/gulp.mjs",
|
|
546
|
-
require: "./dist/gulp.js"
|
|
547
|
-
},
|
|
548
|
-
"./defaults": {
|
|
549
|
-
types: "./dist/defaults.d.ts",
|
|
550
|
-
import: "./dist/defaults.mjs",
|
|
551
|
-
require: "./dist/defaults.js"
|
|
552
|
-
},
|
|
553
|
-
"./presets": {
|
|
554
|
-
types: "./dist/presets.d.ts",
|
|
555
|
-
import: "./dist/presets.mjs",
|
|
556
|
-
require: "./dist/presets.js"
|
|
557
|
-
},
|
|
558
|
-
"./reset": {
|
|
559
|
-
types: "./dist/reset.d.ts",
|
|
560
|
-
import: "./dist/reset.mjs",
|
|
561
|
-
require: "./dist/reset.js"
|
|
562
|
-
},
|
|
563
|
-
"./css-macro/postcss": {
|
|
564
|
-
types: "./dist/css-macro/postcss.d.ts",
|
|
565
|
-
import: "./dist/css-macro/postcss.mjs",
|
|
566
|
-
require: "./dist/css-macro/postcss.js"
|
|
567
|
-
},
|
|
568
|
-
"./css-macro": {
|
|
569
|
-
types: "./dist/css-macro.d.ts",
|
|
570
|
-
import: "./dist/css-macro.mjs",
|
|
571
|
-
require: "./dist/css-macro.js"
|
|
572
|
-
},
|
|
573
|
-
"./types": {
|
|
574
|
-
types: "./dist/types.d.ts",
|
|
575
|
-
import: "./dist/types.mjs",
|
|
576
|
-
require: "./dist/types.js"
|
|
577
|
-
},
|
|
578
|
-
"./postcss-html-transform": {
|
|
579
|
-
types: "./dist/postcss-html-transform.d.ts",
|
|
580
|
-
import: "./dist/postcss-html-transform.mjs",
|
|
581
|
-
require: "./dist/postcss-html-transform.js"
|
|
582
|
-
},
|
|
583
|
-
"./package.json": "./package.json",
|
|
584
|
-
"./index.css": "./index.css",
|
|
585
|
-
"./index": "./index.css",
|
|
586
|
-
"./preflight.css": "./preflight.css",
|
|
587
|
-
"./preflight": "./preflight.css",
|
|
588
|
-
"./theme.css": "./theme.css",
|
|
589
|
-
"./theme": "./theme.css",
|
|
590
|
-
"./utilities.css": "./utilities.css",
|
|
591
|
-
"./utilities": "./utilities.css",
|
|
592
|
-
"./with-layer.css": "./with-layer.css",
|
|
593
|
-
"./with-layer": "./with-layer.css",
|
|
594
|
-
"./uni-app-x": "./uni-app-x.css",
|
|
595
|
-
"./uni-app-x.css": "./uni-app-x.css",
|
|
596
|
-
"./css": "./css/index.css",
|
|
597
|
-
"./*": "./*"
|
|
598
|
-
},
|
|
599
|
-
main: "./dist/index.js",
|
|
600
|
-
module: "./dist/index.mjs",
|
|
601
|
-
types: "./dist/index.d.ts",
|
|
602
|
-
style: "index.css",
|
|
603
|
-
typesVersions: {
|
|
604
|
-
"*": {
|
|
605
|
-
"*": [
|
|
606
|
-
"./dist/*",
|
|
607
|
-
"./dist/index.d.ts"
|
|
608
|
-
]
|
|
609
|
-
}
|
|
610
|
-
},
|
|
611
|
-
bin: {
|
|
612
|
-
"weapp-tailwindcss-webpack-plugin": "bin/weapp-tailwindcss.js",
|
|
613
|
-
"weapp-tailwindcss": "bin/weapp-tailwindcss.js",
|
|
614
|
-
"weapp-tw": "bin/weapp-tailwindcss.js"
|
|
615
|
-
},
|
|
616
|
-
files: [
|
|
617
|
-
"bin",
|
|
618
|
-
"css",
|
|
619
|
-
"dist",
|
|
620
|
-
"index.css",
|
|
621
|
-
"preflight.css",
|
|
622
|
-
"scripts/postinstall.mjs",
|
|
623
|
-
"theme.css",
|
|
624
|
-
"uni-app-x.css",
|
|
625
|
-
"utilities.css",
|
|
626
|
-
"with-layer.css"
|
|
627
|
-
],
|
|
628
|
-
engines: {
|
|
629
|
-
node: "^20.19.0 || >=22.12.0"
|
|
630
|
-
},
|
|
631
|
-
scripts: {
|
|
632
|
-
dev: "tsup --watch --sourcemap",
|
|
633
|
-
build: "tsup && node scripts/ensure-escape-dts.mjs",
|
|
634
|
-
"build:tsc": "cross-env NODE_ENV=development tsc --build tsconfig.json",
|
|
635
|
-
"build:cli": "cd plugins/cli && pnpm run build",
|
|
636
|
-
"build:css": "tsx scripts/build-css.ts",
|
|
637
|
-
"build:weapp-theme": "tsx scripts/build-weapp-theme.ts",
|
|
638
|
-
test: "pnpm run cli:patch && vitest run",
|
|
639
|
-
"test:dev": "vitest",
|
|
640
|
-
"test:ui": "vitest --ui",
|
|
641
|
-
bench: "vitest bench --config ./vitest.config.ts",
|
|
642
|
-
"bench:vite-perf": "tsx scripts/vite-perf-bench.ts",
|
|
643
|
-
"bench:vite-perf:summary": "tsx scripts/vite-perf-summary.ts",
|
|
644
|
-
"bench:js-handlers": "tsx scripts/js-bench.ts",
|
|
645
|
-
"bench:js-diff": "tsx scripts/js-bench-diff.ts",
|
|
646
|
-
tsd: "tsd",
|
|
647
|
-
clean: "tsx scripts/clean.ts",
|
|
648
|
-
"get-decl": "tsx scripts/get-decl.ts",
|
|
649
|
-
"ls:pack": "npm pack --dry-run",
|
|
650
|
-
"cli:patch": "node bin/weapp-tailwindcss.js patch",
|
|
651
|
-
colors: "tsx scripts/colors.ts",
|
|
652
|
-
release: "tsx scripts/release.ts",
|
|
653
|
-
lint: "eslint .",
|
|
654
|
-
"lint:fix": "eslint ./src --fix",
|
|
655
|
-
postinstall: "node scripts/postinstall.mjs",
|
|
656
|
-
"bench:vite-dev-hmr": "tsx scripts/vite-dev-hmr-bench.ts",
|
|
657
|
-
"test:watch-hmr": "node --import tsx scripts/watch-hmr-regression/index.ts"
|
|
658
|
-
},
|
|
659
|
-
publishConfig: {
|
|
660
|
-
access: "public",
|
|
661
|
-
registry: "https://registry.npmjs.org"
|
|
662
|
-
},
|
|
663
|
-
dependencies: {
|
|
664
|
-
"@ast-core/escape": "~1.0.1",
|
|
665
|
-
"@babel/parser": "~7.29.3",
|
|
666
|
-
"@babel/traverse": "~7.29.0",
|
|
667
|
-
"@babel/types": "~7.29.0",
|
|
668
|
-
"@tailwindcss-mangle/config": "^7.0.1",
|
|
669
|
-
"@vue/compiler-dom": "catalog:vue3",
|
|
670
|
-
"@vue/compiler-sfc": "catalog:vue3",
|
|
671
|
-
"@weapp-core/escape": "~7.0.0",
|
|
672
|
-
"@weapp-core/regex": "~1.0.1",
|
|
673
|
-
"@weapp-tailwindcss/logger": "workspace:*",
|
|
674
|
-
"@weapp-tailwindcss/postcss": "workspace:*",
|
|
675
|
-
"@weapp-tailwindcss/reset": "workspace:*",
|
|
676
|
-
"@weapp-tailwindcss/shared": "workspace:*",
|
|
677
|
-
cac: "6.7.14",
|
|
678
|
-
"comment-json": "^4.6.2",
|
|
679
|
-
debug: "~4.4.3",
|
|
680
|
-
"fast-glob": "^3.3.3",
|
|
681
|
-
htmlparser2: "10.1.0",
|
|
682
|
-
"loader-utils": "2.0.4",
|
|
683
|
-
"local-pkg": "^1.1.2",
|
|
684
|
-
"lru-cache": "10.4.3",
|
|
685
|
-
"magic-string": "0.30.21",
|
|
686
|
-
semver: "~7.7.4",
|
|
687
|
-
"tailwindcss-patch": "catalog:tailwindcssPatch",
|
|
688
|
-
"webpack-sources": "3.3.4",
|
|
689
|
-
yaml: "^2.8.4"
|
|
690
|
-
},
|
|
691
|
-
devDependencies: {
|
|
692
|
-
"fast-check": "^4.7.0"
|
|
693
|
-
}
|
|
694
|
-
};
|
|
695
|
-
|
|
696
|
-
// src/constants.ts
|
|
697
|
-
var pluginName = "weapp-tailwindcss-webpack-plugin";
|
|
698
|
-
var vitePluginName = "weapp-tailwindcss:adaptor";
|
|
699
|
-
var WEAPP_TW_VERSION = package_default.version;
|
|
700
|
-
var DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS = {
|
|
701
|
-
"tailwind-merge": "@weapp-tailwindcss/merge",
|
|
702
|
-
"class-variance-authority": "@weapp-tailwindcss/cva",
|
|
703
|
-
"tailwind-variants": "@weapp-tailwindcss/variants"
|
|
704
|
-
};
|
|
705
|
-
|
|
706
|
-
// src/tailwindcss/targets/record-io.ts
|
|
707
|
-
var loggedInvalidPatchRecords = /* @__PURE__ */ new Set();
|
|
708
|
-
function warnInvalidPatchTargetRecord(baseDir, recordPath, reason) {
|
|
709
|
-
const normalizedPath = _path2.default.normalize(recordPath);
|
|
710
|
-
if (loggedInvalidPatchRecords.has(normalizedPath)) {
|
|
711
|
-
return;
|
|
712
|
-
}
|
|
713
|
-
loggedInvalidPatchRecords.add(normalizedPath);
|
|
714
|
-
const fileDisplay = formatRelativeToBase(normalizedPath, baseDir);
|
|
715
|
-
const baseDisplay = formatRelativeToBase(_path2.default.normalize(baseDir), _process2.default.cwd());
|
|
716
|
-
const reasonMessage = reason ? `\uFF1A${reason}` : "";
|
|
717
|
-
_logger.logger.warn(
|
|
718
|
-
`\u68C0\u6D4B\u5230\u635F\u574F\u7684 Tailwind CSS \u76EE\u6807\u8BB0\u5F55 ${fileDisplay}${reasonMessage}\u3002\u8BF7\u5728 ${baseDisplay} \u91CD\u65B0\u6267\u884C "weapp-tw patch --record-target" \u6216\u5220\u9664\u8BE5\u6587\u4EF6\u540E\u518D\u8FD0\u884C\u3002`
|
|
719
|
-
);
|
|
720
|
-
}
|
|
721
|
-
function readPatchTargetRecord(baseDir) {
|
|
722
|
-
if (!baseDir) {
|
|
723
|
-
return void 0;
|
|
724
|
-
}
|
|
725
|
-
const normalizedBase = _path2.default.normalize(baseDir);
|
|
726
|
-
for (const recordPath of getRecordFileCandidates(normalizedBase)) {
|
|
727
|
-
if (!_fs.existsSync.call(void 0, recordPath)) {
|
|
728
|
-
continue;
|
|
729
|
-
}
|
|
730
|
-
try {
|
|
731
|
-
const content = _fs.readFileSync.call(void 0, recordPath, "utf8");
|
|
732
|
-
const parsed = JSON.parse(content);
|
|
733
|
-
if (!parsed || typeof parsed.tailwindPackagePath !== "string") {
|
|
734
|
-
warnInvalidPatchTargetRecord(normalizedBase, recordPath, "\u7F3A\u5C11 tailwindPackagePath \u5B57\u6BB5");
|
|
735
|
-
continue;
|
|
736
|
-
}
|
|
737
|
-
return {
|
|
738
|
-
baseDir: normalizedBase,
|
|
739
|
-
path: recordPath,
|
|
740
|
-
record: parsed
|
|
741
|
-
};
|
|
742
|
-
} catch (error) {
|
|
743
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
744
|
-
warnInvalidPatchTargetRecord(normalizedBase, recordPath, reason);
|
|
745
|
-
continue;
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
return void 0;
|
|
749
|
-
}
|
|
750
|
-
async function saveCliPatchTargetRecord(baseDir, patcher, options) {
|
|
751
|
-
if (!baseDir || !_optionalChain([patcher, 'optionalAccess', _5 => _5.packageInfo, 'optionalAccess', _6 => _6.rootPath])) {
|
|
752
|
-
return void 0;
|
|
753
|
-
}
|
|
754
|
-
const normalizedBase = _path2.default.normalize(baseDir);
|
|
755
|
-
const location = resolveRecordLocation(normalizedBase);
|
|
756
|
-
const recordPath = _optionalChain([options, 'optionalAccess', _7 => _7.recordPath]) ? _path2.default.normalize(options.recordPath) : location.recordPath;
|
|
757
|
-
const record = {
|
|
758
|
-
tailwindPackagePath: _path2.default.normalize(patcher.packageInfo.rootPath),
|
|
759
|
-
packageVersion: patcher.packageInfo.version,
|
|
760
|
-
recordedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
761
|
-
source: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _8 => _8.source]), () => ( "cli")),
|
|
762
|
-
tailwindcssBasedir: normalizedBase,
|
|
763
|
-
cwd: _optionalChain([options, 'optionalAccess', _9 => _9.cwd]) ? _path2.default.normalize(options.cwd) : normalizedBase,
|
|
764
|
-
patchVersion: WEAPP_TW_VERSION,
|
|
765
|
-
packageJsonPath: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _10 => _10.packageJsonPath]), () => ( location.packageJsonPath)),
|
|
766
|
-
recordKey: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _11 => _11.recordKey]), () => ( location.recordKey))
|
|
767
|
-
};
|
|
768
|
-
try {
|
|
769
|
-
await _promises.mkdir.call(void 0, _path2.default.dirname(recordPath), { recursive: true });
|
|
770
|
-
await _promises.writeFile.call(void 0, recordPath, `${JSON.stringify(record, null, 2)}
|
|
771
|
-
`, "utf8");
|
|
772
|
-
return recordPath;
|
|
773
|
-
} catch (error) {
|
|
774
|
-
const baseDisplay = formatRelativeToBase(normalizedBase, _process2.default.cwd());
|
|
775
|
-
_logger.logger.warn(
|
|
776
|
-
'\u81EA\u52A8\u66F4\u65B0 Tailwind CSS \u8865\u4E01\u8BB0\u5F55\u5931\u8D25\uFF0C\u8BF7\u5728 %s \u8FD0\u884C "weapp-tw patch --cwd %s"\u3002',
|
|
777
|
-
baseDisplay,
|
|
778
|
-
normalizedBase
|
|
779
|
-
);
|
|
780
|
-
_logger.logger.debug("failed to persist patch target record %s: %O", recordPath, error);
|
|
781
|
-
return void 0;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
// src/tailwindcss/targets/recorder.ts
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
function findPatchTargetRecord(baseDir) {
|
|
789
|
-
const visited = /* @__PURE__ */ new Set();
|
|
790
|
-
const fallback = _nullishCoalesce(baseDir, () => ( _process2.default.cwd()));
|
|
791
|
-
let current = _path2.default.resolve(fallback);
|
|
792
|
-
while (!visited.has(current)) {
|
|
793
|
-
const record = readPatchTargetRecord(current);
|
|
794
|
-
if (record) {
|
|
795
|
-
return record;
|
|
796
|
-
}
|
|
797
|
-
const parent = _path2.default.dirname(current);
|
|
798
|
-
if (parent === current) {
|
|
799
|
-
break;
|
|
800
|
-
}
|
|
801
|
-
visited.add(current);
|
|
802
|
-
current = parent;
|
|
803
|
-
}
|
|
804
|
-
return void 0;
|
|
805
|
-
}
|
|
806
|
-
function createPatchTargetRecorder(baseDir, patcher, options) {
|
|
807
|
-
if (!baseDir || !_optionalChain([patcher, 'optionalAccess', _12 => _12.packageInfo, 'optionalAccess', _13 => _13.rootPath]) || _optionalChain([options, 'optionalAccess', _14 => _14.recordTarget]) === false) {
|
|
808
|
-
return void 0;
|
|
809
|
-
}
|
|
810
|
-
const normalizedBase = _path2.default.normalize(baseDir);
|
|
811
|
-
const recorded = findPatchTargetRecord(normalizedBase);
|
|
812
|
-
const location = resolveRecordLocation(normalizedBase);
|
|
813
|
-
const expectedPath = _path2.default.normalize(patcher.packageInfo.rootPath);
|
|
814
|
-
let reason;
|
|
815
|
-
if (!recorded) {
|
|
816
|
-
reason = "missing";
|
|
817
|
-
} else {
|
|
818
|
-
const normalizedRecorded = _path2.default.normalize(recorded.record.tailwindPackagePath);
|
|
819
|
-
if (normalizedRecorded !== expectedPath) {
|
|
820
|
-
reason = "mismatch";
|
|
821
|
-
} else if (_path2.default.normalize(recorded.path) !== _path2.default.normalize(location.recordPath) || !recorded.record.recordKey || recorded.record.recordKey !== location.recordKey) {
|
|
822
|
-
reason = "migrate";
|
|
823
|
-
} else if (!recorded.record.patchVersion || recorded.record.patchVersion !== WEAPP_TW_VERSION) {
|
|
824
|
-
reason = "stale";
|
|
825
|
-
} else if (_optionalChain([options, 'optionalAccess', _15 => _15.cwd]) && recorded.record.cwd && _path2.default.normalize(recorded.record.cwd) !== _path2.default.normalize(options.cwd)) {
|
|
826
|
-
reason = "metadata";
|
|
827
|
-
} else if (!recorded.record.cwd && _optionalChain([options, 'optionalAccess', _16 => _16.cwd])) {
|
|
828
|
-
reason = "metadata";
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
const shouldPersist = _optionalChain([options, 'optionalAccess', _17 => _17.alwaysRecord]) || !recorded || Boolean(reason);
|
|
832
|
-
if (!shouldPersist) {
|
|
833
|
-
return void 0;
|
|
834
|
-
}
|
|
835
|
-
let message;
|
|
836
|
-
switch (reason) {
|
|
837
|
-
case "mismatch":
|
|
838
|
-
message = "\u68C0\u6D4B\u5230 Tailwind CSS \u76EE\u6807\u8BB0\u5F55\u4E0E\u5F53\u524D\u89E3\u6790\u7ED3\u679C\u4E0D\u4E00\u81F4\uFF0C\u6B63\u5728\u81EA\u52A8\u91CD\u65B0 patch \u5E76\u5237\u65B0\u7F13\u5B58\u3002";
|
|
839
|
-
break;
|
|
840
|
-
case "migrate":
|
|
841
|
-
case "stale":
|
|
842
|
-
message = "\u6B63\u5728\u5237\u65B0\u5F53\u524D\u5B50\u5305\u7684 Tailwind CSS \u8865\u4E01\u8BB0\u5F55\uFF0C\u786E\u4FDD\u7F13\u5B58\u9694\u79BB\u3002";
|
|
843
|
-
break;
|
|
844
|
-
case "missing":
|
|
845
|
-
message = "\u672A\u627E\u5230\u5F53\u524D\u5B50\u5305\u7684 Tailwind CSS \u76EE\u6807\u8BB0\u5F55\uFF0C\u6B63\u5728\u751F\u6210\u3002";
|
|
846
|
-
break;
|
|
847
|
-
default:
|
|
848
|
-
break;
|
|
849
|
-
}
|
|
850
|
-
const onPatched = async () => saveCliPatchTargetRecord(normalizedBase, patcher, {
|
|
851
|
-
cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _18 => _18.cwd]), () => ( normalizedBase)),
|
|
852
|
-
source: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _19 => _19.source]), () => ( "cli")),
|
|
853
|
-
recordPath: location.recordPath,
|
|
854
|
-
recordKey: location.recordKey,
|
|
855
|
-
packageJsonPath: location.packageJsonPath
|
|
856
|
-
});
|
|
857
|
-
return {
|
|
858
|
-
recordPath: location.recordPath,
|
|
859
|
-
message,
|
|
860
|
-
reason,
|
|
861
|
-
onPatched
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
// src/tailwindcss/targets.ts
|
|
866
|
-
function logTailwindcssTarget(kind, patcher, baseDir) {
|
|
867
|
-
const packageInfo = _optionalChain([patcher, 'optionalAccess', _20 => _20.packageInfo]);
|
|
868
|
-
const label = kind === "cli" ? "weapp-tw patch" : "Weapp-tailwindcss";
|
|
869
|
-
if (!_optionalChain([packageInfo, 'optionalAccess', _21 => _21.rootPath])) {
|
|
870
|
-
_logger.logger.warn(
|
|
871
|
-
"%s \u672A\u627E\u5230 Tailwind CSS \u4F9D\u8D56\uFF0C\u8BF7\u68C0\u67E5\u5728 %s \u662F\u5426\u5DF2\u5B89\u88C5 tailwindcss",
|
|
872
|
-
label,
|
|
873
|
-
_nullishCoalesce(baseDir, () => ( _process2.default.cwd()))
|
|
874
|
-
);
|
|
875
|
-
return;
|
|
876
|
-
}
|
|
877
|
-
const displayPath = formatRelativeToBase(packageInfo.rootPath, baseDir);
|
|
878
|
-
const version = packageInfo.version ? ` (v${packageInfo.version})` : "";
|
|
879
|
-
if (kind === "runtime") {
|
|
880
|
-
logRuntimeTailwindcssTarget(baseDir, packageInfo.rootPath, packageInfo.version);
|
|
881
|
-
return;
|
|
882
|
-
}
|
|
883
|
-
_logger.logger.info("%s \u7ED1\u5B9A Tailwind CSS -> %s%s", label, displayPath, version);
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
// src/context/compiler-context-cache.ts
|
|
887
|
-
var _buffer = require('buffer');
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
var PAREN_CONTENT_RE = /\(([^)]+)\)/u;
|
|
892
|
-
var AT_LOCATION_RE = /at\s+(\S.*)$/u;
|
|
893
|
-
var TRAILING_LINE_COL_RE = /:\d+(?::\d+)?$/u;
|
|
894
|
-
var globalCacheHolder = globalThis;
|
|
895
|
-
var compilerContextCache = _nullishCoalesce(globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__, () => ( (globalCacheHolder.__WEAPP_TW_COMPILER_CONTEXT_CACHE__ = /* @__PURE__ */ new Map())));
|
|
896
|
-
var compilerContextKeyCacheByOptions = /* @__PURE__ */ new WeakMap();
|
|
897
|
-
var compilerContextKeyCacheWithoutOptions = /* @__PURE__ */ new Map();
|
|
898
|
-
function withCircularGuard(value, stack, factory) {
|
|
899
|
-
if (stack.has(value)) {
|
|
900
|
-
throw new TypeError("Cannot serialize circular structure in compiler context options");
|
|
901
|
-
}
|
|
902
|
-
stack.add(value);
|
|
903
|
-
try {
|
|
904
|
-
return factory();
|
|
905
|
-
} finally {
|
|
906
|
-
stack.delete(value);
|
|
907
|
-
}
|
|
908
|
-
}
|
|
909
|
-
function encodeTaggedValue(type, value) {
|
|
910
|
-
const record = { __type: type };
|
|
911
|
-
if (value !== void 0) {
|
|
912
|
-
record.value = value;
|
|
913
|
-
}
|
|
914
|
-
return record;
|
|
915
|
-
}
|
|
916
|
-
function hasExplicitOptionBasedir(opts) {
|
|
917
|
-
return typeof _optionalChain([opts, 'optionalAccess', _22 => _22.tailwindcssBasedir]) === "string" && opts.tailwindcssBasedir.length > 0;
|
|
918
|
-
}
|
|
919
|
-
function shouldProbeCallerLocation(opts) {
|
|
920
|
-
if (hasExplicitOptionBasedir(opts)) {
|
|
921
|
-
return false;
|
|
922
|
-
}
|
|
923
|
-
return !(_process2.default.env.WEAPP_TAILWINDCSS_BASEDIR || _process2.default.env.WEAPP_TAILWINDCSS_BASE_DIR || _process2.default.env.TAILWINDCSS_BASEDIR || _process2.default.env.TAILWINDCSS_BASE_DIR);
|
|
924
|
-
}
|
|
925
|
-
function detectCallerLocation() {
|
|
926
|
-
const stack = new Error("compiler-context-cache stack probe").stack;
|
|
927
|
-
if (!stack) {
|
|
928
|
-
return void 0;
|
|
929
|
-
}
|
|
930
|
-
const lines = stack.split("\n");
|
|
931
|
-
for (const line of lines) {
|
|
932
|
-
const match = _nullishCoalesce(line.match(PAREN_CONTENT_RE), () => ( line.match(AT_LOCATION_RE)));
|
|
933
|
-
const location = _optionalChain([match, 'optionalAccess', _23 => _23[1]]);
|
|
934
|
-
if (!location) {
|
|
935
|
-
continue;
|
|
936
|
-
}
|
|
937
|
-
const candidatePath = location.replace(TRAILING_LINE_COL_RE, "");
|
|
938
|
-
if (!candidatePath || !_path2.default.isAbsolute(candidatePath)) {
|
|
939
|
-
continue;
|
|
940
|
-
}
|
|
941
|
-
if (candidatePath.includes(`${_path2.default.sep}weapp-tailwindcss${_path2.default.sep}src${_path2.default.sep}`) || candidatePath.includes(`${_path2.default.sep}weapp-tailwindcss${_path2.default.sep}dist${_path2.default.sep}`) || candidatePath.includes(`${_path2.default.sep}node_modules${_path2.default.sep}weapp-tailwindcss${_path2.default.sep}`)) {
|
|
942
|
-
continue;
|
|
943
|
-
}
|
|
944
|
-
return candidatePath;
|
|
945
|
-
}
|
|
946
|
-
return void 0;
|
|
947
|
-
}
|
|
948
|
-
function getRuntimeCacheScope(opts) {
|
|
949
|
-
if (hasExplicitOptionBasedir(opts)) {
|
|
950
|
-
return {
|
|
951
|
-
caller: void 0
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
const runtimeScope = {
|
|
955
|
-
caller: void 0,
|
|
956
|
-
cwd: _process2.default.cwd(),
|
|
957
|
-
init_cwd: _process2.default.env.INIT_CWD,
|
|
958
|
-
npm_config_local_prefix: _process2.default.env.npm_config_local_prefix,
|
|
959
|
-
npm_package_json: _process2.default.env.npm_package_json,
|
|
960
|
-
pnpm_package_name: _process2.default.env.PNPM_PACKAGE_NAME,
|
|
961
|
-
pwd: _process2.default.env.PWD,
|
|
962
|
-
tailwindcss_base_dir: _process2.default.env.TAILWINDCSS_BASE_DIR,
|
|
963
|
-
tailwindcss_basedir: _process2.default.env.TAILWINDCSS_BASEDIR,
|
|
964
|
-
uni_app_input_dir: _process2.default.env.UNI_APP_INPUT_DIR,
|
|
965
|
-
uni_cli_root: _process2.default.env.UNI_CLI_ROOT,
|
|
966
|
-
uni_input_dir: _process2.default.env.UNI_INPUT_DIR,
|
|
967
|
-
uni_input_root: _process2.default.env.UNI_INPUT_ROOT,
|
|
968
|
-
weapp_tailwindcss_base_dir: _process2.default.env.WEAPP_TAILWINDCSS_BASE_DIR,
|
|
969
|
-
weapp_tailwindcss_basedir: _process2.default.env.WEAPP_TAILWINDCSS_BASEDIR
|
|
970
|
-
};
|
|
971
|
-
if (shouldProbeCallerLocation(opts)) {
|
|
972
|
-
runtimeScope.caller = detectCallerLocation();
|
|
973
|
-
}
|
|
974
|
-
return runtimeScope;
|
|
975
|
-
}
|
|
976
|
-
function serializeNormalizedValue(value) {
|
|
977
|
-
return JSON.stringify(value);
|
|
978
|
-
}
|
|
979
|
-
function createRuntimeCacheScopeKey(opts) {
|
|
980
|
-
return serializeNormalizedValue(normalizeOptionsValue(getRuntimeCacheScope(opts)));
|
|
981
|
-
}
|
|
982
|
-
function getCompilerContextKeyCacheStore(opts) {
|
|
983
|
-
if (!opts) {
|
|
984
|
-
return compilerContextKeyCacheWithoutOptions;
|
|
985
|
-
}
|
|
986
|
-
let store = compilerContextKeyCacheByOptions.get(opts);
|
|
987
|
-
if (!store) {
|
|
988
|
-
store = /* @__PURE__ */ new Map();
|
|
989
|
-
compilerContextKeyCacheByOptions.set(opts, store);
|
|
990
|
-
}
|
|
991
|
-
return store;
|
|
992
|
-
}
|
|
993
|
-
function createComparableNormalizedValue(rawValue, stack) {
|
|
994
|
-
const normalized = normalizeOptionsValue(rawValue, stack);
|
|
995
|
-
return {
|
|
996
|
-
normalized,
|
|
997
|
-
sortKey: serializeNormalizedValue(normalized)
|
|
998
|
-
};
|
|
999
|
-
}
|
|
1000
|
-
function getRuntimeCacheScopeValue(opts) {
|
|
1001
|
-
return {
|
|
1002
|
-
options: _nullishCoalesce(opts, () => ( {})),
|
|
1003
|
-
runtime: getRuntimeCacheScope(opts)
|
|
1004
|
-
};
|
|
1005
|
-
}
|
|
1006
|
-
function normalizeOptionsValue(rawValue, stack = /* @__PURE__ */ new WeakSet()) {
|
|
1007
|
-
if (rawValue === null) {
|
|
1008
|
-
return null;
|
|
1009
|
-
}
|
|
1010
|
-
if (rawValue === void 0) {
|
|
1011
|
-
return encodeTaggedValue("Undefined");
|
|
1012
|
-
}
|
|
1013
|
-
const type = typeof rawValue;
|
|
1014
|
-
if (type === "string") {
|
|
1015
|
-
return rawValue;
|
|
1016
|
-
}
|
|
1017
|
-
if (type === "boolean") {
|
|
1018
|
-
return rawValue;
|
|
1019
|
-
}
|
|
1020
|
-
if (type === "number") {
|
|
1021
|
-
const numericValue = rawValue;
|
|
1022
|
-
if (Number.isNaN(numericValue)) {
|
|
1023
|
-
return encodeTaggedValue("Number", "NaN");
|
|
1024
|
-
}
|
|
1025
|
-
if (!Number.isFinite(numericValue)) {
|
|
1026
|
-
return encodeTaggedValue("Number", numericValue > 0 ? "Infinity" : "-Infinity");
|
|
1027
|
-
}
|
|
1028
|
-
if (Object.is(numericValue, -0)) {
|
|
1029
|
-
return encodeTaggedValue("Number", "-0");
|
|
1030
|
-
}
|
|
1031
|
-
return numericValue;
|
|
1032
|
-
}
|
|
1033
|
-
if (type === "bigint") {
|
|
1034
|
-
return encodeTaggedValue("BigInt", rawValue.toString());
|
|
1035
|
-
}
|
|
1036
|
-
if (type === "symbol") {
|
|
1037
|
-
const symbolValue = rawValue;
|
|
1038
|
-
return encodeTaggedValue("Symbol", _nullishCoalesce(symbolValue.description, () => ( String(symbolValue))));
|
|
1039
|
-
}
|
|
1040
|
-
if (type === "function") {
|
|
1041
|
-
return encodeTaggedValue("Function", rawValue.toString());
|
|
1042
|
-
}
|
|
1043
|
-
if (Array.isArray(rawValue)) {
|
|
1044
|
-
return withCircularGuard(rawValue, stack, () => rawValue.map((item) => normalizeOptionsValue(item, stack)));
|
|
1045
|
-
}
|
|
1046
|
-
if (rawValue instanceof Date) {
|
|
1047
|
-
return encodeTaggedValue("Date", rawValue.toISOString());
|
|
1048
|
-
}
|
|
1049
|
-
if (rawValue instanceof RegExp) {
|
|
1050
|
-
return {
|
|
1051
|
-
__type: "RegExp",
|
|
1052
|
-
source: rawValue.source,
|
|
1053
|
-
flags: rawValue.flags
|
|
1054
|
-
};
|
|
1055
|
-
}
|
|
1056
|
-
if (typeof _buffer.Buffer !== "undefined" && _buffer.Buffer.isBuffer(rawValue)) {
|
|
1057
|
-
return encodeTaggedValue("Buffer", rawValue.toString("base64"));
|
|
1058
|
-
}
|
|
1059
|
-
if (ArrayBuffer.isView(rawValue)) {
|
|
1060
|
-
const view = rawValue;
|
|
1061
|
-
const buffer = _buffer.Buffer.from(view.buffer, view.byteOffset, view.byteLength);
|
|
1062
|
-
return encodeTaggedValue(_nullishCoalesce(_optionalChain([view, 'access', _24 => _24.constructor, 'optionalAccess', _25 => _25.name]), () => ( "ArrayBufferView")), buffer.toString("base64"));
|
|
1063
|
-
}
|
|
1064
|
-
if (rawValue instanceof ArrayBuffer) {
|
|
1065
|
-
return encodeTaggedValue("ArrayBuffer", _buffer.Buffer.from(rawValue).toString("base64"));
|
|
1066
|
-
}
|
|
1067
|
-
if (rawValue instanceof Set) {
|
|
1068
|
-
return withCircularGuard(rawValue, stack, () => {
|
|
1069
|
-
const normalizedEntries = Array.from(rawValue, (element) => createComparableNormalizedValue(element, stack));
|
|
1070
|
-
normalizedEntries.sort((a, b) => a.sortKey.localeCompare(b.sortKey));
|
|
1071
|
-
return {
|
|
1072
|
-
__type: "Set",
|
|
1073
|
-
value: normalizedEntries.map((entry) => entry.normalized)
|
|
1074
|
-
};
|
|
1075
|
-
});
|
|
1076
|
-
}
|
|
1077
|
-
if (rawValue instanceof Map) {
|
|
1078
|
-
return withCircularGuard(rawValue, stack, () => {
|
|
1079
|
-
const normalizedEntries = Array.from(rawValue.entries(), ([key, entryValue]) => {
|
|
1080
|
-
const normalizedKey = createComparableNormalizedValue(key, stack);
|
|
1081
|
-
return {
|
|
1082
|
-
key: normalizedKey.normalized,
|
|
1083
|
-
sortKey: normalizedKey.sortKey,
|
|
1084
|
-
value: normalizeOptionsValue(entryValue, stack)
|
|
1085
|
-
};
|
|
1086
|
-
});
|
|
1087
|
-
normalizedEntries.sort((a, b) => a.sortKey.localeCompare(b.sortKey));
|
|
1088
|
-
return {
|
|
1089
|
-
__type: "Map",
|
|
1090
|
-
value: normalizedEntries.map((entry) => [entry.key, entry.value])
|
|
1091
|
-
};
|
|
1092
|
-
});
|
|
1093
|
-
}
|
|
1094
|
-
if (typeof URL !== "undefined" && rawValue instanceof URL) {
|
|
1095
|
-
return encodeTaggedValue("URL", rawValue.toString());
|
|
1096
|
-
}
|
|
1097
|
-
if (rawValue instanceof Error) {
|
|
1098
|
-
const errorValue = rawValue;
|
|
1099
|
-
return {
|
|
1100
|
-
__type: "Error",
|
|
1101
|
-
name: errorValue.name,
|
|
1102
|
-
message: errorValue.message,
|
|
1103
|
-
stack: _nullishCoalesce(errorValue.stack, () => ( ""))
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
if (rawValue instanceof Promise) {
|
|
1107
|
-
return encodeTaggedValue("Promise");
|
|
1108
|
-
}
|
|
1109
|
-
if (rawValue instanceof WeakMap) {
|
|
1110
|
-
return encodeTaggedValue("WeakMap");
|
|
1111
|
-
}
|
|
1112
|
-
if (rawValue instanceof WeakSet) {
|
|
1113
|
-
return encodeTaggedValue("WeakSet");
|
|
1114
|
-
}
|
|
1115
|
-
if (rawValue && typeof rawValue === "object") {
|
|
1116
|
-
return withCircularGuard(rawValue, stack, () => {
|
|
1117
|
-
const result = {};
|
|
1118
|
-
const entries = Object.entries(rawValue);
|
|
1119
|
-
entries.sort(([a], [b]) => a.localeCompare(b));
|
|
1120
|
-
for (const [key, entryValue] of entries) {
|
|
1121
|
-
result[key] = normalizeOptionsValue(entryValue, stack);
|
|
1122
|
-
}
|
|
1123
|
-
return result;
|
|
1124
|
-
});
|
|
1125
|
-
}
|
|
1126
|
-
return encodeTaggedValue(typeof rawValue, String(rawValue));
|
|
1127
|
-
}
|
|
1128
|
-
function createCompilerContextCacheKey(opts) {
|
|
1129
|
-
try {
|
|
1130
|
-
const runtimeCacheScopeKey = createRuntimeCacheScopeKey(opts);
|
|
1131
|
-
const keyStore = getCompilerContextKeyCacheStore(opts);
|
|
1132
|
-
const cached = keyStore.get(runtimeCacheScopeKey);
|
|
1133
|
-
if (cached !== void 0) {
|
|
1134
|
-
return cached;
|
|
1135
|
-
}
|
|
1136
|
-
const normalized = normalizeOptionsValue(getRuntimeCacheScopeValue(opts));
|
|
1137
|
-
const cacheKey = _node.md5.call(void 0, serializeNormalizedValue(normalized));
|
|
1138
|
-
keyStore.set(runtimeCacheScopeKey, cacheKey);
|
|
1139
|
-
return cacheKey;
|
|
1140
|
-
} catch (error) {
|
|
1141
|
-
_logger.logger.debug("skip compiler context cache: %O", error);
|
|
1142
|
-
return void 0;
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
function withCompilerContextCache(opts, factory) {
|
|
1146
|
-
const cacheKey = createCompilerContextCacheKey(opts);
|
|
1147
|
-
if (cacheKey) {
|
|
1148
|
-
const cached = compilerContextCache.get(cacheKey);
|
|
1149
|
-
if (cached) {
|
|
1150
|
-
return cached;
|
|
1151
|
-
}
|
|
1152
|
-
}
|
|
1153
|
-
const ctx = factory();
|
|
1154
|
-
if (cacheKey) {
|
|
1155
|
-
compilerContextCache.set(cacheKey, ctx);
|
|
1156
|
-
}
|
|
1157
|
-
return ctx;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
// src/context/custom-attributes.ts
|
|
1161
|
-
function toCustomAttributesEntities(customAttributes) {
|
|
1162
|
-
if (!customAttributes) {
|
|
1163
|
-
return [];
|
|
1164
|
-
}
|
|
1165
|
-
if (_chunkDYLQ6UOIjs.isMap.call(void 0, customAttributes)) {
|
|
1166
|
-
return [
|
|
1167
|
-
...customAttributes.entries()
|
|
1168
|
-
];
|
|
1169
|
-
}
|
|
1170
|
-
return Object.entries(customAttributes);
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
// src/context/handlers.ts
|
|
1174
|
-
var _postcss = require('@weapp-tailwindcss/postcss');
|
|
1175
|
-
|
|
1176
|
-
// src/js/index.ts
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
// src/babel/index.ts
|
|
1180
|
-
var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
|
|
1181
|
-
var _parser = require('@babel/parser');
|
|
1182
|
-
function _interopDefaultCompat(e) {
|
|
1183
|
-
return e && typeof e === "object" && "default" in e ? e.default : e;
|
|
1184
|
-
}
|
|
1185
|
-
var traverse = _interopDefaultCompat(_traverse2.default);
|
|
1186
|
-
|
|
1187
|
-
// src/utils/nameMatcher.ts
|
|
1188
|
-
var _regex = require('@weapp-core/regex');
|
|
1189
|
-
var NEVER_MATCH_NAME = () => false;
|
|
1190
|
-
var GLOBAL_FLAG_REGEXP = /g/g;
|
|
1191
|
-
function buildFuzzyMatcher(fuzzyStrings) {
|
|
1192
|
-
if (fuzzyStrings.length === 0) {
|
|
1193
|
-
return void 0;
|
|
1194
|
-
}
|
|
1195
|
-
if (fuzzyStrings.length === 1) {
|
|
1196
|
-
const [needle] = fuzzyStrings;
|
|
1197
|
-
return (value) => value.includes(needle);
|
|
1198
|
-
}
|
|
1199
|
-
const unique = [...new Set(fuzzyStrings)];
|
|
1200
|
-
const pattern = new RegExp(unique.map(_regex.escapeStringRegexp).join("|"));
|
|
1201
|
-
return (value) => pattern.test(value);
|
|
1202
|
-
}
|
|
1203
|
-
function normaliseRegex(regex) {
|
|
1204
|
-
const { source, flags } = regex;
|
|
1205
|
-
if (!flags.includes("g")) {
|
|
1206
|
-
return regex;
|
|
1207
|
-
}
|
|
1208
|
-
return new RegExp(source, flags.replace(GLOBAL_FLAG_REGEXP, ""));
|
|
1209
|
-
}
|
|
1210
|
-
function createNameMatcher(list, { exact = false } = {}) {
|
|
1211
|
-
if (!list || list.length === 0) {
|
|
1212
|
-
return NEVER_MATCH_NAME;
|
|
1213
|
-
}
|
|
1214
|
-
const exactStrings = exact ? /* @__PURE__ */ new Set() : void 0;
|
|
1215
|
-
const fuzzyStrings = [];
|
|
1216
|
-
const regexList = [];
|
|
1217
|
-
for (const item of list) {
|
|
1218
|
-
if (typeof item === "string") {
|
|
1219
|
-
if (exact) {
|
|
1220
|
-
exactStrings.add(item);
|
|
1221
|
-
} else {
|
|
1222
|
-
fuzzyStrings.push(item);
|
|
1223
|
-
}
|
|
1224
|
-
} else {
|
|
1225
|
-
regexList.push(normaliseRegex(item));
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
if (exact) {
|
|
1229
|
-
const exactStringCount = _nullishCoalesce(_optionalChain([exactStrings, 'optionalAccess', _26 => _26.size]), () => ( 0));
|
|
1230
|
-
if (exactStringCount === 1 && regexList.length === 0) {
|
|
1231
|
-
const [needle] = exactStrings;
|
|
1232
|
-
return (value) => value === needle;
|
|
1233
|
-
}
|
|
1234
|
-
if (regexList.length === 0) {
|
|
1235
|
-
return (value) => exactStrings.has(value);
|
|
1236
|
-
}
|
|
1237
|
-
if (exactStringCount === 0 && regexList.length === 1) {
|
|
1238
|
-
const [regex] = regexList;
|
|
1239
|
-
return (value) => regex.test(value);
|
|
1240
|
-
}
|
|
1241
|
-
return (value) => {
|
|
1242
|
-
if (_optionalChain([exactStrings, 'optionalAccess', _27 => _27.has, 'call', _28 => _28(value)])) {
|
|
1243
|
-
return true;
|
|
1244
|
-
}
|
|
1245
|
-
return regexList.some((regex) => regex.test(value));
|
|
1246
|
-
};
|
|
1247
|
-
}
|
|
1248
|
-
const fuzzyMatcher = exact ? void 0 : buildFuzzyMatcher(fuzzyStrings);
|
|
1249
|
-
const hasRegex = regexList.length > 0;
|
|
1250
|
-
if (fuzzyMatcher && !hasRegex) {
|
|
1251
|
-
return fuzzyMatcher;
|
|
1252
|
-
}
|
|
1253
|
-
if (!fuzzyMatcher && regexList.length === 1) {
|
|
1254
|
-
const [regex] = regexList;
|
|
1255
|
-
return (value) => regex.test(value);
|
|
1256
|
-
}
|
|
1257
|
-
return (value) => {
|
|
1258
|
-
if (_optionalChain([fuzzyMatcher, 'optionalCall', _29 => _29(value)])) {
|
|
1259
|
-
return true;
|
|
1260
|
-
}
|
|
1261
|
-
if (!hasRegex) {
|
|
1262
|
-
return false;
|
|
1263
|
-
}
|
|
1264
|
-
return regexList.some((regex) => regex.test(value));
|
|
1265
|
-
};
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
// src/js/babel/parse.ts
|
|
1269
|
-
|
|
1270
|
-
var parseCache = new (0, _lrucache.LRUCache)(
|
|
1271
|
-
{
|
|
1272
|
-
max: 1024
|
|
1273
|
-
}
|
|
1274
|
-
);
|
|
1275
|
-
function genCacheKey(source, options) {
|
|
1276
|
-
if (typeof options === "string") {
|
|
1277
|
-
return source + options;
|
|
1278
|
-
}
|
|
1279
|
-
return source + JSON.stringify(options, (_, val) => typeof val === "function" ? val.toString() : val);
|
|
1280
|
-
}
|
|
1281
|
-
function babelParse(code, opts = {}) {
|
|
1282
|
-
const { cache, cacheKey, ...rest } = opts;
|
|
1283
|
-
const cacheKeyString = genCacheKey(code, _nullishCoalesce(cacheKey, () => ( rest)));
|
|
1284
|
-
let result;
|
|
1285
|
-
if (cache) {
|
|
1286
|
-
result = parseCache.get(cacheKeyString);
|
|
1287
|
-
}
|
|
1288
|
-
if (!result) {
|
|
1289
|
-
const { cache: _cache, cacheKey: _cacheKey, ...parseOptions } = opts;
|
|
1290
|
-
result = _parser.parse.call(void 0, code, parseOptions);
|
|
1291
|
-
if (cache) {
|
|
1292
|
-
parseCache.set(cacheKeyString, result);
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
return result;
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
// src/js/babel/process.ts
|
|
1299
|
-
var _magicstring = require('magic-string'); var _magicstring2 = _interopRequireDefault(_magicstring);
|
|
1300
|
-
|
|
1301
|
-
// src/js/handlers.ts
|
|
1302
|
-
var _escape = require('@ast-core/escape');
|
|
1303
|
-
var _extractors = require('@weapp-tailwindcss/shared/extractors');
|
|
1304
|
-
|
|
1305
|
-
// src/wxml/shared.ts
|
|
1306
|
-
var _escape3 = require('@weapp-core/escape');
|
|
1307
|
-
var NEWLINE_RE = /[\n\r]+/g;
|
|
1308
|
-
function replaceWxml(original, options = {
|
|
1309
|
-
keepEOL: false,
|
|
1310
|
-
escapeMap: _escape3.MappingChars2String
|
|
1311
|
-
}) {
|
|
1312
|
-
const { keepEOL, escapeMap, ignoreHead } = options;
|
|
1313
|
-
let res = original;
|
|
1314
|
-
if (!keepEOL) {
|
|
1315
|
-
res = res.replaceAll(NEWLINE_RE, "");
|
|
1316
|
-
}
|
|
1317
|
-
res = _escape3.escape.call(void 0, res, {
|
|
1318
|
-
map: escapeMap,
|
|
1319
|
-
ignoreHead
|
|
1320
|
-
});
|
|
1321
|
-
return res;
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
// src/shared/classname-transform.ts
|
|
1325
|
-
var escapedCandidateCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
|
|
1326
|
-
var defaultEscapedCandidateCache = /* @__PURE__ */ new Map();
|
|
1327
|
-
var lastEscapedCandidateEscapeMap;
|
|
1328
|
-
var lastEscapedCandidateCacheStore;
|
|
1329
|
-
function isUrlLikeCandidate(candidate) {
|
|
1330
|
-
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
1331
|
-
}
|
|
1332
|
-
function isArbitraryValueCandidate(candidate) {
|
|
1333
|
-
let hasOpenBracket = false;
|
|
1334
|
-
let hasCloseBracket = false;
|
|
1335
|
-
for (let i = 0; i < candidate.length; i++) {
|
|
1336
|
-
const char = candidate[i];
|
|
1337
|
-
if (char === "[") {
|
|
1338
|
-
hasOpenBracket = true;
|
|
1339
|
-
} else if (char === "]") {
|
|
1340
|
-
hasCloseBracket = true;
|
|
1341
|
-
}
|
|
1342
|
-
if (hasOpenBracket && hasCloseBracket) {
|
|
1343
|
-
break;
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
if (!hasOpenBracket || !hasCloseBracket) {
|
|
1347
|
-
return false;
|
|
1348
|
-
}
|
|
1349
|
-
const normalized = candidate.trim();
|
|
1350
|
-
if (isUrlLikeCandidate(normalized)) {
|
|
1351
|
-
return false;
|
|
1352
|
-
}
|
|
1353
|
-
return true;
|
|
1354
|
-
}
|
|
1355
|
-
function shouldEnableArbitraryValueFallbackByInputs(classNameSet, jsArbitraryValueFallback, tailwindcssMajorVersion) {
|
|
1356
|
-
if (jsArbitraryValueFallback === true) {
|
|
1357
|
-
return true;
|
|
1358
|
-
}
|
|
1359
|
-
if (jsArbitraryValueFallback === false) {
|
|
1360
|
-
return false;
|
|
1361
|
-
}
|
|
1362
|
-
return tailwindcssMajorVersion === 4 && (!classNameSet || classNameSet.size === 0);
|
|
1363
|
-
}
|
|
1364
|
-
function shouldEnableArbitraryValueFallback({
|
|
1365
|
-
classNameSet,
|
|
1366
|
-
jsArbitraryValueFallback,
|
|
1367
|
-
tailwindcssMajorVersion
|
|
1368
|
-
}) {
|
|
1369
|
-
return shouldEnableArbitraryValueFallbackByInputs(
|
|
1370
|
-
classNameSet,
|
|
1371
|
-
jsArbitraryValueFallback,
|
|
1372
|
-
tailwindcssMajorVersion
|
|
1373
|
-
);
|
|
1374
|
-
}
|
|
1375
|
-
var SKIP_RESULT = { decision: "skip" };
|
|
1376
|
-
var DIRECT_RESULT = { decision: "direct" };
|
|
1377
|
-
var FALLBACK_RESULT = { decision: "fallback" };
|
|
1378
|
-
function getEscapedCandidateCacheStore(escapeMap) {
|
|
1379
|
-
if (!escapeMap) {
|
|
1380
|
-
return defaultEscapedCandidateCache;
|
|
1381
|
-
}
|
|
1382
|
-
if (escapeMap === lastEscapedCandidateEscapeMap && lastEscapedCandidateCacheStore) {
|
|
1383
|
-
return lastEscapedCandidateCacheStore;
|
|
1384
|
-
}
|
|
1385
|
-
let store = escapedCandidateCacheByEscapeMap.get(escapeMap);
|
|
1386
|
-
if (!store) {
|
|
1387
|
-
store = /* @__PURE__ */ new Map();
|
|
1388
|
-
escapedCandidateCacheByEscapeMap.set(escapeMap, store);
|
|
1389
|
-
}
|
|
1390
|
-
lastEscapedCandidateEscapeMap = escapeMap;
|
|
1391
|
-
lastEscapedCandidateCacheStore = store;
|
|
1392
|
-
return store;
|
|
1393
|
-
}
|
|
1394
|
-
function getEscapedCandidate(candidate, escapeMap, store = getEscapedCandidateCacheStore(escapeMap)) {
|
|
1395
|
-
let cached = store.get(candidate);
|
|
1396
|
-
if (cached === void 0) {
|
|
1397
|
-
cached = replaceWxml(candidate, { escapeMap });
|
|
1398
|
-
store.set(candidate, cached);
|
|
1399
|
-
}
|
|
1400
|
-
return cached;
|
|
1401
|
-
}
|
|
1402
|
-
function resolveClassNameTransformWithResult(candidate, {
|
|
1403
|
-
alwaysEscape,
|
|
1404
|
-
classNameSet,
|
|
1405
|
-
escapeMap,
|
|
1406
|
-
jsArbitraryValueFallback,
|
|
1407
|
-
jsPreserveClass,
|
|
1408
|
-
tailwindcssMajorVersion,
|
|
1409
|
-
classContext
|
|
1410
|
-
}) {
|
|
1411
|
-
if (alwaysEscape) {
|
|
1412
|
-
return DIRECT_RESULT;
|
|
1413
|
-
}
|
|
1414
|
-
if (_optionalChain([jsPreserveClass, 'optionalCall', _30 => _30(candidate)])) {
|
|
1415
|
-
return SKIP_RESULT;
|
|
1416
|
-
}
|
|
1417
|
-
if (_optionalChain([classNameSet, 'optionalAccess', _31 => _31.has, 'call', _32 => _32(candidate)])) {
|
|
1418
|
-
return DIRECT_RESULT;
|
|
1419
|
-
}
|
|
1420
|
-
if (classNameSet && classNameSet.size > 0) {
|
|
1421
|
-
const escapedCandidate = getEscapedCandidate(candidate, escapeMap);
|
|
1422
|
-
if (escapedCandidate !== candidate && classNameSet.has(escapedCandidate)) {
|
|
1423
|
-
return { decision: "escaped", escapedValue: escapedCandidate };
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
if (classContext && shouldEnableArbitraryValueFallbackByInputs(classNameSet, jsArbitraryValueFallback, tailwindcssMajorVersion) && isArbitraryValueCandidate(candidate)) {
|
|
1427
|
-
return FALLBACK_RESULT;
|
|
1428
|
-
}
|
|
1429
|
-
return SKIP_RESULT;
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
// src/utils/decode.ts
|
|
1433
|
-
var unicodeEscapeRE = /\\u([\dA-Fa-f]{4})/g;
|
|
1434
|
-
var unicodeEscapeTestRE = /\\u[\dA-Fa-f]{4}/;
|
|
1435
|
-
function decodeUnicode(value) {
|
|
1436
|
-
if (!unicodeEscapeTestRE.test(value)) {
|
|
1437
|
-
return value;
|
|
1438
|
-
}
|
|
1439
|
-
return value.replace(unicodeEscapeRE, (_match, hex) => {
|
|
1440
|
-
const codePoint = Number.parseInt(hex, 16);
|
|
1441
|
-
return Number.isNaN(codePoint) ? _match : String.fromCharCode(codePoint);
|
|
1442
|
-
});
|
|
1443
|
-
}
|
|
1444
|
-
function decodeUnicode2(input) {
|
|
1445
|
-
if (!unicodeEscapeTestRE.test(input)) {
|
|
1446
|
-
return input;
|
|
1447
|
-
}
|
|
1448
|
-
try {
|
|
1449
|
-
return JSON.parse(`"${input}"`);
|
|
1450
|
-
} catch (_error) {
|
|
1451
|
-
return decodeUnicode(input);
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
|
|
1455
|
-
// src/js/class-context.ts
|
|
1456
|
-
var CLASS_LIKE_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1457
|
-
"class",
|
|
1458
|
-
"classname",
|
|
1459
|
-
"hoverclass",
|
|
1460
|
-
"virtualhostclass",
|
|
1461
|
-
"rootclass"
|
|
1462
|
-
]);
|
|
1463
|
-
var CLASS_HELPER_IDENTIFIERS = /* @__PURE__ */ new Set([
|
|
1464
|
-
"cn",
|
|
1465
|
-
"clsx",
|
|
1466
|
-
"classnames",
|
|
1467
|
-
"twmerge",
|
|
1468
|
-
"cva",
|
|
1469
|
-
"tv",
|
|
1470
|
-
"cx",
|
|
1471
|
-
"r"
|
|
1472
|
-
]);
|
|
1473
|
-
var DASH_CODE = 45;
|
|
1474
|
-
var COLON_CODE = 58;
|
|
1475
|
-
var UPPERCASE_A_CODE = 65;
|
|
1476
|
-
var UPPERCASE_Z_CODE = 90;
|
|
1477
|
-
var UNDERSCORE_CODE = 95;
|
|
1478
|
-
var ASCII_MAX_CODE = 127;
|
|
1479
|
-
var NORMALIZE_KEYWORD_REGEXP = /[-_:]/g;
|
|
1480
|
-
function normalizeKeyword(name) {
|
|
1481
|
-
const length = name.length;
|
|
1482
|
-
let firstNormalizedIndex = -1;
|
|
1483
|
-
for (let i = 0; i < length; i++) {
|
|
1484
|
-
const code = name.charCodeAt(i);
|
|
1485
|
-
if (code === DASH_CODE || code === UNDERSCORE_CODE || code === COLON_CODE || code >= UPPERCASE_A_CODE && code <= UPPERCASE_Z_CODE) {
|
|
1486
|
-
firstNormalizedIndex = i;
|
|
1487
|
-
break;
|
|
1488
|
-
}
|
|
1489
|
-
if (code > ASCII_MAX_CODE) {
|
|
1490
|
-
return name.replace(NORMALIZE_KEYWORD_REGEXP, "").toLowerCase();
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
if (firstNormalizedIndex === -1) {
|
|
1494
|
-
return name;
|
|
1495
|
-
}
|
|
1496
|
-
let normalized = name.slice(0, firstNormalizedIndex);
|
|
1497
|
-
for (let i = firstNormalizedIndex; i < length; i++) {
|
|
1498
|
-
const code = name.charCodeAt(i);
|
|
1499
|
-
if (code === DASH_CODE || code === UNDERSCORE_CODE || code === COLON_CODE) {
|
|
1500
|
-
continue;
|
|
1501
|
-
}
|
|
1502
|
-
if (code >= UPPERCASE_A_CODE && code <= UPPERCASE_Z_CODE) {
|
|
1503
|
-
normalized += String.fromCharCode(code + 32);
|
|
1504
|
-
continue;
|
|
1505
|
-
}
|
|
1506
|
-
if (code > ASCII_MAX_CODE) {
|
|
1507
|
-
return name.replace(NORMALIZE_KEYWORD_REGEXP, "").toLowerCase();
|
|
1508
|
-
}
|
|
1509
|
-
normalized += name[i];
|
|
1510
|
-
}
|
|
1511
|
-
return normalized;
|
|
1512
|
-
}
|
|
1513
|
-
function readObjectKeyName(path5) {
|
|
1514
|
-
if (path5.isIdentifier()) {
|
|
1515
|
-
return path5.node.name;
|
|
1516
|
-
}
|
|
1517
|
-
if (path5.isStringLiteral()) {
|
|
1518
|
-
return path5.node.value;
|
|
1519
|
-
}
|
|
1520
|
-
if (path5.isTemplateLiteral() && path5.node.expressions.length === 0) {
|
|
1521
|
-
return _nullishCoalesce(_optionalChain([path5, 'access', _33 => _33.node, 'access', _34 => _34.quasis, 'access', _35 => _35[0], 'optionalAccess', _36 => _36.value, 'access', _37 => _37.cooked]), () => ( _optionalChain([path5, 'access', _38 => _38.node, 'access', _39 => _39.quasis, 'access', _40 => _40[0], 'optionalAccess', _41 => _41.value, 'access', _42 => _42.raw])));
|
|
1522
|
-
}
|
|
1523
|
-
return void 0;
|
|
1524
|
-
}
|
|
1525
|
-
function isClassLikeObjectProperty(path5, valuePath) {
|
|
1526
|
-
if (!path5.isObjectProperty()) {
|
|
1527
|
-
return false;
|
|
1528
|
-
}
|
|
1529
|
-
if (path5.get("value") !== valuePath) {
|
|
1530
|
-
return false;
|
|
1531
|
-
}
|
|
1532
|
-
const keyName = readObjectKeyName(path5.get("key"));
|
|
1533
|
-
if (!keyName) {
|
|
1534
|
-
return false;
|
|
1535
|
-
}
|
|
1536
|
-
return CLASS_LIKE_KEYWORDS.has(normalizeKeyword(keyName));
|
|
1537
|
-
}
|
|
1538
|
-
function isClassLikeJsxAttribute(path5) {
|
|
1539
|
-
if (!path5.isJSXAttribute()) {
|
|
1540
|
-
return false;
|
|
1541
|
-
}
|
|
1542
|
-
const namePath = path5.get("name");
|
|
1543
|
-
if (!namePath.isJSXIdentifier()) {
|
|
1544
|
-
return false;
|
|
1545
|
-
}
|
|
1546
|
-
return CLASS_LIKE_KEYWORDS.has(normalizeKeyword(namePath.node.name));
|
|
1547
|
-
}
|
|
1548
|
-
function readCallHelperName(calleePath) {
|
|
1549
|
-
if (calleePath.isIdentifier()) {
|
|
1550
|
-
return calleePath.node.name;
|
|
1551
|
-
}
|
|
1552
|
-
if (calleePath.isMemberExpression()) {
|
|
1553
|
-
const propertyPath = calleePath.get("property");
|
|
1554
|
-
if (propertyPath.isIdentifier()) {
|
|
1555
|
-
return propertyPath.node.name;
|
|
1556
|
-
}
|
|
1557
|
-
if (propertyPath.isStringLiteral()) {
|
|
1558
|
-
return propertyPath.node.value;
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
return void 0;
|
|
1562
|
-
}
|
|
1563
|
-
function isClassLikeCallExpression(path5, valuePath) {
|
|
1564
|
-
if (!path5.isCallExpression()) {
|
|
1565
|
-
return false;
|
|
1566
|
-
}
|
|
1567
|
-
const helperName = readCallHelperName(path5.get("callee"));
|
|
1568
|
-
if (!helperName || !CLASS_HELPER_IDENTIFIERS.has(normalizeKeyword(helperName))) {
|
|
1569
|
-
return false;
|
|
1570
|
-
}
|
|
1571
|
-
return path5.get("arguments").some((argumentPath) => argumentPath.node === valuePath.node);
|
|
1572
|
-
}
|
|
1573
|
-
function isClassContextLiteralPath(path5) {
|
|
1574
|
-
let current = path5;
|
|
1575
|
-
while (current.parentPath) {
|
|
1576
|
-
const parent = current.parentPath;
|
|
1577
|
-
if (isClassLikeObjectProperty(parent, current)) {
|
|
1578
|
-
return true;
|
|
1579
|
-
}
|
|
1580
|
-
if (isClassLikeJsxAttribute(parent)) {
|
|
1581
|
-
return true;
|
|
1582
|
-
}
|
|
1583
|
-
if (isClassLikeCallExpression(parent, current)) {
|
|
1584
|
-
return true;
|
|
1585
|
-
}
|
|
1586
|
-
current = parent;
|
|
1587
|
-
}
|
|
1588
|
-
return false;
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
// src/js/handlers.ts
|
|
1592
|
-
var debug2 = createDebug("[js:handlers] ");
|
|
1593
|
-
var replacementCacheByEscapeMap = /* @__PURE__ */ new WeakMap();
|
|
1594
|
-
var defaultReplacementCache = /* @__PURE__ */ new Map();
|
|
1595
|
-
var WEAPP_TW_IGNORE_MARKER = "weapp-tw";
|
|
1596
|
-
var IGNORE_MARKER = "ignore";
|
|
1597
|
-
function getReplacementCacheStore(escapeMap) {
|
|
1598
|
-
if (!escapeMap) {
|
|
1599
|
-
return defaultReplacementCache;
|
|
1600
|
-
}
|
|
1601
|
-
let store = replacementCacheByEscapeMap.get(escapeMap);
|
|
1602
|
-
if (!store) {
|
|
1603
|
-
store = /* @__PURE__ */ new Map();
|
|
1604
|
-
replacementCacheByEscapeMap.set(escapeMap, store);
|
|
1605
|
-
}
|
|
1606
|
-
return store;
|
|
1607
|
-
}
|
|
1608
|
-
function getReplacement(candidate, escapeMap, store = getReplacementCacheStore(escapeMap)) {
|
|
1609
|
-
let cached = store.get(candidate);
|
|
1610
|
-
if (cached === void 0) {
|
|
1611
|
-
cached = replaceWxml(candidate, { escapeMap });
|
|
1612
|
-
store.set(candidate, cached);
|
|
1613
|
-
}
|
|
1614
|
-
return cached;
|
|
1615
|
-
}
|
|
1616
|
-
function hasIgnoreComment(node) {
|
|
1617
|
-
const { leadingComments } = node;
|
|
1618
|
-
if (!Array.isArray(leadingComments) || leadingComments.length === 0) {
|
|
1619
|
-
return false;
|
|
1620
|
-
}
|
|
1621
|
-
for (const comment of leadingComments) {
|
|
1622
|
-
const { value } = comment;
|
|
1623
|
-
if (value.includes(WEAPP_TW_IGNORE_MARKER) && value.includes(IGNORE_MARKER)) {
|
|
1624
|
-
return true;
|
|
1625
|
-
}
|
|
1626
|
-
}
|
|
1627
|
-
return false;
|
|
1628
|
-
}
|
|
1629
|
-
function extractLiteralValue(path5, { unescapeUnicode, arbitraryValues }) {
|
|
1630
|
-
const allowDoubleQuotes = _optionalChain([arbitraryValues, 'optionalAccess', _43 => _43.allowDoubleQuotes]);
|
|
1631
|
-
const { node } = path5;
|
|
1632
|
-
let offset = 0;
|
|
1633
|
-
let original;
|
|
1634
|
-
if (node.type === "StringLiteral") {
|
|
1635
|
-
offset = 1;
|
|
1636
|
-
original = node.value;
|
|
1637
|
-
} else if (node.type === "TemplateElement") {
|
|
1638
|
-
original = node.value.raw;
|
|
1639
|
-
} else {
|
|
1640
|
-
original = "";
|
|
1641
|
-
}
|
|
1642
|
-
let literal = original;
|
|
1643
|
-
if (unescapeUnicode && original.includes("\\u")) {
|
|
1644
|
-
literal = decodeUnicode2(original);
|
|
1645
|
-
}
|
|
1646
|
-
return {
|
|
1647
|
-
allowDoubleQuotes,
|
|
1648
|
-
literal,
|
|
1649
|
-
offset,
|
|
1650
|
-
original
|
|
1651
|
-
};
|
|
1652
|
-
}
|
|
1653
|
-
function createCandidatePlanResolver(options, classContext) {
|
|
1654
|
-
const { escapeMap } = options;
|
|
1655
|
-
const replacementCache = getReplacementCacheStore(escapeMap);
|
|
1656
|
-
const transformOptions = classContext ? {
|
|
1657
|
-
...options,
|
|
1658
|
-
classContext
|
|
1659
|
-
} : options;
|
|
1660
|
-
let firstCandidate = "";
|
|
1661
|
-
let firstPlan;
|
|
1662
|
-
let cache;
|
|
1663
|
-
const buildCandidatePlan = (candidate) => {
|
|
1664
|
-
const result = resolveClassNameTransformWithResult(candidate, transformOptions);
|
|
1665
|
-
if (result.decision === "skip") {
|
|
1666
|
-
return { result };
|
|
1667
|
-
}
|
|
1668
|
-
let replacement;
|
|
1669
|
-
if (result.decision === "escaped" && result.escapedValue) {
|
|
1670
|
-
replacement = result.escapedValue;
|
|
1671
|
-
replacementCache.set(candidate, replacement);
|
|
1672
|
-
} else {
|
|
1673
|
-
replacement = getReplacement(candidate, escapeMap, replacementCache);
|
|
1674
|
-
}
|
|
1675
|
-
return {
|
|
1676
|
-
result,
|
|
1677
|
-
replacement
|
|
1678
|
-
};
|
|
1679
|
-
};
|
|
1680
|
-
return (candidate) => {
|
|
1681
|
-
if (cache) {
|
|
1682
|
-
const cached = cache.get(candidate);
|
|
1683
|
-
if (cached) {
|
|
1684
|
-
return cached;
|
|
1685
|
-
}
|
|
1686
|
-
} else if (firstPlan && candidate === firstCandidate) {
|
|
1687
|
-
return firstPlan;
|
|
1688
|
-
}
|
|
1689
|
-
const plan = buildCandidatePlan(candidate);
|
|
1690
|
-
if (!firstPlan) {
|
|
1691
|
-
firstCandidate = candidate;
|
|
1692
|
-
firstPlan = plan;
|
|
1693
|
-
return plan;
|
|
1694
|
-
}
|
|
1695
|
-
if (!cache) {
|
|
1696
|
-
cache = /* @__PURE__ */ new Map();
|
|
1697
|
-
cache.set(firstCandidate, firstPlan);
|
|
1698
|
-
}
|
|
1699
|
-
cache.set(candidate, plan);
|
|
1700
|
-
return plan;
|
|
1701
|
-
};
|
|
1702
|
-
}
|
|
1703
|
-
function replaceHandleValue(path5, options) {
|
|
1704
|
-
const { needEscaped = false } = options;
|
|
1705
|
-
const { classNameSet, alwaysEscape } = options;
|
|
1706
|
-
const fallbackEnabled = shouldEnableArbitraryValueFallback(options);
|
|
1707
|
-
if (!alwaysEscape && !fallbackEnabled && (!classNameSet || classNameSet.size === 0)) {
|
|
1708
|
-
return void 0;
|
|
1709
|
-
}
|
|
1710
|
-
if (hasIgnoreComment(path5.node)) {
|
|
1711
|
-
return void 0;
|
|
1712
|
-
}
|
|
1713
|
-
const { literal, original, allowDoubleQuotes, offset } = extractLiteralValue(path5, options);
|
|
1714
|
-
const candidates = _extractors.splitCode.call(void 0, literal, allowDoubleQuotes);
|
|
1715
|
-
if (candidates.length === 0) {
|
|
1716
|
-
return void 0;
|
|
1717
|
-
}
|
|
1718
|
-
const debugEnabled = debug2.enabled;
|
|
1719
|
-
const classContext = options.wrapExpression || isClassContextLiteralPath(path5);
|
|
1720
|
-
let transformed = literal;
|
|
1721
|
-
let mutated = false;
|
|
1722
|
-
let matchedCandidateCount = 0;
|
|
1723
|
-
let escapedDecisionCount = 0;
|
|
1724
|
-
let fallbackDecisionCount = 0;
|
|
1725
|
-
let escapedSamples;
|
|
1726
|
-
let skippedSamples;
|
|
1727
|
-
const resolveCandidatePlan = createCandidatePlanResolver(options, classContext);
|
|
1728
|
-
for (const candidate of candidates) {
|
|
1729
|
-
const plan = resolveCandidatePlan(candidate);
|
|
1730
|
-
if (plan.result.decision === "skip") {
|
|
1731
|
-
if (debugEnabled) {
|
|
1732
|
-
if (!skippedSamples) {
|
|
1733
|
-
skippedSamples = [];
|
|
1734
|
-
}
|
|
1735
|
-
if (skippedSamples.length < 6) {
|
|
1736
|
-
skippedSamples.push(candidate);
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
continue;
|
|
1740
|
-
}
|
|
1741
|
-
if (debugEnabled) {
|
|
1742
|
-
matchedCandidateCount += 1;
|
|
1743
|
-
if (plan.result.decision === "escaped") {
|
|
1744
|
-
escapedDecisionCount += 1;
|
|
1745
|
-
if (!escapedSamples) {
|
|
1746
|
-
escapedSamples = [];
|
|
1747
|
-
}
|
|
1748
|
-
if (escapedSamples.length < 6) {
|
|
1749
|
-
escapedSamples.push(candidate);
|
|
1750
|
-
}
|
|
1751
|
-
}
|
|
1752
|
-
if (plan.result.decision === "fallback") {
|
|
1753
|
-
fallbackDecisionCount += 1;
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
const replaced = transformed.replace(candidate, plan.replacement);
|
|
1757
|
-
if (replaced !== transformed) {
|
|
1758
|
-
transformed = replaced;
|
|
1759
|
-
mutated = true;
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
const node = path5.node;
|
|
1763
|
-
if (!mutated || typeof node.start !== "number" || typeof node.end !== "number") {
|
|
1764
|
-
return void 0;
|
|
1765
|
-
}
|
|
1766
|
-
if (debugEnabled) {
|
|
1767
|
-
debug2(
|
|
1768
|
-
"runtimeSet size=%d fallbackTriggered=%s candidates=%d matched=%d escapedHits=%d skipped=%d file=%s escapedSamples=%s skippedSamples=%s",
|
|
1769
|
-
_nullishCoalesce(_optionalChain([classNameSet, 'optionalAccess', _44 => _44.size]), () => ( 0)),
|
|
1770
|
-
fallbackDecisionCount > 0,
|
|
1771
|
-
candidates.length,
|
|
1772
|
-
matchedCandidateCount,
|
|
1773
|
-
escapedDecisionCount,
|
|
1774
|
-
_nullishCoalesce(_optionalChain([skippedSamples, 'optionalAccess', _45 => _45.length]), () => ( 0)),
|
|
1775
|
-
_nullishCoalesce(options.filename, () => ( "unknown")),
|
|
1776
|
-
_optionalChain([escapedSamples, 'optionalAccess', _46 => _46.join, 'call', _47 => _47(",")]) || "-",
|
|
1777
|
-
_optionalChain([skippedSamples, 'optionalAccess', _48 => _48.join, 'call', _49 => _49(",")]) || "-"
|
|
1778
|
-
);
|
|
1779
|
-
}
|
|
1780
|
-
const start = node.start + offset;
|
|
1781
|
-
const end = node.end - offset;
|
|
1782
|
-
if (start >= end || transformed === original) {
|
|
1783
|
-
return void 0;
|
|
1784
|
-
}
|
|
1785
|
-
const value = needEscaped ? _escape.jsStringEscape.call(void 0, transformed) : transformed;
|
|
1786
|
-
return {
|
|
1787
|
-
start,
|
|
1788
|
-
end,
|
|
1789
|
-
value,
|
|
1790
|
-
path: path5
|
|
1791
|
-
};
|
|
1792
|
-
}
|
|
1793
|
-
|
|
1794
|
-
// src/js/sourceAnalysis.ts
|
|
1795
|
-
function hasReplacementEntries(replacements) {
|
|
1796
|
-
for (const key in replacements) {
|
|
1797
|
-
if (Object.hasOwn(replacements, key)) {
|
|
1798
|
-
return true;
|
|
1799
|
-
}
|
|
1800
|
-
}
|
|
1801
|
-
return false;
|
|
1802
|
-
}
|
|
1803
|
-
function createModuleSpecifierReplacementToken(path5, replacement) {
|
|
1804
|
-
const node = path5.node;
|
|
1805
|
-
if (node.value === replacement) {
|
|
1806
|
-
return void 0;
|
|
1807
|
-
}
|
|
1808
|
-
if (typeof node.start !== "number" || typeof node.end !== "number") {
|
|
1809
|
-
return void 0;
|
|
1810
|
-
}
|
|
1811
|
-
const start = node.start + 1;
|
|
1812
|
-
const end = node.end - 1;
|
|
1813
|
-
if (start >= end) {
|
|
1814
|
-
return void 0;
|
|
1815
|
-
}
|
|
1816
|
-
return {
|
|
1817
|
-
start,
|
|
1818
|
-
end,
|
|
1819
|
-
value: replacement,
|
|
1820
|
-
path: path5
|
|
1821
|
-
};
|
|
1822
|
-
}
|
|
1823
|
-
function collectModuleSpecifierReplacementTokens(analysis, replacements) {
|
|
1824
|
-
if (!hasReplacementEntries(replacements)) {
|
|
1825
|
-
return [];
|
|
1826
|
-
}
|
|
1827
|
-
if (analysis.importDeclarations.size === 0 && analysis.exportDeclarations.size === 0 && analysis.requireCallPaths.length === 0 && analysis.walker.imports.size === 0) {
|
|
1828
|
-
return [];
|
|
1829
|
-
}
|
|
1830
|
-
const tokens = [];
|
|
1831
|
-
const applyReplacement = (path5) => {
|
|
1832
|
-
const replacement = replacements[path5.node.value];
|
|
1833
|
-
if (!replacement) {
|
|
1834
|
-
return;
|
|
1835
|
-
}
|
|
1836
|
-
const token = createModuleSpecifierReplacementToken(path5, replacement);
|
|
1837
|
-
if (token) {
|
|
1838
|
-
tokens.push(token);
|
|
1839
|
-
}
|
|
1840
|
-
};
|
|
1841
|
-
for (const importPath of analysis.importDeclarations) {
|
|
1842
|
-
const source = importPath.get("source");
|
|
1843
|
-
if (source.isStringLiteral()) {
|
|
1844
|
-
applyReplacement(source);
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
for (const exportPath of analysis.exportDeclarations) {
|
|
1848
|
-
if (exportPath.isExportNamedDeclaration() || exportPath.isExportAllDeclaration()) {
|
|
1849
|
-
const source = exportPath.get("source");
|
|
1850
|
-
if (source && !Array.isArray(source) && source.isStringLiteral()) {
|
|
1851
|
-
applyReplacement(source);
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
for (const literalPath of analysis.requireCallPaths) {
|
|
1856
|
-
applyReplacement(literalPath);
|
|
1857
|
-
}
|
|
1858
|
-
for (const token of analysis.walker.imports) {
|
|
1859
|
-
const replacement = replacements[token.source];
|
|
1860
|
-
if (replacement) {
|
|
1861
|
-
token.source = replacement;
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
return tokens;
|
|
1865
|
-
}
|
|
1866
|
-
|
|
1867
|
-
// src/js/babel/process.ts
|
|
1868
|
-
var optionVariantsCache = /* @__PURE__ */ new WeakMap();
|
|
1869
|
-
function getNeedEscapedOptions(options, needEscaped) {
|
|
1870
|
-
if (options.needEscaped === needEscaped) {
|
|
1871
|
-
return options;
|
|
1872
|
-
}
|
|
1873
|
-
let cached = optionVariantsCache.get(options);
|
|
1874
|
-
if (!cached) {
|
|
1875
|
-
cached = {};
|
|
1876
|
-
optionVariantsCache.set(options, cached);
|
|
1877
|
-
}
|
|
1878
|
-
if (needEscaped) {
|
|
1879
|
-
if (!cached.stringLiteralOptions) {
|
|
1880
|
-
cached.stringLiteralOptions = {
|
|
1881
|
-
...options,
|
|
1882
|
-
needEscaped: true
|
|
1883
|
-
};
|
|
1884
|
-
}
|
|
1885
|
-
return cached.stringLiteralOptions;
|
|
1886
|
-
}
|
|
1887
|
-
if (!cached.templateLiteralOptions) {
|
|
1888
|
-
cached.templateLiteralOptions = {
|
|
1889
|
-
...options,
|
|
1890
|
-
needEscaped: false
|
|
1891
|
-
};
|
|
1892
|
-
}
|
|
1893
|
-
return cached.templateLiteralOptions;
|
|
1894
|
-
}
|
|
1895
|
-
function processUpdatedSource(rawSource, options, analysis) {
|
|
1896
|
-
const { targetPaths, jsTokenUpdater, ignoredPaths } = analysis;
|
|
1897
|
-
if (targetPaths.length === 0 && !options.moduleSpecifierReplacements && jsTokenUpdater.length === 0) {
|
|
1898
|
-
return new (0, _magicstring2.default)(rawSource);
|
|
1899
|
-
}
|
|
1900
|
-
const replacementTokens = [];
|
|
1901
|
-
for (const path5 of targetPaths) {
|
|
1902
|
-
if (ignoredPaths.has(path5)) {
|
|
1903
|
-
continue;
|
|
1904
|
-
}
|
|
1905
|
-
const token = replaceHandleValue(
|
|
1906
|
-
path5,
|
|
1907
|
-
path5.isStringLiteral() ? getNeedEscapedOptions(options, true) : getNeedEscapedOptions(options, false)
|
|
1908
|
-
);
|
|
1909
|
-
if (token) {
|
|
1910
|
-
replacementTokens.push(token);
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
if (options.moduleSpecifierReplacements) {
|
|
1914
|
-
replacementTokens.push(
|
|
1915
|
-
...collectModuleSpecifierReplacementTokens(analysis, options.moduleSpecifierReplacements)
|
|
1916
|
-
);
|
|
1917
|
-
}
|
|
1918
|
-
if (jsTokenUpdater.length + replacementTokens.length === 0) {
|
|
1919
|
-
return new (0, _magicstring2.default)(rawSource);
|
|
1920
|
-
}
|
|
1921
|
-
const ms = new (0, _magicstring2.default)(rawSource);
|
|
1922
|
-
jsTokenUpdater.push(...replacementTokens).filter((token) => !ignoredPaths.has(token.path)).updateMagicString(ms);
|
|
1923
|
-
return ms;
|
|
1924
|
-
}
|
|
1925
|
-
|
|
1926
|
-
// src/js/evalTransforms.ts
|
|
1927
|
-
|
|
1928
|
-
var evalHandlerOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
1929
|
-
var EVAL_SCOPE_ERROR_REGEXP = /pass a scope and parentPath|traversing a Program\/File/i;
|
|
1930
|
-
function isEvalPath(path5) {
|
|
1931
|
-
if (path5.isCallExpression()) {
|
|
1932
|
-
const calleePath = path5.get("callee");
|
|
1933
|
-
return calleePath.isIdentifier({ name: "eval" });
|
|
1934
|
-
}
|
|
1935
|
-
return false;
|
|
1936
|
-
}
|
|
1937
|
-
function createEvalReplacementToken(path5, updated) {
|
|
1938
|
-
const node = path5.node;
|
|
1939
|
-
let offset = 0;
|
|
1940
|
-
let original;
|
|
1941
|
-
if (path5.isStringLiteral()) {
|
|
1942
|
-
offset = 1;
|
|
1943
|
-
original = path5.node.value;
|
|
1944
|
-
} else if (path5.isTemplateElement()) {
|
|
1945
|
-
original = path5.node.value.raw;
|
|
1946
|
-
} else {
|
|
1947
|
-
original = "";
|
|
1948
|
-
}
|
|
1949
|
-
if (typeof node.start !== "number" || typeof node.end !== "number") {
|
|
1950
|
-
return void 0;
|
|
1951
|
-
}
|
|
1952
|
-
const start = node.start + offset;
|
|
1953
|
-
const end = node.end - offset;
|
|
1954
|
-
if (start >= end) {
|
|
1955
|
-
return void 0;
|
|
1956
|
-
}
|
|
1957
|
-
if (original === updated) {
|
|
1958
|
-
return void 0;
|
|
1959
|
-
}
|
|
1960
|
-
const value = path5.isStringLiteral() ? _escape.jsStringEscape.call(void 0, updated) : updated;
|
|
1961
|
-
return {
|
|
1962
|
-
start,
|
|
1963
|
-
end,
|
|
1964
|
-
value,
|
|
1965
|
-
path: path5
|
|
1966
|
-
};
|
|
1967
|
-
}
|
|
1968
|
-
function handleEvalStringLiteral(path5, handlerOptions, updater, handler) {
|
|
1969
|
-
const { code } = handler(path5.node.value, handlerOptions);
|
|
1970
|
-
if (!code) {
|
|
1971
|
-
return;
|
|
1972
|
-
}
|
|
1973
|
-
const token = createEvalReplacementToken(path5, code);
|
|
1974
|
-
if (token) {
|
|
1975
|
-
updater.addToken(token);
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
function handleEvalTemplateElement(path5, handlerOptions, updater, handler) {
|
|
1979
|
-
const { code } = handler(path5.node.value.raw, handlerOptions);
|
|
1980
|
-
if (!code) {
|
|
1981
|
-
return;
|
|
1982
|
-
}
|
|
1983
|
-
const token = createEvalReplacementToken(path5, code);
|
|
1984
|
-
if (token) {
|
|
1985
|
-
updater.addToken(token);
|
|
1986
|
-
}
|
|
1987
|
-
}
|
|
1988
|
-
function getEvalStringHandlerOptions(options) {
|
|
1989
|
-
if (options.needEscaped === false && options.generateMap === false) {
|
|
1990
|
-
return options;
|
|
1991
|
-
}
|
|
1992
|
-
let cached = evalHandlerOptionsCache.get(options);
|
|
1993
|
-
if (!cached) {
|
|
1994
|
-
cached = {};
|
|
1995
|
-
evalHandlerOptionsCache.set(options, cached);
|
|
1996
|
-
}
|
|
1997
|
-
if (!cached.stringLiteralOptions) {
|
|
1998
|
-
cached.stringLiteralOptions = {
|
|
1999
|
-
...options,
|
|
2000
|
-
needEscaped: false,
|
|
2001
|
-
generateMap: false
|
|
2002
|
-
};
|
|
2003
|
-
}
|
|
2004
|
-
return cached.stringLiteralOptions;
|
|
2005
|
-
}
|
|
2006
|
-
function getEvalTemplateHandlerOptions(options) {
|
|
2007
|
-
if (options.generateMap === false) {
|
|
2008
|
-
return options;
|
|
2009
|
-
}
|
|
2010
|
-
let cached = evalHandlerOptionsCache.get(options);
|
|
2011
|
-
if (!cached) {
|
|
2012
|
-
cached = {};
|
|
2013
|
-
evalHandlerOptionsCache.set(options, cached);
|
|
2014
|
-
}
|
|
2015
|
-
if (!cached.templateLiteralOptions) {
|
|
2016
|
-
cached.templateLiteralOptions = {
|
|
2017
|
-
...options,
|
|
2018
|
-
generateMap: false
|
|
2019
|
-
};
|
|
2020
|
-
}
|
|
2021
|
-
return cached.templateLiteralOptions;
|
|
2022
|
-
}
|
|
2023
|
-
function walkEvalExpression(path5, options, updater, handler) {
|
|
2024
|
-
const stringHandlerOptions = getEvalStringHandlerOptions(options);
|
|
2025
|
-
const templateHandlerOptions = getEvalTemplateHandlerOptions(options);
|
|
2026
|
-
const maybeTraverse = _optionalChain([path5, 'optionalAccess', _50 => _50.traverse]);
|
|
2027
|
-
if (typeof maybeTraverse === "function") {
|
|
2028
|
-
try {
|
|
2029
|
-
return maybeTraverse.call(path5, {
|
|
2030
|
-
StringLiteral(innerPath) {
|
|
2031
|
-
handleEvalStringLiteral(innerPath, stringHandlerOptions, updater, handler);
|
|
2032
|
-
},
|
|
2033
|
-
TemplateElement(innerPath) {
|
|
2034
|
-
handleEvalTemplateElement(innerPath, templateHandlerOptions, updater, handler);
|
|
2035
|
-
}
|
|
2036
|
-
});
|
|
2037
|
-
} catch (error) {
|
|
2038
|
-
const msg = _nullishCoalesce(_optionalChain([error, 'optionalAccess', _51 => _51.message]), () => ( ""));
|
|
2039
|
-
const scopeError = EVAL_SCOPE_ERROR_REGEXP.test(msg);
|
|
2040
|
-
if (!scopeError) {
|
|
2041
|
-
throw error;
|
|
2042
|
-
}
|
|
2043
|
-
}
|
|
2044
|
-
}
|
|
2045
|
-
const getArgs = _optionalChain([path5, 'optionalAccess', _52 => _52.get, 'optionalCall', _53 => _53("arguments")]);
|
|
2046
|
-
if (Array.isArray(getArgs)) {
|
|
2047
|
-
for (const arg of getArgs) {
|
|
2048
|
-
if (_optionalChain([arg, 'optionalAccess', _54 => _54.isStringLiteral, 'optionalCall', _55 => _55()])) {
|
|
2049
|
-
handleEvalStringLiteral(arg, stringHandlerOptions, updater, handler);
|
|
2050
|
-
continue;
|
|
2051
|
-
}
|
|
2052
|
-
if (_optionalChain([arg, 'optionalAccess', _56 => _56.isTemplateLiteral, 'optionalCall', _57 => _57()])) {
|
|
2053
|
-
for (const quasi of arg.get("quasis")) {
|
|
2054
|
-
handleEvalTemplateElement(quasi, templateHandlerOptions, updater, handler);
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
|
-
return;
|
|
2059
|
-
}
|
|
2060
|
-
const nodeArgs = _optionalChain([path5, 'optionalAccess', _58 => _58.node, 'optionalAccess', _59 => _59.arguments]);
|
|
2061
|
-
if (Array.isArray(nodeArgs)) {
|
|
2062
|
-
for (const n of nodeArgs) {
|
|
2063
|
-
if (_optionalChain([n, 'optionalAccess', _60 => _60.type]) === "StringLiteral") {
|
|
2064
|
-
const stub = {
|
|
2065
|
-
node: n,
|
|
2066
|
-
isStringLiteral: () => true
|
|
2067
|
-
};
|
|
2068
|
-
handleEvalStringLiteral(stub, stringHandlerOptions, updater, handler);
|
|
2069
|
-
} else if (_optionalChain([n, 'optionalAccess', _61 => _61.type]) === "TemplateLiteral" && Array.isArray(n.quasis)) {
|
|
2070
|
-
for (const q of n.quasis) {
|
|
2071
|
-
const stub = {
|
|
2072
|
-
node: q,
|
|
2073
|
-
isStringLiteral: () => false,
|
|
2074
|
-
isTemplateElement: () => true
|
|
2075
|
-
};
|
|
2076
|
-
handleEvalTemplateElement(stub, templateHandlerOptions, updater, handler);
|
|
2077
|
-
}
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
}
|
|
2081
|
-
}
|
|
2082
|
-
|
|
2083
|
-
// src/js/JsTokenUpdater.ts
|
|
2084
|
-
var JsTokenUpdater = class {
|
|
2085
|
-
constructor({ value } = {}) {
|
|
2086
|
-
this.tokens = value ? [...value] : [];
|
|
2087
|
-
}
|
|
2088
|
-
addToken(token) {
|
|
2089
|
-
if (token) {
|
|
2090
|
-
this.tokens.push(token);
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
push(...args) {
|
|
2094
|
-
this.tokens.push(...args);
|
|
2095
|
-
return this;
|
|
2096
|
-
}
|
|
2097
|
-
/**
|
|
2098
|
-
* 待写入的 token 数量。
|
|
2099
|
-
*/
|
|
2100
|
-
get length() {
|
|
2101
|
-
return this.tokens.length;
|
|
2102
|
-
}
|
|
2103
|
-
map(callbackfn) {
|
|
2104
|
-
this.tokens = this.tokens.map(callbackfn);
|
|
2105
|
-
return this;
|
|
2106
|
-
}
|
|
2107
|
-
filter(callbackfn) {
|
|
2108
|
-
this.tokens = this.tokens.filter(callbackfn);
|
|
2109
|
-
return this;
|
|
2110
|
-
}
|
|
2111
|
-
updateMagicString(ms) {
|
|
2112
|
-
for (const { start, end, value } of this.tokens) {
|
|
2113
|
-
ms.update(start, end, value);
|
|
2114
|
-
}
|
|
2115
|
-
return ms;
|
|
2116
|
-
}
|
|
2117
|
-
};
|
|
2118
|
-
|
|
2119
|
-
// src/js/module-graph/ignored-exports.ts
|
|
2120
|
-
var IgnoredExportsTracker = class {
|
|
2121
|
-
constructor(options) {
|
|
2122
|
-
this.options = options;
|
|
2123
|
-
this.ignoredExportNames = /* @__PURE__ */ new Map();
|
|
2124
|
-
}
|
|
2125
|
-
addIgnoredExport(filename, exportName) {
|
|
2126
|
-
if (!exportName) {
|
|
2127
|
-
return;
|
|
2128
|
-
}
|
|
2129
|
-
let pending = this.ignoredExportNames.get(filename);
|
|
2130
|
-
if (!pending) {
|
|
2131
|
-
pending = /* @__PURE__ */ new Set();
|
|
2132
|
-
this.ignoredExportNames.set(filename, pending);
|
|
2133
|
-
}
|
|
2134
|
-
if (pending.has(exportName)) {
|
|
2135
|
-
return;
|
|
2136
|
-
}
|
|
2137
|
-
pending.add(exportName);
|
|
2138
|
-
const existing = this.options.modules.get(filename);
|
|
2139
|
-
if (existing) {
|
|
2140
|
-
this.applyIgnoredExportsToAnalysis(filename, existing.analysis);
|
|
2141
|
-
}
|
|
2142
|
-
}
|
|
2143
|
-
registerIgnoredExportsFromTokens(resolved, tokens) {
|
|
2144
|
-
for (const token of tokens) {
|
|
2145
|
-
if (token.type === "ImportSpecifier") {
|
|
2146
|
-
this.addIgnoredExport(resolved, token.imported);
|
|
2147
|
-
} else if (token.type === "ImportDefaultSpecifier") {
|
|
2148
|
-
this.addIgnoredExport(resolved, "default");
|
|
2149
|
-
}
|
|
2150
|
-
}
|
|
2151
|
-
}
|
|
2152
|
-
applyIgnoredExportsToAnalysis(filename, analysis) {
|
|
2153
|
-
const pending = this.ignoredExportNames.get(filename);
|
|
2154
|
-
if (!pending || pending.size === 0) {
|
|
2155
|
-
return;
|
|
2156
|
-
}
|
|
2157
|
-
const names = new Set(pending);
|
|
2158
|
-
pending.clear();
|
|
2159
|
-
const propagate = [];
|
|
2160
|
-
for (const exportPath of analysis.exportDeclarations) {
|
|
2161
|
-
if (names.size === 0) {
|
|
2162
|
-
break;
|
|
2163
|
-
}
|
|
2164
|
-
if (exportPath.isExportDefaultDeclaration()) {
|
|
2165
|
-
if (names.has("default")) {
|
|
2166
|
-
analysis.walker.walkExportDefaultDeclaration(exportPath);
|
|
2167
|
-
names.delete("default");
|
|
2168
|
-
}
|
|
2169
|
-
continue;
|
|
2170
|
-
}
|
|
2171
|
-
if (exportPath.isExportNamedDeclaration()) {
|
|
2172
|
-
const source = _optionalChain([exportPath, 'access', _62 => _62.node, 'access', _63 => _63.source, 'optionalAccess', _64 => _64.value]);
|
|
2173
|
-
if (typeof source === "string") {
|
|
2174
|
-
for (const spec of exportPath.get("specifiers")) {
|
|
2175
|
-
if (!spec.isExportSpecifier()) {
|
|
2176
|
-
continue;
|
|
2177
|
-
}
|
|
2178
|
-
const exported = spec.get("exported");
|
|
2179
|
-
let exportedName;
|
|
2180
|
-
if (exported.isIdentifier()) {
|
|
2181
|
-
exportedName = exported.node.name;
|
|
2182
|
-
} else if (exported.isStringLiteral()) {
|
|
2183
|
-
exportedName = exported.node.value;
|
|
2184
|
-
}
|
|
2185
|
-
if (!exportedName || !names.has(exportedName)) {
|
|
2186
|
-
continue;
|
|
2187
|
-
}
|
|
2188
|
-
const local = spec.get("local");
|
|
2189
|
-
if (local.isIdentifier()) {
|
|
2190
|
-
propagate.push({
|
|
2191
|
-
specifier: source,
|
|
2192
|
-
exportName: local.node.name
|
|
2193
|
-
});
|
|
2194
|
-
names.delete(exportedName);
|
|
2195
|
-
} else if (local.isStringLiteral()) {
|
|
2196
|
-
propagate.push({
|
|
2197
|
-
specifier: source,
|
|
2198
|
-
exportName: local.node.value
|
|
2199
|
-
});
|
|
2200
|
-
names.delete(exportedName);
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
continue;
|
|
2204
|
-
}
|
|
2205
|
-
const declaration = exportPath.get("declaration");
|
|
2206
|
-
if (declaration.isVariableDeclaration()) {
|
|
2207
|
-
for (const decl of declaration.get("declarations")) {
|
|
2208
|
-
const id = decl.get("id");
|
|
2209
|
-
if (id.isIdentifier()) {
|
|
2210
|
-
const exportName = id.node.name;
|
|
2211
|
-
if (names.has(exportName)) {
|
|
2212
|
-
analysis.walker.walkVariableDeclarator(decl);
|
|
2213
|
-
names.delete(exportName);
|
|
2214
|
-
}
|
|
2215
|
-
}
|
|
2216
|
-
}
|
|
2217
|
-
}
|
|
2218
|
-
for (const spec of exportPath.get("specifiers")) {
|
|
2219
|
-
if (!spec.isExportSpecifier()) {
|
|
2220
|
-
continue;
|
|
2221
|
-
}
|
|
2222
|
-
const exported = spec.get("exported");
|
|
2223
|
-
let exportedName;
|
|
2224
|
-
if (exported.isIdentifier()) {
|
|
2225
|
-
exportedName = exported.node.name;
|
|
2226
|
-
} else if (exported.isStringLiteral()) {
|
|
2227
|
-
exportedName = exported.node.value;
|
|
2228
|
-
}
|
|
2229
|
-
if (!exportedName || !names.has(exportedName)) {
|
|
2230
|
-
continue;
|
|
2231
|
-
}
|
|
2232
|
-
const local = spec.get("local");
|
|
2233
|
-
analysis.walker.walkNode(local);
|
|
2234
|
-
names.delete(exportedName);
|
|
2235
|
-
}
|
|
2236
|
-
continue;
|
|
2237
|
-
}
|
|
2238
|
-
if (exportPath.isExportAllDeclaration()) {
|
|
2239
|
-
const source = _optionalChain([exportPath, 'access', _65 => _65.node, 'access', _66 => _66.source, 'optionalAccess', _67 => _67.value]);
|
|
2240
|
-
if (typeof source === "string") {
|
|
2241
|
-
for (const exportName of names) {
|
|
2242
|
-
propagate.push({
|
|
2243
|
-
specifier: source,
|
|
2244
|
-
exportName
|
|
2245
|
-
});
|
|
2246
|
-
}
|
|
2247
|
-
names.clear();
|
|
2248
|
-
}
|
|
2249
|
-
}
|
|
2250
|
-
}
|
|
2251
|
-
for (const { specifier, exportName } of propagate) {
|
|
2252
|
-
let resolved;
|
|
2253
|
-
try {
|
|
2254
|
-
resolved = this.options.resolve(specifier, filename);
|
|
2255
|
-
} catch (e2) {
|
|
2256
|
-
resolved = void 0;
|
|
2257
|
-
}
|
|
2258
|
-
if (!resolved) {
|
|
2259
|
-
pending.add(exportName);
|
|
2260
|
-
continue;
|
|
2261
|
-
}
|
|
2262
|
-
if (this.options.filter && !this.options.filter(resolved, specifier, filename)) {
|
|
2263
|
-
pending.add(exportName);
|
|
2264
|
-
continue;
|
|
2265
|
-
}
|
|
2266
|
-
this.addIgnoredExport(resolved, exportName);
|
|
2267
|
-
}
|
|
2268
|
-
for (const name of names) {
|
|
2269
|
-
pending.add(name);
|
|
2270
|
-
}
|
|
2271
|
-
}
|
|
2272
|
-
};
|
|
2273
|
-
|
|
2274
|
-
// src/js/ModuleGraph.ts
|
|
2275
|
-
var JsModuleGraph = class {
|
|
2276
|
-
constructor(entry, graphOptions) {
|
|
2277
|
-
this.modules = /* @__PURE__ */ new Map();
|
|
2278
|
-
this.queue = [];
|
|
2279
|
-
this.resolve = graphOptions.resolve;
|
|
2280
|
-
this.load = graphOptions.load;
|
|
2281
|
-
this.filter = graphOptions.filter;
|
|
2282
|
-
this.maxDepth = _nullishCoalesce(graphOptions.maxDepth, () => ( Number.POSITIVE_INFINITY));
|
|
2283
|
-
const { moduleGraph: _moduleGraph, filename: _ignoredFilename, ...rest } = entry.handlerOptions;
|
|
2284
|
-
this.baseOptions = {
|
|
2285
|
-
...rest,
|
|
2286
|
-
filename: entry.filename
|
|
2287
|
-
};
|
|
2288
|
-
this.parserOptions = entry.handlerOptions.babelParserOptions;
|
|
2289
|
-
this.rootFilename = entry.filename;
|
|
2290
|
-
this.ignoredExports = new IgnoredExportsTracker({
|
|
2291
|
-
resolve: this.resolve,
|
|
2292
|
-
filter: this.filter,
|
|
2293
|
-
modules: this.modules
|
|
2294
|
-
});
|
|
2295
|
-
this.modules.set(entry.filename, {
|
|
2296
|
-
filename: entry.filename,
|
|
2297
|
-
source: entry.source,
|
|
2298
|
-
analysis: entry.analysis
|
|
2299
|
-
});
|
|
2300
|
-
this.queue.push({ filename: entry.filename, depth: 0 });
|
|
2301
|
-
}
|
|
2302
|
-
build() {
|
|
2303
|
-
this.collectDependencies();
|
|
2304
|
-
let linked;
|
|
2305
|
-
for (const [filename, state] of this.modules) {
|
|
2306
|
-
if (filename === this.rootFilename) {
|
|
2307
|
-
continue;
|
|
2308
|
-
}
|
|
2309
|
-
const childOptions = {
|
|
2310
|
-
...this.baseOptions,
|
|
2311
|
-
filename
|
|
2312
|
-
};
|
|
2313
|
-
const ms = processUpdatedSource(state.source, childOptions, state.analysis);
|
|
2314
|
-
const code = ms.toString();
|
|
2315
|
-
if (code !== state.source) {
|
|
2316
|
-
if (!linked) {
|
|
2317
|
-
linked = {};
|
|
2318
|
-
}
|
|
2319
|
-
linked[filename] = { code };
|
|
2320
|
-
}
|
|
2321
|
-
}
|
|
2322
|
-
return linked;
|
|
2323
|
-
}
|
|
2324
|
-
collectDependencies() {
|
|
2325
|
-
while (this.queue.length > 0) {
|
|
2326
|
-
const { filename, depth } = this.queue.shift();
|
|
2327
|
-
if (depth >= this.maxDepth) {
|
|
2328
|
-
continue;
|
|
2329
|
-
}
|
|
2330
|
-
const state = this.modules.get(filename);
|
|
2331
|
-
if (!state) {
|
|
2332
|
-
continue;
|
|
2333
|
-
}
|
|
2334
|
-
const dependencySpecifiers = /* @__PURE__ */ new Map();
|
|
2335
|
-
for (const token of state.analysis.walker.imports) {
|
|
2336
|
-
if (!dependencySpecifiers.has(token.source)) {
|
|
2337
|
-
dependencySpecifiers.set(token.source, []);
|
|
2338
|
-
}
|
|
2339
|
-
dependencySpecifiers.get(token.source).push(token);
|
|
2340
|
-
}
|
|
2341
|
-
for (const exportPath of state.analysis.exportDeclarations) {
|
|
2342
|
-
if (exportPath.isExportAllDeclaration() || exportPath.isExportNamedDeclaration()) {
|
|
2343
|
-
const source = _optionalChain([exportPath, 'access', _68 => _68.node, 'access', _69 => _69.source, 'optionalAccess', _70 => _70.value]);
|
|
2344
|
-
if (typeof source === "string" && !dependencySpecifiers.has(source)) {
|
|
2345
|
-
dependencySpecifiers.set(source, []);
|
|
2346
|
-
}
|
|
2347
|
-
}
|
|
2348
|
-
}
|
|
2349
|
-
for (const [specifier, tokens] of dependencySpecifiers) {
|
|
2350
|
-
let resolved;
|
|
2351
|
-
try {
|
|
2352
|
-
resolved = this.resolve(specifier, filename);
|
|
2353
|
-
} catch (e3) {
|
|
2354
|
-
continue;
|
|
2355
|
-
}
|
|
2356
|
-
if (!resolved) {
|
|
2357
|
-
continue;
|
|
2358
|
-
}
|
|
2359
|
-
if (this.filter && !this.filter(resolved, specifier, filename)) {
|
|
2360
|
-
continue;
|
|
2361
|
-
}
|
|
2362
|
-
if (tokens.length > 0) {
|
|
2363
|
-
this.ignoredExports.registerIgnoredExportsFromTokens(resolved, tokens);
|
|
2364
|
-
}
|
|
2365
|
-
if (this.modules.has(resolved)) {
|
|
2366
|
-
continue;
|
|
2367
|
-
}
|
|
2368
|
-
let source;
|
|
2369
|
-
try {
|
|
2370
|
-
source = this.load(resolved);
|
|
2371
|
-
} catch (e4) {
|
|
2372
|
-
continue;
|
|
2373
|
-
}
|
|
2374
|
-
if (typeof source !== "string") {
|
|
2375
|
-
continue;
|
|
2376
|
-
}
|
|
2377
|
-
let analysis;
|
|
2378
|
-
try {
|
|
2379
|
-
const ast = babelParse(source, {
|
|
2380
|
-
...this.parserOptions,
|
|
2381
|
-
sourceFilename: resolved
|
|
2382
|
-
});
|
|
2383
|
-
analysis = analyzeSource(ast, {
|
|
2384
|
-
...this.baseOptions,
|
|
2385
|
-
filename: resolved
|
|
2386
|
-
});
|
|
2387
|
-
this.ignoredExports.applyIgnoredExportsToAnalysis(resolved, analysis);
|
|
2388
|
-
} catch (e5) {
|
|
2389
|
-
continue;
|
|
2390
|
-
}
|
|
2391
|
-
this.modules.set(resolved, {
|
|
2392
|
-
filename: resolved,
|
|
2393
|
-
source,
|
|
2394
|
-
analysis
|
|
2395
|
-
});
|
|
2396
|
-
this.queue.push({ filename: resolved, depth: depth + 1 });
|
|
2397
|
-
}
|
|
2398
|
-
}
|
|
2399
|
-
}
|
|
2400
|
-
};
|
|
2401
|
-
|
|
2402
|
-
// src/js/node-path-walker/export-handlers.ts
|
|
2403
|
-
function walkExportDeclaration(ctx, path5) {
|
|
2404
|
-
if (path5.isExportDeclaration()) {
|
|
2405
|
-
if (path5.isExportNamedDeclaration()) {
|
|
2406
|
-
walkExportNamedDeclaration(ctx, path5);
|
|
2407
|
-
} else if (path5.isExportDefaultDeclaration()) {
|
|
2408
|
-
walkExportDefaultDeclaration(ctx, path5);
|
|
2409
|
-
} else if (path5.isExportAllDeclaration()) {
|
|
2410
|
-
walkExportAllDeclaration(ctx, path5);
|
|
2411
|
-
}
|
|
2412
|
-
}
|
|
2413
|
-
}
|
|
2414
|
-
function walkExportNamedDeclaration(ctx, path5) {
|
|
2415
|
-
const declaration = path5.get("declaration");
|
|
2416
|
-
if (declaration.isVariableDeclaration()) {
|
|
2417
|
-
for (const decl of declaration.get("declarations")) {
|
|
2418
|
-
ctx.walkNode(decl);
|
|
2419
|
-
}
|
|
2420
|
-
}
|
|
2421
|
-
const specifiers = path5.get("specifiers");
|
|
2422
|
-
for (const spec of specifiers) {
|
|
2423
|
-
if (spec.isExportSpecifier()) {
|
|
2424
|
-
const local = spec.get("local");
|
|
2425
|
-
if (local.isIdentifier()) {
|
|
2426
|
-
ctx.walkNode(local);
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
}
|
|
2430
|
-
}
|
|
2431
|
-
function walkExportDefaultDeclaration(ctx, path5) {
|
|
2432
|
-
const decl = path5.get("declaration");
|
|
2433
|
-
if (decl.isIdentifier()) {
|
|
2434
|
-
ctx.walkNode(decl);
|
|
2435
|
-
} else {
|
|
2436
|
-
ctx.walkNode(decl);
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2439
|
-
function walkExportAllDeclaration(ctx, path5) {
|
|
2440
|
-
const source = path5.get("source");
|
|
2441
|
-
if (source.isStringLiteral()) {
|
|
2442
|
-
ctx.addImportToken(
|
|
2443
|
-
{
|
|
2444
|
-
declaration: path5,
|
|
2445
|
-
source: source.node.value,
|
|
2446
|
-
type: "ExportAllDeclaration"
|
|
2447
|
-
}
|
|
2448
|
-
);
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
|
|
2452
|
-
// src/js/node-path-walker/import-tokens.ts
|
|
2453
|
-
function maybeAddImportToken(imports, arg) {
|
|
2454
|
-
if (!(arg.isImportSpecifier() && arg.node.importKind !== "type" || arg.isImportDefaultSpecifier())) {
|
|
2455
|
-
return false;
|
|
2456
|
-
}
|
|
2457
|
-
const importDeclaration = arg.parentPath;
|
|
2458
|
-
if (!importDeclaration.isImportDeclaration() || importDeclaration.node.importKind === "type") {
|
|
2459
|
-
return false;
|
|
2460
|
-
}
|
|
2461
|
-
if (arg.isImportSpecifier()) {
|
|
2462
|
-
const imported = arg.get("imported");
|
|
2463
|
-
if (imported.isIdentifier()) {
|
|
2464
|
-
imports.add(
|
|
2465
|
-
{
|
|
2466
|
-
declaration: importDeclaration,
|
|
2467
|
-
specifier: arg,
|
|
2468
|
-
imported: imported.node.name,
|
|
2469
|
-
local: arg.node.local.name,
|
|
2470
|
-
source: importDeclaration.node.source.value,
|
|
2471
|
-
type: "ImportSpecifier"
|
|
2472
|
-
}
|
|
2473
|
-
);
|
|
2474
|
-
}
|
|
2475
|
-
return true;
|
|
2476
|
-
}
|
|
2477
|
-
imports.add(
|
|
2478
|
-
{
|
|
2479
|
-
declaration: importDeclaration,
|
|
2480
|
-
specifier: arg,
|
|
2481
|
-
local: arg.node.local.name,
|
|
2482
|
-
source: importDeclaration.node.source.value,
|
|
2483
|
-
type: "ImportDefaultSpecifier"
|
|
2484
|
-
}
|
|
2485
|
-
);
|
|
2486
|
-
return true;
|
|
2487
|
-
}
|
|
2488
|
-
|
|
2489
|
-
// src/js/NodePathWalker.ts
|
|
2490
|
-
var EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS = [];
|
|
2491
|
-
var EMPTY_IMPORT_TOKENS = /* @__PURE__ */ new Set();
|
|
2492
|
-
function NOOP_STRING_PATH_CALLBACK() {
|
|
2493
|
-
}
|
|
2494
|
-
var NEVER_MATCH_NAME2 = () => false;
|
|
2495
|
-
var NodePathWalker = class {
|
|
2496
|
-
constructor({ ignoreCallExpressionIdentifiers, callback } = {}) {
|
|
2497
|
-
this.hasIgnoredCallIdentifiers = Boolean(ignoreCallExpressionIdentifiers && ignoreCallExpressionIdentifiers.length > 0);
|
|
2498
|
-
this.ignoreCallExpressionIdentifiers = _nullishCoalesce(ignoreCallExpressionIdentifiers, () => ( EMPTY_IGNORE_CALL_EXPRESSION_IDENTIFIERS));
|
|
2499
|
-
this.callback = _nullishCoalesce(callback, () => ( NOOP_STRING_PATH_CALLBACK));
|
|
2500
|
-
this.isIgnoredCallIdentifier = this.hasIgnoredCallIdentifiers ? createNameMatcher(this.ignoreCallExpressionIdentifiers, { exact: true }) : NEVER_MATCH_NAME2;
|
|
2501
|
-
}
|
|
2502
|
-
get imports() {
|
|
2503
|
-
return _nullishCoalesce(this.importsStore, () => ( EMPTY_IMPORT_TOKENS));
|
|
2504
|
-
}
|
|
2505
|
-
getWritableImports() {
|
|
2506
|
-
if (!this.importsStore) {
|
|
2507
|
-
this.importsStore = /* @__PURE__ */ new Set();
|
|
2508
|
-
}
|
|
2509
|
-
return this.importsStore;
|
|
2510
|
-
}
|
|
2511
|
-
addImportToken(token) {
|
|
2512
|
-
this.getWritableImports().add(token);
|
|
2513
|
-
}
|
|
2514
|
-
getVisited() {
|
|
2515
|
-
if (!this.visitedStore) {
|
|
2516
|
-
this.visitedStore = /* @__PURE__ */ new WeakSet();
|
|
2517
|
-
}
|
|
2518
|
-
return this.visitedStore;
|
|
2519
|
-
}
|
|
2520
|
-
walkVariableDeclarator(path5) {
|
|
2521
|
-
const init = path5.get("init");
|
|
2522
|
-
this.walkNode(init);
|
|
2523
|
-
}
|
|
2524
|
-
walkTemplateLiteral(path5) {
|
|
2525
|
-
for (const exp of path5.get("expressions")) {
|
|
2526
|
-
this.walkNode(exp);
|
|
2527
|
-
}
|
|
2528
|
-
for (const quasis of path5.get("quasis")) {
|
|
2529
|
-
this.callback(quasis);
|
|
2530
|
-
}
|
|
2531
|
-
}
|
|
2532
|
-
walkStringLiteral(path5) {
|
|
2533
|
-
this.callback(path5);
|
|
2534
|
-
}
|
|
2535
|
-
walkBinaryExpression(path5) {
|
|
2536
|
-
const left = path5.get("left");
|
|
2537
|
-
this.walkNode(left);
|
|
2538
|
-
const right = path5.get("right");
|
|
2539
|
-
this.walkNode(right);
|
|
2540
|
-
}
|
|
2541
|
-
walkLogicalExpression(path5) {
|
|
2542
|
-
const left = path5.get("left");
|
|
2543
|
-
this.walkNode(left);
|
|
2544
|
-
const right = path5.get("right");
|
|
2545
|
-
this.walkNode(right);
|
|
2546
|
-
}
|
|
2547
|
-
walkObjectExpression(path5) {
|
|
2548
|
-
const props = path5.get("properties");
|
|
2549
|
-
for (const prop of props) {
|
|
2550
|
-
if (prop.isObjectProperty()) {
|
|
2551
|
-
const key = prop.get("key");
|
|
2552
|
-
this.walkNode(key);
|
|
2553
|
-
const value = prop.get("value");
|
|
2554
|
-
this.walkNode(value);
|
|
2555
|
-
}
|
|
2556
|
-
}
|
|
2557
|
-
}
|
|
2558
|
-
walkArrayExpression(path5) {
|
|
2559
|
-
const elements = path5.get("elements");
|
|
2560
|
-
for (const element of elements) {
|
|
2561
|
-
this.walkNode(element);
|
|
2562
|
-
}
|
|
2563
|
-
}
|
|
2564
|
-
walkNode(arg) {
|
|
2565
|
-
const visited = this.getVisited();
|
|
2566
|
-
if (visited.has(arg)) {
|
|
2567
|
-
return;
|
|
2568
|
-
}
|
|
2569
|
-
visited.add(arg);
|
|
2570
|
-
if (arg.isIdentifier()) {
|
|
2571
|
-
const binding = _optionalChain([arg, 'optionalAccess', _71 => _71.scope, 'optionalAccess', _72 => _72.getBinding, 'optionalCall', _73 => _73(arg.node.name)]);
|
|
2572
|
-
if (binding) {
|
|
2573
|
-
this.walkNode(binding.path);
|
|
2574
|
-
}
|
|
2575
|
-
} else if (arg.isMemberExpression()) {
|
|
2576
|
-
const objectPath = arg.get("object");
|
|
2577
|
-
if (objectPath.isIdentifier()) {
|
|
2578
|
-
const binding = _optionalChain([arg, 'optionalAccess', _74 => _74.scope, 'optionalAccess', _75 => _75.getBinding, 'optionalCall', _76 => _76(objectPath.node.name)]);
|
|
2579
|
-
if (binding) {
|
|
2580
|
-
if (binding.path.isVariableDeclarator()) {
|
|
2581
|
-
this.walkVariableDeclarator(binding.path);
|
|
2582
|
-
}
|
|
2583
|
-
}
|
|
2584
|
-
}
|
|
2585
|
-
} else if (arg.isTemplateLiteral()) {
|
|
2586
|
-
this.walkTemplateLiteral(arg);
|
|
2587
|
-
} else if (arg.isStringLiteral()) {
|
|
2588
|
-
this.walkStringLiteral(arg);
|
|
2589
|
-
} else if (arg.isBinaryExpression()) {
|
|
2590
|
-
this.walkBinaryExpression(arg);
|
|
2591
|
-
} else if (arg.isLogicalExpression()) {
|
|
2592
|
-
this.walkLogicalExpression(arg);
|
|
2593
|
-
} else if (arg.isObjectExpression()) {
|
|
2594
|
-
this.walkObjectExpression(arg);
|
|
2595
|
-
} else if (arg.isArrayExpression()) {
|
|
2596
|
-
this.walkArrayExpression(arg);
|
|
2597
|
-
} else if (arg.isVariableDeclarator()) {
|
|
2598
|
-
this.walkVariableDeclarator(arg);
|
|
2599
|
-
} else if (maybeAddImportToken(this.getWritableImports(), arg)) {
|
|
2600
|
-
}
|
|
2601
|
-
}
|
|
2602
|
-
/**
|
|
2603
|
-
* Walk the arguments of a desired call expression so their bindings can be analysed.
|
|
2604
|
-
*/
|
|
2605
|
-
walkCallExpression(path5) {
|
|
2606
|
-
if (!this.hasIgnoredCallIdentifiers) {
|
|
2607
|
-
return;
|
|
2608
|
-
}
|
|
2609
|
-
const calleePath = path5.get("callee");
|
|
2610
|
-
if (calleePath.isIdentifier() && this.isIgnoredCallIdentifier(calleePath.node.name)) {
|
|
2611
|
-
for (const arg of path5.get("arguments")) {
|
|
2612
|
-
this.walkNode(arg);
|
|
2613
|
-
}
|
|
2614
|
-
}
|
|
2615
|
-
}
|
|
2616
|
-
walkExportDeclaration(path5) {
|
|
2617
|
-
walkExportDeclaration(this, path5);
|
|
2618
|
-
}
|
|
2619
|
-
walkExportNamedDeclaration(path5) {
|
|
2620
|
-
walkExportNamedDeclaration(this, path5);
|
|
2621
|
-
}
|
|
2622
|
-
walkExportDefaultDeclaration(path5) {
|
|
2623
|
-
walkExportDefaultDeclaration(this, path5);
|
|
2624
|
-
}
|
|
2625
|
-
walkExportAllDeclaration(path5) {
|
|
2626
|
-
walkExportAllDeclaration(this, path5);
|
|
2627
|
-
}
|
|
2628
|
-
};
|
|
2629
|
-
|
|
2630
|
-
// src/js/taggedTemplateIgnore.ts
|
|
2631
|
-
function createTaggedTemplateIgnore({ matcher, names }) {
|
|
2632
|
-
const bindingIgnoreCache = /* @__PURE__ */ new Map();
|
|
2633
|
-
const taggedTemplateIgnoreCache = /* @__PURE__ */ new WeakMap();
|
|
2634
|
-
const seenBindings = /* @__PURE__ */ new Set();
|
|
2635
|
-
let singleCanonicalIgnoreName;
|
|
2636
|
-
let canonicalIgnoreNames;
|
|
2637
|
-
for (const item of _nullishCoalesce(names, () => ( []))) {
|
|
2638
|
-
if (typeof item !== "string") {
|
|
2639
|
-
continue;
|
|
2640
|
-
}
|
|
2641
|
-
if (singleCanonicalIgnoreName === void 0) {
|
|
2642
|
-
singleCanonicalIgnoreName = item;
|
|
2643
|
-
continue;
|
|
2644
|
-
}
|
|
2645
|
-
if (item === singleCanonicalIgnoreName) {
|
|
2646
|
-
continue;
|
|
2647
|
-
}
|
|
2648
|
-
if (!canonicalIgnoreNames) {
|
|
2649
|
-
canonicalIgnoreNames = /* @__PURE__ */ new Set([singleCanonicalIgnoreName, item]);
|
|
2650
|
-
continue;
|
|
2651
|
-
}
|
|
2652
|
-
canonicalIgnoreNames.add(item);
|
|
2653
|
-
}
|
|
2654
|
-
const hasCanonicalIgnoreNames = singleCanonicalIgnoreName !== void 0;
|
|
2655
|
-
const matchesIgnoreName = (value) => {
|
|
2656
|
-
if (hasCanonicalIgnoreNames) {
|
|
2657
|
-
if (canonicalIgnoreNames) {
|
|
2658
|
-
if (canonicalIgnoreNames.has(value)) {
|
|
2659
|
-
return true;
|
|
2660
|
-
}
|
|
2661
|
-
} else if (value === singleCanonicalIgnoreName) {
|
|
2662
|
-
return true;
|
|
2663
|
-
}
|
|
2664
|
-
}
|
|
2665
|
-
return matcher(value);
|
|
2666
|
-
};
|
|
2667
|
-
const propertyMatches = (propertyPath) => {
|
|
2668
|
-
if (!propertyPath) {
|
|
2669
|
-
return false;
|
|
2670
|
-
}
|
|
2671
|
-
if (propertyPath.isIdentifier()) {
|
|
2672
|
-
return matchesIgnoreName(propertyPath.node.name);
|
|
2673
|
-
}
|
|
2674
|
-
if (propertyPath.isStringLiteral()) {
|
|
2675
|
-
return matchesIgnoreName(propertyPath.node.value);
|
|
2676
|
-
}
|
|
2677
|
-
return false;
|
|
2678
|
-
};
|
|
2679
|
-
const resolvesMemberExpressionToIgnore = (path5, seen) => {
|
|
2680
|
-
const propertyPath = path5.get("property");
|
|
2681
|
-
if (propertyMatches(propertyPath)) {
|
|
2682
|
-
return true;
|
|
2683
|
-
}
|
|
2684
|
-
const objectPath = path5.get("object");
|
|
2685
|
-
if (objectPath.isIdentifier()) {
|
|
2686
|
-
const scope = _optionalChain([objectPath, 'optionalAccess', _77 => _77.scope]);
|
|
2687
|
-
const binding = _optionalChain([scope, 'optionalAccess', _78 => _78.getBinding, 'optionalCall', _79 => _79(objectPath.node.name)]);
|
|
2688
|
-
if (binding) {
|
|
2689
|
-
return resolvesToWeappTwIgnore(binding, seen);
|
|
2690
|
-
}
|
|
2691
|
-
}
|
|
2692
|
-
return false;
|
|
2693
|
-
};
|
|
2694
|
-
const resolvesToWeappTwIgnore = (binding, seen) => {
|
|
2695
|
-
const cached = bindingIgnoreCache.get(binding);
|
|
2696
|
-
if (cached !== void 0) {
|
|
2697
|
-
return cached;
|
|
2698
|
-
}
|
|
2699
|
-
if (seen.has(binding)) {
|
|
2700
|
-
return false;
|
|
2701
|
-
}
|
|
2702
|
-
seen.add(binding);
|
|
2703
|
-
let result = false;
|
|
2704
|
-
const bindingPath = binding.path;
|
|
2705
|
-
if (bindingPath.isImportSpecifier()) {
|
|
2706
|
-
const imported = bindingPath.node.imported;
|
|
2707
|
-
if (imported.type === "Identifier" && matchesIgnoreName(imported.name)) {
|
|
2708
|
-
result = true;
|
|
2709
|
-
} else if (imported.type === "StringLiteral" && matchesIgnoreName(imported.value)) {
|
|
2710
|
-
result = true;
|
|
2711
|
-
}
|
|
2712
|
-
} else if (bindingPath.isVariableDeclarator()) {
|
|
2713
|
-
const init = bindingPath.get("init");
|
|
2714
|
-
if (init && init.node) {
|
|
2715
|
-
if (init.isIdentifier()) {
|
|
2716
|
-
const target = _optionalChain([binding, 'optionalAccess', _80 => _80.scope, 'optionalAccess', _81 => _81.getBinding, 'optionalCall', _82 => _82(init.node.name)]);
|
|
2717
|
-
if (target) {
|
|
2718
|
-
result = resolvesToWeappTwIgnore(target, seen);
|
|
2719
|
-
}
|
|
2720
|
-
} else if (init.isMemberExpression()) {
|
|
2721
|
-
result = resolvesMemberExpressionToIgnore(init, seen);
|
|
2722
|
-
}
|
|
2723
|
-
}
|
|
2724
|
-
}
|
|
2725
|
-
bindingIgnoreCache.set(binding, result);
|
|
2726
|
-
seen.delete(binding);
|
|
2727
|
-
return result;
|
|
2728
|
-
};
|
|
2729
|
-
const getEffectiveTagPath = (tagPath) => {
|
|
2730
|
-
let current = tagPath;
|
|
2731
|
-
while (true) {
|
|
2732
|
-
if (_optionalChain([current, 'access', _83 => _83.isParenthesizedExpression, 'optionalCall', _84 => _84()]) || current.node.type === "ParenthesizedExpression") {
|
|
2733
|
-
current = current.get("expression");
|
|
2734
|
-
continue;
|
|
2735
|
-
}
|
|
2736
|
-
if (current.isTSAsExpression() || current.isTSTypeAssertion()) {
|
|
2737
|
-
current = current.get("expression");
|
|
2738
|
-
continue;
|
|
2739
|
-
}
|
|
2740
|
-
if (current.isTSNonNullExpression()) {
|
|
2741
|
-
current = current.get("expression");
|
|
2742
|
-
continue;
|
|
2743
|
-
}
|
|
2744
|
-
if (_optionalChain([current, 'access', _85 => _85.isTypeCastExpression, 'optionalCall', _86 => _86()])) {
|
|
2745
|
-
current = current.get("expression");
|
|
2746
|
-
continue;
|
|
2747
|
-
}
|
|
2748
|
-
if (current.isSequenceExpression()) {
|
|
2749
|
-
const expressions = current.get("expressions");
|
|
2750
|
-
const last = expressions.at(-1);
|
|
2751
|
-
if (last) {
|
|
2752
|
-
current = last;
|
|
2753
|
-
continue;
|
|
2754
|
-
}
|
|
2755
|
-
}
|
|
2756
|
-
if (_optionalChain([current, 'access', _87 => _87.isCallExpression, 'optionalCall', _88 => _88()]) || current.node.type === "CallExpression") {
|
|
2757
|
-
const callee = current.get("callee");
|
|
2758
|
-
current = callee;
|
|
2759
|
-
continue;
|
|
2760
|
-
}
|
|
2761
|
-
break;
|
|
2762
|
-
}
|
|
2763
|
-
return current;
|
|
2764
|
-
};
|
|
2765
|
-
const evaluateTagPath = (tagPath, seen) => {
|
|
2766
|
-
if (_optionalChain([tagPath, 'access', _89 => _89.isCallExpression, 'optionalCall', _90 => _90()]) || tagPath.node.type === "CallExpression") {
|
|
2767
|
-
const calleePath = tagPath.get("callee");
|
|
2768
|
-
return evaluateTagPath(calleePath, seen);
|
|
2769
|
-
}
|
|
2770
|
-
if (tagPath.isIdentifier()) {
|
|
2771
|
-
if (matchesIgnoreName(tagPath.node.name)) {
|
|
2772
|
-
return true;
|
|
2773
|
-
}
|
|
2774
|
-
const binding = _optionalChain([tagPath, 'optionalAccess', _91 => _91.scope, 'optionalAccess', _92 => _92.getBinding, 'optionalCall', _93 => _93(tagPath.node.name)]);
|
|
2775
|
-
if (binding) {
|
|
2776
|
-
return resolvesToWeappTwIgnore(binding, seen);
|
|
2777
|
-
}
|
|
2778
|
-
return false;
|
|
2779
|
-
}
|
|
2780
|
-
if (tagPath.isMemberExpression()) {
|
|
2781
|
-
return resolvesMemberExpressionToIgnore(tagPath, seen);
|
|
2782
|
-
}
|
|
2783
|
-
return false;
|
|
2784
|
-
};
|
|
2785
|
-
const computeIgnore = (tagPath) => {
|
|
2786
|
-
const cached = taggedTemplateIgnoreCache.get(tagPath.node);
|
|
2787
|
-
if (cached !== void 0) {
|
|
2788
|
-
return cached;
|
|
2789
|
-
}
|
|
2790
|
-
const effectiveTagPath = getEffectiveTagPath(tagPath);
|
|
2791
|
-
const effectiveCached = taggedTemplateIgnoreCache.get(effectiveTagPath.node);
|
|
2792
|
-
if (effectiveCached !== void 0) {
|
|
2793
|
-
taggedTemplateIgnoreCache.set(tagPath.node, effectiveCached);
|
|
2794
|
-
return effectiveCached;
|
|
2795
|
-
}
|
|
2796
|
-
seenBindings.clear();
|
|
2797
|
-
const result = evaluateTagPath(effectiveTagPath, seenBindings);
|
|
2798
|
-
taggedTemplateIgnoreCache.set(effectiveTagPath.node, result);
|
|
2799
|
-
taggedTemplateIgnoreCache.set(tagPath.node, result);
|
|
2800
|
-
return result;
|
|
2801
|
-
};
|
|
2802
|
-
return {
|
|
2803
|
-
shouldIgnore(tagPath) {
|
|
2804
|
-
return computeIgnore(tagPath);
|
|
2805
|
-
},
|
|
2806
|
-
getEffectiveTagPath
|
|
2807
|
-
};
|
|
2808
|
-
}
|
|
2809
|
-
|
|
2810
|
-
// src/js/babel.ts
|
|
2811
|
-
var EXPRESSION_WRAPPER_PREFIX = "(\n";
|
|
2812
|
-
var EXPRESSION_WRAPPER_SUFFIX = "\n)";
|
|
2813
|
-
var EMPTY_IGNORED_PATHS = /* @__PURE__ */ new WeakSet();
|
|
2814
|
-
var EMPTY_IMPORT_DECLARATIONS = /* @__PURE__ */ new Set();
|
|
2815
|
-
var EMPTY_EXPORT_DECLARATIONS = /* @__PURE__ */ new Set();
|
|
2816
|
-
var EMPTY_REQUIRE_CALL_PATHS = [];
|
|
2817
|
-
var ignoredTaggedTemplateMatcherCache = /* @__PURE__ */ new WeakMap();
|
|
2818
|
-
var defaultEvalHandler;
|
|
2819
|
-
function getIgnoredTaggedTemplateMatcher(options) {
|
|
2820
|
-
const cached = ignoredTaggedTemplateMatcherCache.get(options);
|
|
2821
|
-
if (cached) {
|
|
2822
|
-
return cached;
|
|
2823
|
-
}
|
|
2824
|
-
const created = createNameMatcher(options.ignoreTaggedTemplateExpressionIdentifiers, { exact: true });
|
|
2825
|
-
ignoredTaggedTemplateMatcherCache.set(options, created);
|
|
2826
|
-
return created;
|
|
2827
|
-
}
|
|
2828
|
-
function getDefaultEvalHandler() {
|
|
2829
|
-
if (!defaultEvalHandler) {
|
|
2830
|
-
throw new Error("Default JS eval handler is not initialized.");
|
|
2831
|
-
}
|
|
2832
|
-
return defaultEvalHandler;
|
|
2833
|
-
}
|
|
2834
|
-
function analyzeSource(ast, options, handler, collectModuleMetadata = true) {
|
|
2835
|
-
const jsTokenUpdater = new JsTokenUpdater();
|
|
2836
|
-
const needScope = Boolean(options.ignoreCallExpressionIdentifiers && options.ignoreCallExpressionIdentifiers.length > 0);
|
|
2837
|
-
const ignoredPaths = needScope ? /* @__PURE__ */ new WeakSet() : EMPTY_IGNORED_PATHS;
|
|
2838
|
-
const walker = needScope ? new NodePathWalker({
|
|
2839
|
-
ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
|
|
2840
|
-
callback(path5) {
|
|
2841
|
-
ignoredPaths.add(path5);
|
|
2842
|
-
}
|
|
2843
|
-
}) : new NodePathWalker();
|
|
2844
|
-
let taggedTemplateIgnore;
|
|
2845
|
-
const hasTaggedTemplateIgnoreIdentifiers = Boolean(
|
|
2846
|
-
options.ignoreTaggedTemplateExpressionIdentifiers && options.ignoreTaggedTemplateExpressionIdentifiers.length > 0
|
|
2847
|
-
);
|
|
2848
|
-
function getTaggedTemplateIgnore() {
|
|
2849
|
-
if (!taggedTemplateIgnore) {
|
|
2850
|
-
taggedTemplateIgnore = createTaggedTemplateIgnore({
|
|
2851
|
-
matcher: getIgnoredTaggedTemplateMatcher(options),
|
|
2852
|
-
names: options.ignoreTaggedTemplateExpressionIdentifiers
|
|
2853
|
-
});
|
|
2854
|
-
}
|
|
2855
|
-
return taggedTemplateIgnore;
|
|
2856
|
-
}
|
|
2857
|
-
const targetPaths = [];
|
|
2858
|
-
const importDeclarations = collectModuleMetadata ? /* @__PURE__ */ new Set() : EMPTY_IMPORT_DECLARATIONS;
|
|
2859
|
-
const exportDeclarations = collectModuleMetadata ? /* @__PURE__ */ new Set() : EMPTY_EXPORT_DECLARATIONS;
|
|
2860
|
-
const requireCallPaths = collectModuleMetadata ? [] : EMPTY_REQUIRE_CALL_PATHS;
|
|
2861
|
-
const evalHandler = _nullishCoalesce(handler, () => ( getDefaultEvalHandler()));
|
|
2862
|
-
const templateElementEnter = hasTaggedTemplateIgnoreIdentifiers ? (p) => {
|
|
2863
|
-
const pp = p.parentPath;
|
|
2864
|
-
if (pp.isTemplateLiteral()) {
|
|
2865
|
-
const ppp = pp.parentPath;
|
|
2866
|
-
if (isEvalPath(ppp)) {
|
|
2867
|
-
return;
|
|
2868
|
-
}
|
|
2869
|
-
if (ppp.isTaggedTemplateExpression()) {
|
|
2870
|
-
const tagPath = ppp.get("tag");
|
|
2871
|
-
if (getTaggedTemplateIgnore().shouldIgnore(tagPath)) {
|
|
2872
|
-
return;
|
|
2873
|
-
}
|
|
2874
|
-
}
|
|
2875
|
-
}
|
|
2876
|
-
targetPaths.push(p);
|
|
2877
|
-
} : (p) => {
|
|
2878
|
-
const pp = p.parentPath;
|
|
2879
|
-
if (pp.isTemplateLiteral()) {
|
|
2880
|
-
const ppp = pp.parentPath;
|
|
2881
|
-
if (isEvalPath(ppp)) {
|
|
2882
|
-
return;
|
|
2883
|
-
}
|
|
2884
|
-
}
|
|
2885
|
-
targetPaths.push(p);
|
|
2886
|
-
};
|
|
2887
|
-
const callExpressionEnter = !collectModuleMetadata && !needScope ? (p) => {
|
|
2888
|
-
if (isEvalPath(p)) {
|
|
2889
|
-
walkEvalExpression(p, options, jsTokenUpdater, evalHandler);
|
|
2890
|
-
}
|
|
2891
|
-
} : (p) => {
|
|
2892
|
-
if (isEvalPath(p)) {
|
|
2893
|
-
walkEvalExpression(p, options, jsTokenUpdater, evalHandler);
|
|
2894
|
-
return;
|
|
2895
|
-
}
|
|
2896
|
-
const calleePath = p.get("callee");
|
|
2897
|
-
if (collectModuleMetadata && calleePath.isIdentifier({ name: "require" }) && !_optionalChain([p, 'optionalAccess', _94 => _94.scope, 'optionalAccess', _95 => _95.hasBinding, 'optionalCall', _96 => _96("require")])) {
|
|
2898
|
-
const args = p.get("arguments");
|
|
2899
|
-
if (Array.isArray(args) && args.length > 0) {
|
|
2900
|
-
const first = args[0];
|
|
2901
|
-
if (_optionalChain([first, 'optionalAccess', _97 => _97.isStringLiteral, 'call', _98 => _98()])) {
|
|
2902
|
-
requireCallPaths.push(first);
|
|
2903
|
-
}
|
|
2904
|
-
}
|
|
2905
|
-
}
|
|
2906
|
-
if (needScope) {
|
|
2907
|
-
walker.walkCallExpression(p);
|
|
2908
|
-
}
|
|
2909
|
-
};
|
|
2910
|
-
const traverseOptions = {
|
|
2911
|
-
StringLiteral: {
|
|
2912
|
-
enter(p) {
|
|
2913
|
-
if (isEvalPath(p.parentPath)) {
|
|
2914
|
-
return;
|
|
2915
|
-
}
|
|
2916
|
-
targetPaths.push(p);
|
|
2917
|
-
}
|
|
2918
|
-
},
|
|
2919
|
-
TemplateElement: {
|
|
2920
|
-
enter: templateElementEnter
|
|
2921
|
-
},
|
|
2922
|
-
CallExpression: {
|
|
2923
|
-
enter: callExpressionEnter
|
|
2924
|
-
},
|
|
2925
|
-
...collectModuleMetadata ? {
|
|
2926
|
-
ImportDeclaration: {
|
|
2927
|
-
enter(p) {
|
|
2928
|
-
importDeclarations.add(p);
|
|
2929
|
-
}
|
|
2930
|
-
},
|
|
2931
|
-
ExportDeclaration: {
|
|
2932
|
-
enter(p) {
|
|
2933
|
-
exportDeclarations.add(p);
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
} : {}
|
|
2937
|
-
};
|
|
2938
|
-
traverse(ast, { ...traverseOptions, noScope: !needScope });
|
|
2939
|
-
return {
|
|
2940
|
-
walker,
|
|
2941
|
-
jsTokenUpdater,
|
|
2942
|
-
ast,
|
|
2943
|
-
targetPaths,
|
|
2944
|
-
importDeclarations,
|
|
2945
|
-
exportDeclarations,
|
|
2946
|
-
requireCallPaths,
|
|
2947
|
-
ignoredPaths
|
|
2948
|
-
};
|
|
2949
|
-
}
|
|
2950
|
-
function jsHandler(rawSource, options) {
|
|
2951
|
-
const shouldWrapExpression = Boolean(options.wrapExpression);
|
|
2952
|
-
const source = shouldWrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
|
|
2953
|
-
let ast;
|
|
2954
|
-
try {
|
|
2955
|
-
ast = babelParse(source, options.babelParserOptions);
|
|
2956
|
-
} catch (error) {
|
|
2957
|
-
return {
|
|
2958
|
-
code: rawSource,
|
|
2959
|
-
error
|
|
2960
|
-
};
|
|
2961
|
-
}
|
|
2962
|
-
const needsModuleMetadata = Boolean(options.moduleSpecifierReplacements || options.moduleGraph && options.filename);
|
|
2963
|
-
const analysis = analyzeSource(ast, options, jsHandler, needsModuleMetadata);
|
|
2964
|
-
const ms = processUpdatedSource(source, options, analysis);
|
|
2965
|
-
if (shouldWrapExpression) {
|
|
2966
|
-
const start = 0;
|
|
2967
|
-
const end = source.length;
|
|
2968
|
-
const prefixLength = EXPRESSION_WRAPPER_PREFIX.length;
|
|
2969
|
-
const suffixLength = EXPRESSION_WRAPPER_SUFFIX.length;
|
|
2970
|
-
ms.remove(start, start + prefixLength);
|
|
2971
|
-
ms.remove(end - suffixLength, end);
|
|
2972
|
-
}
|
|
2973
|
-
const result = {
|
|
2974
|
-
code: ms.toString()
|
|
2975
|
-
};
|
|
2976
|
-
if (options.generateMap) {
|
|
2977
|
-
Object.defineProperty(result, "map", {
|
|
2978
|
-
configurable: true,
|
|
2979
|
-
enumerable: true,
|
|
2980
|
-
get() {
|
|
2981
|
-
return ms.generateMap();
|
|
2982
|
-
}
|
|
2983
|
-
});
|
|
2984
|
-
}
|
|
2985
|
-
if (options.moduleGraph && options.filename) {
|
|
2986
|
-
const graph = new JsModuleGraph(
|
|
2987
|
-
{
|
|
2988
|
-
filename: options.filename,
|
|
2989
|
-
source: rawSource,
|
|
2990
|
-
analysis,
|
|
2991
|
-
handlerOptions: options
|
|
2992
|
-
},
|
|
2993
|
-
options.moduleGraph
|
|
2994
|
-
);
|
|
2995
|
-
const linked = graph.build();
|
|
2996
|
-
if (linked) {
|
|
2997
|
-
result.linked = linked;
|
|
2998
|
-
}
|
|
2999
|
-
}
|
|
3000
|
-
return result;
|
|
3001
|
-
}
|
|
3002
|
-
defaultEvalHandler = jsHandler;
|
|
3003
|
-
|
|
3004
|
-
// src/js/index.ts
|
|
3005
|
-
var RESULT_CACHE_MAX = 512;
|
|
3006
|
-
var CACHEABLE_SOURCE_MAX_LENGTH = 512;
|
|
3007
|
-
var classNameSetIds = /* @__PURE__ */ new WeakMap();
|
|
3008
|
-
var nextClassNameSetId = 0;
|
|
3009
|
-
function getClassNameSetId(set) {
|
|
3010
|
-
if (!set) {
|
|
3011
|
-
return "none";
|
|
3012
|
-
}
|
|
3013
|
-
const existing = classNameSetIds.get(set);
|
|
3014
|
-
if (existing !== void 0) {
|
|
3015
|
-
return String(existing);
|
|
3016
|
-
}
|
|
3017
|
-
const id = nextClassNameSetId++;
|
|
3018
|
-
classNameSetIds.set(set, id);
|
|
3019
|
-
return String(id);
|
|
3020
|
-
}
|
|
3021
|
-
var fingerprintCache = /* @__PURE__ */ new WeakMap();
|
|
3022
|
-
function getOptionsFingerprint(options) {
|
|
3023
|
-
const cached = fingerprintCache.get(options);
|
|
3024
|
-
if (cached) {
|
|
3025
|
-
return cached;
|
|
3026
|
-
}
|
|
3027
|
-
const parts = [
|
|
3028
|
-
getClassNameSetId(options.classNameSet),
|
|
3029
|
-
JSON.stringify(_nullishCoalesce(options.escapeMap, () => ( null))),
|
|
3030
|
-
options.needEscaped ? "1" : "0",
|
|
3031
|
-
options.alwaysEscape ? "1" : "0",
|
|
3032
|
-
options.unescapeUnicode ? "1" : "0",
|
|
3033
|
-
options.generateMap ? "1" : "0",
|
|
3034
|
-
options.uniAppX ? "1" : "0",
|
|
3035
|
-
options.wrapExpression ? "1" : "0",
|
|
3036
|
-
String(_nullishCoalesce(options.tailwindcssMajorVersion, () => ( ""))),
|
|
3037
|
-
String(_nullishCoalesce(options.staleClassNameFallback, () => ( ""))),
|
|
3038
|
-
String(_nullishCoalesce(options.jsArbitraryValueFallback, () => ( ""))),
|
|
3039
|
-
JSON.stringify(_nullishCoalesce(options.arbitraryValues, () => ( null))),
|
|
3040
|
-
JSON.stringify(_nullishCoalesce(options.ignoreCallExpressionIdentifiers, () => ( null))),
|
|
3041
|
-
JSON.stringify(_nullishCoalesce(_optionalChain([options, 'access', _99 => _99.ignoreTaggedTemplateExpressionIdentifiers, 'optionalAccess', _100 => _100.map, 'call', _101 => _101((v) => v instanceof RegExp ? v.source : v)]), () => ( null))),
|
|
3042
|
-
JSON.stringify(_nullishCoalesce(options.moduleSpecifierReplacements, () => ( null))),
|
|
3043
|
-
JSON.stringify(_nullishCoalesce(options.babelParserOptions, () => ( null)))
|
|
3044
|
-
];
|
|
3045
|
-
const fingerprint = parts.join("|");
|
|
3046
|
-
fingerprintCache.set(options, fingerprint);
|
|
3047
|
-
return fingerprint;
|
|
3048
|
-
}
|
|
3049
|
-
function hasDefinedOverrides(options) {
|
|
3050
|
-
if (!options) {
|
|
3051
|
-
return false;
|
|
3052
|
-
}
|
|
3053
|
-
for (const key in options) {
|
|
3054
|
-
if (options[key] !== void 0) {
|
|
3055
|
-
return true;
|
|
3056
|
-
}
|
|
3057
|
-
}
|
|
3058
|
-
return false;
|
|
3059
|
-
}
|
|
3060
|
-
function shouldCacheJsResult(rawSource, options) {
|
|
3061
|
-
if (rawSource.length === 0 || rawSource.length > CACHEABLE_SOURCE_MAX_LENGTH) {
|
|
3062
|
-
return false;
|
|
3063
|
-
}
|
|
3064
|
-
if (options.moduleGraph || options.filename) {
|
|
3065
|
-
return false;
|
|
3066
|
-
}
|
|
3067
|
-
return true;
|
|
3068
|
-
}
|
|
3069
|
-
function createJsHandler(options) {
|
|
3070
|
-
const defaults = {
|
|
3071
|
-
escapeMap: options.escapeMap,
|
|
3072
|
-
staleClassNameFallback: options.staleClassNameFallback,
|
|
3073
|
-
jsArbitraryValueFallback: options.jsArbitraryValueFallback,
|
|
3074
|
-
tailwindcssMajorVersion: options.tailwindcssMajorVersion,
|
|
3075
|
-
arbitraryValues: options.arbitraryValues,
|
|
3076
|
-
jsPreserveClass: options.jsPreserveClass,
|
|
3077
|
-
generateMap: options.generateMap,
|
|
3078
|
-
needEscaped: options.needEscaped,
|
|
3079
|
-
alwaysEscape: options.alwaysEscape,
|
|
3080
|
-
unescapeUnicode: options.unescapeUnicode,
|
|
3081
|
-
babelParserOptions: options.babelParserOptions,
|
|
3082
|
-
ignoreCallExpressionIdentifiers: options.ignoreCallExpressionIdentifiers,
|
|
3083
|
-
ignoreTaggedTemplateExpressionIdentifiers: options.ignoreTaggedTemplateExpressionIdentifiers,
|
|
3084
|
-
uniAppX: options.uniAppX,
|
|
3085
|
-
moduleSpecifierReplacements: options.moduleSpecifierReplacements
|
|
3086
|
-
};
|
|
3087
|
-
const defaultOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
3088
|
-
let resolvedOptionsWithoutClassNameSet;
|
|
3089
|
-
const overrideOptionsCache = /* @__PURE__ */ new WeakMap();
|
|
3090
|
-
const resultCache = new (0, _lrucache.LRUCache)({ max: RESULT_CACHE_MAX });
|
|
3091
|
-
function resolveDefaultOptions(classNameSet) {
|
|
3092
|
-
if (!classNameSet) {
|
|
3093
|
-
if (!resolvedOptionsWithoutClassNameSet) {
|
|
3094
|
-
resolvedOptionsWithoutClassNameSet = {
|
|
3095
|
-
...defaults,
|
|
3096
|
-
classNameSet
|
|
3097
|
-
};
|
|
3098
|
-
}
|
|
3099
|
-
return resolvedOptionsWithoutClassNameSet;
|
|
3100
|
-
}
|
|
3101
|
-
const cached = defaultOptionsCache.get(classNameSet);
|
|
3102
|
-
if (cached) {
|
|
3103
|
-
return cached;
|
|
3104
|
-
}
|
|
3105
|
-
const created = {
|
|
3106
|
-
...defaults,
|
|
3107
|
-
classNameSet
|
|
3108
|
-
};
|
|
3109
|
-
defaultOptionsCache.set(classNameSet, created);
|
|
3110
|
-
return created;
|
|
3111
|
-
}
|
|
3112
|
-
function getCachedJsResult(rawSource, resolvedOptions) {
|
|
3113
|
-
if (!shouldCacheJsResult(rawSource, resolvedOptions)) {
|
|
3114
|
-
return void 0;
|
|
3115
|
-
}
|
|
3116
|
-
const key = `${getOptionsFingerprint(resolvedOptions)}:${_node.md5.call(void 0, rawSource)}`;
|
|
3117
|
-
return resultCache.get(key);
|
|
3118
|
-
}
|
|
3119
|
-
function setCachedJsResult(rawSource, resolvedOptions, result) {
|
|
3120
|
-
if (!shouldCacheJsResult(rawSource, resolvedOptions) || result.error || result.linked) {
|
|
3121
|
-
return result;
|
|
3122
|
-
}
|
|
3123
|
-
const key = `${getOptionsFingerprint(resolvedOptions)}:${_node.md5.call(void 0, rawSource)}`;
|
|
3124
|
-
resultCache.set(key, result);
|
|
3125
|
-
return result;
|
|
3126
|
-
}
|
|
3127
|
-
function resolveOptions(classNameSet, overrideOptions) {
|
|
3128
|
-
if (!hasDefinedOverrides(overrideOptions)) {
|
|
3129
|
-
return resolveDefaultOptions(classNameSet);
|
|
3130
|
-
}
|
|
3131
|
-
let entry = overrideOptionsCache.get(overrideOptions);
|
|
3132
|
-
if (!entry) {
|
|
3133
|
-
entry = { bySet: /* @__PURE__ */ new WeakMap() };
|
|
3134
|
-
overrideOptionsCache.set(overrideOptions, entry);
|
|
3135
|
-
}
|
|
3136
|
-
if (!classNameSet) {
|
|
3137
|
-
if (entry.noSet) {
|
|
3138
|
-
return entry.noSet;
|
|
3139
|
-
}
|
|
3140
|
-
const created2 = _chunkDYLQ6UOIjs.defuOverrideArray.call(void 0,
|
|
3141
|
-
{
|
|
3142
|
-
...overrideOptions,
|
|
3143
|
-
classNameSet
|
|
3144
|
-
},
|
|
3145
|
-
defaults
|
|
3146
|
-
);
|
|
3147
|
-
entry.noSet = created2;
|
|
3148
|
-
return created2;
|
|
3149
|
-
}
|
|
3150
|
-
const cached = entry.bySet.get(classNameSet);
|
|
3151
|
-
if (cached) {
|
|
3152
|
-
return cached;
|
|
3153
|
-
}
|
|
3154
|
-
const created = _chunkDYLQ6UOIjs.defuOverrideArray.call(void 0,
|
|
3155
|
-
{
|
|
3156
|
-
...overrideOptions,
|
|
3157
|
-
classNameSet
|
|
3158
|
-
},
|
|
3159
|
-
defaults
|
|
3160
|
-
);
|
|
3161
|
-
entry.bySet.set(classNameSet, created);
|
|
3162
|
-
return created;
|
|
3163
|
-
}
|
|
3164
|
-
function handler(rawSource, classNameSet, options2) {
|
|
3165
|
-
const resolvedOptions = resolveOptions(classNameSet, options2);
|
|
3166
|
-
const cached = getCachedJsResult(rawSource, resolvedOptions);
|
|
3167
|
-
if (cached) {
|
|
3168
|
-
return cached;
|
|
3169
|
-
}
|
|
3170
|
-
return setCachedJsResult(rawSource, resolvedOptions, jsHandler(rawSource, resolvedOptions));
|
|
3171
|
-
}
|
|
3172
|
-
return handler;
|
|
3173
|
-
}
|
|
3174
|
-
|
|
3175
|
-
// src/wxml/custom-attributes.ts
|
|
3176
|
-
function regTest(reg, str) {
|
|
3177
|
-
reg.lastIndex = 0;
|
|
3178
|
-
return reg.test(str);
|
|
3179
|
-
}
|
|
3180
|
-
function isPropsMatch(props, attr) {
|
|
3181
|
-
if (Array.isArray(props)) {
|
|
3182
|
-
let lowerAttr;
|
|
3183
|
-
for (const prop of props) {
|
|
3184
|
-
if (typeof prop === "string") {
|
|
3185
|
-
_nullishCoalesce(lowerAttr, () => ( (lowerAttr = attr.toLowerCase())));
|
|
3186
|
-
if (prop.toLowerCase() === lowerAttr) {
|
|
3187
|
-
return true;
|
|
3188
|
-
}
|
|
3189
|
-
} else if (regTest(prop, attr)) {
|
|
3190
|
-
return true;
|
|
3191
|
-
}
|
|
3192
|
-
}
|
|
3193
|
-
return false;
|
|
3194
|
-
} else if (typeof props === "string") {
|
|
3195
|
-
return props === attr;
|
|
3196
|
-
} else {
|
|
3197
|
-
return regTest(props, attr);
|
|
3198
|
-
}
|
|
3199
|
-
}
|
|
3200
|
-
function createAttributeMatcher(entities) {
|
|
3201
|
-
if (!entities || entities.length === 0) {
|
|
3202
|
-
return void 0;
|
|
3203
|
-
}
|
|
3204
|
-
const wildcardAttributeRules = [];
|
|
3205
|
-
const tagAttributeRuleMap = /* @__PURE__ */ new Map();
|
|
3206
|
-
const regexpAttributeRules = [];
|
|
3207
|
-
for (const [selector, props] of entities) {
|
|
3208
|
-
if (selector === "*") {
|
|
3209
|
-
wildcardAttributeRules.push(props);
|
|
3210
|
-
} else if (typeof selector === "string") {
|
|
3211
|
-
const list = tagAttributeRuleMap.get(selector);
|
|
3212
|
-
if (list) {
|
|
3213
|
-
list.push(props);
|
|
3214
|
-
} else {
|
|
3215
|
-
tagAttributeRuleMap.set(selector, [props]);
|
|
3216
|
-
}
|
|
3217
|
-
} else {
|
|
3218
|
-
regexpAttributeRules.push([selector, props]);
|
|
3219
|
-
}
|
|
3220
|
-
}
|
|
3221
|
-
return (tag, attr) => {
|
|
3222
|
-
for (const props of wildcardAttributeRules) {
|
|
3223
|
-
if (isPropsMatch(props, attr)) {
|
|
3224
|
-
return true;
|
|
3225
|
-
}
|
|
3226
|
-
}
|
|
3227
|
-
const tagRules = tagAttributeRuleMap.get(tag);
|
|
3228
|
-
if (tagRules) {
|
|
3229
|
-
for (const props of tagRules) {
|
|
3230
|
-
if (isPropsMatch(props, attr)) {
|
|
3231
|
-
return true;
|
|
3232
|
-
}
|
|
3233
|
-
}
|
|
3234
|
-
}
|
|
3235
|
-
for (const [selector, props] of regexpAttributeRules) {
|
|
3236
|
-
if (regTest(selector, tag) && isPropsMatch(props, attr)) {
|
|
3237
|
-
return true;
|
|
3238
|
-
}
|
|
3239
|
-
}
|
|
3240
|
-
return false;
|
|
3241
|
-
};
|
|
3242
|
-
}
|
|
3243
|
-
|
|
3244
|
-
// src/wxml/utils/codegen/legacy-rewriter.ts
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
// src/wxml/utils/codegen/legacy-visitor.ts
|
|
3248
|
-
var _types = require('@babel/types'); var t = _interopRequireWildcard(_types);
|
|
3249
|
-
function shouldSkipLegacyStringLiteral(path5) {
|
|
3250
|
-
if (t.isMemberExpression(path5.parent)) {
|
|
3251
|
-
return true;
|
|
3252
|
-
}
|
|
3253
|
-
return Boolean(
|
|
3254
|
-
t.isBinaryExpression(path5.parent) && (t.isConditionalExpression(_optionalChain([path5, 'access', _102 => _102.parentPath, 'optionalAccess', _103 => _103.parent])) || t.isLogicalExpression(_optionalChain([path5, 'access', _104 => _104.parentPath, 'optionalAccess', _105 => _105.parent])))
|
|
3255
|
-
);
|
|
3256
|
-
}
|
|
3257
|
-
function createLegacyTraverseOptions(options, jsTokenUpdater) {
|
|
3258
|
-
const legacyReplaceOptions = {
|
|
3259
|
-
escapeMap: options.escapeMap,
|
|
3260
|
-
classNameSet: options.runtimeSet,
|
|
3261
|
-
needEscaped: true,
|
|
3262
|
-
alwaysEscape: true
|
|
3263
|
-
};
|
|
3264
|
-
return {
|
|
3265
|
-
StringLiteral(path5) {
|
|
3266
|
-
if (shouldSkipLegacyStringLiteral(path5)) {
|
|
3267
|
-
return;
|
|
3268
|
-
}
|
|
3269
|
-
jsTokenUpdater.addToken(
|
|
3270
|
-
replaceHandleValue(
|
|
3271
|
-
path5,
|
|
3272
|
-
legacyReplaceOptions
|
|
3273
|
-
)
|
|
3274
|
-
);
|
|
3275
|
-
},
|
|
3276
|
-
noScope: true
|
|
3277
|
-
};
|
|
3278
|
-
}
|
|
3279
|
-
|
|
3280
|
-
// src/wxml/utils/codegen/legacy-rewriter.ts
|
|
3281
|
-
function rewriteLegacyExpression(match, options) {
|
|
3282
|
-
const ast = _parser.parseExpression.call(void 0, match);
|
|
3283
|
-
const jsTokenUpdater = new JsTokenUpdater();
|
|
3284
|
-
traverse(ast, createLegacyTraverseOptions(options, jsTokenUpdater));
|
|
3285
|
-
if (jsTokenUpdater.length === 0) {
|
|
3286
|
-
return match;
|
|
3287
|
-
}
|
|
3288
|
-
const ms = new (0, _magicstring2.default)(match);
|
|
3289
|
-
jsTokenUpdater.updateMagicString(ms);
|
|
3290
|
-
return ms.toString();
|
|
3291
|
-
}
|
|
3292
|
-
|
|
3293
|
-
// src/wxml/utils/codegen.ts
|
|
3294
|
-
var WRAP_EXPRESSION_HANDLER_OPTIONS = Object.freeze({
|
|
3295
|
-
wrapExpression: true
|
|
3296
|
-
});
|
|
3297
|
-
function generateCode(match, options = {}) {
|
|
3298
|
-
try {
|
|
3299
|
-
const { jsHandler: jsHandler2, runtimeSet, wrapExpression } = options;
|
|
3300
|
-
if (jsHandler2 && runtimeSet) {
|
|
3301
|
-
const initial = jsHandler2(
|
|
3302
|
-
match,
|
|
3303
|
-
runtimeSet,
|
|
3304
|
-
wrapExpression ? WRAP_EXPRESSION_HANDLER_OPTIONS : void 0
|
|
3305
|
-
);
|
|
3306
|
-
if (!initial.error || wrapExpression) {
|
|
3307
|
-
return initial.code;
|
|
3308
|
-
}
|
|
3309
|
-
const fallback = jsHandler2(match, runtimeSet, WRAP_EXPRESSION_HANDLER_OPTIONS);
|
|
3310
|
-
return fallback.code;
|
|
3311
|
-
} else {
|
|
3312
|
-
return rewriteLegacyExpression(match, options);
|
|
3313
|
-
}
|
|
3314
|
-
} catch (e6) {
|
|
3315
|
-
return match;
|
|
3316
|
-
}
|
|
3317
|
-
}
|
|
3318
|
-
|
|
3319
|
-
// src/wxml/utils/custom-template.ts
|
|
3320
|
-
var _htmlparser2 = require('htmlparser2');
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
// src/wxml/utils/template-fragments.ts
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
// src/wxml/whitespace.ts
|
|
3327
|
-
var WHITESPACE_CODES = /* @__PURE__ */ new Set([
|
|
3328
|
-
9,
|
|
3329
|
-
// 制表符 \t
|
|
3330
|
-
10,
|
|
3331
|
-
// 换行符 \n
|
|
3332
|
-
11,
|
|
3333
|
-
// 垂直制表符 \v
|
|
3334
|
-
12,
|
|
3335
|
-
// 换页符 \f
|
|
3336
|
-
13,
|
|
3337
|
-
// 回车符 \r
|
|
3338
|
-
32,
|
|
3339
|
-
// 空格
|
|
3340
|
-
160,
|
|
3341
|
-
// 不间断空格 \u00A0
|
|
3342
|
-
65279
|
|
3343
|
-
// 零宽无断行空格 \uFEFF
|
|
3344
|
-
]);
|
|
3345
|
-
function isWhitespace(char) {
|
|
3346
|
-
if (char.length === 0) {
|
|
3347
|
-
return false;
|
|
3348
|
-
}
|
|
3349
|
-
return WHITESPACE_CODES.has(char.charCodeAt(0));
|
|
3350
|
-
}
|
|
3351
|
-
function isAllWhitespace(value) {
|
|
3352
|
-
for (let i = 0; i < value.length; i++) {
|
|
3353
|
-
if (!WHITESPACE_CODES.has(value.charCodeAt(i))) {
|
|
3354
|
-
return false;
|
|
3355
|
-
}
|
|
3356
|
-
}
|
|
3357
|
-
return true;
|
|
3358
|
-
}
|
|
3359
|
-
|
|
3360
|
-
// src/wxml/Tokenizer.ts
|
|
3361
|
-
var Tokenizer = class {
|
|
3362
|
-
constructor() {
|
|
3363
|
-
this.reset();
|
|
3364
|
-
}
|
|
3365
|
-
processChar(char, index) {
|
|
3366
|
-
switch (this.state) {
|
|
3367
|
-
case 0 /* START */:
|
|
3368
|
-
if (isWhitespace(char)) {
|
|
3369
|
-
} else if (char === "{") {
|
|
3370
|
-
this.state = 2 /* OPEN_BRACE */;
|
|
3371
|
-
this.bufferStartIndex = index;
|
|
3372
|
-
this.buffer += char;
|
|
3373
|
-
this.expressionBuffer = char;
|
|
3374
|
-
this.expressionStartIndex = index;
|
|
3375
|
-
} else {
|
|
3376
|
-
this.state = 1 /* TEXT */;
|
|
3377
|
-
this.bufferStartIndex = index;
|
|
3378
|
-
this.buffer += char;
|
|
3379
|
-
}
|
|
3380
|
-
break;
|
|
3381
|
-
case 1 /* TEXT */:
|
|
3382
|
-
if (isWhitespace(char)) {
|
|
3383
|
-
this.tokens.push({ start: this.bufferStartIndex, end: index, value: this.buffer, expressions: this.expressions });
|
|
3384
|
-
this.buffer = "";
|
|
3385
|
-
this.expressions = [];
|
|
3386
|
-
this.state = 0 /* START */;
|
|
3387
|
-
} else if (char === "{") {
|
|
3388
|
-
this.buffer += char;
|
|
3389
|
-
this.expressionBuffer = char;
|
|
3390
|
-
this.expressionStartIndex = index;
|
|
3391
|
-
this.state = 2 /* OPEN_BRACE */;
|
|
3392
|
-
} else {
|
|
3393
|
-
this.buffer += char;
|
|
3394
|
-
}
|
|
3395
|
-
break;
|
|
3396
|
-
case 2 /* OPEN_BRACE */:
|
|
3397
|
-
if (char === "}") {
|
|
3398
|
-
this.buffer += char;
|
|
3399
|
-
this.expressionBuffer += char;
|
|
3400
|
-
this.state = 3 /* POTENTIAL_CLOSE */;
|
|
3401
|
-
} else {
|
|
3402
|
-
this.buffer += char;
|
|
3403
|
-
this.expressionBuffer += char;
|
|
3404
|
-
}
|
|
3405
|
-
break;
|
|
3406
|
-
case 3 /* POTENTIAL_CLOSE */:
|
|
3407
|
-
if (char === "}") {
|
|
3408
|
-
this.buffer += char;
|
|
3409
|
-
this.expressionBuffer += char;
|
|
3410
|
-
this.expressions.push({
|
|
3411
|
-
start: this.expressionStartIndex,
|
|
3412
|
-
end: index + 1,
|
|
3413
|
-
value: this.expressionBuffer
|
|
3414
|
-
});
|
|
3415
|
-
this.expressionBuffer = "";
|
|
3416
|
-
this.state = 4 /* BRACES_COMPLETE */;
|
|
3417
|
-
} else {
|
|
3418
|
-
this.buffer += char;
|
|
3419
|
-
this.expressionBuffer += char;
|
|
3420
|
-
this.state = 2 /* OPEN_BRACE */;
|
|
3421
|
-
}
|
|
3422
|
-
break;
|
|
3423
|
-
case 4 /* BRACES_COMPLETE */:
|
|
3424
|
-
if (isWhitespace(char)) {
|
|
3425
|
-
this.tokens.push({
|
|
3426
|
-
start: this.bufferStartIndex,
|
|
3427
|
-
end: index,
|
|
3428
|
-
value: this.buffer,
|
|
3429
|
-
expressions: this.expressions
|
|
3430
|
-
});
|
|
3431
|
-
this.buffer = "";
|
|
3432
|
-
this.expressions = [];
|
|
3433
|
-
this.state = 0 /* START */;
|
|
3434
|
-
} else if (char === "{") {
|
|
3435
|
-
this.expressionStartIndex = index;
|
|
3436
|
-
this.expressionBuffer = char;
|
|
3437
|
-
this.buffer += char;
|
|
3438
|
-
this.state = 2 /* OPEN_BRACE */;
|
|
3439
|
-
} else {
|
|
3440
|
-
this.buffer += char;
|
|
3441
|
-
this.state = 1 /* TEXT */;
|
|
3442
|
-
}
|
|
3443
|
-
break;
|
|
3444
|
-
default:
|
|
3445
|
-
throw new Error("Unexpected state");
|
|
3446
|
-
}
|
|
3447
|
-
}
|
|
3448
|
-
run(input) {
|
|
3449
|
-
this.reset();
|
|
3450
|
-
for (let i = 0; i < input.length; i++) {
|
|
3451
|
-
const char = input[i];
|
|
3452
|
-
this.processChar(char, i);
|
|
3453
|
-
}
|
|
3454
|
-
if (this.buffer.length > 0) {
|
|
3455
|
-
this.tokens.push({
|
|
3456
|
-
start: this.bufferStartIndex,
|
|
3457
|
-
end: input.length,
|
|
3458
|
-
value: this.buffer,
|
|
3459
|
-
expressions: this.expressions
|
|
3460
|
-
});
|
|
3461
|
-
}
|
|
3462
|
-
const tokens = this.tokens;
|
|
3463
|
-
this.reset();
|
|
3464
|
-
return tokens;
|
|
3465
|
-
}
|
|
3466
|
-
reset() {
|
|
3467
|
-
this.state = 0 /* START */;
|
|
3468
|
-
this.buffer = "";
|
|
3469
|
-
this.tokens = [];
|
|
3470
|
-
this.bufferStartIndex = 0;
|
|
3471
|
-
this.expressionBuffer = "";
|
|
3472
|
-
this.expressionStartIndex = 0;
|
|
3473
|
-
this.expressions = [];
|
|
3474
|
-
}
|
|
3475
|
-
};
|
|
3476
|
-
|
|
3477
|
-
// src/wxml/utils/fragment-helpers.ts
|
|
3478
|
-
function updateWhitespaceGap(ms, start, end, options) {
|
|
3479
|
-
const gap = ms.slice(start, end);
|
|
3480
|
-
if (isAllWhitespace(gap)) {
|
|
3481
|
-
ms.update(start, end, replaceWxml(gap, {
|
|
3482
|
-
keepEOL: false,
|
|
3483
|
-
escapeMap: options.escapeMap,
|
|
3484
|
-
ignoreHead: true
|
|
3485
|
-
}));
|
|
3486
|
-
}
|
|
3487
|
-
}
|
|
3488
|
-
function updateWxmlSegment(ms, start, end, options, keepEOL, ignoreHead) {
|
|
3489
|
-
ms.update(start, end, replaceWxml(ms.slice(start, end), {
|
|
3490
|
-
keepEOL,
|
|
3491
|
-
escapeMap: options.escapeMap,
|
|
3492
|
-
ignoreHead
|
|
3493
|
-
}));
|
|
3494
|
-
}
|
|
3495
|
-
function updateExpressionSegment(ms, exp, options) {
|
|
3496
|
-
const code = `{{${generateCode(exp.value.slice(2, -2), options)}}}`;
|
|
3497
|
-
ms.update(exp.start, exp.end, code);
|
|
3498
|
-
}
|
|
3499
|
-
|
|
3500
|
-
// src/wxml/utils/fragment-updater.ts
|
|
3501
|
-
function handleEachClassFragment(ms, tokens, options = {}) {
|
|
3502
|
-
let previousEnd = 0;
|
|
3503
|
-
for (const token of tokens) {
|
|
3504
|
-
if (token.start > previousEnd) {
|
|
3505
|
-
updateWhitespaceGap(ms, previousEnd, token.start, options);
|
|
3506
|
-
}
|
|
3507
|
-
let p = token.start;
|
|
3508
|
-
if (token.expressions.length > 0) {
|
|
3509
|
-
for (const exp of token.expressions) {
|
|
3510
|
-
if (exp.start > token.start && p < exp.start) {
|
|
3511
|
-
updateWxmlSegment(ms, p, exp.start, options, true, p > 0);
|
|
3512
|
-
}
|
|
3513
|
-
updateExpressionSegment(ms, exp, options);
|
|
3514
|
-
p = exp.end;
|
|
3515
|
-
}
|
|
3516
|
-
if (token.end > p) {
|
|
3517
|
-
updateWxmlSegment(ms, p, token.end, options, false, true);
|
|
3518
|
-
}
|
|
3519
|
-
} else {
|
|
3520
|
-
updateWxmlSegment(ms, token.start, token.end, options, false, false);
|
|
3521
|
-
}
|
|
3522
|
-
previousEnd = token.end;
|
|
3523
|
-
}
|
|
3524
|
-
if (tokens.length > 0) {
|
|
3525
|
-
const lastToken = tokens[tokens.length - 1];
|
|
3526
|
-
if (lastToken.end < ms.original.length) {
|
|
3527
|
-
updateWhitespaceGap(ms, lastToken.end, ms.original.length, options);
|
|
3528
|
-
}
|
|
3529
|
-
}
|
|
3530
|
-
}
|
|
3531
|
-
|
|
3532
|
-
// src/wxml/utils/template-fragments.ts
|
|
3533
|
-
var sharedTokenizer = new Tokenizer();
|
|
3534
|
-
function templateReplacer(original, options = {}, tokenizer) {
|
|
3535
|
-
const ms = new (0, _magicstring2.default)(original);
|
|
3536
|
-
const tok = _nullishCoalesce(tokenizer, () => ( sharedTokenizer));
|
|
3537
|
-
const tokens = tok.run(ms.original);
|
|
3538
|
-
handleEachClassFragment(ms, tokens, options);
|
|
3539
|
-
return ms.toString();
|
|
3540
|
-
}
|
|
3541
|
-
|
|
3542
|
-
// src/wxml/utils/custom-template.ts
|
|
3543
|
-
async function customTemplateHandler(rawSource, options, cachedMatcher) {
|
|
3544
|
-
const {
|
|
3545
|
-
customAttributesEntities = [],
|
|
3546
|
-
disabledDefaultTemplateHandler,
|
|
3547
|
-
inlineWxs,
|
|
3548
|
-
runtimeSet,
|
|
3549
|
-
jsHandler: jsHandler2
|
|
3550
|
-
} = _nullishCoalesce(options, () => ( {}));
|
|
3551
|
-
const matchCustomAttribute = _nullishCoalesce(cachedMatcher, () => ( createAttributeMatcher(customAttributesEntities)));
|
|
3552
|
-
const defaultTemplateHandlerEnabled = !disabledDefaultTemplateHandler;
|
|
3553
|
-
let replaceOptions;
|
|
3554
|
-
let cachedQuote;
|
|
3555
|
-
let s;
|
|
3556
|
-
let tag = "";
|
|
3557
|
-
let wxsArray;
|
|
3558
|
-
function getMagicString() {
|
|
3559
|
-
if (!s) {
|
|
3560
|
-
s = new (0, _magicstring2.default)(rawSource);
|
|
3561
|
-
}
|
|
3562
|
-
return s;
|
|
3563
|
-
}
|
|
3564
|
-
function getReplaceOptions(quote) {
|
|
3565
|
-
if (!replaceOptions) {
|
|
3566
|
-
replaceOptions = {
|
|
3567
|
-
...options,
|
|
3568
|
-
quote
|
|
3569
|
-
};
|
|
3570
|
-
cachedQuote = quote;
|
|
3571
|
-
return replaceOptions;
|
|
3572
|
-
}
|
|
3573
|
-
if (cachedQuote !== quote) {
|
|
3574
|
-
replaceOptions.quote = quote;
|
|
3575
|
-
cachedQuote = quote;
|
|
3576
|
-
}
|
|
3577
|
-
return replaceOptions;
|
|
3578
|
-
}
|
|
3579
|
-
function isDefaultTemplateAttribute(name) {
|
|
3580
|
-
if (name === "class" || name === "hover-class" || name === "virtualhostclass") {
|
|
3581
|
-
return true;
|
|
3582
|
-
}
|
|
3583
|
-
const lowerName = name.toLowerCase();
|
|
3584
|
-
return lowerName === "class" || lowerName === "hover-class" || lowerName === "virtualhostclass";
|
|
3585
|
-
}
|
|
3586
|
-
const parser = new (0, _htmlparser2.Parser)(
|
|
3587
|
-
{
|
|
3588
|
-
onopentagname(name) {
|
|
3589
|
-
tag = name;
|
|
3590
|
-
},
|
|
3591
|
-
onattribute(name, value, quote) {
|
|
3592
|
-
if (!value) {
|
|
3593
|
-
return;
|
|
3594
|
-
}
|
|
3595
|
-
const shouldHandleDefault = defaultTemplateHandlerEnabled && isDefaultTemplateAttribute(name);
|
|
3596
|
-
const shouldHandleCustom = _nullishCoalesce(_optionalChain([matchCustomAttribute, 'optionalCall', _106 => _106(tag, name)]), () => ( false));
|
|
3597
|
-
if (!shouldHandleDefault && !shouldHandleCustom) {
|
|
3598
|
-
return;
|
|
3599
|
-
}
|
|
3600
|
-
getMagicString().update(
|
|
3601
|
-
parser.startIndex + name.length + 2,
|
|
3602
|
-
// !important
|
|
3603
|
-
// htmlparser2 9.0.0: parser.endIndex
|
|
3604
|
-
// htmlparser2 9.1.0: parser.endIndex - 1
|
|
3605
|
-
// https://github.com/sonofmagic/weapp-tailwindcss/issues/269
|
|
3606
|
-
parser.endIndex - 1,
|
|
3607
|
-
templateReplacer(value, getReplaceOptions(quote))
|
|
3608
|
-
);
|
|
3609
|
-
},
|
|
3610
|
-
ontext(data) {
|
|
3611
|
-
if (inlineWxs && tag === "wxs") {
|
|
3612
|
-
;
|
|
3613
|
-
(_nullishCoalesce(wxsArray, () => ( (wxsArray = [])))).push({
|
|
3614
|
-
data,
|
|
3615
|
-
endIndex: parser.endIndex + 1,
|
|
3616
|
-
startIndex: parser.startIndex
|
|
3617
|
-
});
|
|
3618
|
-
}
|
|
3619
|
-
},
|
|
3620
|
-
onclosetag() {
|
|
3621
|
-
tag = "";
|
|
3622
|
-
}
|
|
3623
|
-
},
|
|
3624
|
-
{
|
|
3625
|
-
xmlMode: true
|
|
3626
|
-
}
|
|
3627
|
-
);
|
|
3628
|
-
parser.write(rawSource);
|
|
3629
|
-
parser.end();
|
|
3630
|
-
for (const { data, endIndex, startIndex } of _nullishCoalesce(wxsArray, () => ( []))) {
|
|
3631
|
-
const { code } = await jsHandler2(data, runtimeSet);
|
|
3632
|
-
if (code !== data) {
|
|
3633
|
-
getMagicString().update(startIndex, endIndex, code);
|
|
3634
|
-
}
|
|
3635
|
-
}
|
|
3636
|
-
return _nullishCoalesce(_optionalChain([s, 'optionalAccess', _107 => _107.toString, 'call', _108 => _108()]), () => ( rawSource));
|
|
3637
|
-
}
|
|
3638
|
-
|
|
3639
|
-
// src/wxml/utils.ts
|
|
3640
|
-
function createTemplateHandler(options = {}) {
|
|
3641
|
-
const cachedMatcher = createAttributeMatcher(
|
|
3642
|
-
options.customAttributesEntities
|
|
3643
|
-
);
|
|
3644
|
-
const defaultOptions = options;
|
|
3645
|
-
let cachedRuntimeSet;
|
|
3646
|
-
let cachedOptionsWithRuntimeSet;
|
|
3647
|
-
return (rawSource, opt) => {
|
|
3648
|
-
const runtimeSet = _optionalChain([opt, 'optionalAccess', _109 => _109.runtimeSet]);
|
|
3649
|
-
if (runtimeSet === void 0) {
|
|
3650
|
-
return customTemplateHandler(rawSource, defaultOptions, cachedMatcher);
|
|
3651
|
-
}
|
|
3652
|
-
if (cachedRuntimeSet !== runtimeSet || !cachedOptionsWithRuntimeSet) {
|
|
3653
|
-
cachedRuntimeSet = runtimeSet;
|
|
3654
|
-
cachedOptionsWithRuntimeSet = {
|
|
3655
|
-
...defaultOptions,
|
|
3656
|
-
runtimeSet
|
|
3657
|
-
};
|
|
3658
|
-
}
|
|
3659
|
-
return customTemplateHandler(rawSource, cachedOptionsWithRuntimeSet, cachedMatcher);
|
|
3660
|
-
};
|
|
3661
|
-
}
|
|
3662
|
-
|
|
3663
|
-
// src/context/handlers.ts
|
|
3664
|
-
function resolveRuntimePackageReplacements(option) {
|
|
3665
|
-
if (!option) {
|
|
3666
|
-
return void 0;
|
|
3667
|
-
}
|
|
3668
|
-
const mapping = option === true ? DEFAULT_RUNTIME_PACKAGE_REPLACEMENTS : option;
|
|
3669
|
-
const normalized = {};
|
|
3670
|
-
for (const [from, to] of Object.entries(mapping)) {
|
|
3671
|
-
if (!from || typeof to !== "string" || to.length === 0) {
|
|
3672
|
-
continue;
|
|
3673
|
-
}
|
|
3674
|
-
normalized[from] = to;
|
|
3675
|
-
}
|
|
3676
|
-
return Object.keys(normalized).length > 0 ? normalized : void 0;
|
|
3677
|
-
}
|
|
3678
|
-
function createHandlersFromContext(ctx, customAttributesEntities, cssCalcOptions, tailwindcssMajorVersion) {
|
|
3679
|
-
const {
|
|
3680
|
-
cssPreflight,
|
|
3681
|
-
cssPreflightRange,
|
|
3682
|
-
escapeMap,
|
|
3683
|
-
cssChildCombinatorReplaceValue,
|
|
3684
|
-
injectAdditionalCssVarScope,
|
|
3685
|
-
cssSelectorReplacement,
|
|
3686
|
-
rem2rpx,
|
|
3687
|
-
postcssOptions,
|
|
3688
|
-
cssRemoveProperty,
|
|
3689
|
-
cssRemoveHoverPseudoClass,
|
|
3690
|
-
cssPresetEnv,
|
|
3691
|
-
autoprefixer,
|
|
3692
|
-
uniAppX,
|
|
3693
|
-
px2rpx,
|
|
3694
|
-
unitsToPx,
|
|
3695
|
-
arbitraryValues,
|
|
3696
|
-
jsPreserveClass,
|
|
3697
|
-
staleClassNameFallback,
|
|
3698
|
-
jsArbitraryValueFallback,
|
|
3699
|
-
babelParserOptions,
|
|
3700
|
-
ignoreCallExpressionIdentifiers,
|
|
3701
|
-
ignoreTaggedTemplateExpressionIdentifiers,
|
|
3702
|
-
inlineWxs,
|
|
3703
|
-
disabledDefaultTemplateHandler,
|
|
3704
|
-
replaceRuntimePackages
|
|
3705
|
-
} = ctx;
|
|
3706
|
-
const uniAppXEnabled = _chunkZAA5ZG3Djs.isUniAppXEnabled.call(void 0, uniAppX);
|
|
3707
|
-
const resolvedUniAppXOptions = _chunkZAA5ZG3Djs.resolveUniAppXOptions.call(void 0, uniAppX);
|
|
3708
|
-
const moduleSpecifierReplacements = resolveRuntimePackageReplacements(replaceRuntimePackages);
|
|
3709
|
-
const styleHandler = _postcss.createStyleHandler.call(void 0, {
|
|
3710
|
-
cssPreflight,
|
|
3711
|
-
cssPreflightRange,
|
|
3712
|
-
escapeMap,
|
|
3713
|
-
cssChildCombinatorReplaceValue,
|
|
3714
|
-
injectAdditionalCssVarScope,
|
|
3715
|
-
cssSelectorReplacement,
|
|
3716
|
-
rem2rpx,
|
|
3717
|
-
postcssOptions,
|
|
3718
|
-
cssRemoveProperty,
|
|
3719
|
-
cssRemoveHoverPseudoClass,
|
|
3720
|
-
cssPresetEnv,
|
|
3721
|
-
autoprefixer,
|
|
3722
|
-
uniAppX: uniAppXEnabled,
|
|
3723
|
-
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
3724
|
-
cssCalc: cssCalcOptions,
|
|
3725
|
-
px2rpx,
|
|
3726
|
-
unitsToPx,
|
|
3727
|
-
majorVersion: tailwindcssMajorVersion
|
|
3728
|
-
});
|
|
3729
|
-
const jsHandler2 = createJsHandler({
|
|
3730
|
-
escapeMap,
|
|
3731
|
-
arbitraryValues,
|
|
3732
|
-
jsPreserveClass,
|
|
3733
|
-
staleClassNameFallback,
|
|
3734
|
-
jsArbitraryValueFallback: _nullishCoalesce(jsArbitraryValueFallback, () => ( "auto")),
|
|
3735
|
-
tailwindcssMajorVersion,
|
|
3736
|
-
generateMap: true,
|
|
3737
|
-
babelParserOptions,
|
|
3738
|
-
ignoreCallExpressionIdentifiers,
|
|
3739
|
-
ignoreTaggedTemplateExpressionIdentifiers,
|
|
3740
|
-
uniAppX: uniAppXEnabled,
|
|
3741
|
-
moduleSpecifierReplacements
|
|
3742
|
-
});
|
|
3743
|
-
const templateHandler = createTemplateHandler({
|
|
3744
|
-
customAttributesEntities,
|
|
3745
|
-
escapeMap,
|
|
3746
|
-
inlineWxs,
|
|
3747
|
-
jsHandler: jsHandler2,
|
|
3748
|
-
disabledDefaultTemplateHandler
|
|
3749
|
-
});
|
|
3750
|
-
return {
|
|
3751
|
-
styleHandler,
|
|
3752
|
-
jsHandler: jsHandler2,
|
|
3753
|
-
templateHandler
|
|
3754
|
-
};
|
|
3755
|
-
}
|
|
3756
|
-
|
|
3757
|
-
// src/context/logger.ts
|
|
3758
|
-
|
|
3759
|
-
var loggerLevelMap = {
|
|
3760
|
-
error: 0,
|
|
3761
|
-
warn: 1,
|
|
3762
|
-
info: 3,
|
|
3763
|
-
silent: -999
|
|
3764
|
-
};
|
|
3765
|
-
function applyLoggerLevel(logLevel) {
|
|
3766
|
-
_logger.logger.level = _nullishCoalesce(loggerLevelMap[_nullishCoalesce(logLevel, () => ( "info"))], () => ( loggerLevelMap.info));
|
|
3767
|
-
}
|
|
3768
|
-
|
|
3769
|
-
// src/context/index.ts
|
|
3770
|
-
async function clearTailwindcssPatcherCache(patcher, options) {
|
|
3771
|
-
if (!patcher) {
|
|
3772
|
-
return;
|
|
3773
|
-
}
|
|
3774
|
-
const cacheOptions = _optionalChain([patcher, 'access', _110 => _110.options, 'optionalAccess', _111 => _111.cache]);
|
|
3775
|
-
if (cacheOptions == null || typeof cacheOptions === "object" && cacheOptions.enabled === false) {
|
|
3776
|
-
return;
|
|
3777
|
-
}
|
|
3778
|
-
if (typeof patcher.clearCache === "function") {
|
|
3779
|
-
try {
|
|
3780
|
-
await patcher.clearCache({ scope: "all" });
|
|
3781
|
-
} catch (error) {
|
|
3782
|
-
_logger.logger.debug("failed to clear tailwindcss patcher cache via clearCache(): %O", error);
|
|
3783
|
-
}
|
|
3784
|
-
}
|
|
3785
|
-
if (!_optionalChain([options, 'optionalAccess', _112 => _112.removeDirectory])) {
|
|
3786
|
-
return;
|
|
3787
|
-
}
|
|
3788
|
-
const cachePaths = /* @__PURE__ */ new Map();
|
|
3789
|
-
const normalizedCacheOptions = typeof cacheOptions === "object" ? cacheOptions : void 0;
|
|
3790
|
-
if (_optionalChain([normalizedCacheOptions, 'optionalAccess', _113 => _113.path])) {
|
|
3791
|
-
cachePaths.set(normalizedCacheOptions.path, false);
|
|
3792
|
-
}
|
|
3793
|
-
const privateCachePath = _optionalChain([patcher, 'optionalAccess', _114 => _114.cacheStore, 'optionalAccess', _115 => _115.options, 'optionalAccess', _116 => _116.path]);
|
|
3794
|
-
if (privateCachePath) {
|
|
3795
|
-
cachePaths.set(privateCachePath, false);
|
|
3796
|
-
}
|
|
3797
|
-
if (_optionalChain([options, 'optionalAccess', _117 => _117.removeDirectory]) && _optionalChain([normalizedCacheOptions, 'optionalAccess', _118 => _118.dir])) {
|
|
3798
|
-
cachePaths.set(normalizedCacheOptions.dir, true);
|
|
3799
|
-
}
|
|
3800
|
-
if (!cachePaths.size) {
|
|
3801
|
-
return;
|
|
3802
|
-
}
|
|
3803
|
-
for (const [cachePath, recursive] of cachePaths.entries()) {
|
|
3804
|
-
try {
|
|
3805
|
-
await _promises.rm.call(void 0, cachePath, { force: true, recursive });
|
|
3806
|
-
} catch (error) {
|
|
3807
|
-
const err = error;
|
|
3808
|
-
if (_optionalChain([err, 'optionalAccess', _119 => _119.code]) === "ENOENT") {
|
|
3809
|
-
continue;
|
|
3810
|
-
}
|
|
3811
|
-
_logger.logger.debug("failed to clear tailwindcss patcher cache: %s %O", cachePath, err);
|
|
3812
|
-
}
|
|
3813
|
-
}
|
|
3814
|
-
}
|
|
3815
|
-
function createInternalCompilerContext(opts) {
|
|
3816
|
-
const ctx = _chunkDYLQ6UOIjs.defuOverrideArray.call(void 0,
|
|
3817
|
-
opts,
|
|
3818
|
-
_chunkA5PB4KZTjs.getDefaultOptions.call(void 0, ),
|
|
3819
|
-
{}
|
|
3820
|
-
);
|
|
3821
|
-
ctx.escapeMap = ctx.customReplaceDictionary;
|
|
3822
|
-
applyLoggerLevel(ctx.logLevel);
|
|
3823
|
-
const twPatcher = _chunkZAA5ZG3Djs.createTailwindcssPatcherFromContext.call(void 0, ctx);
|
|
3824
|
-
logTailwindcssTarget("runtime", twPatcher, ctx.tailwindcssBasedir);
|
|
3825
|
-
logRuntimeTailwindcssVersion(
|
|
3826
|
-
ctx.tailwindcssBasedir,
|
|
3827
|
-
_optionalChain([twPatcher, 'access', _120 => _120.packageInfo, 'optionalAccess', _121 => _121.rootPath]),
|
|
3828
|
-
_optionalChain([twPatcher, 'access', _122 => _122.packageInfo, 'optionalAccess', _123 => _123.version])
|
|
3829
|
-
);
|
|
3830
|
-
_chunkZAA5ZG3Djs.warnMissingCssEntries.call(void 0, ctx, twPatcher);
|
|
3831
|
-
const cssCalcOptions = _chunkZAA5ZG3Djs.applyV4CssCalcDefaults.call(void 0, ctx.cssCalc, twPatcher);
|
|
3832
|
-
ctx.cssCalc = cssCalcOptions;
|
|
3833
|
-
const customAttributesEntities = toCustomAttributesEntities(ctx.customAttributes);
|
|
3834
|
-
const { styleHandler, jsHandler: jsHandler2, templateHandler } = createHandlersFromContext(
|
|
3835
|
-
ctx,
|
|
3836
|
-
customAttributesEntities,
|
|
3837
|
-
cssCalcOptions,
|
|
3838
|
-
twPatcher.majorVersion
|
|
3839
|
-
);
|
|
3840
|
-
ctx.styleHandler = styleHandler;
|
|
3841
|
-
ctx.jsHandler = jsHandler2;
|
|
3842
|
-
ctx.templateHandler = templateHandler;
|
|
3843
|
-
ctx.cache = initializeCache(ctx.cache);
|
|
3844
|
-
ctx.twPatcher = twPatcher;
|
|
3845
|
-
const refreshTailwindcssPatcher = async (options) => {
|
|
3846
|
-
const previousPatcher = ctx.twPatcher;
|
|
3847
|
-
if (_optionalChain([options, 'optionalAccess', _124 => _124.clearCache]) !== false) {
|
|
3848
|
-
await clearTailwindcssPatcherCache(previousPatcher);
|
|
3849
|
-
}
|
|
3850
|
-
_chunkZAA5ZG3Djs.invalidateRuntimeClassSet.call(void 0, previousPatcher);
|
|
3851
|
-
const nextPatcher = _chunkZAA5ZG3Djs.createTailwindcssPatcherFromContext.call(void 0, ctx);
|
|
3852
|
-
Object.assign(previousPatcher, nextPatcher);
|
|
3853
|
-
ctx.twPatcher = previousPatcher;
|
|
3854
|
-
return previousPatcher;
|
|
3855
|
-
};
|
|
3856
|
-
ctx.refreshTailwindcssPatcher = refreshTailwindcssPatcher;
|
|
3857
|
-
Object.defineProperty(ctx.twPatcher, refreshTailwindcssPatcherSymbol, {
|
|
3858
|
-
value: refreshTailwindcssPatcher,
|
|
3859
|
-
configurable: true
|
|
3860
|
-
});
|
|
3861
|
-
return ctx;
|
|
3862
|
-
}
|
|
3863
|
-
function getCompilerContext(opts) {
|
|
3864
|
-
return withCompilerContextCache(opts, () => createInternalCompilerContext(opts));
|
|
3865
|
-
}
|
|
3866
|
-
|
|
3867
|
-
// src/js/precheck.ts
|
|
3868
|
-
|
|
3869
|
-
var FAST_JS_TRANSFORM_HINT_RE = /className\b|class\s*=|classList\.|\b(?:twMerge|clsx|classnames|cn|cva)\b|\[["'`]class["'`]\]|text-\[|bg-\[|\b(?:[whpm]|px|py|mx|my|rounded|flex|grid|gap)-/;
|
|
3870
|
-
var DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
|
|
3871
|
-
function shouldSkipJsTransform(rawSource, options) {
|
|
3872
|
-
if (_process2.default.env.WEAPP_TW_DISABLE_JS_PRECHECK === "1") {
|
|
3873
|
-
return false;
|
|
3874
|
-
}
|
|
3875
|
-
if (!rawSource) {
|
|
3876
|
-
return true;
|
|
3877
|
-
}
|
|
3878
|
-
if (_optionalChain([options, 'optionalAccess', _125 => _125.alwaysEscape])) {
|
|
3879
|
-
return false;
|
|
3880
|
-
}
|
|
3881
|
-
if (_optionalChain([options, 'optionalAccess', _126 => _126.moduleSpecifierReplacements]) && Object.keys(options.moduleSpecifierReplacements).length > 0) {
|
|
3882
|
-
return false;
|
|
3883
|
-
}
|
|
3884
|
-
if (_optionalChain([options, 'optionalAccess', _127 => _127.wrapExpression])) {
|
|
3885
|
-
return false;
|
|
3886
|
-
}
|
|
3887
|
-
if (DEPENDENCY_HINT_RE.test(rawSource)) {
|
|
3888
|
-
return false;
|
|
3889
|
-
}
|
|
3890
|
-
return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
|
|
3891
|
-
}
|
|
3892
|
-
|
|
3893
|
-
// src/tailwindcss/recorder.ts
|
|
3894
|
-
function setupPatchRecorder(patcher, baseDir, options) {
|
|
3895
|
-
const recorder = createPatchTargetRecorder(baseDir, patcher, options);
|
|
3896
|
-
if (_optionalChain([recorder, 'optionalAccess', _128 => _128.message]) && _optionalChain([options, 'optionalAccess', _129 => _129.logMessage]) !== false) {
|
|
3897
|
-
const prefix = _optionalChain([options, 'optionalAccess', _130 => _130.messagePrefix]) ? `${options.messagePrefix} ` : "";
|
|
3898
|
-
_chunkZAA5ZG3Djs.logger.info("%s%s", prefix, recorder.message);
|
|
3899
|
-
}
|
|
3900
|
-
const onPatchCompleted = _optionalChain([recorder, 'optionalAccess', _131 => _131.onPatched]) ? async () => {
|
|
3901
|
-
await recorder.onPatched();
|
|
3902
|
-
} : void 0;
|
|
3903
|
-
const patchPromise = patcher ? createTailwindPatchPromise(patcher, onPatchCompleted) : Promise.resolve();
|
|
3904
|
-
return {
|
|
3905
|
-
recorder,
|
|
3906
|
-
patchPromise,
|
|
3907
|
-
onPatchCompleted
|
|
3908
|
-
};
|
|
3909
|
-
}
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
exports.createDebug = createDebug; exports.refreshTailwindRuntimeState = refreshTailwindRuntimeState; exports.ensureRuntimeClassSet = ensureRuntimeClassSet; exports.collectRuntimeClassSet = collectRuntimeClassSet; exports.pluginName = pluginName; exports.vitePluginName = vitePluginName; exports.toCustomAttributesEntities = toCustomAttributesEntities; exports.traverse = traverse; exports.babelParse = babelParse; exports.replaceWxml = replaceWxml; exports.isClassContextLiteralPath = isClassContextLiteralPath; exports.JsTokenUpdater = JsTokenUpdater; exports.analyzeSource = analyzeSource; exports.createAttributeMatcher = createAttributeMatcher; exports.generateCode = generateCode; exports.getCompilerContext = getCompilerContext; exports.shouldSkipJsTransform = shouldSkipJsTransform; exports.setupPatchRecorder = setupPatchRecorder;
|