本文整理汇总了TypeScript中@babel/types.isObjectProperty函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isObjectProperty函数的具体用法?TypeScript isObjectProperty怎么用?TypeScript isObjectProperty使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isObjectProperty函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: getSimpleObjectProperties
export function* getSimpleObjectProperties(node: babel.ObjectExpression) {
for (const property of node.properties) {
if (babel.isObjectProperty(property) || babel.isObjectMethod(property)) {
yield property;
}
}
}
开发者ID:Polymer,项目名称:tools,代码行数:7,代码来源:esutil.ts
示例2: toScannedMethod
export function toScannedMethod(
node: babel.ObjectProperty|babel.ObjectMethod|babel.ClassMethod,
sourceRange: SourceRange,
document: JavaScriptDocument): ScannedMethod {
const parsedJsdoc = jsdoc.parseJsdoc(getAttachedComment(node) || '');
const description = parsedJsdoc.description.trim();
const maybeName = getPropertyName(node);
const warnings: Warning[] = [];
if (!maybeName) {
warnings.push(new Warning({
code: 'unknown-method-name',
message: `Could not determine name of method from expression of type: ` +
`${node.key.type}`,
sourceRange: sourceRange,
severity: Severity.INFO,
parsedDocument: document
}));
}
const value = babel.isObjectProperty(node) ? node.value : node;
const result = getClosureType(value, parsedJsdoc, sourceRange, document);
const type = result.successful === true ? result.value : 'Function';
const name = maybeName || '';
const scannedMethod: ScannedMethod = {
name,
type,
description,
sourceRange,
warnings,
astNode: {language: 'js', node, containingDocument: document},
jsdoc: parsedJsdoc,
privacy: getOrInferPrivacy(name, parsedJsdoc)
};
if (value && babel.isFunction(value)) {
if (scannedMethod.jsdoc !== undefined) {
scannedMethod.return = getReturnFromAnnotation(scannedMethod.jsdoc);
}
if (scannedMethod.return === undefined) {
scannedMethod.return = inferReturnFromBody(value);
}
scannedMethod.params =
(value.params ||
[]).map((nodeParam) => toMethodParam(nodeParam, scannedMethod.jsdoc));
}
return scannedMethod;
}
开发者ID:Polymer,项目名称:tools,代码行数:52,代码来源:esutil.ts
示例3: toScannedPolymerProperty
export function toScannedPolymerProperty(
node: babel.ObjectMethod|babel.ObjectProperty|babel.ClassMethod,
sourceRange: SourceRange,
document: JavaScriptDocument): ScannedPolymerProperty|undefined {
const parsedJsdoc = jsdoc.parseJsdoc(getAttachedComment(node) || '');
const description = parsedJsdoc.description.trim();
const maybeName = getPropertyName(node);
const warnings: Warning[] = [];
if (!maybeName) {
warnings.push(new Warning({
code: 'unknown-prop-name',
message:
`Could not determine name of property from expression of type: ` +
`${node.key.type}`,
sourceRange: sourceRange,
severity: Severity.WARNING,
parsedDocument: document
}));
return;
}
const value = babel.isObjectProperty(node) ? node.value : node;
const typeResult = getClosureType(value, parsedJsdoc, sourceRange, document);
let type;
if (typeResult.successful) {
type = typeResult.value;
} else {
warnings.push(typeResult.error);
type = 'Object';
}
const name = maybeName || '';
const result: ScannedPolymerProperty = {
name,
type,
description,
sourceRange,
warnings,
astNode: {node, language: 'js', containingDocument: document},
isConfiguration: configurationProperties.has(name),
jsdoc: parsedJsdoc,
privacy: getOrInferPrivacy(name, parsedJsdoc)
};
return result;
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:48,代码来源:js-utils.ts
示例4: extractPropertiesFromClassOrObjectBody
export function extractPropertiesFromClassOrObjectBody(
node: babel.Class|babel.ObjectExpression,
document: JavaScriptDocument): Map<string, ScannedProperty> {
const properties = new Map<string, ScannedProperty>();
const accessors = new Map<string, {
getter?: babel.ClassMethod | babel.ObjectMethod,
setter?: babel.ClassMethod | babel.ObjectMethod
}>();
let body;
if (babel.isClass(node)) {
body = node.body.body;
} else {
body = node.properties;
}
for (const member of body) {
if (!babel.isMethod(member) && !babel.isObjectProperty(member)) {
continue;
}
const name = getPropertyName(member);
if (name === undefined) {
continue;
}
if (babel.isMethod(member) || babel.isFunction(member.value)) {
if (babel.isMethod(member) &&
(member.kind === 'get' || member.kind === 'set')) {
let accessor = accessors.get(name);
if (!accessor) {
accessor = {};
accessors.set(name, accessor);
}
if (member.kind === 'get') {
accessor.getter = member;
} else {
accessor.setter = member;
}
}
continue;
}
const astNode = member.key;
const sourceRange = document.sourceRangeForNode(member)!;
const jsdocAnn = jsdoc.parseJsdoc(getAttachedComment(member) || '');
const detectedType =
getClosureType(member.value, jsdocAnn, sourceRange, document);
let type: string|undefined = undefined;
if (detectedType.successful) {
type = detectedType.value;
}
properties.set(name, {
name,
astNode: {language: 'js', node: astNode, containingDocument: document},
type,
jsdoc: jsdocAnn,
sourceRange,
description: jsdocAnn ? jsdoc.getDescription(jsdocAnn) : undefined,
privacy: getOrInferPrivacy(name, jsdocAnn),
warnings: [],
readOnly: jsdoc.hasTag(jsdocAnn, 'readonly'),
});
}
for (const val of accessors.values()) {
let getter: ScannedProperty|null = null;
let setter: ScannedProperty|null = null;
if (val.getter) {
const parsedJsdoc =
jsdoc.parseJsdoc(getAttachedComment(val.getter) || '');
getter =
extractPropertyFromGetterOrSetter(val.getter, parsedJsdoc, document);
}
if (val.setter) {
const parsedJsdoc =
jsdoc.parseJsdoc(getAttachedComment(val.setter) || '');
setter =
extractPropertyFromGetterOrSetter(val.setter, parsedJsdoc, document);
}
const prop = getter || setter;
if (!prop) {
continue;
}
if (!prop.readOnly) {
prop.readOnly = (val.setter === undefined);
}
properties.set(prop.name, prop);
}
//.........这里部分代码省略.........
开发者ID:Polymer,项目名称:tools,代码行数:101,代码来源:esutil.ts
注:本文中的@babel/types.isObjectProperty函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论