Comments (10)
I guess it depends how complex we do it. I think handling single line if's is the priority for now, and this could be an advanced thing later.
single line if:
if (blah)
action;
else
otheraction;
from blanket.
Maybe we can somehow use the parser built into jshint, or copy the code:
https://github.com/jshint/jshint/tree/master/src/next
from blanket.
Or better yet, use the parsing of Uglify.js:
https://github.com/mishoo/UglifyJS
from blanket.
:) +1
On Tue, Oct 16, 2012 at 4:28 PM, Alex Seville [email protected]:
Or better yet, use the parsing of Uglify.js:
https://github.com/mishoo/UglifyJS—
Reply to this email directly or view it on GitHubhttps://github.com/Migrii/blanket/issues/16#issuecomment-9491809.
from blanket.
These might be of some help:
https://github.com/mishoo/UglifyJS/blob/master/tmp/instrument.js
http://tobyho.com/2012/01/04/fun-with-asts-and-uglify/
from blanket.
Okay, I put some test cases into that instrument.js file and got the following results:
// EDGE CASE 1, no bracket for *FAILS*
for (var i = 0; i < 5; ++i)
console.log("foo2");
// EDGE case 2, no bracket if *FAILS*
if (true)
console.log("foo3")
//EDGE case 3, mis matching the brackets *WORKS*
if (false){
console.log("dujh");
}
else
{
console.log("foo3");
}
//EDGE case 4, multi line logical statement *WORKS*
var out = false ||
true;
console.log(out);
//EDGE case 5, multi line arithmetic *WORKS*
var lastcase = 12+
12+
6;
console.log(lastcase);
So clearly this is a good tool to use. It will help with the parsing of js, except in a few cases. I'll work on getting the "no bracket if/for" issue working, and after that I'll integrate it into the lib/blanket.js file and write some tests.
from blanket.
Here are the results of above:
trace("for", 27, 8, 28, 35);
//FAIL
for (var i = 0; i < 5; ++i) trace("stat", 28, 16, 28, 35);
console.log("foo2");
//FAILEND
trace("if", 31, 8, 32, 30);
//FAIL
if (true) trace("stat", 32, 12, 32, 30);
console.log("foo3");
//FAILEND
trace("if", 35, 8, 41, 8);
if (false) {
trace("stat", 36, 12, 36, 31);
console.log("dujh");
} else {
trace("stat", 40, 12, 40, 31);
console.log("foo3");
}
trace("var", 44, 8, 45, 16);
var out = false || true;
trace("stat", 46, 8, 46, 24);
console.log(out);
trace("var", 49, 8, 51, 25);
var lastcase = 12 + 12 + 6;
trace("stat", 52, 8, 52, 29);
console.log(lastcase);
I've added some extra spacing to clearly show the failing cases.
from blanket.
I figured out how to detect if it's an IF (or try, or while, etc...) without brackets, but I don't know how to update the parse tree.
Line 61: https://gist.github.com/3900493
is where this needs to be handled.
from blanket.
Nice, I think I got a parser working:
https://gist.github.com/3909508
I threw the ultimate one liner at it, and with a small modification it generates good instrumented code. Now I just need to integrate it into the solution and write tests.
from blanket.
I think I've resolved all these issues now.
from blanket.
Related Issues (20)
- mixed case data-cover- options not detected HOT 1
- Commented on: Not seeing any reports - noob alert #244 HOT 1
- _$jscoverage is not defined | blanket 1.2.1 HOT 21
- Reason for replacing ".js" with ""
- In ploymer,the script is written in the component html,is there any method to set data-cover on the script HOT 2
- Publish the latest version HOT 1
- Global object replaced on QUnit test
- How to use Blanket.js in test files loaded with Require.js? HOT 2
- blanket js does not given correct results.
- Can blanket handle source maps?
- documention is wrong for using with mocha HOT 1
- Advice on how to use with WebDriver. HOT 1
- Support for phantomjs 2.1.1 (for blanket to work on ppc64le architecture)
- Coverage for hoisted vars HOT 2
- I am getting Error: invalid reporter "html-cov" HOT 1
- Tests stop running on upgrading to [email protected] HOT 1
- make a new release on the github?
- Instrumentation affects test results.
- Running Jasmine Code Coverage using command Line
- Deprecate this?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blanket.