lwc 2.7.2 → 2.7.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.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +1970 -2104
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +1970 -2104
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +1157 -1283
  5. package/dist/engine-dom/iife/es5/engine-dom.js +1677 -1805
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +1949 -2069
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +1970 -2104
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +1157 -1283
  11. package/dist/engine-dom/umd/es5/engine-dom.js +1677 -1805
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +1949 -2069
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +1322 -1456
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +1322 -1456
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +8 -8
@@ -305,7 +305,7 @@
305
305
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
306
306
  return attributeName;
307
307
  }
308
- /** version: 2.7.2 */
308
+ /** version: 2.7.3 */
309
309
 
310
310
  /*
311
311
  * Copyright (c) 2018, salesforce.com, inc.
@@ -483,7 +483,7 @@
483
483
  setFeatureFlag(name, value);
484
484
  }
485
485
  }
486
- /** version: 2.7.2 */
486
+ /** version: 2.7.3 */
487
487
 
488
488
  /* proxy-compat-disable */
489
489
 
@@ -1017,62 +1017,205 @@
1017
1017
  */
1018
1018
 
1019
1019
 
1020
- function handleEvent(event, vnode) {
1021
- const {
1022
- type
1023
- } = event;
1024
- const {
1025
- data: {
1026
- on
1027
- }
1028
- } = vnode;
1029
- const handler = on && on[type]; // call event handler if exists
1020
+ function isUndef(s) {
1021
+ return s === undefined;
1022
+ }
1023
+
1024
+ function sameVnode(vnode1, vnode2) {
1025
+ return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;
1026
+ }
1027
+
1028
+ function isVNode(vnode) {
1029
+ return vnode != null;
1030
+ }
1031
+
1032
+ function createKeyToOldIdx(children, beginIdx, endIdx) {
1033
+ const map = {};
1034
+ let j, key, ch; // TODO [#1637]: simplify this by assuming that all vnodes has keys
1035
+
1036
+ for (j = beginIdx; j <= endIdx; ++j) {
1037
+ ch = children[j];
1030
1038
 
1031
- if (handler) {
1032
- handler.call(undefined, event);
1039
+ if (isVNode(ch)) {
1040
+ key = ch.key;
1041
+
1042
+ if (key !== undefined) {
1043
+ map[key] = j;
1044
+ }
1045
+ }
1033
1046
  }
1047
+
1048
+ return map;
1034
1049
  }
1035
1050
 
1036
- function createListener() {
1037
- return function handler(event) {
1038
- handleEvent(event, handler.vnode);
1039
- };
1051
+ function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
1052
+ for (; startIdx <= endIdx; ++startIdx) {
1053
+ const ch = vnodes[startIdx];
1054
+
1055
+ if (isVNode(ch)) {
1056
+ ch.hook.create(ch);
1057
+ ch.hook.insert(ch, parentElm, before);
1058
+ }
1059
+ }
1040
1060
  }
1041
1061
 
1042
- function updateAllEventListeners(oldVnode, vnode) {
1043
- if (isUndefined$1(oldVnode.listener)) {
1044
- createAllEventListeners(vnode);
1045
- } else {
1046
- vnode.listener = oldVnode.listener;
1047
- vnode.listener.vnode = vnode;
1062
+ function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
1063
+ for (; startIdx <= endIdx; ++startIdx) {
1064
+ const ch = vnodes[startIdx]; // text nodes do not have logic associated to them
1065
+
1066
+ if (isVNode(ch)) {
1067
+ ch.hook.remove(ch, parentElm);
1068
+ }
1048
1069
  }
1049
1070
  }
1050
1071
 
1051
- function createAllEventListeners(vnode) {
1052
- const {
1053
- elm,
1054
- data: {
1055
- on
1072
+ function updateDynamicChildren(parentElm, oldCh, newCh) {
1073
+ let oldStartIdx = 0;
1074
+ let newStartIdx = 0;
1075
+ let oldEndIdx = oldCh.length - 1;
1076
+ let oldStartVnode = oldCh[0];
1077
+ let oldEndVnode = oldCh[oldEndIdx];
1078
+ const newChEnd = newCh.length - 1;
1079
+ let newEndIdx = newChEnd;
1080
+ let newStartVnode = newCh[0];
1081
+ let newEndVnode = newCh[newEndIdx];
1082
+ let oldKeyToIdx;
1083
+ let idxInOld;
1084
+ let elmToMove;
1085
+ let before;
1086
+
1087
+ while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
1088
+ if (!isVNode(oldStartVnode)) {
1089
+ oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
1090
+ } else if (!isVNode(oldEndVnode)) {
1091
+ oldEndVnode = oldCh[--oldEndIdx];
1092
+ } else if (!isVNode(newStartVnode)) {
1093
+ newStartVnode = newCh[++newStartIdx];
1094
+ } else if (!isVNode(newEndVnode)) {
1095
+ newEndVnode = newCh[--newEndIdx];
1096
+ } else if (sameVnode(oldStartVnode, newStartVnode)) {
1097
+ patchVnode(oldStartVnode, newStartVnode);
1098
+ oldStartVnode = oldCh[++oldStartIdx];
1099
+ newStartVnode = newCh[++newStartIdx];
1100
+ } else if (sameVnode(oldEndVnode, newEndVnode)) {
1101
+ patchVnode(oldEndVnode, newEndVnode);
1102
+ oldEndVnode = oldCh[--oldEndIdx];
1103
+ newEndVnode = newCh[--newEndIdx];
1104
+ } else if (sameVnode(oldStartVnode, newEndVnode)) {
1105
+ // Vnode moved right
1106
+ patchVnode(oldStartVnode, newEndVnode);
1107
+ newEndVnode.hook.move(oldStartVnode, parentElm, nextSibling$1(oldEndVnode.elm));
1108
+ oldStartVnode = oldCh[++oldStartIdx];
1109
+ newEndVnode = newCh[--newEndIdx];
1110
+ } else if (sameVnode(oldEndVnode, newStartVnode)) {
1111
+ // Vnode moved left
1112
+ patchVnode(oldEndVnode, newStartVnode);
1113
+ newStartVnode.hook.move(oldEndVnode, parentElm, oldStartVnode.elm);
1114
+ oldEndVnode = oldCh[--oldEndIdx];
1115
+ newStartVnode = newCh[++newStartIdx];
1116
+ } else {
1117
+ if (oldKeyToIdx === undefined) {
1118
+ oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
1119
+ }
1120
+
1121
+ idxInOld = oldKeyToIdx[newStartVnode.key];
1122
+
1123
+ if (isUndef(idxInOld)) {
1124
+ // New element
1125
+ newStartVnode.hook.create(newStartVnode);
1126
+ newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
1127
+ newStartVnode = newCh[++newStartIdx];
1128
+ } else {
1129
+ elmToMove = oldCh[idxInOld];
1130
+
1131
+ if (isVNode(elmToMove)) {
1132
+ if (elmToMove.sel !== newStartVnode.sel) {
1133
+ // New element
1134
+ newStartVnode.hook.create(newStartVnode);
1135
+ newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
1136
+ } else {
1137
+ patchVnode(elmToMove, newStartVnode);
1138
+ oldCh[idxInOld] = undefined;
1139
+ newStartVnode.hook.move(elmToMove, parentElm, oldStartVnode.elm);
1140
+ }
1141
+ }
1142
+
1143
+ newStartVnode = newCh[++newStartIdx];
1144
+ }
1056
1145
  }
1057
- } = vnode;
1146
+ }
1058
1147
 
1059
- if (isUndefined$1(on)) {
1148
+ if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
1149
+ if (oldStartIdx > oldEndIdx) {
1150
+ // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
1151
+ // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
1152
+ let i = newEndIdx;
1153
+ let n;
1154
+
1155
+ do {
1156
+ n = newCh[++i];
1157
+ } while (!isVNode(n) && i < newChEnd);
1158
+
1159
+ before = isVNode(n) ? n.elm : null;
1160
+ addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
1161
+ } else {
1162
+ removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
1163
+ }
1164
+ }
1165
+ }
1166
+
1167
+ function updateStaticChildren(parentElm, oldCh, newCh) {
1168
+ const oldChLength = oldCh.length;
1169
+ const newChLength = newCh.length;
1170
+
1171
+ if (oldChLength === 0) {
1172
+ // the old list is empty, we can directly insert anything new
1173
+ addVnodes(parentElm, null, newCh, 0, newChLength);
1060
1174
  return;
1061
1175
  }
1062
1176
 
1063
- const listener = vnode.listener = createListener();
1064
- listener.vnode = vnode;
1065
- let name;
1177
+ if (newChLength === 0) {
1178
+ // the old list is nonempty and the new list is empty so we can directly remove all old nodes
1179
+ // this is the case in which the dynamic children of an if-directive should be removed
1180
+ removeVnodes(parentElm, oldCh, 0, oldChLength);
1181
+ return;
1182
+ } // if the old list is not empty, the new list MUST have the same
1183
+ // amount of nodes, that's why we call this static children
1184
+
1185
+
1186
+ let referenceElm = null;
1187
+
1188
+ for (let i = newChLength - 1; i >= 0; i -= 1) {
1189
+ const vnode = newCh[i];
1190
+ const oldVNode = oldCh[i];
1191
+
1192
+ if (vnode !== oldVNode) {
1193
+ if (isVNode(oldVNode)) {
1194
+ if (isVNode(vnode)) {
1195
+ // both vnodes must be equivalent, and se just need to patch them
1196
+ patchVnode(oldVNode, vnode);
1197
+ referenceElm = vnode.elm;
1198
+ } else {
1199
+ // removing the old vnode since the new one is null
1200
+ oldVNode.hook.remove(oldVNode, parentElm);
1201
+ }
1202
+ } else if (isVNode(vnode)) {
1203
+ // this condition is unnecessary
1204
+ vnode.hook.create(vnode); // insert the new node one since the old one is null
1066
1205
 
1067
- for (name in on) {
1068
- addEventListener$1(elm, name, listener);
1206
+ vnode.hook.insert(vnode, parentElm, referenceElm);
1207
+ referenceElm = vnode.elm;
1208
+ }
1209
+ }
1069
1210
  }
1070
1211
  }
1071
1212
 
1072
- var modEvents = {
1073
- update: updateAllEventListeners,
1074
- create: createAllEventListeners
1075
- };
1213
+ function patchVnode(oldVnode, vnode) {
1214
+ if (oldVnode !== vnode) {
1215
+ vnode.elm = oldVnode.elm;
1216
+ vnode.hook.update(oldVnode, vnode);
1217
+ }
1218
+ }
1076
1219
  /*
1077
1220
  * Copyright (c) 2018, salesforce.com, inc.
1078
1221
  * All rights reserved.
@@ -1080,6 +1223,7 @@
1080
1223
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1081
1224
  */
1082
1225
 
1226
+
1083
1227
  const defaultDefHTMLPropertyNames = ['accessKey', 'dir', 'draggable', 'hidden', 'id', 'lang', 'spellcheck', 'tabIndex', 'title'];
1084
1228
 
1085
1229
  function offsetPropertyErrorMessage(name) {
@@ -1199,313 +1343,379 @@
1199
1343
  */
1200
1344
 
1201
1345
 
1202
- const xlinkNS = 'http://www.w3.org/1999/xlink';
1203
- const xmlNS = 'http://www.w3.org/XML/1998/namespace';
1204
- const ColonCharCode = 58;
1205
-
1206
- function updateAttrs(oldVnode, vnode) {
1207
- const {
1208
- data: {
1209
- attrs
1210
- }
1211
- } = vnode;
1346
+ function generateDataDescriptor(options) {
1347
+ return assign({
1348
+ configurable: true,
1349
+ enumerable: true,
1350
+ writable: true
1351
+ }, options);
1352
+ }
1212
1353
 
1213
- if (isUndefined$1(attrs)) {
1214
- return;
1215
- }
1354
+ function generateAccessorDescriptor(options) {
1355
+ return assign({
1356
+ configurable: true,
1357
+ enumerable: true
1358
+ }, options);
1359
+ }
1216
1360
 
1217
- let {
1218
- data: {
1219
- attrs: oldAttrs
1220
- }
1221
- } = oldVnode;
1361
+ let isDomMutationAllowed = false;
1222
1362
 
1223
- if (oldAttrs === attrs) {
1224
- return;
1363
+ function unlockDomMutation() {
1364
+ if (process.env.NODE_ENV === 'production') {
1365
+ // this method should never leak to prod
1366
+ throw new ReferenceError();
1225
1367
  }
1226
1368
 
1227
- if (process.env.NODE_ENV !== 'production') {
1228
- assert.invariant(isUndefined$1(oldAttrs) || keys(oldAttrs).join(',') === keys(attrs).join(','), `vnode.data.attrs cannot change shape.`);
1369
+ isDomMutationAllowed = true;
1370
+ }
1371
+
1372
+ function lockDomMutation() {
1373
+ if (process.env.NODE_ENV === 'production') {
1374
+ // this method should never leak to prod
1375
+ throw new ReferenceError();
1229
1376
  }
1230
1377
 
1231
- const elm = vnode.elm;
1232
- let key;
1233
- oldAttrs = isUndefined$1(oldAttrs) ? EmptyObject : oldAttrs; // update modified attributes, add new attributes
1234
- // this routine is only useful for data-* attributes in all kind of elements
1235
- // and aria-* in standard elements (custom elements will use props for these)
1378
+ isDomMutationAllowed = false;
1379
+ }
1236
1380
 
1237
- for (key in attrs) {
1238
- const cur = attrs[key];
1239
- const old = oldAttrs[key];
1381
+ function logMissingPortalError(name, type) {
1382
+ return logError(`The \`${name}\` ${type} is available only on elements that use the \`lwc:dom="manual"\` directive.`);
1383
+ }
1240
1384
 
1241
- if (old !== cur) {
1242
- unlockAttribute(elm, key);
1385
+ function patchElementWithRestrictions(elm, options) {
1386
+ if (process.env.NODE_ENV === 'production') {
1387
+ // this method should never leak to prod
1388
+ throw new ReferenceError();
1389
+ }
1243
1390
 
1244
- if (StringCharCodeAt.call(key, 3) === ColonCharCode) {
1245
- // Assume xml namespace
1246
- setAttribute$1(elm, key, cur, xmlNS);
1247
- } else if (StringCharCodeAt.call(key, 5) === ColonCharCode) {
1248
- // Assume xlink namespace
1249
- setAttribute$1(elm, key, cur, xlinkNS);
1250
- } else if (isNull(cur) || isUndefined$1(cur)) {
1251
- removeAttribute$1(elm, key);
1252
- } else {
1253
- setAttribute$1(elm, key, cur);
1391
+ const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML');
1392
+ const descriptors = {
1393
+ outerHTML: generateAccessorDescriptor({
1394
+ get() {
1395
+ return originalOuterHTMLDescriptor.get.call(this);
1396
+ },
1397
+
1398
+ set(_value) {
1399
+ throw new TypeError(`Invalid attempt to set outerHTML on Element.`);
1254
1400
  }
1255
1401
 
1256
- lockAttribute();
1257
- }
1258
- }
1259
- }
1402
+ })
1403
+ }; // Apply extra restriction related to DOM manipulation if the element is not a portal.
1260
1404
 
1261
- const emptyVNode$3 = {
1262
- data: {}
1263
- };
1264
- var modAttrs = {
1265
- create: vnode => updateAttrs(emptyVNode$3, vnode),
1266
- update: updateAttrs
1267
- };
1268
- /*
1269
- * Copyright (c) 2018, salesforce.com, inc.
1270
- * All rights reserved.
1271
- * SPDX-License-Identifier: MIT
1272
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1273
- */
1405
+ if (!options.isLight && !options.isPortal) {
1406
+ const {
1407
+ appendChild,
1408
+ insertBefore,
1409
+ removeChild,
1410
+ replaceChild
1411
+ } = elm;
1412
+ const originalNodeValueDescriptor = getPropertyDescriptor(elm, 'nodeValue');
1413
+ const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML');
1414
+ const originalTextContentDescriptor = getPropertyDescriptor(elm, 'textContent');
1415
+ assign(descriptors, {
1416
+ appendChild: generateDataDescriptor({
1417
+ value(aChild) {
1418
+ logMissingPortalError('appendChild', 'method');
1419
+ return appendChild.call(this, aChild);
1420
+ }
1274
1421
 
1275
- function isLiveBindingProp(sel, key) {
1276
- // For properties with live bindings, we read values from the DOM element
1277
- // instead of relying on internally tracked values.
1278
- return sel === 'input' && (key === 'value' || key === 'checked');
1279
- }
1422
+ }),
1423
+ insertBefore: generateDataDescriptor({
1424
+ value(newNode, referenceNode) {
1425
+ if (!isDomMutationAllowed) {
1426
+ logMissingPortalError('insertBefore', 'method');
1427
+ }
1280
1428
 
1281
- function update(oldVnode, vnode) {
1282
- const props = vnode.data.props;
1429
+ return insertBefore.call(this, newNode, referenceNode);
1430
+ }
1283
1431
 
1284
- if (isUndefined$1(props)) {
1285
- return;
1286
- }
1432
+ }),
1433
+ removeChild: generateDataDescriptor({
1434
+ value(aChild) {
1435
+ if (!isDomMutationAllowed) {
1436
+ logMissingPortalError('removeChild', 'method');
1437
+ }
1287
1438
 
1288
- const oldProps = oldVnode.data.props;
1439
+ return removeChild.call(this, aChild);
1440
+ }
1289
1441
 
1290
- if (oldProps === props) {
1291
- return;
1292
- }
1442
+ }),
1443
+ replaceChild: generateDataDescriptor({
1444
+ value(newChild, oldChild) {
1445
+ logMissingPortalError('replaceChild', 'method');
1446
+ return replaceChild.call(this, newChild, oldChild);
1447
+ }
1293
1448
 
1294
- if (process.env.NODE_ENV !== 'production') {
1295
- assert.invariant(isUndefined$1(oldProps) || keys(oldProps).join(',') === keys(props).join(','), 'vnode.data.props cannot change shape.');
1296
- }
1449
+ }),
1450
+ nodeValue: generateAccessorDescriptor({
1451
+ get() {
1452
+ return originalNodeValueDescriptor.get.call(this);
1453
+ },
1297
1454
 
1298
- const isFirstPatch = isUndefined$1(oldProps);
1299
- const {
1300
- elm,
1301
- sel
1302
- } = vnode;
1455
+ set(value) {
1456
+ if (!isDomMutationAllowed) {
1457
+ logMissingPortalError('nodeValue', 'property');
1458
+ }
1303
1459
 
1304
- for (const key in props) {
1305
- const cur = props[key]; // if it is the first time this element is patched, or the current value is different to the previous value...
1460
+ originalNodeValueDescriptor.set.call(this, value);
1461
+ }
1306
1462
 
1307
- if (isFirstPatch || cur !== (isLiveBindingProp(sel, key) ? getProperty$1(elm, key) : oldProps[key])) {
1308
- setProperty$1(elm, key, cur);
1309
- }
1310
- }
1311
- }
1463
+ }),
1464
+ textContent: generateAccessorDescriptor({
1465
+ get() {
1466
+ return originalTextContentDescriptor.get.call(this);
1467
+ },
1312
1468
 
1313
- const emptyVNode$2 = {
1314
- data: {}
1315
- };
1316
- var modProps = {
1317
- create: vnode => update(emptyVNode$2, vnode),
1318
- update
1319
- };
1320
- /*
1321
- * Copyright (c) 2018, salesforce.com, inc.
1322
- * All rights reserved.
1323
- * SPDX-License-Identifier: MIT
1324
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1325
- */
1469
+ set(value) {
1470
+ logMissingPortalError('textContent', 'property');
1471
+ originalTextContentDescriptor.set.call(this, value);
1472
+ }
1326
1473
 
1327
- const classNameToClassMap = create(null);
1474
+ }),
1475
+ innerHTML: generateAccessorDescriptor({
1476
+ get() {
1477
+ return originalInnerHTMLDescriptor.get.call(this);
1478
+ },
1328
1479
 
1329
- function getMapFromClassName(className) {
1330
- // Intentionally using == to match undefined and null values from computed style attribute
1331
- if (className == null) {
1332
- return EmptyObject;
1333
- } // computed class names must be string
1480
+ set(value) {
1481
+ logMissingPortalError('innerHTML', 'property');
1482
+ return originalInnerHTMLDescriptor.set.call(this, value);
1483
+ }
1334
1484
 
1485
+ })
1486
+ });
1487
+ }
1335
1488
 
1336
- className = isString(className) ? className : className + '';
1337
- let map = classNameToClassMap[className];
1489
+ defineProperties(elm, descriptors);
1490
+ }
1338
1491
 
1339
- if (map) {
1340
- return map;
1341
- }
1492
+ function getShadowRootRestrictionsDescriptors(sr) {
1493
+ if (process.env.NODE_ENV === 'production') {
1494
+ // this method should never leak to prod
1495
+ throw new ReferenceError();
1496
+ } // Disallowing properties in dev mode only to avoid people doing the wrong
1497
+ // thing when using the real shadow root, because if that's the case,
1498
+ // the component will not work when running with synthetic shadow.
1342
1499
 
1343
- map = create(null);
1344
- let start = 0;
1345
- let o;
1346
- const len = className.length;
1347
1500
 
1348
- for (o = 0; o < len; o++) {
1349
- if (StringCharCodeAt.call(className, o) === SPACE_CHAR) {
1350
- if (o > start) {
1351
- map[StringSlice.call(className, start, o)] = true;
1501
+ const originalAddEventListener = sr.addEventListener;
1502
+ const originalInnerHTMLDescriptor = getPropertyDescriptor(sr, 'innerHTML');
1503
+ const originalTextContentDescriptor = getPropertyDescriptor(sr, 'textContent');
1504
+ return {
1505
+ innerHTML: generateAccessorDescriptor({
1506
+ get() {
1507
+ return originalInnerHTMLDescriptor.get.call(this);
1508
+ },
1509
+
1510
+ set(_value) {
1511
+ throw new TypeError(`Invalid attempt to set innerHTML on ShadowRoot.`);
1352
1512
  }
1353
1513
 
1354
- start = o + 1;
1355
- }
1356
- }
1514
+ }),
1515
+ textContent: generateAccessorDescriptor({
1516
+ get() {
1517
+ return originalTextContentDescriptor.get.call(this);
1518
+ },
1357
1519
 
1358
- if (o > start) {
1359
- map[StringSlice.call(className, start, o)] = true;
1360
- }
1520
+ set(_value) {
1521
+ throw new TypeError(`Invalid attempt to set textContent on ShadowRoot.`);
1522
+ }
1361
1523
 
1362
- classNameToClassMap[className] = map;
1524
+ }),
1525
+ addEventListener: generateDataDescriptor({
1526
+ value(type, listener, options) {
1527
+ // TODO [#420]: this is triggered when the component author attempts to add a listener
1528
+ // programmatically into its Component's shadow root
1529
+ if (!isUndefined$1(options)) {
1530
+ logError('The `addEventListener` method on ShadowRoot does not support any options.', getAssociatedVMIfPresent(this));
1531
+ } // Typescript does not like it when you treat the `arguments` object as an array
1532
+ // @ts-ignore type-mismatch
1363
1533
 
1364
- if (process.env.NODE_ENV !== 'production') {
1365
- // just to make sure that this object never changes as part of the diffing algo
1366
- freeze(map);
1367
- }
1368
1534
 
1369
- return map;
1370
- }
1535
+ return originalAddEventListener.apply(this, arguments);
1536
+ }
1371
1537
 
1372
- function updateClassAttribute(oldVnode, vnode) {
1373
- const {
1374
- elm,
1375
- data: {
1376
- className: newClass
1377
- }
1378
- } = vnode;
1379
- const {
1380
- data: {
1381
- className: oldClass
1382
- }
1383
- } = oldVnode;
1538
+ })
1539
+ };
1540
+ } // Custom Elements Restrictions:
1541
+ // -----------------------------
1384
1542
 
1385
- if (oldClass === newClass) {
1386
- return;
1543
+
1544
+ function getCustomElementRestrictionsDescriptors(elm) {
1545
+ if (process.env.NODE_ENV === 'production') {
1546
+ // this method should never leak to prod
1547
+ throw new ReferenceError();
1387
1548
  }
1388
1549
 
1389
- const classList = getClassList$1(elm);
1390
- const newClassMap = getMapFromClassName(newClass);
1391
- const oldClassMap = getMapFromClassName(oldClass);
1392
- let name;
1550
+ const originalAddEventListener = elm.addEventListener;
1551
+ const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML');
1552
+ const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML');
1553
+ const originalTextContentDescriptor = getPropertyDescriptor(elm, 'textContent');
1554
+ return {
1555
+ innerHTML: generateAccessorDescriptor({
1556
+ get() {
1557
+ return originalInnerHTMLDescriptor.get.call(this);
1558
+ },
1393
1559
 
1394
- for (name in oldClassMap) {
1395
- // remove only if it is not in the new class collection and it is not set from within the instance
1396
- if (isUndefined$1(newClassMap[name])) {
1397
- classList.remove(name);
1398
- }
1399
- }
1560
+ set(_value) {
1561
+ throw new TypeError(`Invalid attempt to set innerHTML on HTMLElement.`);
1562
+ }
1400
1563
 
1401
- for (name in newClassMap) {
1402
- if (isUndefined$1(oldClassMap[name])) {
1403
- classList.add(name);
1404
- }
1405
- }
1406
- }
1564
+ }),
1565
+ outerHTML: generateAccessorDescriptor({
1566
+ get() {
1567
+ return originalOuterHTMLDescriptor.get.call(this);
1568
+ },
1407
1569
 
1408
- const emptyVNode$1 = {
1409
- data: {}
1410
- };
1411
- var modComputedClassName = {
1412
- create: vnode => updateClassAttribute(emptyVNode$1, vnode),
1413
- update: updateClassAttribute
1414
- };
1415
- /*
1416
- * Copyright (c) 2018, salesforce.com, inc.
1417
- * All rights reserved.
1418
- * SPDX-License-Identifier: MIT
1419
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1420
- */
1570
+ set(_value) {
1571
+ throw new TypeError(`Invalid attempt to set outerHTML on HTMLElement.`);
1572
+ }
1421
1573
 
1422
- function updateStyleAttribute(oldVnode, vnode) {
1423
- const {
1424
- elm,
1425
- data: {
1426
- style: newStyle
1427
- }
1428
- } = vnode;
1574
+ }),
1575
+ textContent: generateAccessorDescriptor({
1576
+ get() {
1577
+ return originalTextContentDescriptor.get.call(this);
1578
+ },
1429
1579
 
1430
- if (oldVnode.data.style === newStyle) {
1431
- return;
1432
- }
1580
+ set(_value) {
1581
+ throw new TypeError(`Invalid attempt to set textContent on HTMLElement.`);
1582
+ }
1433
1583
 
1434
- if (!isString(newStyle) || newStyle === '') {
1435
- removeAttribute$1(elm, 'style');
1436
- } else {
1437
- setAttribute$1(elm, 'style', newStyle);
1584
+ }),
1585
+ addEventListener: generateDataDescriptor({
1586
+ value(type, listener, options) {
1587
+ // TODO [#420]: this is triggered when the component author attempts to add a listener
1588
+ // programmatically into a lighting element node
1589
+ if (!isUndefined$1(options)) {
1590
+ logError('The `addEventListener` method in `LightningElement` does not support any options.', getAssociatedVMIfPresent(this));
1591
+ } // Typescript does not like it when you treat the `arguments` object as an array
1592
+ // @ts-ignore type-mismatch
1593
+
1594
+
1595
+ return originalAddEventListener.apply(this, arguments);
1596
+ }
1597
+
1598
+ })
1599
+ };
1600
+ }
1601
+
1602
+ function getComponentRestrictionsDescriptors() {
1603
+ if (process.env.NODE_ENV === 'production') {
1604
+ // this method should never leak to prod
1605
+ throw new ReferenceError();
1438
1606
  }
1607
+
1608
+ return {
1609
+ tagName: generateAccessorDescriptor({
1610
+ get() {
1611
+ throw new Error(`Usage of property \`tagName\` is disallowed because the component itself does` + ` not know which tagName will be used to create the element, therefore writing` + ` code that check for that value is error prone.`);
1612
+ },
1613
+
1614
+ configurable: true,
1615
+ enumerable: false // no enumerable properties on component
1616
+
1617
+ })
1618
+ };
1439
1619
  }
1440
1620
 
1441
- const emptyVNode = {
1442
- data: {}
1443
- };
1444
- var modComputedStyle = {
1445
- create: vnode => updateStyleAttribute(emptyVNode, vnode),
1446
- update: updateStyleAttribute
1447
- };
1448
- /*
1449
- * Copyright (c) 2018, salesforce.com, inc.
1450
- * All rights reserved.
1451
- * SPDX-License-Identifier: MIT
1452
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1453
- */
1454
- // The compiler takes care of transforming the inline classnames into an object. It's faster to set the
1455
- // different classnames properties individually instead of via a string.
1621
+ function getLightningElementPrototypeRestrictionsDescriptors(proto) {
1622
+ if (process.env.NODE_ENV === 'production') {
1623
+ // this method should never leak to prod
1624
+ throw new ReferenceError();
1625
+ }
1456
1626
 
1457
- function createClassAttribute(vnode) {
1458
- const {
1459
- elm,
1460
- data: {
1461
- classMap
1627
+ const originalDispatchEvent = proto.dispatchEvent;
1628
+ const descriptors = {
1629
+ dispatchEvent: generateDataDescriptor({
1630
+ value(event) {
1631
+ const vm = getAssociatedVM(this);
1632
+
1633
+ if (!isNull(event) && isObject(event)) {
1634
+ const {
1635
+ type
1636
+ } = event;
1637
+
1638
+ if (!/^[a-z][a-z0-9_]*$/.test(type)) {
1639
+ logError(`Invalid event type "${type}" dispatched in element ${getComponentTag(vm)}.` + ` Event name must start with a lowercase letter and followed only lowercase` + ` letters, numbers, and underscores`, vm);
1640
+ }
1641
+ } // Typescript does not like it when you treat the `arguments` object as an array
1642
+ // @ts-ignore type-mismatch
1643
+
1644
+
1645
+ return originalDispatchEvent.apply(this, arguments);
1646
+ }
1647
+
1648
+ })
1649
+ };
1650
+ forEach.call(getOwnPropertyNames$1(globalHTMLProperties), propName => {
1651
+ if (propName in proto) {
1652
+ return; // no need to redefine something that we are already exposing
1462
1653
  }
1463
- } = vnode;
1464
1654
 
1465
- if (isUndefined$1(classMap)) {
1466
- return;
1467
- }
1655
+ descriptors[propName] = generateAccessorDescriptor({
1656
+ get() {
1657
+ const {
1658
+ error,
1659
+ attribute
1660
+ } = globalHTMLProperties[propName];
1661
+ const msg = [];
1662
+ msg.push(`Accessing the global HTML property "${propName}" is disabled.`);
1468
1663
 
1469
- const classList = getClassList$1(elm);
1664
+ if (error) {
1665
+ msg.push(error);
1666
+ } else if (attribute) {
1667
+ msg.push(`Instead access it via \`this.getAttribute("${attribute}")\`.`);
1668
+ }
1470
1669
 
1471
- for (const name in classMap) {
1472
- classList.add(name);
1473
- }
1670
+ logError(msg.join('\n'), getAssociatedVM(this));
1671
+ },
1672
+
1673
+ set() {
1674
+ const {
1675
+ readOnly
1676
+ } = globalHTMLProperties[propName];
1677
+
1678
+ if (readOnly) {
1679
+ logError(`The global HTML property \`${propName}\` is read-only.`, getAssociatedVM(this));
1680
+ }
1681
+ }
1682
+
1683
+ });
1684
+ });
1685
+ return descriptors;
1686
+ } // This routine will prevent access to certain properties on a shadow root instance to guarantee
1687
+ // that all components will work fine in IE11 and other browsers without shadow dom support.
1688
+
1689
+
1690
+ function patchShadowRootWithRestrictions(sr) {
1691
+ defineProperties(sr, getShadowRootRestrictionsDescriptors(sr));
1474
1692
  }
1475
1693
 
1476
- var modStaticClassName = {
1477
- create: createClassAttribute
1478
- };
1694
+ function patchCustomElementWithRestrictions(elm) {
1695
+ const restrictionsDescriptors = getCustomElementRestrictionsDescriptors(elm);
1696
+ const elmProto = getPrototypeOf$1(elm);
1697
+ setPrototypeOf(elm, create(elmProto, restrictionsDescriptors));
1698
+ }
1699
+
1700
+ function patchComponentWithRestrictions(cmp) {
1701
+ defineProperties(cmp, getComponentRestrictionsDescriptors());
1702
+ }
1703
+
1704
+ function patchLightningElementPrototypeWithRestrictions(proto) {
1705
+ defineProperties(proto, getLightningElementPrototypeRestrictionsDescriptors(proto));
1706
+ }
1479
1707
  /*
1480
1708
  * Copyright (c) 2018, salesforce.com, inc.
1481
1709
  * All rights reserved.
1482
1710
  * SPDX-License-Identifier: MIT
1483
1711
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1484
1712
  */
1485
- // The compiler takes care of transforming the inline style into an object. It's faster to set the
1486
- // different style properties individually instead of via a string.
1487
-
1488
- function createStyleAttribute(vnode) {
1489
- const {
1490
- elm,
1491
- data: {
1492
- styleDecls
1493
- }
1494
- } = vnode;
1495
-
1496
- if (isUndefined$1(styleDecls)) {
1497
- return;
1498
- }
1713
+ // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
1714
+ // to inject at runtime.
1499
1715
 
1500
- for (let i = 0; i < styleDecls.length; i++) {
1501
- const [prop, value, important] = styleDecls[i];
1502
- setCSSStyleProperty$1(elm, prop, value, important);
1503
- }
1504
- }
1505
1716
 
1506
- var modStaticStyle = {
1507
- create: createStyleAttribute
1508
- };
1717
+ const HTMLElementConstructor$1 = typeof HTMLElement !== 'undefined' ? HTMLElement : function () {};
1718
+ const HTMLElementPrototype = HTMLElementConstructor$1.prototype;
1509
1719
  /*
1510
1720
  * Copyright (c) 2018, salesforce.com, inc.
1511
1721
  * All rights reserved.
@@ -1513,623 +1723,36 @@
1513
1723
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1514
1724
  */
1515
1725
 
1516
- function isUndef(s) {
1517
- return s === undefined;
1518
- }
1519
-
1520
- function sameVnode(vnode1, vnode2) {
1521
- return vnode1.key === vnode2.key && vnode1.sel === vnode2.sel;
1522
- }
1523
-
1524
- function isVNode(vnode) {
1525
- return vnode != null;
1526
- }
1527
-
1528
- function createKeyToOldIdx(children, beginIdx, endIdx) {
1529
- const map = {};
1530
- let j, key, ch; // TODO [#1637]: simplify this by assuming that all vnodes has keys
1531
-
1532
- for (j = beginIdx; j <= endIdx; ++j) {
1533
- ch = children[j];
1726
+ /**
1727
+ * This is a descriptor map that contains
1728
+ * all standard properties that a Custom Element can support (including AOM properties), which
1729
+ * determines what kind of capabilities the Base HTML Element and
1730
+ * Base Lightning Element should support.
1731
+ */
1534
1732
 
1535
- if (isVNode(ch)) {
1536
- key = ch.key;
1733
+ const HTMLElementOriginalDescriptors = create(null);
1734
+ forEach.call(keys(AriaPropNameToAttrNameMap), propName => {
1735
+ // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
1736
+ // in IE11, some properties are on Element.prototype instead of HTMLElement, just to be sure.
1737
+ const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
1537
1738
 
1538
- if (key !== undefined) {
1539
- map[key] = j;
1540
- }
1541
- }
1739
+ if (!isUndefined$1(descriptor)) {
1740
+ HTMLElementOriginalDescriptors[propName] = descriptor;
1542
1741
  }
1742
+ });
1743
+ forEach.call(defaultDefHTMLPropertyNames, propName => {
1744
+ // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
1745
+ // in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into
1746
+ // this category, so, better to be sure.
1747
+ const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
1543
1748
 
1544
- return map;
1545
- }
1546
-
1547
- function addVnodes(parentElm, before, vnodes, startIdx, endIdx) {
1548
- for (; startIdx <= endIdx; ++startIdx) {
1549
- const ch = vnodes[startIdx];
1550
-
1551
- if (isVNode(ch)) {
1552
- ch.hook.create(ch);
1553
- ch.hook.insert(ch, parentElm, before);
1554
- }
1749
+ if (!isUndefined$1(descriptor)) {
1750
+ HTMLElementOriginalDescriptors[propName] = descriptor;
1555
1751
  }
1556
- }
1557
-
1558
- function removeVnodes(parentElm, vnodes, startIdx, endIdx) {
1559
- for (; startIdx <= endIdx; ++startIdx) {
1560
- const ch = vnodes[startIdx]; // text nodes do not have logic associated to them
1561
-
1562
- if (isVNode(ch)) {
1563
- ch.hook.remove(ch, parentElm);
1564
- }
1565
- }
1566
- }
1567
-
1568
- function updateDynamicChildren(parentElm, oldCh, newCh) {
1569
- let oldStartIdx = 0;
1570
- let newStartIdx = 0;
1571
- let oldEndIdx = oldCh.length - 1;
1572
- let oldStartVnode = oldCh[0];
1573
- let oldEndVnode = oldCh[oldEndIdx];
1574
- const newChEnd = newCh.length - 1;
1575
- let newEndIdx = newChEnd;
1576
- let newStartVnode = newCh[0];
1577
- let newEndVnode = newCh[newEndIdx];
1578
- let oldKeyToIdx;
1579
- let idxInOld;
1580
- let elmToMove;
1581
- let before;
1582
-
1583
- while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
1584
- if (!isVNode(oldStartVnode)) {
1585
- oldStartVnode = oldCh[++oldStartIdx]; // Vnode might have been moved left
1586
- } else if (!isVNode(oldEndVnode)) {
1587
- oldEndVnode = oldCh[--oldEndIdx];
1588
- } else if (!isVNode(newStartVnode)) {
1589
- newStartVnode = newCh[++newStartIdx];
1590
- } else if (!isVNode(newEndVnode)) {
1591
- newEndVnode = newCh[--newEndIdx];
1592
- } else if (sameVnode(oldStartVnode, newStartVnode)) {
1593
- patchVnode(oldStartVnode, newStartVnode);
1594
- oldStartVnode = oldCh[++oldStartIdx];
1595
- newStartVnode = newCh[++newStartIdx];
1596
- } else if (sameVnode(oldEndVnode, newEndVnode)) {
1597
- patchVnode(oldEndVnode, newEndVnode);
1598
- oldEndVnode = oldCh[--oldEndIdx];
1599
- newEndVnode = newCh[--newEndIdx];
1600
- } else if (sameVnode(oldStartVnode, newEndVnode)) {
1601
- // Vnode moved right
1602
- patchVnode(oldStartVnode, newEndVnode);
1603
- newEndVnode.hook.move(oldStartVnode, parentElm, nextSibling$1(oldEndVnode.elm));
1604
- oldStartVnode = oldCh[++oldStartIdx];
1605
- newEndVnode = newCh[--newEndIdx];
1606
- } else if (sameVnode(oldEndVnode, newStartVnode)) {
1607
- // Vnode moved left
1608
- patchVnode(oldEndVnode, newStartVnode);
1609
- newStartVnode.hook.move(oldEndVnode, parentElm, oldStartVnode.elm);
1610
- oldEndVnode = oldCh[--oldEndIdx];
1611
- newStartVnode = newCh[++newStartIdx];
1612
- } else {
1613
- if (oldKeyToIdx === undefined) {
1614
- oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);
1615
- }
1616
-
1617
- idxInOld = oldKeyToIdx[newStartVnode.key];
1618
-
1619
- if (isUndef(idxInOld)) {
1620
- // New element
1621
- newStartVnode.hook.create(newStartVnode);
1622
- newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
1623
- newStartVnode = newCh[++newStartIdx];
1624
- } else {
1625
- elmToMove = oldCh[idxInOld];
1626
-
1627
- if (isVNode(elmToMove)) {
1628
- if (elmToMove.sel !== newStartVnode.sel) {
1629
- // New element
1630
- newStartVnode.hook.create(newStartVnode);
1631
- newStartVnode.hook.insert(newStartVnode, parentElm, oldStartVnode.elm);
1632
- } else {
1633
- patchVnode(elmToMove, newStartVnode);
1634
- oldCh[idxInOld] = undefined;
1635
- newStartVnode.hook.move(elmToMove, parentElm, oldStartVnode.elm);
1636
- }
1637
- }
1638
-
1639
- newStartVnode = newCh[++newStartIdx];
1640
- }
1641
- }
1642
- }
1643
-
1644
- if (oldStartIdx <= oldEndIdx || newStartIdx <= newEndIdx) {
1645
- if (oldStartIdx > oldEndIdx) {
1646
- // There's some cases in which the sub array of vnodes to be inserted is followed by null(s) and an
1647
- // already processed vnode, in such cases the vnodes to be inserted should be before that processed vnode.
1648
- let i = newEndIdx;
1649
- let n;
1650
-
1651
- do {
1652
- n = newCh[++i];
1653
- } while (!isVNode(n) && i < newChEnd);
1654
-
1655
- before = isVNode(n) ? n.elm : null;
1656
- addVnodes(parentElm, before, newCh, newStartIdx, newEndIdx);
1657
- } else {
1658
- removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);
1659
- }
1660
- }
1661
- }
1662
-
1663
- function updateStaticChildren(parentElm, oldCh, newCh) {
1664
- const oldChLength = oldCh.length;
1665
- const newChLength = newCh.length;
1666
-
1667
- if (oldChLength === 0) {
1668
- // the old list is empty, we can directly insert anything new
1669
- addVnodes(parentElm, null, newCh, 0, newChLength);
1670
- return;
1671
- }
1672
-
1673
- if (newChLength === 0) {
1674
- // the old list is nonempty and the new list is empty so we can directly remove all old nodes
1675
- // this is the case in which the dynamic children of an if-directive should be removed
1676
- removeVnodes(parentElm, oldCh, 0, oldChLength);
1677
- return;
1678
- } // if the old list is not empty, the new list MUST have the same
1679
- // amount of nodes, that's why we call this static children
1680
-
1681
-
1682
- let referenceElm = null;
1683
-
1684
- for (let i = newChLength - 1; i >= 0; i -= 1) {
1685
- const vnode = newCh[i];
1686
- const oldVNode = oldCh[i];
1687
-
1688
- if (vnode !== oldVNode) {
1689
- if (isVNode(oldVNode)) {
1690
- if (isVNode(vnode)) {
1691
- // both vnodes must be equivalent, and se just need to patch them
1692
- patchVnode(oldVNode, vnode);
1693
- referenceElm = vnode.elm;
1694
- } else {
1695
- // removing the old vnode since the new one is null
1696
- oldVNode.hook.remove(oldVNode, parentElm);
1697
- }
1698
- } else if (isVNode(vnode)) {
1699
- // this condition is unnecessary
1700
- vnode.hook.create(vnode); // insert the new node one since the old one is null
1701
-
1702
- vnode.hook.insert(vnode, parentElm, referenceElm);
1703
- referenceElm = vnode.elm;
1704
- }
1705
- }
1706
- }
1707
- }
1708
-
1709
- function patchVnode(oldVnode, vnode) {
1710
- if (oldVnode !== vnode) {
1711
- vnode.elm = oldVnode.elm;
1712
- vnode.hook.update(oldVnode, vnode);
1713
- }
1714
- }
1715
- /*
1716
- * Copyright (c) 2018, salesforce.com, inc.
1717
- * All rights reserved.
1718
- * SPDX-License-Identifier: MIT
1719
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1720
- */
1721
-
1722
-
1723
- function generateDataDescriptor(options) {
1724
- return assign({
1725
- configurable: true,
1726
- enumerable: true,
1727
- writable: true
1728
- }, options);
1729
- }
1730
-
1731
- function generateAccessorDescriptor(options) {
1732
- return assign({
1733
- configurable: true,
1734
- enumerable: true
1735
- }, options);
1736
- }
1737
-
1738
- let isDomMutationAllowed = false;
1739
-
1740
- function unlockDomMutation() {
1741
- if (process.env.NODE_ENV === 'production') {
1742
- // this method should never leak to prod
1743
- throw new ReferenceError();
1744
- }
1745
-
1746
- isDomMutationAllowed = true;
1747
- }
1748
-
1749
- function lockDomMutation() {
1750
- if (process.env.NODE_ENV === 'production') {
1751
- // this method should never leak to prod
1752
- throw new ReferenceError();
1753
- }
1754
-
1755
- isDomMutationAllowed = false;
1756
- }
1757
-
1758
- function logMissingPortalError(name, type) {
1759
- return logError(`The \`${name}\` ${type} is available only on elements that use the \`lwc:dom="manual"\` directive.`);
1760
- }
1761
-
1762
- function patchElementWithRestrictions(elm, options) {
1763
- if (process.env.NODE_ENV === 'production') {
1764
- // this method should never leak to prod
1765
- throw new ReferenceError();
1766
- }
1767
-
1768
- const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML');
1769
- const descriptors = {
1770
- outerHTML: generateAccessorDescriptor({
1771
- get() {
1772
- return originalOuterHTMLDescriptor.get.call(this);
1773
- },
1774
-
1775
- set(_value) {
1776
- throw new TypeError(`Invalid attempt to set outerHTML on Element.`);
1777
- }
1778
-
1779
- })
1780
- }; // Apply extra restriction related to DOM manipulation if the element is not a portal.
1781
-
1782
- if (!options.isLight && !options.isPortal) {
1783
- const {
1784
- appendChild,
1785
- insertBefore,
1786
- removeChild,
1787
- replaceChild
1788
- } = elm;
1789
- const originalNodeValueDescriptor = getPropertyDescriptor(elm, 'nodeValue');
1790
- const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML');
1791
- const originalTextContentDescriptor = getPropertyDescriptor(elm, 'textContent');
1792
- assign(descriptors, {
1793
- appendChild: generateDataDescriptor({
1794
- value(aChild) {
1795
- logMissingPortalError('appendChild', 'method');
1796
- return appendChild.call(this, aChild);
1797
- }
1798
-
1799
- }),
1800
- insertBefore: generateDataDescriptor({
1801
- value(newNode, referenceNode) {
1802
- if (!isDomMutationAllowed) {
1803
- logMissingPortalError('insertBefore', 'method');
1804
- }
1805
-
1806
- return insertBefore.call(this, newNode, referenceNode);
1807
- }
1808
-
1809
- }),
1810
- removeChild: generateDataDescriptor({
1811
- value(aChild) {
1812
- if (!isDomMutationAllowed) {
1813
- logMissingPortalError('removeChild', 'method');
1814
- }
1815
-
1816
- return removeChild.call(this, aChild);
1817
- }
1818
-
1819
- }),
1820
- replaceChild: generateDataDescriptor({
1821
- value(newChild, oldChild) {
1822
- logMissingPortalError('replaceChild', 'method');
1823
- return replaceChild.call(this, newChild, oldChild);
1824
- }
1825
-
1826
- }),
1827
- nodeValue: generateAccessorDescriptor({
1828
- get() {
1829
- return originalNodeValueDescriptor.get.call(this);
1830
- },
1831
-
1832
- set(value) {
1833
- if (!isDomMutationAllowed) {
1834
- logMissingPortalError('nodeValue', 'property');
1835
- }
1836
-
1837
- originalNodeValueDescriptor.set.call(this, value);
1838
- }
1839
-
1840
- }),
1841
- textContent: generateAccessorDescriptor({
1842
- get() {
1843
- return originalTextContentDescriptor.get.call(this);
1844
- },
1845
-
1846
- set(value) {
1847
- logMissingPortalError('textContent', 'property');
1848
- originalTextContentDescriptor.set.call(this, value);
1849
- }
1850
-
1851
- }),
1852
- innerHTML: generateAccessorDescriptor({
1853
- get() {
1854
- return originalInnerHTMLDescriptor.get.call(this);
1855
- },
1856
-
1857
- set(value) {
1858
- logMissingPortalError('innerHTML', 'property');
1859
- return originalInnerHTMLDescriptor.set.call(this, value);
1860
- }
1861
-
1862
- })
1863
- });
1864
- }
1865
-
1866
- defineProperties(elm, descriptors);
1867
- }
1868
-
1869
- function getShadowRootRestrictionsDescriptors(sr) {
1870
- if (process.env.NODE_ENV === 'production') {
1871
- // this method should never leak to prod
1872
- throw new ReferenceError();
1873
- } // Disallowing properties in dev mode only to avoid people doing the wrong
1874
- // thing when using the real shadow root, because if that's the case,
1875
- // the component will not work when running with synthetic shadow.
1876
-
1877
-
1878
- const originalAddEventListener = sr.addEventListener;
1879
- const originalInnerHTMLDescriptor = getPropertyDescriptor(sr, 'innerHTML');
1880
- const originalTextContentDescriptor = getPropertyDescriptor(sr, 'textContent');
1881
- return {
1882
- innerHTML: generateAccessorDescriptor({
1883
- get() {
1884
- return originalInnerHTMLDescriptor.get.call(this);
1885
- },
1886
-
1887
- set(_value) {
1888
- throw new TypeError(`Invalid attempt to set innerHTML on ShadowRoot.`);
1889
- }
1890
-
1891
- }),
1892
- textContent: generateAccessorDescriptor({
1893
- get() {
1894
- return originalTextContentDescriptor.get.call(this);
1895
- },
1896
-
1897
- set(_value) {
1898
- throw new TypeError(`Invalid attempt to set textContent on ShadowRoot.`);
1899
- }
1900
-
1901
- }),
1902
- addEventListener: generateDataDescriptor({
1903
- value(type, listener, options) {
1904
- // TODO [#420]: this is triggered when the component author attempts to add a listener
1905
- // programmatically into its Component's shadow root
1906
- if (!isUndefined$1(options)) {
1907
- logError('The `addEventListener` method on ShadowRoot does not support any options.', getAssociatedVMIfPresent(this));
1908
- } // Typescript does not like it when you treat the `arguments` object as an array
1909
- // @ts-ignore type-mismatch
1910
-
1911
-
1912
- return originalAddEventListener.apply(this, arguments);
1913
- }
1914
-
1915
- })
1916
- };
1917
- } // Custom Elements Restrictions:
1918
- // -----------------------------
1919
-
1920
-
1921
- function getCustomElementRestrictionsDescriptors(elm) {
1922
- if (process.env.NODE_ENV === 'production') {
1923
- // this method should never leak to prod
1924
- throw new ReferenceError();
1925
- }
1926
-
1927
- const originalAddEventListener = elm.addEventListener;
1928
- const originalInnerHTMLDescriptor = getPropertyDescriptor(elm, 'innerHTML');
1929
- const originalOuterHTMLDescriptor = getPropertyDescriptor(elm, 'outerHTML');
1930
- const originalTextContentDescriptor = getPropertyDescriptor(elm, 'textContent');
1931
- return {
1932
- innerHTML: generateAccessorDescriptor({
1933
- get() {
1934
- return originalInnerHTMLDescriptor.get.call(this);
1935
- },
1936
-
1937
- set(_value) {
1938
- throw new TypeError(`Invalid attempt to set innerHTML on HTMLElement.`);
1939
- }
1940
-
1941
- }),
1942
- outerHTML: generateAccessorDescriptor({
1943
- get() {
1944
- return originalOuterHTMLDescriptor.get.call(this);
1945
- },
1946
-
1947
- set(_value) {
1948
- throw new TypeError(`Invalid attempt to set outerHTML on HTMLElement.`);
1949
- }
1950
-
1951
- }),
1952
- textContent: generateAccessorDescriptor({
1953
- get() {
1954
- return originalTextContentDescriptor.get.call(this);
1955
- },
1956
-
1957
- set(_value) {
1958
- throw new TypeError(`Invalid attempt to set textContent on HTMLElement.`);
1959
- }
1960
-
1961
- }),
1962
- addEventListener: generateDataDescriptor({
1963
- value(type, listener, options) {
1964
- // TODO [#420]: this is triggered when the component author attempts to add a listener
1965
- // programmatically into a lighting element node
1966
- if (!isUndefined$1(options)) {
1967
- logError('The `addEventListener` method in `LightningElement` does not support any options.', getAssociatedVMIfPresent(this));
1968
- } // Typescript does not like it when you treat the `arguments` object as an array
1969
- // @ts-ignore type-mismatch
1970
-
1971
-
1972
- return originalAddEventListener.apply(this, arguments);
1973
- }
1974
-
1975
- })
1976
- };
1977
- }
1978
-
1979
- function getComponentRestrictionsDescriptors() {
1980
- if (process.env.NODE_ENV === 'production') {
1981
- // this method should never leak to prod
1982
- throw new ReferenceError();
1983
- }
1984
-
1985
- return {
1986
- tagName: generateAccessorDescriptor({
1987
- get() {
1988
- throw new Error(`Usage of property \`tagName\` is disallowed because the component itself does` + ` not know which tagName will be used to create the element, therefore writing` + ` code that check for that value is error prone.`);
1989
- },
1990
-
1991
- configurable: true,
1992
- enumerable: false // no enumerable properties on component
1993
-
1994
- })
1995
- };
1996
- }
1997
-
1998
- function getLightningElementPrototypeRestrictionsDescriptors(proto) {
1999
- if (process.env.NODE_ENV === 'production') {
2000
- // this method should never leak to prod
2001
- throw new ReferenceError();
2002
- }
2003
-
2004
- const originalDispatchEvent = proto.dispatchEvent;
2005
- const descriptors = {
2006
- dispatchEvent: generateDataDescriptor({
2007
- value(event) {
2008
- const vm = getAssociatedVM(this);
2009
-
2010
- if (!isNull(event) && isObject(event)) {
2011
- const {
2012
- type
2013
- } = event;
2014
-
2015
- if (!/^[a-z][a-z0-9_]*$/.test(type)) {
2016
- logError(`Invalid event type "${type}" dispatched in element ${getComponentTag(vm)}.` + ` Event name must start with a lowercase letter and followed only lowercase` + ` letters, numbers, and underscores`, vm);
2017
- }
2018
- } // Typescript does not like it when you treat the `arguments` object as an array
2019
- // @ts-ignore type-mismatch
2020
-
2021
-
2022
- return originalDispatchEvent.apply(this, arguments);
2023
- }
2024
-
2025
- })
2026
- };
2027
- forEach.call(getOwnPropertyNames$1(globalHTMLProperties), propName => {
2028
- if (propName in proto) {
2029
- return; // no need to redefine something that we are already exposing
2030
- }
2031
-
2032
- descriptors[propName] = generateAccessorDescriptor({
2033
- get() {
2034
- const {
2035
- error,
2036
- attribute
2037
- } = globalHTMLProperties[propName];
2038
- const msg = [];
2039
- msg.push(`Accessing the global HTML property "${propName}" is disabled.`);
2040
-
2041
- if (error) {
2042
- msg.push(error);
2043
- } else if (attribute) {
2044
- msg.push(`Instead access it via \`this.getAttribute("${attribute}")\`.`);
2045
- }
2046
-
2047
- logError(msg.join('\n'), getAssociatedVM(this));
2048
- },
2049
-
2050
- set() {
2051
- const {
2052
- readOnly
2053
- } = globalHTMLProperties[propName];
2054
-
2055
- if (readOnly) {
2056
- logError(`The global HTML property \`${propName}\` is read-only.`, getAssociatedVM(this));
2057
- }
2058
- }
2059
-
2060
- });
2061
- });
2062
- return descriptors;
2063
- } // This routine will prevent access to certain properties on a shadow root instance to guarantee
2064
- // that all components will work fine in IE11 and other browsers without shadow dom support.
2065
-
2066
-
2067
- function patchShadowRootWithRestrictions(sr) {
2068
- defineProperties(sr, getShadowRootRestrictionsDescriptors(sr));
2069
- }
2070
-
2071
- function patchCustomElementWithRestrictions(elm) {
2072
- const restrictionsDescriptors = getCustomElementRestrictionsDescriptors(elm);
2073
- const elmProto = getPrototypeOf$1(elm);
2074
- setPrototypeOf(elm, create(elmProto, restrictionsDescriptors));
2075
- }
2076
-
2077
- function patchComponentWithRestrictions(cmp) {
2078
- defineProperties(cmp, getComponentRestrictionsDescriptors());
2079
- }
2080
-
2081
- function patchLightningElementPrototypeWithRestrictions(proto) {
2082
- defineProperties(proto, getLightningElementPrototypeRestrictionsDescriptors(proto));
2083
- }
2084
- /*
2085
- * Copyright (c) 2018, salesforce.com, inc.
2086
- * All rights reserved.
2087
- * SPDX-License-Identifier: MIT
2088
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2089
- */
2090
- // This is a temporary workaround to get the @lwc/engine-server to evaluate in node without having
2091
- // to inject at runtime.
2092
-
2093
-
2094
- const HTMLElementConstructor$1 = typeof HTMLElement !== 'undefined' ? HTMLElement : function () {};
2095
- const HTMLElementPrototype = HTMLElementConstructor$1.prototype;
2096
- /*
2097
- * Copyright (c) 2018, salesforce.com, inc.
2098
- * All rights reserved.
2099
- * SPDX-License-Identifier: MIT
2100
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
2101
- */
2102
-
2103
- /**
2104
- * This is a descriptor map that contains
2105
- * all standard properties that a Custom Element can support (including AOM properties), which
2106
- * determines what kind of capabilities the Base HTML Element and
2107
- * Base Lightning Element should support.
2108
- */
2109
-
2110
- const HTMLElementOriginalDescriptors = create(null);
2111
- forEach.call(keys(AriaPropNameToAttrNameMap), propName => {
2112
- // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
2113
- // in IE11, some properties are on Element.prototype instead of HTMLElement, just to be sure.
2114
- const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
2115
-
2116
- if (!isUndefined$1(descriptor)) {
2117
- HTMLElementOriginalDescriptors[propName] = descriptor;
2118
- }
2119
- });
2120
- forEach.call(defaultDefHTMLPropertyNames, propName => {
2121
- // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because
2122
- // in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into
2123
- // this category, so, better to be sure.
2124
- const descriptor = getPropertyDescriptor(HTMLElementPrototype, propName);
2125
-
2126
- if (!isUndefined$1(descriptor)) {
2127
- HTMLElementOriginalDescriptors[propName] = descriptor;
2128
- }
2129
- });
2130
- /**
2131
- * Copyright (C) 2017 salesforce.com, inc.
2132
- */
1752
+ });
1753
+ /**
1754
+ * Copyright (C) 2017 salesforce.com, inc.
1755
+ */
2133
1756
 
2134
1757
  const {
2135
1758
  isArray
@@ -3309,97 +2932,333 @@
3309
2932
  warnIfInvokedDuringConstruction(vm, childGetter);
3310
2933
  }
3311
2934
 
3312
- return getChildGetter(childGetter)(elm);
3313
- },
3314
-
3315
- configurable: true,
3316
- enumerable: true
3317
- };
3318
- }
2935
+ return getChildGetter(childGetter)(elm);
2936
+ },
2937
+
2938
+ configurable: true,
2939
+ enumerable: true
2940
+ };
2941
+ }
2942
+
2943
+ const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
2944
+
2945
+ function getQueryMethod(methodName) {
2946
+ switch (methodName) {
2947
+ case 'getElementsByClassName':
2948
+ return getElementsByClassName$1;
2949
+
2950
+ case 'getElementsByTagName':
2951
+ return getElementsByTagName$1;
2952
+
2953
+ case 'querySelector':
2954
+ return querySelector$1;
2955
+
2956
+ case 'querySelectorAll':
2957
+ return querySelectorAll$1;
2958
+ }
2959
+ } // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
2960
+
2961
+
2962
+ for (const queryMethod of queryMethods) {
2963
+ queryAndChildGetterDescriptors[queryMethod] = {
2964
+ value(arg) {
2965
+ const vm = getAssociatedVM(this);
2966
+ const {
2967
+ elm
2968
+ } = vm;
2969
+
2970
+ if (process.env.NODE_ENV !== 'production') {
2971
+ warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
2972
+ }
2973
+
2974
+ return getQueryMethod(queryMethod)(elm, arg);
2975
+ },
2976
+
2977
+ configurable: true,
2978
+ enumerable: true,
2979
+ writable: true
2980
+ };
2981
+ }
2982
+
2983
+ defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
2984
+ const lightningBasedDescriptors = create(null);
2985
+
2986
+ for (const propName in HTMLElementOriginalDescriptors) {
2987
+ lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
2988
+ }
2989
+
2990
+ defineProperties(LightningElement.prototype, lightningBasedDescriptors);
2991
+ defineProperty(LightningElement, 'CustomElementConstructor', {
2992
+ get() {
2993
+ // If required, a runtime-specific implementation must be defined.
2994
+ throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
2995
+ },
2996
+
2997
+ configurable: true
2998
+ });
2999
+
3000
+ if (process.env.NODE_ENV !== 'production') {
3001
+ patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
3002
+ }
3003
+ /*
3004
+ * Copyright (c) 2018, salesforce.com, inc.
3005
+ * All rights reserved.
3006
+ * SPDX-License-Identifier: MIT
3007
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3008
+ */
3009
+
3010
+ /**
3011
+ * @wire decorator to wire fields and methods to a wire adapter in
3012
+ * LWC Components. This function implements the internals of this
3013
+ * decorator.
3014
+ */
3015
+
3016
+
3017
+ function wire(_adapter, _config) {
3018
+ if (process.env.NODE_ENV !== 'production') {
3019
+ assert.fail('@wire(adapter, config?) may only be used as a decorator.');
3020
+ }
3021
+
3022
+ throw new Error();
3023
+ }
3024
+
3025
+ function internalWireFieldDecorator(key) {
3026
+ return {
3027
+ get() {
3028
+ const vm = getAssociatedVM(this);
3029
+ componentValueObserved(vm, key);
3030
+ return vm.cmpFields[key];
3031
+ },
3032
+
3033
+ set(value) {
3034
+ const vm = getAssociatedVM(this);
3035
+ /**
3036
+ * Reactivity for wired fields is provided in wiring.
3037
+ * We intentionally add reactivity here since this is just
3038
+ * letting the author to do the wrong thing, but it will keep our
3039
+ * system to be backward compatible.
3040
+ */
3041
+
3042
+ if (value !== vm.cmpFields[key]) {
3043
+ vm.cmpFields[key] = value;
3044
+ componentValueMutated(vm, key);
3045
+ }
3046
+ },
3047
+
3048
+ enumerable: true,
3049
+ configurable: true
3050
+ };
3051
+ }
3052
+ /*
3053
+ * Copyright (c) 2018, salesforce.com, inc.
3054
+ * All rights reserved.
3055
+ * SPDX-License-Identifier: MIT
3056
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3057
+ */
3058
+
3059
+
3060
+ function track(target) {
3061
+ if (arguments.length === 1) {
3062
+ return reactiveMembrane.getProxy(target);
3063
+ }
3064
+
3065
+ if (process.env.NODE_ENV !== 'production') {
3066
+ assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
3067
+ }
3068
+
3069
+ throw new Error();
3070
+ }
3071
+
3072
+ function internalTrackDecorator(key) {
3073
+ return {
3074
+ get() {
3075
+ const vm = getAssociatedVM(this);
3076
+ componentValueObserved(vm, key);
3077
+ return vm.cmpFields[key];
3078
+ },
3079
+
3080
+ set(newValue) {
3081
+ const vm = getAssociatedVM(this);
3082
+
3083
+ if (process.env.NODE_ENV !== 'production') {
3084
+ const vmBeingRendered = getVMBeingRendered();
3085
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
3086
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
3087
+ }
3088
+
3089
+ const reactiveOrAnyValue = reactiveMembrane.getProxy(newValue);
3090
+
3091
+ if (reactiveOrAnyValue !== vm.cmpFields[key]) {
3092
+ vm.cmpFields[key] = reactiveOrAnyValue;
3093
+ componentValueMutated(vm, key);
3094
+ }
3095
+ },
3096
+
3097
+ enumerable: true,
3098
+ configurable: true
3099
+ };
3100
+ }
3101
+ /*
3102
+ * Copyright (c) 2018, salesforce.com, inc.
3103
+ * All rights reserved.
3104
+ * SPDX-License-Identifier: MIT
3105
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3106
+ */
3107
+
3108
+
3109
+ function api$1() {
3110
+ if (process.env.NODE_ENV !== 'production') {
3111
+ assert.fail(`@api decorator can only be used as a decorator function.`);
3112
+ }
3113
+
3114
+ throw new Error();
3115
+ }
3116
+
3117
+ function createPublicPropertyDescriptor(key) {
3118
+ return {
3119
+ get() {
3120
+ const vm = getAssociatedVM(this);
3121
+
3122
+ if (isBeingConstructed(vm)) {
3123
+ if (process.env.NODE_ENV !== 'production') {
3124
+ logError(`Can’t read the value of property \`${toString$1(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
3125
+ }
3126
+
3127
+ return;
3128
+ }
3129
+
3130
+ componentValueObserved(vm, key);
3131
+ return vm.cmpProps[key];
3132
+ },
3133
+
3134
+ set(newValue) {
3135
+ const vm = getAssociatedVM(this);
3136
+
3137
+ if (process.env.NODE_ENV !== 'production') {
3138
+ const vmBeingRendered = getVMBeingRendered();
3139
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
3140
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
3141
+ }
3142
+
3143
+ vm.cmpProps[key] = newValue;
3144
+ componentValueMutated(vm, key);
3145
+ },
3146
+
3147
+ enumerable: true,
3148
+ configurable: true
3149
+ };
3150
+ }
3151
+
3152
+ class AccessorReactiveObserver extends ReactiveObserver {
3153
+ constructor(vm, set) {
3154
+ super(() => {
3155
+ if (isFalse(this.debouncing)) {
3156
+ this.debouncing = true;
3157
+ addCallbackToNextTick(() => {
3158
+ if (isTrue(this.debouncing)) {
3159
+ const {
3160
+ value
3161
+ } = this;
3162
+ const {
3163
+ isDirty: dirtyStateBeforeSetterCall,
3164
+ component,
3165
+ idx
3166
+ } = vm;
3167
+ set.call(component, value); // de-bouncing after the call to the original setter to prevent
3168
+ // infinity loop if the setter itself is mutating things that
3169
+ // were accessed during the previous invocation.
3170
+
3171
+ this.debouncing = false;
3172
+
3173
+ if (isTrue(vm.isDirty) && isFalse(dirtyStateBeforeSetterCall) && idx > 0) {
3174
+ // immediate rehydration due to a setter driven mutation, otherwise
3175
+ // the component will get rendered on the second tick, which it is not
3176
+ // desirable.
3177
+ rerenderVM(vm);
3178
+ }
3179
+ }
3180
+ });
3181
+ }
3182
+ });
3183
+ this.debouncing = false;
3184
+ }
3185
+
3186
+ reset(value) {
3187
+ super.reset();
3188
+ this.debouncing = false;
3319
3189
 
3320
- const queryMethods = ['getElementsByClassName', 'getElementsByTagName', 'querySelector', 'querySelectorAll'];
3190
+ if (arguments.length > 0) {
3191
+ this.value = value;
3192
+ }
3193
+ }
3321
3194
 
3322
- function getQueryMethod(methodName) {
3323
- switch (methodName) {
3324
- case 'getElementsByClassName':
3325
- return getElementsByClassName$1;
3195
+ }
3326
3196
 
3327
- case 'getElementsByTagName':
3328
- return getElementsByTagName$1;
3197
+ function createPublicAccessorDescriptor(key, descriptor) {
3198
+ const {
3199
+ get,
3200
+ set,
3201
+ enumerable,
3202
+ configurable
3203
+ } = descriptor;
3329
3204
 
3330
- case 'querySelector':
3331
- return querySelector$1;
3205
+ if (!isFunction$1(get)) {
3206
+ if (process.env.NODE_ENV !== 'production') {
3207
+ assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
3208
+ }
3332
3209
 
3333
- case 'querySelectorAll':
3334
- return querySelectorAll$1;
3210
+ throw new Error();
3335
3211
  }
3336
- } // Generic passthrough for query APIs on HTMLElement to the relevant Renderer APIs
3337
-
3338
-
3339
- for (const queryMethod of queryMethods) {
3340
- queryAndChildGetterDescriptors[queryMethod] = {
3341
- value(arg) {
3342
- const vm = getAssociatedVM(this);
3343
- const {
3344
- elm
3345
- } = vm;
3346
3212
 
3213
+ return {
3214
+ get() {
3347
3215
  if (process.env.NODE_ENV !== 'production') {
3348
- warnIfInvokedDuringConstruction(vm, `${queryMethod}()`);
3216
+ // Assert that the this value is an actual Component with an associated VM.
3217
+ getAssociatedVM(this);
3349
3218
  }
3350
3219
 
3351
- return getQueryMethod(queryMethod)(elm, arg);
3220
+ return get.call(this);
3352
3221
  },
3353
3222
 
3354
- configurable: true,
3355
- enumerable: true,
3356
- writable: true
3357
- };
3358
- }
3359
-
3360
- defineProperties(LightningElement.prototype, queryAndChildGetterDescriptors);
3361
- const lightningBasedDescriptors = create(null);
3362
-
3363
- for (const propName in HTMLElementOriginalDescriptors) {
3364
- lightningBasedDescriptors[propName] = createBridgeToElementDescriptor(propName, HTMLElementOriginalDescriptors[propName]);
3365
- }
3366
-
3367
- defineProperties(LightningElement.prototype, lightningBasedDescriptors);
3368
- defineProperty(LightningElement, 'CustomElementConstructor', {
3369
- get() {
3370
- // If required, a runtime-specific implementation must be defined.
3371
- throw new ReferenceError('The current runtime does not support CustomElementConstructor.');
3372
- },
3223
+ set(newValue) {
3224
+ const vm = getAssociatedVM(this);
3373
3225
 
3374
- configurable: true
3375
- });
3226
+ if (process.env.NODE_ENV !== 'production') {
3227
+ const vmBeingRendered = getVMBeingRendered();
3228
+ assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
3229
+ assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
3230
+ }
3376
3231
 
3377
- if (process.env.NODE_ENV !== 'production') {
3378
- patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
3379
- }
3380
- /*
3381
- * Copyright (c) 2018, salesforce.com, inc.
3382
- * All rights reserved.
3383
- * SPDX-License-Identifier: MIT
3384
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3385
- */
3232
+ if (set) {
3233
+ if (runtimeFlags.ENABLE_REACTIVE_SETTER) {
3234
+ let ro = vm.oar[key];
3386
3235
 
3387
- /**
3388
- * @wire decorator to wire fields and methods to a wire adapter in
3389
- * LWC Components. This function implements the internals of this
3390
- * decorator.
3391
- */
3236
+ if (isUndefined$1(ro)) {
3237
+ ro = vm.oar[key] = new AccessorReactiveObserver(vm, set);
3238
+ } // every time we invoke this setter from outside (through this wrapper setter)
3239
+ // we should reset the value and then debounce just in case there is a pending
3240
+ // invocation the next tick that is not longer relevant since the value is changing
3241
+ // from outside.
3392
3242
 
3393
3243
 
3394
- function wire(_adapter, _config) {
3395
- if (process.env.NODE_ENV !== 'production') {
3396
- assert.fail('@wire(adapter, config?) may only be used as a decorator.');
3397
- }
3244
+ ro.reset(newValue);
3245
+ ro.observe(() => {
3246
+ set.call(this, newValue);
3247
+ });
3248
+ } else {
3249
+ set.call(this, newValue);
3250
+ }
3251
+ } else if (process.env.NODE_ENV !== 'production') {
3252
+ assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
3253
+ }
3254
+ },
3398
3255
 
3399
- throw new Error();
3256
+ enumerable,
3257
+ configurable
3258
+ };
3400
3259
  }
3401
3260
 
3402
- function internalWireFieldDecorator(key) {
3261
+ function createObservedFieldPropertyDescriptor(key) {
3403
3262
  return {
3404
3263
  get() {
3405
3264
  const vm = getAssociatedVM(this);
@@ -3407,17 +3266,11 @@
3407
3266
  return vm.cmpFields[key];
3408
3267
  },
3409
3268
 
3410
- set(value) {
3269
+ set(newValue) {
3411
3270
  const vm = getAssociatedVM(this);
3412
- /**
3413
- * Reactivity for wired fields is provided in wiring.
3414
- * We intentionally add reactivity here since this is just
3415
- * letting the author to do the wrong thing, but it will keep our
3416
- * system to be backward compatible.
3417
- */
3418
3271
 
3419
- if (value !== vm.cmpFields[key]) {
3420
- vm.cmpFields[key] = value;
3272
+ if (newValue !== vm.cmpFields[key]) {
3273
+ vm.cmpFields[key] = newValue;
3421
3274
  componentValueMutated(vm, key);
3422
3275
  }
3423
3276
  },
@@ -3434,227 +3287,299 @@
3434
3287
  */
3435
3288
 
3436
3289
 
3437
- function track(target) {
3438
- if (arguments.length === 1) {
3439
- return reactiveMembrane.getProxy(target);
3440
- }
3290
+ function getClassDescriptorType(descriptor) {
3291
+ if (isFunction$1(descriptor.value)) {
3292
+ return "method"
3293
+ /* Method */
3294
+ ;
3295
+ } else if (isFunction$1(descriptor.set) || isFunction$1(descriptor.get)) {
3296
+ return "accessor"
3297
+ /* Accessor */
3298
+ ;
3299
+ } else {
3300
+ return "field"
3301
+ /* Field */
3302
+ ;
3303
+ }
3304
+ }
3305
+
3306
+ function validateObservedField(Ctor, fieldName, descriptor) {
3307
+ if (!isUndefined$1(descriptor)) {
3308
+ const type = getClassDescriptorType(descriptor);
3309
+ const message = `Invalid observed ${fieldName} field. Found a duplicate ${type} with the same name.`; // [W-9927596] Ideally we always throw an error when detecting duplicate observed field.
3310
+ // This branch is only here for backward compatibility reasons.
3311
+
3312
+ if (type === "accessor"
3313
+ /* Accessor */
3314
+ ) {
3315
+ logError(message);
3316
+ } else {
3317
+ assert.fail(message);
3318
+ }
3319
+ }
3320
+ }
3321
+
3322
+ function validateFieldDecoratedWithTrack(Ctor, fieldName, descriptor) {
3323
+ if (!isUndefined$1(descriptor)) {
3324
+ const type = getClassDescriptorType(descriptor);
3325
+ assert.fail(`Invalid @track ${fieldName} field. Found a duplicate ${type} with the same name.`);
3326
+ }
3327
+ }
3328
+
3329
+ function validateFieldDecoratedWithWire(Ctor, fieldName, descriptor) {
3330
+ if (!isUndefined$1(descriptor)) {
3331
+ const type = getClassDescriptorType(descriptor);
3332
+ assert.fail(`Invalid @wire ${fieldName} field. Found a duplicate ${type} with the same name.`);
3333
+ }
3334
+ }
3335
+
3336
+ function validateMethodDecoratedWithWire(Ctor, methodName, descriptor) {
3337
+ if (isUndefined$1(descriptor) || !isFunction$1(descriptor.value) || isFalse(descriptor.writable)) {
3338
+ assert.fail(`Invalid @wire ${methodName} method.`);
3339
+ }
3340
+ }
3341
+
3342
+ function validateFieldDecoratedWithApi(Ctor, fieldName, descriptor) {
3343
+ if (!isUndefined$1(descriptor)) {
3344
+ const type = getClassDescriptorType(descriptor);
3345
+ const message = `Invalid @api ${fieldName} field. Found a duplicate ${type} with the same name.`; // [W-9927596] Ideally we always throw an error when detecting duplicate public properties.
3346
+ // This branch is only here for backward compatibility reasons.
3347
+
3348
+ if (type === "accessor"
3349
+ /* Accessor */
3350
+ ) {
3351
+ logError(message);
3352
+ } else {
3353
+ assert.fail(message);
3354
+ }
3355
+ }
3356
+ }
3357
+
3358
+ function validateAccessorDecoratedWithApi(Ctor, fieldName, descriptor) {
3359
+ if (isUndefined$1(descriptor)) {
3360
+ assert.fail(`Invalid @api get ${fieldName} accessor.`);
3361
+ } else if (isFunction$1(descriptor.set)) {
3362
+ assert.isTrue(isFunction$1(descriptor.get), `Missing getter for property ${fieldName} decorated with @api in ${Ctor}. You cannot have a setter without the corresponding getter.`);
3363
+ } else if (!isFunction$1(descriptor.get)) {
3364
+ assert.fail(`Missing @api get ${fieldName} accessor.`);
3365
+ }
3366
+ }
3367
+
3368
+ function validateMethodDecoratedWithApi(Ctor, methodName, descriptor) {
3369
+ if (isUndefined$1(descriptor) || !isFunction$1(descriptor.value) || isFalse(descriptor.writable)) {
3370
+ assert.fail(`Invalid @api ${methodName} method.`);
3371
+ }
3372
+ }
3373
+ /**
3374
+ * INTERNAL: This function can only be invoked by compiled code. The compiler
3375
+ * will prevent this function from being imported by user-land code.
3376
+ */
3377
+
3378
+
3379
+ function registerDecorators(Ctor, meta) {
3380
+ const proto = Ctor.prototype;
3381
+ const {
3382
+ publicProps,
3383
+ publicMethods,
3384
+ wire,
3385
+ track,
3386
+ fields
3387
+ } = meta;
3388
+ const apiMethods = create(null);
3389
+ const apiFields = create(null);
3390
+ const wiredMethods = create(null);
3391
+ const wiredFields = create(null);
3392
+ const observedFields = create(null);
3393
+ const apiFieldsConfig = create(null);
3394
+ let descriptor;
3395
+
3396
+ if (!isUndefined$1(publicProps)) {
3397
+ for (const fieldName in publicProps) {
3398
+ const propConfig = publicProps[fieldName];
3399
+ apiFieldsConfig[fieldName] = propConfig.config;
3400
+ descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
3401
+
3402
+ if (propConfig.config > 0) {
3403
+ // accessor declaration
3404
+ if (process.env.NODE_ENV !== 'production') {
3405
+ validateAccessorDecoratedWithApi(Ctor, fieldName, descriptor);
3406
+ }
3407
+
3408
+ if (isUndefined$1(descriptor)) {
3409
+ throw new Error();
3410
+ }
3441
3411
 
3442
- if (process.env.NODE_ENV !== 'production') {
3443
- assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
3444
- }
3412
+ descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
3413
+ } else {
3414
+ // field declaration
3415
+ if (process.env.NODE_ENV !== 'production') {
3416
+ validateFieldDecoratedWithApi(Ctor, fieldName, descriptor);
3417
+ } // [W-9927596] If a component has both a public property and a private setter/getter
3418
+ // with the same name, the property is defined as a public accessor. This branch is
3419
+ // only here for backward compatibility reasons.
3445
3420
 
3446
- throw new Error();
3447
- }
3448
3421
 
3449
- function internalTrackDecorator(key) {
3450
- return {
3451
- get() {
3452
- const vm = getAssociatedVM(this);
3453
- componentValueObserved(vm, key);
3454
- return vm.cmpFields[key];
3455
- },
3422
+ if (!isUndefined$1(descriptor) && !isUndefined$1(descriptor.get)) {
3423
+ descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
3424
+ } else {
3425
+ descriptor = createPublicPropertyDescriptor(fieldName);
3426
+ }
3427
+ }
3456
3428
 
3457
- set(newValue) {
3458
- const vm = getAssociatedVM(this);
3429
+ apiFields[fieldName] = descriptor;
3430
+ defineProperty(proto, fieldName, descriptor);
3431
+ }
3432
+ }
3433
+
3434
+ if (!isUndefined$1(publicMethods)) {
3435
+ forEach.call(publicMethods, methodName => {
3436
+ descriptor = getOwnPropertyDescriptor$1(proto, methodName);
3459
3437
 
3460
3438
  if (process.env.NODE_ENV !== 'production') {
3461
- const vmBeingRendered = getVMBeingRendered();
3462
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
3463
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
3439
+ validateMethodDecoratedWithApi(Ctor, methodName, descriptor);
3464
3440
  }
3465
3441
 
3466
- const reactiveOrAnyValue = reactiveMembrane.getProxy(newValue);
3467
-
3468
- if (reactiveOrAnyValue !== vm.cmpFields[key]) {
3469
- vm.cmpFields[key] = reactiveOrAnyValue;
3470
- componentValueMutated(vm, key);
3442
+ if (isUndefined$1(descriptor)) {
3443
+ throw new Error();
3471
3444
  }
3472
- },
3473
-
3474
- enumerable: true,
3475
- configurable: true
3476
- };
3477
- }
3478
- /*
3479
- * Copyright (c) 2018, salesforce.com, inc.
3480
- * All rights reserved.
3481
- * SPDX-License-Identifier: MIT
3482
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3483
- */
3484
3445
 
3485
-
3486
- function api$1() {
3487
- if (process.env.NODE_ENV !== 'production') {
3488
- assert.fail(`@api decorator can only be used as a decorator function.`);
3446
+ apiMethods[methodName] = descriptor;
3447
+ });
3489
3448
  }
3490
3449
 
3491
- throw new Error();
3492
- }
3450
+ if (!isUndefined$1(wire)) {
3451
+ for (const fieldOrMethodName in wire) {
3452
+ const {
3453
+ adapter,
3454
+ method,
3455
+ config: configCallback,
3456
+ dynamic = []
3457
+ } = wire[fieldOrMethodName];
3458
+ descriptor = getOwnPropertyDescriptor$1(proto, fieldOrMethodName);
3493
3459
 
3494
- function createPublicPropertyDescriptor(key) {
3495
- return {
3496
- get() {
3497
- const vm = getAssociatedVM(this);
3460
+ if (method === 1) {
3461
+ if (process.env.NODE_ENV !== 'production') {
3462
+ assert.isTrue(adapter, `@wire on method "${fieldOrMethodName}": adapter id must be truthy.`);
3463
+ validateMethodDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
3464
+ }
3498
3465
 
3499
- if (isBeingConstructed(vm)) {
3466
+ if (isUndefined$1(descriptor)) {
3467
+ throw new Error();
3468
+ }
3469
+
3470
+ wiredMethods[fieldOrMethodName] = descriptor;
3471
+ storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic);
3472
+ } else {
3500
3473
  if (process.env.NODE_ENV !== 'production') {
3501
- logError(`Can’t read the value of property \`${toString$1(key)}\` from the constructor because the owner component hasn’t set the value yet. Instead, use the constructor to set a default value for the property.`, vm);
3474
+ assert.isTrue(adapter, `@wire on field "${fieldOrMethodName}": adapter id must be truthy.`);
3475
+ validateFieldDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
3502
3476
  }
3503
3477
 
3504
- return;
3478
+ descriptor = internalWireFieldDecorator(fieldOrMethodName);
3479
+ wiredFields[fieldOrMethodName] = descriptor;
3480
+ storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic);
3481
+ defineProperty(proto, fieldOrMethodName, descriptor);
3505
3482
  }
3483
+ }
3484
+ }
3506
3485
 
3507
- componentValueObserved(vm, key);
3508
- return vm.cmpProps[key];
3509
- },
3510
-
3511
- set(newValue) {
3512
- const vm = getAssociatedVM(this);
3486
+ if (!isUndefined$1(track)) {
3487
+ for (const fieldName in track) {
3488
+ descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
3513
3489
 
3514
3490
  if (process.env.NODE_ENV !== 'production') {
3515
- const vmBeingRendered = getVMBeingRendered();
3516
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
3517
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
3491
+ validateFieldDecoratedWithTrack(Ctor, fieldName, descriptor);
3518
3492
  }
3519
3493
 
3520
- vm.cmpProps[key] = newValue;
3521
- componentValueMutated(vm, key);
3522
- },
3523
-
3524
- enumerable: true,
3525
- configurable: true
3526
- };
3527
- }
3528
-
3529
- class AccessorReactiveObserver extends ReactiveObserver {
3530
- constructor(vm, set) {
3531
- super(() => {
3532
- if (isFalse(this.debouncing)) {
3533
- this.debouncing = true;
3534
- addCallbackToNextTick(() => {
3535
- if (isTrue(this.debouncing)) {
3536
- const {
3537
- value
3538
- } = this;
3539
- const {
3540
- isDirty: dirtyStateBeforeSetterCall,
3541
- component,
3542
- idx
3543
- } = vm;
3544
- set.call(component, value); // de-bouncing after the call to the original setter to prevent
3545
- // infinity loop if the setter itself is mutating things that
3546
- // were accessed during the previous invocation.
3547
-
3548
- this.debouncing = false;
3549
-
3550
- if (isTrue(vm.isDirty) && isFalse(dirtyStateBeforeSetterCall) && idx > 0) {
3551
- // immediate rehydration due to a setter driven mutation, otherwise
3552
- // the component will get rendered on the second tick, which it is not
3553
- // desirable.
3554
- rerenderVM(vm);
3555
- }
3556
- }
3557
- });
3558
- }
3559
- });
3560
- this.debouncing = false;
3494
+ descriptor = internalTrackDecorator(fieldName);
3495
+ defineProperty(proto, fieldName, descriptor);
3496
+ }
3561
3497
  }
3562
3498
 
3563
- reset(value) {
3564
- super.reset();
3565
- this.debouncing = false;
3499
+ if (!isUndefined$1(fields)) {
3500
+ for (let i = 0, n = fields.length; i < n; i++) {
3501
+ const fieldName = fields[i];
3502
+ descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
3566
3503
 
3567
- if (arguments.length > 0) {
3568
- this.value = value;
3569
- }
3570
- }
3504
+ if (process.env.NODE_ENV !== 'production') {
3505
+ validateObservedField(Ctor, fieldName, descriptor);
3506
+ } // [W-9927596] Only mark a field as observed whenever it isn't a duplicated public nor
3507
+ // tracked property. This is only here for backward compatibility purposes.
3571
3508
 
3572
- }
3573
3509
 
3574
- function createPublicAccessorDescriptor(key, descriptor) {
3575
- const {
3576
- get,
3577
- set,
3578
- enumerable,
3579
- configurable
3580
- } = descriptor;
3510
+ const isDuplicatePublicProp = !isUndefined$1(publicProps) && fieldName in publicProps;
3511
+ const isDuplicateTrackedProp = !isUndefined$1(track) && fieldName in track;
3581
3512
 
3582
- if (!isFunction$1(get)) {
3583
- if (process.env.NODE_ENV !== 'production') {
3584
- assert.invariant(isFunction$1(get), `Invalid compiler output for public accessor ${toString$1(key)} decorated with @api`);
3513
+ if (!isDuplicatePublicProp && !isDuplicateTrackedProp) {
3514
+ observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
3515
+ }
3585
3516
  }
3586
-
3587
- throw new Error();
3588
3517
  }
3589
3518
 
3590
- return {
3591
- get() {
3592
- if (process.env.NODE_ENV !== 'production') {
3593
- // Assert that the this value is an actual Component with an associated VM.
3594
- getAssociatedVM(this);
3595
- }
3519
+ setDecoratorsMeta(Ctor, {
3520
+ apiMethods,
3521
+ apiFields,
3522
+ apiFieldsConfig,
3523
+ wiredMethods,
3524
+ wiredFields,
3525
+ observedFields
3526
+ });
3527
+ return Ctor;
3528
+ }
3596
3529
 
3597
- return get.call(this);
3598
- },
3530
+ const signedDecoratorToMetaMap = new Map();
3599
3531
 
3600
- set(newValue) {
3601
- const vm = getAssociatedVM(this);
3532
+ function setDecoratorsMeta(Ctor, meta) {
3533
+ signedDecoratorToMetaMap.set(Ctor, meta);
3534
+ }
3602
3535
 
3603
- if (process.env.NODE_ENV !== 'production') {
3604
- const vmBeingRendered = getVMBeingRendered();
3605
- assert.invariant(!isInvokingRender, `${vmBeingRendered}.render() method has side effects on the state of ${vm}.${toString$1(key)}`);
3606
- assert.invariant(!isUpdatingTemplate, `Updating the template of ${vmBeingRendered} has side effects on the state of ${vm}.${toString$1(key)}`);
3607
- }
3536
+ const defaultMeta = {
3537
+ apiMethods: EmptyObject,
3538
+ apiFields: EmptyObject,
3539
+ apiFieldsConfig: EmptyObject,
3540
+ wiredMethods: EmptyObject,
3541
+ wiredFields: EmptyObject,
3542
+ observedFields: EmptyObject
3543
+ };
3608
3544
 
3609
- if (set) {
3610
- if (runtimeFlags.ENABLE_REACTIVE_SETTER) {
3611
- let ro = vm.oar[key];
3545
+ function getDecoratorsMeta(Ctor) {
3546
+ const meta = signedDecoratorToMetaMap.get(Ctor);
3547
+ return isUndefined$1(meta) ? defaultMeta : meta;
3548
+ }
3612
3549
 
3613
- if (isUndefined$1(ro)) {
3614
- ro = vm.oar[key] = new AccessorReactiveObserver(vm, set);
3615
- } // every time we invoke this setter from outside (through this wrapper setter)
3616
- // we should reset the value and then debounce just in case there is a pending
3617
- // invocation the next tick that is not longer relevant since the value is changing
3618
- // from outside.
3550
+ const signedTemplateSet = new Set();
3619
3551
 
3552
+ function defaultEmptyTemplate() {
3553
+ return [];
3554
+ }
3620
3555
 
3621
- ro.reset(newValue);
3622
- ro.observe(() => {
3623
- set.call(this, newValue);
3624
- });
3625
- } else {
3626
- set.call(this, newValue);
3627
- }
3628
- } else if (process.env.NODE_ENV !== 'production') {
3629
- assert.fail(`Invalid attempt to set a new value for property ${toString$1(key)} of ${vm} that does not has a setter decorated with @api.`);
3630
- }
3631
- },
3556
+ signedTemplateSet.add(defaultEmptyTemplate);
3632
3557
 
3633
- enumerable,
3634
- configurable
3635
- };
3558
+ function isTemplateRegistered(tpl) {
3559
+ return signedTemplateSet.has(tpl);
3636
3560
  }
3561
+ /**
3562
+ * INTERNAL: This function can only be invoked by compiled code. The compiler
3563
+ * will prevent this function from being imported by userland code.
3564
+ */
3637
3565
 
3638
- function createObservedFieldPropertyDescriptor(key) {
3639
- return {
3640
- get() {
3641
- const vm = getAssociatedVM(this);
3642
- componentValueObserved(vm, key);
3643
- return vm.cmpFields[key];
3644
- },
3645
3566
 
3646
- set(newValue) {
3647
- const vm = getAssociatedVM(this);
3567
+ function registerTemplate(tpl) {
3568
+ signedTemplateSet.add(tpl); // chaining this method as a way to wrap existing
3569
+ // assignment of templates easily, without too much transformation
3648
3570
 
3649
- if (newValue !== vm.cmpFields[key]) {
3650
- vm.cmpFields[key] = newValue;
3651
- componentValueMutated(vm, key);
3652
- }
3653
- },
3571
+ return tpl;
3572
+ }
3573
+ /**
3574
+ * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
3575
+ * libraries to sanitize vulnerable attributes.
3576
+ */
3654
3577
 
3655
- enumerable: true,
3656
- configurable: true
3657
- };
3578
+
3579
+ function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
3580
+ // locker-service patches this function during runtime to sanitize vulnerable attributes. When
3581
+ // ran off-core this function becomes a noop and returns the user authored value.
3582
+ return attrValue;
3658
3583
  }
3659
3584
  /*
3660
3585
  * Copyright (c) 2018, salesforce.com, inc.
@@ -3662,798 +3587,861 @@
3662
3587
  * SPDX-License-Identifier: MIT
3663
3588
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3664
3589
  */
3590
+ // from the element instance, and get the value or set a new value on the component.
3591
+ // This means that across different elements, similar names can get the exact same
3592
+ // descriptor, so we can cache them:
3665
3593
 
3666
3594
 
3667
- function getClassDescriptorType(descriptor) {
3668
- if (isFunction$1(descriptor.value)) {
3669
- return "method"
3670
- /* Method */
3671
- ;
3672
- } else if (isFunction$1(descriptor.set) || isFunction$1(descriptor.get)) {
3673
- return "accessor"
3674
- /* Accessor */
3675
- ;
3676
- } else {
3677
- return "field"
3678
- /* Field */
3679
- ;
3680
- }
3681
- }
3595
+ const cachedGetterByKey = create(null);
3596
+ const cachedSetterByKey = create(null);
3682
3597
 
3683
- function validateObservedField(Ctor, fieldName, descriptor) {
3684
- if (!isUndefined$1(descriptor)) {
3685
- const type = getClassDescriptorType(descriptor);
3686
- const message = `Invalid observed ${fieldName} field. Found a duplicate ${type} with the same name.`; // [W-9927596] Ideally we always throw an error when detecting duplicate observed field.
3687
- // This branch is only here for backward compatibility reasons.
3598
+ function createGetter(key) {
3599
+ let fn = cachedGetterByKey[key];
3688
3600
 
3689
- if (type === "accessor"
3690
- /* Accessor */
3691
- ) {
3692
- logError(message);
3693
- } else {
3694
- assert.fail(message);
3695
- }
3601
+ if (isUndefined$1(fn)) {
3602
+ fn = cachedGetterByKey[key] = function () {
3603
+ const vm = getAssociatedVM(this);
3604
+ const {
3605
+ getHook
3606
+ } = vm;
3607
+ return getHook(vm.component, key);
3608
+ };
3696
3609
  }
3697
- }
3698
3610
 
3699
- function validateFieldDecoratedWithTrack(Ctor, fieldName, descriptor) {
3700
- if (!isUndefined$1(descriptor)) {
3701
- const type = getClassDescriptorType(descriptor);
3702
- assert.fail(`Invalid @track ${fieldName} field. Found a duplicate ${type} with the same name.`);
3703
- }
3611
+ return fn;
3704
3612
  }
3705
3613
 
3706
- function validateFieldDecoratedWithWire(Ctor, fieldName, descriptor) {
3707
- if (!isUndefined$1(descriptor)) {
3708
- const type = getClassDescriptorType(descriptor);
3709
- assert.fail(`Invalid @wire ${fieldName} field. Found a duplicate ${type} with the same name.`);
3614
+ function createSetter(key) {
3615
+ let fn = cachedSetterByKey[key];
3616
+
3617
+ if (isUndefined$1(fn)) {
3618
+ fn = cachedSetterByKey[key] = function (newValue) {
3619
+ const vm = getAssociatedVM(this);
3620
+ const {
3621
+ setHook
3622
+ } = vm;
3623
+ newValue = reactiveMembrane.getReadOnlyProxy(newValue);
3624
+ setHook(vm.component, key, newValue);
3625
+ };
3710
3626
  }
3627
+
3628
+ return fn;
3711
3629
  }
3712
3630
 
3713
- function validateMethodDecoratedWithWire(Ctor, methodName, descriptor) {
3714
- if (isUndefined$1(descriptor) || !isFunction$1(descriptor.value) || isFalse(descriptor.writable)) {
3715
- assert.fail(`Invalid @wire ${methodName} method.`);
3716
- }
3631
+ function createMethodCaller(methodName) {
3632
+ return function () {
3633
+ const vm = getAssociatedVM(this);
3634
+ const {
3635
+ callHook,
3636
+ component
3637
+ } = vm;
3638
+ const fn = component[methodName];
3639
+ return callHook(vm.component, fn, ArraySlice.call(arguments));
3640
+ };
3717
3641
  }
3718
3642
 
3719
- function validateFieldDecoratedWithApi(Ctor, fieldName, descriptor) {
3720
- if (!isUndefined$1(descriptor)) {
3721
- const type = getClassDescriptorType(descriptor);
3722
- const message = `Invalid @api ${fieldName} field. Found a duplicate ${type} with the same name.`; // [W-9927596] Ideally we always throw an error when detecting duplicate public properties.
3723
- // This branch is only here for backward compatibility reasons.
3643
+ function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
3644
+ return function attributeChangedCallback(attrName, oldValue, newValue) {
3645
+ if (oldValue === newValue) {
3646
+ // Ignore same values.
3647
+ return;
3648
+ }
3724
3649
 
3725
- if (type === "accessor"
3726
- /* Accessor */
3727
- ) {
3728
- logError(message);
3729
- } else {
3730
- assert.fail(message);
3650
+ const propName = attributeToPropMap[attrName];
3651
+
3652
+ if (isUndefined$1(propName)) {
3653
+ if (!isUndefined$1(superAttributeChangedCallback)) {
3654
+ // delegate unknown attributes to the super.
3655
+ // Typescript does not like it when you treat the `arguments` object as an array
3656
+ // @ts-ignore type-mismatch
3657
+ superAttributeChangedCallback.apply(this, arguments);
3658
+ }
3659
+
3660
+ return;
3731
3661
  }
3732
- }
3662
+
3663
+ if (!isAttributeLocked(this, attrName)) {
3664
+ // Ignore changes triggered by the engine itself during:
3665
+ // * diffing when public props are attempting to reflect to the DOM
3666
+ // * component via `this.setAttribute()`, should never update the prop
3667
+ // Both cases, the setAttribute call is always wrapped by the unlocking of the
3668
+ // attribute to be changed
3669
+ return;
3670
+ } // Reflect attribute change to the corresponding property when changed from outside.
3671
+
3672
+
3673
+ this[propName] = newValue;
3674
+ };
3733
3675
  }
3734
3676
 
3735
- function validateAccessorDecoratedWithApi(Ctor, fieldName, descriptor) {
3736
- if (isUndefined$1(descriptor)) {
3737
- assert.fail(`Invalid @api get ${fieldName} accessor.`);
3738
- } else if (isFunction$1(descriptor.set)) {
3739
- assert.isTrue(isFunction$1(descriptor.get), `Missing getter for property ${fieldName} decorated with @api in ${Ctor}. You cannot have a setter without the corresponding getter.`);
3740
- } else if (!isFunction$1(descriptor.get)) {
3741
- assert.fail(`Missing @api get ${fieldName} accessor.`);
3742
- }
3677
+ function HTMLBridgeElementFactory(SuperClass, props, methods) {
3678
+ let HTMLBridgeElement;
3679
+ /**
3680
+ * Modern browsers will have all Native Constructors as regular Classes
3681
+ * and must be instantiated with the new keyword. In older browsers,
3682
+ * specifically IE11, those are objects with a prototype property defined,
3683
+ * since they are not supposed to be extended or instantiated with the
3684
+ * new keyword. This forking logic supports both cases, specifically because
3685
+ * wc.ts relies on the construction path of the bridges to create new
3686
+ * fully qualifying web components.
3687
+ */
3688
+
3689
+ if (isFunction$1(SuperClass)) {
3690
+ HTMLBridgeElement = class extends SuperClass {};
3691
+ } else {
3692
+ HTMLBridgeElement = function () {
3693
+ // Bridge classes are not supposed to be instantiated directly in
3694
+ // browsers that do not support web components.
3695
+ throw new TypeError('Illegal constructor');
3696
+ }; // prototype inheritance dance
3697
+
3698
+
3699
+ setPrototypeOf(HTMLBridgeElement, SuperClass);
3700
+ setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
3701
+ defineProperty(HTMLBridgeElement.prototype, 'constructor', {
3702
+ writable: true,
3703
+ configurable: true,
3704
+ value: HTMLBridgeElement
3705
+ });
3706
+ } // generating the hash table for attributes to avoid duplicate fields and facilitate validation
3707
+ // and false positives in case of inheritance.
3708
+
3709
+
3710
+ const attributeToPropMap = create(null);
3711
+ const {
3712
+ attributeChangedCallback: superAttributeChangedCallback
3713
+ } = SuperClass.prototype;
3714
+ const {
3715
+ observedAttributes: superObservedAttributes = []
3716
+ } = SuperClass;
3717
+ const descriptors = create(null); // expose getters and setters for each public props on the new Element Bridge
3718
+
3719
+ for (let i = 0, len = props.length; i < len; i += 1) {
3720
+ const propName = props[i];
3721
+ attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
3722
+ descriptors[propName] = {
3723
+ get: createGetter(propName),
3724
+ set: createSetter(propName),
3725
+ enumerable: true,
3726
+ configurable: true
3727
+ };
3728
+ } // expose public methods as props on the new Element Bridge
3729
+
3730
+
3731
+ for (let i = 0, len = methods.length; i < len; i += 1) {
3732
+ const methodName = methods[i];
3733
+ descriptors[methodName] = {
3734
+ value: createMethodCaller(methodName),
3735
+ writable: true,
3736
+ configurable: true
3737
+ };
3738
+ } // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
3739
+ // map of attributes to props. We do this after all other props and methods to avoid the possibility
3740
+ // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
3741
+ // to preserve this definition.
3742
+
3743
+
3744
+ descriptors.attributeChangedCallback = {
3745
+ value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
3746
+ }; // Specify attributes for which we want to reflect changes back to their corresponding
3747
+ // properties via attributeChangedCallback.
3748
+
3749
+ defineProperty(HTMLBridgeElement, 'observedAttributes', {
3750
+ get() {
3751
+ return [...superObservedAttributes, ...keys(attributeToPropMap)];
3752
+ }
3753
+
3754
+ });
3755
+ defineProperties(HTMLBridgeElement.prototype, descriptors);
3756
+ return HTMLBridgeElement;
3743
3757
  }
3744
3758
 
3745
- function validateMethodDecoratedWithApi(Ctor, methodName, descriptor) {
3746
- if (isUndefined$1(descriptor) || !isFunction$1(descriptor.value) || isFalse(descriptor.writable)) {
3747
- assert.fail(`Invalid @api ${methodName} method.`);
3748
- }
3749
- }
3750
- /**
3751
- * INTERNAL: This function can only be invoked by compiled code. The compiler
3752
- * will prevent this function from being imported by user-land code.
3759
+ const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor$1, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
3760
+ freeze(BaseBridgeElement);
3761
+ seal(BaseBridgeElement.prototype);
3762
+ /*
3763
+ * Copyright (c) 2020, salesforce.com, inc.
3764
+ * All rights reserved.
3765
+ * SPDX-License-Identifier: MIT
3766
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3753
3767
  */
3754
3768
 
3769
+ function resolveCircularModuleDependency(fn) {
3770
+ const module = fn();
3771
+ return (module === null || module === void 0 ? void 0 : module.__esModule) ? module.default : module;
3772
+ }
3755
3773
 
3756
- function registerDecorators(Ctor, meta) {
3757
- const proto = Ctor.prototype;
3758
- const {
3759
- publicProps,
3760
- publicMethods,
3761
- wire,
3762
- track,
3763
- fields
3764
- } = meta;
3765
- const apiMethods = create(null);
3766
- const apiFields = create(null);
3767
- const wiredMethods = create(null);
3768
- const wiredFields = create(null);
3769
- const observedFields = create(null);
3770
- const apiFieldsConfig = create(null);
3771
- let descriptor;
3772
-
3773
- if (!isUndefined$1(publicProps)) {
3774
- for (const fieldName in publicProps) {
3775
- const propConfig = publicProps[fieldName];
3776
- apiFieldsConfig[fieldName] = propConfig.config;
3777
- descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
3778
-
3779
- if (propConfig.config > 0) {
3780
- // accessor declaration
3781
- if (process.env.NODE_ENV !== 'production') {
3782
- validateAccessorDecoratedWithApi(Ctor, fieldName, descriptor);
3783
- }
3774
+ function isCircularModuleDependency(obj) {
3775
+ return isFunction$1(obj) && hasOwnProperty$1.call(obj, '__circular__');
3776
+ }
3777
+ /*
3778
+ * Copyright (c) 2020, salesforce.com, inc.
3779
+ * All rights reserved.
3780
+ * SPDX-License-Identifier: MIT
3781
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3782
+ */
3784
3783
 
3785
- if (isUndefined$1(descriptor)) {
3786
- throw new Error();
3787
- }
3788
3784
 
3789
- descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
3790
- } else {
3791
- // field declaration
3792
- if (process.env.NODE_ENV !== 'production') {
3793
- validateFieldDecoratedWithApi(Ctor, fieldName, descriptor);
3794
- } // [W-9927596] If a component has both a public property and a private setter/getter
3795
- // with the same name, the property is defined as a public accessor. This branch is
3796
- // only here for backward compatibility reasons.
3785
+ const swappedTemplateMap = new WeakMap();
3786
+ const swappedComponentMap = new WeakMap();
3787
+ const swappedStyleMap = new WeakMap();
3788
+ const activeTemplates = new WeakMap();
3789
+ const activeComponents = new WeakMap();
3790
+ const activeStyles = new WeakMap();
3797
3791
 
3792
+ function rehydrateHotTemplate(tpl) {
3793
+ const list = activeTemplates.get(tpl);
3798
3794
 
3799
- if (!isUndefined$1(descriptor) && !isUndefined$1(descriptor.get)) {
3800
- descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
3801
- } else {
3802
- descriptor = createPublicPropertyDescriptor(fieldName);
3803
- }
3795
+ if (!isUndefined$1(list)) {
3796
+ list.forEach(vm => {
3797
+ if (isFalse(vm.isDirty)) {
3798
+ // forcing the vm to rehydrate in the micro-task:
3799
+ markComponentAsDirty(vm);
3800
+ scheduleRehydration(vm);
3804
3801
  }
3802
+ }); // resetting the Set to release the memory of those vm references
3803
+ // since they are not longer related to this template, instead
3804
+ // they will get re-associated once these instances are rehydrated.
3805
3805
 
3806
- apiFields[fieldName] = descriptor;
3807
- defineProperty(proto, fieldName, descriptor);
3808
- }
3806
+ list.clear();
3809
3807
  }
3810
3808
 
3811
- if (!isUndefined$1(publicMethods)) {
3812
- forEach.call(publicMethods, methodName => {
3813
- descriptor = getOwnPropertyDescriptor$1(proto, methodName);
3809
+ return true;
3810
+ }
3814
3811
 
3815
- if (process.env.NODE_ENV !== 'production') {
3816
- validateMethodDecoratedWithApi(Ctor, methodName, descriptor);
3817
- }
3812
+ function rehydrateHotStyle(style) {
3813
+ const list = activeStyles.get(style);
3818
3814
 
3819
- if (isUndefined$1(descriptor)) {
3820
- throw new Error();
3821
- }
3815
+ if (!isUndefined$1(list)) {
3816
+ list.forEach(vm => {
3817
+ // if a style definition is swapped, we must reset
3818
+ // vm's template content in the next micro-task:
3819
+ forceRehydration(vm);
3820
+ }); // resetting the Set to release the memory of those vm references
3821
+ // since they are not longer related to this style, instead
3822
+ // they will get re-associated once these instances are rehydrated.
3822
3823
 
3823
- apiMethods[methodName] = descriptor;
3824
- });
3824
+ list.clear();
3825
3825
  }
3826
3826
 
3827
- if (!isUndefined$1(wire)) {
3828
- for (const fieldOrMethodName in wire) {
3829
- const {
3830
- adapter,
3831
- method,
3832
- config: configCallback,
3833
- dynamic = []
3834
- } = wire[fieldOrMethodName];
3835
- descriptor = getOwnPropertyDescriptor$1(proto, fieldOrMethodName);
3827
+ return true;
3828
+ }
3836
3829
 
3837
- if (method === 1) {
3838
- if (process.env.NODE_ENV !== 'production') {
3839
- assert.isTrue(adapter, `@wire on method "${fieldOrMethodName}": adapter id must be truthy.`);
3840
- validateMethodDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
3841
- }
3830
+ function rehydrateHotComponent(Ctor) {
3831
+ const list = activeComponents.get(Ctor);
3832
+ let canRefreshAllInstances = true;
3842
3833
 
3843
- if (isUndefined$1(descriptor)) {
3844
- throw new Error();
3845
- }
3834
+ if (!isUndefined$1(list)) {
3835
+ list.forEach(vm => {
3836
+ const {
3837
+ owner
3838
+ } = vm;
3846
3839
 
3847
- wiredMethods[fieldOrMethodName] = descriptor;
3848
- storeWiredMethodMeta(descriptor, adapter, configCallback, dynamic);
3840
+ if (!isNull(owner)) {
3841
+ // if a component class definition is swapped, we must reset
3842
+ // owner's template content in the next micro-task:
3843
+ forceRehydration(owner);
3849
3844
  } else {
3850
- if (process.env.NODE_ENV !== 'production') {
3851
- assert.isTrue(adapter, `@wire on field "${fieldOrMethodName}": adapter id must be truthy.`);
3852
- validateFieldDecoratedWithWire(Ctor, fieldOrMethodName, descriptor);
3853
- }
3854
-
3855
- descriptor = internalWireFieldDecorator(fieldOrMethodName);
3856
- wiredFields[fieldOrMethodName] = descriptor;
3857
- storeWiredFieldMeta(descriptor, adapter, configCallback, dynamic);
3858
- defineProperty(proto, fieldOrMethodName, descriptor);
3859
- }
3860
- }
3861
- }
3862
-
3863
- if (!isUndefined$1(track)) {
3864
- for (const fieldName in track) {
3865
- descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
3866
-
3867
- if (process.env.NODE_ENV !== 'production') {
3868
- validateFieldDecoratedWithTrack(Ctor, fieldName, descriptor);
3845
+ // the hot swapping for components only work for instances of components
3846
+ // created from a template, root elements can't be swapped because we
3847
+ // don't have a way to force the creation of the element with the same state
3848
+ // of the current element.
3849
+ // Instead, we can report the problem to the caller so it can take action,
3850
+ // for example: reload the entire page.
3851
+ canRefreshAllInstances = false;
3869
3852
  }
3853
+ }); // resetting the Set to release the memory of those vm references
3854
+ // since they are not longer related to this constructor, instead
3855
+ // they will get re-associated once these instances are rehydrated.
3870
3856
 
3871
- descriptor = internalTrackDecorator(fieldName);
3872
- defineProperty(proto, fieldName, descriptor);
3873
- }
3857
+ list.clear();
3874
3858
  }
3875
3859
 
3876
- if (!isUndefined$1(fields)) {
3877
- for (let i = 0, n = fields.length; i < n; i++) {
3878
- const fieldName = fields[i];
3879
- descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
3880
-
3881
- if (process.env.NODE_ENV !== 'production') {
3882
- validateObservedField(Ctor, fieldName, descriptor);
3883
- } // [W-9927596] Only mark a field as observed whenever it isn't a duplicated public nor
3884
- // tracked property. This is only here for backward compatibility purposes.
3885
-
3860
+ return canRefreshAllInstances;
3861
+ }
3886
3862
 
3887
- const isDuplicatePublicProp = !isUndefined$1(publicProps) && fieldName in publicProps;
3888
- const isDuplicateTrackedProp = !isUndefined$1(track) && fieldName in track;
3863
+ function flattenStylesheets(stylesheets) {
3864
+ const list = [];
3889
3865
 
3890
- if (!isDuplicatePublicProp && !isDuplicateTrackedProp) {
3891
- observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
3892
- }
3866
+ for (const stylesheet of stylesheets) {
3867
+ if (!Array.isArray(stylesheet)) {
3868
+ list.push(stylesheet);
3869
+ } else {
3870
+ list.push(...flattenStylesheets(stylesheet));
3893
3871
  }
3894
3872
  }
3895
3873
 
3896
- setDecoratorsMeta(Ctor, {
3897
- apiMethods,
3898
- apiFields,
3899
- apiFieldsConfig,
3900
- wiredMethods,
3901
- wiredFields,
3902
- observedFields
3903
- });
3904
- return Ctor;
3874
+ return list;
3905
3875
  }
3906
3876
 
3907
- const signedDecoratorToMetaMap = new Map();
3877
+ function getTemplateOrSwappedTemplate(tpl) {
3878
+ if (process.env.NODE_ENV === 'production') {
3879
+ // this method should never leak to prod
3880
+ throw new ReferenceError();
3881
+ }
3908
3882
 
3909
- function setDecoratorsMeta(Ctor, meta) {
3910
- signedDecoratorToMetaMap.set(Ctor, meta);
3911
- }
3883
+ if (runtimeFlags.ENABLE_HMR) {
3884
+ const visited = new Set();
3912
3885
 
3913
- const defaultMeta = {
3914
- apiMethods: EmptyObject,
3915
- apiFields: EmptyObject,
3916
- apiFieldsConfig: EmptyObject,
3917
- wiredMethods: EmptyObject,
3918
- wiredFields: EmptyObject,
3919
- observedFields: EmptyObject
3920
- };
3886
+ while (swappedTemplateMap.has(tpl) && !visited.has(tpl)) {
3887
+ visited.add(tpl);
3888
+ tpl = swappedTemplateMap.get(tpl);
3889
+ }
3890
+ }
3921
3891
 
3922
- function getDecoratorsMeta(Ctor) {
3923
- const meta = signedDecoratorToMetaMap.get(Ctor);
3924
- return isUndefined$1(meta) ? defaultMeta : meta;
3892
+ return tpl;
3925
3893
  }
3926
3894
 
3927
- const signedTemplateSet = new Set();
3895
+ function getComponentOrSwappedComponent(Ctor) {
3896
+ if (process.env.NODE_ENV === 'production') {
3897
+ // this method should never leak to prod
3898
+ throw new ReferenceError();
3899
+ }
3928
3900
 
3929
- function defaultEmptyTemplate() {
3930
- return [];
3931
- }
3901
+ if (runtimeFlags.ENABLE_HMR) {
3902
+ const visited = new Set();
3932
3903
 
3933
- signedTemplateSet.add(defaultEmptyTemplate);
3904
+ while (swappedComponentMap.has(Ctor) && !visited.has(Ctor)) {
3905
+ visited.add(Ctor);
3906
+ Ctor = swappedComponentMap.get(Ctor);
3907
+ }
3908
+ }
3934
3909
 
3935
- function isTemplateRegistered(tpl) {
3936
- return signedTemplateSet.has(tpl);
3910
+ return Ctor;
3937
3911
  }
3938
- /**
3939
- * INTERNAL: This function can only be invoked by compiled code. The compiler
3940
- * will prevent this function from being imported by userland code.
3941
- */
3942
3912
 
3913
+ function getStyleOrSwappedStyle(style) {
3914
+ if (process.env.NODE_ENV === 'production') {
3915
+ // this method should never leak to prod
3916
+ throw new ReferenceError();
3917
+ }
3943
3918
 
3944
- function registerTemplate(tpl) {
3945
- signedTemplateSet.add(tpl); // chaining this method as a way to wrap existing
3946
- // assignment of templates easily, without too much transformation
3919
+ if (runtimeFlags.ENABLE_HMR) {
3920
+ const visited = new Set();
3947
3921
 
3948
- return tpl;
3922
+ while (swappedStyleMap.has(style) && !visited.has(style)) {
3923
+ visited.add(style);
3924
+ style = swappedStyleMap.get(style);
3925
+ }
3926
+ }
3927
+
3928
+ return style;
3949
3929
  }
3950
- /**
3951
- * EXPERIMENTAL: This function acts like a hook for Lightning Locker Service and other similar
3952
- * libraries to sanitize vulnerable attributes.
3953
- */
3954
3930
 
3931
+ function setActiveVM(vm) {
3932
+ if (process.env.NODE_ENV === 'production') {
3933
+ // this method should never leak to prod
3934
+ throw new ReferenceError();
3935
+ }
3955
3936
 
3956
- function sanitizeAttribute(tagName, namespaceUri, attrName, attrValue) {
3957
- // locker-service patches this function during runtime to sanitize vulnerable attributes. When
3958
- // ran off-core this function becomes a noop and returns the user authored value.
3959
- return attrValue;
3960
- }
3961
- /*
3962
- * Copyright (c) 2018, salesforce.com, inc.
3963
- * All rights reserved.
3964
- * SPDX-License-Identifier: MIT
3965
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3966
- */
3967
- // from the element instance, and get the value or set a new value on the component.
3968
- // This means that across different elements, similar names can get the exact same
3969
- // descriptor, so we can cache them:
3937
+ if (runtimeFlags.ENABLE_HMR) {
3938
+ // tracking active component
3939
+ const Ctor = vm.def.ctor;
3940
+ let componentVMs = activeComponents.get(Ctor);
3970
3941
 
3942
+ if (isUndefined$1(componentVMs)) {
3943
+ componentVMs = new Set();
3944
+ activeComponents.set(Ctor, componentVMs);
3945
+ } // this will allow us to keep track of the hot components
3971
3946
 
3972
- const cachedGetterByKey = create(null);
3973
- const cachedSetterByKey = create(null);
3974
3947
 
3975
- function createGetter(key) {
3976
- let fn = cachedGetterByKey[key];
3948
+ componentVMs.add(vm); // tracking active template
3977
3949
 
3978
- if (isUndefined$1(fn)) {
3979
- fn = cachedGetterByKey[key] = function () {
3980
- const vm = getAssociatedVM(this);
3981
- const {
3982
- getHook
3983
- } = vm;
3984
- return getHook(vm.component, key);
3985
- };
3986
- }
3950
+ const tpl = vm.cmpTemplate;
3987
3951
 
3988
- return fn;
3989
- }
3952
+ if (tpl) {
3953
+ let templateVMs = activeTemplates.get(tpl);
3990
3954
 
3991
- function createSetter(key) {
3992
- let fn = cachedSetterByKey[key];
3955
+ if (isUndefined$1(templateVMs)) {
3956
+ templateVMs = new Set();
3957
+ activeTemplates.set(tpl, templateVMs);
3958
+ } // this will allow us to keep track of the templates that are
3959
+ // being used by a hot component
3993
3960
 
3994
- if (isUndefined$1(fn)) {
3995
- fn = cachedSetterByKey[key] = function (newValue) {
3996
- const vm = getAssociatedVM(this);
3997
- const {
3998
- setHook
3999
- } = vm;
4000
- newValue = reactiveMembrane.getReadOnlyProxy(newValue);
4001
- setHook(vm.component, key, newValue);
4002
- };
4003
- }
4004
3961
 
4005
- return fn;
4006
- }
3962
+ templateVMs.add(vm); // tracking active styles associated to template
4007
3963
 
4008
- function createMethodCaller(methodName) {
4009
- return function () {
4010
- const vm = getAssociatedVM(this);
4011
- const {
4012
- callHook,
4013
- component
4014
- } = vm;
4015
- const fn = component[methodName];
4016
- return callHook(vm.component, fn, ArraySlice.call(arguments));
4017
- };
4018
- }
3964
+ const stylesheets = tpl.stylesheets;
4019
3965
 
4020
- function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
4021
- return function attributeChangedCallback(attrName, oldValue, newValue) {
4022
- if (oldValue === newValue) {
4023
- // Ignore same values.
4024
- return;
4025
- }
3966
+ if (!isUndefined$1(stylesheets)) {
3967
+ flattenStylesheets(stylesheets).forEach(stylesheet => {
3968
+ // this is necessary because we don't hold the list of styles
3969
+ // in the vm, we only hold the selected (already swapped template)
3970
+ // but the styles attached to the template might not be the actual
3971
+ // active ones, but the swapped versions of those.
3972
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
3973
+ let stylesheetVMs = activeStyles.get(stylesheet);
4026
3974
 
4027
- const propName = attributeToPropMap[attrName];
3975
+ if (isUndefined$1(stylesheetVMs)) {
3976
+ stylesheetVMs = new Set();
3977
+ activeStyles.set(stylesheet, stylesheetVMs);
3978
+ } // this will allow us to keep track of the stylesheet that are
3979
+ // being used by a hot component
4028
3980
 
4029
- if (isUndefined$1(propName)) {
4030
- if (!isUndefined$1(superAttributeChangedCallback)) {
4031
- // delegate unknown attributes to the super.
4032
- // Typescript does not like it when you treat the `arguments` object as an array
4033
- // @ts-ignore type-mismatch
4034
- superAttributeChangedCallback.apply(this, arguments);
4035
- }
4036
3981
 
4037
- return;
3982
+ stylesheetVMs.add(vm);
3983
+ });
3984
+ }
4038
3985
  }
3986
+ }
3987
+ }
4039
3988
 
4040
- if (!isAttributeLocked(this, attrName)) {
4041
- // Ignore changes triggered by the engine itself during:
4042
- // * diffing when public props are attempting to reflect to the DOM
4043
- // * component via `this.setAttribute()`, should never update the prop
4044
- // Both cases, the setAttribute call is always wrapped by the unlocking of the
4045
- // attribute to be changed
4046
- return;
4047
- } // Reflect attribute change to the corresponding property when changed from outside.
4048
-
3989
+ function removeActiveVM(vm) {
3990
+ if (process.env.NODE_ENV === 'production') {
3991
+ // this method should never leak to prod
3992
+ throw new ReferenceError();
3993
+ }
4049
3994
 
4050
- this[propName] = newValue;
4051
- };
4052
- }
3995
+ if (runtimeFlags.ENABLE_HMR) {
3996
+ // tracking inactive component
3997
+ const Ctor = vm.def.ctor;
3998
+ let list = activeComponents.get(Ctor);
4053
3999
 
4054
- function HTMLBridgeElementFactory(SuperClass, props, methods) {
4055
- let HTMLBridgeElement;
4056
- /**
4057
- * Modern browsers will have all Native Constructors as regular Classes
4058
- * and must be instantiated with the new keyword. In older browsers,
4059
- * specifically IE11, those are objects with a prototype property defined,
4060
- * since they are not supposed to be extended or instantiated with the
4061
- * new keyword. This forking logic supports both cases, specifically because
4062
- * wc.ts relies on the construction path of the bridges to create new
4063
- * fully qualifying web components.
4064
- */
4000
+ if (!isUndefined$1(list)) {
4001
+ // deleting the vm from the set to avoid leaking memory
4002
+ list.delete(vm);
4003
+ } // removing inactive template
4065
4004
 
4066
- if (isFunction$1(SuperClass)) {
4067
- HTMLBridgeElement = class extends SuperClass {};
4068
- } else {
4069
- HTMLBridgeElement = function () {
4070
- // Bridge classes are not supposed to be instantiated directly in
4071
- // browsers that do not support web components.
4072
- throw new TypeError('Illegal constructor');
4073
- }; // prototype inheritance dance
4074
4005
 
4006
+ const tpl = vm.cmpTemplate;
4075
4007
 
4076
- setPrototypeOf(HTMLBridgeElement, SuperClass);
4077
- setPrototypeOf(HTMLBridgeElement.prototype, SuperClass.prototype);
4078
- defineProperty(HTMLBridgeElement.prototype, 'constructor', {
4079
- writable: true,
4080
- configurable: true,
4081
- value: HTMLBridgeElement
4082
- });
4083
- } // generating the hash table for attributes to avoid duplicate fields and facilitate validation
4084
- // and false positives in case of inheritance.
4008
+ if (tpl) {
4009
+ list = activeTemplates.get(tpl);
4085
4010
 
4011
+ if (!isUndefined$1(list)) {
4012
+ // deleting the vm from the set to avoid leaking memory
4013
+ list.delete(vm);
4014
+ } // removing active styles associated to template
4086
4015
 
4087
- const attributeToPropMap = create(null);
4088
- const {
4089
- attributeChangedCallback: superAttributeChangedCallback
4090
- } = SuperClass.prototype;
4091
- const {
4092
- observedAttributes: superObservedAttributes = []
4093
- } = SuperClass;
4094
- const descriptors = create(null); // expose getters and setters for each public props on the new Element Bridge
4095
4016
 
4096
- for (let i = 0, len = props.length; i < len; i += 1) {
4097
- const propName = props[i];
4098
- attributeToPropMap[htmlPropertyToAttribute(propName)] = propName;
4099
- descriptors[propName] = {
4100
- get: createGetter(propName),
4101
- set: createSetter(propName),
4102
- enumerable: true,
4103
- configurable: true
4104
- };
4105
- } // expose public methods as props on the new Element Bridge
4017
+ const styles = tpl.stylesheets;
4106
4018
 
4019
+ if (!isUndefined$1(styles)) {
4020
+ flattenStylesheets(styles).forEach(style => {
4021
+ list = activeStyles.get(style);
4107
4022
 
4108
- for (let i = 0, len = methods.length; i < len; i += 1) {
4109
- const methodName = methods[i];
4110
- descriptors[methodName] = {
4111
- value: createMethodCaller(methodName),
4112
- writable: true,
4113
- configurable: true
4114
- };
4115
- } // creating a new attributeChangedCallback per bridge because they are bound to the corresponding
4116
- // map of attributes to props. We do this after all other props and methods to avoid the possibility
4117
- // of getting overrule by a class declaration in user-land, and we make it non-writable, non-configurable
4118
- // to preserve this definition.
4023
+ if (!isUndefined$1(list)) {
4024
+ // deleting the vm from the set to avoid leaking memory
4025
+ list.delete(vm);
4026
+ }
4027
+ });
4028
+ }
4029
+ }
4030
+ }
4031
+ }
4119
4032
 
4033
+ function swapTemplate(oldTpl, newTpl) {
4034
+ if (process.env.NODE_ENV !== 'production') {
4035
+ if (isTemplateRegistered(oldTpl) && isTemplateRegistered(newTpl)) {
4036
+ swappedTemplateMap.set(oldTpl, newTpl);
4037
+ return rehydrateHotTemplate(oldTpl);
4038
+ } else {
4039
+ throw new TypeError(`Invalid Template`);
4040
+ }
4041
+ }
4120
4042
 
4121
- descriptors.attributeChangedCallback = {
4122
- value: createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback)
4123
- }; // Specify attributes for which we want to reflect changes back to their corresponding
4124
- // properties via attributeChangedCallback.
4043
+ if (!runtimeFlags.ENABLE_HMR) {
4044
+ throw new Error('HMR is not enabled');
4045
+ }
4125
4046
 
4126
- defineProperty(HTMLBridgeElement, 'observedAttributes', {
4127
- get() {
4128
- return [...superObservedAttributes, ...keys(attributeToPropMap)];
4047
+ return false;
4048
+ }
4049
+
4050
+ function swapComponent(oldComponent, newComponent) {
4051
+ if (process.env.NODE_ENV !== 'production') {
4052
+ if (isComponentConstructor(oldComponent) && isComponentConstructor(newComponent)) {
4053
+ swappedComponentMap.set(oldComponent, newComponent);
4054
+ return rehydrateHotComponent(oldComponent);
4055
+ } else {
4056
+ throw new TypeError(`Invalid Component`);
4129
4057
  }
4058
+ }
4130
4059
 
4131
- });
4132
- defineProperties(HTMLBridgeElement.prototype, descriptors);
4133
- return HTMLBridgeElement;
4060
+ if (!runtimeFlags.ENABLE_HMR) {
4061
+ throw new Error('HMR is not enabled');
4062
+ }
4063
+
4064
+ return false;
4134
4065
  }
4135
4066
 
4136
- const BaseBridgeElement = HTMLBridgeElementFactory(HTMLElementConstructor$1, getOwnPropertyNames$1(HTMLElementOriginalDescriptors), []);
4137
- freeze(BaseBridgeElement);
4138
- seal(BaseBridgeElement.prototype);
4139
- /*
4140
- * Copyright (c) 2020, salesforce.com, inc.
4141
- * All rights reserved.
4142
- * SPDX-License-Identifier: MIT
4143
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4144
- */
4067
+ function swapStyle(oldStyle, newStyle) {
4068
+ if (process.env.NODE_ENV !== 'production') {
4069
+ // TODO [#1887]: once the support for registering styles is implemented
4070
+ // we can add the validation of both styles around this block.
4071
+ swappedStyleMap.set(oldStyle, newStyle);
4072
+ return rehydrateHotStyle(oldStyle);
4073
+ }
4145
4074
 
4146
- function resolveCircularModuleDependency(fn) {
4147
- const module = fn();
4148
- return (module === null || module === void 0 ? void 0 : module.__esModule) ? module.default : module;
4149
- }
4075
+ if (!runtimeFlags.ENABLE_HMR) {
4076
+ throw new Error('HMR is not enabled');
4077
+ }
4150
4078
 
4151
- function isCircularModuleDependency(obj) {
4152
- return isFunction$1(obj) && hasOwnProperty$1.call(obj, '__circular__');
4079
+ return false;
4153
4080
  }
4154
4081
  /*
4155
- * Copyright (c) 2020, salesforce.com, inc.
4082
+ * Copyright (c) 2018, salesforce.com, inc.
4156
4083
  * All rights reserved.
4157
4084
  * SPDX-License-Identifier: MIT
4158
4085
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4159
4086
  */
4160
4087
 
4161
4088
 
4162
- const swappedTemplateMap = new WeakMap();
4163
- const swappedComponentMap = new WeakMap();
4164
- const swappedStyleMap = new WeakMap();
4165
- const activeTemplates = new WeakMap();
4166
- const activeComponents = new WeakMap();
4167
- const activeStyles = new WeakMap();
4089
+ const CtorToDefMap = new WeakMap();
4168
4090
 
4169
- function rehydrateHotTemplate(tpl) {
4170
- const list = activeTemplates.get(tpl);
4091
+ function getCtorProto(Ctor) {
4092
+ let proto = getPrototypeOf$1(Ctor);
4171
4093
 
4172
- if (!isUndefined$1(list)) {
4173
- list.forEach(vm => {
4174
- if (isFalse(vm.isDirty)) {
4175
- // forcing the vm to rehydrate in the micro-task:
4176
- markComponentAsDirty(vm);
4177
- scheduleRehydration(vm);
4178
- }
4179
- }); // resetting the Set to release the memory of those vm references
4180
- // since they are not longer related to this template, instead
4181
- // they will get re-associated once these instances are rehydrated.
4094
+ if (isNull(proto)) {
4095
+ throw new ReferenceError(`Invalid prototype chain for ${Ctor.name}, you must extend LightningElement.`);
4096
+ } // covering the cases where the ref is circular in AMD
4182
4097
 
4183
- list.clear();
4184
- }
4185
4098
 
4186
- return true;
4187
- }
4099
+ if (isCircularModuleDependency(proto)) {
4100
+ const p = resolveCircularModuleDependency(proto);
4188
4101
 
4189
- function rehydrateHotStyle(style) {
4190
- const list = activeStyles.get(style);
4102
+ if (process.env.NODE_ENV !== 'production') {
4103
+ if (isNull(p)) {
4104
+ throw new ReferenceError(`Circular module dependency for ${Ctor.name}, must resolve to a constructor that extends LightningElement.`);
4105
+ }
4106
+ } // escape hatch for Locker and other abstractions to provide their own base class instead
4107
+ // of our Base class without having to leak it to user-land. If the circular function returns
4108
+ // itself, that's the signal that we have hit the end of the proto chain, which must always
4109
+ // be base.
4191
4110
 
4192
- if (!isUndefined$1(list)) {
4193
- list.forEach(vm => {
4194
- // if a style definition is swapped, we must reset
4195
- // vm's template content in the next micro-task:
4196
- forceRehydration(vm);
4197
- }); // resetting the Set to release the memory of those vm references
4198
- // since they are not longer related to this style, instead
4199
- // they will get re-associated once these instances are rehydrated.
4200
4111
 
4201
- list.clear();
4112
+ proto = p === proto ? LightningElement : p;
4202
4113
  }
4203
4114
 
4204
- return true;
4115
+ return proto;
4205
4116
  }
4206
4117
 
4207
- function rehydrateHotComponent(Ctor) {
4208
- const list = activeComponents.get(Ctor);
4209
- let canRefreshAllInstances = true;
4210
-
4211
- if (!isUndefined$1(list)) {
4212
- list.forEach(vm => {
4213
- const {
4214
- owner
4215
- } = vm;
4216
-
4217
- if (!isNull(owner)) {
4218
- // if a component class definition is swapped, we must reset
4219
- // owner's template content in the next micro-task:
4220
- forceRehydration(owner);
4221
- } else {
4222
- // the hot swapping for components only work for instances of components
4223
- // created from a template, root elements can't be swapped because we
4224
- // don't have a way to force the creation of the element with the same state
4225
- // of the current element.
4226
- // Instead, we can report the problem to the caller so it can take action,
4227
- // for example: reload the entire page.
4228
- canRefreshAllInstances = false;
4229
- }
4230
- }); // resetting the Set to release the memory of those vm references
4231
- // since they are not longer related to this constructor, instead
4232
- // they will get re-associated once these instances are rehydrated.
4118
+ function createComponentDef(Ctor) {
4119
+ const {
4120
+ shadowSupportMode: ctorShadowSupportMode,
4121
+ renderMode: ctorRenderMode
4122
+ } = Ctor;
4233
4123
 
4234
- list.clear();
4235
- }
4124
+ if (process.env.NODE_ENV !== 'production') {
4125
+ const ctorName = Ctor.name; // Removing the following assert until https://bugs.webkit.org/show_bug.cgi?id=190140 is fixed.
4126
+ // assert.isTrue(ctorName && isString(ctorName), `${toString(Ctor)} should have a "name" property with string value, but found ${ctorName}.`);
4236
4127
 
4237
- return canRefreshAllInstances;
4238
- }
4128
+ assert.isTrue(Ctor.constructor, `Missing ${ctorName}.constructor, ${ctorName} should have a "constructor" property.`);
4239
4129
 
4240
- function flattenStylesheets(stylesheets) {
4241
- const list = [];
4130
+ if (!isUndefined$1(ctorShadowSupportMode)) {
4131
+ assert.invariant(ctorShadowSupportMode === "any"
4132
+ /* Any */
4133
+ || ctorShadowSupportMode === "reset"
4134
+ /* Default */
4135
+ , `Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
4136
+ }
4242
4137
 
4243
- for (const stylesheet of stylesheets) {
4244
- if (!Array.isArray(stylesheet)) {
4245
- list.push(stylesheet);
4246
- } else {
4247
- list.push(...flattenStylesheets(stylesheet));
4138
+ if (!isUndefined$1(ctorRenderMode)) {
4139
+ assert.invariant(ctorRenderMode === 'light' || ctorRenderMode === 'shadow', `Invalid value for static property renderMode: '${ctorRenderMode}'. renderMode must be either 'light' or 'shadow'.`);
4248
4140
  }
4249
4141
  }
4250
4142
 
4251
- return list;
4252
- }
4143
+ const decoratorsMeta = getDecoratorsMeta(Ctor);
4144
+ const {
4145
+ apiFields,
4146
+ apiFieldsConfig,
4147
+ apiMethods,
4148
+ wiredFields,
4149
+ wiredMethods,
4150
+ observedFields
4151
+ } = decoratorsMeta;
4152
+ const proto = Ctor.prototype;
4153
+ let {
4154
+ connectedCallback,
4155
+ disconnectedCallback,
4156
+ renderedCallback,
4157
+ errorCallback,
4158
+ render
4159
+ } = proto;
4160
+ const superProto = getCtorProto(Ctor);
4161
+ const superDef = superProto !== LightningElement ? getComponentInternalDef(superProto) : lightingElementDef;
4162
+ const bridge = HTMLBridgeElementFactory(superDef.bridge, keys(apiFields), keys(apiMethods));
4163
+ const props = assign(create(null), superDef.props, apiFields);
4164
+ const propsConfig = assign(create(null), superDef.propsConfig, apiFieldsConfig);
4165
+ const methods = assign(create(null), superDef.methods, apiMethods);
4166
+ const wire = assign(create(null), superDef.wire, wiredFields, wiredMethods);
4167
+ connectedCallback = connectedCallback || superDef.connectedCallback;
4168
+ disconnectedCallback = disconnectedCallback || superDef.disconnectedCallback;
4169
+ renderedCallback = renderedCallback || superDef.renderedCallback;
4170
+ errorCallback = errorCallback || superDef.errorCallback;
4171
+ render = render || superDef.render;
4172
+ let shadowSupportMode = superDef.shadowSupportMode;
4253
4173
 
4254
- function getTemplateOrSwappedTemplate(tpl) {
4255
- if (process.env.NODE_ENV === 'production') {
4256
- // this method should never leak to prod
4257
- throw new ReferenceError();
4174
+ if (!isUndefined$1(ctorShadowSupportMode)) {
4175
+ shadowSupportMode = ctorShadowSupportMode;
4258
4176
  }
4259
4177
 
4260
- if (runtimeFlags.ENABLE_HMR) {
4261
- const visited = new Set();
4178
+ let renderMode = superDef.renderMode;
4262
4179
 
4263
- while (swappedTemplateMap.has(tpl) && !visited.has(tpl)) {
4264
- visited.add(tpl);
4265
- tpl = swappedTemplateMap.get(tpl);
4266
- }
4180
+ if (!isUndefined$1(ctorRenderMode)) {
4181
+ renderMode = ctorRenderMode === 'light' ? 0
4182
+ /* Light */
4183
+ : 1
4184
+ /* Shadow */
4185
+ ;
4267
4186
  }
4268
4187
 
4269
- return tpl;
4270
- }
4271
-
4272
- function getComponentOrSwappedComponent(Ctor) {
4273
- if (process.env.NODE_ENV === 'production') {
4274
- // this method should never leak to prod
4275
- throw new ReferenceError();
4276
- }
4188
+ const template = getComponentRegisteredTemplate(Ctor) || superDef.template;
4189
+ const name = Ctor.name || superDef.name; // installing observed fields into the prototype.
4277
4190
 
4278
- if (runtimeFlags.ENABLE_HMR) {
4279
- const visited = new Set();
4191
+ defineProperties(proto, observedFields);
4192
+ const def = {
4193
+ ctor: Ctor,
4194
+ name,
4195
+ wire,
4196
+ props,
4197
+ propsConfig,
4198
+ methods,
4199
+ bridge,
4200
+ template,
4201
+ renderMode,
4202
+ shadowSupportMode,
4203
+ connectedCallback,
4204
+ disconnectedCallback,
4205
+ renderedCallback,
4206
+ errorCallback,
4207
+ render
4208
+ };
4280
4209
 
4281
- while (swappedComponentMap.has(Ctor) && !visited.has(Ctor)) {
4282
- visited.add(Ctor);
4283
- Ctor = swappedComponentMap.get(Ctor);
4284
- }
4210
+ if (process.env.NODE_ENV !== 'production') {
4211
+ freeze(Ctor.prototype);
4285
4212
  }
4286
4213
 
4287
- return Ctor;
4214
+ return def;
4288
4215
  }
4216
+ /**
4217
+ * EXPERIMENTAL: This function allows for the identification of LWC constructors. This API is
4218
+ * subject to change or being removed.
4219
+ */
4289
4220
 
4290
- function getStyleOrSwappedStyle(style) {
4291
- if (process.env.NODE_ENV === 'production') {
4292
- // this method should never leak to prod
4293
- throw new ReferenceError();
4294
- }
4295
-
4296
- if (runtimeFlags.ENABLE_HMR) {
4297
- const visited = new Set();
4298
-
4299
- while (swappedStyleMap.has(style) && !visited.has(style)) {
4300
- visited.add(style);
4301
- style = swappedStyleMap.get(style);
4302
- }
4303
- }
4304
4221
 
4305
- return style;
4306
- }
4222
+ function isComponentConstructor(ctor) {
4223
+ if (!isFunction$1(ctor)) {
4224
+ return false;
4225
+ } // Fast path: LightningElement is part of the prototype chain of the constructor.
4307
4226
 
4308
- function setActiveVM(vm) {
4309
- if (process.env.NODE_ENV === 'production') {
4310
- // this method should never leak to prod
4311
- throw new ReferenceError();
4312
- }
4313
4227
 
4314
- if (runtimeFlags.ENABLE_HMR) {
4315
- // tracking active component
4316
- const Ctor = vm.def.ctor;
4317
- let componentVMs = activeComponents.get(Ctor);
4228
+ if (ctor.prototype instanceof LightningElement) {
4229
+ return true;
4230
+ } // Slow path: LightningElement is not part of the prototype chain of the constructor, we need
4231
+ // climb up the constructor prototype chain to check in case there are circular dependencies
4232
+ // to resolve.
4318
4233
 
4319
- if (isUndefined$1(componentVMs)) {
4320
- componentVMs = new Set();
4321
- activeComponents.set(Ctor, componentVMs);
4322
- } // this will allow us to keep track of the hot components
4323
4234
 
4235
+ let current = ctor;
4324
4236
 
4325
- componentVMs.add(vm); // tracking active template
4237
+ do {
4238
+ if (isCircularModuleDependency(current)) {
4239
+ const circularResolved = resolveCircularModuleDependency(current); // If the circular function returns itself, that's the signal that we have hit the end
4240
+ // of the proto chain, which must always be a valid base constructor.
4326
4241
 
4327
- const tpl = vm.cmpTemplate;
4242
+ if (circularResolved === current) {
4243
+ return true;
4244
+ }
4328
4245
 
4329
- if (tpl) {
4330
- let templateVMs = activeTemplates.get(tpl);
4246
+ current = circularResolved;
4247
+ }
4331
4248
 
4332
- if (isUndefined$1(templateVMs)) {
4333
- templateVMs = new Set();
4334
- activeTemplates.set(tpl, templateVMs);
4335
- } // this will allow us to keep track of the templates that are
4336
- // being used by a hot component
4249
+ if (current === LightningElement) {
4250
+ return true;
4251
+ }
4252
+ } while (!isNull(current) && (current = getPrototypeOf$1(current))); // Finally return false if the LightningElement is not part of the prototype chain.
4337
4253
 
4338
4254
 
4339
- templateVMs.add(vm); // tracking active styles associated to template
4255
+ return false;
4256
+ }
4340
4257
 
4341
- const stylesheets = tpl.stylesheets;
4258
+ function getComponentInternalDef(Ctor) {
4259
+ if (process.env.NODE_ENV !== 'production') {
4260
+ Ctor = getComponentOrSwappedComponent(Ctor);
4261
+ }
4342
4262
 
4343
- if (!isUndefined$1(stylesheets)) {
4344
- flattenStylesheets(stylesheets).forEach(stylesheet => {
4345
- // this is necessary because we don't hold the list of styles
4346
- // in the vm, we only hold the selected (already swapped template)
4347
- // but the styles attached to the template might not be the actual
4348
- // active ones, but the swapped versions of those.
4349
- stylesheet = getStyleOrSwappedStyle(stylesheet);
4350
- let stylesheetVMs = activeStyles.get(stylesheet);
4263
+ let def = CtorToDefMap.get(Ctor);
4351
4264
 
4352
- if (isUndefined$1(stylesheetVMs)) {
4353
- stylesheetVMs = new Set();
4354
- activeStyles.set(stylesheet, stylesheetVMs);
4355
- } // this will allow us to keep track of the stylesheet that are
4356
- // being used by a hot component
4265
+ if (isUndefined$1(def)) {
4266
+ if (isCircularModuleDependency(Ctor)) {
4267
+ const resolvedCtor = resolveCircularModuleDependency(Ctor);
4268
+ def = getComponentInternalDef(resolvedCtor); // Cache the unresolved component ctor too. The next time if the same unresolved ctor is used,
4269
+ // look up the definition in cache instead of re-resolving and recreating the def.
4357
4270
 
4271
+ CtorToDefMap.set(Ctor, def);
4272
+ return def;
4273
+ }
4358
4274
 
4359
- stylesheetVMs.add(vm);
4360
- });
4361
- }
4275
+ if (!isComponentConstructor(Ctor)) {
4276
+ throw new TypeError(`${Ctor} is not a valid component, or does not extends LightningElement from "lwc". You probably forgot to add the extend clause on the class declaration.`);
4362
4277
  }
4278
+
4279
+ def = createComponentDef(Ctor);
4280
+ CtorToDefMap.set(Ctor, def);
4363
4281
  }
4282
+
4283
+ return def;
4364
4284
  }
4365
4285
 
4366
- function removeActiveVM(vm) {
4367
- if (process.env.NODE_ENV === 'production') {
4368
- // this method should never leak to prod
4369
- throw new ReferenceError();
4370
- }
4286
+ const lightingElementDef = {
4287
+ ctor: LightningElement,
4288
+ name: LightningElement.name,
4289
+ props: lightningBasedDescriptors,
4290
+ propsConfig: EmptyObject,
4291
+ methods: EmptyObject,
4292
+ renderMode: 1
4293
+ /* Shadow */
4294
+ ,
4295
+ shadowSupportMode: "reset"
4296
+ /* Default */
4297
+ ,
4298
+ wire: EmptyObject,
4299
+ bridge: BaseBridgeElement,
4300
+ template: defaultEmptyTemplate,
4301
+ render: LightningElement.prototype.render
4302
+ };
4303
+ /**
4304
+ * EXPERIMENTAL: This function allows for the collection of internal component metadata. This API is
4305
+ * subject to change or being removed.
4306
+ */
4371
4307
 
4372
- if (runtimeFlags.ENABLE_HMR) {
4373
- // tracking inactive component
4374
- const Ctor = vm.def.ctor;
4375
- let list = activeComponents.get(Ctor);
4308
+ function getComponentDef(Ctor) {
4309
+ const def = getComponentInternalDef(Ctor); // From the internal def object, we need to extract the info that is useful
4310
+ // for some external services, e.g.: Locker Service, usually, all they care
4311
+ // is about the shape of the constructor, the internals of it are not relevant
4312
+ // because they don't have a way to mess with that.
4376
4313
 
4377
- if (!isUndefined$1(list)) {
4378
- // deleting the vm from the set to avoid leaking memory
4379
- list.delete(vm);
4380
- } // removing inactive template
4314
+ const {
4315
+ ctor,
4316
+ name,
4317
+ props,
4318
+ propsConfig,
4319
+ methods
4320
+ } = def;
4321
+ const publicProps = {};
4381
4322
 
4323
+ for (const key in props) {
4324
+ // avoid leaking the reference to the public props descriptors
4325
+ publicProps[key] = {
4326
+ config: propsConfig[key] || 0,
4327
+ type: "any"
4328
+ /* any */
4329
+ ,
4330
+ attr: htmlPropertyToAttribute(key)
4331
+ };
4332
+ }
4382
4333
 
4383
- const tpl = vm.cmpTemplate;
4334
+ const publicMethods = {};
4384
4335
 
4385
- if (tpl) {
4386
- list = activeTemplates.get(tpl);
4336
+ for (const key in methods) {
4337
+ // avoid leaking the reference to the public method descriptors
4338
+ publicMethods[key] = methods[key].value;
4339
+ }
4387
4340
 
4388
- if (!isUndefined$1(list)) {
4389
- // deleting the vm from the set to avoid leaking memory
4390
- list.delete(vm);
4391
- } // removing active styles associated to template
4341
+ return {
4342
+ ctor,
4343
+ name,
4344
+ props: publicProps,
4345
+ methods: publicMethods
4346
+ };
4347
+ }
4348
+ /*
4349
+ * Copyright (c) 2018, salesforce.com, inc.
4350
+ * All rights reserved.
4351
+ * SPDX-License-Identifier: MIT
4352
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4353
+ */
4392
4354
 
4393
4355
 
4394
- const styles = tpl.stylesheets;
4356
+ const xlinkNS = 'http://www.w3.org/1999/xlink';
4357
+ const xmlNS = 'http://www.w3.org/XML/1998/namespace';
4358
+ const ColonCharCode = 58;
4395
4359
 
4396
- if (!isUndefined$1(styles)) {
4397
- flattenStylesheets(styles).forEach(style => {
4398
- list = activeStyles.get(style);
4360
+ function patchAttributes(oldVnode, vnode) {
4361
+ const {
4362
+ attrs
4363
+ } = vnode.data;
4399
4364
 
4400
- if (!isUndefined$1(list)) {
4401
- // deleting the vm from the set to avoid leaking memory
4402
- list.delete(vm);
4403
- }
4404
- });
4405
- }
4406
- }
4365
+ if (isUndefined$1(attrs)) {
4366
+ return;
4407
4367
  }
4408
- }
4409
4368
 
4410
- function swapTemplate(oldTpl, newTpl) {
4411
- if (process.env.NODE_ENV !== 'production') {
4412
- if (isTemplateRegistered(oldTpl) && isTemplateRegistered(newTpl)) {
4413
- swappedTemplateMap.set(oldTpl, newTpl);
4414
- return rehydrateHotTemplate(oldTpl);
4415
- } else {
4416
- throw new TypeError(`Invalid Template`);
4417
- }
4418
- }
4369
+ const oldAttrs = isNull(oldVnode) ? EmptyObject : oldVnode.data.attrs;
4419
4370
 
4420
- if (!runtimeFlags.ENABLE_HMR) {
4421
- throw new Error('HMR is not enabled');
4371
+ if (oldAttrs === attrs) {
4372
+ return;
4422
4373
  }
4423
4374
 
4424
- return false;
4425
- }
4375
+ const {
4376
+ elm
4377
+ } = vnode;
4426
4378
 
4427
- function swapComponent(oldComponent, newComponent) {
4428
- if (process.env.NODE_ENV !== 'production') {
4429
- if (isComponentConstructor(oldComponent) && isComponentConstructor(newComponent)) {
4430
- swappedComponentMap.set(oldComponent, newComponent);
4431
- return rehydrateHotComponent(oldComponent);
4432
- } else {
4433
- throw new TypeError(`Invalid Component`);
4379
+ for (const key in attrs) {
4380
+ const cur = attrs[key];
4381
+ const old = oldAttrs[key];
4382
+
4383
+ if (old !== cur) {
4384
+ unlockAttribute(elm, key);
4385
+
4386
+ if (StringCharCodeAt.call(key, 3) === ColonCharCode) {
4387
+ // Assume xml namespace
4388
+ setAttribute$1(elm, key, cur, xmlNS);
4389
+ } else if (StringCharCodeAt.call(key, 5) === ColonCharCode) {
4390
+ // Assume xlink namespace
4391
+ setAttribute$1(elm, key, cur, xlinkNS);
4392
+ } else if (isNull(cur) || isUndefined$1(cur)) {
4393
+ removeAttribute$1(elm, key);
4394
+ } else {
4395
+ setAttribute$1(elm, key, cur);
4396
+ }
4397
+
4398
+ lockAttribute();
4434
4399
  }
4435
4400
  }
4401
+ }
4402
+ /*
4403
+ * Copyright (c) 2018, salesforce.com, inc.
4404
+ * All rights reserved.
4405
+ * SPDX-License-Identifier: MIT
4406
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4407
+ */
4436
4408
 
4437
- if (!runtimeFlags.ENABLE_HMR) {
4438
- throw new Error('HMR is not enabled');
4439
- }
4440
4409
 
4441
- return false;
4410
+ function isLiveBindingProp(sel, key) {
4411
+ // For properties with live bindings, we read values from the DOM element
4412
+ // instead of relying on internally tracked values.
4413
+ return sel === 'input' && (key === 'value' || key === 'checked');
4442
4414
  }
4443
4415
 
4444
- function swapStyle(oldStyle, newStyle) {
4445
- if (process.env.NODE_ENV !== 'production') {
4446
- // TODO [#1887]: once the support for registering styles is implemented
4447
- // we can add the validation of both styles around this block.
4448
- swappedStyleMap.set(oldStyle, newStyle);
4449
- return rehydrateHotStyle(oldStyle);
4416
+ function patchProps(oldVnode, vnode) {
4417
+ const {
4418
+ props
4419
+ } = vnode.data;
4420
+
4421
+ if (isUndefined$1(props)) {
4422
+ return;
4450
4423
  }
4451
4424
 
4452
- if (!runtimeFlags.ENABLE_HMR) {
4453
- throw new Error('HMR is not enabled');
4425
+ const oldProps = isNull(oldVnode) ? EmptyObject : oldVnode.data.props;
4426
+
4427
+ if (oldProps === props) {
4428
+ return;
4454
4429
  }
4455
4430
 
4456
- return false;
4431
+ const isFirstPatch = isNull(oldVnode);
4432
+ const {
4433
+ elm,
4434
+ sel
4435
+ } = vnode;
4436
+
4437
+ for (const key in props) {
4438
+ const cur = props[key]; // Set the property if it's the first time is is patched or if the previous property is
4439
+ // different than the one previously set.
4440
+
4441
+ if (isFirstPatch || cur !== (isLiveBindingProp(sel, key) ? getProperty$1(elm, key) : oldProps[key])) {
4442
+ setProperty$1(elm, key, cur);
4443
+ }
4444
+ }
4457
4445
  }
4458
4446
  /*
4459
4447
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4463,264 +4451,188 @@
4463
4451
  */
4464
4452
 
4465
4453
 
4466
- const CtorToDefMap = new WeakMap();
4454
+ const classNameToClassMap = create(null);
4467
4455
 
4468
- function getCtorProto(Ctor) {
4469
- let proto = getPrototypeOf$1(Ctor);
4456
+ function getMapFromClassName(className) {
4457
+ // Intentionally using == to match undefined and null values from computed style attribute
4458
+ if (className == null) {
4459
+ return EmptyObject;
4460
+ } // computed class names must be string
4470
4461
 
4471
- if (isNull(proto)) {
4472
- throw new ReferenceError(`Invalid prototype chain for ${Ctor.name}, you must extend LightningElement.`);
4473
- } // covering the cases where the ref is circular in AMD
4474
4462
 
4463
+ className = isString(className) ? className : className + '';
4464
+ let map = classNameToClassMap[className];
4475
4465
 
4476
- if (isCircularModuleDependency(proto)) {
4477
- const p = resolveCircularModuleDependency(proto);
4466
+ if (map) {
4467
+ return map;
4468
+ }
4478
4469
 
4479
- if (process.env.NODE_ENV !== 'production') {
4480
- if (isNull(p)) {
4481
- throw new ReferenceError(`Circular module dependency for ${Ctor.name}, must resolve to a constructor that extends LightningElement.`);
4482
- }
4483
- } // escape hatch for Locker and other abstractions to provide their own base class instead
4484
- // of our Base class without having to leak it to user-land. If the circular function returns
4485
- // itself, that's the signal that we have hit the end of the proto chain, which must always
4486
- // be base.
4470
+ map = create(null);
4471
+ let start = 0;
4472
+ let o;
4473
+ const len = className.length;
4487
4474
 
4475
+ for (o = 0; o < len; o++) {
4476
+ if (StringCharCodeAt.call(className, o) === SPACE_CHAR) {
4477
+ if (o > start) {
4478
+ map[StringSlice.call(className, start, o)] = true;
4479
+ }
4488
4480
 
4489
- proto = p === proto ? LightningElement : p;
4481
+ start = o + 1;
4482
+ }
4490
4483
  }
4491
4484
 
4492
- return proto;
4493
- }
4485
+ if (o > start) {
4486
+ map[StringSlice.call(className, start, o)] = true;
4487
+ }
4494
4488
 
4495
- function createComponentDef(Ctor) {
4496
- const {
4497
- shadowSupportMode: ctorShadowSupportMode,
4498
- renderMode: ctorRenderMode
4499
- } = Ctor;
4489
+ classNameToClassMap[className] = map;
4500
4490
 
4501
4491
  if (process.env.NODE_ENV !== 'production') {
4502
- const ctorName = Ctor.name; // Removing the following assert until https://bugs.webkit.org/show_bug.cgi?id=190140 is fixed.
4503
- // assert.isTrue(ctorName && isString(ctorName), `${toString(Ctor)} should have a "name" property with string value, but found ${ctorName}.`);
4504
-
4505
- assert.isTrue(Ctor.constructor, `Missing ${ctorName}.constructor, ${ctorName} should have a "constructor" property.`);
4506
-
4507
- if (!isUndefined$1(ctorShadowSupportMode)) {
4508
- assert.invariant(ctorShadowSupportMode === "any"
4509
- /* Any */
4510
- || ctorShadowSupportMode === "reset"
4511
- /* Default */
4512
- , `Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
4513
- }
4514
-
4515
- if (!isUndefined$1(ctorRenderMode)) {
4516
- assert.invariant(ctorRenderMode === 'light' || ctorRenderMode === 'shadow', `Invalid value for static property renderMode: '${ctorRenderMode}'. renderMode must be either 'light' or 'shadow'.`);
4517
- }
4492
+ // just to make sure that this object never changes as part of the diffing algo
4493
+ freeze(map);
4518
4494
  }
4519
4495
 
4520
- const decoratorsMeta = getDecoratorsMeta(Ctor);
4496
+ return map;
4497
+ }
4498
+
4499
+ function patchClassAttribute(oldVnode, vnode) {
4521
4500
  const {
4522
- apiFields,
4523
- apiFieldsConfig,
4524
- apiMethods,
4525
- wiredFields,
4526
- wiredMethods,
4527
- observedFields
4528
- } = decoratorsMeta;
4529
- const proto = Ctor.prototype;
4530
- let {
4531
- connectedCallback,
4532
- disconnectedCallback,
4533
- renderedCallback,
4534
- errorCallback,
4535
- render
4536
- } = proto;
4537
- const superProto = getCtorProto(Ctor);
4538
- const superDef = superProto !== LightningElement ? getComponentInternalDef(superProto) : lightingElementDef;
4539
- const bridge = HTMLBridgeElementFactory(superDef.bridge, keys(apiFields), keys(apiMethods));
4540
- const props = assign(create(null), superDef.props, apiFields);
4541
- const propsConfig = assign(create(null), superDef.propsConfig, apiFieldsConfig);
4542
- const methods = assign(create(null), superDef.methods, apiMethods);
4543
- const wire = assign(create(null), superDef.wire, wiredFields, wiredMethods);
4544
- connectedCallback = connectedCallback || superDef.connectedCallback;
4545
- disconnectedCallback = disconnectedCallback || superDef.disconnectedCallback;
4546
- renderedCallback = renderedCallback || superDef.renderedCallback;
4547
- errorCallback = errorCallback || superDef.errorCallback;
4548
- render = render || superDef.render;
4549
- let shadowSupportMode = superDef.shadowSupportMode;
4501
+ elm,
4502
+ data: {
4503
+ className: newClass
4504
+ }
4505
+ } = vnode;
4506
+ const oldClass = isNull(oldVnode) ? undefined : oldVnode.data.className;
4550
4507
 
4551
- if (!isUndefined$1(ctorShadowSupportMode)) {
4552
- shadowSupportMode = ctorShadowSupportMode;
4508
+ if (oldClass === newClass) {
4509
+ return;
4553
4510
  }
4554
4511
 
4555
- let renderMode = superDef.renderMode;
4512
+ const classList = getClassList$1(elm);
4513
+ const newClassMap = getMapFromClassName(newClass);
4514
+ const oldClassMap = getMapFromClassName(oldClass);
4515
+ let name;
4556
4516
 
4557
- if (!isUndefined$1(ctorRenderMode)) {
4558
- renderMode = ctorRenderMode === 'light' ? 0
4559
- /* Light */
4560
- : 1
4561
- /* Shadow */
4562
- ;
4517
+ for (name in oldClassMap) {
4518
+ // remove only if it is not in the new class collection and it is not set from within the instance
4519
+ if (isUndefined$1(newClassMap[name])) {
4520
+ classList.remove(name);
4521
+ }
4563
4522
  }
4564
4523
 
4565
- const template = getComponentRegisteredTemplate(Ctor) || superDef.template;
4566
- const name = Ctor.name || superDef.name; // installing observed fields into the prototype.
4567
-
4568
- defineProperties(proto, observedFields);
4569
- const def = {
4570
- ctor: Ctor,
4571
- name,
4572
- wire,
4573
- props,
4574
- propsConfig,
4575
- methods,
4576
- bridge,
4577
- template,
4578
- renderMode,
4579
- shadowSupportMode,
4580
- connectedCallback,
4581
- disconnectedCallback,
4582
- renderedCallback,
4583
- errorCallback,
4584
- render
4585
- };
4586
-
4587
- if (process.env.NODE_ENV !== 'production') {
4588
- freeze(Ctor.prototype);
4524
+ for (name in newClassMap) {
4525
+ if (isUndefined$1(oldClassMap[name])) {
4526
+ classList.add(name);
4527
+ }
4589
4528
  }
4590
-
4591
- return def;
4592
4529
  }
4593
- /**
4594
- * EXPERIMENTAL: This function allows for the identification of LWC constructors. This API is
4595
- * subject to change or being removed.
4530
+ /*
4531
+ * Copyright (c) 2018, salesforce.com, inc.
4532
+ * All rights reserved.
4533
+ * SPDX-License-Identifier: MIT
4534
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4596
4535
  */
4597
4536
 
4598
4537
 
4599
- function isComponentConstructor(ctor) {
4600
- if (!isFunction$1(ctor)) {
4601
- return false;
4602
- } // Fast path: LightningElement is part of the prototype chain of the constructor.
4603
-
4604
-
4605
- if (ctor.prototype instanceof LightningElement) {
4606
- return true;
4607
- } // Slow path: LightningElement is not part of the prototype chain of the constructor, we need
4608
- // climb up the constructor prototype chain to check in case there are circular dependencies
4609
- // to resolve.
4610
-
4611
-
4612
- let current = ctor;
4613
-
4614
- do {
4615
- if (isCircularModuleDependency(current)) {
4616
- const circularResolved = resolveCircularModuleDependency(current); // If the circular function returns itself, that's the signal that we have hit the end
4617
- // of the proto chain, which must always be a valid base constructor.
4618
-
4619
- if (circularResolved === current) {
4620
- return true;
4621
- }
4622
-
4623
- current = circularResolved;
4538
+ function patchStyleAttribute(oldVnode, vnode) {
4539
+ const {
4540
+ elm,
4541
+ data: {
4542
+ style: newStyle
4624
4543
  }
4544
+ } = vnode;
4545
+ const oldStyle = isNull(oldVnode) ? undefined : oldVnode.data.style;
4625
4546
 
4626
- if (current === LightningElement) {
4627
- return true;
4628
- }
4629
- } while (!isNull(current) && (current = getPrototypeOf$1(current))); // Finally return false if the LightningElement is not part of the prototype chain.
4547
+ if (oldStyle === newStyle) {
4548
+ return;
4549
+ }
4550
+
4551
+ if (!isString(newStyle) || newStyle === '') {
4552
+ removeAttribute$1(elm, 'style');
4553
+ } else {
4554
+ setAttribute$1(elm, 'style', newStyle);
4555
+ }
4556
+ }
4557
+ /*
4558
+ * Copyright (c) 2018, salesforce.com, inc.
4559
+ * All rights reserved.
4560
+ * SPDX-License-Identifier: MIT
4561
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4562
+ */
4630
4563
 
4631
4564
 
4632
- return false;
4633
- }
4565
+ function applyEventListeners(vnode) {
4566
+ const {
4567
+ elm,
4568
+ data: {
4569
+ on
4570
+ }
4571
+ } = vnode;
4634
4572
 
4635
- function getComponentInternalDef(Ctor) {
4636
- if (process.env.NODE_ENV !== 'production') {
4637
- Ctor = getComponentOrSwappedComponent(Ctor);
4573
+ if (isUndefined$1(on)) {
4574
+ return;
4638
4575
  }
4639
4576
 
4640
- let def = CtorToDefMap.get(Ctor);
4641
-
4642
- if (isUndefined$1(def)) {
4643
- if (isCircularModuleDependency(Ctor)) {
4644
- const resolvedCtor = resolveCircularModuleDependency(Ctor);
4645
- def = getComponentInternalDef(resolvedCtor); // Cache the unresolved component ctor too. The next time if the same unresolved ctor is used,
4646
- // look up the definition in cache instead of re-resolving and recreating the def.
4577
+ for (const name in on) {
4578
+ const handler = on[name];
4579
+ addEventListener$1(elm, name, handler);
4580
+ }
4581
+ }
4582
+ /*
4583
+ * Copyright (c) 2018, salesforce.com, inc.
4584
+ * All rights reserved.
4585
+ * SPDX-License-Identifier: MIT
4586
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4587
+ */
4588
+ // The compiler takes care of transforming the inline classnames into an object. It's faster to set the
4589
+ // different classnames properties individually instead of via a string.
4647
4590
 
4648
- CtorToDefMap.set(Ctor, def);
4649
- return def;
4650
- }
4651
4591
 
4652
- if (!isComponentConstructor(Ctor)) {
4653
- throw new TypeError(`${Ctor} is not a valid component, or does not extends LightningElement from "lwc". You probably forgot to add the extend clause on the class declaration.`);
4592
+ function applyStaticClassAttribute(vnode) {
4593
+ const {
4594
+ elm,
4595
+ data: {
4596
+ classMap
4654
4597
  }
4598
+ } = vnode;
4655
4599
 
4656
- def = createComponentDef(Ctor);
4657
- CtorToDefMap.set(Ctor, def);
4600
+ if (isUndefined$1(classMap)) {
4601
+ return;
4658
4602
  }
4659
4603
 
4660
- return def;
4661
- }
4604
+ const classList = getClassList$1(elm);
4662
4605
 
4663
- const lightingElementDef = {
4664
- ctor: LightningElement,
4665
- name: LightningElement.name,
4666
- props: lightningBasedDescriptors,
4667
- propsConfig: EmptyObject,
4668
- methods: EmptyObject,
4669
- renderMode: 1
4670
- /* Shadow */
4671
- ,
4672
- shadowSupportMode: "reset"
4673
- /* Default */
4674
- ,
4675
- wire: EmptyObject,
4676
- bridge: BaseBridgeElement,
4677
- template: defaultEmptyTemplate,
4678
- render: LightningElement.prototype.render
4679
- };
4680
- /**
4681
- * EXPERIMENTAL: This function allows for the collection of internal component metadata. This API is
4682
- * subject to change or being removed.
4606
+ for (const name in classMap) {
4607
+ classList.add(name);
4608
+ }
4609
+ }
4610
+ /*
4611
+ * Copyright (c) 2018, salesforce.com, inc.
4612
+ * All rights reserved.
4613
+ * SPDX-License-Identifier: MIT
4614
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4683
4615
  */
4616
+ // The compiler takes care of transforming the inline style into an object. It's faster to set the
4617
+ // different style properties individually instead of via a string.
4684
4618
 
4685
- function getComponentDef(Ctor) {
4686
- const def = getComponentInternalDef(Ctor); // From the internal def object, we need to extract the info that is useful
4687
- // for some external services, e.g.: Locker Service, usually, all they care
4688
- // is about the shape of the constructor, the internals of it are not relevant
4689
- // because they don't have a way to mess with that.
4690
4619
 
4620
+ function applyStaticStyleAttribute(vnode) {
4691
4621
  const {
4692
- ctor,
4693
- name,
4694
- props,
4695
- propsConfig,
4696
- methods
4697
- } = def;
4698
- const publicProps = {};
4622
+ elm,
4623
+ data: {
4624
+ styleDecls
4625
+ }
4626
+ } = vnode;
4699
4627
 
4700
- for (const key in props) {
4701
- // avoid leaking the reference to the public props descriptors
4702
- publicProps[key] = {
4703
- config: propsConfig[key] || 0,
4704
- type: "any"
4705
- /* any */
4706
- ,
4707
- attr: htmlPropertyToAttribute(key)
4708
- };
4628
+ if (isUndefined$1(styleDecls)) {
4629
+ return;
4709
4630
  }
4710
4631
 
4711
- const publicMethods = {};
4712
-
4713
- for (const key in methods) {
4714
- // avoid leaking the reference to the public method descriptors
4715
- publicMethods[key] = methods[key].value;
4632
+ for (let i = 0; i < styleDecls.length; i++) {
4633
+ const [prop, value, important] = styleDecls[i];
4634
+ setCSSStyleProperty$1(elm, prop, value, important);
4716
4635
  }
4717
-
4718
- return {
4719
- ctor,
4720
- name,
4721
- props: publicProps,
4722
- methods: publicMethods
4723
- };
4724
4636
  }
4725
4637
  /*
4726
4638
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4794,28 +4706,24 @@
4794
4706
  }
4795
4707
  }
4796
4708
 
4797
- function createElmHook(vnode) {
4798
- modEvents.create(vnode); // Attrs need to be applied to element before props
4799
- // IE11 will wipe out value on radio inputs if value
4800
- // is set before type=radio.
4709
+ function patchElementPropsAndAttrs(oldVnode, vnode) {
4710
+ if (isNull(oldVnode)) {
4711
+ applyEventListeners(vnode);
4712
+ applyStaticClassAttribute(vnode);
4713
+ applyStaticStyleAttribute(vnode);
4714
+ } // Attrs need to be applied to element before props IE11 will wipe out value on radio inputs if
4715
+ // value is set before type=radio.
4801
4716
 
4802
- modAttrs.create(vnode);
4803
- modProps.create(vnode);
4804
- modStaticClassName.create(vnode);
4805
- modStaticStyle.create(vnode);
4806
- modComputedClassName.create(vnode);
4807
- modComputedStyle.create(vnode);
4717
+
4718
+ patchClassAttribute(oldVnode, vnode);
4719
+ patchStyleAttribute(oldVnode, vnode);
4720
+ patchAttributes(oldVnode, vnode);
4721
+ patchProps(oldVnode, vnode);
4808
4722
  }
4809
4723
 
4810
4724
  function hydrateElmHook(vnode) {
4811
- modEvents.create(vnode); // Attrs are already on the element.
4812
- // modAttrs.create(vnode);
4813
-
4814
- modProps.create(vnode); // Already set.
4815
- // modStaticClassName.create(vnode);
4816
- // modStaticStyle.create(vnode);
4817
- // modComputedClassName.create(vnode);
4818
- // modComputedStyle.create(vnode);
4725
+ applyEventListeners(vnode);
4726
+ patchProps(null, vnode);
4819
4727
  }
4820
4728
 
4821
4729
  function fallbackElmHook(elm, vnode) {
@@ -4867,26 +4775,11 @@
4867
4775
  }
4868
4776
  }
4869
4777
 
4870
- function updateElmHook(oldVnode, vnode) {
4871
- // Attrs need to be applied to element before props
4872
- // IE11 will wipe out value on radio inputs if value
4873
- // is set before type=radio.
4874
- modAttrs.update(oldVnode, vnode);
4875
- modProps.update(oldVnode, vnode);
4876
- modComputedClassName.update(oldVnode, vnode);
4877
- modComputedStyle.update(oldVnode, vnode);
4878
- }
4879
-
4880
- function updateChildrenHook(oldVnode, vnode) {
4881
- const {
4882
- elm,
4883
- children
4884
- } = vnode;
4885
-
4886
- if (hasDynamicChildren(children)) {
4887
- updateDynamicChildren(elm, oldVnode.children, children);
4778
+ function patchChildren(parent, oldCh, newCh) {
4779
+ if (hasDynamicChildren(newCh)) {
4780
+ updateDynamicChildren(parent, oldCh, newCh);
4888
4781
  } else {
4889
- updateStaticChildren(elm, oldVnode.children, children);
4782
+ updateStaticChildren(parent, oldCh, newCh);
4890
4783
  }
4891
4784
  }
4892
4785
 
@@ -4961,19 +4854,6 @@
4961
4854
  }
4962
4855
  }
4963
4856
 
4964
- function createCustomElmHook(vnode) {
4965
- modEvents.create(vnode); // Attrs need to be applied to element before props
4966
- // IE11 will wipe out value on radio inputs if value
4967
- // is set before type=radio.
4968
-
4969
- modAttrs.create(vnode);
4970
- modProps.create(vnode);
4971
- modStaticClassName.create(vnode);
4972
- modStaticStyle.create(vnode);
4973
- modComputedClassName.create(vnode);
4974
- modComputedStyle.create(vnode);
4975
- }
4976
-
4977
4857
  function createChildrenHook(vnode) {
4978
4858
  const {
4979
4859
  elm,
@@ -5154,16 +5034,6 @@
5154
5034
  }
5155
5035
  }
5156
5036
 
5157
- function updateCustomElmHook(oldVnode, vnode) {
5158
- // Attrs need to be applied to element before props
5159
- // IE11 will wipe out value on radio inputs if value
5160
- // is set before type=radio.
5161
- modAttrs.update(oldVnode, vnode);
5162
- modProps.update(oldVnode, vnode);
5163
- modComputedClassName.update(oldVnode, vnode);
5164
- modComputedStyle.update(oldVnode, vnode);
5165
- }
5166
-
5167
5037
  function removeElmHook(vnode) {
5168
5038
  // this method only needs to search on child vnodes from template
5169
5039
  // to trigger the remove hook just in case some of those children
@@ -5180,6 +5050,66 @@
5180
5050
  ch.hook.remove(ch, elm);
5181
5051
  }
5182
5052
  }
5053
+ }
5054
+
5055
+ function allocateInSlot(vm, children) {
5056
+ const {
5057
+ cmpSlots: oldSlots
5058
+ } = vm;
5059
+ const cmpSlots = vm.cmpSlots = create(null);
5060
+
5061
+ for (let i = 0, len = children.length; i < len; i += 1) {
5062
+ const vnode = children[i];
5063
+
5064
+ if (isNull(vnode)) {
5065
+ continue;
5066
+ }
5067
+
5068
+ const {
5069
+ data
5070
+ } = vnode;
5071
+ const slotName = data.attrs && data.attrs.slot || '';
5072
+ const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || []; // re-keying the vnodes is necessary to avoid conflicts with default content for the slot
5073
+ // which might have similar keys. Each vnode will always have a key that
5074
+ // starts with a numeric character from compiler. In this case, we add a unique
5075
+ // notation for slotted vnodes keys, e.g.: `@foo:1:1`
5076
+
5077
+ if (!isUndefined$1(vnode.key)) {
5078
+ vnode.key = `@${slotName}:${vnode.key}`;
5079
+ }
5080
+
5081
+ ArrayPush$1.call(vnodes, vnode);
5082
+ }
5083
+
5084
+ if (isFalse(vm.isDirty)) {
5085
+ // We need to determine if the old allocation is really different from the new one
5086
+ // and mark the vm as dirty
5087
+ const oldKeys = keys(oldSlots);
5088
+
5089
+ if (oldKeys.length !== keys(cmpSlots).length) {
5090
+ markComponentAsDirty(vm);
5091
+ return;
5092
+ }
5093
+
5094
+ for (let i = 0, len = oldKeys.length; i < len; i += 1) {
5095
+ const key = oldKeys[i];
5096
+
5097
+ if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
5098
+ markComponentAsDirty(vm);
5099
+ return;
5100
+ }
5101
+
5102
+ const oldVNodes = oldSlots[key];
5103
+ const vnodes = cmpSlots[key];
5104
+
5105
+ for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
5106
+ if (oldVNodes[j] !== vnodes[j]) {
5107
+ markComponentAsDirty(vm);
5108
+ return;
5109
+ }
5110
+ }
5111
+ }
5112
+ }
5183
5113
  } // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
5184
5114
 
5185
5115
 
@@ -5326,11 +5256,11 @@
5326
5256
  linkNodeToShadow(elm, owner);
5327
5257
  fallbackElmHook(elm, vnode);
5328
5258
  vnode.elm = elm;
5329
- createElmHook(vnode);
5259
+ patchElementPropsAndAttrs(null, vnode);
5330
5260
  },
5331
5261
  update: (oldVnode, vnode) => {
5332
- updateElmHook(oldVnode, vnode);
5333
- updateChildrenHook(oldVnode, vnode);
5262
+ patchElementPropsAndAttrs(oldVnode, vnode);
5263
+ patchChildren(vnode.elm, oldVnode.children, vnode.children);
5334
5264
  },
5335
5265
  insert: (vnode, parentNode, referenceNode) => {
5336
5266
  insertNodeHook(vnode, parentNode, referenceNode);
@@ -5404,10 +5334,10 @@
5404
5334
  throw new TypeError(`Incorrect Component Constructor`);
5405
5335
  }
5406
5336
 
5407
- createCustomElmHook(vnode);
5337
+ patchElementPropsAndAttrs(null, vnode);
5408
5338
  },
5409
5339
  update: (oldVnode, vnode) => {
5410
- updateCustomElmHook(oldVnode, vnode);
5340
+ patchElementPropsAndAttrs(oldVnode, vnode);
5411
5341
  const vm = getAssociatedVMIfPresent(vnode.elm);
5412
5342
 
5413
5343
  if (vm) {
@@ -5418,7 +5348,7 @@
5418
5348
  // will happen, but in native, it does allocate the light dom
5419
5349
 
5420
5350
 
5421
- updateChildrenHook(oldVnode, vnode);
5351
+ patchChildren(vnode.elm, oldVnode.children, vnode.children);
5422
5352
 
5423
5353
  if (vm) {
5424
5354
  if (process.env.NODE_ENV !== 'production') {
@@ -7118,7 +7048,6 @@
7118
7048
  // patch function mutates vnodes by adding the element reference,
7119
7049
  // however, if patching fails it contains partial changes.
7120
7050
  if (oldCh !== newCh) {
7121
- const fn = hasDynamicChildren(newCh) ? updateDynamicChildren : updateStaticChildren;
7122
7051
  runWithBoundaryProtection(vm, vm, () => {
7123
7052
  // pre
7124
7053
  logOperationStart(2
@@ -7126,8 +7055,8 @@
7126
7055
  , vm);
7127
7056
  }, () => {
7128
7057
  // job
7129
- const elementToRenderTo = getRenderRoot(vm);
7130
- fn(elementToRenderTo, oldCh, newCh);
7058
+ const renderRoot = getRenderRoot(vm);
7059
+ patchChildren(renderRoot, oldCh, newCh);
7131
7060
  }, () => {
7132
7061
  // post
7133
7062
  logOperationEnd(2
@@ -7422,69 +7351,6 @@
7422
7351
 
7423
7352
  currentVm = currentVm.owner;
7424
7353
  }
7425
- } // slow path routine
7426
- // NOTE: we should probably more this routine to the synthetic shadow folder
7427
- // and get the allocation to be cached by in the elm instead of in the VM
7428
-
7429
-
7430
- function allocateInSlot(vm, children) {
7431
- const {
7432
- cmpSlots: oldSlots
7433
- } = vm;
7434
- const cmpSlots = vm.cmpSlots = create(null);
7435
-
7436
- for (let i = 0, len = children.length; i < len; i += 1) {
7437
- const vnode = children[i];
7438
-
7439
- if (isNull(vnode)) {
7440
- continue;
7441
- }
7442
-
7443
- const {
7444
- data
7445
- } = vnode;
7446
- const slotName = data.attrs && data.attrs.slot || '';
7447
- const vnodes = cmpSlots[slotName] = cmpSlots[slotName] || []; // re-keying the vnodes is necessary to avoid conflicts with default content for the slot
7448
- // which might have similar keys. Each vnode will always have a key that
7449
- // starts with a numeric character from compiler. In this case, we add a unique
7450
- // notation for slotted vnodes keys, e.g.: `@foo:1:1`
7451
-
7452
- if (!isUndefined$1(vnode.key)) {
7453
- vnode.key = `@${slotName}:${vnode.key}`;
7454
- }
7455
-
7456
- ArrayPush$1.call(vnodes, vnode);
7457
- }
7458
-
7459
- if (isFalse(vm.isDirty)) {
7460
- // We need to determine if the old allocation is really different from the new one
7461
- // and mark the vm as dirty
7462
- const oldKeys = keys(oldSlots);
7463
-
7464
- if (oldKeys.length !== keys(cmpSlots).length) {
7465
- markComponentAsDirty(vm);
7466
- return;
7467
- }
7468
-
7469
- for (let i = 0, len = oldKeys.length; i < len; i += 1) {
7470
- const key = oldKeys[i];
7471
-
7472
- if (isUndefined$1(cmpSlots[key]) || oldSlots[key].length !== cmpSlots[key].length) {
7473
- markComponentAsDirty(vm);
7474
- return;
7475
- }
7476
-
7477
- const oldVNodes = oldSlots[key];
7478
- const vnodes = cmpSlots[key];
7479
-
7480
- for (let j = 0, a = cmpSlots[key].length; j < a; j += 1) {
7481
- if (oldVNodes[j] !== vnodes[j]) {
7482
- markComponentAsDirty(vm);
7483
- return;
7484
- }
7485
- }
7486
- }
7487
- }
7488
7354
  }
7489
7355
 
7490
7356
  function runWithBoundaryProtection(vm, owner, pre, job, post) {
@@ -7935,7 +7801,7 @@
7935
7801
  hooksAreSet = true;
7936
7802
  setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
7937
7803
  }
7938
- /* version: 2.7.2 */
7804
+ /* version: 2.7.3 */
7939
7805
 
7940
7806
  /*
7941
7807
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8637,7 +8503,7 @@
8637
8503
  });
8638
8504
  freeze(LightningElement);
8639
8505
  seal(LightningElement.prototype);
8640
- /* version: 2.7.2 */
8506
+ /* version: 2.7.3 */
8641
8507
 
8642
8508
  exports.LightningElement = LightningElement;
8643
8509
  exports.__unstable__ProfilerControl = profilerControl;