本文整理汇总了TypeScript中convert-source-map.removeComments函数的典型用法代码示例。如果您正苦于以下问题:TypeScript removeComments函数的具体用法?TypeScript removeComments怎么用?TypeScript removeComments使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了removeComments函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: extractSourceMap
/**
* Get the map from the source (note whether it is inline or external)
*/
protected extractSourceMap(file: ts.SourceFile): SourceMapInfo {
const inline = commentRegex.test(file.text);
const external = mapFileCommentRegex.test(file.text);
if (inline) {
const inlineSourceMap = fromSource(file.text);
return {
source: removeComments(file.text).replace(/\n\n$/, '\n'),
map: inlineSourceMap,
isInline: true,
};
} else if (external) {
let externalSourceMap: SourceMapConverter|null = null;
try {
externalSourceMap = fromMapFileSource(file.text, dirname(file.fileName));
} catch (e) {
console.warn(e);
}
return {
source: removeMapFileComments(file.text).replace(/\n\n$/, '\n'),
map: externalSourceMap,
isInline: false,
};
} else {
return {source: file.text, map: null, isInline: false};
}
}
示例2: file
.then( () => {
/*
Angular compiler with 'flatModuleOutFile' turned on creates an entry JS file with a matching d.ts
file and an aggregated metadata.json file.
This is done by creating a corresponding TS file (to the output JS file).
The side-effect is a source map reference to the TS file.
Since the TS is virtual and does not exists we need to remove the comment so the source maps
will not break.
*/
const flatModuleJsPath = Path.join(copyInst.toSrc, `${util.getMainOutputFileName(util.currentPackage())}.js`);
const withoutComments = convert.removeComments(fs.readFileSync(flatModuleJsPath, 'utf-8'));
fs.writeFileSync(flatModuleJsPath, withoutComments, 'utf-8');
});
示例3: extractSourceMap
/**
* Get the map from the source (note whether it is inline or external)
*/
protected extractSourceMap(file: ts.SourceFile): SourceMapInfo {
const inline = commentRegex.test(file.text);
const external = mapFileCommentRegex.test(file.text);
if (inline) {
const inlineSourceMap = fromSource(file.text);
return {
source: removeComments(file.text).replace(/\n\n$/, '\n'),
map: inlineSourceMap,
isInline: true,
};
} else if (external) {
let externalSourceMap: SourceMapConverter|null = null;
try {
externalSourceMap = fromMapFileSource(file.text, dirname(file.fileName));
} catch (e) {
if (e.code === 'ENOENT') {
console.warn(
`The external map file specified in the source code comment "${e.path}" was not found on the file system.`);
const mapPath = file.fileName + '.map';
if (basename(e.path) !== basename(mapPath) && statSync(mapPath).isFile()) {
console.warn(
`Guessing the map file name from the source file name: "${basename(mapPath)}"`);
try {
externalSourceMap = fromObject(JSON.parse(readFileSync(mapPath, 'utf8')));
} catch (e) {
console.error(e);
}
}
}
}
return {
source: removeMapFileComments(file.text).replace(/\n\n$/, '\n'),
map: externalSourceMap,
isInline: false,
};
} else {
return {source: file.text, map: null, isInline: false};
}
}