本文整理汇总了TypeScript中@babel/generator.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: toMethodParam
export function toMethodParam(
nodeParam: babel.LVal, jsdocAnn?: jsdoc.Annotation): MethodParam {
const paramTags = new Map<string, doctrine.Tag>();
let name;
let defaultValue;
let rest;
if (jsdocAnn) {
for (const tag of (jsdocAnn.tags || [])) {
if (tag.title === 'param' && tag.name) {
paramTags.set(tag.name, tag);
}
}
}
if (babel.isIdentifier(nodeParam)) {
// Basic parameter: method(param)
name = nodeParam.name;
} else if (
babel.isRestElement(nodeParam) &&
babel.isIdentifier(nodeParam.argument)) {
// Rest parameter: method(...param)
name = nodeParam.argument.name;
rest = true;
} else if (
babel.isAssignmentPattern(nodeParam) &&
babel.isIdentifier(nodeParam.left)) {
// Parameter with a default: method(param = "default")
name = nodeParam.left.name;
defaultValue = generate(nodeParam.right).code;
} else {
// Some AST pattern we don't recognize. Hope the code generator does
// something reasonable.
name = generate(nodeParam).code;
}
let type;
let description;
const tag = paramTags.get(name);
if (tag) {
if (tag.type) {
type = doctrine.type.stringify(tag.type);
}
if (tag.description) {
description = tag.description;
}
}
const param: MethodParam = {name, type, defaultValue, rest, description};
return param;
}
示例2: rewriteBareModuleSpecifiers
export function rewriteBareModuleSpecifiers(
code: string, packageVersions: PackageVersionMap, rootPackage: string):
string {
const jsAST = babelParser.parse(
code, {sourceType: 'module', plugins: ['dynamicImport']});
for (const node of jsAST.program.body) {
if ((node.type === 'ImportDeclaration' ||
node.type === 'ExportNamedDeclaration' ||
node.type === 'ExportAllDeclaration') &&
node.source) {
if (isBareModuleSpecifier(node.source.value)) {
const parsedPackage = parsePackageName(node.source.value);
const version = packageVersions[parsedPackage.package];
const versionString = version ? '@' + version : '';
const queryString = rootPackage ? '?' + rootPackage : '';
node.source.value = `/${parsedPackage.package}${versionString}${
parsedPackage.path}${queryString}`;
} else {
// Append rootPackage to relative URLs.
const parsedUrl = url.parse(node.source.value);
if (!parsedUrl.protocol) {
parsedUrl.search = rootPackage || '';
node.source.value = url.format(parsedUrl);
}
}
}
}
const outputJs = babelGenerate(jsAST, {retainLines: true}, code);
return outputJs.code;
}
示例3: invariant
const evalFn = (n: t.Node) => {
// variable
if (t.isIdentifier(n)) {
invariant(
staticNamespace.hasOwnProperty(n.name),
'identifier not in staticNamespace'
);
return staticNamespace[n.name];
}
return vm.runInContext(`(${generate(n).code})`, evalContext);
};
示例4: it
it('returns the original prop value if no spread attributes appear before the requested prop', () => {
// TODO: update to use `resolves` when Jest 20 is released
const ast = parse(`<Block {...spread} thing={Wow} />`);
const statement = ast.program.body[0] as t.ExpressionStatement;
const jsxElement = statement.expression as t.JSXElement;
const node = jsxElement.openingElement;
const componentPropValue = getPropValueFromAttributes(
'thing',
node.attributes
);
expect(generate(componentPropValue).code).toEqual('Wow');
});
示例5: Error
node.attributes.forEach(attr => {
if (
!t.isJSXAttribute(attr) ||
typeof attr.name.name !== 'string' ||
!t.isJSXExpressionContainer(attr.value)
) {
throw new Error(
'Received invalid JSXAttribute: ' + generate(attr).code
);
}
testItems[nodeName.name].attrs[attr.name.name] = attr.value.expression;
});
示例6: invariant
// 1. idx is greater than propValue prop index
// 2. attr is a spread operator
(attr, idx): attr is t.JSXSpreadAttribute => {
if (t.isJSXSpreadAttribute(attr)) {
invariant(
// only allow member expressions and identifiers to be spread for now
t.isIdentifier(attr.argument) ||
t.isMemberExpression(attr.argument),
'Unhandled spread operator value of type `%s` (`%s`)',
attr.argument.type,
generate(attr).code
);
return idx > propIndex;
}
return false;
}
示例7: generate
const evalFn = n => vm.runInContext('(' + generate(n).code + ')', ctx);