本文整理汇总了TypeScript中dom5/lib/index-next.setTextContent函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setTextContent函数的具体用法?TypeScript setTextContent怎么用?TypeScript setTextContent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setTextContent函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: transformEsModuleToAmd
function transformEsModuleToAmd(
script: dom5.Node, idx: number, jsOptions: JsTransformOptions|undefined) {
// We're not a module anymore.
dom5.removeAttribute(script, 'type');
if (scriptWasSplitByHtmlSplitter(script)) {
// Nothing else to do here. If we're using HtmlSplitter, the JsTransformer
// is responsible for doing this transformation.
return;
}
const isExternal = dom5.hasAttribute(script, 'src');
if (isExternal) {
const src = dom5.getAttribute(script, 'src');
dom5.removeAttribute(script, 'src');
dom5.setTextContent(script, `define(['${src}']);`);
} else {
// Transform inline scripts with the AMD Babel plugin transformer.
const newJs = jsTransform(dom5.getTextContent(script), {
...jsOptions,
transformModulesToAmd: true,
moduleScriptIdx: idx,
});
dom5.setTextContent(script, newJs);
}
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:27,代码来源:html-transform.ts
示例2: replaceGiantScripts
/**
* Replaces the Babel helpers, Require.js AMD loader, and WCT hack inline
* scripts into just some comments, to make test comparison simpler.
*/
function replaceGiantScripts(html: string): string {
const document = parse5.parse(html);
for (const script of dom5.queryAll(
document, dom5.predicates.hasTagName('script'))) {
const js = dom5.getTextContent(script);
if (js.includes('var requirejs,require')) {
dom5.setTextContent(script, '// amd loader');
} else if (js.includes('babelHelpers={}')) {
dom5.setTextContent(script, '// babel helpers');
} else if (js.includes('window._wctCallback =')) {
dom5.setTextContent(script, '// wct hack 1/2');
} else if (js.includes('window._wctCallback()')) {
dom5.setTextContent(script, '// wct hack 2/2');
}
}
return parse5.serialize(document);
}
开发者ID:Polymer,项目名称:polymer-build,代码行数:21,代码来源:html-transform_test.ts
示例3: html
export function html(text: string) {
const ast = parse5.parse(text);
const styleNodes = dom5.queryAll(
ast, isInlineStyle, dom5.childNodesIncludeTemplate);
for (const styleNode of styleNodes) {
const text = dom5.getTextContent(styleNode);
dom5.setTextContent(styleNode, css(text));
}
return parse5.serialize(ast);
}
开发者ID:poehlmann,项目名称:EvaluacionDiferencialDeLaMemoria,代码行数:10,代码来源:index.ts
示例4: transformEsModuleToAmd
function transformEsModuleToAmd(
script: dom5.Node, idx: number, jsOptions: JsTransformOptions|undefined) {
// We're not a module anymore.
dom5.removeAttribute(script, 'type');
if (scriptWasSplitByHtmlSplitter(script)) {
// Nothing else to do here. If we're using HtmlSplitter, the JsTransformer
// is responsible for doing this transformation.
return;
}
// Module scripts execute in order. AMD modules don't necessarily preserve
// this ordering. To emulate the ordering, we construct an artificial
// dependency chain between all module scripts on the page.
const generatedModule = generateModuleName(idx);
const previousGeneratedModule =
idx === 0 ? undefined : generateModuleName(idx - 1);
const isExternal = dom5.hasAttribute(script, 'src');
if (isExternal) {
const deps = [];
if (previousGeneratedModule !== undefined) {
deps.push(previousGeneratedModule);
}
const externalSrc = dom5.getAttribute(script, 'src');
deps.push(externalSrc);
const depsStr = deps.map((dep) => `'${dep}'`).join(', ');
dom5.removeAttribute(script, 'src');
dom5.setTextContent(script, `define('${generatedModule}', [${depsStr}]);`);
} else {
// Transform inline scripts with the AMD Babel plugin transformer.
const newJs = jsTransform(dom5.getTextContent(script), {
...jsOptions,
transformModulesToAmd: true,
moduleScriptIdx: idx,
});
dom5.setTextContent(script, newJs);
}
}
开发者ID:Polymer,项目名称:polymer-build,代码行数:40,代码来源:html-transform.ts
示例5: addIndentation
export function addIndentation(
textNode: dom5.Node, additionalIndentation = ' ') {
if (!dom5.isTextNode(textNode)) {
return;
}
const text = dom5.getTextContent(textNode);
const indentedText =
text.split('\n')
.map((line) => {
return line.length > 0 ? additionalIndentation + line : line;
})
.join('\n');
dom5.setTextContent(textNode, indentedText);
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:14,代码来源:util.ts
示例6:
const injectScript = (js: string) => {
const fragment = parse5.parseFragment('<script></script>\n');
dom5.setTextContent(fragment.childNodes![0], js);
const firstJsScriptOrHtmlImport =
dom5.query(document, isJsScriptOrHtmlImport);
if (firstJsScriptOrHtmlImport) {
dom5.insertBefore(
firstJsScriptOrHtmlImport.parentNode!,
firstJsScriptOrHtmlImport,
fragment);
} else {
const headOrDocument =
dom5.query(document, dom5.predicates.hasTagName('head')) || document;
dom5.append(headOrDocument, fragment);
}
};
开发者ID:MehdiRaash,项目名称:tools,代码行数:18,代码来源:html-transform.ts
示例7: replaceGiantScripts
/**
* Replaces the Babel helpers, Require.js AMD loader, and WCT hack inline
* scripts into just some comments, to make test comparison simpler.
*/
function replaceGiantScripts(html: string): string {
const document = parse5.parse(html);
for (const script of dom5.queryAll(
document, dom5.predicates.hasTagName('script'))) {
const js = dom5.getTextContent(script);
if (js.includes('window.define=')) {
dom5.setTextContent(script, '// amd loader');
} else if (js.includes('wrapNativeSuper=')) {
dom5.setTextContent(script, '// babel helpers full');
} else if (js.includes('interopRequireDefault=')) {
dom5.setTextContent(script, '// babel helpers amd');
} else if (js.includes('regeneratorRuntime')) {
dom5.setTextContent(script, '// regenerator runtime');
} else if (js.includes('window._wctCallback =')) {
dom5.setTextContent(script, '// wct hack 1/2');
} else if (js.includes('window._wctCallback()')) {
dom5.setTextContent(script, '// wct hack 2/2');
}
}
return parse5.serialize(document);
}
开发者ID:MehdiRaash,项目名称:tools,代码行数:25,代码来源:html-transform_test.ts
示例8: htmlTransform
export function htmlTransform(
html: string, options: HtmlTransformOptions): string {
if (options.js && options.js.moduleResolution === 'node' &&
!options.js.filePath) {
throw new Error('Cannot perform node module resolution without filePath.');
}
const document = parse5.parse(html, {
locationInfo: true, // Required for removeFakeNodes.
});
removeFakeNodes(document);
const allScripts = [...dom5.queryAll(document, isJsScript)];
const shouldTransformEsModuleToAmd = options.js &&
options.js.transformModulesToAmd &&
// Assume that if this document has a nomodule script, the author is
// already handling browsers that don't support modules, and we don't
// need to transform them (even if the configuration was set).
// TODO(aomarks) Check this for HtmlSplitter case too.
!allScripts.some((node) => dom5.hasAttribute(node, 'nomodule'));
let wctScript, firstModuleScript, finalModuleScript;
let moduleScriptIdx = 0;
for (const script of allScripts) {
const isModule = dom5.getAttribute(script, 'type') === 'module';
if (isModule) {
if (firstModuleScript === undefined) {
firstModuleScript = script;
}
finalModuleScript = script;
if (shouldTransformEsModuleToAmd) {
transformEsModuleToAmd(script, moduleScriptIdx++, options.js);
continue; // Bypass the standard jsTransform below.
}
}
const isInline = !dom5.hasAttribute(script, 'src');
if (isInline) {
// Note that scripts split by HtmlSplitter are always external, so we
// don't have to check for that case here.
const newJs = jsTransform(
dom5.getTextContent(script),
{...options.js, transformModulesToAmd: false});
dom5.setTextContent(script, newJs);
} else if (wctScript === undefined) {
const src = dom5.getAttribute(script, 'src') || '';
if (src.includes('web-component-tester/browser.js') ||
src.includes('wct-browser-legacy/browser.js')) {
wctScript = script;
}
}
}
if (shouldTransformEsModuleToAmd && finalModuleScript !== undefined) {
// We've defined a bunch of modules and chained them together. Now we need
// to initiate loading the chain by requiring the final one.
const finalModuleName = generateModuleName(moduleScriptIdx - 1);
const fragment = parse5.parseFragment(
`<script>require(['${finalModuleName}']);</script>`);
dom5.insertAfter(
finalModuleScript.parentNode!, finalModuleScript, fragment);
}
if (options.injectAmdLoader && shouldTransformEsModuleToAmd &&
firstModuleScript !== undefined) {
const fragment = parse5.parseFragment('<script></script>\n');
dom5.setTextContent(fragment.childNodes![0], getMinifiedRequireJs());
const requireJsScript = fragment.childNodes![0];
// Inject as late as possible (just before the first module is declared, if
// there is one) because there may be some UMD dependencies that we want to
// continue to load in global mode instead of AMD mode (which is detected by
// the presence of the `require` global).
dom5.insertBefore(
firstModuleScript.parentNode!, firstModuleScript, fragment);
if (wctScript !== undefined) {
addWctTimingHack(wctScript, requireJsScript);
}
}
if (options.injectBabelHelpers) {
const fragment = parse5.parseFragment('<script></script>\n');
dom5.setTextContent(fragment.childNodes![0], getMinifiedBabelHelpers());
const firstJsScriptOrHtmlImport =
dom5.query(document, isJsScriptOrHtmlImport);
if (firstJsScriptOrHtmlImport) {
dom5.insertBefore(
firstJsScriptOrHtmlImport.parentNode!,
firstJsScriptOrHtmlImport,
fragment);
} else {
const headOrDocument =
dom5.query(document, dom5.predicates.hasTagName('head')) || document;
dom5.append(headOrDocument, fragment);
}
//.........这里部分代码省略.........
开发者ID:Polymer,项目名称:polymer-build,代码行数:101,代码来源:html-transform.ts
示例9: htmlTransform
export function htmlTransform(
html: string, options: HtmlTransformOptions): string {
if (options.js && options.js.moduleResolution === 'node' &&
!options.js.filePath) {
throw new Error('Cannot perform node module resolution without filePath.');
}
const document = parse5.parse(html, {
locationInfo: true, // Required for removeFakeNodes.
});
removeFakeNodes(document);
const allScripts = [...dom5.queryAll(document, isJsScript)];
const shouldTransformEsModuleToAmd = options.js &&
options.js.transformModulesToAmd &&
// Assume that if this document has a nomodule script, the author is
// already handling browsers that don't support modules, and we don't
// need to transform them (even if the configuration was set).
// TODO(aomarks) Check this for HtmlSplitter case too.
!allScripts.some((node) => dom5.hasAttribute(node, 'nomodule'));
let wctScript, firstModuleScript;
for (const script of allScripts) {
const isModule = dom5.getAttribute(script, 'type') === 'module';
if (isModule) {
if (firstModuleScript === undefined) {
firstModuleScript = script;
}
if (shouldTransformEsModuleToAmd) {
transformEsModuleToAmd(script, options.js);
continue; // Bypass the standard jsTransform below.
}
}
const isInline = !dom5.hasAttribute(script, 'src');
if (isInline) {
// Note that scripts split by HtmlSplitter are always external, so we
// don't have to check for that case here.
const newJs = jsTransform(
dom5.getTextContent(script),
{...options.js, transformModulesToAmd: false});
dom5.setTextContent(script, newJs);
} else if (wctScript === undefined) {
const src = dom5.getAttribute(script, 'src') || '';
if (src.includes('web-component-tester/browser.js') ||
src.includes('wct-browser-legacy/browser.js') ||
src.includes('wct-mocha/wct-mocha.js')) {
wctScript = script;
}
}
}
if (options.injectAmdLoader && shouldTransformEsModuleToAmd &&
firstModuleScript !== undefined) {
const fragment = parse5.parseFragment('<script></script>\n');
dom5.setTextContent(fragment.childNodes![0], externalJs.getAmdLoader());
const amdLoaderScript = fragment.childNodes![0];
// Inject as late as possible (just before the first module is declared, if
// there is one) because there may be some UMD dependencies that we want to
// continue to load in global mode instead of AMD mode (which is detected by
// the presence of the `require` global).
// TODO(aomarks) If we don't define require, we can inject earlier.
dom5.insertBefore(
firstModuleScript.parentNode!, firstModuleScript, fragment);
if (wctScript !== undefined) {
addWctTimingHack(wctScript, amdLoaderScript);
}
}
const injectScript = (js: string) => {
const fragment = parse5.parseFragment('<script></script>\n');
dom5.setTextContent(fragment.childNodes![0], js);
const firstJsScriptOrHtmlImport =
dom5.query(document, isJsScriptOrHtmlImport);
if (firstJsScriptOrHtmlImport) {
dom5.insertBefore(
firstJsScriptOrHtmlImport.parentNode!,
firstJsScriptOrHtmlImport,
fragment);
} else {
const headOrDocument =
dom5.query(document, dom5.predicates.hasTagName('head')) || document;
dom5.append(headOrDocument, fragment);
}
};
let babelHelpers;
switch (options.injectBabelHelpers) {
case undefined:
case 'none':
break;
case 'full':
babelHelpers = externalJs.getBabelHelpersFull();
break;
//.........这里部分代码省略.........
开发者ID:Polymer,项目名称:tools,代码行数:101,代码来源:html-transform.ts
注:本文中的dom5/lib/index-next.setTextContent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论