use of com.google.javascript.jscomp.PolymerPass.MemberDefinition in project closure-compiler by google.
the class PolymerClassDefinition method removeBehaviorPropsOverlappingWithElementProps.
/**
* Removes any behavior properties from the given map that have the same name as a property in the
* given list.
*
* <p>For example, if a Polymer element with a property "name" depends on a behavior with a
* property "name", then this method removes the behavior property in favor of the element
* property.
*/
private static void removeBehaviorPropsOverlappingWithElementProps(Map<MemberDefinition, BehaviorDefinition> behaviorProps, List<MemberDefinition> polymerElementProps) {
if (behaviorProps == null) {
return;
}
Set<String> elementPropNames = polymerElementProps.stream().map(x -> x.name.getString()).collect(Collectors.toSet());
Iterator<Map.Entry<MemberDefinition, BehaviorDefinition>> behaviorsItr = behaviorProps.entrySet().iterator();
while (behaviorsItr.hasNext()) {
MemberDefinition memberDefinition = behaviorsItr.next().getKey();
if (elementPropNames.contains(memberDefinition.name.getString())) {
behaviorsItr.remove();
}
}
}
use of com.google.javascript.jscomp.PolymerPass.MemberDefinition in project closure-compiler by google.
the class PolymerPassStaticUtils method extractProperties.
/**
* Finds a list of {@link MemberDefinition}s for the {@code properties} block of the given
* descriptor Object literal.
*
* @param descriptor The Polymer properties configuration object literal node.
* @param constructor If we are finding the properties of an ES6 class, the constructor function
* node for that class, otherwise null. We'll prefer JSDoc from property initialization
* statements in this constructor over the JSDoc within the Polymer properties configuration
* object.
*/
static ImmutableList<MemberDefinition> extractProperties(Node descriptor, PolymerClassDefinition.DefinitionType defType, AbstractCompiler compiler, @Nullable Node constructor) {
Node properties = descriptor;
if (defType == PolymerClassDefinition.DefinitionType.ObjectLiteral) {
properties = NodeUtil.getFirstPropMatchingKey(descriptor, "properties");
}
if (properties == null) {
return ImmutableList.of();
}
Map<String, JSDocInfo> constructorPropertyJsDoc = new HashMap<>();
if (constructor != null) {
collectConstructorPropertyJsDoc(constructor, constructorPropertyJsDoc);
}
ImmutableList.Builder<MemberDefinition> members = ImmutableList.builder();
for (Node keyNode = properties.getFirstChild(); keyNode != null; keyNode = keyNode.getNext()) {
// The JSDoc for a Polymer property in the constructor should win over the JSDoc in the
// Polymer properties configuration object.
JSDocInfo constructorJsDoc = constructorPropertyJsDoc.get(keyNode.getString());
JSDocInfo propertiesConfigJsDoc = NodeUtil.getBestJSDocInfo(keyNode);
JSDocInfo bestJsDoc;
if (constructorJsDoc != null) {
bestJsDoc = constructorJsDoc;
if (propertiesConfigJsDoc != null) {
// Warn if the user put JSDoc in both places.
compiler.report(JSError.make(keyNode, POLYMER_MISPLACED_PROPERTY_JSDOC));
}
} else {
bestJsDoc = propertiesConfigJsDoc;
}
members.add(new MemberDefinition(bestJsDoc, keyNode, keyNode.getFirstChild()));
}
return members.build();
}
Aggregations