Node newName; if (name != null) { newName = processNameWithInlineJSDoc(name); } else { if (isDeclaration || isMember) {
Node newName; if (name != null) { newName = processNameWithInlineJSDoc(name); } else { if (isDeclaration || isMember) {
/** * Processes property name assignments in an object pattern. * * <p>Covers these cases. * * <pre><code> * let {name} = someObject; * let {key: name} = someObject; * let {key: name = something} = someObject; * </code></pre> */ private Node processObjectPatternPropertyNameAssignment( PropertyNameAssignmentTree propertyNameAssignment) { Node key = processObjectLitKeyAsString(propertyNameAssignment.name); key.setToken(Token.STRING_KEY); ParseTree targetTree = propertyNameAssignment.value; final Node valueNode; if (targetTree == null) { // `let { /** inlineType */ key } = something;` // The key is also the target name. valueNode = processNameWithInlineJSDoc(propertyNameAssignment.name.asIdentifier()); key.setShorthandProperty(true); } else { valueNode = processDestructuringElementTarget(targetTree); } key.addChildToFront(valueNode); return key; }
private Node processDestructuringElementTarget(ParseTree targetTree) { final Node valueNode; if (targetTree.type == ParseTreeType.DEFAULT_PARAMETER) { // let {key: /** inlineType */ name = default} = something; // let [/** inlineType */ name = default] = something; // processDefaultParameter() knows how to apply the inline JSDoc, if any, to the right node valueNode = processDefaultParameter(targetTree.asDefaultParameter()); } else if (targetTree.type == ParseTreeType.IDENTIFIER_EXPRESSION) { // let {key: /** inlineType */ name} = something // let [/** inlineType */ name] = something // Allow inline JSDoc on the name, since we may well be declaring it here. valueNode = processNameWithInlineJSDoc(targetTree.asIdentifierExpression()); } else { // ({prop: /** string */ ns.a.b} = someObject); // NOTE: CheckJSDoc will report an error for this case, since we want qualified names to be // declared with individual statements, like `/** @type {string} */ ns.a.b;` valueNode = transformNodeWithInlineJsDoc(targetTree); } return valueNode; }
Node processDefaultParameter(DefaultParameterTree tree) { maybeWarnForFeature(tree, Feature.DEFAULT_PARAMETERS); ParseTree targetTree = tree.lhs; Node targetNode; if (targetTree.type == ParseTreeType.IDENTIFIER_EXPRESSION) { // allow inline JSDoc on an identifier // let { /** inlineType */ x = defaultValue } = someObject; // TODO(bradfordcsmith): Do we need to allow inline JSDoc for qualified names, too? targetNode = processNameWithInlineJSDoc(targetTree.asIdentifierExpression()); } else { // ({prop: /** string */ ns.a.b = 'foo'} = someObject); // NOTE: CheckJSDoc will report an error for this case, since we want qualified names to be // declared with individual statements, like `/** @type {string} */ ns.a.b;` targetNode = transformNodeWithInlineJsDoc(targetTree); } Node defaultValueNode = newNode(Token.DEFAULT_VALUE, targetNode, transform(tree.defaultValue)); setSourceInfo(defaultValueNode, tree); return defaultValueNode; }
private Node processNameWithInlineJSDoc(IdentifierExpressionTree identifierExpression) { return processNameWithInlineJSDoc(identifierExpression.identifierToken); }