"})); + succeed('', TEXTAREA({ value: 'asdf' })); + succeed('', TEXTAREA({ x: 'y', value: 'asdf' })); + succeed('', TEXTAREA({ value: '
' }));
succeed('',
- TEXTAREA({value: ["a", CharRef({html: '&', str: '&'}), "b"]}));
- succeed('', TEXTAREA({value: "', TEXTAREA({ value: '\n', TEXTAREA());
- succeed('', TEXTAREA({value: "asdf"}));
- succeed('', TEXTAREA({value: "\nasdf"}));
- succeed('', TEXTAREA({value: "\n"}));
- succeed('', TEXTAREA({value: "asdf\n"}));
- succeed('', TEXTAREA({value: ""}));
- succeed('', TEXTAREA({value: "asdf"}));
+ succeed('', TEXTAREA({ value: 'asdf' }));
+ succeed('', TEXTAREA({ value: '\nasdf' }));
+ succeed('', TEXTAREA({ value: '\n' }));
+ succeed('', TEXTAREA({ value: 'asdf\n' }));
+ succeed('', TEXTAREA({ value: '' }));
+ succeed('', TEXTAREA({ value: 'asdf' }));
fatal('');
- succeed('
")); - succeed('', SCRIPT("a&b")); - succeed('', SCRIPT("\n', SCRIPT("\n")); - succeed('', SCRIPT("")); - succeed('', SCRIPT("asdf")); + succeed('', SCRIPT('const x="
')); + succeed('', SCRIPT('a&b')); + succeed('', SCRIPT('\n', SCRIPT('\n')); + succeed('', SCRIPT('')); + succeed('', SCRIPT('asdf')); fatal('&davidgreenspan;', SCRIPT("&davidgreenspan;")); - succeed('', SCRIPT("&")); + succeed('', SCRIPT('&davidgreenspan;')); + succeed('', SCRIPT('&')); succeed('asdf', - [SCRIPT("asdf', STYLE("asdf")); - succeed('', STYLE({x: "y"}, "asdf")); - succeed('', STYLE("
")); - succeed('', STYLE("a&b")); - succeed('', STYLE("\n', STYLE("\n")); - succeed('', STYLE("")); - succeed('', STYLE("asdf")); + [SCRIPT('asdf', STYLE('asdf')); + succeed('', STYLE({ x: 'y' }, 'asdf')); + succeed('', STYLE('
')); + succeed('', STYLE('a&b')); + succeed('', STYLE('\n', STYLE('\n')); + succeed('', STYLE('')); + succeed('', STYLE('asdf')); fatal('&davidgreenspan;', STYLE("&davidgreenspan;")); - succeed('', STYLE("&")); + succeed('', STYLE('&davidgreenspan;')); + succeed('', STYLE('&')); succeed('asdf', - [STYLE("
Hello
Hello
x
'); + const p = HTMLTools.parseFragment('x
'); test.equal(p.tagName, 'p'); test.equal(p.attrs, null); test.isTrue(p instanceof HTML.Tag); test.equal(p.children.length, 1); test.equal(p.children[0], 'x'); - })(); + }()); (function () { - var p = HTMLTools.parseFragment('xA
'); + const p = HTMLTools.parseFragment('xA
'); test.equal(p.tagName, 'p'); test.equal(p.attrs, null); test.isTrue(p instanceof HTML.Tag); @@ -229,10 +227,10 @@ Tinytest.add("html-tools - parseFragment", function (test) { test.isTrue(p.children[1] instanceof HTML.CharRef); test.equal(p.children[1].html, 'A'); test.equal(p.children[1].str, 'A'); - })(); + }()); (function () { - var pp = HTMLTools.parseFragment('x
y
'); + const pp = HTMLTools.parseFragment('x
y
'); test.isTrue(pp instanceof Array); test.equal(pp.length, 2); @@ -247,56 +245,52 @@ Tinytest.add("html-tools - parseFragment", function (test) { test.isTrue(pp[1] instanceof HTML.Tag); test.equal(pp[1].children.length, 1); test.equal(pp[1].children[0], 'y'); - })(); + }()); - var scanner = new Scanner('asdf'); + const scanner = new Scanner('asdf'); scanner.pos = 1; test.equal(HTMLTools.parseFragment(scanner), 'sdf'); test.throws(function () { - var scanner = new Scanner('asdf'); - scanner.pos = 1; - HTMLTools.parseFragment(scanner); + const scannerTest = new Scanner('asdf'); + scannerTest.pos = 1; + HTMLTools.parseFragment(scannerTest); }); }); -Tinytest.add("html-tools - getTemplateTag", function (test) { - +Tinytest.add('html-tools - getTemplateTag', function (test) { // match a simple tag consisting of `{{`, an optional `!`, one // or more ASCII letters, spaces or html tags, and a closing `}}`. - var mustache = /^\{\{(!?[a-zA-Z 0-9>]+)\}\}/; + const mustache = /^\{\{(!?[a-zA-Z 0-9>]+)\}\}/; // This implementation of `getTemplateTag` looks for "{{" and if it // finds it, it will match the regex above or fail fatally trying. // The object it returns is opaque to the tokenizer/parser and can // be anything we want. - var getTemplateTag = function (scanner, position) { - if (! (scanner.peek() === '{' && // one-char peek is just an optimization - scanner.rest().slice(0, 2) === '{{')) + const getTemplateTag = function (scanner, position) { + // one-char peek is just an optimization + if (!(scanner.peek() === '{' && scanner.rest().slice(0, 2) === '{{')) { return null; + } - var match = mustache.exec(scanner.rest()); - if (! match) - scanner.fatal("Bad mustache"); + const match = mustache.exec(scanner.rest()); + if (!match) scanner.fatal(`Bad mustache at ${position}`); scanner.pos += match[0].length; - if (match[1].charAt(0) === '!') - return null; // `{{!foo}}` is like a comment + if (match[1].charAt(0) === '!') return null; // `{{!foo}}` is like a comment return TemplateTag({ stuff: match[1] }); }; + const succeed = function (input, expected) { + let endPos = input.indexOf('^^^'); + if (endPos < 0) endPos = input.length; - var succeed = function (input, expected) { - var endPos = input.indexOf('^^^'); - if (endPos < 0) - endPos = input.length; - - var scanner = new Scanner(input.replace('^^^', '')); + const scanner = new Scanner(input.replace('^^^', '')); scanner.getTemplateTag = getTemplateTag; - var result; + let result; try { result = getContent(scanner); } catch (e) { @@ -306,31 +300,30 @@ Tinytest.add("html-tools - getTemplateTag", function (test) { test.equal(BlazeTools.toJS(result), BlazeTools.toJS(expected)); }; - var fatal = function (input, messageContains) { - var scanner = new Scanner(input); + const fatal = function (input, messageContains) { + const scanner = new Scanner(input); scanner.getTemplateTag = getTemplateTag; - var error; + let error; try { getContent(scanner); } catch (e) { error = e; } test.isTrue(error); - if (messageContains) - test.isTrue(messageContains && error.message.indexOf(messageContains) >= 0, error.message); + if (messageContains) test.isTrue(messageContains && error.message.indexOf(messageContains) >= 0, error.message); }; - succeed('{{foo}}', TemplateTag({stuff: 'foo'})); + succeed('{{foo}}', TemplateTag({ stuff: 'foo' })); succeed('{{foo}}', - A({href: "http://www.apple.com/"}, TemplateTag({stuff: 'foo'}))); + A({ href: 'http://www.apple.com/' }, TemplateTag({ stuff: 'foo' }))); // tags not parsed in comments - succeed('', Comment("{{foo}}")); - succeed('', Comment("{{foo")); + succeed('', Comment('{{foo}}')); + succeed('', Comment('{{foo')); - succeed('&am{{foo}}p;', ['&am', TemplateTag({stuff: 'foo'}), 'p;']); + succeed('&am{{foo}}p;', ['&am', TemplateTag({ stuff: 'foo' }), 'p;']); // can't start a mustache and not finish it fatal('{{foo'); @@ -343,58 +336,58 @@ Tinytest.add("html-tools - getTemplateTag", function (test) { // single curly brace is no biggie succeed('a{b', 'a{b'); - succeed('