|
|
@@ -12,14 +12,19 @@
|
|
|
* element attribute; changes to that
|
|
|
* attribute trigger a redraw
|
|
|
* stm-local-{name}="expr" subtree-scoped variable (element +
|
|
|
- * descendants); replaces the removed
|
|
|
- * stm-def-{name}-as
|
|
|
+ * descendants); supersedes
|
|
|
+ * stm-def-{name}-as (kept as an
|
|
|
+ * obsolescent alias, see below)
|
|
|
* stm-local-{name}-from-{attribute} subtree-scoped attribute-sourced
|
|
|
* variable; changes trigger a redraw
|
|
|
* stm-declare-{name} declares {name} for a subtree so a
|
|
|
* descendant can bind it and SIBLINGS
|
|
|
* of that binder can read it
|
|
|
*
|
|
|
+ * The legacy `stm-def-{name}-as="expr"` spelling (the pre-binding-module
|
|
|
+ * form, still emitted by older templates) is accepted as an exact alias of
|
|
|
+ * `stm-local-{name}` and logs a one-time obsolescence warning per element.
|
|
|
+ *
|
|
|
* Semantics (operator-confirmed):
|
|
|
* - LAZY-CACHED: a binding's expression evaluates at most once per render
|
|
|
* pass, only when something reads the variable; the result is cached for
|
|
|
@@ -83,6 +88,8 @@
|
|
|
/** Stable per-element identity for cache keys. @type {WeakMap} */
|
|
|
var elIds = new WeakMap();
|
|
|
var elSeq = 0;
|
|
|
+ /** Elements already warned for legacy stm-def usage. @type {WeakSet} */
|
|
|
+ var legacyWarned = new WeakSet();
|
|
|
|
|
|
function elId(el) {
|
|
|
var id = elIds.get(el);
|
|
|
@@ -122,6 +129,9 @@
|
|
|
/**
|
|
|
* Parse a binding attribute name into {kind, name, source, attr};
|
|
|
* source is the attribute/property name for -from- forms, else null.
|
|
|
+ * `stm-def-{name}-as` (the pre-binding spelling) parses as a LOCAL
|
|
|
+ * expression binding with legacy=true: identical semantics, plus an
|
|
|
+ * obsolescence warning at bind time.
|
|
|
* @param {string} attr
|
|
|
*/
|
|
|
function parseBinding(attr) {
|
|
|
@@ -134,6 +144,8 @@
|
|
|
return { kind: 'local', name: m[1], source: m[2], attr: attr };
|
|
|
if ((m = attr.match(/^stm-local-([A-Za-z_$][\w$]*)$/)))
|
|
|
return { kind: 'local', name: m[1], source: null, attr: attr };
|
|
|
+ if ((m = attr.match(/^stm-def-([A-Za-z_$][\w$]*)-as$/)))
|
|
|
+ return { kind: 'local', name: m[1], source: null, attr: attr, legacy: true };
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
@@ -279,6 +291,11 @@
|
|
|
var binding = parseBinding(attrName);
|
|
|
if (binding && binding.kind === 'local') {
|
|
|
if (!child) child = Object.create(scope || null);
|
|
|
+ if (binding.legacy && !legacyWarned.has(el)) {
|
|
|
+ legacyWarned.add(el);
|
|
|
+ console.warn('[statum] stm-def-' + binding.name + '-as is obsolescent; ' +
|
|
|
+ 'use stm-local-' + binding.name + ' (same semantics)');
|
|
|
+ }
|
|
|
// If an ancestor declared this name, bind into its slot so the
|
|
|
// declarer's whole subtree (including siblings of this element)
|
|
|
// reads this binding.
|