Comparing version 0.9.1-1 to 0.9.1-2
@@ -43,2 +43,4 @@ // Acorn: Loose parser | ||
acorn.defaultOptions.tabSize = 4; | ||
exports.parse_dammit = function(inpt, opts) { | ||
@@ -48,6 +50,4 @@ if (!opts) opts = {}; | ||
if (/^#!.*/.test(input)) input = "//" + input.slice(2); | ||
options = opts; | ||
if (!opts.tabSize) opts.tabSize = 4; | ||
fetchToken = acorn.tokenize(input, opts); | ||
options = fetchToken.options; | ||
sourceFile = options.sourceFile || null; | ||
@@ -64,11 +64,10 @@ context = []; | ||
function next() { | ||
function next(forceRegexp) { | ||
lastEnd = token.end; | ||
if (options.locations) | ||
lastEndLoc = token.endLoc; | ||
if (forceRegexp) | ||
ahead.length = 0; | ||
if (ahead.length) | ||
token = ahead.shift(); | ||
else | ||
token = readToken(); | ||
token = ahead.shift() || readToken(forceRegexp); | ||
@@ -84,6 +83,12 @@ if (token.start >= nextLineStart) { | ||
function readToken() { | ||
function readToken(forceRegexp) { | ||
for (;;) { | ||
try { | ||
return fetchToken(); | ||
var tok = fetchToken(forceRegexp); | ||
if (tok.type === tt.dot && input.substr(tok.end, 1) === '.') { | ||
tok = fetchToken(); | ||
tok.start--; | ||
tok.type = tt.ellipsis; | ||
} | ||
return tok; | ||
} catch(e) { | ||
@@ -263,2 +268,4 @@ if (!(e instanceof SyntaxError)) throw e; | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
@@ -271,3 +278,3 @@ } | ||
function semicolon() { | ||
eat(tt.semi); | ||
return eat(tt.semi); | ||
} | ||
@@ -288,10 +295,22 @@ | ||
function checkLVal(expr) { | ||
if (expr.type === "Identifier" || expr.type === "MemberExpression") return expr; | ||
return dummyIdent(); | ||
if (!expr) return expr; | ||
switch (expr.type) { | ||
case "Identifier": | ||
case "MemberExpression": | ||
case "ObjectPattern": | ||
case "ArrayPattern": | ||
case "SpreadElement": | ||
return expr; | ||
default: | ||
return dummyIdent(); | ||
} | ||
} | ||
function parseTopLevel() { | ||
var node = startNode(); | ||
var node = startNodeAt(options.locations ? [0, acorn.getLineInfo(input, 0)] : 0); | ||
node.body = []; | ||
while (token.type !== tt.eof) node.body.push(parseStatement()); | ||
lastEnd = token.end; | ||
lastEndLoc = token.endLoc; | ||
return finishNode(node, "Program"); | ||
@@ -301,2 +320,5 @@ } | ||
function parseStatement() { | ||
if (token.type === tt.slash || token.type === tt.assign && token.value === "/=") | ||
next(true); | ||
var starttype = token.type, node = startNode(); | ||
@@ -308,4 +330,8 @@ | ||
var isBreak = starttype === tt._break; | ||
node.label = token.type === tt.name ? parseIdent() : null; | ||
semicolon(); | ||
if (semicolon() || canInsertSemicolon()) { | ||
node.label = null; | ||
} else { | ||
node.label = token.type === tt.name ? parseIdent() : null; | ||
semicolon(); | ||
} | ||
return finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement"); | ||
@@ -330,12 +356,13 @@ | ||
if (token.type === tt.semi) return parseFor(node, null); | ||
if (token.type === tt._var) { | ||
var init = startNode(); | ||
next(); | ||
parseVar(init, true); | ||
if (init.declarations.length === 1 && eat(tt._in)) | ||
if (token.type === tt._var || token.type === tt._let) { | ||
var init = parseVar(true); | ||
if (init.declarations.length === 1 && (token.type === tt._in || token.type === tt.name && token.value === "of")) { | ||
return parseForIn(node, init); | ||
} | ||
return parseFor(node, init); | ||
} | ||
var init = parseExpression(false, true); | ||
if (eat(tt._in)) {return parseForIn(node, checkLVal(init));} | ||
if (token.type === tt._in || token.type === tt.name && token.value === "of") { | ||
return parseForIn(node, checkLVal(init)); | ||
} | ||
return parseFor(node, init); | ||
@@ -417,5 +444,5 @@ | ||
case tt._var: | ||
next(); | ||
node = parseVar(node); | ||
return node; | ||
case tt._let: | ||
case tt._const: | ||
return parseVar(); | ||
@@ -441,2 +468,11 @@ case tt._while: | ||
case tt._class: | ||
return parseObj(true, true); | ||
case tt._import: | ||
return parseImport(); | ||
case tt._export: | ||
return parseExport(); | ||
default: | ||
@@ -485,2 +521,4 @@ var expr = parseExpression(); | ||
function parseForIn(node, init) { | ||
var type = token.type === tt._in ? "ForInStatement" : "ForOfStatement"; | ||
next(); | ||
node.left = init; | ||
@@ -491,15 +529,16 @@ node.right = parseExpression(); | ||
node.body = parseStatement(); | ||
return finishNode(node, "ForInStatement"); | ||
return finishNode(node, type); | ||
} | ||
function parseVar(node, noIn) { | ||
function parseVar(noIn) { | ||
var node = startNode(); | ||
node.kind = token.type.keyword; | ||
next(); | ||
node.declarations = []; | ||
node.kind = "var"; | ||
while (token.type === tt.name) { | ||
do { | ||
var decl = startNode(); | ||
decl.id = parseIdent(); | ||
decl.id = options.ecmaVersion >= 6 ? toAssignable(parseExprAtom()) : parseIdent(); | ||
decl.init = eat(tt.eq) ? parseExpression(true, noIn) : null; | ||
node.declarations.push(finishNode(decl, "VariableDeclarator")); | ||
if (!eat(tt.comma)) break; | ||
} | ||
} while (eat(tt.comma)); | ||
if (!node.declarations.length) { | ||
@@ -541,3 +580,3 @@ var decl = startNode(); | ||
node.operator = token.value; | ||
node.left = checkLVal(left); | ||
node.left = token.type === tt.eq ? toAssignable(left) : checkLVal(left); | ||
next(); | ||
@@ -593,3 +632,10 @@ node.right = parseMaybeAssign(noIn); | ||
if (token.type.prefix) { | ||
var node = startNode(), update = token.type.isUpdate; | ||
var node = startNode(), update = token.type.isUpdate, nodeType; | ||
if (token.type === tt.ellipsis) { | ||
nodeType = "SpreadElement"; | ||
} else { | ||
nodeType = update ? "UpdateExpression" : "UnaryExpression"; | ||
node.operator = token.value; | ||
node.prefix = true; | ||
} | ||
node.operator = token.value; | ||
@@ -600,3 +646,3 @@ node.prefix = true; | ||
if (update) node.argument = checkLVal(node.argument); | ||
return finishNode(node, update ? "UpdateExpression" : "UnaryExpression"); | ||
return finishNode(node, nodeType); | ||
} | ||
@@ -667,6 +713,19 @@ var start = storeCurrentPos(); | ||
return finishNode(node, "ThisExpression"); | ||
case tt.name: | ||
return parseIdent(); | ||
case tt.num: case tt.string: case tt.regexp: | ||
var start = storeCurrentPos(); | ||
var id = parseIdent(); | ||
return eat(tt.arrow) ? parseArrowExpression(startNodeAt(start), [id]) : id; | ||
case tt.regexp: | ||
var node = startNode(); | ||
var val = token.value; | ||
node.regex = {pattern: val.pattern, flags: val.flags}; | ||
node.value = val.value; | ||
node.raw = input.slice(token.start, token.end); | ||
next(); | ||
return finishNode(node, "Literal"); | ||
case tt.num: case tt.string: | ||
var node = startNode(); | ||
node.value = token.value; | ||
@@ -685,5 +744,14 @@ node.raw = input.slice(token.start, token.end); | ||
case tt.parenL: | ||
var start = storeCurrentPos(); | ||
next(); | ||
var val = parseExpression(); | ||
expect(tt.parenR); | ||
if (eat(tt.arrow)) { | ||
return parseArrowExpression(startNodeAt(start), val.expressions || (isDummy(val) ? [] : [val])); | ||
} | ||
if (options.preserveParens) { | ||
var par = startNodeAt(start); | ||
par.expression = val; | ||
val = finishNode(par, "ParenthesizedExpression"); | ||
} | ||
return val; | ||
@@ -694,3 +762,3 @@ | ||
pushCx(); | ||
node.elements = parseExprList(tt.bracketR); | ||
node.elements = parseExprList(tt.bracketR, true); | ||
return finishNode(node, "ArrayExpression"); | ||
@@ -701,2 +769,5 @@ | ||
case tt._class: | ||
return parseObj(true); | ||
case tt._function: | ||
@@ -710,2 +781,14 @@ var node = startNode(); | ||
case tt._yield: | ||
var node = startNode(); | ||
next(); | ||
if (semicolon() || canInsertSemicolon()) { | ||
node.delegate = false; | ||
node.argument = null; | ||
} else { | ||
node.delegate = eat(tt.star); | ||
node.argument = parseExpression(true); | ||
} | ||
return finishNode(node, "YieldExpression"); | ||
default: | ||
@@ -730,37 +813,88 @@ return dummyIdent(); | ||
function parseObj() { | ||
function parseObj(isClass, isStatement) { | ||
var node = startNode(); | ||
node.properties = []; | ||
if (isClass) { | ||
next(); | ||
if (token.type === tt.name) node.id = parseIdent(); | ||
else if (isStatement) node.id = dummyIdent(); | ||
node.superClass = eat(tt._extends) ? parseExpression() : null; | ||
node.body = startNode(); | ||
node.body.body = []; | ||
} else { | ||
node.properties = []; | ||
} | ||
pushCx(); | ||
var indent = curIndent + 1, line = curLineStart; | ||
next(); | ||
eat(tt.braceL); | ||
if (curIndent + 1 < indent) { indent = curIndent; line = curLineStart; } | ||
while (!closes(tt.braceR, indent, line)) { | ||
var name = parsePropertyName(); | ||
if (!name) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; } | ||
var prop = startNode(); | ||
prop.key = name; | ||
if (eat(tt.colon)) { | ||
var prop = startNode(), isGenerator; | ||
if (options.ecmaVersion >= 6) { | ||
if (isClass) { | ||
if (prop['static'] = (token.type === tt.name && token.value === "static")) next(); | ||
} else { | ||
prop.method = false; | ||
prop.shorthand = false; | ||
} | ||
isGenerator = eat(tt.star); | ||
} | ||
parsePropertyName(prop); | ||
if (isDummy(prop.key)) { if (isDummy(parseExpression(true))) next(); eat(tt.comma); continue; } | ||
if (!isClass && eat(tt.colon)) { | ||
prop.kind = "init"; | ||
prop.value = parseExpression(true); | ||
prop.kind = "init"; | ||
} else if (options.ecmaVersion >= 6 && (token.type === tt.parenL || token.type === tt.braceL)) { | ||
if (isClass) { | ||
prop.kind = ""; | ||
} else { | ||
prop.kind = "init"; | ||
prop.method = true; | ||
} | ||
prop.value = parseMethod(isGenerator); | ||
} else if (options.ecmaVersion >= 5 && prop.key.type === "Identifier" && | ||
(prop.key.name === "get" || prop.key.name === "set")) { | ||
prop.kind = prop.key.name; | ||
prop.key = parsePropertyName() || dummyIdent(); | ||
prop.value = parseFunction(startNode(), false); | ||
parsePropertyName(prop); | ||
prop.value = parseMethod(false); | ||
} else if (isClass) { | ||
prop.kind = ""; | ||
prop.value = parseMethod(isGenerator); | ||
} else { | ||
prop.value = dummyIdent(); | ||
prop.kind = "init"; | ||
prop.value = options.ecmaVersion >= 6 ? prop.key : dummyIdent(); | ||
prop.shorthand = true; | ||
} | ||
node.properties.push(finishNode(prop, "Property")); | ||
eat(tt.comma); | ||
if (isClass) { | ||
node.body.body.push(finishNode(prop, "MethodDefinition")); | ||
semicolon(); | ||
} else { | ||
node.properties.push(finishNode(prop, "Property")); | ||
eat(tt.comma); | ||
} | ||
} | ||
popCx(); | ||
eat(tt.braceR); | ||
return finishNode(node, "ObjectExpression"); | ||
if (isClass) { | ||
semicolon(); | ||
finishNode(node.body, "ClassBody"); | ||
return finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression"); | ||
} else { | ||
return finishNode(node, "ObjectExpression"); | ||
} | ||
} | ||
function parsePropertyName() { | ||
if (token.type === tt.num || token.type === tt.string) return parseExprAtom(); | ||
if (token.type === tt.name || token.type.keyword) return parseIdent(); | ||
function parsePropertyName(prop) { | ||
if (options.ecmaVersion >= 6) { | ||
if (eat(tt.bracketL)) { | ||
prop.computed = true; | ||
prop.key = parseExpression(); | ||
expect(tt.bracketR); | ||
return; | ||
} else { | ||
prop.computed = false; | ||
} | ||
} | ||
var key = (token.type === tt.num || token.type === tt.string) ? parseExprAtom() : parseIdent(); | ||
prop.key = key || dummyIdent(); | ||
} | ||
@@ -775,2 +909,3 @@ | ||
node.name = token.type === tt.name ? token.value : token.type.keyword; | ||
fetchToken.noRegexp(); | ||
next(); | ||
@@ -780,15 +915,80 @@ return finishNode(node, "Identifier"); | ||
function initFunction(node) { | ||
node.id = null; | ||
node.params = []; | ||
if (options.ecmaVersion >= 6) { | ||
node.defaults = []; | ||
node.rest = null; | ||
node.generator = false; | ||
node.expression = false; | ||
} | ||
} | ||
// Convert existing expression atom to assignable pattern | ||
// if possible. | ||
function toAssignable(node) { | ||
if (options.ecmaVersion >= 6 && node) { | ||
switch (node.type) { | ||
case "ObjectExpression": | ||
node.type = "ObjectPattern"; | ||
var props = node.properties; | ||
for (var i = 0; i < props.length; i++) { | ||
props[i].value = toAssignable(props[i].value); | ||
} | ||
break; | ||
case "ArrayExpression": | ||
node.type = "ArrayPattern"; | ||
var elms = node.elements; | ||
for (var i = 0; i < elms.length; i++) { | ||
elms[i] = toAssignable(elms[i]); | ||
} | ||
break; | ||
case "SpreadElement": | ||
node.argument = toAssignable(node.argument); | ||
break; | ||
} | ||
} | ||
return checkLVal(node); | ||
} | ||
function parseFunctionParams(node, params) { | ||
var defaults = [], hasDefaults = false; | ||
if (!params) { | ||
pushCx(); | ||
params = parseExprList(tt.parenR); | ||
} | ||
for (var i = 0; i < params.length; i++) { | ||
var param = params[i], defValue = null; | ||
if (param.type === "AssignmentExpression") { | ||
defValue = param.right; | ||
param = param.left; | ||
} | ||
param = toAssignable(param); | ||
if (param.type === "SpreadElement") { | ||
param = param.argument; | ||
if (i === params.length - 1) { | ||
node.rest = param; | ||
continue; | ||
} | ||
} | ||
node.params.push(param); | ||
defaults.push(defValue); | ||
if (defValue) hasDefaults = true; | ||
} | ||
if (hasDefaults) node.defaults = defaults; | ||
} | ||
function parseFunction(node, isStatement) { | ||
initFunction(node); | ||
if (options.ecmaVersion >= 6) { | ||
node.generator = eat(tt.star); | ||
} | ||
if (token.type === tt.name) node.id = parseIdent(); | ||
else if (isStatement) node.id = dummyIdent(); | ||
else node.id = null; | ||
node.params = []; | ||
pushCx(); | ||
expect(tt.parenL); | ||
while (token.type == tt.name) { | ||
node.params.push(parseIdent()); | ||
eat(tt.comma); | ||
} | ||
popCx(); | ||
eat(tt.parenR); | ||
parseFunctionParams(node); | ||
node.body = parseBlock(); | ||
@@ -798,3 +998,113 @@ return finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression"); | ||
function parseExprList(close) { | ||
function parseMethod(isGenerator) { | ||
var node = startNode(); | ||
initFunction(node); | ||
parseFunctionParams(node); | ||
node.generator = isGenerator || false; | ||
node.expression = options.ecmaVersion >= 6 && token.type !== tt.braceL; | ||
node.body = node.expression ? parseExpression(true) : parseBlock(); | ||
return finishNode(node, "FunctionExpression"); | ||
} | ||
function parseArrowExpression(node, params) { | ||
initFunction(node); | ||
parseFunctionParams(node, params); | ||
node.expression = token.type !== tt.braceL; | ||
node.body = node.expression ? parseExpression(true) : parseBlock(); | ||
return finishNode(node, "ArrowFunctionExpression"); | ||
} | ||
function parseExport() { | ||
var node = startNode(); | ||
next(); | ||
node['default'] = eat(tt._default); | ||
node.specifiers = node.source = null; | ||
if (node['default']) { | ||
node.declaration = parseExpression(); | ||
semicolon(); | ||
} else if (token.type.keyword) { | ||
node.declaration = parseStatement(); | ||
} else { | ||
node.declaration = null; | ||
parseSpecifierList(node, "Export"); | ||
} | ||
semicolon(); | ||
return finishNode(node, "ExportDeclaration"); | ||
} | ||
function parseImport() { | ||
var node = startNode(); | ||
next(); | ||
if (token.type === tt.string) { | ||
node.specifiers = []; | ||
node.source = parseExprAtom(); | ||
node.kind = ''; | ||
} else { | ||
if (token.type === tt.name && token.value !== "from") { | ||
var elt = startNode(); | ||
elt.id = parseIdent(); | ||
elt.name = null; | ||
elt['default'] = true; | ||
finishNode(elt, "ImportSpecifier"); | ||
eat(tt.comma); | ||
} | ||
parseSpecifierList(node, "Import"); | ||
var specs = node.specifiers; | ||
for (var i = 0; i < specs.length; i++) specs[i]['default'] = false; | ||
if (elt) node.specifiers.unshift(elt); | ||
} | ||
semicolon(); | ||
return finishNode(node, "ImportDeclaration"); | ||
} | ||
function parseSpecifierList(node, prefix) { | ||
var elts = node.specifiers = []; | ||
if (token.type === tt.star) { | ||
var elt = startNode(); | ||
next(); | ||
if (token.type === tt.name && token.value === "as") { | ||
next(); | ||
elt.name = parseIdent(); | ||
} | ||
elts.push(finishNode(elt, prefix + "BatchSpecifier")); | ||
} else { | ||
var indent = curIndent, line = curLineStart, continuedLine = nextLineStart; | ||
pushCx(); | ||
eat(tt.braceL); | ||
if (curLineStart > continuedLine) continuedLine = curLineStart; | ||
while (!closes(tt.braceR, indent + (curLineStart <= continuedLine ? 1 : 0), line)) { | ||
var elt = startNode(); | ||
if (token.type === tt.star) { | ||
next(); | ||
if (token.type === tt.name && token.value === "as") { | ||
next(); | ||
elt.name = parseIdent(); | ||
} | ||
finishNode(elt, prefix + "BatchSpecifier"); | ||
} else { | ||
if (token.type === tt.name && token.value === "from") break; | ||
elt.id = parseIdent(); | ||
if (token.type === tt.name && token.value === "as") { | ||
next(); | ||
elt.name = parseIdent(); | ||
} else { | ||
elt.name = null; | ||
} | ||
finishNode(elt, prefix + "Specifier"); | ||
} | ||
elts.push(elt); | ||
eat(tt.comma); | ||
} | ||
eat(tt.braceR); | ||
popCx(); | ||
} | ||
if (token.type === tt.name && token.value === "from") { | ||
next(); | ||
node.source = parseExprAtom(); | ||
} else { | ||
node.source = null; | ||
} | ||
} | ||
function parseExprList(close, allowEmpty) { | ||
var indent = curIndent, line = curLineStart, elts = [], continuedLine = nextLineStart; | ||
@@ -804,2 +1114,6 @@ next(); // Opening bracket | ||
while (!closes(close, indent + (curLineStart <= continuedLine ? 1 : 0), line)) { | ||
if (eat(tt.comma)) { | ||
elts.push(allowEmpty ? null : dummyIdent()); | ||
continue; | ||
} | ||
var elt = parseExpression(true); | ||
@@ -812,3 +1126,3 @@ if (isDummy(elt)) { | ||
} | ||
while (eat(tt.comma)) {} | ||
eat(tt.comma); | ||
} | ||
@@ -815,0 +1129,0 @@ popCx(); |
@@ -5,3 +5,3 @@ { | ||
"main": "acorn.js", | ||
"version": "0.9.1-1", | ||
"version": "0.9.1-2", | ||
"maintainers": [ | ||
@@ -8,0 +8,0 @@ { |
(function(exports) { | ||
var tests = []; | ||
var acorn = typeof require == "undefined" ? window.acorn : require("../acorn.js"); | ||
exports.test = function(code, ast, options, comments) { | ||
tests.push({code: code, ast: ast, options: options, comments: comments}); | ||
exports.test = function(code, ast, options) { | ||
tests.push({code: code, ast: ast, options: options}); | ||
}; | ||
@@ -15,26 +14,25 @@ exports.testFail = function(code, message, options) { | ||
exports.runTests = function(callback) { | ||
var comments; | ||
exports.runTests = function(config, callback) { | ||
var parse = config.parse; | ||
function onComment(block, text, start, end, startLoc, endLoc) { | ||
comments.push({ | ||
block: block, | ||
text: text, | ||
start: start, | ||
end: end, | ||
startLoc: { line: startLoc.line, column: startLoc.column }, | ||
endLoc: { line: endLoc.line, column: endLoc.column } | ||
}); | ||
} | ||
var opts = {locations: true, onComment: onComment}; | ||
for (var i = 0; i < tests.length; ++i) { | ||
var test = tests[i]; | ||
if (config.filter && !config.filter(test)) continue; | ||
try { | ||
comments = []; | ||
if (test.options && !test.options.onComment) test.options.onComment = onComment; | ||
var ast = acorn.parse(test.code, test.options || opts); | ||
if (test.error) callback("fail", test.code, | ||
"Expected error message: " + test.error + "\nBut parsing succeeded."); | ||
var testOpts = test.options || {locations: true}; | ||
var expected = {}; | ||
if (expected.onComment = testOpts.onComment) { | ||
testOpts.onComment = [] | ||
} | ||
if (expected.onToken = testOpts.onToken) { | ||
testOpts.onToken = []; | ||
} | ||
var ast = parse(test.code, testOpts); | ||
if (test.error) { | ||
if (config.loose) { | ||
callback("ok", test.code); | ||
} else { | ||
callback("fail", test.code, "Expected error message: " + test.error + "\nBut parsing succeeded."); | ||
} | ||
} | ||
else if (test.assert) { | ||
@@ -47,3 +45,9 @@ var error = test.assert(ast); | ||
var mis = misMatch(test.ast, ast); | ||
if (!mis && test.comments) mis = misMatch(test.comments, comments); | ||
for (var name in expected) { | ||
if (mis) break; | ||
if (expected[name]) { | ||
mis = misMatch(expected[name], testOpts[name]); | ||
testOpts[name] = expected[name]; | ||
} | ||
} | ||
if (mis) callback("fail", test.code, mis); | ||
@@ -53,3 +57,6 @@ else callback("ok", test.code); | ||
} catch(e) { | ||
if (test.error && e instanceof SyntaxError) { | ||
if (!(e instanceof SyntaxError)) { | ||
throw e; | ||
} | ||
if (test.error) { | ||
if (e.message == test.error) callback("ok", test.code); | ||
@@ -56,0 +63,0 @@ else callback("fail", test.code, |
116
test/run.js
@@ -1,23 +0,111 @@ | ||
var driver = require("./driver.js"); | ||
require("./tests.js"); | ||
require("./tests-harmony.js"); | ||
require("./tests-jsx.js"); | ||
(function() { | ||
var driver; | ||
var testsRun = 0, failed = 0; | ||
if (typeof require !== "undefined") { | ||
driver = require("./driver.js"); | ||
require("./tests.js"); | ||
require("./tests-harmony.js"); | ||
require("./tests-jsx.js"); | ||
} else { | ||
driver = window; | ||
} | ||
var htmlLog = typeof document === "object" && document.getElementById('log'); | ||
var htmlGroup = htmlLog; | ||
function group(name) { | ||
if (htmlGroup) { | ||
var parentGroup = htmlGroup; | ||
htmlGroup = document.createElement("ul"); | ||
var item = document.createElement("li"); | ||
item.textContent = name; | ||
item.appendChild(htmlGroup); | ||
parentGroup.appendChild(item); | ||
} | ||
if (typeof console === "object" && console.group) { | ||
console.group(name); | ||
} | ||
} | ||
function groupEnd() { | ||
if (htmlGroup) { | ||
htmlGroup = htmlGroup.parentElement.parentElement; | ||
} | ||
if (typeof console === "object" && console.groupEnd) { | ||
console.groupEnd(name); | ||
} | ||
} | ||
function log(title, message) { | ||
if (htmlGroup) { | ||
var elem = document.createElement("li"); | ||
elem.innerHTML = "<b>" + title + "</b> " + message; | ||
htmlGroup.appendChild(elem); | ||
} | ||
if (typeof console === "object") console.log(title, message); | ||
} | ||
var stats, modes = { | ||
Normal: { | ||
config: { | ||
parse: (typeof require === "undefined" ? window.acorn : require("../acorn.js")).parse | ||
} | ||
}, | ||
Loose: { | ||
config: { | ||
parse: (typeof require === "undefined" ? window.acorn : require("../acorn_loose")).parse_dammit, | ||
loose: true, | ||
filter: function (test) { | ||
if (/`/.test(test.code)) return false; // FIXME remove this when the loose parse supports template strings | ||
var opts = test.options || {}; | ||
if (opts.loose === false) return false; | ||
return (opts.ecmaVersion || 5) <= 6; | ||
} | ||
} | ||
} | ||
}; | ||
function report(state, code, message) { | ||
if (state != "ok") {++failed; console.log(code, message);} | ||
++testsRun; | ||
if (state != "ok") {++stats.failed; log(code, message);} | ||
++stats.testsRun; | ||
} | ||
group("Errors"); | ||
for (var name in modes) { | ||
group(name); | ||
var mode = modes[name]; | ||
stats = mode.stats = {testsRun: 0, failed: 0}; | ||
var t0 = +new Date; | ||
driver.runTests(report); | ||
console.log(testsRun + " tests run in " + (+new Date - t0) + "ms"); | ||
driver.runTests(mode.config, report); | ||
mode.stats.duration = +new Date - t0; | ||
groupEnd(); | ||
} | ||
if (failed) { | ||
console.log(failed + " failures."); | ||
groupEnd(); | ||
function outputStats(name, stats) { | ||
log(name + ":", stats.testsRun + " tests run in " + stats.duration + "ms; " + | ||
(stats.failed ? stats.failed + " failures." : "all passed.")); | ||
} | ||
var total = {testsRun: 0, failed: 0, duration: 0}; | ||
group("Stats"); | ||
for (var name in modes) { | ||
var stats = modes[name].stats; | ||
outputStats(name + " parser", stats); | ||
for (var key in stats) total[key] += stats[key]; | ||
} | ||
outputStats("Total", total); | ||
groupEnd(); | ||
if (total.failed && typeof process === "object") { | ||
process.stdout.write("", function() { | ||
process.exit(1); | ||
}); | ||
} else { | ||
console.log("All passed."); | ||
} | ||
} | ||
})(); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3345330
39
92621