Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

fix strong mode errors, and a bunch of analyzer messages #13

Merged
merged 1 commit into from
Sep 24, 2015
Merged
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
15 changes: 9 additions & 6 deletions lib/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ StyleSheet compile(input, {List<Message> errors, PreprocessorOptions options,
analyze([tree], errors: errors, options: options);

if (polyfill) {
var processCss = new PolyFill(messages, true);
var processCss = new PolyFill(messages);
processCss.process(tree, includes: includes);
}

Expand Down Expand Up @@ -430,6 +430,7 @@ class _Parser {
if (unaryOp != -1 || type != null || exprs.length > 0) {
return new MediaQuery(unaryOp, type, exprs, _makeSpan(start));
}
return null;
}

MediaExpression processMediaExpression([bool andOperator = false]) {
Expand All @@ -453,9 +454,9 @@ class _Parser {
}
} else if (isChecked) {
_warning("Missing media feature in media expression", _makeSpan(start));
return null;
}
}
return null;
}

/**
Expand Down Expand Up @@ -798,7 +799,6 @@ class _Parser {
_eat(TokenKind.LBRACE);

List<TreeNode> productions = [];
List<TreeNode> declarations = [];
var mixinDirective;

var start = _peekToken.span;
Expand Down Expand Up @@ -984,6 +984,7 @@ class _Parser {
return new RuleSet(
selectorGroup, processDeclarations(), selectorGroup.span);
}
return null;
}

/**
Expand Down Expand Up @@ -1191,6 +1192,7 @@ class _Parser {
if (selectors.length > 0) {
return new SelectorGroup(selectors, _makeSpan(start));
}
return null;
}

/**
Expand Down Expand Up @@ -1602,6 +1604,7 @@ class _Parser {

return new AttributeSelector(attrName, op, value, _makeSpan(start));
}
return null;
}

// Declaration grammar:
Expand Down Expand Up @@ -1763,6 +1766,7 @@ class _Parser {
if (styleType != null) {
return buildDartStyleNode(styleType, exprs, dartStyles);
}
return null;
}

FontExpression _mergeFontStyles(FontExpression fontExpr, List dartStyles) {
Expand Down Expand Up @@ -1910,10 +1914,8 @@ class _Parser {
return processOneNumber(exprs, styleType);
}
break;
default:
// Don't handle it.
return null;
}
return null;
}

// TODO(terry): Look at handling width of thin, thick, etc. any none numbers
Expand Down Expand Up @@ -1956,6 +1958,7 @@ class _Parser {
return new PaddingExpression(exprs.span, bottom: value);
}
}
return null;
}

/**
Expand Down
11 changes: 5 additions & 6 deletions lib/src/analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -463,22 +463,21 @@ class TopLevelIncludes extends Visitor {
} else if (currDef is MixinRulesetDirective && _anyRulesets(currDef)) {
// currDef is MixinRulesetDirective
MixinRulesetDirective mixinRuleset = currDef;
int index = mixinRuleset.rulesets.indexOf(node as dynamic);
mixinRuleset.rulesets.replaceRange(index, index + 1, [new NoOp()]);
int index = mixinRuleset.rulesets.indexOf(node);
mixinRuleset.rulesets.removeAt(index);
_messages.warning(
'Using declaration mixin ${node.name} as top-level mixin',
node.span);
}
} else {
if (currDef is MixinRulesetDirective) {
MixinRulesetDirective rulesetDirect = currDef as MixinRulesetDirective;
var index = 0;
rulesetDirect.rulesets.forEach((entry) {
rulesetDirect.rulesets.removeWhere((entry) {
if (entry == node) {
rulesetDirect.rulesets.replaceRange(index, index + 1, [new NoOp()]);
_messages.warning('Undefined mixin ${node.name}', node.span);
return true;
}
index++;
return false;
});
}
}
Expand Down
7 changes: 3 additions & 4 deletions lib/src/polyfill.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ part of csslib.parser;
*/
class PolyFill {
final Messages _messages;
final bool _warningsAsErrors;
Map<String, VarDefinition> _allVarDefinitions =
new Map<String, VarDefinition>();

Expand All @@ -21,7 +20,7 @@ class PolyFill {
* CSS pseudo-elements 'name::custom-element' is mapped to the manged name
* associated with the pseudo-element key.
*/
PolyFill(this._messages, this._warningsAsErrors);
PolyFill(this._messages);

/**
* Run the analyzer on every file that is a style sheet or any component that
Expand Down Expand Up @@ -227,7 +226,7 @@ VarDefinition _findTerminalVarDefinition(
var expressions = varDef.expression as Expressions;
for (var expr in expressions.expressions) {
if (expr is VarUsage) {
var usageName = (expr as VarUsage).name;
var usageName = expr.name;
var foundDef = varDefs[usageName];

// If foundDef is unknown check if defaultValues; if it exist then resolve
Expand All @@ -236,7 +235,7 @@ VarDefinition _findTerminalVarDefinition(
// We're either a VarUsage or terminal definition if in varDefs;
// either way replace VarUsage with it's default value because the
// VarDefinition isn't found.
var defaultValues = (expr as VarUsage).defaultValues;
var defaultValues = expr.defaultValues;
var replaceExprs = expressions.expressions;
assert(replaceExprs.length == 1);
replaceExprs.replaceRange(0, 1, defaultValues);
Expand Down
4 changes: 3 additions & 1 deletion lib/src/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,11 @@ class Color implements _StyleProperty, ColorBase {
return new Hsla(args[0], args[1], args[2], args[3]).toHexArgbString();
default:
// Type not defined UnsupportedOperationException should have thrown.
assert(true);
assert(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does ddc check for this? or was this an analyzer hint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... yeah, hah!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, neither ... there is a message about missing return, and the John Analyzer noticed it :)

break;
}
}
return null;
}

static int hexToInt(String hex) => int.parse(hex, radix: 16);
Expand Down Expand Up @@ -785,6 +786,7 @@ class PointXY implements _StyleProperty {

String get cssExpression {
// TODO(terry): TBD
return null;
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/src/tokenkind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class TokenKind {
static const int PSEUDO_CLASS_NAME = 705; // :pseudoClass
static const int NEGATION = 706; // NOT

static const List<Map<int, String>> _DIRECTIVES = const [
static const List<Map<String, dynamic>> _DIRECTIVES = const [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so many lies! I feel deceived!

const {'type': TokenKind.DIRECTIVE_IMPORT, 'value': 'import'},
const {'type': TokenKind.DIRECTIVE_MEDIA, 'value': 'media'},
const {'type': TokenKind.DIRECTIVE_PAGE, 'value': 'page'},
Expand All @@ -218,13 +218,13 @@ class TokenKind {
const {'type': TokenKind.DIRECTIVE_EXTEND, 'value': 'extend'},
];

static const List<Map<int, String>> MEDIA_OPERATORS = const [
static const List<Map<String, dynamic>> MEDIA_OPERATORS = const [
const {'type': TokenKind.MEDIA_OP_ONLY, 'value': 'only'},
const {'type': TokenKind.MEDIA_OP_NOT, 'value': 'not'},
const {'type': TokenKind.MEDIA_OP_AND, 'value': 'and'},
];

static const List<Map<int, String>> MARGIN_DIRECTIVES = const [
static const List<Map<String, dynamic>> MARGIN_DIRECTIVES = const [
const {
'type': TokenKind.MARGIN_DIRECTIVE_TOPLEFTCORNER,
'value': 'top-left-corner'
Expand Down
5 changes: 4 additions & 1 deletion lib/src/tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class AttributeSelector extends SimpleSelector {
case TokenKind.NO_MATCH:
return '';
}
return null;
}

// Return the TokenKind for operator used by visitAttributeSelector.
Expand All @@ -215,6 +216,7 @@ class AttributeSelector extends SimpleSelector {
case TokenKind.SUBSTRING_MATCH:
return 'SUBSTRING_MATCH';
}
return null;
}

String valueToString() {
Expand Down Expand Up @@ -572,6 +574,7 @@ class KeyFrameDirective extends Directive {
case TokenKind.DIRECTIVE_O_KEYFRAMES:
return '@-o-keyframes';
}
return null;
}

KeyFrameDirective clone() {
Expand Down Expand Up @@ -676,7 +679,7 @@ class MixinDefinition extends Directive {

/** Support a Sass @mixin. See http://sass-lang.com for description. */
class MixinRulesetDirective extends MixinDefinition {
final List<RuleSet> rulesets;
final List rulesets;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason we can't preserve the type arg here? or was the list used with a mix of types not just RuleSet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, exactly, it's not just rulesets.
I haven't (yet) figured out what it can contain...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will get fixed further in a follow up which reduces warnings... I'm almost done there. Do you want me to rebase with those changes or does this initial CL look good to you?


MixinRulesetDirective(String name, List<VarDefinitionDirective> args,
bool varArgs, this.rulesets, SourceSpan span)
Expand Down
1 change: 0 additions & 1 deletion lib/src/validate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class Validate {
// Validate the @{css expression} only .class and #elementId are valid inside
// of @{...}.
static template(List<Selector> selectors) {
var errorSelector; // signal which selector didn't match.
bool found = false; // signal if a selector is matched.
int matches = 0; // < 0 IdSelectors, > 0 ClassSelector

Expand Down
Loading