Skip to content

Commit

Permalink
Merge pull request #1329 from alibaba/chore/remove-stylesheet-loader-log
Browse files Browse the repository at this point in the history
chore: disableLog default to true
  • Loading branch information
yuanyan authored Sep 8, 2019
2 parents 28e5d37 + 9ac8e38 commit 2a7929d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/jsx-compiler/src/modules/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ function convertCSSUnit(raw, originExt = 'rem', targetExt = 'rpx') {
}

function createCSSModule(content) {
const loaderContext = { query: '?disableLog=true' };
const loaderContext = { query: '?log=false' };
return stylesheetLoader.call(loaderContext, content);
}
2 changes: 1 addition & 1 deletion packages/stylesheet-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stylesheet-loader",
"version": "0.6.6-0",
"version": "0.6.7",
"description": "Stylesheet loader.",
"license": "BSD-3-Clause",
"main": "lib/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/stylesheet-loader/src/Validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import particular from './particular';
import chalk from 'chalk';

class Validation {
static validate(camelCaseProperty, prop, value, selectors = '', position = {}, disableLog) {
if (disableLog) return {};
static validate(camelCaseProperty, prop, value, selectors = '', position = {}, log) {
if (!log) return {};
if (allStylePropTypes[camelCaseProperty]) {
let error = allStylePropTypes[camelCaseProperty](value, prop, selectors);

Expand Down
2 changes: 1 addition & 1 deletion packages/stylesheet-loader/src/__tests__/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('transformer', () => {
it('should return null when writing multiple selectors', () => {
const result = transformer.sanitizeSelector('.abc .bcd');

expect(result).toBe(null);
expect(result).toBe('abc_bcd');
});

it('should convert prop with camelCase', () => {
Expand Down
9 changes: 6 additions & 3 deletions packages/stylesheet-loader/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ module.exports = function(source) {
}

const parsedQuery = loaderUtils.parseQuery(this.query);

parsedQuery.log = parsedQuery.log === 'true';

const parsedData = parse(parsedQuery, stylesheet);

return genStyleContent(parsedData, parsedQuery);
Expand All @@ -36,10 +39,10 @@ const parse = (parsedQuery, stylesheet) => {

// normal rule
if (rule.type === RULE) {
style = transformer.convert(rule, parsedQuery.disableLog);
style = transformer.convert(rule, parsedQuery.log);

rule.selectors.forEach((selector) => {
let sanitizedSelector = transformer.sanitizeSelector(selector, transformDescendantCombinator, rule.position, parsedQuery.disableLog);
let sanitizedSelector = transformer.sanitizeSelector(selector, transformDescendantCombinator, rule.position, parsedQuery.log);

if (sanitizedSelector) {
// handle pseudo class
Expand Down Expand Up @@ -90,7 +93,7 @@ const genStyleContent = (parsedData, parsedQuery) => {
const {styles, fontFaceRules, mediaRules} = parsedData;
const fontFaceContent = getFontFaceContent(fontFaceRules);
const mediaContent = getMediaContent(mediaRules);
const warnMessageOutput = parsedQuery.disableLog ? '' : getWarnMessageOutput();
const warnMessageOutput = parsedQuery.log ? getWarnMessageOutput() : '';

resetMessage();

Expand Down
8 changes: 4 additions & 4 deletions packages/stylesheet-loader/src/transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const COLOR_PROPERTIES = {
};

export default {
sanitizeSelector(selector, transformDescendantCombinator = false, position = { start: { line: 0, column: 0 } }, disableLog = false) {
sanitizeSelector(selector, transformDescendantCombinator = false, position = { start: { line: 0, column: 0 } }, log = false) {
// tag selector suffix @
if (/^[a-zA-Z]/.test(selector)) {
selector = '@' + selector;
}
// filter multiple extend selectors
if (!disableLog && !transformDescendantCombinator && !/^[.|@|#][a-zA-Z0-9_:\-]+$/.test(selector)) {
if (log && !transformDescendantCombinator && !/^[.|@|#][a-zA-Z0-9_:\-]+$/.test(selector)) {
const message = `line: ${position.start.line}, column: ${position.start.column} - "${selector}" is not a valid selector (e.g. ".abc、.abcBcd、.abc_bcd")`;
console.error(chalk.red.bold(message));
pushErrorMessage(message);
Expand Down Expand Up @@ -64,7 +64,7 @@ export default {
return result;
},

convert(rule, disableLog) {
convert(rule, log) {
let style = {};

if (rule.tagName === 'text') {
Expand All @@ -80,7 +80,7 @@ export default {
let value = this.convertValue(camelCaseProperty, declaration.value);
style[camelCaseProperty] = value;

Validation.validate(camelCaseProperty, declaration.property, declaration.value, rule.selectors.join(', '), declaration.position, disableLog);
Validation.validate(camelCaseProperty, declaration.property, declaration.value, rule.selectors.join(', '), declaration.position, log);
if (particular[camelCaseProperty]) {
let particularResult = particular[camelCaseProperty](value);
if (particularResult.isDeleted) {
Expand Down

0 comments on commit 2a7929d

Please sign in to comment.