OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 @license |
| 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 7 Code distributed by Google as part of the polymer project is also |
| 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 9 --> |
| 10 <link rel="import" href="../polymer/polymer.html"> |
| 11 <link rel="import" href="hydrolysis.html"> |
| 12 |
| 13 <script> |
| 14 (function() { |
| 15 var hydrolysis = require('hydrolysis'); |
| 16 |
| 17 Polymer({ |
| 18 |
| 19 is: 'hydrolysis-analyzer', |
| 20 |
| 21 properties: { |
| 22 |
| 23 /** |
| 24 * The URL to an import that declares (or transitively imports) the |
| 25 * elements that you wish to see analyzed. |
| 26 * |
| 27 * If the URL is relative, it will be resolved relative to the master |
| 28 * document. |
| 29 * |
| 30 * If you change this value after the `<hydrolysis-analyzer>` has been |
| 31 * instantiated, you must call `analyze()`. |
| 32 */ |
| 33 src: { |
| 34 type: String, |
| 35 }, |
| 36 |
| 37 /** |
| 38 * Whether _all_ dependencies should be loaded and analyzed. |
| 39 * |
| 40 * Turning this on will probably slow down the load process dramatically. |
| 41 */ |
| 42 transitive: { |
| 43 type: Boolean, |
| 44 }, |
| 45 |
| 46 /** |
| 47 * Whether the hydrolysis descriptors should be cleaned of redundant |
| 48 * properties. |
| 49 */ |
| 50 clean: { |
| 51 type: Boolean, |
| 52 }, |
| 53 |
| 54 /** The resultant `Analyzer` object from Hydrolysis. */ |
| 55 analyzer: { |
| 56 type: Object, |
| 57 readOnly: true, |
| 58 notify: true, |
| 59 }, |
| 60 |
| 61 /** Whether the analyzer is loading/analyzing resources. */ |
| 62 loading: { |
| 63 type: Boolean, |
| 64 readOnly: true, |
| 65 notify: true, |
| 66 }, |
| 67 |
| 68 }, |
| 69 |
| 70 ready: function() { |
| 71 this.analyze(); |
| 72 }, |
| 73 |
| 74 /** |
| 75 * Begins loading the imports referenced by `src`. |
| 76 * |
| 77 * If you make changes to this element's configuration, you must call this |
| 78 * function to kick off another analysis pass. |
| 79 */ |
| 80 analyze: function() { |
| 81 if (!this.src) { |
| 82 return; |
| 83 } |
| 84 // We can implement request cancellation when someone needs it. |
| 85 if (this.loading) { |
| 86 console.error('Analyzer is already loading a document:', this); |
| 87 return; |
| 88 } |
| 89 this._setLoading(true); |
| 90 |
| 91 var options = { |
| 92 clean: this.clean, |
| 93 filter: this.transitive ? function() { return false; } : null, |
| 94 attachAst: true, |
| 95 }; |
| 96 |
| 97 var baseUri = this.ownerDocument.baseURI; |
| 98 var srcUrl = new URL(this.src, baseUri).toString(); |
| 99 hydrolysis.Analyzer.analyze(srcUrl, options).then(function(analyzer) { |
| 100 this._setLoading(false); |
| 101 this._setAnalyzer(analyzer); |
| 102 }.bind(this)) |
| 103 .catch(function(error) { |
| 104 console.error('Failed to load source at:', this.src, error); |
| 105 console.error(error.stack); |
| 106 this._setLoading(false); |
| 107 this._setAnalyzer(null); |
| 108 }.bind(this)); |
| 109 }, |
| 110 |
| 111 }); |
| 112 |
| 113 })(); |
| 114 </script> |
OLD | NEW |