當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript compiler.precompile函數代碼示例

本文整理匯總了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');
});
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:8,代碼來源:node-test.ts

示例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!;
}
開發者ID:cibernox,項目名稱:ember.js,代碼行數:27,代碼來源:transform-test-case.ts

示例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');
});
開發者ID:asakusuma,項目名稱:glimmer,代碼行數:11,代碼來源:compile-options-test.ts

示例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 };
}
開發者ID:jayphelps,項目名稱:glimmer,代碼行數:6,代碼來源:shared.ts

示例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');
開發者ID:mmun,項目名稱:glimmer,代碼行數:31,代碼來源:template-test.ts

示例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));
}
開發者ID:GreatWizard,項目名稱:ember.js,代碼行數:13,代碼來源:precompile.ts


注:本文中的@glimmer/compiler.precompile函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。