UNPKG

1.75 kBJavaScriptView Raw
1/**
2@license
3Copyright (c) 2020 The Polymer Project Authors. All rights reserved.
4This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7Code distributed by Google as part of the polymer project is also
8subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9*/
10var _a, _b;
11const nativeInsertBefore = Node.prototype.insertBefore;
12const nativeGetFirstChild = (_b =
13// In Chrome 41, `firstChild` is a data descriptor on every instance, not a
14// accessor descriptor on `Node.prototype`.
15(_a = Object.getOwnPropertyDescriptor(Node.prototype, 'firstChild')) === null || _a === void 0 ? void 0 : _a.get) !== null && _b !== void 0 ? _b :
16// In Safari 9, the `firstChild` descriptor's `get` and `set` are undefined.
17function () { return this.firstChild; };
18const installPrepend = (constructor) => {
19 const prototype = constructor.prototype;
20 if (prototype.hasOwnProperty('prepend')) {
21 return;
22 }
23 Object.defineProperty(prototype, 'prepend', {
24 configurable: true,
25 enumerable: true,
26 writable: true,
27 value: function prepend(...args) {
28 const firstChild = nativeGetFirstChild.call(this);
29 for (const arg of args) {
30 const newNode = typeof arg === 'string' ? document.createTextNode(arg) : arg;
31 nativeInsertBefore.call(this, newNode, firstChild);
32 }
33 }
34 });
35};
36installPrepend(Document);
37installPrepend(DocumentFragment);
38installPrepend(Element);
39//# sourceMappingURL=prepend.js.map
\No newline at end of file