chore:更换到主分支

This commit is contained in:
张益铭
2021-03-01 15:26:05 +08:00
parent 9064b372e8
commit 6a5f1810f9
3530 changed files with 59613 additions and 479452 deletions

View File

@@ -32,7 +32,7 @@ class Core {
load(sourceString, sourcePath, trace, pathFetcher) {
let parser = new _parser2.default(pathFetcher, trace);
return (0, _postcss2.default)(this.plugins.concat([parser.plugin])).process(sourceString, { from: "/" + sourcePath }).then(result => {
return (0, _postcss2.default)(this.plugins.concat([parser.plugin()])).process(sourceString, { from: "/" + sourcePath }).then(result => {
return {
injectableSource: result.css,
exportTokens: parser.exportTokens

View File

@@ -22,8 +22,14 @@ class Parser {
this.trace = trace;
}
plugin(css) {
return Promise.all(this.fetchAllImports(css)).then(() => this.linkImportedSymbols(css)).then(() => this.extractExports(css));
plugin() {
const parser = this;
return {
postcssPlugin: "css-modules-parser",
OnceExit(css) {
return Promise.all(parser.fetchAllImports(css)).then(() => parser.linkImportedSymbols(css)).then(() => parser.extractExports(css));
}
};
}
fetchAllImports(css) {

View File

@@ -92,78 +92,78 @@ function dashesCamelCase(string) {
return string.replace(/-+(\w)/g, (_, firstLetter) => firstLetter.toUpperCase());
}
module.exports = _postcss2.default.plugin(PLUGIN_NAME, (opts = {}) => {
const getJSON = opts.getJSON || _saveJSON2.default;
module.exports = (opts = {}) => {
return {
postcssPlugin: PLUGIN_NAME,
OnceExit(css, { result }) {
return _asyncToGenerator(function* () {
const getJSON = opts.getJSON || _saveJSON2.default;
const inputFile = css.source.input.file;
const pluginList = getDefaultPluginsList(opts, inputFile);
const resultPluginIndex = result.processor.plugins.findIndex(function (plugin) {
return isOurPlugin(plugin);
});
if (resultPluginIndex === -1) {
throw new Error('Plugin missing from options.');
}
const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
const loaderPlugins = [...earlierPlugins, ...pluginList];
const loader = getLoader(opts, loaderPlugins);
const parser = new _parser2.default(loader.fetch.bind(loader));
return (() => {
var _ref = _asyncToGenerator(function* (css, result) {
const inputFile = css.source.input.file;
const pluginList = getDefaultPluginsList(opts, inputFile);
const resultPluginIndex = result.processor.plugins.findIndex(function (plugin) {
return isOurPlugin(plugin);
});
if (resultPluginIndex === -1) {
throw new Error('Plugin missing from options.');
}
const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
const loaderPlugins = [...earlierPlugins, ...pluginList];
const loader = getLoader(opts, loaderPlugins);
const parser = new _parser2.default(loader.fetch.bind(loader));
yield (0, _postcss2.default)([...pluginList, parser.plugin()]).process(css, {
from: inputFile
});
yield (0, _postcss2.default)([...pluginList, parser.plugin]).process(css, {
from: inputFile
});
const out = loader.finalSource;
if (out) css.prepend(out);
const out = loader.finalSource;
if (out) css.prepend(out);
if (opts.localsConvention) {
const isFunc = typeof opts.localsConvention === "function";
if (opts.localsConvention) {
const isFunc = typeof opts.localsConvention === "function";
parser.exportTokens = Object.entries(parser.exportTokens).reduce(function (tokens, [className, value]) {
if (isFunc) {
tokens[opts.localsConvention(className, value, inputFile)] = value;
parser.exportTokens = Object.entries(parser.exportTokens).reduce(function (tokens, [className, value]) {
if (isFunc) {
tokens[opts.localsConvention(className, value, inputFile)] = value;
return tokens;
}
switch (opts.localsConvention) {
case "camelCase":
tokens[className] = value;
tokens[(0, _lodash2.default)(className)] = value;
break;
case "camelCaseOnly":
tokens[(0, _lodash2.default)(className)] = value;
break;
case "dashes":
tokens[className] = value;
tokens[dashesCamelCase(className)] = value;
break;
case "dashesOnly":
tokens[dashesCamelCase(className)] = value;
break;
}
return tokens;
}
}, {});
}
switch (opts.localsConvention) {
case "camelCase":
tokens[className] = value;
tokens[(0, _lodash2.default)(className)] = value;
result.messages.push({
type: "export",
plugin: "postcss-modules",
exportTokens: parser.exportTokens
});
break;
case "camelCaseOnly":
tokens[(0, _lodash2.default)(className)] = value;
// getJSON may return a promise
return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
})();
}
};
};
break;
case "dashes":
tokens[className] = value;
tokens[dashesCamelCase(className)] = value;
break;
case "dashesOnly":
tokens[dashesCamelCase(className)] = value;
break;
}
return tokens;
}, {});
}
result.messages.push({
type: "export",
plugin: "postcss-modules",
exportTokens: parser.exportTokens
});
// getJSON may return a promise
return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
});
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
})();
});
module.exports.postcss = true;