本文整理汇总了TypeScript中@glimmer/compiler.precompile函数的典型用法代码示例。如果您正苦于以下问题:TypeScript precompile函数的具体用法?TypeScript precompile怎么用?TypeScript precompile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了precompile函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
QUnit.test('generates id in node', function (assert) {
let template = precompile('hello');
let obj = JSON.parse(template);
assert.equal(obj.id, '3TlrituF', 'short sha of template source');
template = precompile('hello', { meta: {moduleName: 'template/hello'} });
obj = JSON.parse(template);
assert.equal(obj.id, 'CiDxizBQ', 'short sha of template source and meta');
});
示例2: ast
function ast(template: string): AST.Program {
let program: Option<AST.Program> = null;
function extractProgram(): ASTPlugin {
return {
name: 'extract-program',
visitor: {
Program: {
exit(node: AST.Program): void {
program = clone(node);
},
},
},
};
}
let options = compileOptions({
moduleName: '-top-level',
});
options.plugins!.ast!.push(extractProgram);
precompile(template, options);
return program!;
}
示例3:
QUnit.test('returned meta is correct', assert => {
let wire = JSON.parse(precompile('Hi, {{name}}!', {
meta: {
moduleName: 'my/module-name',
metaIsOpaque: 'yes'
} as any as TemplateMeta
}));
assert.equal(wire.meta.moduleName, 'my/module-name', 'Template has correct meta');
assert.equal(wire.meta.metaIsOpaque, 'yes', 'Template has correct meta');
});
示例4: createTemplate
export function createTemplate(templateSource: string, meta: TemplateMeta = {}): ParsedLayout {
let wrapper: SerializedTemplateWithLazyBlock<TemplateMeta> = JSON.parse(precompile(templateSource, { meta }));
let block: SerializedTemplateBlock = JSON.parse(wrapper.block);
return { block, referrer: meta };
}
示例5: beforeEach
}
interface OwnerMeta {
owner: {};
}
let serializedTemplate: SerializedTemplateWithLazyBlock<TestMeta>;
let serializedTemplateNoId: SerializedTemplateWithLazyBlock<TestMeta>;
QUnit.module("templateFactory", {
beforeEach() {
env = new TestEnvironment();
let templateJs = precompile("<div>{{name}}</div>", {
meta: {
version: 12,
lang: 'es',
moduleName: "template/module/name"
}
});
serializedTemplate = JSON.parse(templateJs);
serializedTemplate.id = 'server-id-1';
serializedTemplateNoId = JSON.parse(templateJs);
serializedTemplateNoId.id = null;
}
});
QUnit.test("id of serialized template is exposed on the factory", assert => {
let factory = templateFactory(serializedTemplate);
assert.ok(factory.id, 'is present');
assert.equal(factory.id, serializedTemplate.id, 'id matches serialized template id');
示例6: precompile
/**
Uses HTMLBars `compile` function to process a string into a compiled template string.
The returned string must be passed through `Ember.HTMLBars.template`.
This is not present in production builds.
@private
@method precompile
@param {String} templateString This is the string to be compiled by HTMLBars.
*/
export default function precompile(templateString: string, options: CompileOptions): string {
return glimmerPrecompile(templateString, compileOptions(options));
}