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


TypeScript magic-string.toString函數代碼示例

本文整理匯總了TypeScript中magic-string.toString函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript toString函數的具體用法?TypeScript toString怎麽用?TypeScript toString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了toString函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: setup

 () => {
   const {decorationAnalyses, sourceFile, renderer} = setup(PROGRAM);
   const output = new MagicString(PROGRAM.contents);
   const compiledClass =
       decorationAnalyses.get(sourceFile) !.compiledClasses.find(c => c.name === 'B') !;
   const decorator = compiledClass.decorators[0];
   const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
   decoratorsToRemove.set(decorator.node.parent !, [decorator.node]);
   renderer.removeDecorators(output, decoratorsToRemove);
   expect(output.toString()).toContain(`{ type: Directive, args: [{ selector: '[a]' }] },`);
   expect(output.toString()).toContain(`{ type: OtherA }`);
   expect(output.toString())
       .not.toContain(`{ type: Directive, args: [{ selector: '[b]' }] }`);
   expect(output.toString()).toContain(`{ type: OtherB }`);
   expect(output.toString()).toContain(`{ type: Directive, args: [{ selector: '[c]' }] }`);
 });
開發者ID:zackarychapple,項目名稱:angular,代碼行數:16,代碼來源:esm2015_renderer_spec.ts

示例2: setup

       () => {
         const {analyzer, parser, program, renderer} = setup(PROGRAM);
         const analyzedFile = analyze(parser, analyzer, program.getSourceFile(PROGRAM.name) !);
         const output = new MagicString(PROGRAM.contents);
         const analyzedClass = analyzedFile.analyzedClasses[2];
         const decorator = analyzedClass.decorators[0];
         const decoratorsToRemove = new Map<ts.Node, ts.Node[]>();
         decoratorsToRemove.set(decorator.node.parent !, [decorator.node]);
         renderer.removeDecorators(output, decoratorsToRemove);
         expect(output.toString()).toContain(`{ type: Directive, args: [{ selector: '[a]' }] },`);
         expect(output.toString()).toContain(`{ type: OtherA }`);
         expect(output.toString()).toContain(`{ type: Directive, args: [{ selector: '[b]' }] }`);
         expect(output.toString()).toContain(`{ type: OtherB }`);
         expect(output.toString()).not.toContain(`C.decorators = [
  { type: Directive, args: [{ selector: '[c]' }] },
];`);
       });
開發者ID:DeepanParikh,項目名稱:angular,代碼行數:17,代碼來源:esm5_renderer_spec.ts

示例3: it

 it('should insert a default import at the start of the source file', () => {
   const {renderer} = setup(PROGRAM);
   const output = new MagicString(PROGRAM.contents);
   renderer.addImports(output, [
     {specifier: 'test', qualifier: 'i0', isDefault: true},
   ]);
   expect(output.toString()).toContain(`import i0 from 'test';`);
 });
開發者ID:zackarychapple,項目名稱:angular,代碼行數:8,代碼來源:esm5_renderer_spec.ts

示例4: it

    it('should insert the given imports at the start of the source file', () => {
      const {renderer} = setup(PROGRAM);
      const output = new MagicString(PROGRAM.contents);
      renderer.addImports(
          output, [{name: '@angular/core', as: 'i0'}, {name: '@angular/common', as: 'i1'}]);
      expect(output.toString()).toContain(`import * as i0 from '@angular/core';
import * as i1 from '@angular/common';

/* A copyright notice */`);
    });
開發者ID:KaneFreeman,項目名稱:angular,代碼行數:10,代碼來源:esm2015_renderer_spec.ts

示例5: run

  static run(content: string): StageResult {
    let log = logger(this.name);
    log(content);

    let editor = new MagicString(content);
    addVariableDeclarations(content, editor);
    return {
      code: editor.toString(),
      suggestions: []
    };
  }
開發者ID:alangpierce,項目名稱:decaffeinate,代碼行數:11,代碼來源:index.ts

示例6: it

    it('should insert the definitions directly after the class declaration', () => {
      const {analyzer, parser, program, renderer} = setup(PROGRAM);
      const analyzedFile = analyze(parser, analyzer, program.getSourceFile(PROGRAM.name) !);
      const output = new MagicString(PROGRAM.contents);
      renderer.addDefinitions(output, analyzedFile.analyzedClasses[0], 'SOME DEFINITION TEXT');
      expect(output.toString()).toContain(`
  function A() {}
SOME DEFINITION TEXT
  A.decorators = [
`);
    });
開發者ID:DeepanParikh,項目名稱:angular,代碼行數:11,代碼來源:esm5_renderer_spec.ts

示例7: MagicString

  transform: (code: string) => {
    const newContent = new MagicString(code);

    // Walks through every occurrence of a license comment and overwrites it with an empty string.
    for (let pos = -1; (pos = code.indexOf(licenseBanner, pos + 1)) !== -1; null) {
      newContent.overwrite(pos, pos + licenseBanner.length, '');
    }

    return {
      code: newContent.toString(),
      map:  newContent.generateMap({ hires: true })
    };
  }
開發者ID:Chintuz,項目名稱:material2,代碼行數:13,代碼來源:rollup-remove-licenses.ts

示例8: it

 it('should not insert alias exports in js output', () => {
   const {renderer} = setup(PROGRAM);
   const output = new MagicString(PROGRAM.contents);
   renderer.addExports(output, PROGRAM.name.replace(/\.js$/, ''), [
     {from: '/some/a.js', alias: 'eComponentA1', identifier: 'ComponentA1'},
     {from: '/some/a.js', alias: 'eComponentA2', identifier: 'ComponentA2'},
     {from: '/some/foo/b.js', alias: 'eComponentB', identifier: 'ComponentB'},
     {from: PROGRAM.name, alias: 'eTopLevelComponent', identifier: 'TopLevelComponent'},
   ]);
   const outputString = output.toString();
   expect(outputString).not.toContain(`{eComponentA1 as ComponentA1}`);
   expect(outputString).not.toContain(`{eComponentB as ComponentB}`);
   expect(outputString).not.toContain(`{eTopLevelComponent as TopLevelComponent}`);
 });
開發者ID:alxhub,項目名稱:angular,代碼行數:14,代碼來源:esm5_renderer_spec.ts


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