@mpcore/simulator 1.3.5 → 1.3.6-dev.20261119.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/index.mjs +67 -14
- package/package.json +14 -6
package/dist/index.mjs
CHANGED
|
@@ -2237,6 +2237,7 @@ function mergeRecord(...records) {
|
|
|
2237
2237
|
return Object.assign({}, ...records.filter(Boolean));
|
|
2238
2238
|
}
|
|
2239
2239
|
// src/runtime/componentInstance/observers.ts
|
|
2240
|
+
const observerRunStates = /* @__PURE__ */ new WeakMap();
|
|
2240
2241
|
function runPropertyObservers(definition, instance, changedKeys, previousProperties) {
|
|
2241
2242
|
const propOptions = definition.properties;
|
|
2242
2243
|
if (!propOptions || typeof propOptions !== "object" || Array.isArray(propOptions)) return;
|
|
@@ -2282,7 +2283,7 @@ function matchObserverPattern(pattern, changedKeys) {
|
|
|
2282
2283
|
});
|
|
2283
2284
|
});
|
|
2284
2285
|
}
|
|
2285
|
-
function
|
|
2286
|
+
function runComponentObserversOnce(definition, instance, changedKeys, previousProperties = {}, includePropertyObservers = true) {
|
|
2286
2287
|
if (changedKeys.length === 0) return;
|
|
2287
2288
|
const observers = definition.observers;
|
|
2288
2289
|
if (observers && typeof observers === "object" && !Array.isArray(observers)) for (const [pattern, handler] of Object.entries(observers)) {
|
|
@@ -2290,7 +2291,41 @@ function runComponentObservers(definition, instance, changedKeys, previousProper
|
|
|
2290
2291
|
const args = normalizeObserverPattern(pattern).map((item) => resolveObservedValue(instance, item));
|
|
2291
2292
|
handler.call(instance, ...args);
|
|
2292
2293
|
}
|
|
2293
|
-
runPropertyObservers(definition, instance, changedKeys, previousProperties);
|
|
2294
|
+
if (includePropertyObservers) runPropertyObservers(definition, instance, changedKeys, previousProperties);
|
|
2295
|
+
}
|
|
2296
|
+
function runComponentObservers(definition, instance, changedKeys, previousProperties = {}) {
|
|
2297
|
+
if (changedKeys.length === 0) return;
|
|
2298
|
+
const state = observerRunStates.get(instance) ?? {
|
|
2299
|
+
running: false,
|
|
2300
|
+
pending: []
|
|
2301
|
+
};
|
|
2302
|
+
observerRunStates.set(instance, state);
|
|
2303
|
+
if (state.running) {
|
|
2304
|
+
runPropertyObservers(definition, instance, changedKeys, previousProperties);
|
|
2305
|
+
state.pending.push({
|
|
2306
|
+
changedKeys: [...changedKeys],
|
|
2307
|
+
previousProperties,
|
|
2308
|
+
includePropertyObservers: false
|
|
2309
|
+
});
|
|
2310
|
+
return;
|
|
2311
|
+
}
|
|
2312
|
+
state.pending.push({
|
|
2313
|
+
changedKeys: [...changedKeys],
|
|
2314
|
+
previousProperties,
|
|
2315
|
+
includePropertyObservers: true
|
|
2316
|
+
});
|
|
2317
|
+
state.running = true;
|
|
2318
|
+
try {
|
|
2319
|
+
while (state.pending.length > 0) {
|
|
2320
|
+
const next = state.pending.shift();
|
|
2321
|
+
runComponentObserversOnce(definition, instance, next.changedKeys, next.previousProperties, next.includePropertyObservers);
|
|
2322
|
+
}
|
|
2323
|
+
} catch (error) {
|
|
2324
|
+
state.pending.length = 0;
|
|
2325
|
+
throw error;
|
|
2326
|
+
} finally {
|
|
2327
|
+
state.running = false;
|
|
2328
|
+
}
|
|
2294
2329
|
}
|
|
2295
2330
|
// src/runtime/componentInstance/lifetimes.ts
|
|
2296
2331
|
function mergeComponentLifetimes(behaviors, definition) {
|
|
@@ -2332,27 +2367,45 @@ function flattenBehaviors(definition) {
|
|
|
2332
2367
|
}
|
|
2333
2368
|
return flattened;
|
|
2334
2369
|
}
|
|
2370
|
+
function applyBehaviorDefinitionFilters(definition, behaviors) {
|
|
2371
|
+
if (!behaviors.some((behavior) => typeof behavior.definitionFilter === "function")) return definition;
|
|
2372
|
+
const filteredDefinition = {
|
|
2373
|
+
...definition,
|
|
2374
|
+
...definition.observers && typeof definition.observers === "object" && !Array.isArray(definition.observers) ? { observers: { ...definition.observers } } : {}
|
|
2375
|
+
};
|
|
2376
|
+
for (const behavior of behaviors) if (typeof behavior.definitionFilter === "function") behavior.definitionFilter(filteredDefinition);
|
|
2377
|
+
return filteredDefinition;
|
|
2378
|
+
}
|
|
2335
2379
|
function resolveComponentPropertyDefinitions(definition, behaviors = flattenBehaviors(definition)) {
|
|
2336
2380
|
return behaviors.length === 0 ? definition.properties ?? {} : mergeRecord(...behaviors.map((item) => item.properties), definition.properties);
|
|
2337
2381
|
}
|
|
2382
|
+
const RESERVED_COMPONENT_HOST_PROPERTIES = /* @__PURE__ */ new Set([
|
|
2383
|
+
"id",
|
|
2384
|
+
"class",
|
|
2385
|
+
"slot"
|
|
2386
|
+
]);
|
|
2387
|
+
function isReservedComponentHostProperty(key) {
|
|
2388
|
+
return RESERVED_COMPONENT_HOST_PROPERTIES.has(key);
|
|
2389
|
+
}
|
|
2338
2390
|
function normalizeComponentDefinition(definition) {
|
|
2339
2391
|
const behaviors = flattenBehaviors(definition);
|
|
2340
2392
|
if (behaviors.length === 0) return definition;
|
|
2393
|
+
const filteredDefinition = applyBehaviorDefinitionFilters(definition, behaviors);
|
|
2341
2394
|
const mergedDataEntries = behaviors.map((item) => item.data).filter(Boolean);
|
|
2342
2395
|
const mergedDefinition = {
|
|
2343
|
-
...mergeRecord(...behaviors,
|
|
2344
|
-
methods: mergeRecord(...behaviors.map((item) => item.methods),
|
|
2345
|
-
observers: mergeRecord(...behaviors.map((item) => item.observers),
|
|
2346
|
-
pageLifetimes: mergeRecord(...behaviors.map((item) => item.pageLifetimes),
|
|
2347
|
-
properties: resolveComponentPropertyDefinitions(
|
|
2348
|
-
relations: mergeRecord(...behaviors.map((item) => item.relations),
|
|
2349
|
-
lifetimes: mergeComponentLifetimes(behaviors,
|
|
2350
|
-
};
|
|
2351
|
-
if (mergedDataEntries.length > 0 ||
|
|
2396
|
+
...mergeRecord(...behaviors, filteredDefinition),
|
|
2397
|
+
methods: mergeRecord(...behaviors.map((item) => item.methods), filteredDefinition.methods),
|
|
2398
|
+
observers: mergeRecord(...behaviors.map((item) => item.observers), filteredDefinition.observers),
|
|
2399
|
+
pageLifetimes: mergeRecord(...behaviors.map((item) => item.pageLifetimes), filteredDefinition.pageLifetimes),
|
|
2400
|
+
properties: resolveComponentPropertyDefinitions(filteredDefinition, behaviors),
|
|
2401
|
+
relations: mergeRecord(...behaviors.map((item) => item.relations), filteredDefinition.relations),
|
|
2402
|
+
lifetimes: mergeComponentLifetimes(behaviors, filteredDefinition)
|
|
2403
|
+
};
|
|
2404
|
+
if (mergedDataEntries.length > 0 || filteredDefinition.data) mergedDefinition.data = function mergedComponentData() {
|
|
2352
2405
|
return mergeRecord(mergeRecord(...mergedDataEntries.map((entry) => {
|
|
2353
2406
|
if (typeof entry === "function") return entry.call(this);
|
|
2354
2407
|
return entry;
|
|
2355
|
-
})), typeof
|
|
2408
|
+
})), typeof filteredDefinition.data === "function" ? filteredDefinition.data.call(this) : filteredDefinition.data);
|
|
2356
2409
|
};
|
|
2357
2410
|
return mergedDefinition;
|
|
2358
2411
|
}
|
|
@@ -4642,7 +4695,7 @@ function resolveComponentProperties$1(clonedNode, scope, definition) {
|
|
|
4642
4695
|
const bindingExpressions = {};
|
|
4643
4696
|
const declaredProperties = resolveComponentPropertyDefinitions(definition);
|
|
4644
4697
|
for (const [key, value] of Object.entries(clonedNode.attribs ?? {})) {
|
|
4645
|
-
if (key.startsWith("bind") || key.startsWith("generic:")) continue;
|
|
4698
|
+
if (key.startsWith("bind") || key.startsWith("generic:") || key.startsWith("wx:") || isReservedComponentHostProperty(key)) continue;
|
|
4646
4699
|
const camelizedKey = key.replace(/-([a-z])/g, (_match, char) => char.toUpperCase());
|
|
4647
4700
|
const propertyKey = key in declaredProperties || !(camelizedKey in declaredProperties) ? key : camelizedKey;
|
|
4648
4701
|
if (isMustacheOnly$2(String(value))) bindingExpressions[propertyKey] = String(value).trim().slice(2, -2).trim();
|
|
@@ -10630,7 +10683,7 @@ function resolveComponentProperties(clonedNode, scope, definition) {
|
|
|
10630
10683
|
const bindingExpressions = {};
|
|
10631
10684
|
const declaredProperties = resolveComponentPropertyDefinitions(definition);
|
|
10632
10685
|
for (const [key, value] of Object.entries(clonedNode.attribs ?? {})) {
|
|
10633
|
-
if (key.startsWith("bind") || key.startsWith("generic:")) continue;
|
|
10686
|
+
if (key.startsWith("bind") || key.startsWith("generic:") || key.startsWith("wx:") || isReservedComponentHostProperty(key)) continue;
|
|
10634
10687
|
const camelizedKey = key.replace(/-([a-z])/g, (_match, char) => char.toUpperCase());
|
|
10635
10688
|
const propertyKey = key in declaredProperties || !(camelizedKey in declaredProperties) ? key : camelizedKey;
|
|
10636
10689
|
if (isMustacheOnly(String(value))) bindingExpressions[propertyKey] = String(value).trim().slice(2, -2).trim();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpcore/simulator",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.6-dev.20261119.1",
|
|
5
5
|
"description": "Headless mini-program runtime and testing kernel for the weapp-vite ecosystem",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@babel/parser": "^8.1.2",
|
|
47
|
-
"@weapp-core/constants": "0.6.1",
|
|
48
|
-
"@weapp-core/shared": "3.5.1",
|
|
49
|
-
"@weapp-vite/wxml": "0.0.
|
|
47
|
+
"@weapp-core/constants": "0.6.2-dev.20261119.1",
|
|
48
|
+
"@weapp-core/shared": "3.5.2-dev.20261119.1",
|
|
49
|
+
"@weapp-vite/wxml": "0.0.4-dev.20261119.1",
|
|
50
50
|
"css-select": "^7.0.0",
|
|
51
51
|
"css-what": "^8.0.0",
|
|
52
52
|
"fontoxpath": "^3.34.0",
|
|
@@ -56,11 +56,19 @@
|
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public",
|
|
59
|
-
"registry": "https://registry.npmjs.org"
|
|
59
|
+
"registry": "https://registry.npmjs.org/",
|
|
60
|
+
"tag": "snapshot-nightly"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
63
|
"htmlparser2": "^12.0.0"
|
|
63
64
|
},
|
|
65
|
+
"repoctlSnapshot": {
|
|
66
|
+
"kind": "nightly",
|
|
67
|
+
"commit": "29a77f1e58e5686dbbfceefa78673afa59d2a1ef",
|
|
68
|
+
"buildId": "44450884003-1",
|
|
69
|
+
"identityKey": "0c330c88d6a9536155ce29b9033403e7ca04e00c3d490aa29ff68859371758e7",
|
|
70
|
+
"tag": "snapshot-nightly"
|
|
71
|
+
},
|
|
64
72
|
"scripts": {
|
|
65
73
|
"dev": "tsdown -w",
|
|
66
74
|
"build": "tsdown",
|
|
@@ -73,4 +81,4 @@
|
|
|
73
81
|
"test:types:check": "tsd --files \"test-d/**/*.test-d.ts\"",
|
|
74
82
|
"typecheck": "tsc --noEmit"
|
|
75
83
|
}
|
|
76
|
-
}
|
|
84
|
+
}
|