Open btopro opened 5 years ago
is this because we use a custom base class and or class mixins?
web-component-analyzer supports class mixins, so your code should work.
I have two suspicions:
Two questions:
--debug
? wca analyze video-player.js --outFile custom-elements.js --debug
{ _: [ 'analyze', 'video-player.js' ],
outFile: 'custom-elements.js',
debug: true }
[ '/Users/bto108/Documents/git/elmsln/company/factories/lrnwebcomponents/elements/video-player/video-player.js' ]
Analyzing 1 file...
[ { fileName:
'/Users/bto108/Documents/git/elmsln/company/factories/lrnwebcomponents/elements/video-player/video-player.js',
tags:
[ { fileName:
'/Users/bto108/Documents/git/elmsln/company/factories/lrnwebcomponents/elements/video-player/video-player.js',
tagName: '',
description:
'`video-player`\n`A simple responsive video player with ridiculously powerful backing`',
deprecated: undefined,
members: [],
slots: [],
events: [],
cssProperties: [] } ],
events: [] } ]
Writing result to "custom-elements.js"
from SchemaBehaviors.js:
/**
* Copyright 2018 The Pennsylvania State University
* @license Apache-2.0, see License.md for full text.
*/
export const SchemaBehaviors = function(SuperClass) {
return class extends SuperClass {
static get properties() {
let props = {
/**
* Unique Resource ID, generated when schemaMap processes.
*/
schemaResourceID: {
type: String,
value: ""
},
/**
* Schema Map for the element, used to generate a valid prefix on the fly
*/
schemaMap: {
type: Object,
readOnly: true,
value: {
prefix: {
oer: "http://oerschema.org/",
schema: "http://schema.org/",
dc: "http://purl.org/dc/terms/",
foaf: "http://xmlns.com/foaf/0.1/",
cc: "http://creativecommons.org/ns#",
bib: "http://bib.schema.org"
}
},
observer: "_schemaMapChanged"
}
};
if (super.properties) {
props = Object.assign(props, super.properties);
}
return props;
}
/**
* Generate a uinque ID
*/
generateResourceID() {
function idPart() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return (
"#" +
idPart() +
idPart() +
"-" +
idPart() +
"-" +
idPart() +
"-" +
idPart()
);
}
/**
* Notice the schema map has changed, reprocess attributes.
*/
_schemaMapChanged(newValue, oldValue) {
if (typeof newValue !== typeof undefined) {
// use this to tie into schemaResourceID build
this.schemaResourceID = this.getAttribute("resource");
// if it still doesn't have one then we have to check
if (this.schemaResourceID == "" || this.schemaResourceID == null) {
this.schemaResourceID = this.generateResourceID();
this.setAttribute("resource", this.schemaResourceID);
}
let prefixes = newValue.prefix;
let prefix = "";
// build prefix string
for (var property in prefixes) {
if (prefixes.hasOwnProperty(property)) {
prefix += property + ":" + prefixes[property] + " ";
}
}
// set prefix on the main element itself
if (prefix != "") {
this.setAttribute("prefix", prefix);
}
}
}
};
};
Thanks!
I tried to copy in your code, and WCA seems to finds the mixins. What happens if you add the following code to the files?
Add this to video-player.js
constructor () {
super();
this.foo = "bar";
}
and add this to SchemaBehaviors.js
static get observedAttributes () {
return ["bar"];
}
In my test it found both the property "foo" and the attribute "bar", but the files were in the same project. Therefore, I want to test if WCA is finding your source files. The source file comes from the dependency @lrnwebcomponents/schema-behaviors/schema-behaviors.js
, and I think the underlying (Typescript) parser is not finding them because it expects declaration files for libraries.
In addition, right now, the tool doesn't support assigning properties to a variable and then returning them (see static get properties()
in SchemaBehavior.js
), so I think that bug should be opened as a separate issue :-)
Including here so others can run but this is all I get as output: command:
wca analyze video-player.js --outFile custom-elements.js
output:Input file of
video-player.js
: