本文整理汇总了TypeScript中babel-traverse.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: rewriteExportAllToNamedExports
rewriteExportAllToNamedExports(node: babel.Node, analysis: Analysis) {
traverse(node, {
noScope: true,
ExportAllDeclaration: {
enter(path: NodePath<babel.ExportAllDeclaration>) {
const exportAllDeclaration = path.node;
const sourceUrl =
babel.isStringLiteral(exportAllDeclaration.source) &&
exportAllDeclaration.source.value;
if (!sourceUrl) {
return;
}
const sourceDocument = getAnalysisDocument(analysis, sourceUrl);
const documentExports = sourceDocument.getFeatures({kind: 'export'});
const specifiers: babel.ExportSpecifier[] = [];
for (const documentExport of documentExports) {
for (const exportIdentifier of documentExport.identifiers) {
const identifierValue = exportIdentifier.valueOf();
// It does not appear that `export * from` should re-export
// the default module export of a module.
if (identifierValue !== 'default') {
specifiers.push(babel.exportSpecifier(
babel.identifier(identifierValue),
babel.identifier(identifierValue)));
}
}
}
const namedExportDeclaration = babel.exportNamedDeclaration(
undefined, specifiers, babel.stringLiteral(sourceUrl));
rewriteObject(exportAllDeclaration, namedExportDeclaration);
}
}
});
}
开发者ID:Polymer,项目名称:tools,代码行数:34,代码来源:es6-rewriter.ts
示例2: _rewriteImportStatements
/**
* Rewrite import declarations source URLs reference the bundle URL for
* bundled files and import names to correspond to names as exported by
* bundles.
*/
private _rewriteImportStatements(baseUrl: ResolvedUrl, node: babel.Node) {
const this_ = this;
traverse(node, {
noScope: true,
// Dynamic import() syntax doesn't have full type support yet, so we
// have to use generic `enter` and walk all nodes until that's fixed.
// TODO(usergenic): Switch this to the `Import: { enter }` style
// after dynamic imports fully supported.
enter(path: NodePath) {
if (path.node.type === 'Import') {
this_._rewriteDynamicImport(baseUrl, node, path);
}
},
});
traverse(node, {
noScope: true,
ImportDeclaration: {
enter(path: NodePath) {
const importDeclaration = path.node as babel.ImportDeclaration;
if (!babel.isStringLiteral(importDeclaration.source)) {
// We can't actually handle values which are not string literals, so
// we'll skip them.
return;
}
const source = importDeclaration.source.value as ResolvedUrl;
const sourceBundle = this_.manifest.getBundleForFile(source);
// If there is no import bundle, then this URL is not bundled (maybe
// excluded or something) so we should just ensure the URL is
// converted back to a relative URL.
if (!sourceBundle) {
importDeclaration.source.value =
this_.bundler.analyzer.urlResolver.relative(baseUrl, source);
return;
}
for (const specifier of importDeclaration.specifiers) {
if (babel.isImportSpecifier(specifier)) {
this_._rewriteImportSpecifierName(
specifier, source, sourceBundle);
}
if (babel.isImportDefaultSpecifier(specifier)) {
this_._rewriteImportDefaultSpecifier(
specifier, source, sourceBundle);
}
if (babel.isImportNamespaceSpecifier(specifier)) {
this_._rewriteImportNamespaceSpecifier(
specifier, source, sourceBundle);
}
}
importDeclaration.source.value =
ensureLeadingDot(this_.bundler.analyzer.urlResolver.relative(
baseUrl, sourceBundle.url));
}
}
});
}
开发者ID:Polymer,项目名称:vulcanize,代码行数:61,代码来源:es6-rewriter.ts
示例3: isFileToBeTaroComponent
export function isFileToBeTaroComponent (
code: string,
sourcePath: string,
outputPath: string
) {
const {
buildAdapter,
sourceDir,
constantsReplaceList,
jsxAttributeNameReplace
} = getBuildData()
const transformResult: IWxTransformResult = wxTransformer({
code,
sourcePath: sourcePath,
sourceDir,
outputPath: outputPath,
isNormal: true,
isTyped: REG_TYPESCRIPT.test(sourcePath),
adapter: buildAdapter,
env: constantsReplaceList,
jsxAttributeNameReplace
})
const { ast }: IWxTransformResult = transformResult
let isTaroComponent = false
traverse(ast, {
ClassDeclaration (astPath) {
astPath.traverse({
ClassMethod (astPath) {
if (astPath.get('key').isIdentifier({ name: 'render' })) {
astPath.traverse({
JSXElement () {
isTaroComponent = true
}
})
}
}
})
},
ClassExpression (astPath) {
astPath.traverse({
ClassMethod (astPath) {
if (astPath.get('key').isIdentifier({ name: 'render' })) {
astPath.traverse({
JSXElement () {
isTaroComponent = true
}
})
}
}
})
}
})
return {
isTaroComponent,
transformResult
}
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:60,代码来源:component.ts
示例4: _deduplicateImportStatements
/**
* Attempts to reduce the number of distinct import declarations by combining
* those referencing the same source into the same declaration. Results in
* deduplication of imports of the same item as well.
*
* Before:
* import {a} from './module-1.js';
* import {b} from './module-1.js';
* import {c} from './module-2.js';
* After:
* import {a,b} from './module-1.js';
* import {c} from './module-2.js';
*/
private _deduplicateImportStatements(node: babel.Node) {
const importDeclarations = new Map<string, babel.ImportDeclaration>();
traverse(node, {
noScope: true,
ImportDeclaration: {
enter(path: NodePath) {
const importDeclaration = path.node;
if (!babel.isImportDeclaration(importDeclaration)) {
return;
}
const source = babel.isStringLiteral(importDeclaration.source) &&
importDeclaration.source.value;
if (!source) {
return;
}
const hasNamespaceSpecifier = importDeclaration.specifiers.some(
(s) => babel.isImportNamespaceSpecifier(s));
const hasDefaultSpecifier = importDeclaration.specifiers.some(
(s) => babel.isImportDefaultSpecifier(s));
if (!importDeclarations.has(source) && !hasNamespaceSpecifier &&
!hasDefaultSpecifier) {
importDeclarations.set(source, importDeclaration);
} else if (importDeclarations.has(source)) {
const existingDeclaration = importDeclarations.get(source)!;
for (const specifier of importDeclaration.specifiers) {
existingDeclaration.specifiers.push(specifier);
}
path.remove();
}
}
}
});
}
开发者ID:Polymer,项目名称:vulcanize,代码行数:46,代码来源:es6-rewriter.ts
示例5: _rewriteExportStatements
/**
* Rewrite export declarations source URLs to reference the bundle URL for
* bundled files.
*/
private _rewriteExportStatements(baseUrl: ResolvedUrl, node: babel.Node) {
const this_ = this;
traverse(node, {
noScope: true,
ExportNamedDeclaration: {
enter(path: NodePath<babel.ExportNamedDeclaration>) {
const exportNamedDeclaration = path.node;
if (!exportNamedDeclaration.source ||
!babel.isStringLiteral(exportNamedDeclaration.source)) {
// We can't rewrite a source if there isn't one or if it isn't a
// string literal in the first place.
return;
}
const source = exportNamedDeclaration.source.value as ResolvedUrl;
const sourceBundle = this_.manifest.getBundleForFile(source);
// If there is no bundle associated with the export from statement
// then the URL is not bundled (perhaps it was excluded) so we will
// just ensure the URL is converted back to a relative URL.
if (!sourceBundle) {
exportNamedDeclaration.source.value = ensureLeadingDot(
this_.bundler.analyzer.urlResolver.relative(baseUrl, source));
return;
}
exportNamedDeclaration.source.value =
ensureLeadingDot(this_.bundler.analyzer.urlResolver.relative(
baseUrl, sourceBundle.url));
}
}
});
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:34,代码来源:es6-rewriter.ts
示例6: evalClass
export function evalClass (ast: t.File, props = '', isRequire = false) {
let mainClass!: t.ClassDeclaration
const statements = new Set<t.ExpressionStatement>([
template('Current.inst = this;')() as any
])
traverse(ast, {
ClassDeclaration (path) {
mainClass = path.node
},
/**
* 目前 node 的版本支持不了 class-properties
* 但 babel 又有 bug,某些情况竟然把转换后的 class-properties 编译到 super 之前
* 不然用 babel.transformFromAst 就完事了
* 现在只能自己实现这个 feature 的部分功能了,真 tm 麻烦
* @TODO 有空再给他们提 PR 吧
*/
ClassProperty (path) {
const { key, value } = path.node
statements.add(t.expressionStatement(t.assignmentExpression(
'=',
t.memberExpression(
t.thisExpression(),
key
),
value
)))
path.remove()
}
})
for (const method of mainClass.body.body) {
// constructor 即便没有被定义也会被加上
if (t.isClassMethod(method) && method.kind === 'constructor') {
const index = method.body.body.findIndex(node => t.isSuper(node))
method.body.body.push(
t.expressionStatement(t.assignmentExpression(
'=',
t.memberExpression(
t.thisExpression(),
t.identifier('state')
),
t.callExpression(t.memberExpression(t.thisExpression(), t.identifier('_createData')), [])
))
)
method.body.body.splice(index, 0, ...statements)
}
}
let code = `function f() {};` +
generate(t.classDeclaration(t.identifier('Test'), t.identifier('f'), mainClass.body, [])).code +
';' + `var classInst = new Test(${props});classInst`
code = internalFunction + code
// tslint:disable-next-line
return eval(code)
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:58,代码来源:utils.ts
示例7: parseWXML
export function parseWXML (dirPath: string, wxml?: string, parseImport?: boolean): {
wxses: WXS[]
wxml?: t.Node
imports: Imports[]
refIds: Set<string>
} {
if (!parseImport) {
errors.length = 0
usedComponents.clear()
}
usedComponents.add('Block')
let wxses: WXS[] = []
let imports: Imports[] = []
const refIds = new Set<string>()
const loopIds = new Set<string>()
if (!wxml) {
return {
wxses,
imports,
refIds,
wxml: t.nullLiteral()
}
}
const nodes = removEmptyTextAndComment(parse(wxml.trim()))
const ast = t.file(
t.program(
[
t.expressionStatement(parseNode(
buildElement('block', nodes as Node[])
) as t.Expression)
],
[]
)
)
traverse(ast, createWxmlVistor(loopIds, refIds, dirPath, wxses, imports))
refIds.forEach(id => {
if (loopIds.has(id) || imports.filter(i => i.wxs).map(i => i.name).includes(id)) {
refIds.delete(id)
}
})
return {
wxses,
imports,
wxml: hydrate(ast),
refIds
}
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:50,代码来源:wxml.ts
示例8: traverse
const pickTheReturnOfWebpackResult = (ast: Node): Node => {
let expr = null;
traverse(ast, {
AssignmentExpression(nodePath) {
if (
nodePath.parentPath.parentPath.isProgram() &&
nodePath.get("left").get("object").equals("name", "module") &&
nodePath.get("left").get("property").equals("name", "exports")
) {
expr = nodePath.node.right;
}
},
});
return expr;
};
开发者ID:morlay,项目名称:babel-plugin-webpack-loaders-inline-exports,代码行数:17,代码来源:index.ts
示例9: moduleResolve
captureImports(ast) {
let imports = [];
let exports = [];
let reexports = [];
let exportAllSources = [];
traverse(ast, {
enter(path) {
if (path.isImportDeclaration()) {
imports.push(path.node);
}
}
});
return imports.map((imp) => {
return moduleResolve(imp.source.value, this.id);
});
}
开发者ID:chadhietala,项目名称:fs-graph-diff,代码行数:18,代码来源:module.ts
示例10: enter
rewriteEs6SourceUrlsToResolved(
node: babel.Node, jsImportResolvedUrls: Map<string, ResolvedUrl>) {
const rewriteDeclarationSource = {
enter(
path:
NodePath<babel.ExportAllDeclaration|
babel.ExportNamedDeclaration|babel.ImportDeclaration>) {
const declaration = path.node;
const source = declaration.source &&
babel.isStringLiteral(declaration.source) &&
declaration.source.value;
if (!source) {
return;
}
const resolution = jsImportResolvedUrls.get(source);
if (resolution) {
declaration.source!.value = resolution;
}
}
};
traverse(node, {
noScope: true,
ExportAllDeclaration: rewriteDeclarationSource,
ExportNamedDeclaration: rewriteDeclarationSource,
ImportDeclaration: rewriteDeclarationSource,
CallExpression: {
enter(path: NodePath<babel.Node>) {
const callExpression = path.node;
const callee = callExpression['callee']!;
const callArguments = callExpression['arguments']!;
if (!callee || !callArguments || callArguments.length < 1 ||
!babel.isStringLiteral(callArguments[0]!)) {
return;
}
if (callee.type === 'Import') {
callArguments[0].value =
jsImportResolvedUrls.get(callArguments[0].value);
}
}
}
});
}
开发者ID:Polymer,项目名称:tools,代码行数:42,代码来源:es6-rewriter.ts
注:本文中的babel-traverse.default函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论