@wcstack/router 3.5.4 → 4.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -43,49 +43,37 @@ function getConfig() {
43
43
  }
44
44
  return frozenConfig;
45
45
  }
46
- // The defaults as shipped, for warnInvalid: a value 3.x lets through unchecked must not change
47
- // what a later call is compared against.
48
- const defaults = { ..._config, tagNames: { ..._config.tagNames } };
49
- const warned$1 = new Set();
46
+ /** A misspelt option would otherwise do nothing: `bootstrapRouter` refuses it. */
47
+ function invalid(key) {
48
+ throw new Error(`[@wcstack/router] bootstrapRouter: "${key}" is not one of its options, or not of the option's type.`);
49
+ }
50
50
  /**
51
- * 3.5 forward-compat check. Warns, once per key per page, about an option that 4.0's
52
- * bootstrapRouter throws on: one this package does not have, a value of another type than its
53
- * default (null, or an array for an object, included), or a tag name it does not define or that is
54
- * not a string. An undefined value is left out, as in 4.0. It only warns: setConfig then goes on
55
- * exactly as in 3.x. Bootstrap-time only, never on a hot path.
51
+ * Applies the options given; an undefined value is left out. An option this package does not
52
+ * have, a value of another type than its default (null, or an array for an object, included) or
53
+ * a tag name it does not define throws, and then nothing is applied.
56
54
  */
57
- function warnInvalid(given, known, path = "") {
58
- for (const [key, value] of Object.entries(given)) {
59
- const name = path + key;
60
- const current = known[key];
61
- if (value === undefined) {
62
- continue;
63
- }
64
- if (!Object.prototype.hasOwnProperty.call(known, key) ||
65
- value === null ||
66
- typeof value !== typeof current ||
67
- Array.isArray(value) !== Array.isArray(current)) {
68
- if (!warned$1.has(name)) {
69
- warned$1.add(name);
70
- console.warn(`[@wcstack/router] bootstrapRouter: "${name}" is not one of its options, or not of the option's type. 3.x ignores it or applies it unchecked; 4.0 throws on it.`);
71
- }
72
- }
73
- else if (name === "tagNames") {
74
- warnInvalid(value, current, "tagNames.");
75
- }
76
- }
77
- }
78
55
  function setConfig(partialConfig) {
79
- warnInvalid(partialConfig, defaults);
80
- if (partialConfig.tagNames) {
81
- Object.assign(_config.tagNames, partialConfig.tagNames);
56
+ const options = _config;
57
+ const tags = _config.tagNames;
58
+ const given = Object.entries(partialConfig).filter(([, value]) => value !== undefined);
59
+ const givenTags = Object.entries(partialConfig.tagNames ?? {}).filter(([, tag]) => tag !== undefined);
60
+ for (const [key, value] of given) {
61
+ const current = options[key];
62
+ if (!Object.hasOwn(options, key) || value === null || typeof value !== typeof current || Array.isArray(value) !== Array.isArray(current)) {
63
+ invalid(key);
64
+ }
82
65
  }
83
- if (typeof partialConfig.enableShadowRoot === "boolean") {
84
- _config.enableShadowRoot = partialConfig.enableShadowRoot;
66
+ for (const [name, tag] of givenTags) {
67
+ if (!Object.hasOwn(tags, name) || typeof tag !== "string")
68
+ invalid(`tagNames.${name}`);
85
69
  }
86
- if (Array.isArray(partialConfig.basenameFileExtensions)) {
87
- _config.basenameFileExtensions = partialConfig.basenameFileExtensions;
70
+ for (const [key, value] of given) {
71
+ if (key !== "tagNames") {
72
+ options[key] = value;
73
+ }
88
74
  }
75
+ for (const [name, tag] of givenTags)
76
+ tags[name] = tag;
89
77
  frozenConfig = null;
90
78
  }
91
79
 
@@ -4048,7 +4036,7 @@ function bootstrapRouter(config, registry) {
4048
4036
  registerComponents(registry);
4049
4037
  }
4050
4038
 
4051
- var version = "3.5.4";
4039
+ var version = "4.0.0-rc.3";
4052
4040
  var pkg = {
4053
4041
  version: version};
4054
4042