esprima
Advanced tools
Comparing version 0.9.5 to 0.9.6
@@ -90,3 +90,3 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) { | ||
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word]; | ||
return known ? ret(known.type, known.style, word) : | ||
return (known && state.kwAllowed) ? ret(known.type, known.style, word) : | ||
ret("variable", "variable", word); | ||
@@ -320,2 +320,3 @@ } | ||
reAllowed: true, | ||
kwAllowed: true, | ||
cc: [], | ||
@@ -339,2 +340,3 @@ lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false), | ||
state.reAllowed = type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/); | ||
state.kwAllowed = type != '.'; | ||
return parseJS(state, style, type, content, stream); | ||
@@ -341,0 +343,0 @@ }, |
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.9.5", | ||
"version": "0.9.6", | ||
"engines": { | ||
@@ -12,0 +12,0 @@ "node": ">=0.4.0" |
@@ -30,3 +30,3 @@ Esprima ([esprima.org](http://esprima.org)) is an educational | ||
Esprima is supported on [many browsers](http://code.google.com/p/esprima/wiki/BrowserCompatibility): | ||
IE 8+, Firefox 3.5+, Safari 4+, Chrome 7+, and Opera 10.5+. | ||
IE 6+, Firefox 1+, Safari 3+, Chrome 1+, and Opera 8+. | ||
@@ -33,0 +33,0 @@ Feedback and contribution are welcomed! Please join the |
/*jslint browser: true */ | ||
function runBenchmarks() { | ||
function setupBenchmarks() { | ||
'use strict'; | ||
var index = 0, | ||
totalSize = 0, | ||
totalTime = 0, | ||
fixture; | ||
fixture = [ | ||
'jquery-1.7.1', | ||
'jquery-1.6.4', | ||
'prototype-1.7.0.0', | ||
'prototype-1.6.1', | ||
'ext-core-3.1.0', | ||
'ext-core-3.0.0', | ||
'mootools-1.4.1', | ||
'mootools-1.3.2' | ||
var fixture = [ | ||
'jQuery 1.7.1', | ||
'jQuery 1.6.4', | ||
'jQuery.Mobile 1.0', | ||
'Prototype 1.7.0.0', | ||
'Prototype 1.6.1', | ||
'Ext Core 3.1.0', | ||
'Ext Core 3.0.0', | ||
'MooTools 1.4.1', | ||
'MooTools 1.3.2', | ||
'Backbone 0.5.3', | ||
'Underscore 1.2.3' | ||
]; | ||
function setText(el, str) { | ||
function id(i) { | ||
return document.getElementById(i); | ||
} | ||
function kb(bytes) { | ||
return (bytes / 1024).toFixed(1); | ||
} | ||
function setText(id, str) { | ||
var el = document.getElementById(id); | ||
if (typeof el.innerText === 'string') { | ||
@@ -29,71 +37,193 @@ el.innerText = str; | ||
function showVersion() { | ||
var el = document.getElementById('benchmarkjs-version'); | ||
setText(el, ' version ' + window.Benchmark.version); | ||
el = document.getElementById('version'); | ||
setText(el, window.esprima.version); | ||
function slug(name) { | ||
return name.toLowerCase().replace(/\s/g, '-'); | ||
} | ||
function showStatus(name) { | ||
var el = document.getElementById(name + '-time'); | ||
setText(el, 'Running...'); | ||
function enableRunButtons() { | ||
id('runquick').disabled = false; | ||
id('runfull').disabled = false; | ||
} | ||
function finish() { | ||
var el = document.getElementById('status'); | ||
setText(el, 'Completed.'); | ||
el = document.getElementById('total-size'); | ||
setText(el, (totalSize / 1024).toFixed(1)); | ||
el = document.getElementById('total-time'); | ||
setText(el, (1000 * totalTime).toFixed(1)); | ||
function disableRunButtons() { | ||
id('runquick').disabled = true; | ||
id('runfull').disabled = true; | ||
} | ||
function showResult(name, size, stats) { | ||
var el; | ||
el = document.getElementById(name + '-size'); | ||
setText(el, (size / 1024).toFixed(1)); | ||
el = document.getElementById(name + '-time'); | ||
setText(el, (1000 * stats.mean).toFixed(1)); | ||
el = document.getElementById(name + '-variance'); | ||
setText(el, (1000 * stats.variance).toFixed(1)); | ||
function createTable() { | ||
var str = '', | ||
index, | ||
test, | ||
name; | ||
str += '<table>'; | ||
str += '<thead><tr><th>Source</th><th>Size (KiB)</th>'; | ||
str += '<th>Time (ms)</th><th>Variance</th></tr></thead>'; | ||
str += '<tbody>'; | ||
for (index = 0; index < fixture.length; index += 1) { | ||
test = fixture[index]; | ||
name = slug(test); | ||
str += '<tr>'; | ||
str += '<td>' + test + '</td>'; | ||
str += '<td id="' + name + '-size"></td>'; | ||
str += '<td id="' + name + '-time"></td>'; | ||
str += '<td id="' + name + '-variance"></td>'; | ||
str += '</tr>'; | ||
} | ||
str += '<tr><td><b>Total</b></td>'; | ||
str += '<td id="total-size"></td>'; | ||
str += '<td id="total-time"></td>'; | ||
str += '<td></td></tr>'; | ||
str += '</tbody>'; | ||
str += '</table>'; | ||
id('result').innerHTML = str; | ||
} | ||
function runBenchmark() { | ||
var el, test, source, benchmark; | ||
function loadTests() { | ||
if (index >= fixture.length) { | ||
finish(); | ||
return; | ||
var index = 0, | ||
totalSize = 0; | ||
function load(test, callback) { | ||
var xhr = new XMLHttpRequest(), | ||
src = '3rdparty/' + test + '.js'; | ||
window.data = window.data || {}; | ||
window.data[test] = ''; | ||
try { | ||
xhr.timeout = 30000; | ||
xhr.open('GET', src, true); | ||
xhr.ontimeout = function () { | ||
setText('status', 'Error: time out while loading ' + test); | ||
callback.apply(); | ||
}; | ||
xhr.onreadystatechange = function () { | ||
var success = false, | ||
size = 0; | ||
if (this.readyState === XMLHttpRequest.DONE) { | ||
if (this.status === 200) { | ||
window.data[test] = this.responseText; | ||
size = this.responseText.length; | ||
totalSize += size; | ||
success = true; | ||
} | ||
} | ||
if (success) { | ||
setText(test + '-size', kb(size)); | ||
} else { | ||
setText('status', 'Please wait. Error loading ' + src); | ||
setText(test + '-size', 'Error'); | ||
} | ||
callback.apply(); | ||
}; | ||
xhr.send(null); | ||
} catch (e) { | ||
setText('status', 'Please wait. Error loading ' + src); | ||
callback.apply(); | ||
} | ||
} | ||
test = fixture[index]; | ||
el = document.getElementById(test); | ||
source = (typeof el.innerText === 'string') ? el.innerText : el.textContent; | ||
showStatus(test); | ||
function loadNextTest() { | ||
var test; | ||
// Force the result to be held in this array, thus defeating any | ||
// possible "dead core elimination" optimization. | ||
window.tree = []; | ||
if (index < fixture.length) { | ||
test = fixture[index]; | ||
index += 1; | ||
setText('status', 'Please wait. Loading ' + test + | ||
' (' + index + ' of ' + fixture.length + ')'); | ||
window.setTimeout(function () { | ||
load(slug(test), loadNextTest); | ||
}, 100); | ||
} else { | ||
setText('total-size', kb(totalSize)); | ||
setText('status', 'Ready.'); | ||
enableRunButtons(); | ||
} | ||
} | ||
benchmark = new window.Benchmark(test, function (o) { | ||
var syntax = window.esprima.parse(source); | ||
window.tree.push(syntax.body.length); | ||
}, { | ||
'onComplete': function () { | ||
showResult(this.name, source.length, this.stats); | ||
totalSize += source.length; | ||
totalTime += this.stats.mean; | ||
loadNextTest(); | ||
} | ||
function runBenchmarks(suite) { | ||
var index = 0, | ||
totalTime = 0; | ||
function reset() { | ||
var i, name; | ||
for (i = 0; i < fixture.length; i += 1) { | ||
name = slug(fixture[i]); | ||
setText(name + '-time', ''); | ||
setText(name + '-variance', ''); | ||
} | ||
}); | ||
setText('total-time', ''); | ||
} | ||
window.setTimeout(function () { | ||
benchmark.run(); | ||
index += 1; | ||
window.setTimeout(runBenchmark, 211); | ||
}, 211); | ||
function run() { | ||
var el, test, source, benchmark; | ||
if (index >= suite.length) { | ||
setText('total-time', (1000 * totalTime).toFixed(1)); | ||
setText('status', 'Ready.'); | ||
enableRunButtons(); | ||
return; | ||
} | ||
test = slug(suite[index]); | ||
el = id(test); | ||
source = window.data[test]; | ||
setText(test + '-time', 'Running...'); | ||
// Force the result to be held in this array, thus defeating any | ||
// possible "dead core elimination" optimization. | ||
window.tree = []; | ||
benchmark = new window.Benchmark(test, function (o) { | ||
var syntax = window.esprima.parse(source); | ||
window.tree.push(syntax.body.length); | ||
}, { | ||
'onComplete': function () { | ||
setText(this.name + '-time', (1000 * this.stats.mean).toFixed(1)); | ||
setText(this.name + '-variance', (1000 * this.stats.variance).toFixed(1)); | ||
totalTime += this.stats.mean; | ||
} | ||
}); | ||
window.setTimeout(function () { | ||
benchmark.run(); | ||
index += 1; | ||
window.setTimeout(run, 211); | ||
}, 211); | ||
} | ||
disableRunButtons(); | ||
setText('status', 'Please wait. Running benchmarks...'); | ||
reset(); | ||
run(); | ||
} | ||
showVersion(); | ||
window.setTimeout(runBenchmark, 211); | ||
id('runquick').onclick = function () { | ||
runBenchmarks(['jQuery 1.7.1', 'jQuery.Mobile 1.0', 'Backbone 0.5.3']); | ||
}; | ||
id('runfull').onclick = function () { | ||
runBenchmarks(fixture); | ||
}; | ||
setText('benchmarkjs-version', ' version ' + window.Benchmark.version); | ||
setText('version', window.esprima.version); | ||
createTable(); | ||
disableRunButtons(); | ||
loadTests(); | ||
} | ||
@@ -5,5 +5,6 @@ /*jslint browser: true */ | ||
'use strict'; | ||
var index = 0, | ||
totalSize = 0, | ||
totalTime = 0, | ||
totalTime = {}, | ||
fixture; | ||
@@ -33,10 +34,12 @@ | ||
totalTime = { | ||
'esprima': 0, | ||
'narcissus': 0, | ||
'parsejs': 0, | ||
'zeparser': 0 | ||
}; | ||
function id(i) { | ||
return document.getElementById(i); | ||
} | ||
function setText(el, str) { | ||
function kb(bytes) { | ||
return (bytes / 1024).toFixed(1); | ||
} | ||
function setText(id, str) { | ||
var el = document.getElementById(id); | ||
if (typeof el.innerText === 'string') { | ||
@@ -49,41 +52,80 @@ el.innerText = str; | ||
function showVersion() { | ||
var el = document.getElementById('benchmarkjs-version'); | ||
setText(el, ' version ' + window.Benchmark.version); | ||
el = document.getElementById('version'); | ||
setText(el, window.esprima.version); | ||
function ready() { | ||
setText('status', 'Ready.'); | ||
id('run').disabled = false; | ||
id('run').style.visibility = 'visible'; | ||
} | ||
function showStatus(parser, name) { | ||
var el = document.getElementById(parser + '-' + name); | ||
el.textContent = 'Running...'; | ||
} | ||
function load(tst, callback) { | ||
var xhr = new XMLHttpRequest(), | ||
src = '3rdparty/' + tst + '.js'; | ||
function finish() { | ||
var el = document.getElementById('status'); | ||
el.textContent = 'Completed.'; | ||
el = document.getElementById('total-size'); | ||
el.textContent = (totalSize / 1024).toFixed(1); | ||
el = document.getElementById('esprima-time'); | ||
el.textContent = (1000 * totalTime.esprima).toFixed(1) + ' ms'; | ||
el = document.getElementById('narcissus-time'); | ||
if (totalTime.narcissus > 0) { | ||
el.textContent = (1000 * totalTime.narcissus).toFixed(1) + ' ms'; | ||
// Already available? Don't reload from server. | ||
if (window.data && window.data.hasOwnProperty(tst)) { | ||
callback.apply(); | ||
} | ||
el = document.getElementById('parsejs-time'); | ||
el.textContent = (1000 * totalTime.parsejs).toFixed(1) + ' ms'; | ||
el = document.getElementById('zeparser-time'); | ||
el.textContent = (1000 * totalTime.zeparser).toFixed(1) + ' ms'; | ||
try { | ||
xhr.timeout = 30000; | ||
xhr.open('GET', src, true); | ||
setText('status', 'Please wait. Loading ' + src); | ||
xhr.ontimeout = function () { | ||
setText('status', 'Please wait. Error: time out while loading ' + src + ' '); | ||
callback.apply(); | ||
}; | ||
xhr.onreadystatechange = function () { | ||
var success = false, | ||
size = 0; | ||
if (this.readyState === XMLHttpRequest.DONE) { | ||
if (this.status === 200) { | ||
window.data = window.data || {}; | ||
window.data[tst] = this.responseText; | ||
size = this.responseText.length; | ||
totalSize += size; | ||
success = true; | ||
} | ||
} | ||
if (success) { | ||
setText(tst + '-size', kb(size)); | ||
} else { | ||
setText('status', 'Please wait. Error loading ' + src); | ||
setText(tst + '-size', 'Error'); | ||
} | ||
callback.apply(); | ||
}; | ||
xhr.send(null); | ||
} catch (e) { | ||
setText('status', 'Please wait. Error loading ' + src); | ||
callback.apply(); | ||
} | ||
} | ||
function showResult(parser, name, size, stats) { | ||
var el; | ||
el = document.getElementById(name + '-size'); | ||
el.textContent = (size / 1024).toFixed(1); | ||
el = document.getElementById(parser + '-' + name); | ||
if (stats.size === 0) { | ||
el.textContent = 'N/A'; | ||
} else { | ||
el.textContent = (1000 * stats.mean).toFixed(1) + ' ms'; | ||
function loadTests() { | ||
var sources = fixture.slice(); | ||
function loadNextTest() { | ||
var tst; | ||
if (sources.length > 0) { | ||
tst = sources[0].split(' '); | ||
tst = tst[1]; | ||
sources.splice(0, 1); | ||
window.setTimeout(function () { | ||
load(tst, loadNextTest); | ||
}, 100); | ||
} else { | ||
setText('total-size', kb(totalSize)); | ||
ready(); | ||
} | ||
} | ||
id('run').style.visibility = 'hidden'; | ||
loadNextTest(); | ||
} | ||
@@ -95,3 +137,10 @@ | ||
if (index >= fixture.length) { | ||
finish(); | ||
setText('total-size', kb(totalSize)); | ||
setText('esprima-time', (1000 * totalTime.esprima).toFixed(1) + ' ms'); | ||
setText('parsejs-time', (1000 * totalTime.parsejs).toFixed(1) + ' ms'); | ||
setText('zeparser-time', (1000 * totalTime.zeparser).toFixed(1) + ' ms'); | ||
if (totalTime.narcissus > 0) { | ||
setText('narcissus-time', (1000 * totalTime.narcissus).toFixed(1) + ' ms'); | ||
} | ||
ready(); | ||
return; | ||
@@ -104,9 +153,5 @@ } | ||
if (!document.getElementById(test)) { | ||
throw 'Unknown text fixture ' + test; | ||
} | ||
source = window.data[test]; | ||
setText(parser + '-' + test, 'Running...'); | ||
source = document.getElementById(test).textContent; | ||
showStatus(parser, test); | ||
// Force the result to be held in this array, thus defeating any | ||
@@ -147,3 +192,3 @@ // possible "dead core elimination" optimization. | ||
'onComplete': function () { | ||
showResult(parser, this.name, source.length, this.stats); | ||
setText(parser + '-' + this.name, (1000 * this.stats.mean).toFixed(1) + ' ms'); | ||
totalSize += source.length; | ||
@@ -161,5 +206,36 @@ totalTime[parser] += this.stats.mean; | ||
showVersion(); | ||
window.setTimeout(runBenchmark, 211); | ||
id('run').onclick = function () { | ||
var test; | ||
for (index = 0; index < fixture.length; index += 1) { | ||
test = fixture[index].split(' ').join('-'); | ||
setText(test, ''); | ||
} | ||
setText('status', 'Please wait. Running benchmarks...'); | ||
id('run').style.visibility = 'hidden'; | ||
index = 0; | ||
totalTime = { | ||
'esprima': 0, | ||
'narcissus': 0, | ||
'parsejs': 0, | ||
'zeparser': 0 | ||
}; | ||
for (test in totalTime) { | ||
if (totalTime.hasOwnProperty(test)) { | ||
setText(test + '-time', ''); | ||
} | ||
} | ||
runBenchmark(); | ||
}; | ||
setText('benchmarkjs-version', ' version ' + window.Benchmark.version); | ||
setText('version', window.esprima.version); | ||
loadTests(); | ||
} | ||
@@ -142,11 +142,14 @@ /* | ||
pattern.assert = function (tree) { | ||
var actual, expected; | ||
actual = JSON.stringify(tree, adjustRegexLiteral, 4); | ||
expected = JSON.stringify(obj, null, 4); | ||
if (expected !== actual) { | ||
reportFailure(expected, actual); | ||
} | ||
}; | ||
if (obj.type && (obj.type === 'Program')) { | ||
pattern.assert = function (tree) { | ||
var actual, expected; | ||
actual = JSON.stringify(tree, adjustRegexLiteral, 4); | ||
expected = JSON.stringify(obj, null, 4); | ||
if (expected !== actual) { | ||
reportFailure(expected, actual); | ||
} | ||
}; | ||
} | ||
return pattern; | ||
@@ -153,0 +156,0 @@ }; |
@@ -30,3 +30,3 @@ // This is modified from Mozilla Reflect.parse test suite (the file is located | ||
params: params, | ||
body: body, | ||
body: body | ||
}) } | ||
@@ -36,3 +36,3 @@ function genFunDecl(id, params, body) { return Pattern({ type: "FunctionDeclaration", | ||
params: params, | ||
body: body, | ||
body: body | ||
}) } | ||
@@ -66,3 +66,3 @@ function varDecl(decls) { return Pattern({ type: "VariableDeclaration", declarations: decls, kind: "var" }) } | ||
params: args, | ||
body: body, | ||
body: body | ||
}) } | ||
@@ -72,3 +72,3 @@ function genFunExpr(id, args, body) { return Pattern({ type: "FunctionExpression", | ||
params: args, | ||
body: body, | ||
body: body | ||
}) } | ||
@@ -75,0 +75,0 @@ |
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 not supported yet
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 not supported yet
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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
45
78120
2821095
2