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