Skip to content

Commit

Permalink
Merge pull request #447 from meteor/revert-436-feature/blaze-tool-es6
Browse files Browse the repository at this point in the history
Revert "Blaze-tool to ES6"
  • Loading branch information
Grubba27 authored Dec 29, 2023
2 parents 7960b61 + 7c50403 commit 3fdd170
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 57 deletions.
4 changes: 2 additions & 2 deletions packages/blaze-tools/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Package.describe({
});

Package.onUse(function (api) {
api.use('ecmascript@0.16.7');
api.use('ecmascript@0.15.1');
api.use('htmljs@1.1.1');

api.export('BlazeTools');
api.mainModule('preamble.js');
});

Package.onTest(function (api) {
api.use('tinytest@1.2.2');
api.use('tinytest@1.1.0');
api.use('ecmascript');

api.use('blaze-tools');
Expand Down
34 changes: 17 additions & 17 deletions packages/blaze-tools/tojs.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function toJSLiteral (obj) {



const jsReservedWordSet = (function (set) {
var jsReservedWordSet = (function (set) {
"abstract else instanceof super boolean enum int switch break export interface synchronized byte extends let this case false long throw catch final native throws char finally new transient class float null true const for package try continue function private typeof debugger goto protected var default if public void delete implements return volatile do import short while double in static with".split(' ').forEach(function (w) {
set[w] = 1;
});
Expand All @@ -41,7 +41,7 @@ export function toObjectLiteralKey (k) {
return toJSLiteral(k);
}

const hasToJS = function (x) {
var hasToJS = function (x) {
return x.toJS && (typeof (x.toJS) === 'function');
};

Expand All @@ -54,8 +54,8 @@ ToJSVisitor.def({
return toJSLiteral(stringBooleanOrNumber);
},
visitArray: function (array) {
const parts = [];
for (let i = 0; i < array.length; i++)
var parts = [];
for (var i = 0; i < array.length; i++)
parts.push(this.visit(array[i]));
return '[' + parts.join(', ') + ']';
},
Expand All @@ -80,7 +80,7 @@ ToJSVisitor.def({
throw new Error("Unexpected object in HTMLjs in toJS: " + x);
},
generateCall: function (name, attrs, children) {
let tagSymbol;
var tagSymbol;
if (name.indexOf('.') >= 0) {
tagSymbol = name;
} else if (HTML.isTagEnsured(name)) {
Expand All @@ -89,19 +89,19 @@ ToJSVisitor.def({
tagSymbol = 'HTML.getTag(' + toJSLiteral(name) + ')';
}

let attrsArray = null;
let needsHTMLAttrs = false;
var attrsArray = null;
if (attrs) {
attrsArray = [];
var needsHTMLAttrs = false;
if (HTML.isArray(attrs)) {
attrsArray = [];
for (let i = 0; i < attrs.length; i++) {
const a = attrs[i];
var attrsArray = [];
for (var i = 0; i < attrs.length; i++) {
var a = attrs[i];
if (hasToJS(a)) {
attrsArray.push(a.toJS(this));
needsHTMLAttrs = true;
} else {
const attrsObjStr = this.generateAttrsDictionary(attrs[i]);
var attrsObjStr = this.generateAttrsDictionary(attrs[i]);
if (attrsObjStr !== null)
attrsArray.push(attrsObjStr);
}
Expand All @@ -113,7 +113,7 @@ ToJSVisitor.def({
attrsArray.push(this.generateAttrsDictionary(attrs));
}
}
let attrsStr = null;
var attrsStr = null;
if (attrsArray && attrsArray.length) {
if (attrsArray.length === 1 && ! needsHTMLAttrs) {
attrsStr = attrsArray[0];
Expand All @@ -122,12 +122,12 @@ ToJSVisitor.def({
}
}

const argStrs = [];
var argStrs = [];
if (attrsStr !== null)
argStrs.push(attrsStr);

if (children) {
for (let i = 0; i < children.length; i++)
for (var i = 0; i < children.length; i++)
argStrs.push(this.visit(children[i]));
}

Expand All @@ -139,12 +139,12 @@ ToJSVisitor.def({
return attrsDict.toJS(this);
}

const kvStrs = [];
Object.getOwnPropertyNames(attrsDict).forEach((k) => {
var kvStrs = [];
for (var k in attrsDict) {
if (! HTML.isNully(attrsDict[k]))
kvStrs.push(toObjectLiteralKey(k) + ': ' +
this.visit(attrsDict[k]));
});
}
if (kvStrs.length)
return '{' + kvStrs.join(', ') + '}';
return null;
Expand Down
18 changes: 9 additions & 9 deletions packages/blaze-tools/token_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { HTMLTools } from 'meteor/html-tools';

Tinytest.add("blaze-tools - token parsers", function (test) {

const run = function (func, input, expected) {
const scanner = new HTMLTools.Scanner('z' + input);
var run = function (func, input, expected) {
var scanner = new HTMLTools.Scanner('z' + input);
// make sure the parse function respects `scanner.pos`
scanner.pos = 1;
const result = func(scanner);
var result = func(scanner);
if (expected === null) {
test.equal(scanner.pos, 1);
test.equal(result, null);
Expand All @@ -17,19 +17,19 @@ Tinytest.add("blaze-tools - token parsers", function (test) {
}
};

const runValue = function (func, input, expectedValue) {
let expected;
var runValue = function (func, input, expectedValue) {
var expected;
if (expectedValue === null)
expected = null;
else
expected = { text: input, value: expectedValue };
run(func, input, expected);
};

const parseNumber = BlazeTools.parseNumber;
const parseIdentifierName = BlazeTools.parseIdentifierName;
const parseExtendedIdentifierName = BlazeTools.parseExtendedIdentifierName;
const parseStringLiteral = BlazeTools.parseStringLiteral;
var parseNumber = BlazeTools.parseNumber;
var parseIdentifierName = BlazeTools.parseIdentifierName;
var parseExtendedIdentifierName = BlazeTools.parseExtendedIdentifierName;
var parseStringLiteral = BlazeTools.parseStringLiteral;

runValue(parseNumber, "0", 0);
runValue(parseNumber, "-0", 0);
Expand Down
58 changes: 29 additions & 29 deletions packages/blaze-tools/tokens.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// Adapted from source code of http://xregexp.com/plugins/#unicode
const unicodeCategories = {
var unicodeCategories = {
Ll: "0061-007A00B500DF-00F600F8-00FF01010103010501070109010B010D010F01110113011501170119011B011D011F01210123012501270129012B012D012F01310133013501370138013A013C013E014001420144014601480149014B014D014F01510153015501570159015B015D015F01610163016501670169016B016D016F0171017301750177017A017C017E-0180018301850188018C018D019201950199-019B019E01A101A301A501A801AA01AB01AD01B001B401B601B901BA01BD-01BF01C601C901CC01CE01D001D201D401D601D801DA01DC01DD01DF01E101E301E501E701E901EB01ED01EF01F001F301F501F901FB01FD01FF02010203020502070209020B020D020F02110213021502170219021B021D021F02210223022502270229022B022D022F02310233-0239023C023F0240024202470249024B024D024F-02930295-02AF037103730377037B-037D039003AC-03CE03D003D103D5-03D703D903DB03DD03DF03E103E303E503E703E903EB03ED03EF-03F303F503F803FB03FC0430-045F04610463046504670469046B046D046F04710473047504770479047B047D047F0481048B048D048F04910493049504970499049B049D049F04A104A304A504A704A904AB04AD04AF04B104B304B504B704B904BB04BD04BF04C204C404C604C804CA04CC04CE04CF04D104D304D504D704D904DB04DD04DF04E104E304E504E704E904EB04ED04EF04F104F304F504F704F904FB04FD04FF05010503050505070509050B050D050F05110513051505170519051B051D051F05210523052505270561-05871D00-1D2B1D6B-1D771D79-1D9A1E011E031E051E071E091E0B1E0D1E0F1E111E131E151E171E191E1B1E1D1E1F1E211E231E251E271E291E2B1E2D1E2F1E311E331E351E371E391E3B1E3D1E3F1E411E431E451E471E491E4B1E4D1E4F1E511E531E551E571E591E5B1E5D1E5F1E611E631E651E671E691E6B1E6D1E6F1E711E731E751E771E791E7B1E7D1E7F1E811E831E851E871E891E8B1E8D1E8F1E911E931E95-1E9D1E9F1EA11EA31EA51EA71EA91EAB1EAD1EAF1EB11EB31EB51EB71EB91EBB1EBD1EBF1EC11EC31EC51EC71EC91ECB1ECD1ECF1ED11ED31ED51ED71ED91EDB1EDD1EDF1EE11EE31EE51EE71EE91EEB1EED1EEF1EF11EF31EF51EF71EF91EFB1EFD1EFF-1F071F10-1F151F20-1F271F30-1F371F40-1F451F50-1F571F60-1F671F70-1F7D1F80-1F871F90-1F971FA0-1FA71FB0-1FB41FB61FB71FBE1FC2-1FC41FC61FC71FD0-1FD31FD61FD71FE0-1FE71FF2-1FF41FF61FF7210A210E210F2113212F21342139213C213D2146-2149214E21842C30-2C5E2C612C652C662C682C6A2C6C2C712C732C742C76-2C7B2C812C832C852C872C892C8B2C8D2C8F2C912C932C952C972C992C9B2C9D2C9F2CA12CA32CA52CA72CA92CAB2CAD2CAF2CB12CB32CB52CB72CB92CBB2CBD2CBF2CC12CC32CC52CC72CC92CCB2CCD2CCF2CD12CD32CD52CD72CD92CDB2CDD2CDF2CE12CE32CE42CEC2CEE2CF32D00-2D252D272D2DA641A643A645A647A649A64BA64DA64FA651A653A655A657A659A65BA65DA65FA661A663A665A667A669A66BA66DA681A683A685A687A689A68BA68DA68FA691A693A695A697A723A725A727A729A72BA72DA72F-A731A733A735A737A739A73BA73DA73FA741A743A745A747A749A74BA74DA74FA751A753A755A757A759A75BA75DA75FA761A763A765A767A769A76BA76DA76FA771-A778A77AA77CA77FA781A783A785A787A78CA78EA791A793A7A1A7A3A7A5A7A7A7A9A7FAFB00-FB06FB13-FB17FF41-FF5A",
Lm: "02B0-02C102C6-02D102E0-02E402EC02EE0374037A0559064006E506E607F407F507FA081A0824082809710E460EC610FC17D718431AA71C78-1C7D1D2C-1D6A1D781D9B-1DBF2071207F2090-209C2C7C2C7D2D6F2E2F30053031-3035303B309D309E30FC-30FEA015A4F8-A4FDA60CA67FA717-A71FA770A788A7F8A7F9A9CFAA70AADDAAF3AAF4FF70FF9EFF9F",
Lo: "00AA00BA01BB01C0-01C3029405D0-05EA05F0-05F20620-063F0641-064A066E066F0671-06D306D506EE06EF06FA-06FC06FF07100712-072F074D-07A507B107CA-07EA0800-08150840-085808A008A2-08AC0904-0939093D09500958-09610972-09770979-097F0985-098C098F09900993-09A809AA-09B009B209B6-09B909BD09CE09DC09DD09DF-09E109F009F10A05-0A0A0A0F0A100A13-0A280A2A-0A300A320A330A350A360A380A390A59-0A5C0A5E0A72-0A740A85-0A8D0A8F-0A910A93-0AA80AAA-0AB00AB20AB30AB5-0AB90ABD0AD00AE00AE10B05-0B0C0B0F0B100B13-0B280B2A-0B300B320B330B35-0B390B3D0B5C0B5D0B5F-0B610B710B830B85-0B8A0B8E-0B900B92-0B950B990B9A0B9C0B9E0B9F0BA30BA40BA8-0BAA0BAE-0BB90BD00C05-0C0C0C0E-0C100C12-0C280C2A-0C330C35-0C390C3D0C580C590C600C610C85-0C8C0C8E-0C900C92-0CA80CAA-0CB30CB5-0CB90CBD0CDE0CE00CE10CF10CF20D05-0D0C0D0E-0D100D12-0D3A0D3D0D4E0D600D610D7A-0D7F0D85-0D960D9A-0DB10DB3-0DBB0DBD0DC0-0DC60E01-0E300E320E330E40-0E450E810E820E840E870E880E8A0E8D0E94-0E970E99-0E9F0EA1-0EA30EA50EA70EAA0EAB0EAD-0EB00EB20EB30EBD0EC0-0EC40EDC-0EDF0F000F40-0F470F49-0F6C0F88-0F8C1000-102A103F1050-1055105A-105D106110651066106E-10701075-1081108E10D0-10FA10FD-1248124A-124D1250-12561258125A-125D1260-1288128A-128D1290-12B012B2-12B512B8-12BE12C012C2-12C512C8-12D612D8-13101312-13151318-135A1380-138F13A0-13F41401-166C166F-167F1681-169A16A0-16EA1700-170C170E-17111720-17311740-17511760-176C176E-17701780-17B317DC1820-18421844-18771880-18A818AA18B0-18F51900-191C1950-196D1970-19741980-19AB19C1-19C71A00-1A161A20-1A541B05-1B331B45-1B4B1B83-1BA01BAE1BAF1BBA-1BE51C00-1C231C4D-1C4F1C5A-1C771CE9-1CEC1CEE-1CF11CF51CF62135-21382D30-2D672D80-2D962DA0-2DA62DA8-2DAE2DB0-2DB62DB8-2DBE2DC0-2DC62DC8-2DCE2DD0-2DD62DD8-2DDE3006303C3041-3096309F30A1-30FA30FF3105-312D3131-318E31A0-31BA31F0-31FF3400-4DB54E00-9FCCA000-A014A016-A48CA4D0-A4F7A500-A60BA610-A61FA62AA62BA66EA6A0-A6E5A7FB-A801A803-A805A807-A80AA80C-A822A840-A873A882-A8B3A8F2-A8F7A8FBA90A-A925A930-A946A960-A97CA984-A9B2AA00-AA28AA40-AA42AA44-AA4BAA60-AA6FAA71-AA76AA7AAA80-AAAFAAB1AAB5AAB6AAB9-AABDAAC0AAC2AADBAADCAAE0-AAEAAAF2AB01-AB06AB09-AB0EAB11-AB16AB20-AB26AB28-AB2EABC0-ABE2AC00-D7A3D7B0-D7C6D7CB-D7FBF900-FA6DFA70-FAD9FB1DFB1F-FB28FB2A-FB36FB38-FB3CFB3EFB40FB41FB43FB44FB46-FBB1FBD3-FD3DFD50-FD8FFD92-FDC7FDF0-FDFBFE70-FE74FE76-FEFCFF66-FF6FFF71-FF9DFFA0-FFBEFFC2-FFC7FFCA-FFCFFFD2-FFD7FFDA-FFDC",
Expand All @@ -13,15 +13,15 @@ const unicodeCategories = {
Pc: "005F203F20402054FE33FE34FE4D-FE4FFF3F"
};

const unicodeClass = function (abbrev) {
var unicodeClass = function (abbrev) {
return '[' +
unicodeCategories[abbrev].replace(/[0-9A-F]{4}/ig, "\\u$&") + ']';
};

// See ECMA-262 spec, 3rd edition, Section 7.6
// Match one or more characters that can start an identifier.
// This is IdentifierStart+.
const rIdentifierPrefix = new RegExp(
var rIdentifierPrefix = new RegExp(
"^([a-zA-Z$_]+|\\\\u[0-9a-fA-F]{4}|" +
[unicodeClass('Lu'), unicodeClass('Ll'), unicodeClass('Lt'),
unicodeClass('Lm'), unicodeClass('Lo'), unicodeClass('Nl')].join('|') +
Expand All @@ -30,62 +30,62 @@ const rIdentifierPrefix = new RegExp(
// This is (IdentifierPart and not IdentifierStart)+.
// To match a full identifier, match rIdentifierPrefix, then
// match rIdentifierMiddle followed by rIdentifierPrefix until they both fail.
const rIdentifierMiddle = new RegExp(
var rIdentifierMiddle = new RegExp(
"^([0-9]|" + [unicodeClass('Mn'), unicodeClass('Mc'), unicodeClass('Nd'),
unicodeClass('Pc')].join('|') + ")+");


// See ECMA-262 spec, 3rd edition, Section 7.8.3
const rHexLiteral = /^0[xX][0-9a-fA-F]+(?!\w)/;
const rDecLiteral =
var rHexLiteral = /^0[xX][0-9a-fA-F]+(?!\w)/;
var rDecLiteral =
/^(((0|[1-9][0-9]*)(\.[0-9]*)?)|\.[0-9]+)([Ee][+-]?[0-9]+)?(?!\w)/;

// Section 7.8.4
const rStringQuote = /^["']/;
var rStringQuote = /^["']/;
// Match one or more characters besides quotes, backslashes, or line ends
const rStringMiddle = /^(?=.)[^"'\\]+?((?!.)|(?=["'\\]))/;
var rStringMiddle = /^(?=.)[^"'\\]+?((?!.)|(?=["'\\]))/;
// Match one escape sequence, including the backslash.
const rEscapeSequence =
var rEscapeSequence =
/^\\(['"\\bfnrtv]|0(?![0-9])|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|(?=.)[^ux0-9])/;
// Match one ES5 line continuation
const rLineContinuation =
var rLineContinuation =
/^\\(\r\n|[\u000A\u000D\u2028\u2029])/;


export function parseNumber (scanner) {
const startPos = scanner.pos;
var startPos = scanner.pos;

let isNegative = false;
var isNegative = false;
if (scanner.peek() === '-') {
scanner.pos++;
isNegative = true;
}
// Note that we allow `"-0xa"`, unlike `Number(...)`.

const rest = scanner.rest();
const match = rDecLiteral.exec(rest) || rHexLiteral.exec(rest);
var rest = scanner.rest();
var match = rDecLiteral.exec(rest) || rHexLiteral.exec(rest);
if (! match) {
scanner.pos = startPos;
return null;
}
const matchText = match[0];
var matchText = match[0];
scanner.pos += matchText.length;

const text = (isNegative ? '-' : '') + matchText;
let value = Number(matchText);
var text = (isNegative ? '-' : '') + matchText;
var value = Number(matchText);
value = (isNegative ? -value : value);
return { text: text, value: value };
}

export function parseIdentifierName (scanner) {
const startPos = scanner.pos;
let rest = scanner.rest();
let match = rIdentifierPrefix.exec(rest);
var startPos = scanner.pos;
var rest = scanner.rest();
var match = rIdentifierPrefix.exec(rest);
if (! match)
return null;
scanner.pos += match[0].length;
rest = scanner.rest();
let foundMore = true;
var foundMore = true;

while (foundMore) {
foundMore = false;
Expand All @@ -112,7 +112,7 @@ export function parseExtendedIdentifierName (scanner) {
// parse an identifier name optionally preceded by '@'
if (scanner.peek() === '@') {
scanner.pos++;
const afterAt = parseIdentifierName(scanner);
var afterAt = parseIdentifierName(scanner);
if (afterAt) {
return '@' + afterAt;
} else {
Expand All @@ -125,17 +125,17 @@ export function parseExtendedIdentifierName (scanner) {
}

export function parseStringLiteral (scanner) {
const startPos = scanner.pos;
let rest = scanner.rest();
let match = rStringQuote.exec(rest);
var startPos = scanner.pos;
var rest = scanner.rest();
var match = rStringQuote.exec(rest);
if (! match)
return null;

const quote = match[0];
var quote = match[0];
scanner.pos++;
rest = scanner.rest();

let jsonLiteral = '"';
var jsonLiteral = '"';

while (match) {
match = rStringMiddle.exec(rest);
Expand Down Expand Up @@ -187,7 +187,7 @@ export function parseStringLiteral (scanner) {
scanner.fatal("Unterminated string literal");

jsonLiteral += '"';
const text = scanner.input.substring(startPos, scanner.pos);
const value = JSON.parse(jsonLiteral);
var text = scanner.input.substring(startPos, scanner.pos);
var value = JSON.parse(jsonLiteral);
return { text: text, value: value };
}

0 comments on commit 3fdd170

Please sign in to comment.