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


TypeScript clone類代碼示例

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


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

示例1: _rollupInlineModuleScripts

 /**
  * Inlines the contents of external module scripts and rolls-up imported
  * modules into inline scripts.
  */
 private async _rollupInlineModuleScripts(ast: ASTNode) {
   this.document = await this._reanalyze(serialize(ast));
   rewriteObject(ast, this.document.parsedDocument.ast);
   dom5.removeFakeRootElements(ast);
   const es6Rewriter =
       new Es6Rewriter(this.bundler, this.manifest, this.assignedBundle);
   const inlineModuleScripts =
       [...this.document.getFeatures({
         kind: 'js-document',
         imported: false,
         externalPackages: true,
         excludeBackreferences: true,
       })].filter(({
                    isInline,
                    parsedDocument: {parsedAsSourceType}
                  }) => isInline && parsedAsSourceType === 'module');
   for (const inlineModuleScript of inlineModuleScripts) {
     const ast = clone(inlineModuleScript.parsedDocument.ast);
     const importResolutions =
         es6Rewriter.getEs6ImportResolutions(inlineModuleScript);
     es6Rewriter.rewriteEs6SourceUrlsToResolved(ast, importResolutions);
     const serializedCode = serializeEs6(ast).code;
     const {code} = await es6Rewriter.rollup(
         this.document.parsedDocument.baseUrl,
         serializedCode,
         inlineModuleScript);
     if (inlineModuleScript.astNode &&
         inlineModuleScript.astNode.language === 'html') {
       // Second argument 'true' tells encodeString to escape the <script>
       // content.
       dom5.setTextContent(
           inlineModuleScript.astNode.node, encodeString(`\n${code}\n`, true));
     }
   }
 }
開發者ID:Polymer,項目名稱:tools,代碼行數:39,代碼來源:html-bundler.ts

示例2: bundle

  async bundle(): Promise<BundledDocument> {
    this.document = await this._prepareBundleDocument();
    let ast = clone(this.document.parsedDocument.ast);
    dom5.removeFakeRootElements(ast);
    this._injectHtmlImportsForBundle(ast);
    this._rewriteAstToEmulateBaseTag(ast, this.assignedBundle.url);

    // Re-analyzing the document using the updated ast to refresh the scanned
    // imports, since we may now have appended some that were not initially
    // present.
    this.document = await this._reanalyze(serialize(ast));

    await this._inlineHtmlImports(ast);

    await this._updateExternalModuleScripts(ast);
    if (this.bundler.enableScriptInlining) {
      await this._inlineNonModuleScripts(ast);
      await this._inlineModuleScripts(ast);
    }
    if (this.bundler.enableCssInlining) {
      await this._inlineStylesheetLinks(ast);
      await this._inlineStylesheetImports(ast);
    }
    if (this.bundler.stripComments) {
      stripComments(ast);
    }
    this._removeEmptyHiddenDivs(ast);
    if (this.bundler.sourcemaps) {
      ast = updateSourcemapLocations(this.document, ast);
    }
    const content = serialize(ast);
    const files = [...this.assignedBundle.bundle.files];
    return {ast, content, files};
  }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:34,代碼來源:html-bundler.ts

示例3: test

 test('isSameNode', () => {
   const html = parse5.parseFragment(
       `<div><h1>hi</h1><h1>h1</h1></div>`, {locationInfo: true});
   const h1_1 = html.childNodes![0]!.childNodes![0]!;
   const h1_2 = html.childNodes![0]!.childNodes![1]!;
   const h1_1_clone = clone(h1_1);
   assert.isFalse(h1_1 === h1_2);
   assert.isFalse(h1_1 === h1_1_clone);
   assert.isFalse(ast.isSameNode(h1_1, h1_2));
   assert.isTrue(ast.isSameNode(h1_1, h1_1_clone));
 });
開發者ID:MehdiRaash,項目名稱:tools,代碼行數:11,代碼來源:parse5-utils_test.ts

示例4: _prepareBundleDocument

 /**
  * Generate a fresh document to bundle contents into.  If we're building
  * a bundle which is based on an existing file, we should load that file and
  * prepare it as the bundle document, otherwise we'll create a clean/empty
  * HTML document.
  */
 private async _prepareBundleDocument(): Promise<Document> {
   if (!this.assignedBundle.bundle.files.has(this.assignedBundle.url)) {
     return this._reanalyze('');
   }
   const analysis =
       await this.bundler.analyzer.analyze([this.assignedBundle.url]);
   const document = getAnalysisDocument(analysis, this.assignedBundle.url);
   const ast = clone(document.parsedDocument.ast);
   this._moveOrderedImperativesFromHeadIntoHiddenDiv(ast);
   this._moveUnhiddenHtmlImportsIntoHiddenDiv(ast);
   dom5.removeFakeRootElements(ast);
   return this._reanalyze(serialize(ast));
 }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:19,代碼來源:html-bundler.ts

示例5: makeChoice

	makeChoice(gs: GameState, microwaveIndex: number): GameState {
		if (microwaveIndex in gs.microwaves) {
			const newGs: GameState = clone(gs)
			if (newGs.line.length > 0) {
				newGs.microwaves[microwaveIndex].line.push(newGs.line.shift())
				return newGs
			}
			else {
				throw new Error(`Cannot move to microwave index ${microwaveIndex} with nothing in ine in game state ${gs}`)
			}
		}
		else {
			throw new Error(`Invalid microwave index ${microwaveIndex} for game state ${gs}`)
		}
	}
開發者ID:quinston,項目名稱:microwave,代碼行數:15,代碼來源:stateMachine.ts

示例6: test

  test(testName, async () => {
    const capabilities = clone(defaultClientCapabilities);
    capabilities.textDocument!.completion!.completionItem! = {
      ...(capabilities.textDocument!.completion!.completionItem!),
      documentationFormat: undefined
    };

    const {client} = await createTestEnvironment({fixtureDir, capabilities});
    await client.openFile(indexFile);
    const completions =
        await client.getCompletions(indexFile, {line: 0, column: 0});

    assert.deepEqual(
        completions,
        {isIncomplete: false, items: elementCompletionsWithPlainDescriptions});
  });
開發者ID:Polymer,項目名稱:tools,代碼行數:16,代碼來源:auto-completer_test.ts

示例7: create

export function create(configOrName: builder.IConfiguration|string, verbose?: boolean, json?: boolean, onError?: (message: any) => void): () => Stream {

    var config: builder.IConfiguration;
    if (typeof configOrName === 'string') {
        var parsed = readConfigFile(configOrName, (path) => readFileSync(path, undefined));
        if (parsed.error) {
            console.error(parsed.error);
            return () => null;
        }
        config = parsed.config.compilerOptions;

    } else {
        // clone the configuration
        config = clone(configOrName);
    }

    // add those
    config.verbose = config.verbose || verbose;
    config.json = config.json || json;

    if (!onError) {
        onError = (err) => console.log(JSON.stringify(err, null, 4));
    }

    var _builder = builder.createTypeScriptBuilder(config);

    function createStream(token?: builder.CancellationToken): Stream {

        return through(function (file: vinyl) {
            // give the file to the compiler
            if (file.isStream()) {
                this.emit('error', 'no support for streams');
                return;
            }
            _builder.file(file);
        }, function () {
            // start the compilation process
            _builder.build(file => this.queue(file), onError, token).then(() => this.queue(null));
        });
    }

    return (token?: builder.CancellationToken) => createStream(token);
}
開發者ID:auchenberg,項目名稱:gulp-tsb,代碼行數:43,代碼來源:index.ts

示例8: advanceTime

	advanceTime(gs: GameState, time: number): GameState {
		if (time === Math.floor(time) && time >= 0) {
			const newGs: GameState = clone(gs)
			let timeElapsed = 0
			newGs.microwaves.forEach(m => {
				let timeToAdvance = time
				while (timeToAdvance >= m.timeLeft && m.line.length > 0) {
					timeToAdvance -= m.timeLeft
					m.timeLeft = m.line.shift().desiredMicrowaveTime
				}
				timeElapsed = Math.max(timeElapsed, (time - timeToAdvance) + Math.min(m.timeLeft, timeToAdvance))
				m.timeLeft = Math.max(0, m.timeLeft - timeToAdvance)
			})
			newGs.makespan += timeElapsed
			return newGs
		}
		else {
			throw new Error(`Time must be a nonnegative integer; got ${time}`)
		}
	}
開發者ID:quinston,項目名稱:microwave,代碼行數:20,代碼來源:stateMachine.ts

示例9: _rewriteDynamicImport

 /**
  * Extends dynamic import statements to extract the explicitly namespace
  * export for the imported module.
  *
  * Before:
  *     import('./module-a.js')
  *         .then((moduleA) => moduleA.doSomething());
  *
  * After:
  *     import('./bundle_1.js')
  *         .then(({$moduleA}) => $moduleA)
  *         .then((moduleA) => moduleA.doSomething());
  */
 private _rewriteDynamicImport(
     baseUrl: ResolvedUrl,
     root: babel.Node,
     importNodePath: NodePath) {
   if (!importNodePath) {
     return;
   }
   const importCallExpression = importNodePath.parent;
   if (!importCallExpression ||
       !babel.isCallExpression(importCallExpression)) {
     return;
   }
   const importCallArgument = importCallExpression.arguments[0];
   if (!babel.isStringLiteral(importCallArgument)) {
     return;
   }
   const sourceUrl = importCallArgument.value;
   const resolvedSourceUrl = this.bundler.analyzer.urlResolver.resolve(
       baseUrl, sourceUrl as FileRelativeUrl);
   if (!resolvedSourceUrl) {
     return;
   }
   const sourceBundle = this.manifest.getBundleForFile(resolvedSourceUrl);
   // TODO(usergenic): To support *skipping* the rewrite, we need a way to
   // identify whether a bundle contains a single top-level module or is a
   // merged bundle with multiple top-level modules.
   let exportName;
   if (sourceBundle) {
     exportName =
         getOrSetBundleModuleExportName(sourceBundle, resolvedSourceUrl, '*');
   }
   // If there's no source bundle or the namespace export name of the bundle
   // is just '*', then we don't need to append a .then() to transform the
   // return value of the import().  Lets just rewrite the URL to be a relative
   // path and exit.
   if (!sourceBundle || exportName === '*') {
     const relativeSourceUrl =
         ensureLeadingDot(this.bundler.analyzer.urlResolver.relative(
             baseUrl, resolvedSourceUrl));
     importCallArgument.value = relativeSourceUrl;
     return;
   }
   // Rewrite the URL to be a relative path to the bundle.
   const relativeSourceUrl = ensureLeadingDot(
       this.bundler.analyzer.urlResolver.relative(baseUrl, sourceBundle.url));
   importCallArgument.value = relativeSourceUrl;
   const importCallExpressionParent = importNodePath.parentPath.parent!;
   if (!importCallExpressionParent) {
     return;
   }
   const thenifiedCallExpression = babel.callExpression(
       babel.memberExpression(
           clone(importCallExpression), babel.identifier('then')),
       [babel.arrowFunctionExpression(
           [
             babel.objectPattern(
                 [babel.objectProperty(
                      babel.identifier(exportName),
                      babel.identifier(exportName),
                      undefined,
                      true) as any]),
           ],
           babel.identifier(exportName))]);
   rewriteObject(importCallExpression, thenifiedCallExpression);
 }
開發者ID:Polymer,項目名稱:vulcanize,代碼行數:78,代碼來源:es6-rewriter.ts

示例10: createField

export function createField() {
    return clone({ lands: LANDS, overlays: OVERLAYS });
}
開發者ID:progre,項目名稱:sutahigashi,代碼行數:3,代碼來源:field.ts


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