Skip to content

Commit 8bfb453

Browse files
committed
Advance html5lib to newest breaking changes in core: getKeys -> keys, etc
Review URL: https://chromiumcodereview.appspot.com//11260039
1 parent 315721d commit 8bfb453

11 files changed

+97
-97
lines changed

lib/dom.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ abstract class Node {
8888
* Note that attribute order needs to be stable for serialization, so we use a
8989
* LinkedHashMap. Each key is a [String] or [AttributeName].
9090
*/
91-
LinkedHashMap<Dynamic, String> attributes = new LinkedHashMap();
91+
LinkedHashMap<dynamic, String> attributes = new LinkedHashMap();
9292

9393
/**
9494
* A list of child nodes of the current node. This must

lib/parser.dart

Lines changed: 58 additions & 58 deletions
Large diffs are not rendered by default.

lib/src/inputstream.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class HtmlInputStream {
9393

9494
if (source is String) {
9595
// TODO(jmesserly): if the data is already a string, we should just use
96-
// the source.charCodes() instead of wasting time encoding/decoding.
96+
// the source.charCodes instead of wasting time encoding/decoding.
9797
rawBytes = encodeUtf8(source);
9898
charEncodingName = 'utf-8';
9999
charEncodingCertain = true;
@@ -306,7 +306,7 @@ class HtmlInputStream {
306306
hex = (hex.length == 1) ? "0$hex" : hex;
307307
return "\\u00$hex";
308308
}
309-
var regex = joinStr(characters.charCodes().map(escapeChar));
309+
var regex = joinStr(characters.charCodes.map(escapeChar));
310310
if (!opposite) {
311311
regex = "^${regex}";
312312
}
@@ -326,8 +326,8 @@ class HtmlInputStream {
326326
break;
327327
}
328328
} else {
329-
assert(m.start() == 0);
330-
var end = m.end();
329+
assert(m.start == 0);
330+
var end = m.end;
331331
// If not the whole chunk matched, return everything
332332
// up to the part that didn't match
333333
if (end != chunk.length - chunkOffset) {

lib/src/list_proxy.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ListProxy<E> implements List<E> {
5151
bool every(bool f(E element)) => _list.every(f);
5252
bool some(bool f(E element)) => _list.some(f);
5353
bool get isEmpty => _list.isEmpty;
54-
E last() => _list.last();
54+
E get last => _list.last;
5555

5656
set length(int value) { _list.length = value; }
5757
operator []=(int index, E value) { _list[index] = value; }

lib/src/tokenizer.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'utils.dart';
1414
// we had it implemented in Dart.
1515
Map<String, List<String>> entitiesByFirstChar = (() {
1616
var result = {};
17-
for (var k in entities.getKeys()) {
17+
for (var k in entities.keys) {
1818
result.putIfAbsent(k[0], () => []).add(k);
1919
}
2020
return result;
@@ -71,7 +71,7 @@ class HtmlTokenizer implements Iterator<Token> {
7171
reset();
7272
}
7373

74-
get lastData => currentToken.data.last();
74+
get lastData => currentToken.data.last;
7575

7676
TagToken get currentTagToken => currentToken;
7777
DoctypeToken get currentDoctypeToken => currentToken;
@@ -211,16 +211,16 @@ class HtmlTokenizer implements Iterator<Token> {
211211
// Read the next character to see if it's hex or decimal
212212
bool hex = false;
213213
charStack.add(stream.char());
214-
if (charStack.last() == 'x' || charStack.last() == 'X') {
214+
if (charStack.last == 'x' || charStack.last == 'X') {
215215
hex = true;
216216
charStack.add(stream.char());
217217
}
218218

219-
// charStack.last() should be the first digit
220-
if (hex && isHexDigit(charStack.last()) ||
221-
(!hex && isDigit(charStack.last()))) {
219+
// charStack.last should be the first digit
220+
if (hex && isHexDigit(charStack.last) ||
221+
(!hex && isDigit(charStack.last))) {
222222
// At least one digit found, so consume the whole number
223-
stream.unget(charStack.last());
223+
stream.unget(charStack.last);
224224
output = consumeNumberEntity(hex);
225225
} else {
226226
// No digits found
@@ -237,7 +237,7 @@ class HtmlTokenizer implements Iterator<Token> {
237237
var filteredEntityList = entitiesByFirstChar[charStack[0]];
238238
if (filteredEntityList == null) filteredEntityList = const [];
239239

240-
while (charStack.last() !== EOF) {
240+
while (charStack.last !== EOF) {
241241
var name = joinStr(charStack);
242242
filteredEntityList = filteredEntityList.filter(
243243
(e) => e.startsWith(name));
@@ -1211,14 +1211,14 @@ class HtmlTokenizer implements Iterator<Token> {
12111211

12121212
bool markupDeclarationOpenState() {
12131213
var charStack = [stream.char()];
1214-
if (charStack.last() == "-") {
1214+
if (charStack.last == "-") {
12151215
charStack.add(stream.char());
1216-
if (charStack.last() == "-") {
1216+
if (charStack.last == "-") {
12171217
currentToken = new CommentToken("");
12181218
state = commentStartState;
12191219
return true;
12201220
}
1221-
} else if (charStack.last() == 'd' || charStack.last() == 'D') {
1221+
} else if (charStack.last == 'd' || charStack.last == 'D') {
12221222
var matched = true;
12231223
for (var expected in const ['oO', 'cC', 'tT', 'yY', 'pP', 'eE']) {
12241224
var char = stream.char();
@@ -1233,14 +1233,14 @@ class HtmlTokenizer implements Iterator<Token> {
12331233
state = doctypeState;
12341234
return true;
12351235
}
1236-
} else if (charStack.last() == "[" &&
1236+
} else if (charStack.last == "[" &&
12371237
parser !== null && parser.tree.openElements.length > 0 &&
1238-
parser.tree.openElements.last().namespace
1238+
parser.tree.openElements.last.namespace
12391239
!= parser.tree.defaultNamespace) {
12401240
var matched = true;
12411241
for (var expected in const ["C", "D", "A", "T", "A", "["]) {
12421242
charStack.add(stream.char());
1243-
if (charStack.last() != expected) {
1243+
if (charStack.last != expected) {
12441244
matched = false;
12451245
break;
12461246
}

lib/src/treebuilder.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bool _mapEquals(Map a, Map b) {
4242
if (a.length != b.length) return false;
4343
if (a.length == 0) return true;
4444

45-
for (var keyA in a.getKeys()) {
45+
for (var keyA in a.keys) {
4646
var valB = b[keyA];
4747
if (valB == null && !b.containsKey(keyA)) {
4848
return false;
@@ -194,7 +194,7 @@ class TreeBuilder {
194194
activeFormattingElements[i] = element;
195195

196196
// Step 11
197-
if (element == activeFormattingElements.last()) {
197+
if (element == activeFormattingElements.last) {
198198
break;
199199
}
200200
}
@@ -239,7 +239,7 @@ class TreeBuilder {
239239

240240
void insertComment(Token token, [Node parent]) {
241241
if (parent == null) {
242-
parent = openElements.last();
242+
parent = openElements.last;
243243
}
244244
parent.nodes.add(new Comment(token.data)..span = token.span);
245245
}
@@ -267,15 +267,15 @@ class TreeBuilder {
267267
var element = new Element(name, namespace)
268268
..attributes = token.data
269269
..span = token.span;
270-
openElements.last().nodes.add(element);
270+
openElements.last.nodes.add(element);
271271
openElements.add(element);
272272
return element;
273273
}
274274

275275
Element insertElementTable(token) {
276276
/** Create an element and insert it into the tree */
277277
var element = createElement(token);
278-
if (!tableInsertModeElements.contains(openElements.last().tagName)) {
278+
if (!tableInsertModeElements.contains(openElements.last.tagName)) {
279279
return insertElementNormal(token);
280280
} else {
281281
// We should be in the InTable mode. This means we want to do
@@ -296,10 +296,10 @@ class TreeBuilder {
296296

297297
/** Insert text data. */
298298
void insertText(String data, SourceSpan span) {
299-
var parent = openElements.last();
299+
var parent = openElements.last;
300300

301301
if (!insertFromTable || insertFromTable &&
302-
!tableInsertModeElements.contains(openElements.last().tagName)) {
302+
!tableInsertModeElements.contains(openElements.last.tagName)) {
303303
_insertText(parent, data, span);
304304
} else {
305305
// We should be in the InTable mode. This means we want to do
@@ -317,8 +317,8 @@ class TreeBuilder {
317317
[Element refNode]) {
318318
var nodes = parent.nodes;
319319
if (refNode == null) {
320-
if (nodes.length > 0 && nodes.last() is Text) {
321-
Text last = nodes.last();
320+
if (nodes.length > 0 && nodes.last is Text) {
321+
Text last = nodes.last;
322322
last.value = '${last.value}$data';
323323
} else {
324324
nodes.add(new Text(data)..span = span);
@@ -367,7 +367,7 @@ class TreeBuilder {
367367
}
368368

369369
void generateImpliedEndTags([String exclude]) {
370-
var name = openElements.last().tagName;
370+
var name = openElements.last.tagName;
371371
// XXX td, th and tr are not actually needed
372372
if (name != exclude && const ["dd", "dt", "li", "option", "optgroup", "p",
373373
"rp", "rt"].contains(name)) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: html5lib
22
author: "Dart Team <misc@dartlang.org>"
33
homepage: https://github.com/dart-lang/html5lib
44
description: A library for working with HTML documents.
5-
version: 0.0.16
5+
version: 0.0.17
66
dependencies:
77
unittest: { sdk: unittest }
88
args: { sdk: args }

test/parser_feature_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ ParseError:4:3: Unexpected DOCTYPE. Ignored.
165165
xlink:show="new"></desc>
166166
''');
167167
var n = doc.query('desc');
168-
var keys = n.attributes.getKeys();
168+
var keys = n.attributes.keys;
169169
expect(keys[0] is AttributeName);
170170
expect(keys[0].prefix, equals('xlink'));
171171
expect(keys[0].namespace, equals('http://www.w3.org/1999/xlink'));

test/parser_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void main() {
8383
errors = errors.split("\n");
8484
}
8585

86-
for (var treeCtor in treeTypes.getValues()) {
86+
for (var treeCtor in treeTypes.values) {
8787
for (var namespaceHTMLElements in const [false, true]) {
8888
test(input, () {
8989
runParserTest(testName, innerHTML, input, expected, errors,

test/support.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class TestData implements Iterable<Map> {
6060
var lines = _text.split('\n');
6161
int numLines = lines.length;
6262
// Remove trailing newline to match Python
63-
if (lines.last() == '') {
63+
if (lines.last == '') {
6464
lines.removeLast();
6565
}
6666
for (var line in lines) {
@@ -162,7 +162,7 @@ class TestSerializer extends TreeVisitor {
162162
_str.add(node);
163163
if (node.attributes.length > 0) {
164164
indent += 2;
165-
var keys = new List.from(node.attributes.getKeys());
165+
var keys = new List.from(node.attributes.keys);
166166
keys.sort((x, y) => x.compareTo(y));
167167
for (var key in keys) {
168168
var v = node.attributes[key];

0 commit comments

Comments
 (0)