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

Refactored html-tools and htmljs to move ES6 version #385

Open
wants to merge 21 commits into
base: release-3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 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
4,691 changes: 2,358 additions & 2,333 deletions packages/html-tools/charref.js

Large diffs are not rendered by default.

50 changes: 24 additions & 26 deletions packages/html-tools/charref_tests.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
/* eslint-env meteor */

Choose a reason for hiding this comment

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

Question @jankapunkt @guncebektas : Does this have to be included in different files? Isn't there a default .eslintrc or something for blaze which should contain this?

import { HTMLTools } from 'meteor/html-tools';

var Scanner = HTMLTools.Scanner;
var getCharacterReference = HTMLTools.Parse.getCharacterReference;
const { Scanner } = HTMLTools;

Choose a reason for hiding this comment

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

Nit: I think the old way was more straightforward to read - const is fine but in general? Do we need this everywhere?

const { getCharacterReference } = HTMLTools.Parse;

Tinytest.add("html-tools - entities", function (test) {
var succeed = function (input, match, codepoints) {
if (typeof input === 'string')
input = {input: input};
Tinytest.add('html-tools - entities', function (test) {
const succeed = function (input, match, codepoints) {
if (typeof input === 'string') input = { input };

// match arg is optional; codepoints is never a string
if (typeof match !== 'string') {
codepoints = match;
match = input.input;
}

var scanner = new Scanner(input.input);
var result = getCharacterReference(scanner, input.inAttribute, input.allowedChar);
const scanner = new Scanner(input.input);
const result = getCharacterReference(scanner, input.inAttribute, input.allowedChar);
test.isTrue(result);
test.equal(scanner.pos, match.length);
test.equal(result, {
t: 'CharRef',
v: match,
cp: codepoints.map(
function (x) { return (typeof x === 'string' ?
x.charCodeAt(0) : x); })
function (x) {
return (typeof x === 'string' ?
x.charCodeAt(0) : x);
}),
});
};

var ignore = function (input) {
if (typeof input === 'string')
input = {input: input};
const ignore = function (input) {
if (typeof input === 'string') input = { input };

var scanner = new Scanner(input.input);
var result = getCharacterReference(scanner, input.inAttribute, input.allowedChar);
const scanner = new Scanner(input.input);
const result = getCharacterReference(scanner, input.inAttribute, input.allowedChar);
test.isFalse(result);
test.equal(scanner.pos, 0);
};

var fatal = function (input, messageContains) {
if (typeof input === 'string')
input = {input: input};
const fatal = function (input, messageContains) {
if (typeof input === 'string') input = { input };

var scanner = new Scanner(input.input);
var error;
const scanner = new Scanner(input.input);
let error;
try {
getCharacterReference(scanner, input.inAttribute, input.allowedChar);
} catch (e) {
error = e;
}
test.isTrue(error);
if (error)
test.isTrue(messageContains && error.message.indexOf(messageContains) >= 0, error.message);
if (error) test.isTrue(messageContains && error.message.indexOf(messageContains) >= 0, error.message);
};

ignore('a');
Expand All @@ -61,15 +60,15 @@ Tinytest.add("html-tools - entities", function (test) {
fatal('&#', 'Invalid numerical character reference starting with &#');
ignore('&a');
fatal('&a;', 'Invalid character reference: &a;');
ignore({input: '&"', allowedChar: '"'});
ignore({ input: '&"', allowedChar: '"' });
ignore('&"');

succeed('>', ['>']);
fatal('&gt', 'Character reference requires semicolon');
ignore('&aaa');
fatal('&gta', 'Character reference requires semicolon');
ignore({input: '&gta', inAttribute: true});
fatal({input: '&gt=', inAttribute: true}, 'Character reference requires semicolon: &gt');
ignore({ input: '&gta', inAttribute: true });
fatal({ input: '&gt=', inAttribute: true }, 'Character reference requires semicolon: &gt');

succeed('>;', '>', ['>']);

Expand Down Expand Up @@ -112,5 +111,4 @@ Tinytest.add("html-tools - entities", function (test) {
fatal('', 'Illegal codepoint in numerical character reference');
fatal('', 'Illegal codepoint in numerical character reference');
succeed('􏿽', [0x10fffd]);

});
11 changes: 4 additions & 7 deletions packages/html-tools/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

import { getCharacterReference } from './charref';
import { asciiLowerCase, properCaseTagName, properCaseAttributeName} from "./utils";
import { TemplateTag } from './templatetag'
import { asciiLowerCase, properCaseTagName, properCaseAttributeName } from './utils';
import { TemplateTag } from './templatetag';
import { Scanner } from './scanner';
import { parseFragment, codePointToString, getContent, getRCData } from './parse';
import { getComment, getDoctype, getHTMLToken, getTagToken, TEMPLATE_TAG_POSITION } from './tokenize';

HTMLTools = {
export const HTMLTools = {
asciiLowerCase,
properCaseTagName,
properCaseAttributeName,
Expand All @@ -23,7 +22,5 @@ HTMLTools = {
getDoctype,
getHTMLToken,
getTagToken,
}
},
};

export { HTMLTools };
9 changes: 5 additions & 4 deletions packages/html-tools/package.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-env meteor */
Package.describe({
name: 'html-tools',
summary: "Standards-compliant HTML tools",
version: '1.1.3',
Copy link
Collaborator

Choose a reason for hiding this comment

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

@StorytellerCZ @denihs should PRs to 3.0 include version bumps? I'd rather keep them and at release bump them to whatever is suitable but that's not my call.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ping @Grubba27

Choose a reason for hiding this comment

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

Actually I think PRs probably shouldn't include individual version bumps, it feels like this way lie merge conflicts & conflicting version number schemes for sure :D

git: 'https://github.com/meteor/blaze.git'
summary: 'Standards-compliant HTML tools',
version: '1.2.0',
git: 'https://github.com/meteor/blaze.git',
});

Package.onUse(function (api) {
Expand All @@ -25,6 +26,6 @@ Package.onTest(function (api) {
api.addFiles([
'charref_tests.js',
'tokenize_tests.js',
'parse_tests.js'
'parse_tests.js',
]);
});
Loading