@microsoft/api-extractor
Version:
Validate, document, and review the exported API for a TypeScript library
49 lines • 1.91 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
const ts = require("typescript");
const node_core_library_1 = require("@microsoft/node-core-library");
const AstItem_1 = require("./AstItem");
const AstMember_1 = require("./AstMember");
/**
* This class is part of the AstItem abstract syntax tree. It represents properties of classes or interfaces
* (It does not represent member methods)
*/
class AstProperty extends AstMember_1.AstMember {
constructor(options) {
super(options);
this.kind = AstItem_1.AstItemKind.Property;
const declaration = options.declaration;
if (declaration.type) {
this.type = node_core_library_1.Text.convertToLf(declaration.type.getText());
}
else {
this.hasIncompleteTypes = true;
this.type = 'any';
}
if (this.documentation.hasReadOnlyTag) {
this.isReadOnly = true;
}
else {
// Check for a readonly modifier
for (const modifier of declaration.modifiers || []) {
if (modifier.kind === ts.SyntaxKind.ReadonlyKeyword) {
this.isReadOnly = true;
}
}
}
this.isEventProperty = this.documentation.isEventProperty || false;
if (this.isEventProperty && !this.isReadOnly) {
this.reportWarning('The @eventProperty tag requires the property to be readonly');
}
}
getDeclarationLine() {
return super.getDeclarationLine({
type: this.type,
readonly: this.isReadOnly
});
}
}
exports.AstProperty = AstProperty;
//# sourceMappingURL=AstProperty.js.map