Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 Getters aren't recognized as properties #1536

Closed
ChadKillingsworth opened this issue Apr 26, 2017 · 4 comments
Closed

ES6 Getters aren't recognized as properties #1536

ChadKillingsworth opened this issue Apr 26, 2017 · 4 comments

Comments

@ChadKillingsworth
Copy link
Contributor

The analyzer seems to completely ignore ES6 getters - they are not recognized as properties.

We're beginning to switch our code base to use ES6 getters instead of computed properties.

class FooElement extends Polymer.Element {
  static get is() { return 'foo-element'; }

  get otherProp() {
    return 'some value';
  }
}
@rictic rictic self-assigned this Apr 26, 2017
@rictic
Copy link
Contributor

rictic commented Apr 26, 2017

I'm gonna do a pass in a bit where I'll recognize property declarations in constructors. Will be a good time to add this in too.

@baszczewski
Copy link

baszczewski commented Apr 29, 2017

This lack of functionality affects also: https://github.com/Polymer/polymer-analyzer/issues/329.

Is there any support for analyze elements which extends Polymer.Element with ES6 classes? For my example I don't get any elelements details:
test.html

<!--
  Test element.
-->

<script>

class FooElement extends Polymer.Element {
  static get is() { return 'foo-element'; }

  get otherProp() {
    return 'some value';
  }

  static get properties() {
    return {
      /**
      * Propety test.
      */
      type: {
        type: String
      }
    }
  }
}

</script>

Script.js

const Analyzer = require('polymer-analyzer').Analyzer;
const FSUrlLoader = require('polymer-analyzer/lib/url-loader/fs-url-loader').FSUrlLoader;

let analyzer = new Analyzer({
    urlLoader: new FSUrlLoader('build/debug/xxx/elements'),
});

analyzer.analyze(['test.html']).then(result => {
    // console.log('result', result);

    var doc = result.getDocument('test.html');

    for (const element of doc.getFeatures({kind: 'element'})) {
        console.log('element', element);
    }
});

@ChadKillingsworth
Copy link
Contributor Author

ChadKillingsworth commented May 16, 2017

@baszczewski You need annotations:

/**
 * @polymer
 * @customElement
 * @extends {Polymer.Element}
 */
class FooElement extends Polymer.Element { }

@rictic
Copy link
Contributor

rictic commented Jun 15, 2017

Alternatively you need to do customElements.define(FooElement.is, FooElement); in the same script that you declare FooElement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants