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

Commit c2c937b

Browse files
author
John Messerly
committed
Merge pull request #13 from dart-lang/strong_mode
fix strong mode errors, and a bunch of analyzer messages
2 parents ad5f8c3 + 1dfc4a2 commit c2c937b

8 files changed

+218
-213
lines changed

lib/parser.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ StyleSheet compile(input, {List<Message> errors, PreprocessorOptions options,
6464
analyze([tree], errors: errors, options: options);
6565

6666
if (polyfill) {
67-
var processCss = new PolyFill(messages, true);
67+
var processCss = new PolyFill(messages);
6868
processCss.process(tree, includes: includes);
6969
}
7070

@@ -430,6 +430,7 @@ class _Parser {
430430
if (unaryOp != -1 || type != null || exprs.length > 0) {
431431
return new MediaQuery(unaryOp, type, exprs, _makeSpan(start));
432432
}
433+
return null;
433434
}
434435

435436
MediaExpression processMediaExpression([bool andOperator = false]) {
@@ -453,9 +454,9 @@ class _Parser {
453454
}
454455
} else if (isChecked) {
455456
_warning("Missing media feature in media expression", _makeSpan(start));
456-
return null;
457457
}
458458
}
459+
return null;
459460
}
460461

461462
/**
@@ -798,7 +799,6 @@ class _Parser {
798799
_eat(TokenKind.LBRACE);
799800

800801
List<TreeNode> productions = [];
801-
List<TreeNode> declarations = [];
802802
var mixinDirective;
803803

804804
var start = _peekToken.span;
@@ -984,6 +984,7 @@ class _Parser {
984984
return new RuleSet(
985985
selectorGroup, processDeclarations(), selectorGroup.span);
986986
}
987+
return null;
987988
}
988989

989990
/**
@@ -1191,6 +1192,7 @@ class _Parser {
11911192
if (selectors.length > 0) {
11921193
return new SelectorGroup(selectors, _makeSpan(start));
11931194
}
1195+
return null;
11941196
}
11951197

11961198
/**
@@ -1602,6 +1604,7 @@ class _Parser {
16021604

16031605
return new AttributeSelector(attrName, op, value, _makeSpan(start));
16041606
}
1607+
return null;
16051608
}
16061609

16071610
// Declaration grammar:
@@ -1763,6 +1766,7 @@ class _Parser {
17631766
if (styleType != null) {
17641767
return buildDartStyleNode(styleType, exprs, dartStyles);
17651768
}
1769+
return null;
17661770
}
17671771

17681772
FontExpression _mergeFontStyles(FontExpression fontExpr, List dartStyles) {
@@ -1910,10 +1914,8 @@ class _Parser {
19101914
return processOneNumber(exprs, styleType);
19111915
}
19121916
break;
1913-
default:
1914-
// Don't handle it.
1915-
return null;
19161917
}
1918+
return null;
19171919
}
19181920

19191921
// TODO(terry): Look at handling width of thin, thick, etc. any none numbers
@@ -1956,6 +1958,7 @@ class _Parser {
19561958
return new PaddingExpression(exprs.span, bottom: value);
19571959
}
19581960
}
1961+
return null;
19591962
}
19601963

19611964
/**

lib/src/analyzer.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -463,22 +463,21 @@ class TopLevelIncludes extends Visitor {
463463
} else if (currDef is MixinRulesetDirective && _anyRulesets(currDef)) {
464464
// currDef is MixinRulesetDirective
465465
MixinRulesetDirective mixinRuleset = currDef;
466-
int index = mixinRuleset.rulesets.indexOf(node as dynamic);
467-
mixinRuleset.rulesets.replaceRange(index, index + 1, [new NoOp()]);
466+
int index = mixinRuleset.rulesets.indexOf(node);
467+
mixinRuleset.rulesets.removeAt(index);
468468
_messages.warning(
469469
'Using declaration mixin ${node.name} as top-level mixin',
470470
node.span);
471471
}
472472
} else {
473473
if (currDef is MixinRulesetDirective) {
474474
MixinRulesetDirective rulesetDirect = currDef as MixinRulesetDirective;
475-
var index = 0;
476-
rulesetDirect.rulesets.forEach((entry) {
475+
rulesetDirect.rulesets.removeWhere((entry) {
477476
if (entry == node) {
478-
rulesetDirect.rulesets.replaceRange(index, index + 1, [new NoOp()]);
479477
_messages.warning('Undefined mixin ${node.name}', node.span);
478+
return true;
480479
}
481-
index++;
480+
return false;
482481
});
483482
}
484483
}

lib/src/polyfill.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ part of csslib.parser;
1010
*/
1111
class PolyFill {
1212
final Messages _messages;
13-
final bool _warningsAsErrors;
1413
Map<String, VarDefinition> _allVarDefinitions =
1514
new Map<String, VarDefinition>();
1615

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

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

233232
// If foundDef is unknown check if defaultValues; if it exist then resolve
@@ -236,7 +235,7 @@ VarDefinition _findTerminalVarDefinition(
236235
// We're either a VarUsage or terminal definition if in varDefs;
237236
// either way replace VarUsage with it's default value because the
238237
// VarDefinition isn't found.
239-
var defaultValues = (expr as VarUsage).defaultValues;
238+
var defaultValues = expr.defaultValues;
240239
var replaceExprs = expressions.expressions;
241240
assert(replaceExprs.length == 1);
242241
replaceExprs.replaceRange(0, 1, defaultValues);

lib/src/property.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,11 @@ class Color implements _StyleProperty, ColorBase {
278278
return new Hsla(args[0], args[1], args[2], args[3]).toHexArgbString();
279279
default:
280280
// Type not defined UnsupportedOperationException should have thrown.
281-
assert(true);
281+
assert(false);
282282
break;
283283
}
284284
}
285+
return null;
285286
}
286287

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

786787
String get cssExpression {
787788
// TODO(terry): TBD
789+
return null;
788790
}
789791
}
790792

lib/src/tokenkind.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class TokenKind {
192192
static const int PSEUDO_CLASS_NAME = 705; // :pseudoClass
193193
static const int NEGATION = 706; // NOT
194194

195-
static const List<Map<int, String>> _DIRECTIVES = const [
195+
static const List<Map<String, dynamic>> _DIRECTIVES = const [
196196
const {'type': TokenKind.DIRECTIVE_IMPORT, 'value': 'import'},
197197
const {'type': TokenKind.DIRECTIVE_MEDIA, 'value': 'media'},
198198
const {'type': TokenKind.DIRECTIVE_PAGE, 'value': 'page'},
@@ -218,13 +218,13 @@ class TokenKind {
218218
const {'type': TokenKind.DIRECTIVE_EXTEND, 'value': 'extend'},
219219
];
220220

221-
static const List<Map<int, String>> MEDIA_OPERATORS = const [
221+
static const List<Map<String, dynamic>> MEDIA_OPERATORS = const [
222222
const {'type': TokenKind.MEDIA_OP_ONLY, 'value': 'only'},
223223
const {'type': TokenKind.MEDIA_OP_NOT, 'value': 'not'},
224224
const {'type': TokenKind.MEDIA_OP_AND, 'value': 'and'},
225225
];
226226

227-
static const List<Map<int, String>> MARGIN_DIRECTIVES = const [
227+
static const List<Map<String, dynamic>> MARGIN_DIRECTIVES = const [
228228
const {
229229
'type': TokenKind.MARGIN_DIRECTIVE_TOPLEFTCORNER,
230230
'value': 'top-left-corner'

lib/src/tree.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class AttributeSelector extends SimpleSelector {
197197
case TokenKind.NO_MATCH:
198198
return '';
199199
}
200+
return null;
200201
}
201202

202203
// Return the TokenKind for operator used by visitAttributeSelector.
@@ -215,6 +216,7 @@ class AttributeSelector extends SimpleSelector {
215216
case TokenKind.SUBSTRING_MATCH:
216217
return 'SUBSTRING_MATCH';
217218
}
219+
return null;
218220
}
219221

220222
String valueToString() {
@@ -572,6 +574,7 @@ class KeyFrameDirective extends Directive {
572574
case TokenKind.DIRECTIVE_O_KEYFRAMES:
573575
return '@-o-keyframes';
574576
}
577+
return null;
575578
}
576579

577580
KeyFrameDirective clone() {
@@ -676,7 +679,7 @@ class MixinDefinition extends Directive {
676679

677680
/** Support a Sass @mixin. See http://sass-lang.com for description. */
678681
class MixinRulesetDirective extends MixinDefinition {
679-
final List<RuleSet> rulesets;
682+
final List rulesets;
680683

681684
MixinRulesetDirective(String name, List<VarDefinitionDirective> args,
682685
bool varArgs, this.rulesets, SourceSpan span)

lib/src/validate.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class Validate {
5353
// Validate the @{css expression} only .class and #elementId are valid inside
5454
// of @{...}.
5555
static template(List<Selector> selectors) {
56-
var errorSelector; // signal which selector didn't match.
5756
bool found = false; // signal if a selector is matched.
5857
int matches = 0; // < 0 IdSelectors, > 0 ClassSelector
5958

0 commit comments

Comments
 (0)