-
Notifications
You must be signed in to change notification settings - Fork 580
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
Node API: add options parameter to require.makeDefault() #1166
Conversation
Added tests. I've enabled @johnjbarton would you be able to review this when you have time? Thanks. |
{blockBinding: true}); | ||
// TODO(arv): The path below is sucky... | ||
var x = require(path.join(__dirname, './resources/let-x.js')).x; | ||
assert.equal(x, 'x'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point we have mutated nodejs's configuration via makeDefault
. We should undo that mutation with another call to makeDefault
and test that let
now fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could add this same let
-fails test before your call to makeDefault
to verify that blockBinding
is still an option that is false by default.
Thanks for this! Two review comments. |
@johnjbarton oh sorry for spamming the commits, by the way. I'm using Travis to run the tests as I don't have Make at the moment. Guess I'll boot up my Linux VM for the next contributions. |
if (!results.js) | ||
console.error(results.errors); | ||
|
||
return results.js; | ||
} | ||
|
||
function traceurRequire(filename) { | ||
var source = compile(filename); | ||
function traceurRequire(filename, options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just unsure about this change. If a user sets options here and the code contains require()
without options then what happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
traceur.require()
only uses the options argument to compile the requested file, it will never affect other traceur.require
nor the default require
calls as far as I can see. If no options are passed, it will be treated the same as calling .compile()
without options -- default parameters will kick in when we pass an undefined
options argument into .compile()
.
I can remove that part if you'd like, though it could be useful in some use cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnjbarton I'm assuming you mean a function call such as traceur.require('foo.js')
.
In that case, the options
argument will be undefined
. This proposed change will pass through the options
argument (object or undefined
) to Compiler#compile
, where the options
argument will default to an empty object if the function call does not provide a value or provides the undefined
value.
Is there any doubts about this process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh woops, checking it again, traceur.require
actually forwards the options
argument to Compiler.commonJSOptions
, which will also default to an empty object too anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is the first case you outlined that concerns me:
traceur.require() only uses the options argument to compile the requested file, it will never affect other traceur.require nor the default require calls as far as I can see
Users may be confused if they set an option through this API. Let's remove it until we see use cases for sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, I'll do it right away.
@johnjbarton alright, pushed your requested changes. By the way, should we merge the "traceurRequire options" test into the "traceurRequire.makeDefault options" test as well? Or should we move the |
@UltCombo You can get make for windows. I used one of these (I don't remember which one) |
Thanks @arv! Guess I was just a bit too lazy to look it up for the first PR test, but it will undoubtedly speed up my workflow here now. |
Damn typos, guess I'll go home and take a nap soon -- can't really be very productive with sleep deprivation. @johnjbarton If you're unsure about the |
Alright, cleaned up the code and updated the PR summary. By the way, in regards to the contributing guide:
Does "message body" refer to the PR summary (first line) or does it also includes the message body (which Github displays as "first comment")? If it is the latter, I'll update the PR body/first comment as well. |
The first comment. Alternatively you can squash all commits into one with the desired commit message. |
LGTM Let me know when you've done one of the above and I can merge this for you (I see that you've signed the CLA already). |
@arv done, I've just squashed all the commits. |
I'm seeing extra output in the result: https://travis-ci.org/google/traceur-compiler/builds/29587370#L470 Can this be removed? |
I'll be a bit busy in the next hours, I'm not sure why that line is appearing. Wouldn't it be related to the unit testing framework? |
It looks like the code gets executed and the error message is from that. If the options got updated correctly then the Traceur parser would raise the error. |
@arv sorry, not sure if I understood correctly. Do you mean that the Traceur parser logs the error whenever it fails? If so, we could think of something to replace the try/catch tests. |
It looks like the code parses fine by Traceur. The error comes when Node.js tries to execute the code. I thought the goal of this test was that we can reset the traceur options back, which should cause an error in Traceur's parser which gets reported through the ErrorReporter and the code never gets executed. |
@arv yes, I expected that to be the case too. I'm a bit busy atm, I'll probably be able to take a look later tonight. |
Thanks |
The compile function writes to the console: Unfortunately if you throw instead of write the console I don't think you will see the compile errors. |
Oh I see, thanks for the quick analysis @johnjbarton. Is there something we should change there? Doesn't ErrorReporter display those errors? (sorry, I haven't checked it yet) |
Please change |
@johnjbarton ok, done and squashed. |
@arv are you okay with this change? If you'd rather display all errors, maybe we could |
I think we want the type throw to extend
Note that that |
if (!results.js) | ||
console.error(results.errors); | ||
throw results.errors[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error(results.errors[0])
Fixing our messy error reporting story is out of scope for this PR. We already have bugs about these. With the change to the throw statement this looks good. |
Thanks for the quick feedback guys! Fixed it as requested by @arv. |
Oh, there's something weird. Now I'm at a loss again. |
I've installed Make on my MSysGit but I'm still having issues to run the tests, by the way. The initial 2 tests run just fine, but then it throws:
Am I supposed to do anything other than |
please create that directory and let me know if you hit any other problems. On Thu, Jul 10, 2014 at 3:25 PM, Fabrício Matté [email protected]
|
@johnjbarton thanks, I've created
|
I cloned your repo and built your branch without hitting any ENOENTs so I guess the problem here is related to windows. (The extra output is still there). Please post the exact output. My guess is that we are not normalizing for windows; this may in fact be solved by PR #1155. You could just try that diff, its two lines. |
@johnjbarton Well, those 3 failed test don't seem to affect the other tests, so don't give it too much thought. Well, I can open a separate issue if you'd like. To don't pollute this thread too much, I've posted the test script's output (stdout + stderr) on pastebin: http://pastebin.com/MMZJGCmm I'm pondering why Well, I'm a bit too tired atm and got a full day tomorrow, so I might not be able to contribute very soon. |
Oh wait, |
Weirdly enough, if I use |
Looks like this an issue with Node. Vanilla Node.js test case: server.js (entry point): try {
require('./let-x');
} catch(e) {} let-x.js: let x = 21; The error is logged when Node attempts to execute the code, even inside a try block. I'm not sure if this is the expected behavior in this scenario. Assuming Thoughts? |
To further prove my point, a fork of my test case above: server.js (entry point): console.log('Before let.');
try {
require('./let-x'); // logs error to console
} catch(e) {
console.log('inside catch');
}
console.log('After let.');
console.log('Before async function.');
try {
require('./async'); // does *not* log any error!
} catch(e) {
console.log('inside catch');
}
console.log('After async function.'); let-x.js let x = 21; async.js async function foo() {} Console output:
So, it is a Node.js issue after all. |
I've reworked the unit test ( |
test('traceurRequire.makeDefault options', function() { | ||
var traceurRequire = require('../../../src/node/require'), | ||
// TODO(arv): The path below is sucky... | ||
fixturePath = path.join(__dirname, './resources/async-function.js'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry one more issue of style, this code base uses
var x;
var y;
rather than
var x,
y;
Fixed in 66d05ab |
@johnjbarton oh my bad, damn habits get the best of me. Thanks @arv for fixing it so quickly. |
Just for the record, the extra output in the console was caused by this node bug: syntax errors are printed to stderr, even when wrapped with try/catch which has been fixed in the 0.11 branch by this PR. |
Closes #1162.
I've signed the CLA using my email ( ultcombo [\at] gmail {!dot!} com )
I'm unsure how to properly add a test for
require.makeDefault()
, as there is no way to "resetDefault()". Should we create a method for that as well?