Skip to content

Commit

Permalink
build: fix --css-optimize-names (regression)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Jun 21, 2016
1 parent a824641 commit 59923ed
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
8 changes: 3 additions & 5 deletions lib/build/css/optimizeNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function toBase52(num){
return !classMap[key].postfix;
}).sort(function(a, b){
return (b.length - 1) * classMap[b].length - (a.length - 1) * classMap[a].length;
}).forEach(function processKey(name, idx){
}).forEach(function processKey(name){
function replaceFn(cls){
var result = cls == name ? replace : cls;
if (item.type != 'tmpl-class-binding')
Expand All @@ -68,7 +68,7 @@ function toBase52(num){
}

var list = classMap[name];
var replace = getClassNameReplace(idx) + list.postfix;
var replace = getClassNameReplace(list.name) + list.postfix;
var saving = 0;

for (var i = 0, item, token, tokenSaving; item = list[i]; i++)
Expand Down Expand Up @@ -120,9 +120,7 @@ function toBase52(num){
totalSaving += saving;
fconsole.log(name, '->', replace, '(' + saving + ' / ' + list.length + ')');

list.nested.forEach(function(nestedName){
processKey(nestedName, idx);
});
list.nested.forEach(processKey);
});

fconsole.endl();
Expand Down
23 changes: 12 additions & 11 deletions lib/extract/css/collectInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,31 @@ var atTmpl = require('basisjs-tools-ast').tmpl;
// Collect names
//

function getMap(map, theme, key){
function getMap(map, theme, name){
if (!hasOwnProperty.call(map, theme))
map[theme] = {};

var themeMap = map[theme];

if (!hasOwnProperty.call(themeMap, key))
if (!hasOwnProperty.call(themeMap, name))
{
var list = [];
list.sources = {};
list.nested = [];
list.key = key;
list.name = name;
list.postfix = '';
themeMap[key] = list;
themeMap[name] = list;

var baseKey = key.replace(/-anim$/, '');
if (baseKey != key)
var baseName = name.replace(/-anim$/, '');
if (baseName != name)
{
list.postfix = '-anim';
getMap(map, theme, baseKey).nested.push(key);
list.name = baseName;
getMap(map, theme, baseName).nested.push(name);
}
}

return themeMap[key];
return themeMap[name];
}

function addToScope(namespaces, className){
Expand All @@ -73,14 +74,14 @@ var atTmpl = require('basisjs-tools-ast').tmpl;
}
}

function add(map, file, key, token, type, loc){
function add(map, file, name, token, type, loc){
var typePart = type.split('-');
var themes = file.themes || appThemes;

themes.forEach(function(theme){
var list = getMap(map, theme, key);
var list = getMap(map, theme, name);

fconsole.log(typePart[1] + ': ' + key + ' (' + theme + ')');
fconsole.log(typePart[1] + ': ' + name + ' (' + theme + ')');

list.push({
file: file,
Expand Down

0 comments on commit 59923ed

Please sign in to comment.