1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | const babel = require("@babel/types");
|
17 | const astValue = require("../javascript/ast-value");
|
18 | const ast_value_1 = require("../javascript/ast-value");
|
19 | const analyze_properties_1 = require("./analyze-properties");
|
20 | function getStaticGetterValue(node, name) {
|
21 | const getter = node.body.body.find((n) => babel.isClassMethod(n) && n.static === true &&
|
22 | n.kind === 'get' && ast_value_1.getIdentifierName(n.key) === name);
|
23 | if (!getter) {
|
24 | return undefined;
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 | const getterBody = getter.body;
|
30 | if (getterBody.body.length !== 1) {
|
31 |
|
32 | return undefined;
|
33 | }
|
34 | const statement = getterBody.body[0];
|
35 | if (!babel.isReturnStatement(statement)) {
|
36 |
|
37 | return undefined;
|
38 | }
|
39 | return statement.argument;
|
40 | }
|
41 | exports.getStaticGetterValue = getStaticGetterValue;
|
42 | function getIsValue(node) {
|
43 | const getterValue = getStaticGetterValue(node, 'is');
|
44 | if (!getterValue || !babel.isLiteral(getterValue)) {
|
45 |
|
46 | return undefined;
|
47 | }
|
48 | const value = astValue.expressionToValue(getterValue);
|
49 | if (typeof value !== 'string') {
|
50 | return undefined;
|
51 | }
|
52 | return value;
|
53 | }
|
54 | exports.getIsValue = getIsValue;
|
55 |
|
56 |
|
57 |
|
58 | function getPolymerProperties(node, document) {
|
59 | if (!babel.isClassDeclaration(node) && !babel.isClassExpression(node)) {
|
60 | return [];
|
61 | }
|
62 | const propertiesNode = getStaticGetterValue(node, 'properties');
|
63 | return propertiesNode ? analyze_properties_1.analyzeProperties(propertiesNode, document) : [];
|
64 | }
|
65 | exports.getPolymerProperties = getPolymerProperties;
|
66 |
|
\ | No newline at end of file |