1 | [](https://travis-ci.org/Polymer/polymer-analyzer)
|
2 | [](https://www.npmjs.com/package/polymer-analyzer)
|
3 |
|
4 | # Polymer Analyzer
|
5 |
|
6 | A static analysis framework for Web Components.
|
7 |
|
8 | ## Install
|
9 |
|
10 | ```
|
11 | npm install polymer-analyzer
|
12 | ```
|
13 |
|
14 | ## Usage
|
15 | ```js
|
16 | const {Analyzer, FsUrlLoader, PackageUrlResolver} = require('polymer-analyzer');
|
17 |
|
18 | const rootDir = process.cwd();
|
19 | const analyzer = new Analyzer({
|
20 | urlLoader: new FsUrlLoader(rootDir),
|
21 | urlResolver: new PackageUrlResolver({ packageDir: rootDir }),
|
22 | });
|
23 |
|
24 | // This path is relative to the root dir
|
25 | analyzer.analyze(['my-element.html']).then((analysis) => {
|
26 | // Print the name of every property on paper-button, and where it was
|
27 | // inherited from.
|
28 | const [paperButton] = analysis.getFeatures(
|
29 | {kind: 'element', id: 'paper-button', externalPackages: true});
|
30 | if (paperButton) {
|
31 | for (const [name, property] of paperButton.properties) {
|
32 | let message = `${name}`;
|
33 | if (property.inheritedFrom) {
|
34 | message += ` inherited from ${property.inheritedFrom}`;
|
35 | } else {
|
36 | message += ` was defined directly on paper-button`;
|
37 | }
|
38 | console.log(message);
|
39 | }
|
40 | } else {
|
41 | console.log(`my-element.html didn't define or import paper-button.`);
|
42 | }
|
43 | });
|
44 | ```
|
45 |
|
46 | ## What's it used for?
|
47 |
|
48 | * [webcomponents.org](https://webcomponents.org) - discovery, demos, and docs for web components
|
49 | * [polymer-linter](https://github.com/Polymer/polymer-linter) - lints the web
|
50 | * [polymer-build](https://github.com/Polymer/polymer-build) - performs HTML-aware buildtime optimization
|
51 | * [polymer-editor-service](https://github.com/Polymer/polymer-editor-service) - IDE plugin, provides live as-you-type help
|
52 |
|
53 | ## Developing
|
54 |
|
55 | Polymer Analyzer is supported on Node LTS and stable. It is written
|
56 | in TypeScript. All development dependencies are installed via npm.
|
57 |
|
58 | ```sh
|
59 | npm install
|
60 | npm test
|
61 | ```
|
62 |
|
63 | Or watch the source for changes, and run tests each time a file is modified:
|
64 |
|
65 | ```sh
|
66 | npm run test:watch
|
67 | ```
|
68 |
|
69 | ## Looking for Hydrolysis?
|
70 |
|
71 | Hydrolysis has been renamed to Polymer Analyzer for version 2. You can find the
|
72 | hydrolysis source on the
|
73 | [`hydrolysis-1.x`](https://github.com/Polymer/polymer-analyzer/tree/hydrolysis-1.x)
|
74 | branch.
|