本文整理匯總了TypeScript中escodegen.generate函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript generate函數的具體用法?TypeScript generate怎麽用?TypeScript generate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了generate函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
enter: function (n:any) {
if (matcher(n)) {
var classname = escodegen.generate(n.arguments[0]).replace(/AWS\.(\w+)\.prototype/, "$1")
var methodList = n.arguments[1].properties.map((x:any) => {
var context = {
classname: classname,
name: x.key.name,
commentStr: (x.leadingComments && x.leadingComments.map((x: any) => { return x.value }).join('\n')) || ""
} as ExtraClientMethod
context.commentStr = context.commentStr.replace(/\n\s+\*/g, "\n *");
var m = /@api\s+private/.exec(context.commentStr)
if (m) {
return null
}
if (0 == context.commentStr.length) {
context.commentStr = null;
}
return context
}).filter((x: ExtraClientMethod) => {
return null != x
})
console.log("Adding class: ", classname, " and methods: ", methodList)
methodsToAdd[classname] = methodList
}
}
示例2: function
enter: function(n: any) {
if (matcher(n)) {
var classname = escodegen.generate(n.arguments[0]).replace(/AWS\.(\w+)\.prototype/, "$1")
var methodList = n.arguments[1].properties.map(function(x: any) { return x.key.name })
console.log("Adding class: ", classname, " and methods: ", methodList)
methodsToAdd[classname] = methodList
}
}
示例3: getLscAst
return qFs.read(inputLambdaScriptFile).then(function(lambdaScriptCode: string) {
const lscAst = getLscAst(lambdaScriptCode),
jsAst = astToJsAst(lscAst);
logger.debug({jsAst: jsAst}, 'Converted LambdaScript AST to JS AST');
const js = escodegen.generate(jsAst);
logger.debug({js: js}, 'Generated raw js');
const jsWithPrelude = withPrelude(js);
logger.debug({jsWithPrelude: jsWithPrelude}, 'Added prelude to raw js');
return qFs.write(outputJsFile, jsWithPrelude);
});
示例4: bundle
export function bundle(options: IBundleOptions, host: IHost = new DefaultHost()): string {
const context: IPaeckchenContext = {
config: createConfig(options, host),
host
};
if (!context.config.input.entryPoint) {
throw new Error('Missing entry-point');
}
const detectedGlobals: IDetectedGlobals = {
global: false,
process: false,
buffer: false
};
const paeckchenAst = parse(paeckchenSource);
const modules = getModules(paeckchenAst).elements;
const absoluteEntryPath = join(host.cwd(), context.config.input.entryPoint);
// start bundling...
enqueueModule(getModulePath('.', absoluteEntryPath, context));
while (bundleNextModule(modules, context, detectedGlobals)) {
process.stderr.write('.');
}
// ... when ready inject globals...
injectGlobals(detectedGlobals, paeckchenAst, context);
// ... and bundle global dependencies
while (bundleNextModule(modules, context, detectedGlobals)) {
process.stderr.write('.');
}
process.stderr.write('\n');
const bundleResult = generate(paeckchenAst, {
comment: true
});
if (context.config.output.file) {
host.writeFile(
host.joinPath(context.config.output.folder, context.config.output.file),
bundleResult);
return undefined;
}
return bundleResult;
}
示例5: function
files.forEach((file: {src: string[]; dest: string}) => {
var jsFileContent = fs.readFileSync(file.src[0]).toString(),
ast = esprima.parse(jsFileContent, {loc: true, range: true});
// Ensure destination folder exists
if (!fs.existsSync(path.dirname(file.dest))) {
grunt.file.mkdir(path.dirname(file.dest));
}
var processedAst = estraverse.replace(ast, {
enter: function(node: any) {
if (node.type === 'ExpressionStatement' &&
node.expression.type === 'CallExpression' &&
remove.indexOf(node.expression.callee.name) > -1) {
return {type:'EmptyStatement'};
}
}
}), output = escodegen.generate(processedAst, {sourceMap: path.relative(path.dirname(file.dest), file.src[0]), sourceMapWithCode: true});
var mapDest = file.dest + '.map';
fs.writeFileSync(mapDest, output.map);
fs.writeFileSync(file.dest, `${output.code}\n//# sourceMappingURL=${path.basename(file.dest)}.map`);
});
示例6: addShadowDomTests
async function addShadowDomTests(element: ElementRepo): Promise<void> {
const testDir = path.join(element.dir, 'test');
if (!existsSync(testDir) || !fs.statSync(testDir).isDirectory()) {
return; // nothing to do
}
const testIndexFile = path.join(testDir, 'index.html');
if (!existsSync(testIndexFile)) {
return; // nothing to do
}
const contents = fs.readFileSync(testIndexFile, 'utf8');
const domTree = dom5.parse(contents);
const scripts = dom5.queryAll(domTree, (n) => n.tagName === 'script');
let updateNeeded = false;
for (const script of scripts) {
const data = script.childNodes[0];
if (!data || data.nodeName !== '#text') {
continue;
}
const program = espree.parse(data.value, {attachComment: true});
estree_walker.walk(program, {
enter(n) {
if (!(n.type === 'CallExpression' &&
n.callee.type === 'MemberExpression')) {
return;
}
if (!(n.callee.object && n.callee.property)) {
return;
}
if (!(n.callee.object.name === 'WCT' &&
n.callee.property.name === 'loadSuites')) {
return;
}
if (!(n.arguments && n.arguments.length === 1 &&
n.arguments[0].type === 'ArrayExpression')) {
return;
}
const testFilenameExpressions = n.arguments[0];
const shadyFilenames = new Set<string>();
const shadowFilenames = new Set<string>();
for (const filenameExpression of testFilenameExpressions.elements) {
if (/dom=shadow/.test(filenameExpression.value)) {
shadowFilenames.add(filenameExpression.value);
} else {
shadyFilenames.add(filenameExpression.value);
}
}
for (const shadyFilename of shadyFilenames) {
if (!shadowFilenames.has(shadyFilename + '?dom=shadow')) {
updateNeeded = true;
}
}
testFilenameExpressions.elements = [];
for (const shadyFilename of shadyFilenames) {
testFilenameExpressions.elements.push(
{type: 'Literal', value: shadyFilename});
}
for (const shadyFilename of shadyFilenames) {
testFilenameExpressions.elements.push(
{type: 'Literal', value: shadyFilename + '?dom=shadow'});
}
}
});
// Try to infer indentation
let indentation = ' ';
const parent = script.parentNode;
const scriptIndex = parent.childNodes.indexOf(script);
if (scriptIndex >= 0 &&
parent.childNodes[scriptIndex - 1].nodeName === '#text') {
const textJustBefore = parent.childNodes[scriptIndex - 1].value;
indentation = textJustBefore.match(/( +)$/)[1];
}
data.value = '\n' + escodegen.generate(program, {
comment: true,
format: {
indent: {
style: ' ',
base: (indentation.length / 2) + 1,
adjustMultilineComment: true
}
}
}) + '\n' + indentation;
}
if (updateNeeded) {
fs.writeFileSync(testIndexFile, dom5.serialize(domTree) + '\n', 'utf8');
element.needsReview = true;
await makeCommit(
element, ['test/index.html'],
'Add shadow dom test configurations.');
}
}
示例7:
safeConcatenation: true,
preserveBlankLines: true
};
let emptyMozillaOptions: escodegen.MozillaOptions = {};
let mozillaOptions: escodegen.MozillaOptions = {
starlessGenerator: true,
parenthesizedComprehensionBlock: true,
comprehensionExpressionStartsWithAssignment: true
}
let emptyGenerateOptions: escodegen.GenerateOptions = {};
let generateOptions: escodegen.GenerateOptions = {
format: formatOptions,
moz: mozillaOptions,
parse: () => {},
comment: true,
sourceMap: " ",
sourceMapWithCode: true,
sourceContent: " ",
sourceCode: " ",
sourceMapRoot: " ",
directive: true,
file: " ",
verbatim: " "
};
let precedence: escodegen.Precedence = escodegen.Precedence.Primary;
let myCode: string = escodegen.generate({}, generateOptions);
let ast: any = escodegen.attachComments({}, {}, {});
示例8: generate
export function generate(node: ESTree.Node): string {
return escodegen.generate(node);
};
示例9: function
export default function (tree: ESTree.Program, options?: TransformOptions): string {
return escodegen.generate(transform(tree, options));
}