@mpcore/simulator 1.3.4-dev.20261112.3 → 1.3.4-dev.20261114.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.d.mts CHANGED
@@ -1396,6 +1396,7 @@ export interface BrowserModuleLoader {
1396
1396
  executePageModule: (filePath: string, route: string) => HeadlessPageDefinition;
1397
1397
  reloadPageModule: (filePath: string, route: string) => boolean;
1398
1398
  wx: HeadlessWx;
1399
+ warn: (message: string) => void;
1399
1400
  }
1400
1401
  export declare function createBrowserModuleLoader(files: BrowserVirtualFiles, registries: HeadlessHostRegistries, getCurrentPages: () => any[], getApp: () => any, wxDriver: Parameters<typeof createHeadlessWx>[0], options: {
1401
1402
  globals?: Record<string, unknown>;
@@ -1662,6 +1663,7 @@ interface HeadlessModuleLoader {
1662
1663
  executePageModule: (filePath: string, route: string) => HeadlessPageDefinition;
1663
1664
  reloadPageModule: (filePath: string, route: string) => boolean;
1664
1665
  wx: HeadlessWx;
1666
+ warn: (message: string) => void;
1665
1667
  }
1666
1668
  interface DomNodeLike$3 {
1667
1669
  attribs?: Record<string, string>;
package/dist/index.mjs CHANGED
@@ -1836,7 +1836,8 @@ function createBrowserModuleLoader(files, registries, getCurrentPages, getApp, w
1836
1836
  if (!definition) throw new Error(`Component() was not registered for id "${id}" while executing ${normalize(filePath)}.`);
1837
1837
  return definition;
1838
1838
  },
1839
- wx: executionContext.wx
1839
+ wx: executionContext.wx,
1840
+ warn: (message) => executionContext.console.warn(message)
1840
1841
  };
1841
1842
  return loader;
1842
1843
  }
@@ -2163,6 +2164,16 @@ function hasNativeDataCommit(owner, dependencies, after, through) {
2163
2164
  for (const entry of commits.get(owner)?.paths.values() ?? []) if (entry.revision > after && entry.revision <= through && dependencies.some((path) => pathsIntersect(path, entry.path))) return true;
2164
2165
  return false;
2165
2166
  }
2167
+ // src/runtime/componentInstance/pureData.ts
2168
+ /** 原生纯数据保留在逻辑层,不能参与组件自身的模板求值。 */
2169
+ function isPureDataField(definition, key) {
2170
+ const pattern = definition?.options?.pureDataPattern;
2171
+ return typeof pattern?.source === "string" && typeof pattern?.flags === "string" && new RegExp(pattern.source, pattern.flags).test(key);
2172
+ }
2173
+ /** Node 与浏览器渲染共享同一纯数据边界。 */
2174
+ function resolveComponentViewData(instance) {
2175
+ return Object.fromEntries(Object.entries(instance.data).filter(([key]) => !isPureDataField(instance.__definition__, key)));
2176
+ }
2166
2177
  // src/runtime/componentInstance/shared.ts
2167
2178
  const ARRAY_INDEX_PATH_RE$1 = /\[(\d+)\]/g;
2168
2179
  const ARRAY_INDEX_SEGMENT_RE$1 = /^\d+$/;
@@ -2231,7 +2242,7 @@ function runPropertyObservers(definition, instance, changedKeys, previousPropert
2231
2242
  if (!propOptions || typeof propOptions !== "object" || Array.isArray(propOptions)) return;
2232
2243
  const changedRoots = new Set(changedKeys.map((key) => parseDataPath$1(key)[0]));
2233
2244
  for (const changedKey of Object.keys(propOptions)) {
2234
- if (!changedRoots.has(changedKey)) continue;
2245
+ if (!changedRoots.has(changedKey) || isPureDataField(definition, changedKey)) continue;
2235
2246
  const value = instance.properties[changedKey];
2236
2247
  if ((value === null || typeof value !== "object") && Object.hasOwn(previousProperties, changedKey) && Object.is(value, previousProperties[changedKey])) continue;
2237
2248
  const option = propOptions[changedKey];
@@ -2453,6 +2464,11 @@ function resolveInitialProperties(definition, properties) {
2453
2464
  }
2454
2465
  return resolved;
2455
2466
  }
2467
+ /** 与真实宿主对齐:显式传入空值与未声明属性不同,String 空值会产生类型警告。 */
2468
+ function isInvalidStringPropertyNull(definition, key, value) {
2469
+ const candidates = resolvePropertyTypeCandidates(definition.properties?.[key]);
2470
+ return value == null && candidates[0] === String && !candidates.includes(null);
2471
+ }
2456
2472
  // src/runtime/componentInstance/relations.ts
2457
2473
  const states = /* @__PURE__ */ new WeakMap();
2458
2474
  const opposite = {
@@ -2895,6 +2911,29 @@ function syncNativePropertyCommits(instance, properties) {
2895
2911
  if (last?.owner === binding.owner && hasNativeDataCommit(binding.owner, binding.paths, last.revision, binding.revision)) recordNativeDataCommit(instance, [key]);
2896
2912
  }
2897
2913
  }
2914
+ // src/runtime/componentInstance/propertyDiagnostics.ts
2915
+ const diagnostics = /* @__PURE__ */ new WeakMap();
2916
+ /** 使用会话所属的 console,避免将属性警告写入另一运行时。 */
2917
+ function attachComponentPropertyDiagnostics(instance, label, warn) {
2918
+ diagnostics.set(instance, {
2919
+ label,
2920
+ warn,
2921
+ invalidKeys: /* @__PURE__ */ new Set()
2922
+ });
2923
+ }
2924
+ /** 重复渲染不重复交付同一空属性;值恢复有效后允许下一次空值发出警告。 */
2925
+ function reportComponentPropertyValue(instance, definition, key, value) {
2926
+ const state = diagnostics.get(instance);
2927
+ if (!state) return;
2928
+ if (!isInvalidStringPropertyNull(definition, key, value)) {
2929
+ state.invalidKeys.delete(key);
2930
+ return;
2931
+ }
2932
+ if (!state.invalidKeys.has(key)) {
2933
+ state.invalidKeys.add(key);
2934
+ state.warn(`[Component] property "${key}" of "${state.label}" received type-uncompatible value: expected <String> but get null value. Use empty string instead.`);
2935
+ }
2936
+ }
2898
2937
  // src/runtime/componentInstance/propertyBindings.ts
2899
2938
  const consumedPageChanges = /* @__PURE__ */ new WeakMap();
2900
2939
  function syncComponentProperties(instance, definition, nextProperties, bindingExpressions, changedPageKeys, beforeObservers) {
@@ -2905,6 +2944,7 @@ function syncComponentProperties(instance, definition, nextProperties, bindingEx
2905
2944
  const previousProperties = {};
2906
2945
  for (const [key, value] of Object.entries(nextProperties)) {
2907
2946
  if (!Object.hasOwn(definition.properties ?? {}, key)) continue;
2947
+ reportComponentPropertyValue(instance, definition, key, value);
2908
2948
  const nextValue = normalizeComponentPropertyValue(definition, key, value);
2909
2949
  const bindingExpression = bindingExpressions[key];
2910
2950
  const bindingAffected = freshPageChanges && !!bindingExpression && changedPageKeys.some((changedKey) => {
@@ -4472,7 +4512,7 @@ function createComponentScope$1(clonedNode, scope, componentScopeId, componentIn
4472
4512
  return {
4473
4513
  alias: clonedNode.name,
4474
4514
  classList: String(clonedNode.attribs?.class ?? "").split(CLASS_SPLIT_RE$1).map((item) => item.trim()).filter(Boolean),
4475
- data: { ...componentInstance.data },
4515
+ data: resolveComponentViewData(componentInstance),
4476
4516
  dataOwner: componentInstance,
4477
4517
  dataset: collectDataset$1(clonedNode, wxsScopeData(scope)),
4478
4518
  ...bindComponentEventHost(clonedNode),
@@ -4512,6 +4552,7 @@ function createBrowserComponentInstance(componentScopeId, context, componentEntr
4512
4552
  requestRender: (callback) => context.session.requestRender(callback)
4513
4553
  };
4514
4554
  const componentInstance = createComponentInstance(instanceOptions);
4555
+ attachComponentPropertyDiagnostics(componentInstance, componentEntry.filePath.replace(/^\/+/, "").replace(JS_FILE_RE$1, ""), context.moduleLoader.warn);
4515
4556
  bindAttachmentBindingScope(componentInstance, context);
4516
4557
  setSelectorQueryScopeId(componentInstance, componentScopeId);
4517
4558
  componentInstance.is = componentEntry.filePath.replace(JS_FILE_RE$1, "");
@@ -6676,7 +6717,7 @@ function createHeadlessWxState(scheduler = nativeScheduler, options = {}) {
6676
6717
  };
6677
6718
  },
6678
6719
  getImageInfo(option) {
6679
- const fileContent = files.get(option.src);
6720
+ const fileContent = files.get(normalizeFsPath(option.src)) ?? options.readPackageFile?.(option.src);
6680
6721
  if (fileContent == null) throw new Error(`getImageInfo:fail file not found: ${option.src}`);
6681
6722
  const size = inferImageSize(readArtifactText(fileContent));
6682
6723
  return {
@@ -10429,7 +10470,7 @@ function createComponentScope(clonedNode, scope, componentScopeId, componentInst
10429
10470
  return {
10430
10471
  alias: clonedNode.name,
10431
10472
  classList: String(clonedNode.attribs?.class ?? "").split(CLASS_SPLIT_RE).map((item) => item.trim()).filter(Boolean),
10432
- data: { ...componentInstance.data },
10473
+ data: resolveComponentViewData(componentInstance),
10433
10474
  dataOwner: componentInstance,
10434
10475
  dataset: collectDataset(clonedNode, wxsScopeData(scope)),
10435
10476
  ...bindComponentEventHost(clonedNode),
@@ -10469,6 +10510,7 @@ function createRuntimeComponentInstance(componentScopeId, context, componentEntr
10469
10510
  requestRender: (callback) => context.session.requestRender(callback)
10470
10511
  };
10471
10512
  const componentInstance = createComponentInstance(instanceOptions);
10513
+ attachComponentPropertyDiagnostics(componentInstance, componentEntry.filePath.replaceAll("\\", "/").replace(/^\/+/, "").replace(JS_FILE_RE, ""), context.moduleLoader.warn);
10472
10514
  bindAttachmentBindingScope(componentInstance, context);
10473
10515
  setSelectorQueryScopeId(componentInstance, componentScopeId);
10474
10516
  componentInstance.is = componentEntry.filePath.replace(JS_FILE_RE, "");
@@ -10940,7 +10982,8 @@ function createModuleLoader(registries, getCurrentPages, getApp, wxDriver, optio
10940
10982
  if (!definition) throw new Error(`Component() was not registered for id "${id}" while executing ${normalize(filePath)}.`);
10941
10983
  return definition;
10942
10984
  },
10943
- wx: executionContext.wx
10985
+ wx: executionContext.wx,
10986
+ warn: (message) => executionContext.console.warn(message)
10944
10987
  };
10945
10988
  return loader;
10946
10989
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mpcore/simulator",
3
3
  "type": "module",
4
- "version": "1.3.4-dev.20261112.3",
4
+ "version": "1.3.4-dev.20261114.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",
@@ -43,10 +43,10 @@
43
43
  "node": "^22.23.4 || ^24.22.1 || >=26.12.1"
44
44
  },
45
45
  "dependencies": {
46
- "@babel/parser": "^8.1.0",
47
- "@weapp-core/constants": "0.5.5-dev.20261112.3",
48
- "@weapp-core/shared": "3.4.3-dev.20261112.3",
49
- "@weapp-vite/wxml": "0.0.1-dev.20261112.3",
46
+ "@babel/parser": "^8.1.2",
47
+ "@weapp-core/constants": "0.6.0-dev.20261114.1",
48
+ "@weapp-core/shared": "3.5.0-dev.20261114.1",
49
+ "@weapp-vite/wxml": "0.0.2-dev.20261114.1",
50
50
  "css-select": "^7.0.0",
51
51
  "css-what": "^8.0.0",
52
52
  "fontoxpath": "^3.34.0",
@@ -64,9 +64,9 @@
64
64
  },
65
65
  "repoctlSnapshot": {
66
66
  "kind": "nightly",
67
- "commit": "8ca9aafdedcb688596814e1430c8e571fb540b93",
68
- "buildId": "43314231283-1",
69
- "identityKey": "af86ccdf5befcdc313380a806c430308b056b012d4541fee2c76ee1363600bd1",
67
+ "commit": "b098ea06ce1752679ffdec07228f9284afa14e5f",
68
+ "buildId": "43546123322-1",
69
+ "identityKey": "c32ae1660ff7f54fdbceae9a78aca56a1df42331ce90b77e87135036cf7e8a1a",
70
70
  "tag": "snapshot-nightly"
71
71
  },
72
72
  "scripts": {