本文整理汇总了TypeScript中@babel/core.transformFromAst函数的典型用法代码示例。如果您正苦于以下问题:TypeScript transformFromAst函数的具体用法?TypeScript transformFromAst怎么用?TypeScript transformFromAst使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了transformFromAst函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: transformDew
function transformDew (ast, source, resolveMap) {
const { code: dewTransform } = babel.transformFromAst(ast, source, {
babelrc: false,
babelrcRoots: false,
configFile: false,
highlightCode: false,
compact: false,
sourceType: 'script',
parserOpts: {
allowReturnOutsideFunction: true,
plugins: stage3Syntax
},
plugins: [[dewTransformPlugin, {
resolve: (name, opts) => {
if ((opts.optional || opts.wildcard) && !resolveMap[name])
return null;
return resolveMap[name];
},
wildcardExtensions: ['.js', '.json', '.node'],
esmDependencies: resolved => isESM(resolved),
filename: `import.meta.url.startsWith('file:') ? decodeURI(import.meta.url.slice(7 + (typeof process !== 'undefined' && process.platform === 'win32'))) : new URL(import.meta.url).pathname`,
dirname: `import.meta.url.startsWith('file:') ? decodeURI(import.meta.url.slice(0, import.meta.url.lastIndexOf('/')).slice(7 + (typeof process !== 'undefined' && process.platform === 'win32'))) : new URL(import.meta.url.slice(0, import.meta.url.lastIndexOf('/'))).pathname`
}]]
});
return dewTransform;
}
开发者ID:jspm,项目名称:jspm-cli,代码行数:26,代码来源:dew-worker.ts
示例2: resolve
return new Promise<Babel.BabelFileResult | null>((resolve) => {
Babel.transformFromAst(ast, code, options, (error, res) => {
if (error != null) {
console.error("fable: Error transforming Babel AST", error);
resolve(null);
} else {
resolve(res);
}
});
});
开发者ID:rfrerebe,项目名称:Fable,代码行数:10,代码来源:index.ts
示例3:
const options: babel.TransformOptions = {
ast: true,
sourceMaps: true
};
babel.transform("code();", options, (err, result) => {
const { code, map, ast } = result!;
});
const transformSyncResult = babel.transformSync("code();", options);
if (transformSyncResult) {
const { code, map, ast } = transformSyncResult;
}
babel.transformFile("filename.js", options, (err, result) => {
const { code, map, ast } = result!;
});
babel.transformFileSync("filename.js", options)!.code;
const sourceCode = "if (true) return;";
const parsedAst = babel.parse(sourceCode, options);
babel.transformFromAst(parsedAst!, sourceCode, options, (err, result) => {
const { code, map, ast } = result!;
});
const transformFromAstSyncResult = babel.transformFromAstSync(parsedAst!, sourceCode, options);
const { code, map, ast } = transformFromAstSyncResult!;
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:29,代码来源:babel__core-tests.ts
示例4: jsTransform
//.........这里部分代码省略.........
if (options.compile === true || options.compile === 'es5') {
doBabelTransform = true;
plugins.push(...babelTransformEs2015);
plugins.push(...babelTransformEs2016);
plugins.push(...babelTransformEs2017);
plugins.push(...babelTransformEs2018);
} else if (options.compile === 'es2015') {
doBabelTransform = true;
plugins.push(...babelTransformEs2016);
plugins.push(...babelTransformEs2017);
plugins.push(...babelTransformEs2018);
} else if (options.compile === 'es2016') {
doBabelTransform = true;
plugins.push(...babelTransformEs2017);
plugins.push(...babelTransformEs2018);
} else if (options.compile === 'es2017') {
doBabelTransform = true;
plugins.push(...babelTransformEs2018);
}
if (options.moduleResolution === 'node') {
if (!options.filePath) {
throw new Error(
'Cannot perform node module resolution without filePath.');
}
doBabelTransform = true;
plugins.push(resolveBareSpecifiers(
options.filePath,
!!options.isComponentRequest,
options.packageName,
options.componentDir,
options.rootDir));
}
// When the AMD option is "auto", these options will change based on whether
// we have a module or not (unless they are already definitely true).
let transformModulesToAmd = options.transformModulesToAmd;
if (transformModulesToAmd === true) {
doBabelTransform = true;
}
const maybeDoBabelTransform =
doBabelTransform || transformModulesToAmd === 'auto';
if (maybeDoBabelTransform) {
let ast;
try {
ast = babylon.parse(js, {
// TODO(aomarks) Remove any when typings are updated for babylon 7.
// tslint:disable-next-line: no-any
sourceType: transformModulesToAmd === 'auto' ? 'unambiguous' as any :
'module',
plugins: [
'asyncGenerators',
'dynamicImport',
// tslint:disable-next-line: no-any
'importMeta' as any,
'objectRestSpread',
],
});
} catch (e) {
if (options.softSyntaxError && e.constructor.name === 'SyntaxError') {
console.error(
'ERROR [polymer-build]: failed to parse JavaScript' +
(options.filePath ? ` (${options.filePath}):` : ':'),
e);
return js;
} else {
throw e;
}
}
if (transformModulesToAmd === 'auto' &&
ast.program.sourceType === 'module') {
transformModulesToAmd = true;
}
if (transformModulesToAmd) {
doBabelTransform = true;
plugins.push(...babelTransformModulesAmd);
}
if (doBabelTransform) {
const result = babelCore.transformFromAst(ast, js, {presets, plugins});
if (result.code === undefined) {
throw new Error(
'Babel transform failed: resulting code was undefined.');
}
js = result.code;
if (!options.externalHelpers && options.compile === 'es5' &&
js.includes('regeneratorRuntime')) {
js = externalJs.getRegeneratorRuntime() + js;
}
}
}
js = replaceTemplateObjectNames(js);
return js;
}
开发者ID:poehlmann,项目名称:EvaluacionDiferencialDeLaMemoria,代码行数:101,代码来源:js-transform.ts
注:本文中的@babel/core.transformFromAst函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论