Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/less/dist

This file was deleted.

11,785 changes: 11,785 additions & 0 deletions packages/less/dist/less.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions packages/less/dist/less.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/less/dist/less.min.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/less/src/less/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2102,6 +2102,9 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
hasUnknown = true;
isRooted = false;
break;
case '@starting-style':
isRooted = false;
break;
default:
hasUnknown = true;
break;
Expand Down
127 changes: 112 additions & 15 deletions packages/less/src/less/tree/atrule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Node from './node';
import Selector from './selector';
import Ruleset from './ruleset';
import Anonymous from './anonymous';
import NestableAtRulePrototype from './nested-at-rule';

const AtRule = function(
name,
Expand All @@ -14,19 +15,45 @@ const AtRule = function(
visibilityInfo
) {
let i;
var selectors = (new Selector([], null, null, this._index, this._fileInfo)).createEmptySelectors();

this.name = name;
this.value = (value instanceof Node) ? value : (value ? new Anonymous(value) : value);
if (rules) {
if (Array.isArray(rules)) {
this.rules = rules;
const allDeclarations = rules.filter(function (node) { return node.type === 'Declaration' && !node.merge; }).length === rules.length;

let allRulesetDeclarations = true;
rules.forEach(rule => {
if (rule.type === 'Ruleset' && rule.rules) allRulesetDeclarations = allRulesetDeclarations && rule.rules.filter(function (node) { return node.type === 'Declaration'; }).length === rule.rules.length
});

if (allDeclarations && !isRooted) {
this.simpleBlock = true;
this.declarations = rules;
} else if (allRulesetDeclarations && rules.length === 1 && !isRooted && !value) {
this.simpleBlock = true;
this.declarations = rules[0].rules ? rules[0].rules : rules;
} else {
this.rules = rules;
}
} else {
this.rules = [rules];
this.rules[0].selectors = (new Selector([], null, null, index, currentFileInfo)).createEmptySelectors();
const allDeclarations = rules.rules.filter(function (node) { return node.type === 'Declaration' && !node.merge}).length === rules.rules.length;

if (allDeclarations && !isRooted && !value) {
this.simpleBlock = true;
this.declarations = rules.rules;
} else {
this.rules = [rules];
this.rules[0].selectors = (new Selector([], null, null, index, currentFileInfo)).createEmptySelectors();
}
}
for (i = 0; i < this.rules.length; i++) {
this.rules[i].allowImports = true;
if (!this.simpleBlock) {
for (i = 0; i < this.rules.length; i++) {
this.rules[i].allowImports = true;
}
}
this.setParent(selectors, this);
this.setParent(this.rules, this);
}
this._index = index;
Expand All @@ -39,11 +66,18 @@ const AtRule = function(

AtRule.prototype = Object.assign(new Node(), {
type: 'AtRule',

...NestableAtRulePrototype,

accept(visitor) {
const value = this.value, rules = this.rules;
const value = this.value, rules = this.rules, declarations = this.declarations;

if (rules) {
this.rules = visitor.visitArray(rules);
}
else if (declarations) {
this.declarations = visitor.visitArray(declarations);
}
if (value) {
this.value = visitor.visit(value);
}
Expand All @@ -58,22 +92,24 @@ AtRule.prototype = Object.assign(new Node(), {
},

genCSS(context, output) {
const value = this.value, rules = this.rules;
const value = this.value, rules = this.rules || this.declarations;
output.add(this.name, this.fileInfo(), this.getIndex());
if (value) {
output.add(' ');
value.genCSS(context, output);
}
if (rules) {
if (this.simpleBlock) {
this.outputRuleset(context, output, this.declarations);
} else if (rules) {
this.outputRuleset(context, output, rules);
} else {
output.add(';');
}
},

eval(context) {
let mediaPathBackup, mediaBlocksBackup, value = this.value, rules = this.rules;

let mediaPathBackup, mediaBlocksBackup, value = this.value, rules = this.rules || this.declarations;
// media stored inside other atrule should not bubble over it
// backpup media bubbling information
mediaPathBackup = context.mediaPath;
Expand All @@ -85,17 +121,78 @@ AtRule.prototype = Object.assign(new Node(), {
if (value) {
value = value.eval(context);
}

if (rules) {
// assuming that there is only one rule at this point - that is how parser constructs the rule
rules = [rules[0].eval(context)];
rules[0].root = true;
rules = this.evalRoot(context, rules);
}
if (Array.isArray(rules) && rules[0].rules && Array.isArray(rules[0].rules) && rules[0].rules.length) {
var allMergeableDeclarations = rules[0].rules.filter(function (node) { return node.type === 'Declaration'; }).length === rules[0].rules.length;
var allDeclarations = rules[0].rules.filter(function (node) { return node.type === 'Declaration' && !node.merge; }).length === rules[0].rules.length;
if (!allDeclarations && allMergeableDeclarations && !this.isRooted && !value) {
var mergeRules = context.pluginManager.less.visitors.ToCSSVisitor.prototype._mergeRules;
mergeRules(rules[0].rules);
rules = rules[0].rules;
}
}
if (this.simpleBlock && rules) {
rules[0].functionRegistry = context.frames[0].functionRegistry.inherit();
rules= rules.map(function (rule) { return rule.eval(context); });
}

// restore media bubbling information
context.mediaPath = mediaPathBackup;
context.mediaBlocks = mediaBlocksBackup;
return new AtRule(this.name, value, rules, this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo());
},

return new AtRule(this.name, value, rules,
this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo());
evalRoot(context, rules) {
let ampersandCount = 0;
let noAmpersandCount = 0;
let noAmpersands = true;
let allAmpersands = false;

if (!this.simpleBlock) {
rules = [rules[0].eval(context)];
}

let precedingSelectors = [];
if (context.frames.length > 0) {
for (let index = 0; index < context.frames.length; index++) {
const frame = context.frames[index];
if (
frame.type === 'Ruleset' &&
frame.rules &&
frame.rules.length > 0
) {
if (frame && !frame.root && frame.selectors && frame.selectors.length > 0) {
precedingSelectors = precedingSelectors.concat(frame.selectors);
}
}
if (precedingSelectors.length > 0) {
let value = '';
const output = { add: function (s) { value += s; } };
for (let i = 0; i < precedingSelectors.length; i++) {
precedingSelectors[i].genCSS(context, output);
}
if (/^&+$/.test(value.replace(/\s+/g, ''))) {
noAmpersands = false;
noAmpersandCount++;
} else {
allAmpersands = false;
ampersandCount++;
}
}
}
}

const mixedAmpersands = ampersandCount > 0 && noAmpersandCount > 0 && !allAmpersands && !noAmpersands;
if (
(this.isRooted && ampersandCount > 0 && noAmpersandCount === 0 && !allAmpersands && noAmpersands)
|| !mixedAmpersands
) {
rules[0].root = true;
}
return rules;
},

variable(name) {
Expand Down
13 changes: 12 additions & 1 deletion packages/less/src/less/visitors/import-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,18 @@ ImportVisitor.prototype = {
}
},
visitAtRule: function (atRuleNode, visitArgs) {
this.context.frames.unshift(atRuleNode);
//this.context.frames.unshift(atRuleNode);
if (atRuleNode.value) {//}} && !atRuleNode.declarations && !atRuleNode.rules) {
this.context.frames.unshift(atRuleNode);
} else if (atRuleNode.declarations && atRuleNode.declarations.length) {
if (atRuleNode.isRooted) {
this.context.frames.unshift(atRuleNode);
} else {
this.context.frames.unshift(atRuleNode.declarations[0]);
}
} else if (atRuleNode.rules && atRuleNode.rules.length) {
this.context.frames.unshift(atRuleNode);
}
},
visitAtRuleOut: function (atRuleNode) {
this.context.frames.shift();
Expand Down
8 changes: 6 additions & 2 deletions packages/less/src/less/visitors/join-selector-visitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ class JoinSelectorVisitor {
}

visitAtRule(atRuleNode, visitArgs) {
const context = this.contexts[this.contexts.length - 1];
if (atRuleNode.rules && atRuleNode.rules.length) {
let context = this.contexts[this.contexts.length - 1];

if (atRuleNode.declarations && atRuleNode.declarations.length) {
atRuleNode.declarations[0].root = (context.length === 0 || context[0].multiMedia);
}
else if (atRuleNode.rules && atRuleNode.rules.length) {
atRuleNode.rules[0].root = (atRuleNode.isRooted || context.length === 0 || null);
}
}
Expand Down
45 changes: 45 additions & 0 deletions packages/test-data/css/_main/starting-style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#nav {
transition: background-color 3.5s;
background-color: gray;
}
[popover]:popover-open {
opacity: 1;
transform: scaleX(1);
}
@starting-style {
[popover]:popover-open {
opacity: 0;
transform: scaleX(0);
}
}
#target {
transition: background-color 1.5s;
background-color: green;
}
@starting-style {
#target {
background-color: transparent;
}
}
#source {
transition: background-color 2.5s;
background-color: red;
}
source:first {
opacity: 1;
transform: scaleX(1);
}
@starting-style {
source:first {
opacity: 0;
transform: scaleX(0);
}
}
#footer {
color: yellow;
}
@starting-style {
#footer {
background-color: transparent;
}
}
50 changes: 50 additions & 0 deletions packages/test-data/less/_main/starting-style.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#nav {
transition: background-color 3.5s;
background-color: gray;
}

[popover]:popover-open {
opacity: 1;
transform: scaleX(1);

@starting-style {
opacity: 0;
transform: scaleX(0);
}
}

#target {
transition: background-color 1.5s;
background-color: green;
}

@starting-style {
#target {
background-color: transparent;
}
}

#source {
transition: background-color 2.5s;
background-color: red;
}

source:first {
opacity: 1;
transform: scaleX(1);

@starting-style {
opacity: 0;
transform: scaleX(0);
}
}

#footer {
color: yellow;
}

@starting-style {
#footer {
background-color: transparent;
}
}
Loading