Mikael, can you clarify the problem?
Kris Kowal
-Charles
> --
> You received this message because you are subscribed to the Google Groups "CommonJS" group.
> To post to this group, send email to comm...@googlegroups.com.
> To unsubscribe from this group, send email to commonjs+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/commonjs?hl=en.
>
That's not the case; require.main must be the "module" not the
"exports", which means that if there is a main module, the "id"
property must at least be defined.
Kris Kowal
We'd
Sent from my iPhone
Sorry for depositing my objection in the voting thread. Since you
started a new thread I'll write a few more words to explain my view:
As Daniel pointed out on the original thread, require.main == module
will throw a ReferenceError if both sides are undefined and module is
not declared. The only way this could fool you is by having something
like
var module;
if (require.main === module) ...
which is highly unlikely and easily debuggable. So with other things
the same, it's easier to check for require.main than for, say,
require.main.id or require.main.uri.
Hannes
> Mikael, can you clarify the problem?
>
> Kris Kowal
>
Ah, I see where you're coming from. This is actually not the case.
"module" is an undeclared free variable in 1.0, so this expression
will actually throw an error, not evaluate to true. I think it's safe
for "main" to be undefined if there's no module.
Kris Kowal
if (!require.main.id) {
// no main module
}
How is this better than the if (!require.main) we currently have?
if (require.main.id === module.id) {
// this module is main
} else {
// this module is not main - in fact there may be no main at all!
}
vs
if (require.main && (require.main.id === module.id)) {
...
} else {
...
Err, redundant. The spec says that if require.main is referentially identical to the 'module' object from the main module.
if (require.main === module) {
}
Done. No need to check the id's match as the *objects* are identical.
Anyway - for me Modules 1.1.1 is OK as is or could change to allow require.main === undefined. I am convinced that both are equally easy.
-C
There is something strange about my eval environment because I don't get an exception, but it doesn't really matter, once I implement the spec with the other changes this problem goes away entirely.
Except we have to change (according to the spec page) 7 perfectly
working sets of code.
I'm sorry, but changing a ratified spec based on the misapprehension
of a single person does not exactly boost my confidence in this whole
process.
Hannes
There's no cause for alarm. As always, unanimity is important; I for
one have no intention of going forward without your hand up. I think
that we're on the cusp of reverting to require.main === undefined; I'm
just waiting for Mikeal to weigh in.
Kris Kowal
--