本文整理匯總了TypeScript中magic-string.Bundle.indent方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Bundle.indent方法的具體用法?TypeScript Bundle.indent怎麽用?TypeScript Bundle.indent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類magic-string.Bundle
的用法示例。
在下文中一共展示了Bundle.indent方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: system
export default function system(
magicString: MagicStringBundle,
{
dependencies,
exports,
indentString: t,
intro,
outro,
usesTopLevelAwait,
varOrConst
}: FinaliserOptions,
options: OutputOptions
) {
const n = options.compact ? '' : '\n';
const _ = options.compact ? '' : ' ';
const dependencyIds = dependencies.map(m => `'${m.id}'`);
const importBindings: string[] = [];
let starExcludes: Set<string>;
const setters: string[] = [];
dependencies.forEach(({ imports, reexports }) => {
const setter: string[] = [];
if (imports) {
imports.forEach(specifier => {
importBindings.push(specifier.local);
if (specifier.imported === '*') {
setter.push(`${specifier.local}${_}=${_}module;`);
} else {
setter.push(`${specifier.local}${_}=${_}module.${specifier.imported};`);
}
});
}
if (reexports) {
let createdSetter = false;
// bulk-reexport form
if (
reexports.length > 1 ||
(reexports.length === 1 &&
(reexports[0].reexported === '*' || reexports[0].imported === '*'))
) {
// star reexports
reexports.forEach(specifier => {
if (specifier.reexported !== '*') return;
// need own exports list for deduping in star export case
if (!starExcludes) {
starExcludes = getStarExcludes({ dependencies, exports });
}
if (!createdSetter) {
setter.push(`${varOrConst} _setter${_}=${_}{};`);
createdSetter = true;
}
setter.push(`for${_}(var _$p${_}in${_}module)${_}{`);
setter.push(`${t}if${_}(!_starExcludes[_$p])${_}_setter[_$p]${_}=${_}module[_$p];`);
setter.push('}');
});
// star import reexport
reexports.forEach(specifier => {
if (specifier.imported !== '*' || specifier.reexported === '*') return;
setter.push(`exports('${specifier.reexported}',${_}module);`);
});
// reexports
reexports.forEach(specifier => {
if (specifier.reexported === '*' || specifier.imported === '*') return;
if (!createdSetter) {
setter.push(`${varOrConst} _setter${_}=${_}{};`);
createdSetter = true;
}
setter.push(`_setter.${specifier.reexported}${_}=${_}module.${specifier.imported};`);
});
if (createdSetter) {
setter.push('exports(_setter);');
}
} else {
// single reexport
reexports.forEach(specifier => {
setter.push(`exports('${specifier.reexported}',${_}module.${specifier.imported});`);
});
}
}
setters.push(setter.join(`${n}${t}${t}${t}`));
});
const registeredName = options.name ? `'${options.name}',${_}` : '';
let wrapperStart =
`System.register(${registeredName}[` +
dependencyIds.join(`,${_}`) +
`],${_}function${_}(exports,${_}module)${_}{${n}${t}'use strict';` +
getStarExcludesBlock(starExcludes, varOrConst, _, t, n) +
getImportBindingsBlock(importBindings, _, t, n) +
`${n}${t}return${_}{${
setters.length
? `${n}${t}${t}setters:${_}[${setters
.map(s =>
s
? `function${_}(module)${_}{${n}${t}${t}${t}${s}${n}${t}${t}}`
: `function${_}()${_}{}`
)
//.........這裏部分代碼省略.........
示例2: system
export default function system(
magicString: MagicStringBundle,
{
graph,
indentString: t,
intro,
outro,
dependencies,
exports,
usesTopLevelAwait
}: FinaliserOptions,
options: OutputOptions
) {
const n = options.compact ? '' : '\n';
const _ = options.compact ? '' : ' ';
const dependencyIds = dependencies.map(m => `'${m.id}'`);
const importBindings: string[] = [];
let starExcludes: Set<string>;
const setters: string[] = [];
const varOrConst = graph.varOrConst;
dependencies.forEach(({ imports, reexports }) => {
const setter: string[] = [];
if (imports) {
imports.forEach(specifier => {
importBindings.push(specifier.local);
if (specifier.imported === '*') {
setter.push(`${specifier.local}${_}=${_}module;`);
} else {
setter.push(`${specifier.local}${_}=${_}module.${specifier.imported};`);
}
});
}
if (reexports) {
let createdSetter = false;
// bulk-reexport form
if (
reexports.length > 1 ||
(reexports.length === 1 &&
(reexports[0].reexported === '*' || reexports[0].imported === '*'))
) {
// star reexports
reexports.forEach(specifier => {
if (specifier.reexported !== '*') return;
// need own exports list for deduping in star export case
if (!starExcludes) {
starExcludes = getStarExcludes({ dependencies, exports });
}
if (!createdSetter) {
setter.push(`${varOrConst} _setter${_}=${_}{};`);
createdSetter = true;
}
setter.push(`for${_}(var _$p${_}in${_}module)${_}{`);
setter.push(`${t}if${_}(!_starExcludes[_$p])${_}_setter[_$p]${_}=${_}module[_$p];`);
setter.push('}');
});
// star import reexport
reexports.forEach(specifier => {
if (specifier.imported !== '*' || specifier.reexported === '*') return;
setter.push(`exports('${specifier.reexported}',${_}module);`);
});
// reexports
reexports.forEach(specifier => {
if (specifier.reexported === '*' || specifier.imported === '*') return;
if (!createdSetter) {
setter.push(`${varOrConst} _setter${_}=${_}{};`);
createdSetter = true;
}
setter.push(`_setter.${specifier.reexported}${_}=${_}module.${specifier.imported};`);
});
if (createdSetter) {
setter.push('exports(_setter);');
}
} else {
// single reexport
reexports.forEach(specifier => {
setter.push(`exports('${specifier.reexported}',${_}module.${specifier.imported});`);
});
}
}
setters.push(setter.join(`${n}${t}${t}${t}`));
});
// function declarations hoist
const hoistedExports: string[] = [];
const hoistedExportObjs = exports.filter(expt => expt.hoisted || expt.uninitialized);
if (hoistedExportObjs.length === 1) {
const expt = hoistedExportObjs[0];
hoistedExports.push(
`exports('${expt.exported}',${_}${expt.uninitialized ? 'void 0' : expt.local});`
);
} else if (hoistedExportObjs.length > 1) {
hoistedExports.push(`exports({`);
for (let i = 0; i < hoistedExportObjs.length; i++) {
const expt = hoistedExportObjs[i];
hoistedExports.push(
`${t}${expt.exported}:${_}${expt.uninitialized ? 'void 0' : expt.local}${
//.........這裏部分代碼省略.........
示例3: iife
export default function iife(
magicString: MagicStringBundle,
{
graph,
namedExportsMode,
hasExports,
indentString: t,
intro,
outro,
dependencies,
exports
}: FinaliserOptions,
options: OutputOptions
) {
const _ = options.compact ? '' : ' ';
const n = options.compact ? '' : '\n';
const { extend, name } = options;
const isNamespaced = name && name.indexOf('.') !== -1;
const possibleVariableAssignment = !extend && !isNamespaced;
if (name && possibleVariableAssignment && !isLegal(name)) {
error({
code: 'ILLEGAL_IDENTIFIER_AS_NAME',
message: `Given name (${name}) is not legal JS identifier. If you need this you can try --extend option`
});
}
warnOnBuiltins(graph, dependencies);
const external = trimEmptyImports(dependencies);
const deps = external.map(dep => dep.globalName || 'null');
const args = external.map(m => m.name);
if (hasExports && !name) {
error({
code: 'INVALID_OPTION',
message: `You must supply output.name for IIFE bundles`
});
}
if (extend) {
deps.unshift(`(${thisProp(name)}${_}=${_}${thisProp(name)}${_}||${_}{})`);
args.unshift('exports');
} else if (namedExportsMode && hasExports) {
deps.unshift('{}');
args.unshift('exports');
}
const useStrict = options.strict !== false ? `${t}'use strict';${n}${n}` : ``;
let wrapperIntro = `(function${_}(${args})${_}{${n}${useStrict}`;
if (hasExports && !extend) {
wrapperIntro =
(isNamespaced ? thisProp(name) : `${graph.varOrConst} ${name}`) + `${_}=${_}${wrapperIntro}`;
}
if (isNamespaced) {
wrapperIntro =
setupNamespace(name, 'this', false, options.globals, options.compact) + wrapperIntro;
}
let wrapperOutro = `${n}${n}}(${deps}));`;
if (!extend && namedExportsMode && hasExports) {
wrapperOutro = `${n}${n}${t}return exports;${wrapperOutro}`;
}
// var foo__default = 'default' in foo ? foo['default'] : foo;
const interopBlock = getInteropBlock(dependencies, options, graph.varOrConst);
if (interopBlock) magicString.prepend(interopBlock + n + n);
if (intro) magicString.prepend(intro);
const exportBlock = getExportBlock(
exports,
dependencies,
namedExportsMode,
options.interop,
options.compact
);
if (exportBlock) magicString.append(n + n + exportBlock);
if (outro) magicString.append(outro);
return magicString
.indent(t)
.prepend(wrapperIntro)
.append(wrapperOutro);
}
示例4: amd
export default function amd(
magicString: MagicStringBundle,
{
graph,
namedExportsMode,
hasExports,
indentString,
intro,
outro,
dynamicImport,
needsAmdModule,
dependencies,
exports,
isEntryModuleFacade
}: FinaliserOptions,
options: OutputOptions
) {
warnOnBuiltins(graph, dependencies);
const deps = dependencies.map(m => `'${m.id}'`);
const args = dependencies.map(m => m.name);
const n = options.compact ? '' : '\n';
const _ = options.compact ? '' : ' ';
if (namedExportsMode && hasExports) {
args.unshift(`exports`);
deps.unshift(`'exports'`);
}
if (dynamicImport) {
args.unshift('require');
deps.unshift(`'require'`);
}
if (needsAmdModule) {
args.unshift('module');
deps.unshift(`'module'`);
}
const amdOptions = options.amd || {};
const params =
(amdOptions.id ? `'${amdOptions.id}',${_}` : ``) +
(deps.length ? `[${deps.join(`,${_}`)}],${_}` : ``);
const useStrict = options.strict !== false ? `${_}'use strict';` : ``;
const define = amdOptions.define || 'define';
const wrapperStart = `${define}(${params}function${_}(${args.join(
`,${_}`
)})${_}{${useStrict}${n}${n}`;
// var foo__default = 'default' in foo ? foo['default'] : foo;
const interopBlock = getInteropBlock(dependencies, options, graph.varOrConst);
if (interopBlock) magicString.prepend(interopBlock + n + n);
if (intro) magicString.prepend(intro);
const exportBlock = getExportBlock(
exports,
dependencies,
namedExportsMode,
options.interop,
options.compact
);
if (exportBlock) magicString.append(n + n + exportBlock);
if (namedExportsMode && hasExports && isEntryModuleFacade && options.esModule)
magicString.append(`${n}${n}${options.compact ? compactEsModuleExport : esModuleExport}`);
if (outro) magicString.append(outro);
return magicString
.indent(indentString)
.append(n + n + '});')
.prepend(wrapperStart);
}