This commit is contained in:
2021-11-21 11:18:28 +01:00
parent 7a358eb836
commit 230b10b2a3
9339 changed files with 892519 additions and 62 deletions

View File

@@ -0,0 +1,53 @@
'use strict';
var acorn = require('acorn');
var postcss = require('postcss');
var SourceMapGenerator = require('source-map').SourceMapGenerator;
function generateJs(sourcePath, fileContent) {
var generator = new SourceMapGenerator({ file: sourcePath });
var tokenizer = acorn.tokenizer(fileContent, {
allowHashBang: true,
locations: true,
});
/* eslint no-constant-condition: 0 */
while (true) {
var token = tokenizer.getToken();
if (token.type.label === 'eof') {
break;
}
var mapping = {
original: token.loc.start,
generated: token.loc.start,
source: sourcePath,
};
if (token.type.label === 'name') {
mapping.name = token.value;
}
generator.addMapping(mapping);
}
generator.setSourceContent(sourcePath, fileContent);
return generator.toJSON();
}
var postcssSourceMapOptions = {
inline: false,
prev: false,
sourcesContent: true,
annotation: false,
};
function generateCss(sourcePath, fileContent) {
var root = postcss.parse(fileContent, { from: sourcePath });
var result = root.toResult({ to: sourcePath, map: postcssSourceMapOptions });
return result.map.toJSON();
}
module.exports = {
js: generateJs,
css: generateCss,
};