本文整理匯總了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));
}