Prechádzať zdrojové kódy

Merge remote-tracking branch 'simotod/master-ie11' into master-ie11

Keyur Shah 5 rokov pred
rodič
commit
51aac9ada4
5 zmenil súbory, kde vykonal 77 pridanie a 36 odobranie
  1. 1 1
      examples/index_ie11.html
  2. 37 1
      package-lock.json
  3. 1 0
      package.json
  4. 20 17
      rollup.config.js
  5. 18 17
      src/component.js

+ 1 - 1
examples/index_ie11.html

@@ -233,7 +233,7 @@
                     </div>
                 </td>
             </tr>
-            
+
             <tr>
                 <td>Transitions</td>
                 <td>

+ 37 - 1
package-lock.json

@@ -1,6 +1,6 @@
 {
   "name": "alpinejs",
-  "version": "1.2.0",
+  "version": "1.9.8",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {
@@ -4316,6 +4316,15 @@
         "js-tokens": "^3.0.0 || ^4.0.0"
       }
     },
+    "magic-string": {
+      "version": "0.25.3",
+      "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.3.tgz",
+      "integrity": "sha512-6QK0OpF/phMz0Q2AxILkX2mFhi7m+WMwTRg0LQKq/WBB0cDP4rYH3Wp4/d3OTXlrPLVJT/RFqj8tFeAR4nk8AA==",
+      "dev": true,
+      "requires": {
+        "sourcemap-codec": "^1.4.4"
+      }
+    },
     "make-dir": {
       "version": "2.1.0",
       "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz",
@@ -5233,6 +5242,27 @@
         "rollup-pluginutils": "^2.8.1"
       }
     },
+    "rollup-plugin-strip-code": {
+      "version": "0.2.7",
+      "resolved": "https://registry.npmjs.org/rollup-plugin-strip-code/-/rollup-plugin-strip-code-0.2.7.tgz",
+      "integrity": "sha512-+5t9u/VrHPSfiRWWKMVin+KOtFwFak337FAZxeTjxYDjB3DDoHBQRkXHQvBn713eAfW81t41mGuysqsMXiuTjw==",
+      "dev": true,
+      "requires": {
+        "magic-string": "0.25.3",
+        "rollup-pluginutils": "2.8.1"
+      },
+      "dependencies": {
+        "rollup-pluginutils": {
+          "version": "2.8.1",
+          "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.1.tgz",
+          "integrity": "sha512-J5oAoysWar6GuZo0s+3bZ6sVZAC0pfqKz68De7ZgDi5z63jOVZn1uJL/+z1jeKHNbGII8kAyHF5q8LnxSX5lQg==",
+          "dev": true,
+          "requires": {
+            "estree-walker": "^0.6.1"
+          }
+        }
+      }
+    },
     "rollup-plugin-terser": {
       "version": "5.1.3",
       "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-5.1.3.tgz",
@@ -5535,6 +5565,12 @@
       "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=",
       "dev": true
     },
+    "sourcemap-codec": {
+      "version": "1.4.8",
+      "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz",
+      "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==",
+      "dev": true
+    },
     "spdx-correct": {
       "version": "3.1.0",
       "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.0.tgz",

+ 1 - 0
package.json

@@ -27,6 +27,7 @@
     "rollup-plugin-babel": "^4.3.3",
     "rollup-plugin-filesize": "^6.2.1",
     "rollup-plugin-node-resolve": "^5.2.0",
+    "rollup-plugin-strip-code": "^0.2.7",
     "rollup-plugin-terser": "^5.1.3"
   },
   "dependencies": {}

+ 20 - 17
rollup.config.js

@@ -1,9 +1,8 @@
 import babel from 'rollup-plugin-babel';
 import filesize from 'rollup-plugin-filesize';
-import {
-    terser
-} from "rollup-plugin-terser";
+import { terser } from "rollup-plugin-terser";
 import resolve from "rollup-plugin-node-resolve"
+import stripCode from 'rollup-plugin-strip-code';
 
 
 export default [{
@@ -14,19 +13,23 @@ export default [{
             format: 'umd',
             sourcemap: true,
         },
-            plugins: [
-                resolve(),
-                filesize(),
-                terser({
-                    mangle: false,
-                    compress: {
-                        drop_debugger: false,
-                    },
-                }),
-                babel({
-                    exclude: 'node_modules/**'
-                })
-            ]
+        plugins: [
+            resolve(),
+            filesize(),
+            terser({
+                mangle: false,
+                compress: {
+                    drop_debugger: false,
+                },
+            }),
+            babel({
+                exclude: 'node_modules/**'
+            }),
+            stripCode({
+                start_comment: 'IE11-ONLY:START',
+                end_comment: 'IE11-ONLY:END'
+            })
+        ]
     },
     {
         input: 'src/index.js',
@@ -69,4 +72,4 @@ export default [{
             })
         ]
     }
-]
+]

+ 18 - 17
src/component.js

@@ -18,13 +18,13 @@ export default class Component {
 
         const unobservedData = saferEval(dataExpression, {})
 
-        // For IE11, add our magic properties to the original data for access.
-        // Since the polyfill proxy does not allow properties to be added after creation 
-        if (window.document.documentMode) {
-            unobservedData.$el = null 
-            unobservedData.$refs = null 
-            unobservedData.$nextTick = null 
-        }
+        /* IE11-ONLY:START */
+            // For IE11, add our magic properties to the original data for access.
+            // Since the polyfill proxy does not allow properties to be added after creation
+            unobservedData.$el = null
+            unobservedData.$refs = null
+            unobservedData.$nextTick = null
+        /* IE11-ONLY:END */
 
         // Construct a Proxy-based observable. This will be used to handle reactivity.
         this.$data = this.wrapDataInObservable(unobservedData)
@@ -330,21 +330,22 @@ export default class Component {
         var self = this
 
         var refObj = {}
-        
-        //add any properties that might be necessary for ie11 proxy
-        refObj.$isRefsProxy = false;
-        refObj.$isAlpineProxy = false;
-
-        // If we are in IE, since the polyfill needs all properties to be defined before building the proxy,
-        // we just loop on the element, look for any x-ref and create a the property on a fake object.
-        // We don't need to put a real value since it will be resolved by the proxy class
-        if (window.document.documentMode) {
+
+        /* IE11-ONLY:START */
+            //add any properties that might be necessary for ie11 proxy
+            refObj.$isRefsProxy = false;
+            refObj.$isAlpineProxy = false;
+
+            // If we are in IE, since the polyfill needs all properties to be defined before building the proxy,
+            // we just loop on the element, look for any x-ref and create a the property on a fake object.
+            // We don't need to put a real value since it will be resolved by the proxy class
             this.walkAndSkipNestedComponents(self.$el, el => {
                 if (el.hasAttribute('x-ref')) {
                     refObj[el.getAttribute('x-ref')] = true
                 }
             })
-        }
+        /* IE11-ONLY:END */
+
 
         // One of the goals of this is to not hold elements in memory, but rather re-evaluate
         // the DOM when the system needs something from it. This way, the framework is flexible and