Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix text-shadow bug #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 1 addition & 0 deletions lib/css/valuebucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ exports['text-decoration-style'] = require('./values/text-decoration-style');
exports['text-indent'] = require('./values/text-indent');
exports['text-overflow'] = require('./values/text-overflow');
exports['text-shadow'] = require('./values/text-shadow');
exports['text-shadow-single'] = require('./values/text-shadow-single');
exports['text-size-adjust'] = require('./values/text-size-adjust');
exports['text-transform-case'] = require('./values/text-transform-case');
exports['text-transform'] = require('./values/text-transform');
Expand Down
66 changes: 66 additions & 0 deletions lib/css/values/text-shadow-single.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* <text-shadow-single>
*
* CSS3: none | [ <length>{2,3} && <color>? ]#
*
*/

"use strict";

var base = require('./base');
var util = require('../../util');
var validate = require('./validate');

var TextShadowSingle = base.baseConstructor();

util.extend(TextShadowSingle.prototype, base.base, {
name: "text-shadow-single"
});


exports.parse = function (unparsedReal, bucket, container) {
var tss = new TextShadowSingle(bucket, container, unparsedReal);
tss.debug('parse', unparsedReal);
var noneFound = false;
validate.call(tss, 'minimumCss', tss.firstToken(), 3);

if (tss.handleInherit(function () {})) {
return tss;
}

if (tss.unparsed.isContent('none')) {
noneFound = true;
tss.add(tss.unparsed.advance());
return tss;
}

var c = bucket['color'].parse(tss.unparsed, bucket, tss);

if (c) {
tss.add(c);
tss.unparsed = c.unparsed;
}

var lengths = tss.repeatParser([ bucket['length'] ], 3);

if (lengths < 2) {
tss.debug('parse fail');
return null;
}

if (! c) {
c = bucket['color'].parse(tss.unparsed, bucket, tss);

if (c) {
tss.add(c);
tss.unparsed = c.unparsed;
}
}

if (! noneFound && tss.unparsed.isContent('none')) {
tss.add(tss.unparsed.advance());
}

tss.warnIfInherit();
tss.debug('parse success', tss.unparsed);
return tss;
};
33 changes: 4 additions & 29 deletions lib/css/values/text-shadow.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* <text-shadow>
*
* CSS3: none | [ <length>{2,3} && <color>? ]#
*
* CSS3: inherit | none | <text-shadow-single>#
*/

"use strict";
Expand All @@ -16,51 +15,27 @@ util.extend(TextShadow.prototype, base.base, {
name: "text-shadow"
});


exports.parse = function (unparsedReal, bucket, container) {
var ts = new TextShadow(bucket, container, unparsedReal);
var unparsed = unparsedReal.clone();
ts.debug('parse', unparsedReal);
var noneFound = false;
validate.call(ts, 'minimumCss', ts.firstToken(), 3);

if (ts.handleInherit(function () {})) {
return ts;
}

if (ts.unparsed.isContent('none')) {
noneFound = true;
ts.add(ts.unparsed.advance());
return ts;
}

var c = bucket['color'].parse(ts.unparsed, bucket, ts);

if (c) {
ts.add(c);
ts.unparsed = c.unparsed;
}
ts.repeatWithCommas = true;

var lengths = ts.repeatParser([ bucket['length'] ], 3);

if (lengths < 2) {
ts.debug('parse fail');
if (! ts.repeatParser([ bucket['text-shadow-single'] ])) {
return null;
}

if (! c) {
c = bucket['color'].parse(ts.unparsed, bucket, ts);

if (c) {
ts.add(c);
ts.unparsed = c.unparsed;
}
}

if (! noneFound && ts.unparsed.isContent('none')) {
ts.add(ts.unparsed.advance());
}

ts.warnIfInherit();
ts.debug('parse success', ts.unparsed);
return ts;
};
53 changes: 53 additions & 0 deletions test/css/values/text-shadow-single-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use strict";
var util = require('./util');

exports.batch = util.makeVows('text-shadow-single', {
'none': {
'tokens': ['IDENT'],
'toString': 'none',
'unparsed': [],
'warnings': ['css-minimum:3']
},
'12px': {
'tokens': ['UNIT'],
'toString': null,
'unparsed': ['UNIT'],
'warnings': null
},
'12px 12px watermelon': {
'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT'],
'toString': '12px 12px',
'unparsed': ['IDENT'],
'warnings': ['css-minimum:3']
},
'12px 12px blue 12px': {
'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT', 'S', 'UNIT'],
'toString': '12px 12px blue',
'unparsed': ['UNIT'],
'warnings': ['css-minimum:3']
},
'blue 12px 1px 5px': {
'tokens': ['IDENT', 'S', 'UNIT', 'S', 'UNIT', 'S', 'UNIT'],
'toString': 'blue 12px 1px 5px',
'unparsed': [],
'warnings': ['css-minimum:3']
},
'12px 12px inherit': {
'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT'],
'toString': '12px 12px inherit',
'unparsed': [],
'warnings': ['css-minimum:3', 'inherit-not-allowed']
},
'inherit': {
'tokens': ['IDENT'],
'toString': 'inherit',
'unparsed': [],
'warnings': ['css-minimum:3']
},
'invalidValue': {
'tokens': ['IDENT'],
'toString': null,
'unparsed': ['IDENT'],
'warnings': null
}
});
72 changes: 24 additions & 48 deletions test/css/values/text-shadow-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,28 @@
var util = require('./util');

exports.batch = util.makeVows('text-shadow', {
'none': {
'tokens': ['IDENT'],
'toString': 'none',
'unparsed': [],
'warnings': ['css-minimum:3']
},
'12px': {
'tokens': ['UNIT'],
'toString': null,
'unparsed': ['UNIT'],
'warnings': null
},
'12px 12px watermelon': {
'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT'],
'toString': '12px 12px',
'unparsed': ['IDENT'],
'warnings': ['css-minimum:3']
},
'12px 12px blue 12px': {
'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT', 'S', 'UNIT'],
'toString': '12px 12px blue',
'unparsed': ['UNIT'],
'warnings': ['css-minimum:3']
},
'blue 12px 1px 5px': {
'tokens': ['IDENT', 'S', 'UNIT', 'S', 'UNIT', 'S', 'UNIT'],
'toString': 'blue 12px 1px 5px',
'unparsed': [],
'warnings': ['css-minimum:3']
},
'12px 12px inherit': {
'tokens': ['UNIT', 'S', 'UNIT', 'S', 'IDENT'],
'toString': '12px 12px inherit',
'unparsed': [],
'warnings': ['css-minimum:3', 'inherit-not-allowed']
},
'inherit': {
'tokens': ['IDENT'],
'toString': 'inherit',
'unparsed': [],
'warnings': ['css-minimum:3']
},
'invalidValue': {
'tokens': ['IDENT'],
'toString': null,
'unparsed': ['IDENT'],
'warnings': null
}
'blue 12px 1px 5px, blue 12px 1px 5px': {
'tokens': ['IDENT', 'S', 'UNIT', 'S', 'UNIT', 'S', 'UNIT', 'OPERATOR', 'S', 'IDENT', 'S', 'UNIT', 'S', 'UNIT', 'S', 'UNIT'],
'toString': 'blue 12px 1px 5px, blue 12px 1px 5px',
'unparsed': [],
'warnings': ['css-minimum:3']
},
'none': {
'tokens': ['IDENT'],
'toString': 'none',
'unparsed': [],
'warnings': ['css-minimum:3']
},
'inherit': {
'tokens': ['IDENT'],
'toString': 'inherit',
'unparsed': [],
'warnings': ['css-minimum:3']
},
'invalidValue': {
'tokens': ['IDENT'],
'toString': null,
'unparsed': ['IDENT'],
'warnings': null
}
});